viewer.js 522 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * JavaScript code in this page
  4. *
  5. * Copyright 2023 Mozilla Foundation
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. *
  19. * @licend The above is the entire license notice for the
  20. * JavaScript code in this page
  21. */
  22. /******/ (() => {
  23. // webpackBootstrap
  24. /******/ "use strict";
  25. /******/ var __webpack_modules__ = [
  26. ,
  27. /* 0 */ /* 1 */
  28. /***/ (__unused_webpack_module, exports, __webpack_require__) => {
  29. Object.defineProperty(exports, "__esModule", {
  30. value: true,
  31. });
  32. exports.GenericCom = void 0;
  33. var _app = __webpack_require__(2);
  34. var _preferences = __webpack_require__(42);
  35. var _download_manager = __webpack_require__(43);
  36. var _genericl10n = __webpack_require__(44);
  37. var _generic_scripting = __webpack_require__(46);
  38. const GenericCom = {};
  39. exports.GenericCom = GenericCom;
  40. class GenericPreferences extends _preferences.BasePreferences {
  41. async _writeToStorage(prefObj) {
  42. localStorage.setItem("pdfjs.preferences", JSON.stringify(prefObj));
  43. }
  44. async _readFromStorage(prefObj) {
  45. return JSON.parse(localStorage.getItem("pdfjs.preferences"));
  46. }
  47. }
  48. class GenericExternalServices extends _app.DefaultExternalServices {
  49. static createDownloadManager() {
  50. return new _download_manager.DownloadManager();
  51. }
  52. static createPreferences() {
  53. return new GenericPreferences();
  54. }
  55. static createL10n({ locale = "en-US" }) {
  56. return new _genericl10n.GenericL10n(locale);
  57. }
  58. static createScripting({ sandboxBundleSrc }) {
  59. return new _generic_scripting.GenericScripting(sandboxBundleSrc);
  60. }
  61. }
  62. _app.PDFViewerApplication.externalServices = GenericExternalServices;
  63. /***/
  64. },
  65. /* 2 */
  66. /***/ (__unused_webpack_module, exports, __webpack_require__) => {
  67. Object.defineProperty(exports, "__esModule", {
  68. value: true,
  69. });
  70. exports.PDFViewerApplication =
  71. exports.PDFPrintServiceFactory =
  72. exports.DefaultExternalServices =
  73. void 0;
  74. var _ui_utils = __webpack_require__(3);
  75. var _pdfjsLib = __webpack_require__(4);
  76. var _app_options = __webpack_require__(5);
  77. var _event_utils = __webpack_require__(6);
  78. var _pdf_link_service = __webpack_require__(7);
  79. var _webAnnotation_editor_params = __webpack_require__(8);
  80. var _overlay_manager = __webpack_require__(9);
  81. var _password_prompt = __webpack_require__(10);
  82. var _webPdf_attachment_viewer = __webpack_require__(11);
  83. var _webPdf_cursor_tools = __webpack_require__(13);
  84. var _webPdf_document_properties = __webpack_require__(15);
  85. var _webPdf_find_bar = __webpack_require__(16);
  86. var _pdf_find_controller = __webpack_require__(17);
  87. var _pdf_history = __webpack_require__(19);
  88. var _webPdf_layer_viewer = __webpack_require__(20);
  89. var _webPdf_outline_viewer = __webpack_require__(21);
  90. var _webPdf_presentation_mode = __webpack_require__(22);
  91. var _pdf_rendering_queue = __webpack_require__(23);
  92. var _pdf_scripting_manager = __webpack_require__(24);
  93. var _webPdf_sidebar = __webpack_require__(25);
  94. var _webPdf_sidebar_resizer = __webpack_require__(26);
  95. var _webPdf_thumbnail_viewer = __webpack_require__(27);
  96. var _pdf_viewer = __webpack_require__(29);
  97. var _webSecondary_toolbar = __webpack_require__(39);
  98. var _webToolbar = __webpack_require__(40);
  99. var _view_history = __webpack_require__(41);
  100. const FORCE_PAGES_LOADED_TIMEOUT = 10000;
  101. const WHEEL_ZOOM_DISABLED_TIMEOUT = 1000;
  102. const ViewOnLoad = {
  103. UNKNOWN: -1,
  104. PREVIOUS: 0,
  105. INITIAL: 1,
  106. };
  107. const ViewerCssTheme = {
  108. AUTOMATIC: 0,
  109. LIGHT: 1,
  110. DARK: 2,
  111. };
  112. class DefaultExternalServices {
  113. constructor() {
  114. throw new Error("Cannot initialize DefaultExternalServices.");
  115. }
  116. static updateFindControlState(data) {}
  117. static updateFindMatchesCount(data) {}
  118. static initPassiveLoading(callbacks) {}
  119. static reportTelemetry(data) {}
  120. static createDownloadManager() {
  121. throw new Error("Not implemented: createDownloadManager");
  122. }
  123. static createPreferences() {
  124. throw new Error("Not implemented: createPreferences");
  125. }
  126. static createL10n(options) {
  127. throw new Error("Not implemented: createL10n");
  128. }
  129. static createScripting(options) {
  130. throw new Error("Not implemented: createScripting");
  131. }
  132. static get supportsPinchToZoom() {
  133. return (0, _pdfjsLib.shadow)(this, "supportsPinchToZoom", true);
  134. }
  135. static get supportsIntegratedFind() {
  136. return (0, _pdfjsLib.shadow)(this, "supportsIntegratedFind", false);
  137. }
  138. static get supportsDocumentFonts() {
  139. return (0, _pdfjsLib.shadow)(this, "supportsDocumentFonts", true);
  140. }
  141. static get supportedMouseWheelZoomModifierKeys() {
  142. return (0, _pdfjsLib.shadow)(
  143. this,
  144. "supportedMouseWheelZoomModifierKeys",
  145. {
  146. ctrlKey: true,
  147. metaKey: true,
  148. }
  149. );
  150. }
  151. static get isInAutomation() {
  152. return (0, _pdfjsLib.shadow)(this, "isInAutomation", false);
  153. }
  154. static updateEditorStates(data) {
  155. throw new Error("Not implemented: updateEditorStates");
  156. }
  157. static get canvasMaxAreaInBytes() {
  158. return (0, _pdfjsLib.shadow)(this, "canvasMaxAreaInBytes", -1);
  159. }
  160. }
  161. exports.DefaultExternalServices = DefaultExternalServices;
  162. const PDFViewerApplication = {
  163. initialBookmark: document.location.hash.substring(1),
  164. _initializedCapability: (0, _pdfjsLib.createPromiseCapability)(),
  165. appConfig: null,
  166. pdfDocument: null,
  167. pdfLoadingTask: null,
  168. printService: null,
  169. pdfViewer: null,
  170. pdfThumbnailViewer: null,
  171. pdfRenderingQueue: null,
  172. pdfPresentationMode: null,
  173. pdfDocumentProperties: null,
  174. pdfLinkService: null,
  175. pdfHistory: null,
  176. pdfSidebar: null,
  177. pdfSidebarResizer: null,
  178. pdfOutlineViewer: null,
  179. pdfAttachmentViewer: null,
  180. pdfLayerViewer: null,
  181. pdfCursorTools: null,
  182. pdfScriptingManager: null,
  183. store: null,
  184. downloadManager: null,
  185. overlayManager: null,
  186. preferences: null,
  187. toolbar: null,
  188. secondaryToolbar: null,
  189. eventBus: null,
  190. l10n: null,
  191. annotationEditorParams: null,
  192. isInitialViewSet: false,
  193. downloadComplete: false,
  194. isViewerEmbedded: window.parent !== window,
  195. url: "",
  196. baseUrl: "",
  197. _downloadUrl: "",
  198. externalServices: DefaultExternalServices,
  199. _boundEvents: Object.create(null),
  200. documentInfo: null,
  201. metadata: null,
  202. _contentDispositionFilename: null,
  203. _contentLength: null,
  204. _saveInProgress: false,
  205. _wheelUnusedTicks: 0,
  206. _wheelUnusedFactor: 1,
  207. _touchUnusedTicks: 0,
  208. _touchUnusedFactor: 1,
  209. _PDFBug: null,
  210. _hasAnnotationEditors: false,
  211. _title: document.title,
  212. _printAnnotationStoragePromise: null,
  213. _touchInfo: null,
  214. _isCtrlKeyDown: false,
  215. async initialize(appConfig) {
  216. this.preferences = this.externalServices.createPreferences();
  217. this.appConfig = appConfig;
  218. await this._initializeOptions();
  219. this._forceCssTheme();
  220. await this._initializeL10n();
  221. if (
  222. this.isViewerEmbedded &&
  223. _app_options.AppOptions.get("externalLinkTarget") ===
  224. _pdf_link_service.LinkTarget.NONE
  225. ) {
  226. _app_options.AppOptions.set(
  227. "externalLinkTarget",
  228. _pdf_link_service.LinkTarget.TOP
  229. );
  230. }
  231. await this._initializeViewerComponents();
  232. this.bindEvents();
  233. this.bindWindowEvents();
  234. const appContainer =
  235. appConfig.appContainer || document.documentElement;
  236. this.l10n.translate(appContainer).then(() => {
  237. this.eventBus.dispatch("localized", {
  238. source: this,
  239. });
  240. });
  241. this._initializedCapability.resolve();
  242. },
  243. async _initializeOptions() {
  244. if (_app_options.AppOptions.get("disablePreferences")) {
  245. if (_app_options.AppOptions.get("pdfBugEnabled")) {
  246. await this._parseHashParams();
  247. }
  248. return;
  249. }
  250. if (_app_options.AppOptions._hasUserOptions()) {
  251. console.warn(
  252. "_initializeOptions: The Preferences may override manually set AppOptions; " +
  253. 'please use the "disablePreferences"-option in order to prevent that.'
  254. );
  255. }
  256. try {
  257. _app_options.AppOptions.setAll(await this.preferences.getAll());
  258. } catch (reason) {
  259. console.error(`_initializeOptions: "${reason.message}".`);
  260. }
  261. if (_app_options.AppOptions.get("pdfBugEnabled")) {
  262. await this._parseHashParams();
  263. }
  264. },
  265. async _parseHashParams() {
  266. const hash = document.location.hash.substring(1);
  267. if (!hash) {
  268. return;
  269. }
  270. const { mainContainer, viewerContainer } = this.appConfig,
  271. params = (0, _ui_utils.parseQueryString)(hash);
  272. if (params.get("disableworker") === "true") {
  273. try {
  274. await loadFakeWorker();
  275. } catch (ex) {
  276. console.error(`_parseHashParams: "${ex.message}".`);
  277. }
  278. }
  279. if (params.has("disablerange")) {
  280. _app_options.AppOptions.set(
  281. "disableRange",
  282. params.get("disablerange") === "true"
  283. );
  284. }
  285. if (params.has("disablestream")) {
  286. _app_options.AppOptions.set(
  287. "disableStream",
  288. params.get("disablestream") === "true"
  289. );
  290. }
  291. if (params.has("disableautofetch")) {
  292. _app_options.AppOptions.set(
  293. "disableAutoFetch",
  294. params.get("disableautofetch") === "true"
  295. );
  296. }
  297. if (params.has("disablefontface")) {
  298. _app_options.AppOptions.set(
  299. "disableFontFace",
  300. params.get("disablefontface") === "true"
  301. );
  302. }
  303. if (params.has("disablehistory")) {
  304. _app_options.AppOptions.set(
  305. "disableHistory",
  306. params.get("disablehistory") === "true"
  307. );
  308. }
  309. if (params.has("verbosity")) {
  310. _app_options.AppOptions.set(
  311. "verbosity",
  312. params.get("verbosity") | 0
  313. );
  314. }
  315. if (params.has("textlayer")) {
  316. switch (params.get("textlayer")) {
  317. case "off":
  318. _app_options.AppOptions.set(
  319. "textLayerMode",
  320. _ui_utils.TextLayerMode.DISABLE
  321. );
  322. break;
  323. case "visible":
  324. case "shadow":
  325. case "hover":
  326. viewerContainer.classList.add(
  327. `textLayer-${params.get("textlayer")}`
  328. );
  329. try {
  330. await loadPDFBug(this);
  331. this._PDFBug.loadCSS();
  332. } catch (ex) {
  333. console.error(`_parseHashParams: "${ex.message}".`);
  334. }
  335. break;
  336. }
  337. }
  338. if (params.has("pdfbug")) {
  339. _app_options.AppOptions.set("pdfBug", true);
  340. _app_options.AppOptions.set("fontExtraProperties", true);
  341. const enabled = params.get("pdfbug").split(",");
  342. try {
  343. await loadPDFBug(this);
  344. this._PDFBug.init(
  345. {
  346. OPS: _pdfjsLib.OPS,
  347. },
  348. mainContainer,
  349. enabled
  350. );
  351. } catch (ex) {
  352. console.error(`_parseHashParams: "${ex.message}".`);
  353. }
  354. }
  355. if (params.has("locale")) {
  356. _app_options.AppOptions.set("locale", params.get("locale"));
  357. }
  358. },
  359. async _initializeL10n() {
  360. this.l10n = this.externalServices.createL10n({
  361. locale: _app_options.AppOptions.get("locale"),
  362. });
  363. const dir = await this.l10n.getDirection();
  364. document.getElementsByTagName("html")[0].dir = dir;
  365. },
  366. _forceCssTheme() {
  367. const cssTheme = _app_options.AppOptions.get("viewerCssTheme");
  368. if (
  369. cssTheme === ViewerCssTheme.AUTOMATIC ||
  370. !Object.values(ViewerCssTheme).includes(cssTheme)
  371. ) {
  372. return;
  373. }
  374. try {
  375. const styleSheet = document.styleSheets[0];
  376. const cssRules = styleSheet?.cssRules || [];
  377. for (let i = 0, ii = cssRules.length; i < ii; i++) {
  378. const rule = cssRules[i];
  379. if (
  380. rule instanceof CSSMediaRule &&
  381. rule.media?.[0] === "(prefers-color-scheme: dark)"
  382. ) {
  383. if (cssTheme === ViewerCssTheme.LIGHT) {
  384. styleSheet.deleteRule(i);
  385. return;
  386. }
  387. const darkRules =
  388. /^@media \(prefers-color-scheme: dark\) {\n\s*([\w\s-.,:;/\\{}()]+)\n}$/.exec(
  389. rule.cssText
  390. );
  391. if (darkRules?.[1]) {
  392. styleSheet.deleteRule(i);
  393. styleSheet.insertRule(darkRules[1], i);
  394. }
  395. return;
  396. }
  397. }
  398. } catch (reason) {
  399. console.error(`_forceCssTheme: "${reason?.message}".`);
  400. }
  401. },
  402. async _initializeViewerComponents() {
  403. const { appConfig, externalServices } = this;
  404. const eventBus = externalServices.isInAutomation
  405. ? new _event_utils.AutomationEventBus()
  406. : new _event_utils.EventBus();
  407. this.eventBus = eventBus;
  408. this.overlayManager = new _overlay_manager.OverlayManager();
  409. const pdfRenderingQueue =
  410. new _pdf_rendering_queue.PDFRenderingQueue();
  411. pdfRenderingQueue.onIdle = this._cleanup.bind(this);
  412. this.pdfRenderingQueue = pdfRenderingQueue;
  413. const pdfLinkService = new _pdf_link_service.PDFLinkService({
  414. eventBus,
  415. externalLinkTarget:
  416. _app_options.AppOptions.get("externalLinkTarget"),
  417. externalLinkRel: _app_options.AppOptions.get("externalLinkRel"),
  418. ignoreDestinationZoom: _app_options.AppOptions.get(
  419. "ignoreDestinationZoom"
  420. ),
  421. });
  422. this.pdfLinkService = pdfLinkService;
  423. const downloadManager = externalServices.createDownloadManager();
  424. this.downloadManager = downloadManager;
  425. const findController = new _pdf_find_controller.PDFFindController({
  426. linkService: pdfLinkService,
  427. eventBus,
  428. updateMatchesCountOnProgress: true,
  429. });
  430. this.findController = findController;
  431. const pdfScriptingManager =
  432. new _pdf_scripting_manager.PDFScriptingManager({
  433. eventBus,
  434. sandboxBundleSrc: _app_options.AppOptions.get("sandboxBundleSrc"),
  435. scriptingFactory: externalServices,
  436. docPropertiesLookup: this._scriptingDocProperties.bind(this),
  437. });
  438. this.pdfScriptingManager = pdfScriptingManager;
  439. const container = appConfig.mainContainer,
  440. viewer = appConfig.viewerContainer;
  441. const annotationEditorMode = _app_options.AppOptions.get(
  442. "annotationEditorMode"
  443. );
  444. const pageColors =
  445. _app_options.AppOptions.get("forcePageColors") ||
  446. window.matchMedia("(forced-colors: active)").matches
  447. ? {
  448. background: _app_options.AppOptions.get(
  449. "pageColorsBackground"
  450. ),
  451. foreground: _app_options.AppOptions.get(
  452. "pageColorsForeground"
  453. ),
  454. }
  455. : null;
  456. this.pdfViewer = new _pdf_viewer.PDFViewer({
  457. container,
  458. viewer,
  459. eventBus,
  460. renderingQueue: pdfRenderingQueue,
  461. linkService: pdfLinkService,
  462. downloadManager,
  463. findController,
  464. scriptingManager:
  465. _app_options.AppOptions.get("enableScripting") &&
  466. pdfScriptingManager,
  467. renderer: _app_options.AppOptions.get("renderer"),
  468. l10n: this.l10n,
  469. textLayerMode: _app_options.AppOptions.get("textLayerMode"),
  470. annotationMode: _app_options.AppOptions.get("annotationMode"),
  471. annotationEditorMode,
  472. imageResourcesPath:
  473. _app_options.AppOptions.get("imageResourcesPath"),
  474. enablePrintAutoRotate: _app_options.AppOptions.get(
  475. "enablePrintAutoRotate"
  476. ),
  477. useOnlyCssZoom: _app_options.AppOptions.get("useOnlyCssZoom"),
  478. isOffscreenCanvasSupported: _app_options.AppOptions.get(
  479. "isOffscreenCanvasSupported"
  480. ),
  481. maxCanvasPixels: _app_options.AppOptions.get("maxCanvasPixels"),
  482. enablePermissions: _app_options.AppOptions.get("enablePermissions"),
  483. pageColors,
  484. });
  485. pdfRenderingQueue.setViewer(this.pdfViewer);
  486. pdfLinkService.setViewer(this.pdfViewer);
  487. pdfScriptingManager.setViewer(this.pdfViewer);
  488. if (appConfig.sidebar?.thumbnailView) {
  489. this.pdfThumbnailViewer =
  490. new _webPdf_thumbnail_viewer.PDFThumbnailViewer({
  491. container: appConfig.sidebar.thumbnailView,
  492. renderingQueue: pdfRenderingQueue,
  493. linkService: pdfLinkService,
  494. l10n: this.l10n,
  495. pageColors,
  496. });
  497. pdfRenderingQueue.setThumbnailViewer(this.pdfThumbnailViewer);
  498. }
  499. if (
  500. !this.isViewerEmbedded &&
  501. !_app_options.AppOptions.get("disableHistory")
  502. ) {
  503. this.pdfHistory = new _pdf_history.PDFHistory({
  504. linkService: pdfLinkService,
  505. eventBus,
  506. });
  507. pdfLinkService.setHistory(this.pdfHistory);
  508. }
  509. if (!this.supportsIntegratedFind && appConfig.findBar) {
  510. this.findBar = new _webPdf_find_bar.PDFFindBar(
  511. appConfig.findBar,
  512. eventBus,
  513. this.l10n
  514. );
  515. }
  516. if (appConfig.annotationEditorParams) {
  517. if (
  518. annotationEditorMode !== _pdfjsLib.AnnotationEditorType.DISABLE
  519. ) {
  520. this.annotationEditorParams =
  521. new _webAnnotation_editor_params.AnnotationEditorParams(
  522. appConfig.annotationEditorParams,
  523. eventBus
  524. );
  525. } else {
  526. for (const id of ["editorModeButtons", "editorModeSeparator"]) {
  527. document.getElementById(id)?.classList.add("hidden");
  528. }
  529. }
  530. }
  531. if (appConfig.documentProperties) {
  532. this.pdfDocumentProperties =
  533. new _webPdf_document_properties.PDFDocumentProperties(
  534. appConfig.documentProperties,
  535. this.overlayManager,
  536. eventBus,
  537. this.l10n,
  538. () => {
  539. return this._docFilename;
  540. }
  541. );
  542. }
  543. if (appConfig.secondaryToolbar?.cursorHandToolButton) {
  544. this.pdfCursorTools = new _webPdf_cursor_tools.PDFCursorTools({
  545. container,
  546. eventBus,
  547. cursorToolOnLoad: _app_options.AppOptions.get("cursorToolOnLoad"),
  548. });
  549. }
  550. if (appConfig.toolbar) {
  551. this.toolbar = new _webToolbar.Toolbar(
  552. appConfig.toolbar,
  553. eventBus,
  554. this.l10n
  555. );
  556. }
  557. if (appConfig.secondaryToolbar) {
  558. this.secondaryToolbar = new _webSecondary_toolbar.SecondaryToolbar(
  559. appConfig.secondaryToolbar,
  560. eventBus,
  561. this.externalServices
  562. );
  563. }
  564. if (
  565. this.supportsFullscreen &&
  566. appConfig.secondaryToolbar?.presentationModeButton
  567. ) {
  568. this.pdfPresentationMode =
  569. new _webPdf_presentation_mode.PDFPresentationMode({
  570. container,
  571. pdfViewer: this.pdfViewer,
  572. eventBus,
  573. });
  574. }
  575. if (appConfig.passwordOverlay) {
  576. this.passwordPrompt = new _password_prompt.PasswordPrompt(
  577. appConfig.passwordOverlay,
  578. this.overlayManager,
  579. this.l10n,
  580. this.isViewerEmbedded
  581. );
  582. }
  583. if (appConfig.sidebar?.outlineView) {
  584. this.pdfOutlineViewer = new _webPdf_outline_viewer.PDFOutlineViewer(
  585. {
  586. container: appConfig.sidebar.outlineView,
  587. eventBus,
  588. linkService: pdfLinkService,
  589. downloadManager,
  590. }
  591. );
  592. }
  593. if (appConfig.sidebar?.attachmentsView) {
  594. this.pdfAttachmentViewer =
  595. new _webPdf_attachment_viewer.PDFAttachmentViewer({
  596. container: appConfig.sidebar.attachmentsView,
  597. eventBus,
  598. downloadManager,
  599. });
  600. }
  601. if (appConfig.sidebar?.layersView) {
  602. this.pdfLayerViewer = new _webPdf_layer_viewer.PDFLayerViewer({
  603. container: appConfig.sidebar.layersView,
  604. eventBus,
  605. l10n: this.l10n,
  606. });
  607. }
  608. if (appConfig.sidebar) {
  609. this.pdfSidebar = new _webPdf_sidebar.PDFSidebar({
  610. elements: appConfig.sidebar,
  611. pdfViewer: this.pdfViewer,
  612. pdfThumbnailViewer: this.pdfThumbnailViewer,
  613. eventBus,
  614. l10n: this.l10n,
  615. });
  616. this.pdfSidebar.onToggled = this.forceRendering.bind(this);
  617. this.pdfSidebarResizer =
  618. new _webPdf_sidebar_resizer.PDFSidebarResizer(
  619. appConfig.sidebarResizer,
  620. eventBus,
  621. this.l10n
  622. );
  623. }
  624. },
  625. run(config) {
  626. this.initialize(config).then(webViewerInitialized);
  627. },
  628. get initialized() {
  629. return this._initializedCapability.settled;
  630. },
  631. get initializedPromise() {
  632. return this._initializedCapability.promise;
  633. },
  634. zoomIn(steps, scaleFactor) {
  635. if (this.pdfViewer.isInPresentationMode) {
  636. return;
  637. }
  638. this.pdfViewer.increaseScale({
  639. drawingDelay: _app_options.AppOptions.get("defaultZoomDelay"),
  640. steps,
  641. scaleFactor,
  642. });
  643. },
  644. zoomOut(steps, scaleFactor) {
  645. if (this.pdfViewer.isInPresentationMode) {
  646. return;
  647. }
  648. this.pdfViewer.decreaseScale({
  649. drawingDelay: _app_options.AppOptions.get("defaultZoomDelay"),
  650. steps,
  651. scaleFactor,
  652. });
  653. },
  654. zoomReset() {
  655. if (this.pdfViewer.isInPresentationMode) {
  656. return;
  657. }
  658. this.pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  659. },
  660. get pagesCount() {
  661. return this.pdfDocument ? this.pdfDocument.numPages : 0;
  662. },
  663. get page() {
  664. return this.pdfViewer.currentPageNumber;
  665. },
  666. set page(val) {
  667. this.pdfViewer.currentPageNumber = val;
  668. },
  669. get supportsPrinting() {
  670. return PDFPrintServiceFactory.instance.supportsPrinting;
  671. },
  672. get supportsFullscreen() {
  673. return (0, _pdfjsLib.shadow)(
  674. this,
  675. "supportsFullscreen",
  676. document.fullscreenEnabled
  677. );
  678. },
  679. get supportsPinchToZoom() {
  680. return this.externalServices.supportsPinchToZoom;
  681. },
  682. get supportsIntegratedFind() {
  683. return this.externalServices.supportsIntegratedFind;
  684. },
  685. get supportsDocumentFonts() {
  686. return this.externalServices.supportsDocumentFonts;
  687. },
  688. get loadingBar() {
  689. const barElement = document.getElementById("loadingBar");
  690. const bar = barElement ? new _ui_utils.ProgressBar(barElement) : null;
  691. return (0, _pdfjsLib.shadow)(this, "loadingBar", bar);
  692. },
  693. get supportedMouseWheelZoomModifierKeys() {
  694. return this.externalServices.supportedMouseWheelZoomModifierKeys;
  695. },
  696. initPassiveLoading() {
  697. throw new Error("Not implemented: initPassiveLoading");
  698. },
  699. setTitleUsingUrl(url = "", downloadUrl = null) {
  700. this.url = url;
  701. this.baseUrl = url.split("#")[0];
  702. if (downloadUrl) {
  703. this._downloadUrl =
  704. downloadUrl === url ? this.baseUrl : downloadUrl.split("#")[0];
  705. }
  706. if ((0, _pdfjsLib.isDataScheme)(url)) {
  707. this._hideViewBookmark();
  708. }
  709. let title = (0, _pdfjsLib.getPdfFilenameFromUrl)(url, "");
  710. if (!title) {
  711. try {
  712. title =
  713. decodeURIComponent((0, _pdfjsLib.getFilenameFromUrl)(url)) ||
  714. url;
  715. } catch (ex) {
  716. title = url;
  717. }
  718. }
  719. this.setTitle(title);
  720. },
  721. setTitle(title = this._title) {
  722. this._title = title;
  723. if (this.isViewerEmbedded) {
  724. return;
  725. }
  726. const editorIndicator =
  727. this._hasAnnotationEditors && !this.pdfRenderingQueue.printing;
  728. document.title = `${editorIndicator ? "* " : ""}${title}`;
  729. },
  730. get _docFilename() {
  731. return (
  732. this._contentDispositionFilename ||
  733. (0, _pdfjsLib.getPdfFilenameFromUrl)(this.url)
  734. );
  735. },
  736. _hideViewBookmark() {
  737. const { secondaryToolbar } = this.appConfig;
  738. secondaryToolbar?.viewBookmarkButton.classList.add("hidden");
  739. if (
  740. secondaryToolbar?.presentationModeButton.classList.contains(
  741. "hidden"
  742. )
  743. ) {
  744. document
  745. .getElementById("viewBookmarkSeparator")
  746. ?.classList.add("hidden");
  747. }
  748. },
  749. async close() {
  750. this._unblockDocumentLoadEvent();
  751. this._hideViewBookmark();
  752. if (!this.pdfLoadingTask) {
  753. return;
  754. }
  755. if (
  756. this.pdfDocument?.annotationStorage.size > 0 &&
  757. this._annotationStorageModified
  758. ) {
  759. try {
  760. await this.save();
  761. } catch (reason) {}
  762. }
  763. const promises = [];
  764. promises.push(this.pdfLoadingTask.destroy());
  765. this.pdfLoadingTask = null;
  766. if (this.pdfDocument) {
  767. this.pdfDocument = null;
  768. this.pdfThumbnailViewer?.setDocument(null);
  769. this.pdfViewer.setDocument(null);
  770. this.pdfLinkService.setDocument(null);
  771. this.pdfDocumentProperties?.setDocument(null);
  772. }
  773. this.pdfLinkService.externalLinkEnabled = true;
  774. this.store = null;
  775. this.isInitialViewSet = false;
  776. this.downloadComplete = false;
  777. this.url = "";
  778. this.baseUrl = "";
  779. this._downloadUrl = "";
  780. this.documentInfo = null;
  781. this.metadata = null;
  782. this._contentDispositionFilename = null;
  783. this._contentLength = null;
  784. this._saveInProgress = false;
  785. this._hasAnnotationEditors = false;
  786. promises.push(this.pdfScriptingManager.destroyPromise);
  787. this.setTitle();
  788. this.pdfSidebar?.reset();
  789. this.pdfOutlineViewer?.reset();
  790. this.pdfAttachmentViewer?.reset();
  791. this.pdfLayerViewer?.reset();
  792. this.pdfHistory?.reset();
  793. this.findBar?.reset();
  794. this.toolbar?.reset();
  795. this.secondaryToolbar?.reset();
  796. this._PDFBug?.cleanup();
  797. await Promise.all(promises);
  798. },
  799. async open(args) {
  800. let deprecatedArgs = false;
  801. if (typeof args === "string") {
  802. args = {
  803. url: args,
  804. };
  805. deprecatedArgs = true;
  806. } else if (args?.byteLength) {
  807. args = {
  808. data: args,
  809. };
  810. deprecatedArgs = true;
  811. }
  812. if (deprecatedArgs) {
  813. console.error(
  814. "The `PDFViewerApplication.open` signature was updated, please use an object instead."
  815. );
  816. }
  817. if (this.pdfLoadingTask) {
  818. await this.close();
  819. }
  820. const workerParams = _app_options.AppOptions.getAll(
  821. _app_options.OptionKind.WORKER
  822. );
  823. Object.assign(_pdfjsLib.GlobalWorkerOptions, workerParams);
  824. if (args.url) {
  825. this.setTitleUsingUrl(args.originalUrl || args.url, args.url);
  826. }
  827. const apiParams = _app_options.AppOptions.getAll(
  828. _app_options.OptionKind.API
  829. );
  830. const params = {
  831. canvasMaxAreaInBytes: this.externalServices.canvasMaxAreaInBytes,
  832. ...apiParams,
  833. ...args,
  834. };
  835. const loadingTask = (0, _pdfjsLib.getDocument)(params);
  836. this.pdfLoadingTask = loadingTask;
  837. loadingTask.onPassword = (updateCallback, reason) => {
  838. if (this.isViewerEmbedded) {
  839. this._unblockDocumentLoadEvent();
  840. }
  841. this.pdfLinkService.externalLinkEnabled = false;
  842. this.passwordPrompt.setUpdateCallback(updateCallback, reason);
  843. this.passwordPrompt.open();
  844. };
  845. loadingTask.onProgress = ({ loaded, total }) => {
  846. this.progress(loaded / total);
  847. };
  848. return loadingTask.promise.then(
  849. (pdfDocument) => {
  850. this.load(pdfDocument);
  851. },
  852. (reason) => {
  853. if (loadingTask !== this.pdfLoadingTask) {
  854. return undefined;
  855. }
  856. let key = "loading_error";
  857. if (reason instanceof _pdfjsLib.InvalidPDFException) {
  858. key = "invalid_file_error";
  859. } else if (reason instanceof _pdfjsLib.MissingPDFException) {
  860. key = "missing_file_error";
  861. } else if (
  862. reason instanceof _pdfjsLib.UnexpectedResponseException
  863. ) {
  864. key = "unexpected_response_error";
  865. }
  866. return this.l10n.get(key).then((msg) => {
  867. this._documentError(msg, {
  868. message: reason?.message,
  869. });
  870. throw reason;
  871. });
  872. }
  873. );
  874. },
  875. _ensureDownloadComplete() {
  876. if (this.pdfDocument && this.downloadComplete) {
  877. return;
  878. }
  879. throw new Error("PDF document not downloaded.");
  880. },
  881. async download() {
  882. const url = this._downloadUrl,
  883. filename = this._docFilename;
  884. try {
  885. this._ensureDownloadComplete();
  886. const data = await this.pdfDocument.getData();
  887. const blob = new Blob([data], {
  888. type: "application/pdf",
  889. });
  890. await this.downloadManager.download(blob, url, filename);
  891. } catch (reason) {
  892. await this.downloadManager.downloadUrl(url, filename);
  893. }
  894. },
  895. async save() {
  896. if (this._saveInProgress) {
  897. return;
  898. }
  899. this._saveInProgress = true;
  900. await this.pdfScriptingManager.dispatchWillSave();
  901. const url = this._downloadUrl,
  902. filename = this._docFilename;
  903. try {
  904. this._ensureDownloadComplete();
  905. const data = await this.pdfDocument.saveDocument();
  906. const blob = new Blob([data], {
  907. type: "application/pdf",
  908. });
  909. await this.downloadManager.download(blob, url, filename);
  910. } catch (reason) {
  911. console.error(`Error when saving the document: ${reason.message}`);
  912. await this.download();
  913. } finally {
  914. await this.pdfScriptingManager.dispatchDidSave();
  915. this._saveInProgress = false;
  916. }
  917. if (this._hasAnnotationEditors) {
  918. this.externalServices.reportTelemetry({
  919. type: "editing",
  920. data: {
  921. type: "save",
  922. },
  923. });
  924. }
  925. },
  926. downloadOrSave() {
  927. if (this.pdfDocument?.annotationStorage.size > 0) {
  928. this.save();
  929. } else {
  930. this.download();
  931. }
  932. },
  933. _documentError(message, moreInfo = null) {
  934. this._unblockDocumentLoadEvent();
  935. this._otherError(message, moreInfo);
  936. this.eventBus.dispatch("documenterror", {
  937. source: this,
  938. message,
  939. reason: moreInfo?.message ?? null,
  940. });
  941. },
  942. _otherError(message, moreInfo = null) {
  943. const moreInfoText = [
  944. `PDF.js v${_pdfjsLib.version || "?"} (build: ${
  945. _pdfjsLib.build || "?"
  946. })`,
  947. ];
  948. if (moreInfo) {
  949. moreInfoText.push(`Message: ${moreInfo.message}`);
  950. if (moreInfo.stack) {
  951. moreInfoText.push(`Stack: ${moreInfo.stack}`);
  952. } else {
  953. if (moreInfo.filename) {
  954. moreInfoText.push(`File: ${moreInfo.filename}`);
  955. }
  956. if (moreInfo.lineNumber) {
  957. moreInfoText.push(`Line: ${moreInfo.lineNumber}`);
  958. }
  959. }
  960. }
  961. console.error(`${message}\n\n${moreInfoText.join("\n")}`);
  962. },
  963. progress(level) {
  964. if (!this.loadingBar || this.downloadComplete) {
  965. return;
  966. }
  967. const percent = Math.round(level * 100);
  968. if (percent <= this.loadingBar.percent) {
  969. return;
  970. }
  971. this.loadingBar.percent = percent;
  972. if (
  973. this.pdfDocument?.loadingParams.disableAutoFetch ??
  974. _app_options.AppOptions.get("disableAutoFetch")
  975. ) {
  976. this.loadingBar.setDisableAutoFetch();
  977. }
  978. },
  979. load(pdfDocument) {
  980. this.pdfDocument = pdfDocument;
  981. pdfDocument.getDownloadInfo().then(({ length }) => {
  982. this._contentLength = length;
  983. this.downloadComplete = true;
  984. this.loadingBar?.hide();
  985. firstPagePromise.then(() => {
  986. this.eventBus.dispatch("documentloaded", {
  987. source: this,
  988. });
  989. });
  990. });
  991. const pageLayoutPromise = pdfDocument
  992. .getPageLayout()
  993. .catch(function () {});
  994. const pageModePromise = pdfDocument
  995. .getPageMode()
  996. .catch(function () {});
  997. const openActionPromise = pdfDocument
  998. .getOpenAction()
  999. .catch(function () {});
  1000. this.toolbar?.setPagesCount(pdfDocument.numPages, false);
  1001. this.secondaryToolbar?.setPagesCount(pdfDocument.numPages);
  1002. this.pdfLinkService.setDocument(pdfDocument);
  1003. this.pdfDocumentProperties?.setDocument(pdfDocument);
  1004. const pdfViewer = this.pdfViewer;
  1005. pdfViewer.setDocument(pdfDocument);
  1006. const { firstPagePromise, onePageRendered, pagesPromise } = pdfViewer;
  1007. this.pdfThumbnailViewer?.setDocument(pdfDocument);
  1008. const storedPromise = (this.store = new _view_history.ViewHistory(
  1009. pdfDocument.fingerprints[0]
  1010. ))
  1011. .getMultiple({
  1012. page: null,
  1013. zoom: _ui_utils.DEFAULT_SCALE_VALUE,
  1014. scrollLeft: "0",
  1015. scrollTop: "0",
  1016. rotation: null,
  1017. sidebarView: _ui_utils.SidebarView.UNKNOWN,
  1018. scrollMode: _ui_utils.ScrollMode.UNKNOWN,
  1019. spreadMode: _ui_utils.SpreadMode.UNKNOWN,
  1020. })
  1021. .catch(() => {
  1022. return Object.create(null);
  1023. });
  1024. firstPagePromise.then((pdfPage) => {
  1025. this.loadingBar?.setWidth(this.appConfig.viewerContainer);
  1026. this._initializeAnnotationStorageCallbacks(pdfDocument);
  1027. Promise.all([
  1028. _ui_utils.animationStarted,
  1029. storedPromise,
  1030. pageLayoutPromise,
  1031. pageModePromise,
  1032. openActionPromise,
  1033. ])
  1034. .then(
  1035. async ([
  1036. timeStamp,
  1037. stored,
  1038. pageLayout,
  1039. pageMode,
  1040. openAction,
  1041. ]) => {
  1042. const viewOnLoad = _app_options.AppOptions.get("viewOnLoad");
  1043. this._initializePdfHistory({
  1044. fingerprint: pdfDocument.fingerprints[0],
  1045. viewOnLoad,
  1046. initialDest: openAction?.dest,
  1047. });
  1048. const initialBookmark = this.initialBookmark;
  1049. const zoom = _app_options.AppOptions.get("defaultZoomValue");
  1050. let hash = zoom ? `zoom=${zoom}` : null;
  1051. let rotation = null;
  1052. let sidebarView =
  1053. _app_options.AppOptions.get("sidebarViewOnLoad");
  1054. let scrollMode =
  1055. _app_options.AppOptions.get("scrollModeOnLoad");
  1056. let spreadMode =
  1057. _app_options.AppOptions.get("spreadModeOnLoad");
  1058. if (stored.page && viewOnLoad !== ViewOnLoad.INITIAL) {
  1059. hash =
  1060. `page=${stored.page}&zoom=${zoom || stored.zoom},` +
  1061. `${stored.scrollLeft},${stored.scrollTop}`;
  1062. rotation = parseInt(stored.rotation, 10);
  1063. if (sidebarView === _ui_utils.SidebarView.UNKNOWN) {
  1064. sidebarView = stored.sidebarView | 0;
  1065. }
  1066. if (scrollMode === _ui_utils.ScrollMode.UNKNOWN) {
  1067. scrollMode = stored.scrollMode | 0;
  1068. }
  1069. if (spreadMode === _ui_utils.SpreadMode.UNKNOWN) {
  1070. spreadMode = stored.spreadMode | 0;
  1071. }
  1072. }
  1073. if (
  1074. pageMode &&
  1075. sidebarView === _ui_utils.SidebarView.UNKNOWN
  1076. ) {
  1077. sidebarView = (0, _ui_utils.apiPageModeToSidebarView)(
  1078. pageMode
  1079. );
  1080. }
  1081. if (
  1082. pageLayout &&
  1083. scrollMode === _ui_utils.ScrollMode.UNKNOWN &&
  1084. spreadMode === _ui_utils.SpreadMode.UNKNOWN
  1085. ) {
  1086. const modes = (0, _ui_utils.apiPageLayoutToViewerModes)(
  1087. pageLayout
  1088. );
  1089. spreadMode = modes.spreadMode;
  1090. }
  1091. this.setInitialView(hash, {
  1092. rotation,
  1093. sidebarView,
  1094. scrollMode,
  1095. spreadMode,
  1096. });
  1097. this.eventBus.dispatch("documentinit", {
  1098. source: this,
  1099. });
  1100. if (!this.isViewerEmbedded) {
  1101. pdfViewer.focus();
  1102. }
  1103. await Promise.race([
  1104. pagesPromise,
  1105. new Promise((resolve) => {
  1106. setTimeout(resolve, FORCE_PAGES_LOADED_TIMEOUT);
  1107. }),
  1108. ]);
  1109. if (!initialBookmark && !hash) {
  1110. return;
  1111. }
  1112. if (pdfViewer.hasEqualPageSizes) {
  1113. return;
  1114. }
  1115. this.initialBookmark = initialBookmark;
  1116. pdfViewer.currentScaleValue = pdfViewer.currentScaleValue;
  1117. this.setInitialView(hash);
  1118. }
  1119. )
  1120. .catch(() => {
  1121. this.setInitialView();
  1122. })
  1123. .then(function () {
  1124. pdfViewer.update();
  1125. });
  1126. });
  1127. pagesPromise.then(
  1128. () => {
  1129. this._unblockDocumentLoadEvent();
  1130. this._initializeAutoPrint(pdfDocument, openActionPromise);
  1131. },
  1132. (reason) => {
  1133. this.l10n.get("loading_error").then((msg) => {
  1134. this._documentError(msg, {
  1135. message: reason?.message,
  1136. });
  1137. });
  1138. }
  1139. );
  1140. onePageRendered.then((data) => {
  1141. this.externalServices.reportTelemetry({
  1142. type: "pageInfo",
  1143. timestamp: data.timestamp,
  1144. });
  1145. if (this.pdfOutlineViewer) {
  1146. pdfDocument.getOutline().then((outline) => {
  1147. if (pdfDocument !== this.pdfDocument) {
  1148. return;
  1149. }
  1150. this.pdfOutlineViewer.render({
  1151. outline,
  1152. pdfDocument,
  1153. });
  1154. });
  1155. }
  1156. if (this.pdfAttachmentViewer) {
  1157. pdfDocument.getAttachments().then((attachments) => {
  1158. if (pdfDocument !== this.pdfDocument) {
  1159. return;
  1160. }
  1161. this.pdfAttachmentViewer.render({
  1162. attachments,
  1163. });
  1164. });
  1165. }
  1166. if (this.pdfLayerViewer) {
  1167. pdfViewer.optionalContentConfigPromise.then(
  1168. (optionalContentConfig) => {
  1169. if (pdfDocument !== this.pdfDocument) {
  1170. return;
  1171. }
  1172. this.pdfLayerViewer.render({
  1173. optionalContentConfig,
  1174. pdfDocument,
  1175. });
  1176. }
  1177. );
  1178. }
  1179. });
  1180. this._initializePageLabels(pdfDocument);
  1181. this._initializeMetadata(pdfDocument);
  1182. },
  1183. async _scriptingDocProperties(pdfDocument) {
  1184. if (!this.documentInfo) {
  1185. await new Promise((resolve) => {
  1186. this.eventBus._on("metadataloaded", resolve, {
  1187. once: true,
  1188. });
  1189. });
  1190. if (pdfDocument !== this.pdfDocument) {
  1191. return null;
  1192. }
  1193. }
  1194. if (!this._contentLength) {
  1195. await new Promise((resolve) => {
  1196. this.eventBus._on("documentloaded", resolve, {
  1197. once: true,
  1198. });
  1199. });
  1200. if (pdfDocument !== this.pdfDocument) {
  1201. return null;
  1202. }
  1203. }
  1204. return {
  1205. ...this.documentInfo,
  1206. baseURL: this.baseUrl,
  1207. filesize: this._contentLength,
  1208. filename: this._docFilename,
  1209. metadata: this.metadata?.getRaw(),
  1210. authors: this.metadata?.get("dc:creator"),
  1211. numPages: this.pagesCount,
  1212. URL: this.url,
  1213. };
  1214. },
  1215. async _initializeAutoPrint(pdfDocument, openActionPromise) {
  1216. const [openAction, javaScript] = await Promise.all([
  1217. openActionPromise,
  1218. !this.pdfViewer.enableScripting
  1219. ? pdfDocument.getJavaScript()
  1220. : null,
  1221. ]);
  1222. if (pdfDocument !== this.pdfDocument) {
  1223. return;
  1224. }
  1225. let triggerAutoPrint = false;
  1226. if (openAction?.action === "Print") {
  1227. triggerAutoPrint = true;
  1228. }
  1229. if (javaScript) {
  1230. javaScript.some((js) => {
  1231. if (!js) {
  1232. return false;
  1233. }
  1234. console.warn("Warning: JavaScript support is not enabled");
  1235. return true;
  1236. });
  1237. if (!triggerAutoPrint) {
  1238. for (const js of javaScript) {
  1239. if (js && _ui_utils.AutoPrintRegExp.test(js)) {
  1240. triggerAutoPrint = true;
  1241. break;
  1242. }
  1243. }
  1244. }
  1245. }
  1246. if (triggerAutoPrint) {
  1247. this.triggerPrinting();
  1248. }
  1249. },
  1250. async _initializeMetadata(pdfDocument) {
  1251. const { info, metadata, contentDispositionFilename, contentLength } =
  1252. await pdfDocument.getMetadata();
  1253. if (pdfDocument !== this.pdfDocument) {
  1254. return;
  1255. }
  1256. this.documentInfo = info;
  1257. this.metadata = metadata;
  1258. this._contentDispositionFilename ??= contentDispositionFilename;
  1259. this._contentLength ??= contentLength;
  1260. console.log(
  1261. `PDF ${pdfDocument.fingerprints[0]} [${info.PDFFormatVersion} ` +
  1262. `${(info.Producer || "-").trim()} / ${(
  1263. info.Creator || "-"
  1264. ).trim()}] ` +
  1265. `(PDF.js: ${_pdfjsLib.version || "?"} [${
  1266. _pdfjsLib.build || "?"
  1267. }])`
  1268. );
  1269. let pdfTitle = info.Title;
  1270. const metadataTitle = metadata?.get("dc:title");
  1271. if (metadataTitle) {
  1272. if (
  1273. metadataTitle !== "Untitled" &&
  1274. !/[\uFFF0-\uFFFF]/g.test(metadataTitle)
  1275. ) {
  1276. pdfTitle = metadataTitle;
  1277. }
  1278. }
  1279. if (pdfTitle) {
  1280. this.setTitle(
  1281. `${pdfTitle} - ${this._contentDispositionFilename || this._title}`
  1282. );
  1283. } else if (this._contentDispositionFilename) {
  1284. this.setTitle(this._contentDispositionFilename);
  1285. }
  1286. if (
  1287. info.IsXFAPresent &&
  1288. !info.IsAcroFormPresent &&
  1289. !pdfDocument.isPureXfa
  1290. ) {
  1291. if (pdfDocument.loadingParams.enableXfa) {
  1292. console.warn(
  1293. "Warning: XFA Foreground documents are not supported"
  1294. );
  1295. } else {
  1296. console.warn("Warning: XFA support is not enabled");
  1297. }
  1298. } else if (
  1299. (info.IsAcroFormPresent || info.IsXFAPresent) &&
  1300. !this.pdfViewer.renderForms
  1301. ) {
  1302. console.warn("Warning: Interactive form support is not enabled");
  1303. }
  1304. if (info.IsSignaturesPresent) {
  1305. console.warn(
  1306. "Warning: Digital signatures validation is not supported"
  1307. );
  1308. }
  1309. this.eventBus.dispatch("metadataloaded", {
  1310. source: this,
  1311. });
  1312. },
  1313. async _initializePageLabels(pdfDocument) {
  1314. const labels = await pdfDocument.getPageLabels();
  1315. if (pdfDocument !== this.pdfDocument) {
  1316. return;
  1317. }
  1318. if (!labels || _app_options.AppOptions.get("disablePageLabels")) {
  1319. return;
  1320. }
  1321. const numLabels = labels.length;
  1322. let standardLabels = 0,
  1323. emptyLabels = 0;
  1324. for (let i = 0; i < numLabels; i++) {
  1325. const label = labels[i];
  1326. if (label === (i + 1).toString()) {
  1327. standardLabels++;
  1328. } else if (label === "") {
  1329. emptyLabels++;
  1330. } else {
  1331. break;
  1332. }
  1333. }
  1334. if (standardLabels >= numLabels || emptyLabels >= numLabels) {
  1335. return;
  1336. }
  1337. const { pdfViewer, pdfThumbnailViewer, toolbar } = this;
  1338. pdfViewer.setPageLabels(labels);
  1339. pdfThumbnailViewer?.setPageLabels(labels);
  1340. toolbar?.setPagesCount(numLabels, true);
  1341. toolbar?.setPageNumber(
  1342. pdfViewer.currentPageNumber,
  1343. pdfViewer.currentPageLabel
  1344. );
  1345. },
  1346. _initializePdfHistory({ fingerprint, viewOnLoad, initialDest = null }) {
  1347. if (!this.pdfHistory) {
  1348. return;
  1349. }
  1350. this.pdfHistory.initialize({
  1351. fingerprint,
  1352. resetHistory: viewOnLoad === ViewOnLoad.INITIAL,
  1353. updateUrl: _app_options.AppOptions.get("historyUpdateUrl"),
  1354. });
  1355. if (this.pdfHistory.initialBookmark) {
  1356. this.initialBookmark = this.pdfHistory.initialBookmark;
  1357. this.initialRotation = this.pdfHistory.initialRotation;
  1358. }
  1359. if (
  1360. initialDest &&
  1361. !this.initialBookmark &&
  1362. viewOnLoad === ViewOnLoad.UNKNOWN
  1363. ) {
  1364. this.initialBookmark = JSON.stringify(initialDest);
  1365. this.pdfHistory.push({
  1366. explicitDest: initialDest,
  1367. pageNumber: null,
  1368. });
  1369. }
  1370. },
  1371. _initializeAnnotationStorageCallbacks(pdfDocument) {
  1372. if (pdfDocument !== this.pdfDocument) {
  1373. return;
  1374. }
  1375. const { annotationStorage } = pdfDocument;
  1376. annotationStorage.onSetModified = () => {
  1377. window.addEventListener("beforeunload", beforeUnload);
  1378. this._annotationStorageModified = true;
  1379. };
  1380. annotationStorage.onResetModified = () => {
  1381. window.removeEventListener("beforeunload", beforeUnload);
  1382. delete this._annotationStorageModified;
  1383. };
  1384. annotationStorage.onAnnotationEditor = (typeStr) => {
  1385. this._hasAnnotationEditors = !!typeStr;
  1386. this.setTitle();
  1387. if (typeStr) {
  1388. this.externalServices.reportTelemetry({
  1389. type: "editing",
  1390. data: {
  1391. type: typeStr,
  1392. },
  1393. });
  1394. }
  1395. };
  1396. },
  1397. setInitialView(
  1398. storedHash,
  1399. { rotation, sidebarView, scrollMode, spreadMode } = {}
  1400. ) {
  1401. const setRotation = (angle) => {
  1402. if ((0, _ui_utils.isValidRotation)(angle)) {
  1403. this.pdfViewer.pagesRotation = angle;
  1404. }
  1405. };
  1406. const setViewerModes = (scroll, spread) => {
  1407. if ((0, _ui_utils.isValidScrollMode)(scroll)) {
  1408. this.pdfViewer.scrollMode = scroll;
  1409. }
  1410. if ((0, _ui_utils.isValidSpreadMode)(spread)) {
  1411. this.pdfViewer.spreadMode = spread;
  1412. }
  1413. };
  1414. this.isInitialViewSet = true;
  1415. this.pdfSidebar?.setInitialView(sidebarView);
  1416. setViewerModes(scrollMode, spreadMode);
  1417. if (this.initialBookmark) {
  1418. setRotation(this.initialRotation);
  1419. delete this.initialRotation;
  1420. this.pdfLinkService.setHash(this.initialBookmark);
  1421. this.initialBookmark = null;
  1422. } else if (storedHash) {
  1423. setRotation(rotation);
  1424. this.pdfLinkService.setHash(storedHash);
  1425. }
  1426. this.toolbar?.setPageNumber(
  1427. this.pdfViewer.currentPageNumber,
  1428. this.pdfViewer.currentPageLabel
  1429. );
  1430. this.secondaryToolbar?.setPageNumber(
  1431. this.pdfViewer.currentPageNumber
  1432. );
  1433. if (!this.pdfViewer.currentScaleValue) {
  1434. this.pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  1435. }
  1436. },
  1437. _cleanup() {
  1438. if (!this.pdfDocument) {
  1439. return;
  1440. }
  1441. this.pdfViewer.cleanup();
  1442. this.pdfThumbnailViewer?.cleanup();
  1443. this.pdfDocument.cleanup(
  1444. this.pdfViewer.renderer === _ui_utils.RendererType.SVG
  1445. );
  1446. },
  1447. forceRendering() {
  1448. this.pdfRenderingQueue.printing = !!this.printService;
  1449. this.pdfRenderingQueue.isThumbnailViewEnabled =
  1450. this.pdfSidebar?.visibleView === _ui_utils.SidebarView.THUMBS;
  1451. this.pdfRenderingQueue.renderHighestPriority();
  1452. },
  1453. beforePrint() {
  1454. this._printAnnotationStoragePromise = this.pdfScriptingManager
  1455. .dispatchWillPrint()
  1456. .catch(() => {})
  1457. .then(() => {
  1458. return this.pdfDocument?.annotationStorage.print;
  1459. });
  1460. if (this.printService) {
  1461. return;
  1462. }
  1463. if (!this.supportsPrinting) {
  1464. this.l10n.get("printing_not_supported").then((msg) => {
  1465. this._otherError(msg);
  1466. });
  1467. return;
  1468. }
  1469. if (!this.pdfViewer.pageViewsReady) {
  1470. this.l10n.get("printing_not_ready").then((msg) => {
  1471. window.alert(msg);
  1472. });
  1473. return;
  1474. }
  1475. const pagesOverview = this.pdfViewer.getPagesOverview();
  1476. const printContainer = this.appConfig.printContainer;
  1477. const printResolution =
  1478. _app_options.AppOptions.get("printResolution");
  1479. const optionalContentConfigPromise =
  1480. this.pdfViewer.optionalContentConfigPromise;
  1481. const printService =
  1482. PDFPrintServiceFactory.instance.createPrintService(
  1483. this.pdfDocument,
  1484. pagesOverview,
  1485. printContainer,
  1486. printResolution,
  1487. optionalContentConfigPromise,
  1488. this._printAnnotationStoragePromise,
  1489. this.l10n
  1490. );
  1491. this.printService = printService;
  1492. this.forceRendering();
  1493. this.setTitle();
  1494. printService.layout();
  1495. if (this._hasAnnotationEditors) {
  1496. this.externalServices.reportTelemetry({
  1497. type: "editing",
  1498. data: {
  1499. type: "print",
  1500. },
  1501. });
  1502. }
  1503. },
  1504. afterPrint() {
  1505. if (this._printAnnotationStoragePromise) {
  1506. this._printAnnotationStoragePromise.then(() => {
  1507. this.pdfScriptingManager.dispatchDidPrint();
  1508. });
  1509. this._printAnnotationStoragePromise = null;
  1510. }
  1511. if (this.printService) {
  1512. this.printService.destroy();
  1513. this.printService = null;
  1514. this.pdfDocument?.annotationStorage.resetModified();
  1515. }
  1516. this.forceRendering();
  1517. this.setTitle();
  1518. },
  1519. rotatePages(delta) {
  1520. this.pdfViewer.pagesRotation += delta;
  1521. },
  1522. requestPresentationMode() {
  1523. this.pdfPresentationMode?.request();
  1524. },
  1525. triggerPrinting() {
  1526. if (!this.supportsPrinting) {
  1527. return;
  1528. }
  1529. window.print();
  1530. },
  1531. bindEvents() {
  1532. const { eventBus, _boundEvents } = this;
  1533. _boundEvents.beforePrint = this.beforePrint.bind(this);
  1534. _boundEvents.afterPrint = this.afterPrint.bind(this);
  1535. eventBus._on("resize", webViewerResize);
  1536. eventBus._on("hashchange", webViewerHashchange);
  1537. eventBus._on("beforeprint", _boundEvents.beforePrint);
  1538. eventBus._on("afterprint", _boundEvents.afterPrint);
  1539. eventBus._on("pagerender", webViewerPageRender);
  1540. eventBus._on("pagerendered", webViewerPageRendered);
  1541. eventBus._on("updateviewarea", webViewerUpdateViewarea);
  1542. eventBus._on("pagechanging", webViewerPageChanging);
  1543. eventBus._on("scalechanging", webViewerScaleChanging);
  1544. eventBus._on("rotationchanging", webViewerRotationChanging);
  1545. eventBus._on("sidebarviewchanged", webViewerSidebarViewChanged);
  1546. eventBus._on("pagemode", webViewerPageMode);
  1547. eventBus._on("namedaction", webViewerNamedAction);
  1548. eventBus._on(
  1549. "presentationmodechanged",
  1550. webViewerPresentationModeChanged
  1551. );
  1552. eventBus._on("presentationmode", webViewerPresentationMode);
  1553. eventBus._on(
  1554. "switchannotationeditormode",
  1555. webViewerSwitchAnnotationEditorMode
  1556. );
  1557. eventBus._on(
  1558. "switchannotationeditorparams",
  1559. webViewerSwitchAnnotationEditorParams
  1560. );
  1561. eventBus._on("print", webViewerPrint);
  1562. eventBus._on("download", webViewerDownload);
  1563. eventBus._on("firstpage", webViewerFirstPage);
  1564. eventBus._on("lastpage", webViewerLastPage);
  1565. eventBus._on("nextpage", webViewerNextPage);
  1566. eventBus._on("previouspage", webViewerPreviousPage);
  1567. eventBus._on("zoomin", webViewerZoomIn);
  1568. eventBus._on("zoomout", webViewerZoomOut);
  1569. eventBus._on("zoomreset", webViewerZoomReset);
  1570. eventBus._on("pagenumberchanged", webViewerPageNumberChanged);
  1571. eventBus._on("scalechanged", webViewerScaleChanged);
  1572. eventBus._on("rotatecw", webViewerRotateCw);
  1573. eventBus._on("rotateccw", webViewerRotateCcw);
  1574. eventBus._on("optionalcontentconfig", webViewerOptionalContentConfig);
  1575. eventBus._on("switchscrollmode", webViewerSwitchScrollMode);
  1576. eventBus._on("scrollmodechanged", webViewerScrollModeChanged);
  1577. eventBus._on("switchspreadmode", webViewerSwitchSpreadMode);
  1578. eventBus._on("spreadmodechanged", webViewerSpreadModeChanged);
  1579. eventBus._on("documentproperties", webViewerDocumentProperties);
  1580. eventBus._on("findfromurlhash", webViewerFindFromUrlHash);
  1581. eventBus._on(
  1582. "updatefindmatchescount",
  1583. webViewerUpdateFindMatchesCount
  1584. );
  1585. eventBus._on(
  1586. "updatefindcontrolstate",
  1587. webViewerUpdateFindControlState
  1588. );
  1589. if (_app_options.AppOptions.get("pdfBug")) {
  1590. _boundEvents.reportPageStatsPDFBug = reportPageStatsPDFBug;
  1591. eventBus._on("pagerendered", _boundEvents.reportPageStatsPDFBug);
  1592. eventBus._on("pagechanging", _boundEvents.reportPageStatsPDFBug);
  1593. }
  1594. eventBus._on("fileinputchange", webViewerFileInputChange);
  1595. eventBus._on("openfile", webViewerOpenFile);
  1596. },
  1597. bindWindowEvents() {
  1598. const { eventBus, _boundEvents } = this;
  1599. function addWindowResolutionChange(evt = null) {
  1600. if (evt) {
  1601. webViewerResolutionChange(evt);
  1602. }
  1603. const mediaQueryList = window.matchMedia(
  1604. `(resolution: ${window.devicePixelRatio || 1}dppx)`
  1605. );
  1606. mediaQueryList.addEventListener(
  1607. "change",
  1608. addWindowResolutionChange,
  1609. {
  1610. once: true,
  1611. }
  1612. );
  1613. _boundEvents.removeWindowResolutionChange ||= function () {
  1614. mediaQueryList.removeEventListener(
  1615. "change",
  1616. addWindowResolutionChange
  1617. );
  1618. _boundEvents.removeWindowResolutionChange = null;
  1619. };
  1620. }
  1621. addWindowResolutionChange();
  1622. _boundEvents.windowResize = () => {
  1623. eventBus.dispatch("resize", {
  1624. source: window,
  1625. });
  1626. };
  1627. _boundEvents.windowHashChange = () => {
  1628. eventBus.dispatch("hashchange", {
  1629. source: window,
  1630. hash: document.location.hash.substring(1),
  1631. });
  1632. };
  1633. _boundEvents.windowBeforePrint = () => {
  1634. eventBus.dispatch("beforeprint", {
  1635. source: window,
  1636. });
  1637. };
  1638. _boundEvents.windowAfterPrint = () => {
  1639. eventBus.dispatch("afterprint", {
  1640. source: window,
  1641. });
  1642. };
  1643. _boundEvents.windowUpdateFromSandbox = (event) => {
  1644. eventBus.dispatch("updatefromsandbox", {
  1645. source: window,
  1646. detail: event.detail,
  1647. });
  1648. };
  1649. window.addEventListener(
  1650. "visibilitychange",
  1651. webViewerVisibilityChange
  1652. );
  1653. window.addEventListener("wheel", webViewerWheel, {
  1654. passive: false,
  1655. });
  1656. window.addEventListener("touchstart", webViewerTouchStart, {
  1657. passive: false,
  1658. });
  1659. window.addEventListener("touchmove", webViewerTouchMove, {
  1660. passive: false,
  1661. });
  1662. window.addEventListener("touchend", webViewerTouchEnd, {
  1663. passive: false,
  1664. });
  1665. window.addEventListener("click", webViewerClick);
  1666. window.addEventListener("keydown", webViewerKeyDown);
  1667. window.addEventListener("keyup", webViewerKeyUp);
  1668. window.addEventListener("resize", _boundEvents.windowResize);
  1669. window.addEventListener("hashchange", _boundEvents.windowHashChange);
  1670. window.addEventListener(
  1671. "beforeprint",
  1672. _boundEvents.windowBeforePrint
  1673. );
  1674. window.addEventListener("afterprint", _boundEvents.windowAfterPrint);
  1675. window.addEventListener(
  1676. "updatefromsandbox",
  1677. _boundEvents.windowUpdateFromSandbox
  1678. );
  1679. },
  1680. unbindEvents() {
  1681. const { eventBus, _boundEvents } = this;
  1682. eventBus._off("resize", webViewerResize);
  1683. eventBus._off("hashchange", webViewerHashchange);
  1684. eventBus._off("beforeprint", _boundEvents.beforePrint);
  1685. eventBus._off("afterprint", _boundEvents.afterPrint);
  1686. eventBus._off("pagerender", webViewerPageRender);
  1687. eventBus._off("pagerendered", webViewerPageRendered);
  1688. eventBus._off("updateviewarea", webViewerUpdateViewarea);
  1689. eventBus._off("pagechanging", webViewerPageChanging);
  1690. eventBus._off("scalechanging", webViewerScaleChanging);
  1691. eventBus._off("rotationchanging", webViewerRotationChanging);
  1692. eventBus._off("sidebarviewchanged", webViewerSidebarViewChanged);
  1693. eventBus._off("pagemode", webViewerPageMode);
  1694. eventBus._off("namedaction", webViewerNamedAction);
  1695. eventBus._off(
  1696. "presentationmodechanged",
  1697. webViewerPresentationModeChanged
  1698. );
  1699. eventBus._off("presentationmode", webViewerPresentationMode);
  1700. eventBus._off("print", webViewerPrint);
  1701. eventBus._off("download", webViewerDownload);
  1702. eventBus._off("firstpage", webViewerFirstPage);
  1703. eventBus._off("lastpage", webViewerLastPage);
  1704. eventBus._off("nextpage", webViewerNextPage);
  1705. eventBus._off("previouspage", webViewerPreviousPage);
  1706. eventBus._off("zoomin", webViewerZoomIn);
  1707. eventBus._off("zoomout", webViewerZoomOut);
  1708. eventBus._off("zoomreset", webViewerZoomReset);
  1709. eventBus._off("pagenumberchanged", webViewerPageNumberChanged);
  1710. eventBus._off("scalechanged", webViewerScaleChanged);
  1711. eventBus._off("rotatecw", webViewerRotateCw);
  1712. eventBus._off("rotateccw", webViewerRotateCcw);
  1713. eventBus._off(
  1714. "optionalcontentconfig",
  1715. webViewerOptionalContentConfig
  1716. );
  1717. eventBus._off("switchscrollmode", webViewerSwitchScrollMode);
  1718. eventBus._off("scrollmodechanged", webViewerScrollModeChanged);
  1719. eventBus._off("switchspreadmode", webViewerSwitchSpreadMode);
  1720. eventBus._off("spreadmodechanged", webViewerSpreadModeChanged);
  1721. eventBus._off("documentproperties", webViewerDocumentProperties);
  1722. eventBus._off("findfromurlhash", webViewerFindFromUrlHash);
  1723. eventBus._off(
  1724. "updatefindmatchescount",
  1725. webViewerUpdateFindMatchesCount
  1726. );
  1727. eventBus._off(
  1728. "updatefindcontrolstate",
  1729. webViewerUpdateFindControlState
  1730. );
  1731. if (_boundEvents.reportPageStatsPDFBug) {
  1732. eventBus._off("pagerendered", _boundEvents.reportPageStatsPDFBug);
  1733. eventBus._off("pagechanging", _boundEvents.reportPageStatsPDFBug);
  1734. _boundEvents.reportPageStatsPDFBug = null;
  1735. }
  1736. eventBus._off("fileinputchange", webViewerFileInputChange);
  1737. eventBus._off("openfile", webViewerOpenFile);
  1738. _boundEvents.beforePrint = null;
  1739. _boundEvents.afterPrint = null;
  1740. },
  1741. unbindWindowEvents() {
  1742. const { _boundEvents } = this;
  1743. window.removeEventListener(
  1744. "visibilitychange",
  1745. webViewerVisibilityChange
  1746. );
  1747. window.removeEventListener("wheel", webViewerWheel, {
  1748. passive: false,
  1749. });
  1750. window.removeEventListener("touchstart", webViewerTouchStart, {
  1751. passive: false,
  1752. });
  1753. window.removeEventListener("touchmove", webViewerTouchMove, {
  1754. passive: false,
  1755. });
  1756. window.removeEventListener("touchend", webViewerTouchEnd, {
  1757. passive: false,
  1758. });
  1759. window.removeEventListener("click", webViewerClick);
  1760. window.removeEventListener("keydown", webViewerKeyDown);
  1761. window.removeEventListener("keyup", webViewerKeyUp);
  1762. window.removeEventListener("resize", _boundEvents.windowResize);
  1763. window.removeEventListener(
  1764. "hashchange",
  1765. _boundEvents.windowHashChange
  1766. );
  1767. window.removeEventListener(
  1768. "beforeprint",
  1769. _boundEvents.windowBeforePrint
  1770. );
  1771. window.removeEventListener(
  1772. "afterprint",
  1773. _boundEvents.windowAfterPrint
  1774. );
  1775. window.removeEventListener(
  1776. "updatefromsandbox",
  1777. _boundEvents.windowUpdateFromSandbox
  1778. );
  1779. _boundEvents.removeWindowResolutionChange?.();
  1780. _boundEvents.windowResize = null;
  1781. _boundEvents.windowHashChange = null;
  1782. _boundEvents.windowBeforePrint = null;
  1783. _boundEvents.windowAfterPrint = null;
  1784. _boundEvents.windowUpdateFromSandbox = null;
  1785. },
  1786. _accumulateTicks(ticks, prop) {
  1787. if ((this[prop] > 0 && ticks < 0) || (this[prop] < 0 && ticks > 0)) {
  1788. this[prop] = 0;
  1789. }
  1790. this[prop] += ticks;
  1791. const wholeTicks = Math.trunc(this[prop]);
  1792. this[prop] -= wholeTicks;
  1793. return wholeTicks;
  1794. },
  1795. _accumulateFactor(previousScale, factor, prop) {
  1796. if (factor === 1) {
  1797. return 1;
  1798. }
  1799. if (
  1800. (this[prop] > 1 && factor < 1) ||
  1801. (this[prop] < 1 && factor > 1)
  1802. ) {
  1803. this[prop] = 1;
  1804. }
  1805. const newFactor =
  1806. Math.floor(previousScale * factor * this[prop] * 100) /
  1807. (100 * previousScale);
  1808. this[prop] = factor / newFactor;
  1809. return newFactor;
  1810. },
  1811. _centerAtPos(previousScale, x, y) {
  1812. const { pdfViewer } = this;
  1813. const scaleDiff = pdfViewer.currentScale / previousScale - 1;
  1814. if (scaleDiff !== 0) {
  1815. const [top, left] = pdfViewer.containerTopLeft;
  1816. pdfViewer.container.scrollLeft += (x - left) * scaleDiff;
  1817. pdfViewer.container.scrollTop += (y - top) * scaleDiff;
  1818. }
  1819. },
  1820. _unblockDocumentLoadEvent() {
  1821. document.blockUnblockOnload?.(false);
  1822. this._unblockDocumentLoadEvent = () => {};
  1823. },
  1824. get scriptingReady() {
  1825. return this.pdfScriptingManager.ready;
  1826. },
  1827. };
  1828. exports.PDFViewerApplication = PDFViewerApplication;
  1829. {
  1830. const HOSTED_VIEWER_ORIGINS = [
  1831. "null",
  1832. "http://mozilla.github.io",
  1833. "https://mozilla.github.io",
  1834. "https://4dkk.4dage.com",
  1835. "https://ossxiaoan.4dage.com",
  1836. ];
  1837. var validateFileURL = function (file) {
  1838. if (!file) {
  1839. return;
  1840. }
  1841. try {
  1842. const viewerOrigin = new URL(window.location.href).origin || "null";
  1843. if (HOSTED_VIEWER_ORIGINS.includes(viewerOrigin)) {
  1844. return;
  1845. }
  1846. const fileOrigin = new URL(file, window.location.href).origin;
  1847. // if (fileOrigin !== viewerOrigin) {
  1848. // throw new Error("file origin does not match viewer's");
  1849. // }
  1850. } catch (ex) {
  1851. PDFViewerApplication.l10n.get("loading_error").then((msg) => {
  1852. PDFViewerApplication._documentError(msg, {
  1853. message: ex?.message,
  1854. });
  1855. });
  1856. throw ex;
  1857. }
  1858. };
  1859. }
  1860. async function loadFakeWorker() {
  1861. _pdfjsLib.GlobalWorkerOptions.workerSrc ||=
  1862. _app_options.AppOptions.get("workerSrc");
  1863. await (0, _pdfjsLib.loadScript)(_pdfjsLib.PDFWorker.workerSrc);
  1864. }
  1865. async function loadPDFBug(self) {
  1866. const { debuggerScriptPath } = self.appConfig;
  1867. const { PDFBug } = await import(debuggerScriptPath);
  1868. self._PDFBug = PDFBug;
  1869. }
  1870. function reportPageStatsPDFBug({ pageNumber }) {
  1871. if (!globalThis.Stats?.enabled) {
  1872. return;
  1873. }
  1874. const pageView = PDFViewerApplication.pdfViewer.getPageView(
  1875. pageNumber - 1
  1876. );
  1877. globalThis.Stats.add(pageNumber, pageView?.pdfPage?.stats);
  1878. }
  1879. function webViewerInitialized() {
  1880. const { appConfig, eventBus, l10n } = PDFViewerApplication;
  1881. let file;
  1882. const queryString = document.location.search.substring(1);
  1883. const params = (0, _ui_utils.parseQueryString)(queryString);
  1884. file = params.get("file") ?? _app_options.AppOptions.get("defaultUrl");
  1885. validateFileURL(file);
  1886. const fileInput = appConfig.openFileInput;
  1887. fileInput.value = null;
  1888. fileInput.addEventListener("change", function (evt) {
  1889. const { files } = evt.target;
  1890. if (!files || files.length === 0) {
  1891. return;
  1892. }
  1893. eventBus.dispatch("fileinputchange", {
  1894. source: this,
  1895. fileInput: evt.target,
  1896. });
  1897. });
  1898. appConfig.mainContainer.addEventListener("dragover", function (evt) {
  1899. evt.preventDefault();
  1900. evt.dataTransfer.dropEffect =
  1901. evt.dataTransfer.effectAllowed === "copy" ? "copy" : "move";
  1902. });
  1903. appConfig.mainContainer.addEventListener("drop", function (evt) {
  1904. evt.preventDefault();
  1905. const { files } = evt.dataTransfer;
  1906. if (!files || files.length === 0) {
  1907. return;
  1908. }
  1909. eventBus.dispatch("fileinputchange", {
  1910. source: this,
  1911. fileInput: evt.dataTransfer,
  1912. });
  1913. });
  1914. if (!PDFViewerApplication.supportsDocumentFonts) {
  1915. _app_options.AppOptions.set("disableFontFace", true);
  1916. l10n.get("web_fonts_disabled").then((msg) => {
  1917. console.warn(msg);
  1918. });
  1919. }
  1920. if (!PDFViewerApplication.supportsPrinting) {
  1921. appConfig.toolbar?.print.classList.add("hidden");
  1922. appConfig.secondaryToolbar?.printButton.classList.add("hidden");
  1923. }
  1924. if (!PDFViewerApplication.supportsFullscreen) {
  1925. appConfig.secondaryToolbar?.presentationModeButton.classList.add(
  1926. "hidden"
  1927. );
  1928. }
  1929. if (PDFViewerApplication.supportsIntegratedFind) {
  1930. appConfig.toolbar?.viewFind.classList.add("hidden");
  1931. }
  1932. appConfig.mainContainer.addEventListener(
  1933. "transitionend",
  1934. function (evt) {
  1935. if (evt.target === this) {
  1936. eventBus.dispatch("resize", {
  1937. source: this,
  1938. });
  1939. }
  1940. },
  1941. true
  1942. );
  1943. try {
  1944. if (file) {
  1945. PDFViewerApplication.open({
  1946. url: file,
  1947. });
  1948. } else {
  1949. PDFViewerApplication._hideViewBookmark();
  1950. }
  1951. } catch (reason) {
  1952. l10n.get("loading_error").then((msg) => {
  1953. PDFViewerApplication._documentError(msg, reason);
  1954. });
  1955. }
  1956. }
  1957. function webViewerPageRender({ pageNumber }) {
  1958. if (pageNumber === PDFViewerApplication.page) {
  1959. PDFViewerApplication.toolbar?.updateLoadingIndicatorState(true);
  1960. }
  1961. }
  1962. function webViewerPageRendered({ pageNumber, error }) {
  1963. if (pageNumber === PDFViewerApplication.page) {
  1964. PDFViewerApplication.toolbar?.updateLoadingIndicatorState(false);
  1965. }
  1966. if (
  1967. PDFViewerApplication.pdfSidebar?.visibleView ===
  1968. _ui_utils.SidebarView.THUMBS
  1969. ) {
  1970. const pageView = PDFViewerApplication.pdfViewer.getPageView(
  1971. pageNumber - 1
  1972. );
  1973. const thumbnailView =
  1974. PDFViewerApplication.pdfThumbnailViewer?.getThumbnail(
  1975. pageNumber - 1
  1976. );
  1977. if (pageView && thumbnailView) {
  1978. thumbnailView.setImage(pageView);
  1979. }
  1980. }
  1981. if (error) {
  1982. PDFViewerApplication.l10n.get("rendering_error").then((msg) => {
  1983. PDFViewerApplication._otherError(msg, error);
  1984. });
  1985. }
  1986. }
  1987. function webViewerPageMode({ mode }) {
  1988. let view;
  1989. switch (mode) {
  1990. case "thumbs":
  1991. view = _ui_utils.SidebarView.THUMBS;
  1992. break;
  1993. case "bookmarks":
  1994. case "outline":
  1995. view = _ui_utils.SidebarView.OUTLINE;
  1996. break;
  1997. case "attachments":
  1998. view = _ui_utils.SidebarView.ATTACHMENTS;
  1999. break;
  2000. case "layers":
  2001. view = _ui_utils.SidebarView.LAYERS;
  2002. break;
  2003. case "none":
  2004. view = _ui_utils.SidebarView.NONE;
  2005. break;
  2006. default:
  2007. console.error('Invalid "pagemode" hash parameter: ' + mode);
  2008. return;
  2009. }
  2010. PDFViewerApplication.pdfSidebar?.switchView(view, true);
  2011. }
  2012. function webViewerNamedAction(evt) {
  2013. switch (evt.action) {
  2014. case "GoToPage":
  2015. PDFViewerApplication.appConfig.toolbar?.pageNumber.select();
  2016. break;
  2017. case "Find":
  2018. if (!PDFViewerApplication.supportsIntegratedFind) {
  2019. PDFViewerApplication?.findBar.toggle();
  2020. }
  2021. break;
  2022. case "Print":
  2023. PDFViewerApplication.triggerPrinting();
  2024. break;
  2025. case "SaveAs":
  2026. PDFViewerApplication.downloadOrSave();
  2027. break;
  2028. }
  2029. }
  2030. function webViewerPresentationModeChanged(evt) {
  2031. PDFViewerApplication.pdfViewer.presentationModeState = evt.state;
  2032. }
  2033. function webViewerSidebarViewChanged({ view }) {
  2034. PDFViewerApplication.pdfRenderingQueue.isThumbnailViewEnabled =
  2035. view === _ui_utils.SidebarView.THUMBS;
  2036. if (PDFViewerApplication.isInitialViewSet) {
  2037. PDFViewerApplication.store?.set("sidebarView", view).catch(() => {});
  2038. }
  2039. }
  2040. function webViewerUpdateViewarea({ location }) {
  2041. if (PDFViewerApplication.isInitialViewSet) {
  2042. PDFViewerApplication.store
  2043. ?.setMultiple({
  2044. page: location.pageNumber,
  2045. zoom: location.scale,
  2046. scrollLeft: location.left,
  2047. scrollTop: location.top,
  2048. rotation: location.rotation,
  2049. })
  2050. .catch(() => {});
  2051. }
  2052. if (PDFViewerApplication.appConfig.secondaryToolbar) {
  2053. const href = PDFViewerApplication.pdfLinkService.getAnchorUrl(
  2054. location.pdfOpenParams
  2055. );
  2056. PDFViewerApplication.appConfig.secondaryToolbar.viewBookmarkButton.href =
  2057. href;
  2058. }
  2059. }
  2060. function webViewerScrollModeChanged(evt) {
  2061. if (
  2062. PDFViewerApplication.isInitialViewSet &&
  2063. !PDFViewerApplication.pdfViewer.isInPresentationMode
  2064. ) {
  2065. PDFViewerApplication.store
  2066. ?.set("scrollMode", evt.mode)
  2067. .catch(() => {});
  2068. }
  2069. }
  2070. function webViewerSpreadModeChanged(evt) {
  2071. if (
  2072. PDFViewerApplication.isInitialViewSet &&
  2073. !PDFViewerApplication.pdfViewer.isInPresentationMode
  2074. ) {
  2075. PDFViewerApplication.store
  2076. ?.set("spreadMode", evt.mode)
  2077. .catch(() => {});
  2078. }
  2079. }
  2080. function webViewerResize() {
  2081. const { pdfDocument, pdfViewer, pdfRenderingQueue } =
  2082. PDFViewerApplication;
  2083. if (pdfRenderingQueue.printing && window.matchMedia("print").matches) {
  2084. return;
  2085. }
  2086. if (!pdfDocument) {
  2087. return;
  2088. }
  2089. const currentScaleValue = pdfViewer.currentScaleValue;
  2090. if (
  2091. currentScaleValue === "auto" ||
  2092. currentScaleValue === "page-fit" ||
  2093. currentScaleValue === "page-width"
  2094. ) {
  2095. pdfViewer.currentScaleValue = currentScaleValue;
  2096. }
  2097. pdfViewer.update();
  2098. }
  2099. function webViewerHashchange(evt) {
  2100. const hash = evt.hash;
  2101. if (!hash) {
  2102. return;
  2103. }
  2104. if (!PDFViewerApplication.isInitialViewSet) {
  2105. PDFViewerApplication.initialBookmark = hash;
  2106. } else if (!PDFViewerApplication.pdfHistory?.popStateInProgress) {
  2107. PDFViewerApplication.pdfLinkService.setHash(hash);
  2108. }
  2109. }
  2110. {
  2111. var webViewerFileInputChange = function (evt) {
  2112. if (PDFViewerApplication.pdfViewer?.isInPresentationMode) {
  2113. return;
  2114. }
  2115. const file = evt.fileInput.files[0];
  2116. PDFViewerApplication.open({
  2117. url: URL.createObjectURL(file),
  2118. originalUrl: file.name,
  2119. });
  2120. };
  2121. var webViewerOpenFile = function (evt) {
  2122. const fileInput = PDFViewerApplication.appConfig.openFileInput;
  2123. fileInput.click();
  2124. };
  2125. }
  2126. function webViewerPresentationMode() {
  2127. PDFViewerApplication.requestPresentationMode();
  2128. }
  2129. function webViewerSwitchAnnotationEditorMode(evt) {
  2130. PDFViewerApplication.pdfViewer.annotationEditorMode = evt.mode;
  2131. }
  2132. function webViewerSwitchAnnotationEditorParams(evt) {
  2133. PDFViewerApplication.pdfViewer.annotationEditorParams = evt;
  2134. }
  2135. function webViewerPrint() {
  2136. PDFViewerApplication.triggerPrinting();
  2137. }
  2138. function webViewerDownload() {
  2139. PDFViewerApplication.downloadOrSave();
  2140. }
  2141. function webViewerFirstPage() {
  2142. PDFViewerApplication.page = 1;
  2143. }
  2144. function webViewerLastPage() {
  2145. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  2146. }
  2147. function webViewerNextPage() {
  2148. PDFViewerApplication.pdfViewer.nextPage();
  2149. }
  2150. function webViewerPreviousPage() {
  2151. PDFViewerApplication.pdfViewer.previousPage();
  2152. }
  2153. function webViewerZoomIn() {
  2154. PDFViewerApplication.zoomIn();
  2155. }
  2156. function webViewerZoomOut() {
  2157. PDFViewerApplication.zoomOut();
  2158. }
  2159. function webViewerZoomReset() {
  2160. PDFViewerApplication.zoomReset();
  2161. }
  2162. function webViewerPageNumberChanged(evt) {
  2163. const pdfViewer = PDFViewerApplication.pdfViewer;
  2164. if (evt.value !== "") {
  2165. PDFViewerApplication.pdfLinkService.goToPage(evt.value);
  2166. }
  2167. if (
  2168. evt.value !== pdfViewer.currentPageNumber.toString() &&
  2169. evt.value !== pdfViewer.currentPageLabel
  2170. ) {
  2171. PDFViewerApplication.toolbar?.setPageNumber(
  2172. pdfViewer.currentPageNumber,
  2173. pdfViewer.currentPageLabel
  2174. );
  2175. }
  2176. }
  2177. function webViewerScaleChanged(evt) {
  2178. PDFViewerApplication.pdfViewer.currentScaleValue = evt.value;
  2179. }
  2180. function webViewerRotateCw() {
  2181. PDFViewerApplication.rotatePages(90);
  2182. }
  2183. function webViewerRotateCcw() {
  2184. PDFViewerApplication.rotatePages(-90);
  2185. }
  2186. function webViewerOptionalContentConfig(evt) {
  2187. PDFViewerApplication.pdfViewer.optionalContentConfigPromise =
  2188. evt.promise;
  2189. }
  2190. function webViewerSwitchScrollMode(evt) {
  2191. PDFViewerApplication.pdfViewer.scrollMode = evt.mode;
  2192. }
  2193. function webViewerSwitchSpreadMode(evt) {
  2194. PDFViewerApplication.pdfViewer.spreadMode = evt.mode;
  2195. }
  2196. function webViewerDocumentProperties() {
  2197. PDFViewerApplication.pdfDocumentProperties?.open();
  2198. }
  2199. function webViewerFindFromUrlHash(evt) {
  2200. PDFViewerApplication.eventBus.dispatch("find", {
  2201. source: evt.source,
  2202. type: "",
  2203. query: evt.query,
  2204. phraseSearch: evt.phraseSearch,
  2205. caseSensitive: false,
  2206. entireWord: false,
  2207. highlightAll: true,
  2208. findPrevious: false,
  2209. matchDiacritics: true,
  2210. });
  2211. }
  2212. function webViewerUpdateFindMatchesCount({ matchesCount }) {
  2213. if (PDFViewerApplication.supportsIntegratedFind) {
  2214. PDFViewerApplication.externalServices.updateFindMatchesCount(
  2215. matchesCount
  2216. );
  2217. } else {
  2218. PDFViewerApplication.findBar.updateResultsCount(matchesCount);
  2219. }
  2220. }
  2221. function webViewerUpdateFindControlState({
  2222. state,
  2223. previous,
  2224. matchesCount,
  2225. rawQuery,
  2226. }) {
  2227. if (PDFViewerApplication.supportsIntegratedFind) {
  2228. PDFViewerApplication.externalServices.updateFindControlState({
  2229. result: state,
  2230. findPrevious: previous,
  2231. matchesCount,
  2232. rawQuery,
  2233. });
  2234. } else {
  2235. PDFViewerApplication.findBar?.updateUIState(
  2236. state,
  2237. previous,
  2238. matchesCount
  2239. );
  2240. }
  2241. }
  2242. function webViewerScaleChanging(evt) {
  2243. PDFViewerApplication.toolbar?.setPageScale(evt.presetValue, evt.scale);
  2244. PDFViewerApplication.pdfViewer.update();
  2245. }
  2246. function webViewerRotationChanging(evt) {
  2247. if (PDFViewerApplication.pdfThumbnailViewer) {
  2248. PDFViewerApplication.pdfThumbnailViewer.pagesRotation =
  2249. evt.pagesRotation;
  2250. }
  2251. PDFViewerApplication.forceRendering();
  2252. PDFViewerApplication.pdfViewer.currentPageNumber = evt.pageNumber;
  2253. }
  2254. function webViewerPageChanging({ pageNumber, pageLabel }) {
  2255. PDFViewerApplication.toolbar?.setPageNumber(pageNumber, pageLabel);
  2256. PDFViewerApplication.secondaryToolbar?.setPageNumber(pageNumber);
  2257. if (
  2258. PDFViewerApplication.pdfSidebar?.visibleView ===
  2259. _ui_utils.SidebarView.THUMBS
  2260. ) {
  2261. PDFViewerApplication.pdfThumbnailViewer?.scrollThumbnailIntoView(
  2262. pageNumber
  2263. );
  2264. }
  2265. const currentPage = PDFViewerApplication.pdfViewer.getPageView(
  2266. pageNumber - 1
  2267. );
  2268. PDFViewerApplication.toolbar?.updateLoadingIndicatorState(
  2269. currentPage?.renderingState === _ui_utils.RenderingStates.RUNNING
  2270. );
  2271. }
  2272. function webViewerResolutionChange(evt) {
  2273. PDFViewerApplication.pdfViewer.refresh();
  2274. }
  2275. function webViewerVisibilityChange(evt) {
  2276. if (document.visibilityState === "visible") {
  2277. setZoomDisabledTimeout();
  2278. }
  2279. }
  2280. let zoomDisabledTimeout = null;
  2281. function setZoomDisabledTimeout() {
  2282. if (zoomDisabledTimeout) {
  2283. clearTimeout(zoomDisabledTimeout);
  2284. }
  2285. zoomDisabledTimeout = setTimeout(function () {
  2286. zoomDisabledTimeout = null;
  2287. }, WHEEL_ZOOM_DISABLED_TIMEOUT);
  2288. }
  2289. function webViewerWheel(evt) {
  2290. const {
  2291. pdfViewer,
  2292. supportedMouseWheelZoomModifierKeys,
  2293. supportsPinchToZoom,
  2294. } = PDFViewerApplication;
  2295. if (pdfViewer.isInPresentationMode) {
  2296. return;
  2297. }
  2298. const deltaMode = evt.deltaMode;
  2299. let scaleFactor = Math.exp(-evt.deltaY / 100);
  2300. const isBuiltInMac = false;
  2301. const isPinchToZoom =
  2302. evt.ctrlKey &&
  2303. !PDFViewerApplication._isCtrlKeyDown &&
  2304. deltaMode === WheelEvent.DOM_DELTA_PIXEL &&
  2305. evt.deltaX === 0 &&
  2306. (Math.abs(scaleFactor - 1) < 0.05 || isBuiltInMac) &&
  2307. evt.deltaZ === 0;
  2308. if (
  2309. isPinchToZoom ||
  2310. (evt.ctrlKey && supportedMouseWheelZoomModifierKeys.ctrlKey) ||
  2311. (evt.metaKey && supportedMouseWheelZoomModifierKeys.metaKey)
  2312. ) {
  2313. evt.preventDefault();
  2314. if (zoomDisabledTimeout || document.visibilityState === "hidden") {
  2315. return;
  2316. }
  2317. const previousScale = pdfViewer.currentScale;
  2318. if (isPinchToZoom && supportsPinchToZoom) {
  2319. scaleFactor = PDFViewerApplication._accumulateFactor(
  2320. previousScale,
  2321. scaleFactor,
  2322. "_wheelUnusedFactor"
  2323. );
  2324. if (scaleFactor < 1) {
  2325. PDFViewerApplication.zoomOut(null, scaleFactor);
  2326. } else if (scaleFactor > 1) {
  2327. PDFViewerApplication.zoomIn(null, scaleFactor);
  2328. } else {
  2329. return;
  2330. }
  2331. } else {
  2332. const delta = (0, _ui_utils.normalizeWheelEventDirection)(evt);
  2333. let ticks = 0;
  2334. if (
  2335. deltaMode === WheelEvent.DOM_DELTA_LINE ||
  2336. deltaMode === WheelEvent.DOM_DELTA_PAGE
  2337. ) {
  2338. if (Math.abs(delta) >= 1) {
  2339. ticks = Math.sign(delta);
  2340. } else {
  2341. ticks = PDFViewerApplication._accumulateTicks(
  2342. delta,
  2343. "_wheelUnusedTicks"
  2344. );
  2345. }
  2346. } else {
  2347. const PIXELS_PER_LINE_SCALE = 30;
  2348. ticks = PDFViewerApplication._accumulateTicks(
  2349. delta / PIXELS_PER_LINE_SCALE,
  2350. "_wheelUnusedTicks"
  2351. );
  2352. }
  2353. if (ticks < 0) {
  2354. PDFViewerApplication.zoomOut(-ticks);
  2355. } else if (ticks > 0) {
  2356. PDFViewerApplication.zoomIn(ticks);
  2357. } else {
  2358. return;
  2359. }
  2360. }
  2361. PDFViewerApplication._centerAtPos(
  2362. previousScale,
  2363. evt.clientX,
  2364. evt.clientY
  2365. );
  2366. } else {
  2367. setZoomDisabledTimeout();
  2368. }
  2369. }
  2370. function webViewerTouchStart(evt) {
  2371. if (
  2372. PDFViewerApplication.pdfViewer.isInPresentationMode ||
  2373. evt.touches.length < 2
  2374. ) {
  2375. return;
  2376. }
  2377. evt.preventDefault();
  2378. if (evt.touches.length !== 2) {
  2379. PDFViewerApplication._touchInfo = null;
  2380. return;
  2381. }
  2382. let [touch0, touch1] = evt.touches;
  2383. if (touch0.identifier > touch1.identifier) {
  2384. [touch0, touch1] = [touch1, touch0];
  2385. }
  2386. PDFViewerApplication._touchInfo = {
  2387. touch0X: touch0.pageX,
  2388. touch0Y: touch0.pageY,
  2389. touch1X: touch1.pageX,
  2390. touch1Y: touch1.pageY,
  2391. };
  2392. }
  2393. function webViewerTouchMove(evt) {
  2394. if (!PDFViewerApplication._touchInfo || evt.touches.length !== 2) {
  2395. return;
  2396. }
  2397. const { pdfViewer, _touchInfo, supportsPinchToZoom } =
  2398. PDFViewerApplication;
  2399. let [touch0, touch1] = evt.touches;
  2400. if (touch0.identifier > touch1.identifier) {
  2401. [touch0, touch1] = [touch1, touch0];
  2402. }
  2403. const { pageX: page0X, pageY: page0Y } = touch0;
  2404. const { pageX: page1X, pageY: page1Y } = touch1;
  2405. const {
  2406. touch0X: pTouch0X,
  2407. touch0Y: pTouch0Y,
  2408. touch1X: pTouch1X,
  2409. touch1Y: pTouch1Y,
  2410. } = _touchInfo;
  2411. if (
  2412. Math.abs(pTouch0X - page0X) <= 1 &&
  2413. Math.abs(pTouch0Y - page0Y) <= 1 &&
  2414. Math.abs(pTouch1X - page1X) <= 1 &&
  2415. Math.abs(pTouch1Y - page1Y) <= 1
  2416. ) {
  2417. return;
  2418. }
  2419. _touchInfo.touch0X = page0X;
  2420. _touchInfo.touch0Y = page0Y;
  2421. _touchInfo.touch1X = page1X;
  2422. _touchInfo.touch1Y = page1Y;
  2423. if (pTouch0X === page0X && pTouch0Y === page0Y) {
  2424. const v1X = pTouch1X - page0X;
  2425. const v1Y = pTouch1Y - page0Y;
  2426. const v2X = page1X - page0X;
  2427. const v2Y = page1Y - page0Y;
  2428. const det = v1X * v2Y - v1Y * v2X;
  2429. if (
  2430. Math.abs(det) >
  2431. 0.02 * Math.hypot(v1X, v1Y) * Math.hypot(v2X, v2Y)
  2432. ) {
  2433. return;
  2434. }
  2435. } else if (pTouch1X === page1X && pTouch1Y === page1Y) {
  2436. const v1X = pTouch0X - page1X;
  2437. const v1Y = pTouch0Y - page1Y;
  2438. const v2X = page0X - page1X;
  2439. const v2Y = page0Y - page1Y;
  2440. const det = v1X * v2Y - v1Y * v2X;
  2441. if (
  2442. Math.abs(det) >
  2443. 0.02 * Math.hypot(v1X, v1Y) * Math.hypot(v2X, v2Y)
  2444. ) {
  2445. return;
  2446. }
  2447. } else {
  2448. const diff0X = page0X - pTouch0X;
  2449. const diff1X = page1X - pTouch1X;
  2450. const diff0Y = page0Y - pTouch0Y;
  2451. const diff1Y = page1Y - pTouch1Y;
  2452. const dotProduct = diff0X * diff1X + diff0Y * diff1Y;
  2453. if (dotProduct >= 0) {
  2454. return;
  2455. }
  2456. }
  2457. evt.preventDefault();
  2458. const distance = Math.hypot(page0X - page1X, page0Y - page1Y) || 1;
  2459. const pDistance =
  2460. Math.hypot(pTouch0X - pTouch1X, pTouch0Y - pTouch1Y) || 1;
  2461. const previousScale = pdfViewer.currentScale;
  2462. if (supportsPinchToZoom) {
  2463. const newScaleFactor = PDFViewerApplication._accumulateFactor(
  2464. previousScale,
  2465. distance / pDistance,
  2466. "_touchUnusedFactor"
  2467. );
  2468. if (newScaleFactor < 1) {
  2469. PDFViewerApplication.zoomOut(null, newScaleFactor);
  2470. } else if (newScaleFactor > 1) {
  2471. PDFViewerApplication.zoomIn(null, newScaleFactor);
  2472. } else {
  2473. return;
  2474. }
  2475. } else {
  2476. const PIXELS_PER_LINE_SCALE = 30;
  2477. const ticks = PDFViewerApplication._accumulateTicks(
  2478. (distance - pDistance) / PIXELS_PER_LINE_SCALE,
  2479. "_touchUnusedTicks"
  2480. );
  2481. if (ticks < 0) {
  2482. PDFViewerApplication.zoomOut(-ticks);
  2483. } else if (ticks > 0) {
  2484. PDFViewerApplication.zoomIn(ticks);
  2485. } else {
  2486. return;
  2487. }
  2488. }
  2489. PDFViewerApplication._centerAtPos(
  2490. previousScale,
  2491. (page0X + page1X) / 2,
  2492. (page0Y + page1Y) / 2
  2493. );
  2494. }
  2495. function webViewerTouchEnd(evt) {
  2496. if (!PDFViewerApplication._touchInfo) {
  2497. return;
  2498. }
  2499. evt.preventDefault();
  2500. PDFViewerApplication._touchInfo = null;
  2501. PDFViewerApplication._touchUnusedTicks = 0;
  2502. PDFViewerApplication._touchUnusedFactor = 1;
  2503. }
  2504. function webViewerClick(evt) {
  2505. if (!PDFViewerApplication.secondaryToolbar?.isOpen) {
  2506. return;
  2507. }
  2508. const appConfig = PDFViewerApplication.appConfig;
  2509. if (
  2510. PDFViewerApplication.pdfViewer.containsElement(evt.target) ||
  2511. (appConfig.toolbar?.container.contains(evt.target) &&
  2512. evt.target !== appConfig.secondaryToolbar?.toggleButton)
  2513. ) {
  2514. PDFViewerApplication.secondaryToolbar.close();
  2515. }
  2516. }
  2517. function webViewerKeyUp(evt) {
  2518. if (evt.key === "Control") {
  2519. PDFViewerApplication._isCtrlKeyDown = false;
  2520. }
  2521. }
  2522. function webViewerKeyDown(evt) {
  2523. PDFViewerApplication._isCtrlKeyDown = evt.key === "Control";
  2524. if (PDFViewerApplication.overlayManager.active) {
  2525. return;
  2526. }
  2527. const { eventBus, pdfViewer } = PDFViewerApplication;
  2528. const isViewerInPresentationMode = pdfViewer.isInPresentationMode;
  2529. let handled = false,
  2530. ensureViewerFocused = false;
  2531. const cmd =
  2532. (evt.ctrlKey ? 1 : 0) |
  2533. (evt.altKey ? 2 : 0) |
  2534. (evt.shiftKey ? 4 : 0) |
  2535. (evt.metaKey ? 8 : 0);
  2536. if (cmd === 1 || cmd === 8 || cmd === 5 || cmd === 12) {
  2537. switch (evt.keyCode) {
  2538. case 70:
  2539. if (
  2540. !PDFViewerApplication.supportsIntegratedFind &&
  2541. !evt.shiftKey
  2542. ) {
  2543. PDFViewerApplication.findBar?.open();
  2544. handled = true;
  2545. }
  2546. break;
  2547. case 71:
  2548. if (!PDFViewerApplication.supportsIntegratedFind) {
  2549. const { state } = PDFViewerApplication.findController;
  2550. if (state) {
  2551. const newState = {
  2552. source: window,
  2553. type: "again",
  2554. findPrevious: cmd === 5 || cmd === 12,
  2555. };
  2556. eventBus.dispatch("find", {
  2557. ...state,
  2558. ...newState,
  2559. });
  2560. }
  2561. handled = true;
  2562. }
  2563. break;
  2564. case 61:
  2565. case 107:
  2566. case 187:
  2567. case 171:
  2568. PDFViewerApplication.zoomIn();
  2569. handled = true;
  2570. break;
  2571. case 173:
  2572. case 109:
  2573. case 189:
  2574. PDFViewerApplication.zoomOut();
  2575. handled = true;
  2576. break;
  2577. case 48:
  2578. case 96:
  2579. if (!isViewerInPresentationMode) {
  2580. setTimeout(function () {
  2581. PDFViewerApplication.zoomReset();
  2582. });
  2583. handled = false;
  2584. }
  2585. break;
  2586. case 38:
  2587. if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
  2588. PDFViewerApplication.page = 1;
  2589. handled = true;
  2590. ensureViewerFocused = true;
  2591. }
  2592. break;
  2593. case 40:
  2594. if (
  2595. isViewerInPresentationMode ||
  2596. PDFViewerApplication.page < PDFViewerApplication.pagesCount
  2597. ) {
  2598. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  2599. handled = true;
  2600. ensureViewerFocused = true;
  2601. }
  2602. break;
  2603. }
  2604. }
  2605. if (cmd === 1 || cmd === 8) {
  2606. switch (evt.keyCode) {
  2607. case 83:
  2608. eventBus.dispatch("download", {
  2609. source: window,
  2610. });
  2611. handled = true;
  2612. break;
  2613. case 79:
  2614. {
  2615. eventBus.dispatch("openfile", {
  2616. source: window,
  2617. });
  2618. handled = true;
  2619. }
  2620. break;
  2621. }
  2622. }
  2623. if (cmd === 3 || cmd === 10) {
  2624. switch (evt.keyCode) {
  2625. case 80:
  2626. PDFViewerApplication.requestPresentationMode();
  2627. handled = true;
  2628. PDFViewerApplication.externalServices.reportTelemetry({
  2629. type: "buttons",
  2630. data: {
  2631. id: "presentationModeKeyboard",
  2632. },
  2633. });
  2634. break;
  2635. case 71:
  2636. if (PDFViewerApplication.appConfig.toolbar) {
  2637. PDFViewerApplication.appConfig.toolbar.pageNumber.select();
  2638. handled = true;
  2639. }
  2640. break;
  2641. }
  2642. }
  2643. if (handled) {
  2644. if (ensureViewerFocused && !isViewerInPresentationMode) {
  2645. pdfViewer.focus();
  2646. }
  2647. evt.preventDefault();
  2648. return;
  2649. }
  2650. const curElement = (0, _ui_utils.getActiveOrFocusedElement)();
  2651. const curElementTagName = curElement?.tagName.toUpperCase();
  2652. if (
  2653. curElementTagName === "INPUT" ||
  2654. curElementTagName === "TEXTAREA" ||
  2655. curElementTagName === "SELECT" ||
  2656. curElement?.isContentEditable
  2657. ) {
  2658. if (evt.keyCode !== 27) {
  2659. return;
  2660. }
  2661. }
  2662. if (cmd === 0) {
  2663. let turnPage = 0,
  2664. turnOnlyIfPageFit = false;
  2665. switch (evt.keyCode) {
  2666. case 38:
  2667. case 33:
  2668. if (pdfViewer.isVerticalScrollbarEnabled) {
  2669. turnOnlyIfPageFit = true;
  2670. }
  2671. turnPage = -1;
  2672. break;
  2673. case 8:
  2674. if (!isViewerInPresentationMode) {
  2675. turnOnlyIfPageFit = true;
  2676. }
  2677. turnPage = -1;
  2678. break;
  2679. case 37:
  2680. if (pdfViewer.isHorizontalScrollbarEnabled) {
  2681. turnOnlyIfPageFit = true;
  2682. }
  2683. case 75:
  2684. case 80:
  2685. turnPage = -1;
  2686. break;
  2687. case 27:
  2688. if (PDFViewerApplication.secondaryToolbar?.isOpen) {
  2689. PDFViewerApplication.secondaryToolbar.close();
  2690. handled = true;
  2691. }
  2692. if (
  2693. !PDFViewerApplication.supportsIntegratedFind &&
  2694. PDFViewerApplication.findBar?.opened
  2695. ) {
  2696. PDFViewerApplication.findBar.close();
  2697. handled = true;
  2698. }
  2699. break;
  2700. case 40:
  2701. case 34:
  2702. if (pdfViewer.isVerticalScrollbarEnabled) {
  2703. turnOnlyIfPageFit = true;
  2704. }
  2705. turnPage = 1;
  2706. break;
  2707. case 13:
  2708. case 32:
  2709. if (!isViewerInPresentationMode) {
  2710. turnOnlyIfPageFit = true;
  2711. }
  2712. turnPage = 1;
  2713. break;
  2714. case 39:
  2715. if (pdfViewer.isHorizontalScrollbarEnabled) {
  2716. turnOnlyIfPageFit = true;
  2717. }
  2718. case 74:
  2719. case 78:
  2720. turnPage = 1;
  2721. break;
  2722. case 36:
  2723. if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
  2724. PDFViewerApplication.page = 1;
  2725. handled = true;
  2726. ensureViewerFocused = true;
  2727. }
  2728. break;
  2729. case 35:
  2730. if (
  2731. isViewerInPresentationMode ||
  2732. PDFViewerApplication.page < PDFViewerApplication.pagesCount
  2733. ) {
  2734. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  2735. handled = true;
  2736. ensureViewerFocused = true;
  2737. }
  2738. break;
  2739. case 83:
  2740. PDFViewerApplication.pdfCursorTools?.switchTool(
  2741. _ui_utils.CursorTool.SELECT
  2742. );
  2743. break;
  2744. case 72:
  2745. PDFViewerApplication.pdfCursorTools?.switchTool(
  2746. _ui_utils.CursorTool.HAND
  2747. );
  2748. break;
  2749. case 82:
  2750. PDFViewerApplication.rotatePages(90);
  2751. break;
  2752. case 115:
  2753. PDFViewerApplication.pdfSidebar?.toggle();
  2754. break;
  2755. }
  2756. if (
  2757. turnPage !== 0 &&
  2758. (!turnOnlyIfPageFit || pdfViewer.currentScaleValue === "page-fit")
  2759. ) {
  2760. if (turnPage > 0) {
  2761. pdfViewer.nextPage();
  2762. } else {
  2763. pdfViewer.previousPage();
  2764. }
  2765. handled = true;
  2766. }
  2767. }
  2768. if (cmd === 4) {
  2769. switch (evt.keyCode) {
  2770. case 13:
  2771. case 32:
  2772. if (
  2773. !isViewerInPresentationMode &&
  2774. pdfViewer.currentScaleValue !== "page-fit"
  2775. ) {
  2776. break;
  2777. }
  2778. pdfViewer.previousPage();
  2779. handled = true;
  2780. break;
  2781. case 82:
  2782. PDFViewerApplication.rotatePages(-90);
  2783. break;
  2784. }
  2785. }
  2786. if (!handled && !isViewerInPresentationMode) {
  2787. if (
  2788. (evt.keyCode >= 33 && evt.keyCode <= 40) ||
  2789. (evt.keyCode === 32 && curElementTagName !== "BUTTON")
  2790. ) {
  2791. ensureViewerFocused = true;
  2792. }
  2793. }
  2794. if (ensureViewerFocused && !pdfViewer.containsElement(curElement)) {
  2795. pdfViewer.focus();
  2796. }
  2797. if (handled) {
  2798. evt.preventDefault();
  2799. }
  2800. }
  2801. function beforeUnload(evt) {
  2802. evt.preventDefault();
  2803. evt.returnValue = "";
  2804. return false;
  2805. }
  2806. function webViewerAnnotationEditorStatesChanged(data) {
  2807. PDFViewerApplication.externalServices.updateEditorStates(data);
  2808. }
  2809. const PDFPrintServiceFactory = {
  2810. instance: {
  2811. supportsPrinting: false,
  2812. createPrintService() {
  2813. throw new Error("Not implemented: createPrintService");
  2814. },
  2815. },
  2816. };
  2817. exports.PDFPrintServiceFactory = PDFPrintServiceFactory;
  2818. /***/
  2819. },
  2820. /* 3 */
  2821. /***/ (__unused_webpack_module, exports) => {
  2822. Object.defineProperty(exports, "__esModule", {
  2823. value: true,
  2824. });
  2825. exports.animationStarted =
  2826. exports.VERTICAL_PADDING =
  2827. exports.UNKNOWN_SCALE =
  2828. exports.TextLayerMode =
  2829. exports.SpreadMode =
  2830. exports.SidebarView =
  2831. exports.ScrollMode =
  2832. exports.SCROLLBAR_PADDING =
  2833. exports.RenderingStates =
  2834. exports.RendererType =
  2835. exports.ProgressBar =
  2836. exports.PresentationModeState =
  2837. exports.OutputScale =
  2838. exports.MIN_SCALE =
  2839. exports.MAX_SCALE =
  2840. exports.MAX_AUTO_SCALE =
  2841. exports.DEFAULT_SCALE_VALUE =
  2842. exports.DEFAULT_SCALE_DELTA =
  2843. exports.DEFAULT_SCALE =
  2844. exports.CursorTool =
  2845. exports.AutoPrintRegExp =
  2846. void 0;
  2847. exports.apiPageLayoutToViewerModes = apiPageLayoutToViewerModes;
  2848. exports.apiPageModeToSidebarView = apiPageModeToSidebarView;
  2849. exports.approximateFraction = approximateFraction;
  2850. exports.backtrackBeforeAllVisibleElements =
  2851. backtrackBeforeAllVisibleElements;
  2852. exports.binarySearchFirstItem = binarySearchFirstItem;
  2853. exports.docStyle = void 0;
  2854. exports.getActiveOrFocusedElement = getActiveOrFocusedElement;
  2855. exports.getPageSizeInches = getPageSizeInches;
  2856. exports.getVisibleElements = getVisibleElements;
  2857. exports.isPortraitOrientation = isPortraitOrientation;
  2858. exports.isValidRotation = isValidRotation;
  2859. exports.isValidScrollMode = isValidScrollMode;
  2860. exports.isValidSpreadMode = isValidSpreadMode;
  2861. exports.noContextMenuHandler = noContextMenuHandler;
  2862. exports.normalizeWheelEventDelta = normalizeWheelEventDelta;
  2863. exports.normalizeWheelEventDirection = normalizeWheelEventDirection;
  2864. exports.parseQueryString = parseQueryString;
  2865. exports.removeNullCharacters = removeNullCharacters;
  2866. exports.roundToDivide = roundToDivide;
  2867. exports.scrollIntoView = scrollIntoView;
  2868. exports.watchScroll = watchScroll;
  2869. const DEFAULT_SCALE_VALUE = "auto";
  2870. exports.DEFAULT_SCALE_VALUE = DEFAULT_SCALE_VALUE;
  2871. const DEFAULT_SCALE = 1.0;
  2872. exports.DEFAULT_SCALE = DEFAULT_SCALE;
  2873. const DEFAULT_SCALE_DELTA = 1.1;
  2874. exports.DEFAULT_SCALE_DELTA = DEFAULT_SCALE_DELTA;
  2875. const MIN_SCALE = 0.1;
  2876. exports.MIN_SCALE = MIN_SCALE;
  2877. const MAX_SCALE = 10.0;
  2878. exports.MAX_SCALE = MAX_SCALE;
  2879. const UNKNOWN_SCALE = 0;
  2880. exports.UNKNOWN_SCALE = UNKNOWN_SCALE;
  2881. const MAX_AUTO_SCALE = 1.25;
  2882. exports.MAX_AUTO_SCALE = MAX_AUTO_SCALE;
  2883. const SCROLLBAR_PADDING = 40;
  2884. exports.SCROLLBAR_PADDING = SCROLLBAR_PADDING;
  2885. const VERTICAL_PADDING = 5;
  2886. exports.VERTICAL_PADDING = VERTICAL_PADDING;
  2887. const RenderingStates = {
  2888. INITIAL: 0,
  2889. RUNNING: 1,
  2890. PAUSED: 2,
  2891. FINISHED: 3,
  2892. };
  2893. exports.RenderingStates = RenderingStates;
  2894. const PresentationModeState = {
  2895. UNKNOWN: 0,
  2896. NORMAL: 1,
  2897. CHANGING: 2,
  2898. FULLSCREEN: 3,
  2899. };
  2900. exports.PresentationModeState = PresentationModeState;
  2901. const SidebarView = {
  2902. UNKNOWN: -1,
  2903. NONE: 0,
  2904. THUMBS: 1,
  2905. OUTLINE: 2,
  2906. ATTACHMENTS: 3,
  2907. LAYERS: 4,
  2908. };
  2909. exports.SidebarView = SidebarView;
  2910. const RendererType = {
  2911. CANVAS: "canvas",
  2912. SVG: "svg",
  2913. };
  2914. exports.RendererType = RendererType;
  2915. const TextLayerMode = {
  2916. DISABLE: 0,
  2917. ENABLE: 1,
  2918. };
  2919. exports.TextLayerMode = TextLayerMode;
  2920. const ScrollMode = {
  2921. UNKNOWN: -1,
  2922. VERTICAL: 0,
  2923. HORIZONTAL: 1,
  2924. WRAPPED: 2,
  2925. PAGE: 3,
  2926. };
  2927. exports.ScrollMode = ScrollMode;
  2928. const SpreadMode = {
  2929. UNKNOWN: -1,
  2930. NONE: 0,
  2931. ODD: 1,
  2932. EVEN: 2,
  2933. };
  2934. exports.SpreadMode = SpreadMode;
  2935. const CursorTool = {
  2936. SELECT: 0,
  2937. HAND: 1,
  2938. ZOOM: 2,
  2939. };
  2940. exports.CursorTool = CursorTool;
  2941. const AutoPrintRegExp = /\bprint\s*\(/;
  2942. exports.AutoPrintRegExp = AutoPrintRegExp;
  2943. class OutputScale {
  2944. constructor() {
  2945. const pixelRatio = window.devicePixelRatio || 1;
  2946. this.sx = pixelRatio;
  2947. this.sy = pixelRatio;
  2948. }
  2949. get scaled() {
  2950. return this.sx !== 1 || this.sy !== 1;
  2951. }
  2952. }
  2953. exports.OutputScale = OutputScale;
  2954. function scrollIntoView(element, spot, scrollMatches = false) {
  2955. let parent = element.offsetParent;
  2956. if (!parent) {
  2957. console.error("offsetParent is not set -- cannot scroll");
  2958. return;
  2959. }
  2960. let offsetY = element.offsetTop + element.clientTop;
  2961. let offsetX = element.offsetLeft + element.clientLeft;
  2962. while (
  2963. (parent.clientHeight === parent.scrollHeight &&
  2964. parent.clientWidth === parent.scrollWidth) ||
  2965. (scrollMatches &&
  2966. (parent.classList.contains("markedContent") ||
  2967. getComputedStyle(parent).overflow === "hidden"))
  2968. ) {
  2969. offsetY += parent.offsetTop;
  2970. offsetX += parent.offsetLeft;
  2971. parent = parent.offsetParent;
  2972. if (!parent) {
  2973. return;
  2974. }
  2975. }
  2976. if (spot) {
  2977. if (spot.top !== undefined) {
  2978. offsetY += spot.top;
  2979. }
  2980. if (spot.left !== undefined) {
  2981. offsetX += spot.left;
  2982. parent.scrollLeft = offsetX;
  2983. }
  2984. }
  2985. parent.scrollTop = offsetY;
  2986. }
  2987. function watchScroll(viewAreaElement, callback) {
  2988. const debounceScroll = function (evt) {
  2989. if (rAF) {
  2990. return;
  2991. }
  2992. rAF = window.requestAnimationFrame(
  2993. function viewAreaElementScrolled() {
  2994. rAF = null;
  2995. const currentX = viewAreaElement.scrollLeft;
  2996. const lastX = state.lastX;
  2997. if (currentX !== lastX) {
  2998. state.right = currentX > lastX;
  2999. }
  3000. state.lastX = currentX;
  3001. const currentY = viewAreaElement.scrollTop;
  3002. const lastY = state.lastY;
  3003. if (currentY !== lastY) {
  3004. state.down = currentY > lastY;
  3005. }
  3006. state.lastY = currentY;
  3007. callback(state);
  3008. }
  3009. );
  3010. };
  3011. const state = {
  3012. right: true,
  3013. down: true,
  3014. lastX: viewAreaElement.scrollLeft,
  3015. lastY: viewAreaElement.scrollTop,
  3016. _eventHandler: debounceScroll,
  3017. };
  3018. let rAF = null;
  3019. viewAreaElement.addEventListener("scroll", debounceScroll, true);
  3020. return state;
  3021. }
  3022. function parseQueryString(query) {
  3023. const params = new Map();
  3024. for (const [key, value] of new URLSearchParams(query)) {
  3025. params.set(key.toLowerCase(), value);
  3026. }
  3027. return params;
  3028. }
  3029. const InvisibleCharactersRegExp = /[\x01-\x1F]/g;
  3030. function removeNullCharacters(str, replaceInvisible = false) {
  3031. if (typeof str !== "string") {
  3032. console.error(`The argument must be a string.`);
  3033. return str;
  3034. }
  3035. if (replaceInvisible) {
  3036. str = str.replaceAll(InvisibleCharactersRegExp, " ");
  3037. }
  3038. return str.replaceAll("\x00", "");
  3039. }
  3040. function binarySearchFirstItem(items, condition, start = 0) {
  3041. let minIndex = start;
  3042. let maxIndex = items.length - 1;
  3043. if (maxIndex < 0 || !condition(items[maxIndex])) {
  3044. return items.length;
  3045. }
  3046. if (condition(items[minIndex])) {
  3047. return minIndex;
  3048. }
  3049. while (minIndex < maxIndex) {
  3050. const currentIndex = (minIndex + maxIndex) >> 1;
  3051. const currentItem = items[currentIndex];
  3052. if (condition(currentItem)) {
  3053. maxIndex = currentIndex;
  3054. } else {
  3055. minIndex = currentIndex + 1;
  3056. }
  3057. }
  3058. return minIndex;
  3059. }
  3060. function approximateFraction(x) {
  3061. if (Math.floor(x) === x) {
  3062. return [x, 1];
  3063. }
  3064. const xinv = 1 / x;
  3065. const limit = 8;
  3066. if (xinv > limit) {
  3067. return [1, limit];
  3068. } else if (Math.floor(xinv) === xinv) {
  3069. return [1, xinv];
  3070. }
  3071. const x_ = x > 1 ? xinv : x;
  3072. let a = 0,
  3073. b = 1,
  3074. c = 1,
  3075. d = 1;
  3076. while (true) {
  3077. const p = a + c,
  3078. q = b + d;
  3079. if (q > limit) {
  3080. break;
  3081. }
  3082. if (x_ <= p / q) {
  3083. c = p;
  3084. d = q;
  3085. } else {
  3086. a = p;
  3087. b = q;
  3088. }
  3089. }
  3090. let result;
  3091. if (x_ - a / b < c / d - x_) {
  3092. result = x_ === x ? [a, b] : [b, a];
  3093. } else {
  3094. result = x_ === x ? [c, d] : [d, c];
  3095. }
  3096. return result;
  3097. }
  3098. function roundToDivide(x, div) {
  3099. const r = x % div;
  3100. return r === 0 ? x : Math.round(x - r + div);
  3101. }
  3102. function getPageSizeInches({ view, userUnit, rotate }) {
  3103. const [x1, y1, x2, y2] = view;
  3104. const changeOrientation = rotate % 180 !== 0;
  3105. const width = ((x2 - x1) / 72) * userUnit;
  3106. const height = ((y2 - y1) / 72) * userUnit;
  3107. return {
  3108. width: changeOrientation ? height : width,
  3109. height: changeOrientation ? width : height,
  3110. };
  3111. }
  3112. function backtrackBeforeAllVisibleElements(index, views, top) {
  3113. if (index < 2) {
  3114. return index;
  3115. }
  3116. let elt = views[index].div;
  3117. let pageTop = elt.offsetTop + elt.clientTop;
  3118. if (pageTop >= top) {
  3119. elt = views[index - 1].div;
  3120. pageTop = elt.offsetTop + elt.clientTop;
  3121. }
  3122. for (let i = index - 2; i >= 0; --i) {
  3123. elt = views[i].div;
  3124. if (elt.offsetTop + elt.clientTop + elt.clientHeight <= pageTop) {
  3125. break;
  3126. }
  3127. index = i;
  3128. }
  3129. return index;
  3130. }
  3131. function getVisibleElements({
  3132. scrollEl,
  3133. views,
  3134. sortByVisibility = false,
  3135. horizontal = false,
  3136. rtl = false,
  3137. }) {
  3138. const top = scrollEl.scrollTop,
  3139. bottom = top + scrollEl.clientHeight;
  3140. const left = scrollEl.scrollLeft,
  3141. right = left + scrollEl.clientWidth;
  3142. function isElementBottomAfterViewTop(view) {
  3143. const element = view.div;
  3144. const elementBottom =
  3145. element.offsetTop + element.clientTop + element.clientHeight;
  3146. return elementBottom > top;
  3147. }
  3148. function isElementNextAfterViewHorizontally(view) {
  3149. const element = view.div;
  3150. const elementLeft = element.offsetLeft + element.clientLeft;
  3151. const elementRight = elementLeft + element.clientWidth;
  3152. return rtl ? elementLeft < right : elementRight > left;
  3153. }
  3154. const visible = [],
  3155. ids = new Set(),
  3156. numViews = views.length;
  3157. let firstVisibleElementInd = binarySearchFirstItem(
  3158. views,
  3159. horizontal
  3160. ? isElementNextAfterViewHorizontally
  3161. : isElementBottomAfterViewTop
  3162. );
  3163. if (
  3164. firstVisibleElementInd > 0 &&
  3165. firstVisibleElementInd < numViews &&
  3166. !horizontal
  3167. ) {
  3168. firstVisibleElementInd = backtrackBeforeAllVisibleElements(
  3169. firstVisibleElementInd,
  3170. views,
  3171. top
  3172. );
  3173. }
  3174. let lastEdge = horizontal ? right : -1;
  3175. for (let i = firstVisibleElementInd; i < numViews; i++) {
  3176. const view = views[i],
  3177. element = view.div;
  3178. const currentWidth = element.offsetLeft + element.clientLeft;
  3179. const currentHeight = element.offsetTop + element.clientTop;
  3180. const viewWidth = element.clientWidth,
  3181. viewHeight = element.clientHeight;
  3182. const viewRight = currentWidth + viewWidth;
  3183. const viewBottom = currentHeight + viewHeight;
  3184. if (lastEdge === -1) {
  3185. if (viewBottom >= bottom) {
  3186. lastEdge = viewBottom;
  3187. }
  3188. } else if ((horizontal ? currentWidth : currentHeight) > lastEdge) {
  3189. break;
  3190. }
  3191. if (
  3192. viewBottom <= top ||
  3193. currentHeight >= bottom ||
  3194. viewRight <= left ||
  3195. currentWidth >= right
  3196. ) {
  3197. continue;
  3198. }
  3199. const hiddenHeight =
  3200. Math.max(0, top - currentHeight) + Math.max(0, viewBottom - bottom);
  3201. const hiddenWidth =
  3202. Math.max(0, left - currentWidth) + Math.max(0, viewRight - right);
  3203. const fractionHeight = (viewHeight - hiddenHeight) / viewHeight,
  3204. fractionWidth = (viewWidth - hiddenWidth) / viewWidth;
  3205. const percent = (fractionHeight * fractionWidth * 100) | 0;
  3206. visible.push({
  3207. id: view.id,
  3208. x: currentWidth,
  3209. y: currentHeight,
  3210. view,
  3211. percent,
  3212. widthPercent: (fractionWidth * 100) | 0,
  3213. });
  3214. ids.add(view.id);
  3215. }
  3216. const first = visible[0],
  3217. last = visible.at(-1);
  3218. if (sortByVisibility) {
  3219. visible.sort(function (a, b) {
  3220. const pc = a.percent - b.percent;
  3221. if (Math.abs(pc) > 0.001) {
  3222. return -pc;
  3223. }
  3224. return a.id - b.id;
  3225. });
  3226. }
  3227. return {
  3228. first,
  3229. last,
  3230. views: visible,
  3231. ids,
  3232. };
  3233. }
  3234. function noContextMenuHandler(evt) {
  3235. evt.preventDefault();
  3236. }
  3237. function normalizeWheelEventDirection(evt) {
  3238. let delta = Math.hypot(evt.deltaX, evt.deltaY);
  3239. const angle = Math.atan2(evt.deltaY, evt.deltaX);
  3240. if (-0.25 * Math.PI < angle && angle < 0.75 * Math.PI) {
  3241. delta = -delta;
  3242. }
  3243. return delta;
  3244. }
  3245. function normalizeWheelEventDelta(evt) {
  3246. const deltaMode = evt.deltaMode;
  3247. let delta = normalizeWheelEventDirection(evt);
  3248. const MOUSE_PIXELS_PER_LINE = 30;
  3249. const MOUSE_LINES_PER_PAGE = 30;
  3250. if (deltaMode === WheelEvent.DOM_DELTA_PIXEL) {
  3251. delta /= MOUSE_PIXELS_PER_LINE * MOUSE_LINES_PER_PAGE;
  3252. } else if (deltaMode === WheelEvent.DOM_DELTA_LINE) {
  3253. delta /= MOUSE_LINES_PER_PAGE;
  3254. }
  3255. return delta;
  3256. }
  3257. function isValidRotation(angle) {
  3258. return Number.isInteger(angle) && angle % 90 === 0;
  3259. }
  3260. function isValidScrollMode(mode) {
  3261. return (
  3262. Number.isInteger(mode) &&
  3263. Object.values(ScrollMode).includes(mode) &&
  3264. mode !== ScrollMode.UNKNOWN
  3265. );
  3266. }
  3267. function isValidSpreadMode(mode) {
  3268. return (
  3269. Number.isInteger(mode) &&
  3270. Object.values(SpreadMode).includes(mode) &&
  3271. mode !== SpreadMode.UNKNOWN
  3272. );
  3273. }
  3274. function isPortraitOrientation(size) {
  3275. return size.width <= size.height;
  3276. }
  3277. const animationStarted = new Promise(function (resolve) {
  3278. window.requestAnimationFrame(resolve);
  3279. });
  3280. exports.animationStarted = animationStarted;
  3281. const docStyle = document.documentElement.style;
  3282. exports.docStyle = docStyle;
  3283. function clamp(v, min, max) {
  3284. return Math.min(Math.max(v, min), max);
  3285. }
  3286. class ProgressBar {
  3287. #classList = null;
  3288. #disableAutoFetchTimeout = null;
  3289. #percent = 0;
  3290. #style = null;
  3291. #visible = true;
  3292. constructor(bar) {
  3293. this.#classList = bar.classList;
  3294. this.#style = bar.style;
  3295. }
  3296. get percent() {
  3297. return this.#percent;
  3298. }
  3299. set percent(val) {
  3300. this.#percent = clamp(val, 0, 100);
  3301. if (isNaN(val)) {
  3302. this.#classList.add("indeterminate");
  3303. return;
  3304. }
  3305. this.#classList.remove("indeterminate");
  3306. this.#style.setProperty("--progressBar-percent", `${this.#percent}%`);
  3307. }
  3308. setWidth(viewer) {
  3309. if (!viewer) {
  3310. return;
  3311. }
  3312. const container = viewer.parentNode;
  3313. const scrollbarWidth = container.offsetWidth - viewer.offsetWidth;
  3314. if (scrollbarWidth > 0) {
  3315. this.#style.setProperty(
  3316. "--progressBar-end-offset",
  3317. `${scrollbarWidth}px`
  3318. );
  3319. }
  3320. }
  3321. setDisableAutoFetch(delay = 5000) {
  3322. if (isNaN(this.#percent)) {
  3323. return;
  3324. }
  3325. if (this.#disableAutoFetchTimeout) {
  3326. clearTimeout(this.#disableAutoFetchTimeout);
  3327. }
  3328. this.show();
  3329. this.#disableAutoFetchTimeout = setTimeout(() => {
  3330. this.#disableAutoFetchTimeout = null;
  3331. this.hide();
  3332. }, delay);
  3333. }
  3334. hide() {
  3335. if (!this.#visible) {
  3336. return;
  3337. }
  3338. this.#visible = false;
  3339. this.#classList.add("hidden");
  3340. }
  3341. show() {
  3342. if (this.#visible) {
  3343. return;
  3344. }
  3345. this.#visible = true;
  3346. this.#classList.remove("hidden");
  3347. }
  3348. }
  3349. exports.ProgressBar = ProgressBar;
  3350. function getActiveOrFocusedElement() {
  3351. let curRoot = document;
  3352. let curActiveOrFocused =
  3353. curRoot.activeElement || curRoot.querySelector(":focus");
  3354. while (curActiveOrFocused?.shadowRoot) {
  3355. curRoot = curActiveOrFocused.shadowRoot;
  3356. curActiveOrFocused =
  3357. curRoot.activeElement || curRoot.querySelector(":focus");
  3358. }
  3359. return curActiveOrFocused;
  3360. }
  3361. function apiPageLayoutToViewerModes(layout) {
  3362. let scrollMode = ScrollMode.VERTICAL,
  3363. spreadMode = SpreadMode.NONE;
  3364. switch (layout) {
  3365. case "SinglePage":
  3366. scrollMode = ScrollMode.PAGE;
  3367. break;
  3368. case "OneColumn":
  3369. break;
  3370. case "TwoPageLeft":
  3371. scrollMode = ScrollMode.PAGE;
  3372. case "TwoColumnLeft":
  3373. spreadMode = SpreadMode.ODD;
  3374. break;
  3375. case "TwoPageRight":
  3376. scrollMode = ScrollMode.PAGE;
  3377. case "TwoColumnRight":
  3378. spreadMode = SpreadMode.EVEN;
  3379. break;
  3380. }
  3381. return {
  3382. scrollMode,
  3383. spreadMode,
  3384. };
  3385. }
  3386. function apiPageModeToSidebarView(mode) {
  3387. switch (mode) {
  3388. case "UseNone":
  3389. return SidebarView.NONE;
  3390. case "UseThumbs":
  3391. return SidebarView.THUMBS;
  3392. case "UseOutlines":
  3393. return SidebarView.OUTLINE;
  3394. case "UseAttachments":
  3395. return SidebarView.ATTACHMENTS;
  3396. case "UseOC":
  3397. return SidebarView.LAYERS;
  3398. }
  3399. return SidebarView.NONE;
  3400. }
  3401. /***/
  3402. },
  3403. /* 4 */
  3404. /***/ (module) => {
  3405. let pdfjsLib;
  3406. if (typeof window !== "undefined" && window["pdfjs-dist/build/pdf"]) {
  3407. pdfjsLib = window["pdfjs-dist/build/pdf"];
  3408. } else {
  3409. pdfjsLib = require("../build/pdf.js");
  3410. }
  3411. module.exports = pdfjsLib;
  3412. /***/
  3413. },
  3414. /* 5 */
  3415. /***/ (__unused_webpack_module, exports) => {
  3416. Object.defineProperty(exports, "__esModule", {
  3417. value: true,
  3418. });
  3419. exports.compatibilityParams =
  3420. exports.OptionKind =
  3421. exports.AppOptions =
  3422. void 0;
  3423. const compatibilityParams = Object.create(null);
  3424. exports.compatibilityParams = compatibilityParams;
  3425. {
  3426. const userAgent = navigator.userAgent || "";
  3427. const platform = navigator.platform || "";
  3428. const maxTouchPoints = navigator.maxTouchPoints || 1;
  3429. const isAndroid = /Android/.test(userAgent);
  3430. const isIOS =
  3431. /\b(iPad|iPhone|iPod)(?=;)/.test(userAgent) ||
  3432. (platform === "MacIntel" && maxTouchPoints > 1);
  3433. (function checkCanvasSizeLimitation() {
  3434. if (isIOS || isAndroid) {
  3435. compatibilityParams.maxCanvasPixels = 5242880;
  3436. }
  3437. })();
  3438. }
  3439. const OptionKind = {
  3440. VIEWER: 0x02,
  3441. API: 0x04,
  3442. WORKER: 0x08,
  3443. PREFERENCE: 0x80,
  3444. };
  3445. exports.OptionKind = OptionKind;
  3446. const defaultOptions = {
  3447. annotationEditorMode: {
  3448. value: 0,
  3449. kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
  3450. },
  3451. annotationMode: {
  3452. value: 2,
  3453. kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
  3454. },
  3455. cursorToolOnLoad: {
  3456. value: 0,
  3457. kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
  3458. },
  3459. defaultZoomDelay: {
  3460. value: 400,
  3461. kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
  3462. },
  3463. defaultZoomValue: {
  3464. value: "",
  3465. kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
  3466. },
  3467. disableHistory: {
  3468. value: false,
  3469. kind: OptionKind.VIEWER,
  3470. },
  3471. disablePageLabels: {
  3472. value: false,
  3473. kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
  3474. },
  3475. enablePermissions: {
  3476. value: false,
  3477. kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
  3478. },
  3479. enablePrintAutoRotate: {
  3480. value: true,
  3481. kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
  3482. },
  3483. enableScripting: {
  3484. value: true,
  3485. kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
  3486. },
  3487. externalLinkRel: {
  3488. value: "noopener noreferrer nofollow",
  3489. kind: OptionKind.VIEWER,
  3490. },
  3491. externalLinkTarget: {
  3492. value: 0,
  3493. kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
  3494. },
  3495. historyUpdateUrl: {
  3496. value: false,
  3497. kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
  3498. },
  3499. ignoreDestinationZoom: {
  3500. value: false,
  3501. kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
  3502. },
  3503. imageResourcesPath: {
  3504. value: "./images/",
  3505. kind: OptionKind.VIEWER,
  3506. },
  3507. maxCanvasPixels: {
  3508. value: 16777216,
  3509. kind: OptionKind.VIEWER,
  3510. },
  3511. forcePageColors: {
  3512. value: false,
  3513. kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
  3514. },
  3515. pageColorsBackground: {
  3516. value: "Canvas",
  3517. kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
  3518. },
  3519. pageColorsForeground: {
  3520. value: "CanvasText",
  3521. kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
  3522. },
  3523. pdfBugEnabled: {
  3524. value: false,
  3525. kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
  3526. },
  3527. printResolution: {
  3528. value: 150,
  3529. kind: OptionKind.VIEWER,
  3530. },
  3531. sidebarViewOnLoad: {
  3532. value: -1,
  3533. kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
  3534. },
  3535. scrollModeOnLoad: {
  3536. value: -1,
  3537. kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
  3538. },
  3539. spreadModeOnLoad: {
  3540. value: -1,
  3541. kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
  3542. },
  3543. textLayerMode: {
  3544. value: 1,
  3545. kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
  3546. },
  3547. useOnlyCssZoom: {
  3548. value: false,
  3549. kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
  3550. },
  3551. viewerCssTheme: {
  3552. value: 0,
  3553. kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
  3554. },
  3555. viewOnLoad: {
  3556. value: 0,
  3557. kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
  3558. },
  3559. cMapPacked: {
  3560. value: true,
  3561. kind: OptionKind.API,
  3562. },
  3563. cMapUrl: {
  3564. value: "../web/cmaps/",
  3565. kind: OptionKind.API,
  3566. },
  3567. disableAutoFetch: {
  3568. value: false,
  3569. kind: OptionKind.API + OptionKind.PREFERENCE,
  3570. },
  3571. disableFontFace: {
  3572. value: false,
  3573. kind: OptionKind.API + OptionKind.PREFERENCE,
  3574. },
  3575. disableRange: {
  3576. value: false,
  3577. kind: OptionKind.API + OptionKind.PREFERENCE,
  3578. },
  3579. disableStream: {
  3580. value: false,
  3581. kind: OptionKind.API + OptionKind.PREFERENCE,
  3582. },
  3583. docBaseUrl: {
  3584. value: "",
  3585. kind: OptionKind.API,
  3586. },
  3587. enableXfa: {
  3588. value: true,
  3589. kind: OptionKind.API + OptionKind.PREFERENCE,
  3590. },
  3591. fontExtraProperties: {
  3592. value: false,
  3593. kind: OptionKind.API,
  3594. },
  3595. isEvalSupported: {
  3596. value: true,
  3597. kind: OptionKind.API,
  3598. },
  3599. isOffscreenCanvasSupported: {
  3600. value: true,
  3601. kind: OptionKind.API,
  3602. },
  3603. maxImageSize: {
  3604. value: -1,
  3605. kind: OptionKind.API,
  3606. },
  3607. pdfBug: {
  3608. value: false,
  3609. kind: OptionKind.API,
  3610. },
  3611. standardFontDataUrl: {
  3612. value: "../web/standard_fonts/",
  3613. kind: OptionKind.API,
  3614. },
  3615. verbosity: {
  3616. value: 1,
  3617. kind: OptionKind.API,
  3618. },
  3619. workerPort: {
  3620. value: null,
  3621. kind: OptionKind.WORKER,
  3622. },
  3623. workerSrc: {
  3624. value: "../build/pdf.worker.js",
  3625. kind: OptionKind.WORKER,
  3626. },
  3627. };
  3628. {
  3629. defaultOptions.defaultUrl = {
  3630. value: "compressed.tracemonkey-pldi-09.pdf",
  3631. kind: OptionKind.VIEWER,
  3632. };
  3633. defaultOptions.disablePreferences = {
  3634. value: false,
  3635. kind: OptionKind.VIEWER,
  3636. };
  3637. defaultOptions.locale = {
  3638. value: navigator.language || "en-US",
  3639. kind: OptionKind.VIEWER,
  3640. };
  3641. defaultOptions.renderer = {
  3642. value: "canvas",
  3643. kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
  3644. };
  3645. defaultOptions.sandboxBundleSrc = {
  3646. value: "../build/pdf.sandbox.js",
  3647. kind: OptionKind.VIEWER,
  3648. };
  3649. }
  3650. const userOptions = Object.create(null);
  3651. class AppOptions {
  3652. constructor() {
  3653. throw new Error("Cannot initialize AppOptions.");
  3654. }
  3655. static get(name) {
  3656. const userOption = userOptions[name];
  3657. if (userOption !== undefined) {
  3658. return userOption;
  3659. }
  3660. const defaultOption = defaultOptions[name];
  3661. if (defaultOption !== undefined) {
  3662. return compatibilityParams[name] ?? defaultOption.value;
  3663. }
  3664. return undefined;
  3665. }
  3666. static getAll(kind = null) {
  3667. const options = Object.create(null);
  3668. for (const name in defaultOptions) {
  3669. const defaultOption = defaultOptions[name];
  3670. if (kind) {
  3671. if ((kind & defaultOption.kind) === 0) {
  3672. continue;
  3673. }
  3674. if (kind === OptionKind.PREFERENCE) {
  3675. const value = defaultOption.value,
  3676. valueType = typeof value;
  3677. if (
  3678. valueType === "boolean" ||
  3679. valueType === "string" ||
  3680. (valueType === "number" && Number.isInteger(value))
  3681. ) {
  3682. options[name] = value;
  3683. continue;
  3684. }
  3685. throw new Error(`Invalid type for preference: ${name}`);
  3686. }
  3687. }
  3688. const userOption = userOptions[name];
  3689. options[name] =
  3690. userOption !== undefined
  3691. ? userOption
  3692. : compatibilityParams[name] ?? defaultOption.value;
  3693. }
  3694. return options;
  3695. }
  3696. static set(name, value) {
  3697. userOptions[name] = value;
  3698. }
  3699. static setAll(options) {
  3700. for (const name in options) {
  3701. userOptions[name] = options[name];
  3702. }
  3703. }
  3704. static remove(name) {
  3705. delete userOptions[name];
  3706. }
  3707. }
  3708. exports.AppOptions = AppOptions;
  3709. {
  3710. AppOptions._hasUserOptions = function () {
  3711. return Object.keys(userOptions).length > 0;
  3712. };
  3713. }
  3714. /***/
  3715. },
  3716. /* 6 */
  3717. /***/ (__unused_webpack_module, exports) => {
  3718. Object.defineProperty(exports, "__esModule", {
  3719. value: true,
  3720. });
  3721. exports.WaitOnType =
  3722. exports.EventBus =
  3723. exports.AutomationEventBus =
  3724. void 0;
  3725. exports.waitOnEventOrTimeout = waitOnEventOrTimeout;
  3726. const WaitOnType = {
  3727. EVENT: "event",
  3728. TIMEOUT: "timeout",
  3729. };
  3730. exports.WaitOnType = WaitOnType;
  3731. function waitOnEventOrTimeout({ target, name, delay = 0 }) {
  3732. return new Promise(function (resolve, reject) {
  3733. if (
  3734. typeof target !== "object" ||
  3735. !(name && typeof name === "string") ||
  3736. !(Number.isInteger(delay) && delay >= 0)
  3737. ) {
  3738. throw new Error("waitOnEventOrTimeout - invalid parameters.");
  3739. }
  3740. function handler(type) {
  3741. if (target instanceof EventBus) {
  3742. target._off(name, eventHandler);
  3743. } else {
  3744. target.removeEventListener(name, eventHandler);
  3745. }
  3746. if (timeout) {
  3747. clearTimeout(timeout);
  3748. }
  3749. resolve(type);
  3750. }
  3751. const eventHandler = handler.bind(null, WaitOnType.EVENT);
  3752. if (target instanceof EventBus) {
  3753. target._on(name, eventHandler);
  3754. } else {
  3755. target.addEventListener(name, eventHandler);
  3756. }
  3757. const timeoutHandler = handler.bind(null, WaitOnType.TIMEOUT);
  3758. const timeout = setTimeout(timeoutHandler, delay);
  3759. });
  3760. }
  3761. class EventBus {
  3762. #listeners = Object.create(null);
  3763. on(eventName, listener, options = null) {
  3764. this._on(eventName, listener, {
  3765. external: true,
  3766. once: options?.once,
  3767. });
  3768. }
  3769. off(eventName, listener, options = null) {
  3770. this._off(eventName, listener, {
  3771. external: true,
  3772. once: options?.once,
  3773. });
  3774. }
  3775. dispatch(eventName, data) {
  3776. const eventListeners = this.#listeners[eventName];
  3777. if (!eventListeners || eventListeners.length === 0) {
  3778. return;
  3779. }
  3780. let externalListeners;
  3781. for (const { listener, external, once } of eventListeners.slice(0)) {
  3782. if (once) {
  3783. this._off(eventName, listener);
  3784. }
  3785. if (external) {
  3786. (externalListeners ||= []).push(listener);
  3787. continue;
  3788. }
  3789. listener(data);
  3790. }
  3791. if (externalListeners) {
  3792. for (const listener of externalListeners) {
  3793. listener(data);
  3794. }
  3795. externalListeners = null;
  3796. }
  3797. }
  3798. _on(eventName, listener, options = null) {
  3799. const eventListeners = (this.#listeners[eventName] ||= []);
  3800. eventListeners.push({
  3801. listener,
  3802. external: options?.external === true,
  3803. once: options?.once === true,
  3804. });
  3805. }
  3806. _off(eventName, listener, options = null) {
  3807. const eventListeners = this.#listeners[eventName];
  3808. if (!eventListeners) {
  3809. return;
  3810. }
  3811. for (let i = 0, ii = eventListeners.length; i < ii; i++) {
  3812. if (eventListeners[i].listener === listener) {
  3813. eventListeners.splice(i, 1);
  3814. return;
  3815. }
  3816. }
  3817. }
  3818. }
  3819. exports.EventBus = EventBus;
  3820. class AutomationEventBus extends EventBus {
  3821. dispatch(eventName, data) {
  3822. throw new Error("Not implemented: AutomationEventBus.dispatch");
  3823. }
  3824. }
  3825. exports.AutomationEventBus = AutomationEventBus;
  3826. /***/
  3827. },
  3828. /* 7 */
  3829. /***/ (__unused_webpack_module, exports, __webpack_require__) => {
  3830. Object.defineProperty(exports, "__esModule", {
  3831. value: true,
  3832. });
  3833. exports.SimpleLinkService =
  3834. exports.PDFLinkService =
  3835. exports.LinkTarget =
  3836. void 0;
  3837. var _ui_utils = __webpack_require__(3);
  3838. const DEFAULT_LINK_REL = "noopener noreferrer nofollow";
  3839. const LinkTarget = {
  3840. NONE: 0,
  3841. SELF: 1,
  3842. BLANK: 2,
  3843. PARENT: 3,
  3844. TOP: 4,
  3845. };
  3846. exports.LinkTarget = LinkTarget;
  3847. function addLinkAttributes(
  3848. link,
  3849. { url, target, rel, enabled = true } = {}
  3850. ) {
  3851. if (!url || typeof url !== "string") {
  3852. throw new Error('A valid "url" parameter must provided.');
  3853. }
  3854. const urlNullRemoved = (0, _ui_utils.removeNullCharacters)(url);
  3855. if (enabled) {
  3856. link.href = link.title = urlNullRemoved;
  3857. } else {
  3858. link.href = "";
  3859. link.title = `Disabled: ${urlNullRemoved}`;
  3860. link.onclick = () => {
  3861. return false;
  3862. };
  3863. }
  3864. let targetStr = "";
  3865. switch (target) {
  3866. case LinkTarget.NONE:
  3867. break;
  3868. case LinkTarget.SELF:
  3869. targetStr = "_self";
  3870. break;
  3871. case LinkTarget.BLANK:
  3872. targetStr = "_blank";
  3873. break;
  3874. case LinkTarget.PARENT:
  3875. targetStr = "_parent";
  3876. break;
  3877. case LinkTarget.TOP:
  3878. targetStr = "_top";
  3879. break;
  3880. }
  3881. link.target = targetStr;
  3882. link.rel = typeof rel === "string" ? rel : DEFAULT_LINK_REL;
  3883. }
  3884. class PDFLinkService {
  3885. #pagesRefCache = new Map();
  3886. constructor({
  3887. eventBus,
  3888. externalLinkTarget = null,
  3889. externalLinkRel = null,
  3890. ignoreDestinationZoom = false,
  3891. } = {}) {
  3892. this.eventBus = eventBus;
  3893. this.externalLinkTarget = externalLinkTarget;
  3894. this.externalLinkRel = externalLinkRel;
  3895. this.externalLinkEnabled = true;
  3896. this._ignoreDestinationZoom = ignoreDestinationZoom;
  3897. this.baseUrl = null;
  3898. this.pdfDocument = null;
  3899. this.pdfViewer = null;
  3900. this.pdfHistory = null;
  3901. }
  3902. setDocument(pdfDocument, baseUrl = null) {
  3903. this.baseUrl = baseUrl;
  3904. this.pdfDocument = pdfDocument;
  3905. this.#pagesRefCache.clear();
  3906. }
  3907. setViewer(pdfViewer) {
  3908. this.pdfViewer = pdfViewer;
  3909. }
  3910. setHistory(pdfHistory) {
  3911. this.pdfHistory = pdfHistory;
  3912. }
  3913. get pagesCount() {
  3914. return this.pdfDocument ? this.pdfDocument.numPages : 0;
  3915. }
  3916. get page() {
  3917. return this.pdfViewer.currentPageNumber;
  3918. }
  3919. set page(value) {
  3920. this.pdfViewer.currentPageNumber = value;
  3921. }
  3922. get rotation() {
  3923. return this.pdfViewer.pagesRotation;
  3924. }
  3925. set rotation(value) {
  3926. this.pdfViewer.pagesRotation = value;
  3927. }
  3928. get isInPresentationMode() {
  3929. return this.pdfViewer.isInPresentationMode;
  3930. }
  3931. #goToDestinationHelper(rawDest, namedDest = null, explicitDest) {
  3932. const destRef = explicitDest[0];
  3933. let pageNumber;
  3934. if (typeof destRef === "object" && destRef !== null) {
  3935. pageNumber = this._cachedPageNumber(destRef);
  3936. if (!pageNumber) {
  3937. this.pdfDocument
  3938. .getPageIndex(destRef)
  3939. .then((pageIndex) => {
  3940. this.cachePageRef(pageIndex + 1, destRef);
  3941. this.#goToDestinationHelper(rawDest, namedDest, explicitDest);
  3942. })
  3943. .catch(() => {
  3944. console.error(
  3945. `PDFLinkService.#goToDestinationHelper: "${destRef}" is not ` +
  3946. `a valid page reference, for dest="${rawDest}".`
  3947. );
  3948. });
  3949. return;
  3950. }
  3951. } else if (Number.isInteger(destRef)) {
  3952. pageNumber = destRef + 1;
  3953. } else {
  3954. console.error(
  3955. `PDFLinkService.#goToDestinationHelper: "${destRef}" is not ` +
  3956. `a valid destination reference, for dest="${rawDest}".`
  3957. );
  3958. return;
  3959. }
  3960. if (!pageNumber || pageNumber < 1 || pageNumber > this.pagesCount) {
  3961. console.error(
  3962. `PDFLinkService.#goToDestinationHelper: "${pageNumber}" is not ` +
  3963. `a valid page number, for dest="${rawDest}".`
  3964. );
  3965. return;
  3966. }
  3967. if (this.pdfHistory) {
  3968. this.pdfHistory.pushCurrentPosition();
  3969. this.pdfHistory.push({
  3970. namedDest,
  3971. explicitDest,
  3972. pageNumber,
  3973. });
  3974. }
  3975. this.pdfViewer.scrollPageIntoView({
  3976. pageNumber,
  3977. destArray: explicitDest,
  3978. ignoreDestinationZoom: this._ignoreDestinationZoom,
  3979. });
  3980. }
  3981. async goToDestination(dest) {
  3982. if (!this.pdfDocument) {
  3983. return;
  3984. }
  3985. let namedDest, explicitDest;
  3986. if (typeof dest === "string") {
  3987. namedDest = dest;
  3988. explicitDest = await this.pdfDocument.getDestination(dest);
  3989. } else {
  3990. namedDest = null;
  3991. explicitDest = await dest;
  3992. }
  3993. if (!Array.isArray(explicitDest)) {
  3994. console.error(
  3995. `PDFLinkService.goToDestination: "${explicitDest}" is not ` +
  3996. `a valid destination array, for dest="${dest}".`
  3997. );
  3998. return;
  3999. }
  4000. this.#goToDestinationHelper(dest, namedDest, explicitDest);
  4001. }
  4002. goToPage(val) {
  4003. if (!this.pdfDocument) {
  4004. return;
  4005. }
  4006. const pageNumber =
  4007. (typeof val === "string" &&
  4008. this.pdfViewer.pageLabelToPageNumber(val)) ||
  4009. val | 0;
  4010. if (
  4011. !(
  4012. Number.isInteger(pageNumber) &&
  4013. pageNumber > 0 &&
  4014. pageNumber <= this.pagesCount
  4015. )
  4016. ) {
  4017. console.error(
  4018. `PDFLinkService.goToPage: "${val}" is not a valid page.`
  4019. );
  4020. return;
  4021. }
  4022. if (this.pdfHistory) {
  4023. this.pdfHistory.pushCurrentPosition();
  4024. this.pdfHistory.pushPage(pageNumber);
  4025. }
  4026. this.pdfViewer.scrollPageIntoView({
  4027. pageNumber,
  4028. });
  4029. }
  4030. addLinkAttributes(link, url, newWindow = false) {
  4031. addLinkAttributes(link, {
  4032. url,
  4033. target: newWindow ? LinkTarget.BLANK : this.externalLinkTarget,
  4034. rel: this.externalLinkRel,
  4035. enabled: this.externalLinkEnabled,
  4036. });
  4037. }
  4038. getDestinationHash(dest) {
  4039. if (typeof dest === "string") {
  4040. if (dest.length > 0) {
  4041. return this.getAnchorUrl("#" + escape(dest));
  4042. }
  4043. } else if (Array.isArray(dest)) {
  4044. const str = JSON.stringify(dest);
  4045. if (str.length > 0) {
  4046. return this.getAnchorUrl("#" + escape(str));
  4047. }
  4048. }
  4049. return this.getAnchorUrl("");
  4050. }
  4051. getAnchorUrl(anchor) {
  4052. return this.baseUrl ? this.baseUrl + anchor : anchor;
  4053. }
  4054. setHash(hash) {
  4055. if (!this.pdfDocument) {
  4056. return;
  4057. }
  4058. let pageNumber, dest;
  4059. if (hash.includes("=")) {
  4060. const params = (0, _ui_utils.parseQueryString)(hash);
  4061. if (params.has("search")) {
  4062. this.eventBus.dispatch("findfromurlhash", {
  4063. source: this,
  4064. query: params.get("search").replaceAll('"', ""),
  4065. phraseSearch: params.get("phrase") === "true",
  4066. });
  4067. }
  4068. if (params.has("page")) {
  4069. pageNumber = params.get("page") | 0 || 1;
  4070. }
  4071. if (params.has("zoom")) {
  4072. const zoomArgs = params.get("zoom").split(",");
  4073. const zoomArg = zoomArgs[0];
  4074. const zoomArgNumber = parseFloat(zoomArg);
  4075. if (!zoomArg.includes("Fit")) {
  4076. dest = [
  4077. null,
  4078. {
  4079. name: "XYZ",
  4080. },
  4081. zoomArgs.length > 1 ? zoomArgs[1] | 0 : null,
  4082. zoomArgs.length > 2 ? zoomArgs[2] | 0 : null,
  4083. zoomArgNumber ? zoomArgNumber / 100 : zoomArg,
  4084. ];
  4085. } else {
  4086. if (zoomArg === "Fit" || zoomArg === "FitB") {
  4087. dest = [
  4088. null,
  4089. {
  4090. name: zoomArg,
  4091. },
  4092. ];
  4093. } else if (
  4094. zoomArg === "FitH" ||
  4095. zoomArg === "FitBH" ||
  4096. zoomArg === "FitV" ||
  4097. zoomArg === "FitBV"
  4098. ) {
  4099. dest = [
  4100. null,
  4101. {
  4102. name: zoomArg,
  4103. },
  4104. zoomArgs.length > 1 ? zoomArgs[1] | 0 : null,
  4105. ];
  4106. } else if (zoomArg === "FitR") {
  4107. if (zoomArgs.length !== 5) {
  4108. console.error(
  4109. 'PDFLinkService.setHash: Not enough parameters for "FitR".'
  4110. );
  4111. } else {
  4112. dest = [
  4113. null,
  4114. {
  4115. name: zoomArg,
  4116. },
  4117. zoomArgs[1] | 0,
  4118. zoomArgs[2] | 0,
  4119. zoomArgs[3] | 0,
  4120. zoomArgs[4] | 0,
  4121. ];
  4122. }
  4123. } else {
  4124. console.error(
  4125. `PDFLinkService.setHash: "${zoomArg}" is not a valid zoom value.`
  4126. );
  4127. }
  4128. }
  4129. }
  4130. if (dest) {
  4131. this.pdfViewer.scrollPageIntoView({
  4132. pageNumber: pageNumber || this.page,
  4133. destArray: dest,
  4134. allowNegativeOffset: true,
  4135. });
  4136. } else if (pageNumber) {
  4137. this.page = pageNumber;
  4138. }
  4139. if (params.has("pagemode")) {
  4140. this.eventBus.dispatch("pagemode", {
  4141. source: this,
  4142. mode: params.get("pagemode"),
  4143. });
  4144. }
  4145. if (params.has("nameddest")) {
  4146. this.goToDestination(params.get("nameddest"));
  4147. }
  4148. } else {
  4149. dest = unescape(hash);
  4150. try {
  4151. dest = JSON.parse(dest);
  4152. if (!Array.isArray(dest)) {
  4153. dest = dest.toString();
  4154. }
  4155. } catch (ex) {}
  4156. if (
  4157. typeof dest === "string" ||
  4158. PDFLinkService.#isValidExplicitDestination(dest)
  4159. ) {
  4160. this.goToDestination(dest);
  4161. return;
  4162. }
  4163. console.error(
  4164. `PDFLinkService.setHash: "${unescape(
  4165. hash
  4166. )}" is not a valid destination.`
  4167. );
  4168. }
  4169. }
  4170. executeNamedAction(action) {
  4171. switch (action) {
  4172. case "GoBack":
  4173. this.pdfHistory?.back();
  4174. break;
  4175. case "GoForward":
  4176. this.pdfHistory?.forward();
  4177. break;
  4178. case "NextPage":
  4179. this.pdfViewer.nextPage();
  4180. break;
  4181. case "PrevPage":
  4182. this.pdfViewer.previousPage();
  4183. break;
  4184. case "LastPage":
  4185. this.page = this.pagesCount;
  4186. break;
  4187. case "FirstPage":
  4188. this.page = 1;
  4189. break;
  4190. default:
  4191. break;
  4192. }
  4193. this.eventBus.dispatch("namedaction", {
  4194. source: this,
  4195. action,
  4196. });
  4197. }
  4198. async executeSetOCGState(action) {
  4199. const pdfDocument = this.pdfDocument;
  4200. const optionalContentConfig = await this.pdfViewer
  4201. .optionalContentConfigPromise;
  4202. if (pdfDocument !== this.pdfDocument) {
  4203. return;
  4204. }
  4205. let operator;
  4206. for (const elem of action.state) {
  4207. switch (elem) {
  4208. case "ON":
  4209. case "OFF":
  4210. case "Toggle":
  4211. operator = elem;
  4212. continue;
  4213. }
  4214. switch (operator) {
  4215. case "ON":
  4216. optionalContentConfig.setVisibility(elem, true);
  4217. break;
  4218. case "OFF":
  4219. optionalContentConfig.setVisibility(elem, false);
  4220. break;
  4221. case "Toggle":
  4222. const group = optionalContentConfig.getGroup(elem);
  4223. if (group) {
  4224. optionalContentConfig.setVisibility(elem, !group.visible);
  4225. }
  4226. break;
  4227. }
  4228. }
  4229. this.pdfViewer.optionalContentConfigPromise = Promise.resolve(
  4230. optionalContentConfig
  4231. );
  4232. }
  4233. cachePageRef(pageNum, pageRef) {
  4234. if (!pageRef) {
  4235. return;
  4236. }
  4237. const refStr =
  4238. pageRef.gen === 0
  4239. ? `${pageRef.num}R`
  4240. : `${pageRef.num}R${pageRef.gen}`;
  4241. this.#pagesRefCache.set(refStr, pageNum);
  4242. }
  4243. _cachedPageNumber(pageRef) {
  4244. if (!pageRef) {
  4245. return null;
  4246. }
  4247. const refStr =
  4248. pageRef.gen === 0
  4249. ? `${pageRef.num}R`
  4250. : `${pageRef.num}R${pageRef.gen}`;
  4251. return this.#pagesRefCache.get(refStr) || null;
  4252. }
  4253. isPageVisible(pageNumber) {
  4254. return this.pdfViewer.isPageVisible(pageNumber);
  4255. }
  4256. isPageCached(pageNumber) {
  4257. return this.pdfViewer.isPageCached(pageNumber);
  4258. }
  4259. static #isValidExplicitDestination(dest) {
  4260. if (!Array.isArray(dest)) {
  4261. return false;
  4262. }
  4263. const destLength = dest.length;
  4264. if (destLength < 2) {
  4265. return false;
  4266. }
  4267. const page = dest[0];
  4268. if (
  4269. !(
  4270. typeof page === "object" &&
  4271. Number.isInteger(page.num) &&
  4272. Number.isInteger(page.gen)
  4273. ) &&
  4274. !(Number.isInteger(page) && page >= 0)
  4275. ) {
  4276. return false;
  4277. }
  4278. const zoom = dest[1];
  4279. if (!(typeof zoom === "object" && typeof zoom.name === "string")) {
  4280. return false;
  4281. }
  4282. let allowNull = true;
  4283. switch (zoom.name) {
  4284. case "XYZ":
  4285. if (destLength !== 5) {
  4286. return false;
  4287. }
  4288. break;
  4289. case "Fit":
  4290. case "FitB":
  4291. return destLength === 2;
  4292. case "FitH":
  4293. case "FitBH":
  4294. case "FitV":
  4295. case "FitBV":
  4296. if (destLength !== 3) {
  4297. return false;
  4298. }
  4299. break;
  4300. case "FitR":
  4301. if (destLength !== 6) {
  4302. return false;
  4303. }
  4304. allowNull = false;
  4305. break;
  4306. default:
  4307. return false;
  4308. }
  4309. for (let i = 2; i < destLength; i++) {
  4310. const param = dest[i];
  4311. if (!(typeof param === "number" || (allowNull && param === null))) {
  4312. return false;
  4313. }
  4314. }
  4315. return true;
  4316. }
  4317. }
  4318. exports.PDFLinkService = PDFLinkService;
  4319. class SimpleLinkService {
  4320. constructor() {
  4321. this.externalLinkEnabled = true;
  4322. }
  4323. get pagesCount() {
  4324. return 0;
  4325. }
  4326. get page() {
  4327. return 0;
  4328. }
  4329. set page(value) {}
  4330. get rotation() {
  4331. return 0;
  4332. }
  4333. set rotation(value) {}
  4334. get isInPresentationMode() {
  4335. return false;
  4336. }
  4337. async goToDestination(dest) {}
  4338. goToPage(val) {}
  4339. addLinkAttributes(link, url, newWindow = false) {
  4340. addLinkAttributes(link, {
  4341. url,
  4342. enabled: this.externalLinkEnabled,
  4343. });
  4344. }
  4345. getDestinationHash(dest) {
  4346. return "#";
  4347. }
  4348. getAnchorUrl(hash) {
  4349. return "#";
  4350. }
  4351. setHash(hash) {}
  4352. executeNamedAction(action) {}
  4353. executeSetOCGState(action) {}
  4354. cachePageRef(pageNum, pageRef) {}
  4355. isPageVisible(pageNumber) {
  4356. return true;
  4357. }
  4358. isPageCached(pageNumber) {
  4359. return true;
  4360. }
  4361. }
  4362. exports.SimpleLinkService = SimpleLinkService;
  4363. /***/
  4364. },
  4365. /* 8 */
  4366. /***/ (__unused_webpack_module, exports, __webpack_require__) => {
  4367. Object.defineProperty(exports, "__esModule", {
  4368. value: true,
  4369. });
  4370. exports.AnnotationEditorParams = void 0;
  4371. var _pdfjsLib = __webpack_require__(4);
  4372. class AnnotationEditorParams {
  4373. constructor(options, eventBus) {
  4374. this.eventBus = eventBus;
  4375. this.#bindListeners(options);
  4376. }
  4377. #bindListeners({
  4378. editorFreeTextFontSize,
  4379. editorFreeTextColor,
  4380. editorInkColor,
  4381. editorInkThickness,
  4382. editorInkOpacity,
  4383. }) {
  4384. editorFreeTextFontSize.addEventListener("input", (evt) => {
  4385. this.eventBus.dispatch("switchannotationeditorparams", {
  4386. source: this,
  4387. type: _pdfjsLib.AnnotationEditorParamsType.FREETEXT_SIZE,
  4388. value: editorFreeTextFontSize.valueAsNumber,
  4389. });
  4390. });
  4391. editorFreeTextColor.addEventListener("input", (evt) => {
  4392. this.eventBus.dispatch("switchannotationeditorparams", {
  4393. source: this,
  4394. type: _pdfjsLib.AnnotationEditorParamsType.FREETEXT_COLOR,
  4395. value: editorFreeTextColor.value,
  4396. });
  4397. });
  4398. editorInkColor.addEventListener("input", (evt) => {
  4399. this.eventBus.dispatch("switchannotationeditorparams", {
  4400. source: this,
  4401. type: _pdfjsLib.AnnotationEditorParamsType.INK_COLOR,
  4402. value: editorInkColor.value,
  4403. });
  4404. });
  4405. editorInkThickness.addEventListener("input", (evt) => {
  4406. this.eventBus.dispatch("switchannotationeditorparams", {
  4407. source: this,
  4408. type: _pdfjsLib.AnnotationEditorParamsType.INK_THICKNESS,
  4409. value: editorInkThickness.valueAsNumber,
  4410. });
  4411. });
  4412. editorInkOpacity.addEventListener("input", (evt) => {
  4413. this.eventBus.dispatch("switchannotationeditorparams", {
  4414. source: this,
  4415. type: _pdfjsLib.AnnotationEditorParamsType.INK_OPACITY,
  4416. value: editorInkOpacity.valueAsNumber,
  4417. });
  4418. });
  4419. this.eventBus._on("annotationeditorparamschanged", (evt) => {
  4420. for (const [type, value] of evt.details) {
  4421. switch (type) {
  4422. case _pdfjsLib.AnnotationEditorParamsType.FREETEXT_SIZE:
  4423. editorFreeTextFontSize.value = value;
  4424. break;
  4425. case _pdfjsLib.AnnotationEditorParamsType.FREETEXT_COLOR:
  4426. editorFreeTextColor.value = value;
  4427. break;
  4428. case _pdfjsLib.AnnotationEditorParamsType.INK_COLOR:
  4429. editorInkColor.value = value;
  4430. break;
  4431. case _pdfjsLib.AnnotationEditorParamsType.INK_THICKNESS:
  4432. editorInkThickness.value = value;
  4433. break;
  4434. case _pdfjsLib.AnnotationEditorParamsType.INK_OPACITY:
  4435. editorInkOpacity.value = value;
  4436. break;
  4437. }
  4438. }
  4439. });
  4440. }
  4441. }
  4442. exports.AnnotationEditorParams = AnnotationEditorParams;
  4443. /***/
  4444. },
  4445. /* 9 */
  4446. /***/ (__unused_webpack_module, exports) => {
  4447. Object.defineProperty(exports, "__esModule", {
  4448. value: true,
  4449. });
  4450. exports.OverlayManager = void 0;
  4451. class OverlayManager {
  4452. #overlays = new WeakMap();
  4453. #active = null;
  4454. get active() {
  4455. return this.#active;
  4456. }
  4457. async register(dialog, canForceClose = false) {
  4458. if (typeof dialog !== "object") {
  4459. throw new Error("Not enough parameters.");
  4460. } else if (this.#overlays.has(dialog)) {
  4461. throw new Error("The overlay is already registered.");
  4462. }
  4463. this.#overlays.set(dialog, {
  4464. canForceClose,
  4465. });
  4466. dialog.addEventListener("cancel", (evt) => {
  4467. this.#active = null;
  4468. });
  4469. }
  4470. async unregister(dialog) {
  4471. if (!this.#overlays.has(dialog)) {
  4472. throw new Error("The overlay does not exist.");
  4473. } else if (this.#active === dialog) {
  4474. throw new Error(
  4475. "The overlay cannot be removed while it is active."
  4476. );
  4477. }
  4478. this.#overlays.delete(dialog);
  4479. }
  4480. async open(dialog) {
  4481. if (!this.#overlays.has(dialog)) {
  4482. throw new Error("The overlay does not exist.");
  4483. } else if (this.#active) {
  4484. if (this.#active === dialog) {
  4485. throw new Error("The overlay is already active.");
  4486. } else if (this.#overlays.get(dialog).canForceClose) {
  4487. await this.close();
  4488. } else {
  4489. throw new Error("Another overlay is currently active.");
  4490. }
  4491. }
  4492. this.#active = dialog;
  4493. dialog.showModal();
  4494. }
  4495. async close(dialog = this.#active) {
  4496. if (!this.#overlays.has(dialog)) {
  4497. throw new Error("The overlay does not exist.");
  4498. } else if (!this.#active) {
  4499. throw new Error("The overlay is currently not active.");
  4500. } else if (this.#active !== dialog) {
  4501. throw new Error("Another overlay is currently active.");
  4502. }
  4503. dialog.close();
  4504. this.#active = null;
  4505. }
  4506. }
  4507. exports.OverlayManager = OverlayManager;
  4508. /***/
  4509. },
  4510. /* 10 */
  4511. /***/ (__unused_webpack_module, exports, __webpack_require__) => {
  4512. Object.defineProperty(exports, "__esModule", {
  4513. value: true,
  4514. });
  4515. exports.PasswordPrompt = void 0;
  4516. var _pdfjsLib = __webpack_require__(4);
  4517. class PasswordPrompt {
  4518. #activeCapability = null;
  4519. #updateCallback = null;
  4520. #reason = null;
  4521. constructor(options, overlayManager, l10n, isViewerEmbedded = false) {
  4522. this.dialog = options.dialog;
  4523. this.label = options.label;
  4524. this.input = options.input;
  4525. this.submitButton = options.submitButton;
  4526. this.cancelButton = options.cancelButton;
  4527. this.overlayManager = overlayManager;
  4528. this.l10n = l10n;
  4529. this._isViewerEmbedded = isViewerEmbedded;
  4530. this.submitButton.addEventListener("click", this.#verify.bind(this));
  4531. this.cancelButton.addEventListener("click", this.close.bind(this));
  4532. this.input.addEventListener("keydown", (e) => {
  4533. if (e.keyCode === 13) {
  4534. this.#verify();
  4535. }
  4536. });
  4537. this.overlayManager.register(this.dialog, true);
  4538. this.dialog.addEventListener("close", this.#cancel.bind(this));
  4539. }
  4540. async open() {
  4541. if (this.#activeCapability) {
  4542. await this.#activeCapability.promise;
  4543. }
  4544. this.#activeCapability = (0, _pdfjsLib.createPromiseCapability)();
  4545. try {
  4546. await this.overlayManager.open(this.dialog);
  4547. } catch (ex) {
  4548. this.#activeCapability = null;
  4549. throw ex;
  4550. }
  4551. const passwordIncorrect =
  4552. this.#reason === _pdfjsLib.PasswordResponses.INCORRECT_PASSWORD;
  4553. if (!this._isViewerEmbedded || passwordIncorrect) {
  4554. this.input.focus();
  4555. }
  4556. this.label.textContent = await this.l10n.get(
  4557. `password_${passwordIncorrect ? "invalid" : "label"}`
  4558. );
  4559. }
  4560. async close() {
  4561. if (this.overlayManager.active === this.dialog) {
  4562. this.overlayManager.close(this.dialog);
  4563. }
  4564. }
  4565. #verify() {
  4566. const password = this.input.value;
  4567. if (password?.length > 0) {
  4568. this.#invokeCallback(password);
  4569. }
  4570. }
  4571. #cancel() {
  4572. this.#invokeCallback(new Error("PasswordPrompt cancelled."));
  4573. this.#activeCapability.resolve();
  4574. }
  4575. #invokeCallback(password) {
  4576. if (!this.#updateCallback) {
  4577. return;
  4578. }
  4579. this.close();
  4580. this.input.value = "";
  4581. this.#updateCallback(password);
  4582. this.#updateCallback = null;
  4583. }
  4584. async setUpdateCallback(updateCallback, reason) {
  4585. if (this.#activeCapability) {
  4586. await this.#activeCapability.promise;
  4587. }
  4588. this.#updateCallback = updateCallback;
  4589. this.#reason = reason;
  4590. }
  4591. }
  4592. exports.PasswordPrompt = PasswordPrompt;
  4593. /***/
  4594. },
  4595. /* 11 */
  4596. /***/ (__unused_webpack_module, exports, __webpack_require__) => {
  4597. Object.defineProperty(exports, "__esModule", {
  4598. value: true,
  4599. });
  4600. exports.PDFAttachmentViewer = void 0;
  4601. var _pdfjsLib = __webpack_require__(4);
  4602. var _base_tree_viewer = __webpack_require__(12);
  4603. var _event_utils = __webpack_require__(6);
  4604. class PDFAttachmentViewer extends _base_tree_viewer.BaseTreeViewer {
  4605. constructor(options) {
  4606. super(options);
  4607. this.downloadManager = options.downloadManager;
  4608. this.eventBus._on(
  4609. "fileattachmentannotation",
  4610. this.#appendAttachment.bind(this)
  4611. );
  4612. }
  4613. reset(keepRenderedCapability = false) {
  4614. super.reset();
  4615. this._attachments = null;
  4616. if (!keepRenderedCapability) {
  4617. this._renderedCapability = (0, _pdfjsLib.createPromiseCapability)();
  4618. }
  4619. this._pendingDispatchEvent = false;
  4620. }
  4621. async _dispatchEvent(attachmentsCount) {
  4622. this._renderedCapability.resolve();
  4623. if (attachmentsCount === 0 && !this._pendingDispatchEvent) {
  4624. this._pendingDispatchEvent = true;
  4625. await (0, _event_utils.waitOnEventOrTimeout)({
  4626. target: this.eventBus,
  4627. name: "annotationlayerrendered",
  4628. delay: 1000,
  4629. });
  4630. if (!this._pendingDispatchEvent) {
  4631. return;
  4632. }
  4633. }
  4634. this._pendingDispatchEvent = false;
  4635. this.eventBus.dispatch("attachmentsloaded", {
  4636. source: this,
  4637. attachmentsCount,
  4638. });
  4639. }
  4640. _bindLink(element, { content, filename }) {
  4641. element.onclick = () => {
  4642. this.downloadManager.openOrDownloadData(element, content, filename);
  4643. return false;
  4644. };
  4645. }
  4646. render({ attachments, keepRenderedCapability = false }) {
  4647. if (this._attachments) {
  4648. this.reset(keepRenderedCapability);
  4649. }
  4650. this._attachments = attachments || null;
  4651. if (!attachments) {
  4652. this._dispatchEvent(0);
  4653. return;
  4654. }
  4655. const names = Object.keys(attachments).sort(function (a, b) {
  4656. return a.toLowerCase().localeCompare(b.toLowerCase());
  4657. });
  4658. const fragment = document.createDocumentFragment();
  4659. let attachmentsCount = 0;
  4660. for (const name of names) {
  4661. const item = attachments[name];
  4662. const content = item.content,
  4663. filename = (0, _pdfjsLib.getFilenameFromUrl)(item.filename, true);
  4664. const div = document.createElement("div");
  4665. div.className = "treeItem";
  4666. const element = document.createElement("a");
  4667. this._bindLink(element, {
  4668. content,
  4669. filename,
  4670. });
  4671. element.textContent = this._normalizeTextContent(filename);
  4672. div.append(element);
  4673. fragment.append(div);
  4674. attachmentsCount++;
  4675. }
  4676. this._finishRendering(fragment, attachmentsCount);
  4677. }
  4678. #appendAttachment({ filename, content }) {
  4679. const renderedPromise = this._renderedCapability.promise;
  4680. renderedPromise.then(() => {
  4681. if (renderedPromise !== this._renderedCapability.promise) {
  4682. return;
  4683. }
  4684. const attachments = this._attachments || Object.create(null);
  4685. for (const name in attachments) {
  4686. if (filename === name) {
  4687. return;
  4688. }
  4689. }
  4690. attachments[filename] = {
  4691. filename,
  4692. content,
  4693. };
  4694. this.render({
  4695. attachments,
  4696. keepRenderedCapability: true,
  4697. });
  4698. });
  4699. }
  4700. }
  4701. exports.PDFAttachmentViewer = PDFAttachmentViewer;
  4702. /***/
  4703. },
  4704. /* 12 */
  4705. /***/ (__unused_webpack_module, exports, __webpack_require__) => {
  4706. Object.defineProperty(exports, "__esModule", {
  4707. value: true,
  4708. });
  4709. exports.BaseTreeViewer = void 0;
  4710. var _ui_utils = __webpack_require__(3);
  4711. const TREEITEM_OFFSET_TOP = -100;
  4712. const TREEITEM_SELECTED_CLASS = "selected";
  4713. class BaseTreeViewer {
  4714. constructor(options) {
  4715. if (this.constructor === BaseTreeViewer) {
  4716. throw new Error("Cannot initialize BaseTreeViewer.");
  4717. }
  4718. this.container = options.container;
  4719. this.eventBus = options.eventBus;
  4720. this.reset();
  4721. }
  4722. reset() {
  4723. this._pdfDocument = null;
  4724. this._lastToggleIsShow = true;
  4725. this._currentTreeItem = null;
  4726. this.container.textContent = "";
  4727. this.container.classList.remove("treeWithDeepNesting");
  4728. }
  4729. _dispatchEvent(count) {
  4730. throw new Error("Not implemented: _dispatchEvent");
  4731. }
  4732. _bindLink(element, params) {
  4733. throw new Error("Not implemented: _bindLink");
  4734. }
  4735. _normalizeTextContent(str) {
  4736. return (0, _ui_utils.removeNullCharacters)(str, true) || "\u2013";
  4737. }
  4738. _addToggleButton(div, hidden = false) {
  4739. const toggler = document.createElement("div");
  4740. toggler.className = "treeItemToggler";
  4741. if (hidden) {
  4742. toggler.classList.add("treeItemsHidden");
  4743. }
  4744. toggler.onclick = (evt) => {
  4745. evt.stopPropagation();
  4746. toggler.classList.toggle("treeItemsHidden");
  4747. if (evt.shiftKey) {
  4748. const shouldShowAll =
  4749. !toggler.classList.contains("treeItemsHidden");
  4750. this._toggleTreeItem(div, shouldShowAll);
  4751. }
  4752. };
  4753. div.prepend(toggler);
  4754. }
  4755. _toggleTreeItem(root, show = false) {
  4756. this._lastToggleIsShow = show;
  4757. for (const toggler of root.querySelectorAll(".treeItemToggler")) {
  4758. toggler.classList.toggle("treeItemsHidden", !show);
  4759. }
  4760. }
  4761. _toggleAllTreeItems() {
  4762. this._toggleTreeItem(this.container, !this._lastToggleIsShow);
  4763. }
  4764. _finishRendering(fragment, count, hasAnyNesting = false) {
  4765. if (hasAnyNesting) {
  4766. this.container.classList.add("treeWithDeepNesting");
  4767. this._lastToggleIsShow =
  4768. !fragment.querySelector(".treeItemsHidden");
  4769. }
  4770. this.container.append(fragment);
  4771. this._dispatchEvent(count);
  4772. }
  4773. render(params) {
  4774. throw new Error("Not implemented: render");
  4775. }
  4776. _updateCurrentTreeItem(treeItem = null) {
  4777. if (this._currentTreeItem) {
  4778. this._currentTreeItem.classList.remove(TREEITEM_SELECTED_CLASS);
  4779. this._currentTreeItem = null;
  4780. }
  4781. if (treeItem) {
  4782. treeItem.classList.add(TREEITEM_SELECTED_CLASS);
  4783. this._currentTreeItem = treeItem;
  4784. }
  4785. }
  4786. _scrollToCurrentTreeItem(treeItem) {
  4787. if (!treeItem) {
  4788. return;
  4789. }
  4790. let currentNode = treeItem.parentNode;
  4791. while (currentNode && currentNode !== this.container) {
  4792. if (currentNode.classList.contains("treeItem")) {
  4793. const toggler = currentNode.firstElementChild;
  4794. toggler?.classList.remove("treeItemsHidden");
  4795. }
  4796. currentNode = currentNode.parentNode;
  4797. }
  4798. this._updateCurrentTreeItem(treeItem);
  4799. this.container.scrollTo(
  4800. treeItem.offsetLeft,
  4801. treeItem.offsetTop + TREEITEM_OFFSET_TOP
  4802. );
  4803. }
  4804. }
  4805. exports.BaseTreeViewer = BaseTreeViewer;
  4806. /***/
  4807. },
  4808. /* 13 */
  4809. /***/ (__unused_webpack_module, exports, __webpack_require__) => {
  4810. Object.defineProperty(exports, "__esModule", {
  4811. value: true,
  4812. });
  4813. exports.PDFCursorTools = void 0;
  4814. var _ui_utils = __webpack_require__(3);
  4815. var _pdfjsLib = __webpack_require__(4);
  4816. var _grab_to_pan = __webpack_require__(14);
  4817. class PDFCursorTools {
  4818. constructor({
  4819. container,
  4820. eventBus,
  4821. cursorToolOnLoad = _ui_utils.CursorTool.SELECT,
  4822. }) {
  4823. this.container = container;
  4824. this.eventBus = eventBus;
  4825. this.active = _ui_utils.CursorTool.SELECT;
  4826. this.previouslyActive = null;
  4827. this.handTool = new _grab_to_pan.GrabToPan({
  4828. element: this.container,
  4829. });
  4830. this.#addEventListeners();
  4831. Promise.resolve().then(() => {
  4832. this.switchTool(cursorToolOnLoad);
  4833. });
  4834. }
  4835. get activeTool() {
  4836. return this.active;
  4837. }
  4838. switchTool(tool) {
  4839. if (this.previouslyActive !== null) {
  4840. return;
  4841. }
  4842. if (tool === this.active) {
  4843. return;
  4844. }
  4845. const disableActiveTool = () => {
  4846. switch (this.active) {
  4847. case _ui_utils.CursorTool.SELECT:
  4848. break;
  4849. case _ui_utils.CursorTool.HAND:
  4850. this.handTool.deactivate();
  4851. break;
  4852. case _ui_utils.CursorTool.ZOOM:
  4853. }
  4854. };
  4855. switch (tool) {
  4856. case _ui_utils.CursorTool.SELECT:
  4857. disableActiveTool();
  4858. break;
  4859. case _ui_utils.CursorTool.HAND:
  4860. disableActiveTool();
  4861. this.handTool.activate();
  4862. break;
  4863. case _ui_utils.CursorTool.ZOOM:
  4864. default:
  4865. console.error(`switchTool: "${tool}" is an unsupported value.`);
  4866. return;
  4867. }
  4868. this.active = tool;
  4869. this.#dispatchEvent();
  4870. }
  4871. #dispatchEvent() {
  4872. this.eventBus.dispatch("cursortoolchanged", {
  4873. source: this,
  4874. tool: this.active,
  4875. });
  4876. }
  4877. #addEventListeners() {
  4878. this.eventBus._on("switchcursortool", (evt) => {
  4879. this.switchTool(evt.tool);
  4880. });
  4881. let annotationEditorMode = _pdfjsLib.AnnotationEditorType.NONE,
  4882. presentationModeState = _ui_utils.PresentationModeState.NORMAL;
  4883. const disableActive = () => {
  4884. const previouslyActive = this.active;
  4885. this.switchTool(_ui_utils.CursorTool.SELECT);
  4886. this.previouslyActive ??= previouslyActive;
  4887. };
  4888. const enableActive = () => {
  4889. const previouslyActive = this.previouslyActive;
  4890. if (
  4891. previouslyActive !== null &&
  4892. annotationEditorMode === _pdfjsLib.AnnotationEditorType.NONE &&
  4893. presentationModeState === _ui_utils.PresentationModeState.NORMAL
  4894. ) {
  4895. this.previouslyActive = null;
  4896. this.switchTool(previouslyActive);
  4897. }
  4898. };
  4899. this.eventBus._on("secondarytoolbarreset", (evt) => {
  4900. if (this.previouslyActive !== null) {
  4901. annotationEditorMode = _pdfjsLib.AnnotationEditorType.NONE;
  4902. presentationModeState = _ui_utils.PresentationModeState.NORMAL;
  4903. enableActive();
  4904. }
  4905. });
  4906. this.eventBus._on("annotationeditormodechanged", ({ mode }) => {
  4907. annotationEditorMode = mode;
  4908. if (mode === _pdfjsLib.AnnotationEditorType.NONE) {
  4909. enableActive();
  4910. } else {
  4911. disableActive();
  4912. }
  4913. });
  4914. this.eventBus._on("presentationmodechanged", ({ state }) => {
  4915. presentationModeState = state;
  4916. if (state === _ui_utils.PresentationModeState.NORMAL) {
  4917. enableActive();
  4918. } else if (state === _ui_utils.PresentationModeState.FULLSCREEN) {
  4919. disableActive();
  4920. }
  4921. });
  4922. }
  4923. }
  4924. exports.PDFCursorTools = PDFCursorTools;
  4925. /***/
  4926. },
  4927. /* 14 */
  4928. /***/ (__unused_webpack_module, exports) => {
  4929. Object.defineProperty(exports, "__esModule", {
  4930. value: true,
  4931. });
  4932. exports.GrabToPan = void 0;
  4933. const CSS_CLASS_GRAB = "grab-to-pan-grab";
  4934. class GrabToPan {
  4935. constructor(options) {
  4936. this.element = options.element;
  4937. this.document = options.element.ownerDocument;
  4938. if (typeof options.ignoreTarget === "function") {
  4939. this.ignoreTarget = options.ignoreTarget;
  4940. }
  4941. this.onActiveChanged = options.onActiveChanged;
  4942. this.activate = this.activate.bind(this);
  4943. this.deactivate = this.deactivate.bind(this);
  4944. this.toggle = this.toggle.bind(this);
  4945. this._onMouseDown = this.#onMouseDown.bind(this);
  4946. this._onMouseMove = this.#onMouseMove.bind(this);
  4947. this._endPan = this.#endPan.bind(this);
  4948. const overlay = (this.overlay = document.createElement("div"));
  4949. overlay.className = "grab-to-pan-grabbing";
  4950. }
  4951. activate() {
  4952. if (!this.active) {
  4953. this.active = true;
  4954. this.element.addEventListener("mousedown", this._onMouseDown, true);
  4955. this.element.classList.add(CSS_CLASS_GRAB);
  4956. this.onActiveChanged?.(true);
  4957. }
  4958. }
  4959. deactivate() {
  4960. if (this.active) {
  4961. this.active = false;
  4962. this.element.removeEventListener(
  4963. "mousedown",
  4964. this._onMouseDown,
  4965. true
  4966. );
  4967. this._endPan();
  4968. this.element.classList.remove(CSS_CLASS_GRAB);
  4969. this.onActiveChanged?.(false);
  4970. }
  4971. }
  4972. toggle() {
  4973. if (this.active) {
  4974. this.deactivate();
  4975. } else {
  4976. this.activate();
  4977. }
  4978. }
  4979. ignoreTarget(node) {
  4980. return node.matches(
  4981. "a[href], a[href] *, input, textarea, button, button *, select, option"
  4982. );
  4983. }
  4984. #onMouseDown(event) {
  4985. if (event.button !== 0 || this.ignoreTarget(event.target)) {
  4986. return;
  4987. }
  4988. if (event.originalTarget) {
  4989. try {
  4990. event.originalTarget.tagName;
  4991. } catch (e) {
  4992. return;
  4993. }
  4994. }
  4995. this.scrollLeftStart = this.element.scrollLeft;
  4996. this.scrollTopStart = this.element.scrollTop;
  4997. this.clientXStart = event.clientX;
  4998. this.clientYStart = event.clientY;
  4999. this.document.addEventListener("mousemove", this._onMouseMove, true);
  5000. this.document.addEventListener("mouseup", this._endPan, true);
  5001. this.element.addEventListener("scroll", this._endPan, true);
  5002. event.preventDefault();
  5003. event.stopPropagation();
  5004. const focusedElement = document.activeElement;
  5005. if (focusedElement && !focusedElement.contains(event.target)) {
  5006. focusedElement.blur();
  5007. }
  5008. }
  5009. #onMouseMove(event) {
  5010. this.element.removeEventListener("scroll", this._endPan, true);
  5011. if (!(event.buttons & 1)) {
  5012. this._endPan();
  5013. return;
  5014. }
  5015. const xDiff = event.clientX - this.clientXStart;
  5016. const yDiff = event.clientY - this.clientYStart;
  5017. const scrollTop = this.scrollTopStart - yDiff;
  5018. const scrollLeft = this.scrollLeftStart - xDiff;
  5019. if (this.element.scrollTo) {
  5020. this.element.scrollTo({
  5021. top: scrollTop,
  5022. left: scrollLeft,
  5023. behavior: "instant",
  5024. });
  5025. } else {
  5026. this.element.scrollTop = scrollTop;
  5027. this.element.scrollLeft = scrollLeft;
  5028. }
  5029. if (!this.overlay.parentNode) {
  5030. document.body.append(this.overlay);
  5031. }
  5032. }
  5033. #endPan() {
  5034. this.element.removeEventListener("scroll", this._endPan, true);
  5035. this.document.removeEventListener(
  5036. "mousemove",
  5037. this._onMouseMove,
  5038. true
  5039. );
  5040. this.document.removeEventListener("mouseup", this._endPan, true);
  5041. this.overlay.remove();
  5042. }
  5043. }
  5044. exports.GrabToPan = GrabToPan;
  5045. /***/
  5046. },
  5047. /* 15 */
  5048. /***/ (__unused_webpack_module, exports, __webpack_require__) => {
  5049. Object.defineProperty(exports, "__esModule", {
  5050. value: true,
  5051. });
  5052. exports.PDFDocumentProperties = void 0;
  5053. var _pdfjsLib = __webpack_require__(4);
  5054. var _ui_utils = __webpack_require__(3);
  5055. const DEFAULT_FIELD_CONTENT = "-";
  5056. const NON_METRIC_LOCALES = ["en-us", "en-lr", "my"];
  5057. const US_PAGE_NAMES = {
  5058. "8.5x11": "Letter",
  5059. "8.5x14": "Legal",
  5060. };
  5061. const METRIC_PAGE_NAMES = {
  5062. "297x420": "A3",
  5063. "210x297": "A4",
  5064. };
  5065. function getPageName(size, isPortrait, pageNames) {
  5066. const width = isPortrait ? size.width : size.height;
  5067. const height = isPortrait ? size.height : size.width;
  5068. return pageNames[`${width}x${height}`];
  5069. }
  5070. class PDFDocumentProperties {
  5071. #fieldData = null;
  5072. constructor(
  5073. { dialog, fields, closeButton },
  5074. overlayManager,
  5075. eventBus,
  5076. l10n,
  5077. fileNameLookup
  5078. ) {
  5079. this.dialog = dialog;
  5080. this.fields = fields;
  5081. this.overlayManager = overlayManager;
  5082. this.l10n = l10n;
  5083. this._fileNameLookup = fileNameLookup;
  5084. this.#reset();
  5085. closeButton.addEventListener("click", this.close.bind(this));
  5086. this.overlayManager.register(this.dialog);
  5087. eventBus._on("pagechanging", (evt) => {
  5088. this._currentPageNumber = evt.pageNumber;
  5089. });
  5090. eventBus._on("rotationchanging", (evt) => {
  5091. this._pagesRotation = evt.pagesRotation;
  5092. });
  5093. this._isNonMetricLocale = true;
  5094. l10n.getLanguage().then((locale) => {
  5095. this._isNonMetricLocale = NON_METRIC_LOCALES.includes(locale);
  5096. });
  5097. }
  5098. async open() {
  5099. await Promise.all([
  5100. this.overlayManager.open(this.dialog),
  5101. this._dataAvailableCapability.promise,
  5102. ]);
  5103. const currentPageNumber = this._currentPageNumber;
  5104. const pagesRotation = this._pagesRotation;
  5105. if (
  5106. this.#fieldData &&
  5107. currentPageNumber === this.#fieldData._currentPageNumber &&
  5108. pagesRotation === this.#fieldData._pagesRotation
  5109. ) {
  5110. this.#updateUI();
  5111. return;
  5112. }
  5113. const { info, contentLength } = await this.pdfDocument.getMetadata();
  5114. const [
  5115. fileName,
  5116. fileSize,
  5117. creationDate,
  5118. modificationDate,
  5119. pageSize,
  5120. isLinearized,
  5121. ] = await Promise.all([
  5122. this._fileNameLookup(),
  5123. this.#parseFileSize(contentLength),
  5124. this.#parseDate(info.CreationDate),
  5125. this.#parseDate(info.ModDate),
  5126. this.pdfDocument.getPage(currentPageNumber).then((pdfPage) => {
  5127. return this.#parsePageSize(
  5128. (0, _ui_utils.getPageSizeInches)(pdfPage),
  5129. pagesRotation
  5130. );
  5131. }),
  5132. this.#parseLinearization(info.IsLinearized),
  5133. ]);
  5134. this.#fieldData = Object.freeze({
  5135. fileName,
  5136. fileSize,
  5137. title: info.Title,
  5138. author: info.Author,
  5139. subject: info.Subject,
  5140. keywords: info.Keywords,
  5141. creationDate,
  5142. modificationDate,
  5143. creator: info.Creator,
  5144. producer: info.Producer,
  5145. version: info.PDFFormatVersion,
  5146. pageCount: this.pdfDocument.numPages,
  5147. pageSize,
  5148. linearized: isLinearized,
  5149. _currentPageNumber: currentPageNumber,
  5150. _pagesRotation: pagesRotation,
  5151. });
  5152. this.#updateUI();
  5153. const { length } = await this.pdfDocument.getDownloadInfo();
  5154. if (contentLength === length) {
  5155. return;
  5156. }
  5157. const data = Object.assign(Object.create(null), this.#fieldData);
  5158. data.fileSize = await this.#parseFileSize(length);
  5159. this.#fieldData = Object.freeze(data);
  5160. this.#updateUI();
  5161. }
  5162. async close() {
  5163. this.overlayManager.close(this.dialog);
  5164. }
  5165. setDocument(pdfDocument) {
  5166. if (this.pdfDocument) {
  5167. this.#reset();
  5168. this.#updateUI(true);
  5169. }
  5170. if (!pdfDocument) {
  5171. return;
  5172. }
  5173. this.pdfDocument = pdfDocument;
  5174. this._dataAvailableCapability.resolve();
  5175. }
  5176. #reset() {
  5177. this.pdfDocument = null;
  5178. this.#fieldData = null;
  5179. this._dataAvailableCapability = (0,
  5180. _pdfjsLib.createPromiseCapability)();
  5181. this._currentPageNumber = 1;
  5182. this._pagesRotation = 0;
  5183. }
  5184. #updateUI(reset = false) {
  5185. if (reset || !this.#fieldData) {
  5186. for (const id in this.fields) {
  5187. this.fields[id].textContent = DEFAULT_FIELD_CONTENT;
  5188. }
  5189. return;
  5190. }
  5191. if (this.overlayManager.active !== this.dialog) {
  5192. return;
  5193. }
  5194. for (const id in this.fields) {
  5195. const content = this.#fieldData[id];
  5196. this.fields[id].textContent =
  5197. content || content === 0 ? content : DEFAULT_FIELD_CONTENT;
  5198. }
  5199. }
  5200. async #parseFileSize(fileSize = 0) {
  5201. const kb = fileSize / 1024,
  5202. mb = kb / 1024;
  5203. if (!kb) {
  5204. return undefined;
  5205. }
  5206. return this.l10n.get(`document_properties_${mb >= 1 ? "mb" : "kb"}`, {
  5207. size_mb: mb >= 1 && (+mb.toPrecision(3)).toLocaleString(),
  5208. size_kb: mb < 1 && (+kb.toPrecision(3)).toLocaleString(),
  5209. size_b: fileSize.toLocaleString(),
  5210. });
  5211. }
  5212. async #parsePageSize(pageSizeInches, pagesRotation) {
  5213. if (!pageSizeInches) {
  5214. return undefined;
  5215. }
  5216. if (pagesRotation % 180 !== 0) {
  5217. pageSizeInches = {
  5218. width: pageSizeInches.height,
  5219. height: pageSizeInches.width,
  5220. };
  5221. }
  5222. const isPortrait = (0, _ui_utils.isPortraitOrientation)(
  5223. pageSizeInches
  5224. );
  5225. let sizeInches = {
  5226. width: Math.round(pageSizeInches.width * 100) / 100,
  5227. height: Math.round(pageSizeInches.height * 100) / 100,
  5228. };
  5229. let sizeMillimeters = {
  5230. width: Math.round(pageSizeInches.width * 25.4 * 10) / 10,
  5231. height: Math.round(pageSizeInches.height * 25.4 * 10) / 10,
  5232. };
  5233. let rawName =
  5234. getPageName(sizeInches, isPortrait, US_PAGE_NAMES) ||
  5235. getPageName(sizeMillimeters, isPortrait, METRIC_PAGE_NAMES);
  5236. if (
  5237. !rawName &&
  5238. !(
  5239. Number.isInteger(sizeMillimeters.width) &&
  5240. Number.isInteger(sizeMillimeters.height)
  5241. )
  5242. ) {
  5243. const exactMillimeters = {
  5244. width: pageSizeInches.width * 25.4,
  5245. height: pageSizeInches.height * 25.4,
  5246. };
  5247. const intMillimeters = {
  5248. width: Math.round(sizeMillimeters.width),
  5249. height: Math.round(sizeMillimeters.height),
  5250. };
  5251. if (
  5252. Math.abs(exactMillimeters.width - intMillimeters.width) < 0.1 &&
  5253. Math.abs(exactMillimeters.height - intMillimeters.height) < 0.1
  5254. ) {
  5255. rawName = getPageName(
  5256. intMillimeters,
  5257. isPortrait,
  5258. METRIC_PAGE_NAMES
  5259. );
  5260. if (rawName) {
  5261. sizeInches = {
  5262. width: Math.round((intMillimeters.width / 25.4) * 100) / 100,
  5263. height:
  5264. Math.round((intMillimeters.height / 25.4) * 100) / 100,
  5265. };
  5266. sizeMillimeters = intMillimeters;
  5267. }
  5268. }
  5269. }
  5270. const [{ width, height }, unit, name, orientation] =
  5271. await Promise.all([
  5272. this._isNonMetricLocale ? sizeInches : sizeMillimeters,
  5273. this.l10n.get(
  5274. `document_properties_page_size_unit_${
  5275. this._isNonMetricLocale ? "inches" : "millimeters"
  5276. }`
  5277. ),
  5278. rawName &&
  5279. this.l10n.get(
  5280. `document_properties_page_size_name_${rawName.toLowerCase()}`
  5281. ),
  5282. this.l10n.get(
  5283. `document_properties_page_size_orientation_${
  5284. isPortrait ? "portrait" : "landscape"
  5285. }`
  5286. ),
  5287. ]);
  5288. return this.l10n.get(
  5289. `document_properties_page_size_dimension_${
  5290. name ? "name_" : ""
  5291. }string`,
  5292. {
  5293. width: width.toLocaleString(),
  5294. height: height.toLocaleString(),
  5295. unit,
  5296. name,
  5297. orientation,
  5298. }
  5299. );
  5300. }
  5301. async #parseDate(inputDate) {
  5302. const dateObject = _pdfjsLib.PDFDateString.toDateObject(inputDate);
  5303. if (!dateObject) {
  5304. return undefined;
  5305. }
  5306. return this.l10n.get("document_properties_date_string", {
  5307. date: dateObject.toLocaleDateString(),
  5308. time: dateObject.toLocaleTimeString(),
  5309. });
  5310. }
  5311. #parseLinearization(isLinearized) {
  5312. return this.l10n.get(
  5313. `document_properties_linearized_${isLinearized ? "yes" : "no"}`
  5314. );
  5315. }
  5316. }
  5317. exports.PDFDocumentProperties = PDFDocumentProperties;
  5318. /***/
  5319. },
  5320. /* 16 */
  5321. /***/ (__unused_webpack_module, exports, __webpack_require__) => {
  5322. Object.defineProperty(exports, "__esModule", {
  5323. value: true,
  5324. });
  5325. exports.PDFFindBar = void 0;
  5326. var _pdf_find_controller = __webpack_require__(17);
  5327. const MATCHES_COUNT_LIMIT = 1000;
  5328. class PDFFindBar {
  5329. constructor(options, eventBus, l10n) {
  5330. this.opened = false;
  5331. this.bar = options.bar;
  5332. this.toggleButton = options.toggleButton;
  5333. this.findField = options.findField;
  5334. this.highlightAll = options.highlightAllCheckbox;
  5335. this.caseSensitive = options.caseSensitiveCheckbox;
  5336. this.matchDiacritics = options.matchDiacriticsCheckbox;
  5337. this.entireWord = options.entireWordCheckbox;
  5338. this.findMsg = options.findMsg;
  5339. this.findResultsCount = options.findResultsCount;
  5340. this.findPreviousButton = options.findPreviousButton;
  5341. this.findNextButton = options.findNextButton;
  5342. this.eventBus = eventBus;
  5343. this.l10n = l10n;
  5344. this.toggleButton.addEventListener("click", () => {
  5345. this.toggle();
  5346. });
  5347. this.findField.addEventListener("input", () => {
  5348. this.dispatchEvent("");
  5349. });
  5350. this.bar.addEventListener("keydown", (e) => {
  5351. switch (e.keyCode) {
  5352. case 13:
  5353. if (e.target === this.findField) {
  5354. this.dispatchEvent("again", e.shiftKey);
  5355. }
  5356. break;
  5357. case 27:
  5358. this.close();
  5359. break;
  5360. }
  5361. });
  5362. this.findPreviousButton.addEventListener("click", () => {
  5363. this.dispatchEvent("again", true);
  5364. });
  5365. this.findNextButton.addEventListener("click", () => {
  5366. this.dispatchEvent("again", false);
  5367. });
  5368. this.highlightAll.addEventListener("click", () => {
  5369. this.dispatchEvent("highlightallchange");
  5370. });
  5371. this.caseSensitive.addEventListener("click", () => {
  5372. this.dispatchEvent("casesensitivitychange");
  5373. });
  5374. this.entireWord.addEventListener("click", () => {
  5375. this.dispatchEvent("entirewordchange");
  5376. });
  5377. this.matchDiacritics.addEventListener("click", () => {
  5378. this.dispatchEvent("diacriticmatchingchange");
  5379. });
  5380. this.eventBus._on("resize", this.#adjustWidth.bind(this));
  5381. }
  5382. reset() {
  5383. this.updateUIState();
  5384. }
  5385. dispatchEvent(type, findPrev = false) {
  5386. this.eventBus.dispatch("find", {
  5387. source: this,
  5388. type,
  5389. query: this.findField.value,
  5390. phraseSearch: true,
  5391. caseSensitive: this.caseSensitive.checked,
  5392. entireWord: this.entireWord.checked,
  5393. highlightAll: this.highlightAll.checked,
  5394. findPrevious: findPrev,
  5395. matchDiacritics: this.matchDiacritics.checked,
  5396. });
  5397. }
  5398. updateUIState(state, previous, matchesCount) {
  5399. let findMsg = Promise.resolve("");
  5400. let status = "";
  5401. switch (state) {
  5402. case _pdf_find_controller.FindState.FOUND:
  5403. break;
  5404. case _pdf_find_controller.FindState.PENDING:
  5405. status = "pending";
  5406. break;
  5407. case _pdf_find_controller.FindState.NOT_FOUND:
  5408. findMsg = this.l10n.get("find_not_found");
  5409. status = "notFound";
  5410. break;
  5411. case _pdf_find_controller.FindState.WRAPPED:
  5412. findMsg = this.l10n.get(
  5413. `find_reached_${previous ? "top" : "bottom"}`
  5414. );
  5415. break;
  5416. }
  5417. this.findField.setAttribute("data-status", status);
  5418. this.findField.setAttribute(
  5419. "aria-invalid",
  5420. state === _pdf_find_controller.FindState.NOT_FOUND
  5421. );
  5422. findMsg.then((msg) => {
  5423. this.findMsg.textContent = msg;
  5424. this.#adjustWidth();
  5425. });
  5426. this.updateResultsCount(matchesCount);
  5427. }
  5428. updateResultsCount({ current = 0, total = 0 } = {}) {
  5429. const limit = MATCHES_COUNT_LIMIT;
  5430. let matchCountMsg = Promise.resolve("");
  5431. if (total > 0) {
  5432. if (total > limit) {
  5433. let key = "find_match_count_limit";
  5434. matchCountMsg = this.l10n.get(key, {
  5435. limit,
  5436. });
  5437. } else {
  5438. let key = "find_match_count";
  5439. matchCountMsg = this.l10n.get(key, {
  5440. current,
  5441. total,
  5442. });
  5443. }
  5444. }
  5445. matchCountMsg.then((msg) => {
  5446. this.findResultsCount.textContent = msg;
  5447. this.#adjustWidth();
  5448. });
  5449. }
  5450. open() {
  5451. if (!this.opened) {
  5452. this.opened = true;
  5453. this.toggleButton.classList.add("toggled");
  5454. this.toggleButton.setAttribute("aria-expanded", "true");
  5455. this.bar.classList.remove("hidden");
  5456. }
  5457. this.findField.select();
  5458. this.findField.focus();
  5459. this.#adjustWidth();
  5460. }
  5461. close() {
  5462. if (!this.opened) {
  5463. return;
  5464. }
  5465. this.opened = false;
  5466. this.toggleButton.classList.remove("toggled");
  5467. this.toggleButton.setAttribute("aria-expanded", "false");
  5468. this.bar.classList.add("hidden");
  5469. this.eventBus.dispatch("findbarclose", {
  5470. source: this,
  5471. });
  5472. }
  5473. toggle() {
  5474. if (this.opened) {
  5475. this.close();
  5476. } else {
  5477. this.open();
  5478. }
  5479. }
  5480. #adjustWidth() {
  5481. if (!this.opened) {
  5482. return;
  5483. }
  5484. this.bar.classList.remove("wrapContainers");
  5485. const findbarHeight = this.bar.clientHeight;
  5486. const inputContainerHeight = this.bar.firstElementChild.clientHeight;
  5487. if (findbarHeight > inputContainerHeight) {
  5488. this.bar.classList.add("wrapContainers");
  5489. }
  5490. }
  5491. }
  5492. exports.PDFFindBar = PDFFindBar;
  5493. /***/
  5494. },
  5495. /* 17 */
  5496. /***/ (__unused_webpack_module, exports, __webpack_require__) => {
  5497. Object.defineProperty(exports, "__esModule", {
  5498. value: true,
  5499. });
  5500. exports.PDFFindController = exports.FindState = void 0;
  5501. var _ui_utils = __webpack_require__(3);
  5502. var _pdfjsLib = __webpack_require__(4);
  5503. var _pdf_find_utils = __webpack_require__(18);
  5504. const FindState = {
  5505. FOUND: 0,
  5506. NOT_FOUND: 1,
  5507. WRAPPED: 2,
  5508. PENDING: 3,
  5509. };
  5510. exports.FindState = FindState;
  5511. const FIND_TIMEOUT = 250;
  5512. const MATCH_SCROLL_OFFSET_TOP = -50;
  5513. const MATCH_SCROLL_OFFSET_LEFT = -400;
  5514. const CHARACTERS_TO_NORMALIZE = {
  5515. "\u2010": "-",
  5516. "\u2018": "'",
  5517. "\u2019": "'",
  5518. "\u201A": "'",
  5519. "\u201B": "'",
  5520. "\u201C": '"',
  5521. "\u201D": '"',
  5522. "\u201E": '"',
  5523. "\u201F": '"',
  5524. "\u00BC": "1/4",
  5525. "\u00BD": "1/2",
  5526. "\u00BE": "3/4",
  5527. };
  5528. const DIACRITICS_EXCEPTION = new Set([
  5529. 0x3099, 0x309a, 0x094d, 0x09cd, 0x0a4d, 0x0acd, 0x0b4d, 0x0bcd, 0x0c4d,
  5530. 0x0ccd, 0x0d3b, 0x0d3c, 0x0d4d, 0x0dca, 0x0e3a, 0x0eba, 0x0f84, 0x1039,
  5531. 0x103a, 0x1714, 0x1734, 0x17d2, 0x1a60, 0x1b44, 0x1baa, 0x1bab, 0x1bf2,
  5532. 0x1bf3, 0x2d7f, 0xa806, 0xa82c, 0xa8c4, 0xa953, 0xa9c0, 0xaaf6, 0xabed,
  5533. 0x0c56, 0x0f71, 0x0f72, 0x0f7a, 0x0f7b, 0x0f7c, 0x0f7d, 0x0f80, 0x0f74,
  5534. ]);
  5535. let DIACRITICS_EXCEPTION_STR;
  5536. const DIACRITICS_REG_EXP = /\p{M}+/gu;
  5537. const SPECIAL_CHARS_REG_EXP =
  5538. /([.*+?^${}()|[\]\\])|(\p{P})|(\s+)|(\p{M})|(\p{L})/gu;
  5539. const NOT_DIACRITIC_FROM_END_REG_EXP = /([^\p{M}])\p{M}*$/u;
  5540. const NOT_DIACRITIC_FROM_START_REG_EXP = /^\p{M}*([^\p{M}])/u;
  5541. const SYLLABLES_REG_EXP =
  5542. /[\uAC00-\uD7AF\uFA6C\uFACF-\uFAD1\uFAD5-\uFAD7]+/g;
  5543. const SYLLABLES_LENGTHS = new Map();
  5544. const FIRST_CHAR_SYLLABLES_REG_EXP =
  5545. "[\\u1100-\\u1112\\ud7a4-\\ud7af\\ud84a\\ud84c\\ud850\\ud854\\ud857\\ud85f]";
  5546. const NFKC_CHARS_TO_NORMALIZE = new Map();
  5547. let noSyllablesRegExp = null;
  5548. let withSyllablesRegExp = null;
  5549. function normalize(text) {
  5550. const syllablePositions = [];
  5551. let m;
  5552. while ((m = SYLLABLES_REG_EXP.exec(text)) !== null) {
  5553. let { index } = m;
  5554. for (const char of m[0]) {
  5555. let len = SYLLABLES_LENGTHS.get(char);
  5556. if (!len) {
  5557. len = char.normalize("NFD").length;
  5558. SYLLABLES_LENGTHS.set(char, len);
  5559. }
  5560. syllablePositions.push([len, index++]);
  5561. }
  5562. }
  5563. let normalizationRegex;
  5564. if (syllablePositions.length === 0 && noSyllablesRegExp) {
  5565. normalizationRegex = noSyllablesRegExp;
  5566. } else if (syllablePositions.length > 0 && withSyllablesRegExp) {
  5567. normalizationRegex = withSyllablesRegExp;
  5568. } else {
  5569. const replace = Object.keys(CHARACTERS_TO_NORMALIZE).join("");
  5570. const toNormalizeWithNFKC =
  5571. "\u2460-\u2473" +
  5572. "\u24b6-\u24ff" +
  5573. "\u3244-\u32bf" +
  5574. "\u32d0-\u32fe" +
  5575. "\uff00-\uffef";
  5576. const CJK = "(?:\\p{Ideographic}|[\u3040-\u30FF])";
  5577. const HKDiacritics = "(?:\u3099|\u309A)";
  5578. const regexp = `([${replace}])|([${toNormalizeWithNFKC}])|(${HKDiacritics}\\n)|(\\p{M}+(?:-\\n)?)|(\\S-\\n)|(${CJK}\\n)|(\\n)`;
  5579. if (syllablePositions.length === 0) {
  5580. normalizationRegex = noSyllablesRegExp = new RegExp(
  5581. regexp + "|(\\u0000)",
  5582. "gum"
  5583. );
  5584. } else {
  5585. normalizationRegex = withSyllablesRegExp = new RegExp(
  5586. regexp + `|(${FIRST_CHAR_SYLLABLES_REG_EXP})`,
  5587. "gum"
  5588. );
  5589. }
  5590. }
  5591. const rawDiacriticsPositions = [];
  5592. while ((m = DIACRITICS_REG_EXP.exec(text)) !== null) {
  5593. rawDiacriticsPositions.push([m[0].length, m.index]);
  5594. }
  5595. let normalized = text.normalize("NFD");
  5596. const positions = [[0, 0]];
  5597. let rawDiacriticsIndex = 0;
  5598. let syllableIndex = 0;
  5599. let shift = 0;
  5600. let shiftOrigin = 0;
  5601. let eol = 0;
  5602. let hasDiacritics = false;
  5603. normalized = normalized.replace(
  5604. normalizationRegex,
  5605. (match, p1, p2, p3, p4, p5, p6, p7, p8, i) => {
  5606. i -= shiftOrigin;
  5607. if (p1) {
  5608. const replacement = CHARACTERS_TO_NORMALIZE[p1];
  5609. const jj = replacement.length;
  5610. for (let j = 1; j < jj; j++) {
  5611. positions.push([i - shift + j, shift - j]);
  5612. }
  5613. shift -= jj - 1;
  5614. return replacement;
  5615. }
  5616. if (p2) {
  5617. let replacement = NFKC_CHARS_TO_NORMALIZE.get(p2);
  5618. if (!replacement) {
  5619. replacement = p2.normalize("NFKC");
  5620. NFKC_CHARS_TO_NORMALIZE.set(p2, replacement);
  5621. }
  5622. const jj = replacement.length;
  5623. for (let j = 1; j < jj; j++) {
  5624. positions.push([i - shift + j, shift - j]);
  5625. }
  5626. shift -= jj - 1;
  5627. return replacement;
  5628. }
  5629. if (p3) {
  5630. hasDiacritics = true;
  5631. if (i + eol === rawDiacriticsPositions[rawDiacriticsIndex]?.[1]) {
  5632. ++rawDiacriticsIndex;
  5633. } else {
  5634. positions.push([i - 1 - shift + 1, shift - 1]);
  5635. shift -= 1;
  5636. shiftOrigin += 1;
  5637. }
  5638. positions.push([i - shift + 1, shift]);
  5639. shiftOrigin += 1;
  5640. eol += 1;
  5641. return p3.charAt(0);
  5642. }
  5643. if (p4) {
  5644. const hasTrailingDashEOL = p4.endsWith("\n");
  5645. const len = hasTrailingDashEOL ? p4.length - 2 : p4.length;
  5646. hasDiacritics = true;
  5647. let jj = len;
  5648. if (i + eol === rawDiacriticsPositions[rawDiacriticsIndex]?.[1]) {
  5649. jj -= rawDiacriticsPositions[rawDiacriticsIndex][0];
  5650. ++rawDiacriticsIndex;
  5651. }
  5652. for (let j = 1; j <= jj; j++) {
  5653. positions.push([i - 1 - shift + j, shift - j]);
  5654. }
  5655. shift -= jj;
  5656. shiftOrigin += jj;
  5657. if (hasTrailingDashEOL) {
  5658. i += len - 1;
  5659. positions.push([i - shift + 1, 1 + shift]);
  5660. shift += 1;
  5661. shiftOrigin += 1;
  5662. eol += 1;
  5663. return p4.slice(0, len);
  5664. }
  5665. return p4;
  5666. }
  5667. if (p5) {
  5668. const len = p5.length - 2;
  5669. positions.push([i - shift + len, 1 + shift]);
  5670. shift += 1;
  5671. shiftOrigin += 1;
  5672. eol += 1;
  5673. return p5.slice(0, -2);
  5674. }
  5675. if (p6) {
  5676. const len = p6.length - 1;
  5677. positions.push([i - shift + len, shift]);
  5678. shiftOrigin += 1;
  5679. eol += 1;
  5680. return p6.slice(0, -1);
  5681. }
  5682. if (p7) {
  5683. positions.push([i - shift + 1, shift - 1]);
  5684. shift -= 1;
  5685. shiftOrigin += 1;
  5686. eol += 1;
  5687. return " ";
  5688. }
  5689. if (i + eol === syllablePositions[syllableIndex]?.[1]) {
  5690. const newCharLen = syllablePositions[syllableIndex][0] - 1;
  5691. ++syllableIndex;
  5692. for (let j = 1; j <= newCharLen; j++) {
  5693. positions.push([i - (shift - j), shift - j]);
  5694. }
  5695. shift -= newCharLen;
  5696. shiftOrigin += newCharLen;
  5697. }
  5698. return p8;
  5699. }
  5700. );
  5701. positions.push([normalized.length, shift]);
  5702. return [normalized, positions, hasDiacritics];
  5703. }
  5704. function getOriginalIndex(diffs, pos, len) {
  5705. if (!diffs) {
  5706. return [pos, len];
  5707. }
  5708. const start = pos;
  5709. const end = pos + len;
  5710. let i = (0, _ui_utils.binarySearchFirstItem)(
  5711. diffs,
  5712. (x) => x[0] >= start
  5713. );
  5714. if (diffs[i][0] > start) {
  5715. --i;
  5716. }
  5717. let j = (0, _ui_utils.binarySearchFirstItem)(
  5718. diffs,
  5719. (x) => x[0] >= end,
  5720. i
  5721. );
  5722. if (diffs[j][0] > end) {
  5723. --j;
  5724. }
  5725. return [start + diffs[i][1], len + diffs[j][1] - diffs[i][1]];
  5726. }
  5727. class PDFFindController {
  5728. #updateMatchesCountOnProgress = true;
  5729. #visitedPagesCount = 0;
  5730. constructor({
  5731. linkService,
  5732. eventBus,
  5733. updateMatchesCountOnProgress = true,
  5734. }) {
  5735. this._linkService = linkService;
  5736. this._eventBus = eventBus;
  5737. this.#updateMatchesCountOnProgress = updateMatchesCountOnProgress;
  5738. this.#reset();
  5739. eventBus._on("find", this.#onFind.bind(this));
  5740. eventBus._on("findbarclose", this.#onFindBarClose.bind(this));
  5741. }
  5742. get highlightMatches() {
  5743. return this._highlightMatches;
  5744. }
  5745. get pageMatches() {
  5746. return this._pageMatches;
  5747. }
  5748. get pageMatchesLength() {
  5749. return this._pageMatchesLength;
  5750. }
  5751. get selected() {
  5752. return this._selected;
  5753. }
  5754. get state() {
  5755. return this._state;
  5756. }
  5757. setDocument(pdfDocument) {
  5758. if (this._pdfDocument) {
  5759. this.#reset();
  5760. }
  5761. if (!pdfDocument) {
  5762. return;
  5763. }
  5764. this._pdfDocument = pdfDocument;
  5765. this._firstPageCapability.resolve();
  5766. }
  5767. #onFind(state) {
  5768. if (!state) {
  5769. return;
  5770. }
  5771. const pdfDocument = this._pdfDocument;
  5772. const { type } = state;
  5773. if (this._state === null || this.#shouldDirtyMatch(state)) {
  5774. this._dirtyMatch = true;
  5775. }
  5776. this._state = state;
  5777. if (type !== "highlightallchange") {
  5778. this.#updateUIState(FindState.PENDING);
  5779. }
  5780. this._firstPageCapability.promise.then(() => {
  5781. if (
  5782. !this._pdfDocument ||
  5783. (pdfDocument && this._pdfDocument !== pdfDocument)
  5784. ) {
  5785. return;
  5786. }
  5787. this.#extractText();
  5788. const findbarClosed = !this._highlightMatches;
  5789. const pendingTimeout = !!this._findTimeout;
  5790. if (this._findTimeout) {
  5791. clearTimeout(this._findTimeout);
  5792. this._findTimeout = null;
  5793. }
  5794. if (!type) {
  5795. this._findTimeout = setTimeout(() => {
  5796. this.#nextMatch();
  5797. this._findTimeout = null;
  5798. }, FIND_TIMEOUT);
  5799. } else if (this._dirtyMatch) {
  5800. this.#nextMatch();
  5801. } else if (type === "again") {
  5802. this.#nextMatch();
  5803. if (findbarClosed && this._state.highlightAll) {
  5804. this.#updateAllPages();
  5805. }
  5806. } else if (type === "highlightallchange") {
  5807. if (pendingTimeout) {
  5808. this.#nextMatch();
  5809. } else {
  5810. this._highlightMatches = true;
  5811. }
  5812. this.#updateAllPages();
  5813. } else {
  5814. this.#nextMatch();
  5815. }
  5816. });
  5817. }
  5818. scrollMatchIntoView({
  5819. element = null,
  5820. selectedLeft = 0,
  5821. pageIndex = -1,
  5822. matchIndex = -1,
  5823. }) {
  5824. if (!this._scrollMatches || !element) {
  5825. return;
  5826. } else if (
  5827. matchIndex === -1 ||
  5828. matchIndex !== this._selected.matchIdx
  5829. ) {
  5830. return;
  5831. } else if (pageIndex === -1 || pageIndex !== this._selected.pageIdx) {
  5832. return;
  5833. }
  5834. this._scrollMatches = false;
  5835. const spot = {
  5836. top: MATCH_SCROLL_OFFSET_TOP,
  5837. left: selectedLeft + MATCH_SCROLL_OFFSET_LEFT,
  5838. };
  5839. (0, _ui_utils.scrollIntoView)(element, spot, true);
  5840. }
  5841. #reset() {
  5842. this._highlightMatches = false;
  5843. this._scrollMatches = false;
  5844. this._pdfDocument = null;
  5845. this._pageMatches = [];
  5846. this._pageMatchesLength = [];
  5847. this.#visitedPagesCount = 0;
  5848. this._state = null;
  5849. this._selected = {
  5850. pageIdx: -1,
  5851. matchIdx: -1,
  5852. };
  5853. this._offset = {
  5854. pageIdx: null,
  5855. matchIdx: null,
  5856. wrapped: false,
  5857. };
  5858. this._extractTextPromises = [];
  5859. this._pageContents = [];
  5860. this._pageDiffs = [];
  5861. this._hasDiacritics = [];
  5862. this._matchesCountTotal = 0;
  5863. this._pagesToSearch = null;
  5864. this._pendingFindMatches = new Set();
  5865. this._resumePageIdx = null;
  5866. this._dirtyMatch = false;
  5867. clearTimeout(this._findTimeout);
  5868. this._findTimeout = null;
  5869. this._firstPageCapability = (0, _pdfjsLib.createPromiseCapability)();
  5870. }
  5871. get #query() {
  5872. if (this._state.query !== this._rawQuery) {
  5873. this._rawQuery = this._state.query;
  5874. [this._normalizedQuery] = normalize(this._state.query);
  5875. }
  5876. return this._normalizedQuery;
  5877. }
  5878. #shouldDirtyMatch(state) {
  5879. if (state.query !== this._state.query) {
  5880. return true;
  5881. }
  5882. switch (state.type) {
  5883. case "again":
  5884. const pageNumber = this._selected.pageIdx + 1;
  5885. const linkService = this._linkService;
  5886. if (
  5887. pageNumber >= 1 &&
  5888. pageNumber <= linkService.pagesCount &&
  5889. pageNumber !== linkService.page &&
  5890. !linkService.isPageVisible(pageNumber)
  5891. ) {
  5892. return true;
  5893. }
  5894. return false;
  5895. case "highlightallchange":
  5896. return false;
  5897. }
  5898. return true;
  5899. }
  5900. #isEntireWord(content, startIdx, length) {
  5901. let match = content
  5902. .slice(0, startIdx)
  5903. .match(NOT_DIACRITIC_FROM_END_REG_EXP);
  5904. if (match) {
  5905. const first = content.charCodeAt(startIdx);
  5906. const limit = match[1].charCodeAt(0);
  5907. if (
  5908. (0, _pdf_find_utils.getCharacterType)(first) ===
  5909. (0, _pdf_find_utils.getCharacterType)(limit)
  5910. ) {
  5911. return false;
  5912. }
  5913. }
  5914. match = content
  5915. .slice(startIdx + length)
  5916. .match(NOT_DIACRITIC_FROM_START_REG_EXP);
  5917. if (match) {
  5918. const last = content.charCodeAt(startIdx + length - 1);
  5919. const limit = match[1].charCodeAt(0);
  5920. if (
  5921. (0, _pdf_find_utils.getCharacterType)(last) ===
  5922. (0, _pdf_find_utils.getCharacterType)(limit)
  5923. ) {
  5924. return false;
  5925. }
  5926. }
  5927. return true;
  5928. }
  5929. #calculateRegExpMatch(query, entireWord, pageIndex, pageContent) {
  5930. const matches = (this._pageMatches[pageIndex] = []);
  5931. const matchesLength = (this._pageMatchesLength[pageIndex] = []);
  5932. if (!query) {
  5933. return;
  5934. }
  5935. const diffs = this._pageDiffs[pageIndex];
  5936. let match;
  5937. while ((match = query.exec(pageContent)) !== null) {
  5938. if (
  5939. entireWord &&
  5940. !this.#isEntireWord(pageContent, match.index, match[0].length)
  5941. ) {
  5942. continue;
  5943. }
  5944. const [matchPos, matchLen] = getOriginalIndex(
  5945. diffs,
  5946. match.index,
  5947. match[0].length
  5948. );
  5949. if (matchLen) {
  5950. matches.push(matchPos);
  5951. matchesLength.push(matchLen);
  5952. }
  5953. }
  5954. }
  5955. #convertToRegExpString(query, hasDiacritics) {
  5956. const { matchDiacritics } = this._state;
  5957. let isUnicode = false;
  5958. query = query.replaceAll(
  5959. SPECIAL_CHARS_REG_EXP,
  5960. (match, p1, p2, p3, p4, p5) => {
  5961. if (p1) {
  5962. return `[ ]*\\${p1}[ ]*`;
  5963. }
  5964. if (p2) {
  5965. return `[ ]*${p2}[ ]*`;
  5966. }
  5967. if (p3) {
  5968. return "[ ]+";
  5969. }
  5970. if (matchDiacritics) {
  5971. return p4 || p5;
  5972. }
  5973. if (p4) {
  5974. return DIACRITICS_EXCEPTION.has(p4.charCodeAt(0)) ? p4 : "";
  5975. }
  5976. if (hasDiacritics) {
  5977. isUnicode = true;
  5978. return `${p5}\\p{M}*`;
  5979. }
  5980. return p5;
  5981. }
  5982. );
  5983. const trailingSpaces = "[ ]*";
  5984. if (query.endsWith(trailingSpaces)) {
  5985. query = query.slice(0, query.length - trailingSpaces.length);
  5986. }
  5987. if (matchDiacritics) {
  5988. if (hasDiacritics) {
  5989. DIACRITICS_EXCEPTION_STR ||= String.fromCharCode(
  5990. ...DIACRITICS_EXCEPTION
  5991. );
  5992. isUnicode = true;
  5993. query = `${query}(?=[${DIACRITICS_EXCEPTION_STR}]|[^\\p{M}]|$)`;
  5994. }
  5995. }
  5996. return [isUnicode, query];
  5997. }
  5998. #calculateMatch(pageIndex) {
  5999. let query = this.#query;
  6000. if (!query) {
  6001. return;
  6002. }
  6003. const { caseSensitive, entireWord, phraseSearch } = this._state;
  6004. const pageContent = this._pageContents[pageIndex];
  6005. const hasDiacritics = this._hasDiacritics[pageIndex];
  6006. let isUnicode = false;
  6007. if (phraseSearch) {
  6008. [isUnicode, query] = this.#convertToRegExpString(
  6009. query,
  6010. hasDiacritics
  6011. );
  6012. } else {
  6013. const match = query.match(/\S+/g);
  6014. if (match) {
  6015. query = match
  6016. .sort()
  6017. .reverse()
  6018. .map((q) => {
  6019. const [isUnicodePart, queryPart] =
  6020. this.#convertToRegExpString(q, hasDiacritics);
  6021. isUnicode ||= isUnicodePart;
  6022. return `(${queryPart})`;
  6023. })
  6024. .join("|");
  6025. }
  6026. }
  6027. const flags = `g${isUnicode ? "u" : ""}${caseSensitive ? "" : "i"}`;
  6028. query = query ? new RegExp(query, flags) : null;
  6029. this.#calculateRegExpMatch(query, entireWord, pageIndex, pageContent);
  6030. if (this._state.highlightAll) {
  6031. this.#updatePage(pageIndex);
  6032. }
  6033. if (this._resumePageIdx === pageIndex) {
  6034. this._resumePageIdx = null;
  6035. this.#nextPageMatch();
  6036. }
  6037. const pageMatchesCount = this._pageMatches[pageIndex].length;
  6038. this._matchesCountTotal += pageMatchesCount;
  6039. if (this.#updateMatchesCountOnProgress) {
  6040. if (pageMatchesCount > 0) {
  6041. this.#updateUIResultsCount();
  6042. }
  6043. } else if (
  6044. ++this.#visitedPagesCount === this._linkService.pagesCount
  6045. ) {
  6046. this.#updateUIResultsCount();
  6047. }
  6048. }
  6049. #extractText() {
  6050. if (this._extractTextPromises.length > 0) {
  6051. return;
  6052. }
  6053. let promise = Promise.resolve();
  6054. for (let i = 0, ii = this._linkService.pagesCount; i < ii; i++) {
  6055. const extractTextCapability = (0,
  6056. _pdfjsLib.createPromiseCapability)();
  6057. this._extractTextPromises[i] = extractTextCapability.promise;
  6058. promise = promise.then(() => {
  6059. return this._pdfDocument
  6060. .getPage(i + 1)
  6061. .then((pdfPage) => {
  6062. return pdfPage.getTextContent();
  6063. })
  6064. .then(
  6065. (textContent) => {
  6066. const strBuf = [];
  6067. for (const textItem of textContent.items) {
  6068. strBuf.push(textItem.str);
  6069. if (textItem.hasEOL) {
  6070. strBuf.push("\n");
  6071. }
  6072. }
  6073. [
  6074. this._pageContents[i],
  6075. this._pageDiffs[i],
  6076. this._hasDiacritics[i],
  6077. ] = normalize(strBuf.join(""));
  6078. extractTextCapability.resolve();
  6079. },
  6080. (reason) => {
  6081. console.error(
  6082. `Unable to get text content for page ${i + 1}`,
  6083. reason
  6084. );
  6085. this._pageContents[i] = "";
  6086. this._pageDiffs[i] = null;
  6087. this._hasDiacritics[i] = false;
  6088. extractTextCapability.resolve();
  6089. }
  6090. );
  6091. });
  6092. }
  6093. }
  6094. #updatePage(index) {
  6095. if (this._scrollMatches && this._selected.pageIdx === index) {
  6096. this._linkService.page = index + 1;
  6097. }
  6098. this._eventBus.dispatch("updatetextlayermatches", {
  6099. source: this,
  6100. pageIndex: index,
  6101. });
  6102. }
  6103. #updateAllPages() {
  6104. this._eventBus.dispatch("updatetextlayermatches", {
  6105. source: this,
  6106. pageIndex: -1,
  6107. });
  6108. }
  6109. #nextMatch() {
  6110. const previous = this._state.findPrevious;
  6111. const currentPageIndex = this._linkService.page - 1;
  6112. const numPages = this._linkService.pagesCount;
  6113. this._highlightMatches = true;
  6114. if (this._dirtyMatch) {
  6115. this._dirtyMatch = false;
  6116. this._selected.pageIdx = this._selected.matchIdx = -1;
  6117. this._offset.pageIdx = currentPageIndex;
  6118. this._offset.matchIdx = null;
  6119. this._offset.wrapped = false;
  6120. this._resumePageIdx = null;
  6121. this._pageMatches.length = 0;
  6122. this._pageMatchesLength.length = 0;
  6123. this.#visitedPagesCount = 0;
  6124. this._matchesCountTotal = 0;
  6125. this.#updateAllPages();
  6126. for (let i = 0; i < numPages; i++) {
  6127. if (this._pendingFindMatches.has(i)) {
  6128. continue;
  6129. }
  6130. this._pendingFindMatches.add(i);
  6131. this._extractTextPromises[i].then(() => {
  6132. this._pendingFindMatches.delete(i);
  6133. this.#calculateMatch(i);
  6134. });
  6135. }
  6136. }
  6137. if (!this.#query) {
  6138. this.#updateUIState(FindState.FOUND);
  6139. return;
  6140. }
  6141. if (this._resumePageIdx) {
  6142. return;
  6143. }
  6144. const offset = this._offset;
  6145. this._pagesToSearch = numPages;
  6146. if (offset.matchIdx !== null) {
  6147. const numPageMatches = this._pageMatches[offset.pageIdx].length;
  6148. if (
  6149. (!previous && offset.matchIdx + 1 < numPageMatches) ||
  6150. (previous && offset.matchIdx > 0)
  6151. ) {
  6152. offset.matchIdx = previous
  6153. ? offset.matchIdx - 1
  6154. : offset.matchIdx + 1;
  6155. this.#updateMatch(true);
  6156. return;
  6157. }
  6158. this.#advanceOffsetPage(previous);
  6159. }
  6160. this.#nextPageMatch();
  6161. }
  6162. #matchesReady(matches) {
  6163. const offset = this._offset;
  6164. const numMatches = matches.length;
  6165. const previous = this._state.findPrevious;
  6166. if (numMatches) {
  6167. offset.matchIdx = previous ? numMatches - 1 : 0;
  6168. this.#updateMatch(true);
  6169. return true;
  6170. }
  6171. this.#advanceOffsetPage(previous);
  6172. if (offset.wrapped) {
  6173. offset.matchIdx = null;
  6174. if (this._pagesToSearch < 0) {
  6175. this.#updateMatch(false);
  6176. return true;
  6177. }
  6178. }
  6179. return false;
  6180. }
  6181. #nextPageMatch() {
  6182. if (this._resumePageIdx !== null) {
  6183. console.error("There can only be one pending page.");
  6184. }
  6185. let matches = null;
  6186. do {
  6187. const pageIdx = this._offset.pageIdx;
  6188. matches = this._pageMatches[pageIdx];
  6189. if (!matches) {
  6190. this._resumePageIdx = pageIdx;
  6191. break;
  6192. }
  6193. } while (!this.#matchesReady(matches));
  6194. }
  6195. #advanceOffsetPage(previous) {
  6196. const offset = this._offset;
  6197. const numPages = this._linkService.pagesCount;
  6198. offset.pageIdx = previous ? offset.pageIdx - 1 : offset.pageIdx + 1;
  6199. offset.matchIdx = null;
  6200. this._pagesToSearch--;
  6201. if (offset.pageIdx >= numPages || offset.pageIdx < 0) {
  6202. offset.pageIdx = previous ? numPages - 1 : 0;
  6203. offset.wrapped = true;
  6204. }
  6205. }
  6206. #updateMatch(found = false) {
  6207. let state = FindState.NOT_FOUND;
  6208. const wrapped = this._offset.wrapped;
  6209. this._offset.wrapped = false;
  6210. if (found) {
  6211. const previousPage = this._selected.pageIdx;
  6212. this._selected.pageIdx = this._offset.pageIdx;
  6213. this._selected.matchIdx = this._offset.matchIdx;
  6214. state = wrapped ? FindState.WRAPPED : FindState.FOUND;
  6215. if (
  6216. previousPage !== -1 &&
  6217. previousPage !== this._selected.pageIdx
  6218. ) {
  6219. this.#updatePage(previousPage);
  6220. }
  6221. }
  6222. this.#updateUIState(state, this._state.findPrevious);
  6223. if (this._selected.pageIdx !== -1) {
  6224. this._scrollMatches = true;
  6225. this.#updatePage(this._selected.pageIdx);
  6226. }
  6227. }
  6228. #onFindBarClose(evt) {
  6229. const pdfDocument = this._pdfDocument;
  6230. this._firstPageCapability.promise.then(() => {
  6231. if (
  6232. !this._pdfDocument ||
  6233. (pdfDocument && this._pdfDocument !== pdfDocument)
  6234. ) {
  6235. return;
  6236. }
  6237. if (this._findTimeout) {
  6238. clearTimeout(this._findTimeout);
  6239. this._findTimeout = null;
  6240. }
  6241. if (this._resumePageIdx) {
  6242. this._resumePageIdx = null;
  6243. this._dirtyMatch = true;
  6244. }
  6245. this.#updateUIState(FindState.FOUND);
  6246. this._highlightMatches = false;
  6247. this.#updateAllPages();
  6248. });
  6249. }
  6250. #requestMatchesCount() {
  6251. const { pageIdx, matchIdx } = this._selected;
  6252. let current = 0,
  6253. total = this._matchesCountTotal;
  6254. if (matchIdx !== -1) {
  6255. for (let i = 0; i < pageIdx; i++) {
  6256. current += this._pageMatches[i]?.length || 0;
  6257. }
  6258. current += matchIdx + 1;
  6259. }
  6260. if (current < 1 || current > total) {
  6261. current = total = 0;
  6262. }
  6263. return {
  6264. current,
  6265. total,
  6266. };
  6267. }
  6268. #updateUIResultsCount() {
  6269. this._eventBus.dispatch("updatefindmatchescount", {
  6270. source: this,
  6271. matchesCount: this.#requestMatchesCount(),
  6272. });
  6273. }
  6274. #updateUIState(state, previous = false) {
  6275. if (
  6276. !this.#updateMatchesCountOnProgress &&
  6277. (this.#visitedPagesCount !== this._linkService.pagesCount ||
  6278. state === FindState.PENDING)
  6279. ) {
  6280. return;
  6281. }
  6282. this._eventBus.dispatch("updatefindcontrolstate", {
  6283. source: this,
  6284. state,
  6285. previous,
  6286. matchesCount: this.#requestMatchesCount(),
  6287. rawQuery: this._state?.query ?? null,
  6288. });
  6289. }
  6290. }
  6291. exports.PDFFindController = PDFFindController;
  6292. /***/
  6293. },
  6294. /* 18 */
  6295. /***/ (__unused_webpack_module, exports) => {
  6296. Object.defineProperty(exports, "__esModule", {
  6297. value: true,
  6298. });
  6299. exports.CharacterType = void 0;
  6300. exports.getCharacterType = getCharacterType;
  6301. const CharacterType = {
  6302. SPACE: 0,
  6303. ALPHA_LETTER: 1,
  6304. PUNCT: 2,
  6305. HAN_LETTER: 3,
  6306. KATAKANA_LETTER: 4,
  6307. HIRAGANA_LETTER: 5,
  6308. HALFWIDTH_KATAKANA_LETTER: 6,
  6309. THAI_LETTER: 7,
  6310. };
  6311. exports.CharacterType = CharacterType;
  6312. function isAlphabeticalScript(charCode) {
  6313. return charCode < 0x2e80;
  6314. }
  6315. function isAscii(charCode) {
  6316. return (charCode & 0xff80) === 0;
  6317. }
  6318. function isAsciiAlpha(charCode) {
  6319. return (
  6320. (charCode >= 0x61 && charCode <= 0x7a) ||
  6321. (charCode >= 0x41 && charCode <= 0x5a)
  6322. );
  6323. }
  6324. function isAsciiDigit(charCode) {
  6325. return charCode >= 0x30 && charCode <= 0x39;
  6326. }
  6327. function isAsciiSpace(charCode) {
  6328. return (
  6329. charCode === 0x20 ||
  6330. charCode === 0x09 ||
  6331. charCode === 0x0d ||
  6332. charCode === 0x0a
  6333. );
  6334. }
  6335. function isHan(charCode) {
  6336. return (
  6337. (charCode >= 0x3400 && charCode <= 0x9fff) ||
  6338. (charCode >= 0xf900 && charCode <= 0xfaff)
  6339. );
  6340. }
  6341. function isKatakana(charCode) {
  6342. return charCode >= 0x30a0 && charCode <= 0x30ff;
  6343. }
  6344. function isHiragana(charCode) {
  6345. return charCode >= 0x3040 && charCode <= 0x309f;
  6346. }
  6347. function isHalfwidthKatakana(charCode) {
  6348. return charCode >= 0xff60 && charCode <= 0xff9f;
  6349. }
  6350. function isThai(charCode) {
  6351. return (charCode & 0xff80) === 0x0e00;
  6352. }
  6353. function getCharacterType(charCode) {
  6354. if (isAlphabeticalScript(charCode)) {
  6355. if (isAscii(charCode)) {
  6356. if (isAsciiSpace(charCode)) {
  6357. return CharacterType.SPACE;
  6358. } else if (
  6359. isAsciiAlpha(charCode) ||
  6360. isAsciiDigit(charCode) ||
  6361. charCode === 0x5f
  6362. ) {
  6363. return CharacterType.ALPHA_LETTER;
  6364. }
  6365. return CharacterType.PUNCT;
  6366. } else if (isThai(charCode)) {
  6367. return CharacterType.THAI_LETTER;
  6368. } else if (charCode === 0xa0) {
  6369. return CharacterType.SPACE;
  6370. }
  6371. return CharacterType.ALPHA_LETTER;
  6372. }
  6373. if (isHan(charCode)) {
  6374. return CharacterType.HAN_LETTER;
  6375. } else if (isKatakana(charCode)) {
  6376. return CharacterType.KATAKANA_LETTER;
  6377. } else if (isHiragana(charCode)) {
  6378. return CharacterType.HIRAGANA_LETTER;
  6379. } else if (isHalfwidthKatakana(charCode)) {
  6380. return CharacterType.HALFWIDTH_KATAKANA_LETTER;
  6381. }
  6382. return CharacterType.ALPHA_LETTER;
  6383. }
  6384. /***/
  6385. },
  6386. /* 19 */
  6387. /***/ (__unused_webpack_module, exports, __webpack_require__) => {
  6388. Object.defineProperty(exports, "__esModule", {
  6389. value: true,
  6390. });
  6391. exports.PDFHistory = void 0;
  6392. exports.isDestArraysEqual = isDestArraysEqual;
  6393. exports.isDestHashesEqual = isDestHashesEqual;
  6394. var _ui_utils = __webpack_require__(3);
  6395. var _event_utils = __webpack_require__(6);
  6396. const HASH_CHANGE_TIMEOUT = 1000;
  6397. const POSITION_UPDATED_THRESHOLD = 50;
  6398. const UPDATE_VIEWAREA_TIMEOUT = 1000;
  6399. function getCurrentHash() {
  6400. return document.location.hash;
  6401. }
  6402. class PDFHistory {
  6403. constructor({ linkService, eventBus }) {
  6404. this.linkService = linkService;
  6405. this.eventBus = eventBus;
  6406. this._initialized = false;
  6407. this._fingerprint = "";
  6408. this.reset();
  6409. this._boundEvents = null;
  6410. this.eventBus._on("pagesinit", () => {
  6411. this._isPagesLoaded = false;
  6412. this.eventBus._on(
  6413. "pagesloaded",
  6414. (evt) => {
  6415. this._isPagesLoaded = !!evt.pagesCount;
  6416. },
  6417. {
  6418. once: true,
  6419. }
  6420. );
  6421. });
  6422. }
  6423. initialize({ fingerprint, resetHistory = false, updateUrl = false }) {
  6424. if (!fingerprint || typeof fingerprint !== "string") {
  6425. console.error(
  6426. 'PDFHistory.initialize: The "fingerprint" must be a non-empty string.'
  6427. );
  6428. return;
  6429. }
  6430. if (this._initialized) {
  6431. this.reset();
  6432. }
  6433. const reInitialized =
  6434. this._fingerprint !== "" && this._fingerprint !== fingerprint;
  6435. this._fingerprint = fingerprint;
  6436. this._updateUrl = updateUrl === true;
  6437. this._initialized = true;
  6438. this._bindEvents();
  6439. const state = window.history.state;
  6440. this._popStateInProgress = false;
  6441. this._blockHashChange = 0;
  6442. this._currentHash = getCurrentHash();
  6443. this._numPositionUpdates = 0;
  6444. this._uid = this._maxUid = 0;
  6445. this._destination = null;
  6446. this._position = null;
  6447. if (!this._isValidState(state, true) || resetHistory) {
  6448. const { hash, page, rotation } = this._parseCurrentHash(true);
  6449. if (!hash || reInitialized || resetHistory) {
  6450. this._pushOrReplaceState(null, true);
  6451. return;
  6452. }
  6453. this._pushOrReplaceState(
  6454. {
  6455. hash,
  6456. page,
  6457. rotation,
  6458. },
  6459. true
  6460. );
  6461. return;
  6462. }
  6463. const destination = state.destination;
  6464. this._updateInternalState(destination, state.uid, true);
  6465. if (destination.rotation !== undefined) {
  6466. this._initialRotation = destination.rotation;
  6467. }
  6468. if (destination.dest) {
  6469. this._initialBookmark = JSON.stringify(destination.dest);
  6470. this._destination.page = null;
  6471. } else if (destination.hash) {
  6472. this._initialBookmark = destination.hash;
  6473. } else if (destination.page) {
  6474. this._initialBookmark = `page=${destination.page}`;
  6475. }
  6476. }
  6477. reset() {
  6478. if (this._initialized) {
  6479. this._pageHide();
  6480. this._initialized = false;
  6481. this._unbindEvents();
  6482. }
  6483. if (this._updateViewareaTimeout) {
  6484. clearTimeout(this._updateViewareaTimeout);
  6485. this._updateViewareaTimeout = null;
  6486. }
  6487. this._initialBookmark = null;
  6488. this._initialRotation = null;
  6489. }
  6490. push({ namedDest = null, explicitDest, pageNumber }) {
  6491. if (!this._initialized) {
  6492. return;
  6493. }
  6494. if (namedDest && typeof namedDest !== "string") {
  6495. console.error(
  6496. "PDFHistory.push: " +
  6497. `"${namedDest}" is not a valid namedDest parameter.`
  6498. );
  6499. return;
  6500. } else if (!Array.isArray(explicitDest)) {
  6501. console.error(
  6502. "PDFHistory.push: " +
  6503. `"${explicitDest}" is not a valid explicitDest parameter.`
  6504. );
  6505. return;
  6506. } else if (!this._isValidPage(pageNumber)) {
  6507. if (pageNumber !== null || this._destination) {
  6508. console.error(
  6509. "PDFHistory.push: " +
  6510. `"${pageNumber}" is not a valid pageNumber parameter.`
  6511. );
  6512. return;
  6513. }
  6514. }
  6515. const hash = namedDest || JSON.stringify(explicitDest);
  6516. if (!hash) {
  6517. return;
  6518. }
  6519. let forceReplace = false;
  6520. if (
  6521. this._destination &&
  6522. (isDestHashesEqual(this._destination.hash, hash) ||
  6523. isDestArraysEqual(this._destination.dest, explicitDest))
  6524. ) {
  6525. if (this._destination.page) {
  6526. return;
  6527. }
  6528. forceReplace = true;
  6529. }
  6530. if (this._popStateInProgress && !forceReplace) {
  6531. return;
  6532. }
  6533. this._pushOrReplaceState(
  6534. {
  6535. dest: explicitDest,
  6536. hash,
  6537. page: pageNumber,
  6538. rotation: this.linkService.rotation,
  6539. },
  6540. forceReplace
  6541. );
  6542. if (!this._popStateInProgress) {
  6543. this._popStateInProgress = true;
  6544. Promise.resolve().then(() => {
  6545. this._popStateInProgress = false;
  6546. });
  6547. }
  6548. }
  6549. pushPage(pageNumber) {
  6550. if (!this._initialized) {
  6551. return;
  6552. }
  6553. if (!this._isValidPage(pageNumber)) {
  6554. console.error(
  6555. `PDFHistory.pushPage: "${pageNumber}" is not a valid page number.`
  6556. );
  6557. return;
  6558. }
  6559. if (this._destination?.page === pageNumber) {
  6560. return;
  6561. }
  6562. if (this._popStateInProgress) {
  6563. return;
  6564. }
  6565. this._pushOrReplaceState({
  6566. dest: null,
  6567. hash: `page=${pageNumber}`,
  6568. page: pageNumber,
  6569. rotation: this.linkService.rotation,
  6570. });
  6571. if (!this._popStateInProgress) {
  6572. this._popStateInProgress = true;
  6573. Promise.resolve().then(() => {
  6574. this._popStateInProgress = false;
  6575. });
  6576. }
  6577. }
  6578. pushCurrentPosition() {
  6579. if (!this._initialized || this._popStateInProgress) {
  6580. return;
  6581. }
  6582. this._tryPushCurrentPosition();
  6583. }
  6584. back() {
  6585. if (!this._initialized || this._popStateInProgress) {
  6586. return;
  6587. }
  6588. const state = window.history.state;
  6589. if (this._isValidState(state) && state.uid > 0) {
  6590. window.history.back();
  6591. }
  6592. }
  6593. forward() {
  6594. if (!this._initialized || this._popStateInProgress) {
  6595. return;
  6596. }
  6597. const state = window.history.state;
  6598. if (this._isValidState(state) && state.uid < this._maxUid) {
  6599. window.history.forward();
  6600. }
  6601. }
  6602. get popStateInProgress() {
  6603. return (
  6604. this._initialized &&
  6605. (this._popStateInProgress || this._blockHashChange > 0)
  6606. );
  6607. }
  6608. get initialBookmark() {
  6609. return this._initialized ? this._initialBookmark : null;
  6610. }
  6611. get initialRotation() {
  6612. return this._initialized ? this._initialRotation : null;
  6613. }
  6614. _pushOrReplaceState(destination, forceReplace = false) {
  6615. const shouldReplace = forceReplace || !this._destination;
  6616. const newState = {
  6617. fingerprint: this._fingerprint,
  6618. uid: shouldReplace ? this._uid : this._uid + 1,
  6619. destination,
  6620. };
  6621. this._updateInternalState(destination, newState.uid);
  6622. let newUrl;
  6623. if (this._updateUrl && destination?.hash) {
  6624. const baseUrl = document.location.href.split("#")[0];
  6625. if (!baseUrl.startsWith("file://")) {
  6626. newUrl = `${baseUrl}#${destination.hash}`;
  6627. }
  6628. }
  6629. if (shouldReplace) {
  6630. window.history.replaceState(newState, "", newUrl);
  6631. } else {
  6632. window.history.pushState(newState, "", newUrl);
  6633. }
  6634. }
  6635. _tryPushCurrentPosition(temporary = false) {
  6636. if (!this._position) {
  6637. return;
  6638. }
  6639. let position = this._position;
  6640. if (temporary) {
  6641. position = Object.assign(Object.create(null), this._position);
  6642. position.temporary = true;
  6643. }
  6644. if (!this._destination) {
  6645. this._pushOrReplaceState(position);
  6646. return;
  6647. }
  6648. if (this._destination.temporary) {
  6649. this._pushOrReplaceState(position, true);
  6650. return;
  6651. }
  6652. if (this._destination.hash === position.hash) {
  6653. return;
  6654. }
  6655. if (
  6656. !this._destination.page &&
  6657. (POSITION_UPDATED_THRESHOLD <= 0 ||
  6658. this._numPositionUpdates <= POSITION_UPDATED_THRESHOLD)
  6659. ) {
  6660. return;
  6661. }
  6662. let forceReplace = false;
  6663. if (
  6664. this._destination.page >= position.first &&
  6665. this._destination.page <= position.page
  6666. ) {
  6667. if (
  6668. this._destination.dest !== undefined ||
  6669. !this._destination.first
  6670. ) {
  6671. return;
  6672. }
  6673. forceReplace = true;
  6674. }
  6675. this._pushOrReplaceState(position, forceReplace);
  6676. }
  6677. _isValidPage(val) {
  6678. return (
  6679. Number.isInteger(val) &&
  6680. val > 0 &&
  6681. val <= this.linkService.pagesCount
  6682. );
  6683. }
  6684. _isValidState(state, checkReload = false) {
  6685. if (!state) {
  6686. return false;
  6687. }
  6688. if (state.fingerprint !== this._fingerprint) {
  6689. if (checkReload) {
  6690. if (
  6691. typeof state.fingerprint !== "string" ||
  6692. state.fingerprint.length !== this._fingerprint.length
  6693. ) {
  6694. return false;
  6695. }
  6696. const [perfEntry] = performance.getEntriesByType("navigation");
  6697. if (perfEntry?.type !== "reload") {
  6698. return false;
  6699. }
  6700. } else {
  6701. return false;
  6702. }
  6703. }
  6704. if (!Number.isInteger(state.uid) || state.uid < 0) {
  6705. return false;
  6706. }
  6707. if (
  6708. state.destination === null ||
  6709. typeof state.destination !== "object"
  6710. ) {
  6711. return false;
  6712. }
  6713. return true;
  6714. }
  6715. _updateInternalState(destination, uid, removeTemporary = false) {
  6716. if (this._updateViewareaTimeout) {
  6717. clearTimeout(this._updateViewareaTimeout);
  6718. this._updateViewareaTimeout = null;
  6719. }
  6720. if (removeTemporary && destination?.temporary) {
  6721. delete destination.temporary;
  6722. }
  6723. this._destination = destination;
  6724. this._uid = uid;
  6725. this._maxUid = Math.max(this._maxUid, uid);
  6726. this._numPositionUpdates = 0;
  6727. }
  6728. _parseCurrentHash(checkNameddest = false) {
  6729. const hash = unescape(getCurrentHash()).substring(1);
  6730. const params = (0, _ui_utils.parseQueryString)(hash);
  6731. const nameddest = params.get("nameddest") || "";
  6732. let page = params.get("page") | 0;
  6733. if (
  6734. !this._isValidPage(page) ||
  6735. (checkNameddest && nameddest.length > 0)
  6736. ) {
  6737. page = null;
  6738. }
  6739. return {
  6740. hash,
  6741. page,
  6742. rotation: this.linkService.rotation,
  6743. };
  6744. }
  6745. _updateViewarea({ location }) {
  6746. if (this._updateViewareaTimeout) {
  6747. clearTimeout(this._updateViewareaTimeout);
  6748. this._updateViewareaTimeout = null;
  6749. }
  6750. this._position = {
  6751. hash: location.pdfOpenParams.substring(1),
  6752. page: this.linkService.page,
  6753. first: location.pageNumber,
  6754. rotation: location.rotation,
  6755. };
  6756. if (this._popStateInProgress) {
  6757. return;
  6758. }
  6759. if (
  6760. POSITION_UPDATED_THRESHOLD > 0 &&
  6761. this._isPagesLoaded &&
  6762. this._destination &&
  6763. !this._destination.page
  6764. ) {
  6765. this._numPositionUpdates++;
  6766. }
  6767. if (UPDATE_VIEWAREA_TIMEOUT > 0) {
  6768. this._updateViewareaTimeout = setTimeout(() => {
  6769. if (!this._popStateInProgress) {
  6770. this._tryPushCurrentPosition(true);
  6771. }
  6772. this._updateViewareaTimeout = null;
  6773. }, UPDATE_VIEWAREA_TIMEOUT);
  6774. }
  6775. }
  6776. _popState({ state }) {
  6777. const newHash = getCurrentHash(),
  6778. hashChanged = this._currentHash !== newHash;
  6779. this._currentHash = newHash;
  6780. if (!state) {
  6781. this._uid++;
  6782. const { hash, page, rotation } = this._parseCurrentHash();
  6783. this._pushOrReplaceState(
  6784. {
  6785. hash,
  6786. page,
  6787. rotation,
  6788. },
  6789. true
  6790. );
  6791. return;
  6792. }
  6793. if (!this._isValidState(state)) {
  6794. return;
  6795. }
  6796. this._popStateInProgress = true;
  6797. if (hashChanged) {
  6798. this._blockHashChange++;
  6799. (0, _event_utils.waitOnEventOrTimeout)({
  6800. target: window,
  6801. name: "hashchange",
  6802. delay: HASH_CHANGE_TIMEOUT,
  6803. }).then(() => {
  6804. this._blockHashChange--;
  6805. });
  6806. }
  6807. const destination = state.destination;
  6808. this._updateInternalState(destination, state.uid, true);
  6809. if ((0, _ui_utils.isValidRotation)(destination.rotation)) {
  6810. this.linkService.rotation = destination.rotation;
  6811. }
  6812. if (destination.dest) {
  6813. this.linkService.goToDestination(destination.dest);
  6814. } else if (destination.hash) {
  6815. this.linkService.setHash(destination.hash);
  6816. } else if (destination.page) {
  6817. this.linkService.page = destination.page;
  6818. }
  6819. Promise.resolve().then(() => {
  6820. this._popStateInProgress = false;
  6821. });
  6822. }
  6823. _pageHide() {
  6824. if (!this._destination || this._destination.temporary) {
  6825. this._tryPushCurrentPosition();
  6826. }
  6827. }
  6828. _bindEvents() {
  6829. if (this._boundEvents) {
  6830. return;
  6831. }
  6832. this._boundEvents = {
  6833. updateViewarea: this._updateViewarea.bind(this),
  6834. popState: this._popState.bind(this),
  6835. pageHide: this._pageHide.bind(this),
  6836. };
  6837. this.eventBus._on("updateviewarea", this._boundEvents.updateViewarea);
  6838. window.addEventListener("popstate", this._boundEvents.popState);
  6839. window.addEventListener("pagehide", this._boundEvents.pageHide);
  6840. }
  6841. _unbindEvents() {
  6842. if (!this._boundEvents) {
  6843. return;
  6844. }
  6845. this.eventBus._off(
  6846. "updateviewarea",
  6847. this._boundEvents.updateViewarea
  6848. );
  6849. window.removeEventListener("popstate", this._boundEvents.popState);
  6850. window.removeEventListener("pagehide", this._boundEvents.pageHide);
  6851. this._boundEvents = null;
  6852. }
  6853. }
  6854. exports.PDFHistory = PDFHistory;
  6855. function isDestHashesEqual(destHash, pushHash) {
  6856. if (typeof destHash !== "string" || typeof pushHash !== "string") {
  6857. return false;
  6858. }
  6859. if (destHash === pushHash) {
  6860. return true;
  6861. }
  6862. const nameddest = (0, _ui_utils.parseQueryString)(destHash).get(
  6863. "nameddest"
  6864. );
  6865. if (nameddest === pushHash) {
  6866. return true;
  6867. }
  6868. return false;
  6869. }
  6870. function isDestArraysEqual(firstDest, secondDest) {
  6871. function isEntryEqual(first, second) {
  6872. if (typeof first !== typeof second) {
  6873. return false;
  6874. }
  6875. if (Array.isArray(first) || Array.isArray(second)) {
  6876. return false;
  6877. }
  6878. if (first !== null && typeof first === "object" && second !== null) {
  6879. if (Object.keys(first).length !== Object.keys(second).length) {
  6880. return false;
  6881. }
  6882. for (const key in first) {
  6883. if (!isEntryEqual(first[key], second[key])) {
  6884. return false;
  6885. }
  6886. }
  6887. return true;
  6888. }
  6889. return (
  6890. first === second || (Number.isNaN(first) && Number.isNaN(second))
  6891. );
  6892. }
  6893. if (!(Array.isArray(firstDest) && Array.isArray(secondDest))) {
  6894. return false;
  6895. }
  6896. if (firstDest.length !== secondDest.length) {
  6897. return false;
  6898. }
  6899. for (let i = 0, ii = firstDest.length; i < ii; i++) {
  6900. if (!isEntryEqual(firstDest[i], secondDest[i])) {
  6901. return false;
  6902. }
  6903. }
  6904. return true;
  6905. }
  6906. /***/
  6907. },
  6908. /* 20 */
  6909. /***/ (__unused_webpack_module, exports, __webpack_require__) => {
  6910. Object.defineProperty(exports, "__esModule", {
  6911. value: true,
  6912. });
  6913. exports.PDFLayerViewer = void 0;
  6914. var _base_tree_viewer = __webpack_require__(12);
  6915. class PDFLayerViewer extends _base_tree_viewer.BaseTreeViewer {
  6916. constructor(options) {
  6917. super(options);
  6918. this.l10n = options.l10n;
  6919. this.eventBus._on("optionalcontentconfigchanged", (evt) => {
  6920. this.#updateLayers(evt.promise);
  6921. });
  6922. this.eventBus._on("resetlayers", () => {
  6923. this.#updateLayers();
  6924. });
  6925. this.eventBus._on(
  6926. "togglelayerstree",
  6927. this._toggleAllTreeItems.bind(this)
  6928. );
  6929. }
  6930. reset() {
  6931. super.reset();
  6932. this._optionalContentConfig = null;
  6933. this._optionalContentHash = null;
  6934. }
  6935. _dispatchEvent(layersCount) {
  6936. this.eventBus.dispatch("layersloaded", {
  6937. source: this,
  6938. layersCount,
  6939. });
  6940. }
  6941. _bindLink(element, { groupId, input }) {
  6942. const setVisibility = () => {
  6943. this._optionalContentConfig.setVisibility(groupId, input.checked);
  6944. this._optionalContentHash = this._optionalContentConfig.getHash();
  6945. this.eventBus.dispatch("optionalcontentconfig", {
  6946. source: this,
  6947. promise: Promise.resolve(this._optionalContentConfig),
  6948. });
  6949. };
  6950. element.onclick = (evt) => {
  6951. if (evt.target === input) {
  6952. setVisibility();
  6953. return true;
  6954. } else if (evt.target !== element) {
  6955. return true;
  6956. }
  6957. input.checked = !input.checked;
  6958. setVisibility();
  6959. return false;
  6960. };
  6961. }
  6962. async _setNestedName(element, { name = null }) {
  6963. if (typeof name === "string") {
  6964. element.textContent = this._normalizeTextContent(name);
  6965. return;
  6966. }
  6967. element.textContent = await this.l10n.get("additional_layers");
  6968. element.style.fontStyle = "italic";
  6969. }
  6970. _addToggleButton(div, { name = null }) {
  6971. super._addToggleButton(div, name === null);
  6972. }
  6973. _toggleAllTreeItems() {
  6974. if (!this._optionalContentConfig) {
  6975. return;
  6976. }
  6977. super._toggleAllTreeItems();
  6978. }
  6979. render({ optionalContentConfig, pdfDocument }) {
  6980. if (this._optionalContentConfig) {
  6981. this.reset();
  6982. }
  6983. this._optionalContentConfig = optionalContentConfig || null;
  6984. this._pdfDocument = pdfDocument || null;
  6985. const groups = optionalContentConfig?.getOrder();
  6986. if (!groups) {
  6987. this._dispatchEvent(0);
  6988. return;
  6989. }
  6990. this._optionalContentHash = optionalContentConfig.getHash();
  6991. const fragment = document.createDocumentFragment(),
  6992. queue = [
  6993. {
  6994. parent: fragment,
  6995. groups,
  6996. },
  6997. ];
  6998. let layersCount = 0,
  6999. hasAnyNesting = false;
  7000. while (queue.length > 0) {
  7001. const levelData = queue.shift();
  7002. for (const groupId of levelData.groups) {
  7003. const div = document.createElement("div");
  7004. div.className = "treeItem";
  7005. const element = document.createElement("a");
  7006. div.append(element);
  7007. if (typeof groupId === "object") {
  7008. hasAnyNesting = true;
  7009. this._addToggleButton(div, groupId);
  7010. this._setNestedName(element, groupId);
  7011. const itemsDiv = document.createElement("div");
  7012. itemsDiv.className = "treeItems";
  7013. div.append(itemsDiv);
  7014. queue.push({
  7015. parent: itemsDiv,
  7016. groups: groupId.order,
  7017. });
  7018. } else {
  7019. const group = optionalContentConfig.getGroup(groupId);
  7020. const input = document.createElement("input");
  7021. this._bindLink(element, {
  7022. groupId,
  7023. input,
  7024. });
  7025. input.type = "checkbox";
  7026. input.checked = group.visible;
  7027. const label = document.createElement("label");
  7028. label.textContent = this._normalizeTextContent(group.name);
  7029. label.append(input);
  7030. element.append(label);
  7031. layersCount++;
  7032. }
  7033. levelData.parent.append(div);
  7034. }
  7035. }
  7036. this._finishRendering(fragment, layersCount, hasAnyNesting);
  7037. }
  7038. async #updateLayers(promise = null) {
  7039. if (!this._optionalContentConfig) {
  7040. return;
  7041. }
  7042. const pdfDocument = this._pdfDocument;
  7043. const optionalContentConfig = await (promise ||
  7044. pdfDocument.getOptionalContentConfig());
  7045. if (pdfDocument !== this._pdfDocument) {
  7046. return;
  7047. }
  7048. if (promise) {
  7049. if (optionalContentConfig.getHash() === this._optionalContentHash) {
  7050. return;
  7051. }
  7052. } else {
  7053. this.eventBus.dispatch("optionalcontentconfig", {
  7054. source: this,
  7055. promise: Promise.resolve(optionalContentConfig),
  7056. });
  7057. }
  7058. this.render({
  7059. optionalContentConfig,
  7060. pdfDocument: this._pdfDocument,
  7061. });
  7062. }
  7063. }
  7064. exports.PDFLayerViewer = PDFLayerViewer;
  7065. /***/
  7066. },
  7067. /* 21 */
  7068. /***/ (__unused_webpack_module, exports, __webpack_require__) => {
  7069. Object.defineProperty(exports, "__esModule", {
  7070. value: true,
  7071. });
  7072. exports.PDFOutlineViewer = void 0;
  7073. var _base_tree_viewer = __webpack_require__(12);
  7074. var _pdfjsLib = __webpack_require__(4);
  7075. var _ui_utils = __webpack_require__(3);
  7076. class PDFOutlineViewer extends _base_tree_viewer.BaseTreeViewer {
  7077. constructor(options) {
  7078. super(options);
  7079. this.linkService = options.linkService;
  7080. this.downloadManager = options.downloadManager;
  7081. this.eventBus._on(
  7082. "toggleoutlinetree",
  7083. this._toggleAllTreeItems.bind(this)
  7084. );
  7085. this.eventBus._on(
  7086. "currentoutlineitem",
  7087. this._currentOutlineItem.bind(this)
  7088. );
  7089. this.eventBus._on("pagechanging", (evt) => {
  7090. this._currentPageNumber = evt.pageNumber;
  7091. });
  7092. this.eventBus._on("pagesloaded", (evt) => {
  7093. this._isPagesLoaded = !!evt.pagesCount;
  7094. if (
  7095. this._currentOutlineItemCapability &&
  7096. !this._currentOutlineItemCapability.settled
  7097. ) {
  7098. this._currentOutlineItemCapability.resolve(this._isPagesLoaded);
  7099. }
  7100. });
  7101. this.eventBus._on("sidebarviewchanged", (evt) => {
  7102. this._sidebarView = evt.view;
  7103. });
  7104. }
  7105. reset() {
  7106. super.reset();
  7107. this._outline = null;
  7108. this._pageNumberToDestHashCapability = null;
  7109. this._currentPageNumber = 1;
  7110. this._isPagesLoaded = null;
  7111. if (
  7112. this._currentOutlineItemCapability &&
  7113. !this._currentOutlineItemCapability.settled
  7114. ) {
  7115. this._currentOutlineItemCapability.resolve(false);
  7116. }
  7117. this._currentOutlineItemCapability = null;
  7118. }
  7119. _dispatchEvent(outlineCount) {
  7120. this._currentOutlineItemCapability = (0,
  7121. _pdfjsLib.createPromiseCapability)();
  7122. if (
  7123. outlineCount === 0 ||
  7124. this._pdfDocument?.loadingParams.disableAutoFetch
  7125. ) {
  7126. this._currentOutlineItemCapability.resolve(false);
  7127. } else if (this._isPagesLoaded !== null) {
  7128. this._currentOutlineItemCapability.resolve(this._isPagesLoaded);
  7129. }
  7130. this.eventBus.dispatch("outlineloaded", {
  7131. source: this,
  7132. outlineCount,
  7133. currentOutlineItemPromise:
  7134. this._currentOutlineItemCapability.promise,
  7135. });
  7136. }
  7137. _bindLink(
  7138. element,
  7139. { url, newWindow, action, attachment, dest, setOCGState }
  7140. ) {
  7141. const { linkService } = this;
  7142. if (url) {
  7143. linkService.addLinkAttributes(element, url, newWindow);
  7144. return;
  7145. }
  7146. if (action) {
  7147. element.href = linkService.getAnchorUrl("");
  7148. element.onclick = () => {
  7149. linkService.executeNamedAction(action);
  7150. return false;
  7151. };
  7152. return;
  7153. }
  7154. if (attachment) {
  7155. element.href = linkService.getAnchorUrl("");
  7156. element.onclick = () => {
  7157. this.downloadManager.openOrDownloadData(
  7158. element,
  7159. attachment.content,
  7160. attachment.filename
  7161. );
  7162. return false;
  7163. };
  7164. return;
  7165. }
  7166. if (setOCGState) {
  7167. element.href = linkService.getAnchorUrl("");
  7168. element.onclick = () => {
  7169. linkService.executeSetOCGState(setOCGState);
  7170. return false;
  7171. };
  7172. return;
  7173. }
  7174. element.href = linkService.getDestinationHash(dest);
  7175. element.onclick = (evt) => {
  7176. this._updateCurrentTreeItem(evt.target.parentNode);
  7177. if (dest) {
  7178. linkService.goToDestination(dest);
  7179. }
  7180. return false;
  7181. };
  7182. }
  7183. _setStyles(element, { bold, italic }) {
  7184. if (bold) {
  7185. element.style.fontWeight = "bold";
  7186. }
  7187. if (italic) {
  7188. element.style.fontStyle = "italic";
  7189. }
  7190. }
  7191. _addToggleButton(div, { count, items }) {
  7192. let hidden = false;
  7193. if (count < 0) {
  7194. let totalCount = items.length;
  7195. if (totalCount > 0) {
  7196. const queue = [...items];
  7197. while (queue.length > 0) {
  7198. const { count: nestedCount, items: nestedItems } =
  7199. queue.shift();
  7200. if (nestedCount > 0 && nestedItems.length > 0) {
  7201. totalCount += nestedItems.length;
  7202. queue.push(...nestedItems);
  7203. }
  7204. }
  7205. }
  7206. if (Math.abs(count) === totalCount) {
  7207. hidden = true;
  7208. }
  7209. }
  7210. super._addToggleButton(div, hidden);
  7211. }
  7212. _toggleAllTreeItems() {
  7213. if (!this._outline) {
  7214. return;
  7215. }
  7216. super._toggleAllTreeItems();
  7217. }
  7218. render({ outline, pdfDocument }) {
  7219. if (this._outline) {
  7220. this.reset();
  7221. }
  7222. this._outline = outline || null;
  7223. this._pdfDocument = pdfDocument || null;
  7224. if (!outline) {
  7225. this._dispatchEvent(0);
  7226. return;
  7227. }
  7228. const fragment = document.createDocumentFragment();
  7229. const queue = [
  7230. {
  7231. parent: fragment,
  7232. items: outline,
  7233. },
  7234. ];
  7235. let outlineCount = 0,
  7236. hasAnyNesting = false;
  7237. while (queue.length > 0) {
  7238. const levelData = queue.shift();
  7239. for (const item of levelData.items) {
  7240. const div = document.createElement("div");
  7241. div.className = "treeItem";
  7242. const element = document.createElement("a");
  7243. this._bindLink(element, item);
  7244. this._setStyles(element, item);
  7245. element.textContent = this._normalizeTextContent(item.title);
  7246. div.append(element);
  7247. if (item.items.length > 0) {
  7248. hasAnyNesting = true;
  7249. this._addToggleButton(div, item);
  7250. const itemsDiv = document.createElement("div");
  7251. itemsDiv.className = "treeItems";
  7252. div.append(itemsDiv);
  7253. queue.push({
  7254. parent: itemsDiv,
  7255. items: item.items,
  7256. });
  7257. }
  7258. levelData.parent.append(div);
  7259. outlineCount++;
  7260. }
  7261. }
  7262. this._finishRendering(fragment, outlineCount, hasAnyNesting);
  7263. }
  7264. async _currentOutlineItem() {
  7265. if (!this._isPagesLoaded) {
  7266. throw new Error(
  7267. "_currentOutlineItem: All pages have not been loaded."
  7268. );
  7269. }
  7270. if (!this._outline || !this._pdfDocument) {
  7271. return;
  7272. }
  7273. const pageNumberToDestHash = await this._getPageNumberToDestHash(
  7274. this._pdfDocument
  7275. );
  7276. if (!pageNumberToDestHash) {
  7277. return;
  7278. }
  7279. this._updateCurrentTreeItem(null);
  7280. if (this._sidebarView !== _ui_utils.SidebarView.OUTLINE) {
  7281. return;
  7282. }
  7283. for (let i = this._currentPageNumber; i > 0; i--) {
  7284. const destHash = pageNumberToDestHash.get(i);
  7285. if (!destHash) {
  7286. continue;
  7287. }
  7288. const linkElement = this.container.querySelector(
  7289. `a[href="${destHash}"]`
  7290. );
  7291. if (!linkElement) {
  7292. continue;
  7293. }
  7294. this._scrollToCurrentTreeItem(linkElement.parentNode);
  7295. break;
  7296. }
  7297. }
  7298. async _getPageNumberToDestHash(pdfDocument) {
  7299. if (this._pageNumberToDestHashCapability) {
  7300. return this._pageNumberToDestHashCapability.promise;
  7301. }
  7302. this._pageNumberToDestHashCapability = (0,
  7303. _pdfjsLib.createPromiseCapability)();
  7304. const pageNumberToDestHash = new Map(),
  7305. pageNumberNesting = new Map();
  7306. const queue = [
  7307. {
  7308. nesting: 0,
  7309. items: this._outline,
  7310. },
  7311. ];
  7312. while (queue.length > 0) {
  7313. const levelData = queue.shift(),
  7314. currentNesting = levelData.nesting;
  7315. for (const { dest, items } of levelData.items) {
  7316. let explicitDest, pageNumber;
  7317. if (typeof dest === "string") {
  7318. explicitDest = await pdfDocument.getDestination(dest);
  7319. if (pdfDocument !== this._pdfDocument) {
  7320. return null;
  7321. }
  7322. } else {
  7323. explicitDest = dest;
  7324. }
  7325. if (Array.isArray(explicitDest)) {
  7326. const [destRef] = explicitDest;
  7327. if (typeof destRef === "object" && destRef !== null) {
  7328. pageNumber = this.linkService._cachedPageNumber(destRef);
  7329. if (!pageNumber) {
  7330. try {
  7331. pageNumber =
  7332. (await pdfDocument.getPageIndex(destRef)) + 1;
  7333. if (pdfDocument !== this._pdfDocument) {
  7334. return null;
  7335. }
  7336. this.linkService.cachePageRef(pageNumber, destRef);
  7337. } catch (ex) {}
  7338. }
  7339. } else if (Number.isInteger(destRef)) {
  7340. pageNumber = destRef + 1;
  7341. }
  7342. if (
  7343. Number.isInteger(pageNumber) &&
  7344. (!pageNumberToDestHash.has(pageNumber) ||
  7345. currentNesting > pageNumberNesting.get(pageNumber))
  7346. ) {
  7347. const destHash = this.linkService.getDestinationHash(dest);
  7348. pageNumberToDestHash.set(pageNumber, destHash);
  7349. pageNumberNesting.set(pageNumber, currentNesting);
  7350. }
  7351. }
  7352. if (items.length > 0) {
  7353. queue.push({
  7354. nesting: currentNesting + 1,
  7355. items,
  7356. });
  7357. }
  7358. }
  7359. }
  7360. this._pageNumberToDestHashCapability.resolve(
  7361. pageNumberToDestHash.size > 0 ? pageNumberToDestHash : null
  7362. );
  7363. return this._pageNumberToDestHashCapability.promise;
  7364. }
  7365. }
  7366. exports.PDFOutlineViewer = PDFOutlineViewer;
  7367. /***/
  7368. },
  7369. /* 22 */
  7370. /***/ (__unused_webpack_module, exports, __webpack_require__) => {
  7371. Object.defineProperty(exports, "__esModule", {
  7372. value: true,
  7373. });
  7374. exports.PDFPresentationMode = void 0;
  7375. var _ui_utils = __webpack_require__(3);
  7376. var _pdfjsLib = __webpack_require__(4);
  7377. const DELAY_BEFORE_HIDING_CONTROLS = 3000;
  7378. const ACTIVE_SELECTOR = "pdfPresentationMode";
  7379. const CONTROLS_SELECTOR = "pdfPresentationModeControls";
  7380. const MOUSE_SCROLL_COOLDOWN_TIME = 50;
  7381. const PAGE_SWITCH_THRESHOLD = 0.1;
  7382. const SWIPE_MIN_DISTANCE_THRESHOLD = 50;
  7383. const SWIPE_ANGLE_THRESHOLD = Math.PI / 6;
  7384. class PDFPresentationMode {
  7385. #state = _ui_utils.PresentationModeState.UNKNOWN;
  7386. #args = null;
  7387. constructor({ container, pdfViewer, eventBus }) {
  7388. this.container = container;
  7389. this.pdfViewer = pdfViewer;
  7390. this.eventBus = eventBus;
  7391. this.contextMenuOpen = false;
  7392. this.mouseScrollTimeStamp = 0;
  7393. this.mouseScrollDelta = 0;
  7394. this.touchSwipeState = null;
  7395. }
  7396. async request() {
  7397. const { container, pdfViewer } = this;
  7398. if (
  7399. this.active ||
  7400. !pdfViewer.pagesCount ||
  7401. !container.requestFullscreen
  7402. ) {
  7403. return false;
  7404. }
  7405. this.#addFullscreenChangeListeners();
  7406. this.#notifyStateChange(_ui_utils.PresentationModeState.CHANGING);
  7407. const promise = container.requestFullscreen();
  7408. this.#args = {
  7409. pageNumber: pdfViewer.currentPageNumber,
  7410. scaleValue: pdfViewer.currentScaleValue,
  7411. scrollMode: pdfViewer.scrollMode,
  7412. spreadMode: null,
  7413. annotationEditorMode: null,
  7414. };
  7415. if (
  7416. pdfViewer.spreadMode !== _ui_utils.SpreadMode.NONE &&
  7417. !(pdfViewer.pageViewsReady && pdfViewer.hasEqualPageSizes)
  7418. ) {
  7419. console.warn(
  7420. "Ignoring Spread modes when entering PresentationMode, " +
  7421. "since the document may contain varying page sizes."
  7422. );
  7423. this.#args.spreadMode = pdfViewer.spreadMode;
  7424. }
  7425. if (
  7426. pdfViewer.annotationEditorMode !==
  7427. _pdfjsLib.AnnotationEditorType.DISABLE
  7428. ) {
  7429. this.#args.annotationEditorMode = pdfViewer.annotationEditorMode;
  7430. }
  7431. try {
  7432. await promise;
  7433. pdfViewer.focus();
  7434. return true;
  7435. } catch (reason) {
  7436. this.#removeFullscreenChangeListeners();
  7437. this.#notifyStateChange(_ui_utils.PresentationModeState.NORMAL);
  7438. }
  7439. return false;
  7440. }
  7441. get active() {
  7442. return (
  7443. this.#state === _ui_utils.PresentationModeState.CHANGING ||
  7444. this.#state === _ui_utils.PresentationModeState.FULLSCREEN
  7445. );
  7446. }
  7447. #mouseWheel(evt) {
  7448. if (!this.active) {
  7449. return;
  7450. }
  7451. evt.preventDefault();
  7452. const delta = (0, _ui_utils.normalizeWheelEventDelta)(evt);
  7453. const currentTime = Date.now();
  7454. const storedTime = this.mouseScrollTimeStamp;
  7455. if (
  7456. currentTime > storedTime &&
  7457. currentTime - storedTime < MOUSE_SCROLL_COOLDOWN_TIME
  7458. ) {
  7459. return;
  7460. }
  7461. if (
  7462. (this.mouseScrollDelta > 0 && delta < 0) ||
  7463. (this.mouseScrollDelta < 0 && delta > 0)
  7464. ) {
  7465. this.#resetMouseScrollState();
  7466. }
  7467. this.mouseScrollDelta += delta;
  7468. if (Math.abs(this.mouseScrollDelta) >= PAGE_SWITCH_THRESHOLD) {
  7469. const totalDelta = this.mouseScrollDelta;
  7470. this.#resetMouseScrollState();
  7471. const success =
  7472. totalDelta > 0
  7473. ? this.pdfViewer.previousPage()
  7474. : this.pdfViewer.nextPage();
  7475. if (success) {
  7476. this.mouseScrollTimeStamp = currentTime;
  7477. }
  7478. }
  7479. }
  7480. #notifyStateChange(state) {
  7481. this.#state = state;
  7482. this.eventBus.dispatch("presentationmodechanged", {
  7483. source: this,
  7484. state,
  7485. });
  7486. }
  7487. #enter() {
  7488. this.#notifyStateChange(_ui_utils.PresentationModeState.FULLSCREEN);
  7489. this.container.classList.add(ACTIVE_SELECTOR);
  7490. setTimeout(() => {
  7491. this.pdfViewer.scrollMode = _ui_utils.ScrollMode.PAGE;
  7492. if (this.#args.spreadMode !== null) {
  7493. this.pdfViewer.spreadMode = _ui_utils.SpreadMode.NONE;
  7494. }
  7495. this.pdfViewer.currentPageNumber = this.#args.pageNumber;
  7496. this.pdfViewer.currentScaleValue = "page-fit";
  7497. if (this.#args.annotationEditorMode !== null) {
  7498. this.pdfViewer.annotationEditorMode =
  7499. _pdfjsLib.AnnotationEditorType.NONE;
  7500. }
  7501. }, 0);
  7502. this.#addWindowListeners();
  7503. this.#showControls();
  7504. this.contextMenuOpen = false;
  7505. window.getSelection().removeAllRanges();
  7506. }
  7507. #exit() {
  7508. const pageNumber = this.pdfViewer.currentPageNumber;
  7509. this.container.classList.remove(ACTIVE_SELECTOR);
  7510. setTimeout(() => {
  7511. this.#removeFullscreenChangeListeners();
  7512. this.#notifyStateChange(_ui_utils.PresentationModeState.NORMAL);
  7513. this.pdfViewer.scrollMode = this.#args.scrollMode;
  7514. if (this.#args.spreadMode !== null) {
  7515. this.pdfViewer.spreadMode = this.#args.spreadMode;
  7516. }
  7517. this.pdfViewer.currentScaleValue = this.#args.scaleValue;
  7518. this.pdfViewer.currentPageNumber = pageNumber;
  7519. if (this.#args.annotationEditorMode !== null) {
  7520. this.pdfViewer.annotationEditorMode =
  7521. this.#args.annotationEditorMode;
  7522. }
  7523. this.#args = null;
  7524. }, 0);
  7525. this.#removeWindowListeners();
  7526. this.#hideControls();
  7527. this.#resetMouseScrollState();
  7528. this.contextMenuOpen = false;
  7529. }
  7530. #mouseDown(evt) {
  7531. if (this.contextMenuOpen) {
  7532. this.contextMenuOpen = false;
  7533. evt.preventDefault();
  7534. return;
  7535. }
  7536. if (evt.button !== 0) {
  7537. return;
  7538. }
  7539. if (
  7540. evt.target.href &&
  7541. evt.target.parentNode?.hasAttribute("data-internal-link")
  7542. ) {
  7543. return;
  7544. }
  7545. evt.preventDefault();
  7546. if (evt.shiftKey) {
  7547. this.pdfViewer.previousPage();
  7548. } else {
  7549. this.pdfViewer.nextPage();
  7550. }
  7551. }
  7552. #contextMenu() {
  7553. this.contextMenuOpen = true;
  7554. }
  7555. #showControls() {
  7556. if (this.controlsTimeout) {
  7557. clearTimeout(this.controlsTimeout);
  7558. } else {
  7559. this.container.classList.add(CONTROLS_SELECTOR);
  7560. }
  7561. this.controlsTimeout = setTimeout(() => {
  7562. this.container.classList.remove(CONTROLS_SELECTOR);
  7563. delete this.controlsTimeout;
  7564. }, DELAY_BEFORE_HIDING_CONTROLS);
  7565. }
  7566. #hideControls() {
  7567. if (!this.controlsTimeout) {
  7568. return;
  7569. }
  7570. clearTimeout(this.controlsTimeout);
  7571. this.container.classList.remove(CONTROLS_SELECTOR);
  7572. delete this.controlsTimeout;
  7573. }
  7574. #resetMouseScrollState() {
  7575. this.mouseScrollTimeStamp = 0;
  7576. this.mouseScrollDelta = 0;
  7577. }
  7578. #touchSwipe(evt) {
  7579. if (!this.active) {
  7580. return;
  7581. }
  7582. if (evt.touches.length > 1) {
  7583. this.touchSwipeState = null;
  7584. return;
  7585. }
  7586. switch (evt.type) {
  7587. case "touchstart":
  7588. this.touchSwipeState = {
  7589. startX: evt.touches[0].pageX,
  7590. startY: evt.touches[0].pageY,
  7591. endX: evt.touches[0].pageX,
  7592. endY: evt.touches[0].pageY,
  7593. };
  7594. break;
  7595. case "touchmove":
  7596. if (this.touchSwipeState === null) {
  7597. return;
  7598. }
  7599. this.touchSwipeState.endX = evt.touches[0].pageX;
  7600. this.touchSwipeState.endY = evt.touches[0].pageY;
  7601. evt.preventDefault();
  7602. break;
  7603. case "touchend":
  7604. if (this.touchSwipeState === null) {
  7605. return;
  7606. }
  7607. let delta = 0;
  7608. const dx =
  7609. this.touchSwipeState.endX - this.touchSwipeState.startX;
  7610. const dy =
  7611. this.touchSwipeState.endY - this.touchSwipeState.startY;
  7612. const absAngle = Math.abs(Math.atan2(dy, dx));
  7613. if (
  7614. Math.abs(dx) > SWIPE_MIN_DISTANCE_THRESHOLD &&
  7615. (absAngle <= SWIPE_ANGLE_THRESHOLD ||
  7616. absAngle >= Math.PI - SWIPE_ANGLE_THRESHOLD)
  7617. ) {
  7618. delta = dx;
  7619. } else if (
  7620. Math.abs(dy) > SWIPE_MIN_DISTANCE_THRESHOLD &&
  7621. Math.abs(absAngle - Math.PI / 2) <= SWIPE_ANGLE_THRESHOLD
  7622. ) {
  7623. delta = dy;
  7624. }
  7625. if (delta > 0) {
  7626. this.pdfViewer.previousPage();
  7627. } else if (delta < 0) {
  7628. this.pdfViewer.nextPage();
  7629. }
  7630. break;
  7631. }
  7632. }
  7633. #addWindowListeners() {
  7634. this.showControlsBind = this.#showControls.bind(this);
  7635. this.mouseDownBind = this.#mouseDown.bind(this);
  7636. this.mouseWheelBind = this.#mouseWheel.bind(this);
  7637. this.resetMouseScrollStateBind =
  7638. this.#resetMouseScrollState.bind(this);
  7639. this.contextMenuBind = this.#contextMenu.bind(this);
  7640. this.touchSwipeBind = this.#touchSwipe.bind(this);
  7641. window.addEventListener("mousemove", this.showControlsBind);
  7642. window.addEventListener("mousedown", this.mouseDownBind);
  7643. window.addEventListener("wheel", this.mouseWheelBind, {
  7644. passive: false,
  7645. });
  7646. window.addEventListener("keydown", this.resetMouseScrollStateBind);
  7647. window.addEventListener("contextmenu", this.contextMenuBind);
  7648. window.addEventListener("touchstart", this.touchSwipeBind);
  7649. window.addEventListener("touchmove", this.touchSwipeBind);
  7650. window.addEventListener("touchend", this.touchSwipeBind);
  7651. }
  7652. #removeWindowListeners() {
  7653. window.removeEventListener("mousemove", this.showControlsBind);
  7654. window.removeEventListener("mousedown", this.mouseDownBind);
  7655. window.removeEventListener("wheel", this.mouseWheelBind, {
  7656. passive: false,
  7657. });
  7658. window.removeEventListener("keydown", this.resetMouseScrollStateBind);
  7659. window.removeEventListener("contextmenu", this.contextMenuBind);
  7660. window.removeEventListener("touchstart", this.touchSwipeBind);
  7661. window.removeEventListener("touchmove", this.touchSwipeBind);
  7662. window.removeEventListener("touchend", this.touchSwipeBind);
  7663. delete this.showControlsBind;
  7664. delete this.mouseDownBind;
  7665. delete this.mouseWheelBind;
  7666. delete this.resetMouseScrollStateBind;
  7667. delete this.contextMenuBind;
  7668. delete this.touchSwipeBind;
  7669. }
  7670. #fullscreenChange() {
  7671. if (document.fullscreenElement) {
  7672. this.#enter();
  7673. } else {
  7674. this.#exit();
  7675. }
  7676. }
  7677. #addFullscreenChangeListeners() {
  7678. this.fullscreenChangeBind = this.#fullscreenChange.bind(this);
  7679. window.addEventListener(
  7680. "fullscreenchange",
  7681. this.fullscreenChangeBind
  7682. );
  7683. }
  7684. #removeFullscreenChangeListeners() {
  7685. window.removeEventListener(
  7686. "fullscreenchange",
  7687. this.fullscreenChangeBind
  7688. );
  7689. delete this.fullscreenChangeBind;
  7690. }
  7691. }
  7692. exports.PDFPresentationMode = PDFPresentationMode;
  7693. /***/
  7694. },
  7695. /* 23 */
  7696. /***/ (__unused_webpack_module, exports, __webpack_require__) => {
  7697. Object.defineProperty(exports, "__esModule", {
  7698. value: true,
  7699. });
  7700. exports.PDFRenderingQueue = void 0;
  7701. var _pdfjsLib = __webpack_require__(4);
  7702. var _ui_utils = __webpack_require__(3);
  7703. const CLEANUP_TIMEOUT = 30000;
  7704. class PDFRenderingQueue {
  7705. constructor() {
  7706. this.pdfViewer = null;
  7707. this.pdfThumbnailViewer = null;
  7708. this.onIdle = null;
  7709. this.highestPriorityPage = null;
  7710. this.idleTimeout = null;
  7711. this.printing = false;
  7712. this.isThumbnailViewEnabled = false;
  7713. }
  7714. setViewer(pdfViewer) {
  7715. this.pdfViewer = pdfViewer;
  7716. }
  7717. setThumbnailViewer(pdfThumbnailViewer) {
  7718. this.pdfThumbnailViewer = pdfThumbnailViewer;
  7719. }
  7720. isHighestPriority(view) {
  7721. return this.highestPriorityPage === view.renderingId;
  7722. }
  7723. hasViewer() {
  7724. return !!this.pdfViewer;
  7725. }
  7726. renderHighestPriority(currentlyVisiblePages) {
  7727. if (this.idleTimeout) {
  7728. clearTimeout(this.idleTimeout);
  7729. this.idleTimeout = null;
  7730. }
  7731. if (this.pdfViewer.forceRendering(currentlyVisiblePages)) {
  7732. return;
  7733. }
  7734. if (
  7735. this.isThumbnailViewEnabled &&
  7736. this.pdfThumbnailViewer?.forceRendering()
  7737. ) {
  7738. return;
  7739. }
  7740. if (this.printing) {
  7741. return;
  7742. }
  7743. if (this.onIdle) {
  7744. this.idleTimeout = setTimeout(
  7745. this.onIdle.bind(this),
  7746. CLEANUP_TIMEOUT
  7747. );
  7748. }
  7749. }
  7750. getHighestPriority(
  7751. visible,
  7752. views,
  7753. scrolledDown,
  7754. preRenderExtra = false
  7755. ) {
  7756. const visibleViews = visible.views,
  7757. numVisible = visibleViews.length;
  7758. if (numVisible === 0) {
  7759. return null;
  7760. }
  7761. for (let i = 0; i < numVisible; i++) {
  7762. const view = visibleViews[i].view;
  7763. if (!this.isViewFinished(view)) {
  7764. return view;
  7765. }
  7766. }
  7767. const firstId = visible.first.id,
  7768. lastId = visible.last.id;
  7769. if (lastId - firstId + 1 > numVisible) {
  7770. const visibleIds = visible.ids;
  7771. for (let i = 1, ii = lastId - firstId; i < ii; i++) {
  7772. const holeId = scrolledDown ? firstId + i : lastId - i;
  7773. if (visibleIds.has(holeId)) {
  7774. continue;
  7775. }
  7776. const holeView = views[holeId - 1];
  7777. if (!this.isViewFinished(holeView)) {
  7778. return holeView;
  7779. }
  7780. }
  7781. }
  7782. let preRenderIndex = scrolledDown ? lastId : firstId - 2;
  7783. let preRenderView = views[preRenderIndex];
  7784. if (preRenderView && !this.isViewFinished(preRenderView)) {
  7785. return preRenderView;
  7786. }
  7787. if (preRenderExtra) {
  7788. preRenderIndex += scrolledDown ? 1 : -1;
  7789. preRenderView = views[preRenderIndex];
  7790. if (preRenderView && !this.isViewFinished(preRenderView)) {
  7791. return preRenderView;
  7792. }
  7793. }
  7794. return null;
  7795. }
  7796. isViewFinished(view) {
  7797. return view.renderingState === _ui_utils.RenderingStates.FINISHED;
  7798. }
  7799. renderView(view) {
  7800. switch (view.renderingState) {
  7801. case _ui_utils.RenderingStates.FINISHED:
  7802. return false;
  7803. case _ui_utils.RenderingStates.PAUSED:
  7804. this.highestPriorityPage = view.renderingId;
  7805. view.resume();
  7806. break;
  7807. case _ui_utils.RenderingStates.RUNNING:
  7808. this.highestPriorityPage = view.renderingId;
  7809. break;
  7810. case _ui_utils.RenderingStates.INITIAL:
  7811. this.highestPriorityPage = view.renderingId;
  7812. view
  7813. .draw()
  7814. .finally(() => {
  7815. this.renderHighestPriority();
  7816. })
  7817. .catch((reason) => {
  7818. if (reason instanceof _pdfjsLib.RenderingCancelledException) {
  7819. return;
  7820. }
  7821. console.error(`renderView: "${reason}"`);
  7822. });
  7823. break;
  7824. }
  7825. return true;
  7826. }
  7827. }
  7828. exports.PDFRenderingQueue = PDFRenderingQueue;
  7829. /***/
  7830. },
  7831. /* 24 */
  7832. /***/ (__unused_webpack_module, exports, __webpack_require__) => {
  7833. Object.defineProperty(exports, "__esModule", {
  7834. value: true,
  7835. });
  7836. exports.PDFScriptingManager = void 0;
  7837. var _ui_utils = __webpack_require__(3);
  7838. var _pdfjsLib = __webpack_require__(4);
  7839. class PDFScriptingManager {
  7840. constructor({
  7841. eventBus,
  7842. sandboxBundleSrc = null,
  7843. scriptingFactory = null,
  7844. docPropertiesLookup = null,
  7845. }) {
  7846. this._pdfDocument = null;
  7847. this._pdfViewer = null;
  7848. this._closeCapability = null;
  7849. this._destroyCapability = null;
  7850. this._scripting = null;
  7851. this._ready = false;
  7852. this._eventBus = eventBus;
  7853. this._sandboxBundleSrc = sandboxBundleSrc;
  7854. this._scriptingFactory = scriptingFactory;
  7855. this._docPropertiesLookup = docPropertiesLookup;
  7856. }
  7857. setViewer(pdfViewer) {
  7858. this._pdfViewer = pdfViewer;
  7859. }
  7860. async setDocument(pdfDocument) {
  7861. if (this._pdfDocument) {
  7862. await this._destroyScripting();
  7863. }
  7864. this._pdfDocument = pdfDocument;
  7865. if (!pdfDocument) {
  7866. return;
  7867. }
  7868. const [objects, calculationOrder, docActions] = await Promise.all([
  7869. pdfDocument.getFieldObjects(),
  7870. pdfDocument.getCalculationOrderIds(),
  7871. pdfDocument.getJSActions(),
  7872. ]);
  7873. if (!objects && !docActions) {
  7874. await this._destroyScripting();
  7875. return;
  7876. }
  7877. if (pdfDocument !== this._pdfDocument) {
  7878. return;
  7879. }
  7880. try {
  7881. this._scripting = this._createScripting();
  7882. } catch (error) {
  7883. console.error(
  7884. `PDFScriptingManager.setDocument: "${error?.message}".`
  7885. );
  7886. await this._destroyScripting();
  7887. return;
  7888. }
  7889. this._internalEvents.set("updatefromsandbox", (event) => {
  7890. if (event?.source !== window) {
  7891. return;
  7892. }
  7893. this._updateFromSandbox(event.detail);
  7894. });
  7895. this._internalEvents.set("dispatcheventinsandbox", (event) => {
  7896. this._scripting?.dispatchEventInSandbox(event.detail);
  7897. });
  7898. this._internalEvents.set(
  7899. "pagechanging",
  7900. ({ pageNumber, previous }) => {
  7901. if (pageNumber === previous) {
  7902. return;
  7903. }
  7904. this._dispatchPageClose(previous);
  7905. this._dispatchPageOpen(pageNumber);
  7906. }
  7907. );
  7908. this._internalEvents.set("pagerendered", ({ pageNumber }) => {
  7909. if (!this._pageOpenPending.has(pageNumber)) {
  7910. return;
  7911. }
  7912. if (pageNumber !== this._pdfViewer.currentPageNumber) {
  7913. return;
  7914. }
  7915. this._dispatchPageOpen(pageNumber);
  7916. });
  7917. this._internalEvents.set("pagesdestroy", async (event) => {
  7918. await this._dispatchPageClose(this._pdfViewer.currentPageNumber);
  7919. await this._scripting?.dispatchEventInSandbox({
  7920. id: "doc",
  7921. name: "WillClose",
  7922. });
  7923. this._closeCapability?.resolve();
  7924. });
  7925. for (const [name, listener] of this._internalEvents) {
  7926. this._eventBus._on(name, listener);
  7927. }
  7928. try {
  7929. const docProperties = await this._getDocProperties();
  7930. if (pdfDocument !== this._pdfDocument) {
  7931. return;
  7932. }
  7933. await this._scripting.createSandbox({
  7934. objects,
  7935. calculationOrder,
  7936. appInfo: {
  7937. platform: navigator.platform,
  7938. language: navigator.language,
  7939. },
  7940. docInfo: {
  7941. ...docProperties,
  7942. actions: docActions,
  7943. },
  7944. });
  7945. this._eventBus.dispatch("sandboxcreated", {
  7946. source: this,
  7947. });
  7948. } catch (error) {
  7949. console.error(
  7950. `PDFScriptingManager.setDocument: "${error?.message}".`
  7951. );
  7952. await this._destroyScripting();
  7953. return;
  7954. }
  7955. await this._scripting?.dispatchEventInSandbox({
  7956. id: "doc",
  7957. name: "Open",
  7958. });
  7959. await this._dispatchPageOpen(this._pdfViewer.currentPageNumber, true);
  7960. Promise.resolve().then(() => {
  7961. if (pdfDocument === this._pdfDocument) {
  7962. this._ready = true;
  7963. }
  7964. });
  7965. }
  7966. async dispatchWillSave(detail) {
  7967. return this._scripting?.dispatchEventInSandbox({
  7968. id: "doc",
  7969. name: "WillSave",
  7970. });
  7971. }
  7972. async dispatchDidSave(detail) {
  7973. return this._scripting?.dispatchEventInSandbox({
  7974. id: "doc",
  7975. name: "DidSave",
  7976. });
  7977. }
  7978. async dispatchWillPrint(detail) {
  7979. return this._scripting?.dispatchEventInSandbox({
  7980. id: "doc",
  7981. name: "WillPrint",
  7982. });
  7983. }
  7984. async dispatchDidPrint(detail) {
  7985. return this._scripting?.dispatchEventInSandbox({
  7986. id: "doc",
  7987. name: "DidPrint",
  7988. });
  7989. }
  7990. get destroyPromise() {
  7991. return this._destroyCapability?.promise || null;
  7992. }
  7993. get ready() {
  7994. return this._ready;
  7995. }
  7996. get _internalEvents() {
  7997. return (0, _pdfjsLib.shadow)(this, "_internalEvents", new Map());
  7998. }
  7999. get _pageOpenPending() {
  8000. return (0, _pdfjsLib.shadow)(this, "_pageOpenPending", new Set());
  8001. }
  8002. get _visitedPages() {
  8003. return (0, _pdfjsLib.shadow)(this, "_visitedPages", new Map());
  8004. }
  8005. async _updateFromSandbox(detail) {
  8006. const isInPresentationMode =
  8007. this._pdfViewer.isInPresentationMode ||
  8008. this._pdfViewer.isChangingPresentationMode;
  8009. const { id, siblings, command, value } = detail;
  8010. if (!id) {
  8011. switch (command) {
  8012. case "clear":
  8013. console.clear();
  8014. break;
  8015. case "error":
  8016. console.error(value);
  8017. break;
  8018. case "layout": {
  8019. if (isInPresentationMode) {
  8020. return;
  8021. }
  8022. const modes = (0, _ui_utils.apiPageLayoutToViewerModes)(value);
  8023. this._pdfViewer.spreadMode = modes.spreadMode;
  8024. break;
  8025. }
  8026. case "page-num":
  8027. this._pdfViewer.currentPageNumber = value + 1;
  8028. break;
  8029. case "print":
  8030. await this._pdfViewer.pagesPromise;
  8031. this._eventBus.dispatch("print", {
  8032. source: this,
  8033. });
  8034. break;
  8035. case "println":
  8036. console.log(value);
  8037. break;
  8038. case "zoom":
  8039. if (isInPresentationMode) {
  8040. return;
  8041. }
  8042. this._pdfViewer.currentScaleValue = value;
  8043. break;
  8044. case "SaveAs":
  8045. this._eventBus.dispatch("download", {
  8046. source: this,
  8047. });
  8048. break;
  8049. case "FirstPage":
  8050. this._pdfViewer.currentPageNumber = 1;
  8051. break;
  8052. case "LastPage":
  8053. this._pdfViewer.currentPageNumber = this._pdfViewer.pagesCount;
  8054. break;
  8055. case "NextPage":
  8056. this._pdfViewer.nextPage();
  8057. break;
  8058. case "PrevPage":
  8059. this._pdfViewer.previousPage();
  8060. break;
  8061. case "ZoomViewIn":
  8062. if (isInPresentationMode) {
  8063. return;
  8064. }
  8065. this._pdfViewer.increaseScale();
  8066. break;
  8067. case "ZoomViewOut":
  8068. if (isInPresentationMode) {
  8069. return;
  8070. }
  8071. this._pdfViewer.decreaseScale();
  8072. break;
  8073. }
  8074. return;
  8075. }
  8076. if (isInPresentationMode) {
  8077. if (detail.focus) {
  8078. return;
  8079. }
  8080. }
  8081. delete detail.id;
  8082. delete detail.siblings;
  8083. const ids = siblings ? [id, ...siblings] : [id];
  8084. for (const elementId of ids) {
  8085. const element = document.querySelector(
  8086. `[data-element-id="${elementId}"]`
  8087. );
  8088. if (element) {
  8089. element.dispatchEvent(
  8090. new CustomEvent("updatefromsandbox", {
  8091. detail,
  8092. })
  8093. );
  8094. } else {
  8095. this._pdfDocument?.annotationStorage.setValue(elementId, detail);
  8096. }
  8097. }
  8098. }
  8099. async _dispatchPageOpen(pageNumber, initialize = false) {
  8100. const pdfDocument = this._pdfDocument,
  8101. visitedPages = this._visitedPages;
  8102. if (initialize) {
  8103. this._closeCapability = (0, _pdfjsLib.createPromiseCapability)();
  8104. }
  8105. if (!this._closeCapability) {
  8106. return;
  8107. }
  8108. const pageView = this._pdfViewer.getPageView(pageNumber - 1);
  8109. if (pageView?.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  8110. this._pageOpenPending.add(pageNumber);
  8111. return;
  8112. }
  8113. this._pageOpenPending.delete(pageNumber);
  8114. const actionsPromise = (async () => {
  8115. const actions = await (!visitedPages.has(pageNumber)
  8116. ? pageView.pdfPage?.getJSActions()
  8117. : null);
  8118. if (pdfDocument !== this._pdfDocument) {
  8119. return;
  8120. }
  8121. await this._scripting?.dispatchEventInSandbox({
  8122. id: "page",
  8123. name: "PageOpen",
  8124. pageNumber,
  8125. actions,
  8126. });
  8127. })();
  8128. visitedPages.set(pageNumber, actionsPromise);
  8129. }
  8130. async _dispatchPageClose(pageNumber) {
  8131. const pdfDocument = this._pdfDocument,
  8132. visitedPages = this._visitedPages;
  8133. if (!this._closeCapability) {
  8134. return;
  8135. }
  8136. if (this._pageOpenPending.has(pageNumber)) {
  8137. return;
  8138. }
  8139. const actionsPromise = visitedPages.get(pageNumber);
  8140. if (!actionsPromise) {
  8141. return;
  8142. }
  8143. visitedPages.set(pageNumber, null);
  8144. await actionsPromise;
  8145. if (pdfDocument !== this._pdfDocument) {
  8146. return;
  8147. }
  8148. await this._scripting?.dispatchEventInSandbox({
  8149. id: "page",
  8150. name: "PageClose",
  8151. pageNumber,
  8152. });
  8153. }
  8154. async _getDocProperties() {
  8155. if (this._docPropertiesLookup) {
  8156. return this._docPropertiesLookup(this._pdfDocument);
  8157. }
  8158. throw new Error("_getDocProperties: Unable to lookup properties.");
  8159. }
  8160. _createScripting() {
  8161. this._destroyCapability = (0, _pdfjsLib.createPromiseCapability)();
  8162. if (this._scripting) {
  8163. throw new Error("_createScripting: Scripting already exists.");
  8164. }
  8165. if (this._scriptingFactory) {
  8166. return this._scriptingFactory.createScripting({
  8167. sandboxBundleSrc: this._sandboxBundleSrc,
  8168. });
  8169. }
  8170. throw new Error("_createScripting: Cannot create scripting.");
  8171. }
  8172. async _destroyScripting() {
  8173. if (!this._scripting) {
  8174. this._pdfDocument = null;
  8175. this._destroyCapability?.resolve();
  8176. return;
  8177. }
  8178. if (this._closeCapability) {
  8179. await Promise.race([
  8180. this._closeCapability.promise,
  8181. new Promise((resolve) => {
  8182. setTimeout(resolve, 1000);
  8183. }),
  8184. ]).catch((reason) => {});
  8185. this._closeCapability = null;
  8186. }
  8187. this._pdfDocument = null;
  8188. try {
  8189. await this._scripting.destroySandbox();
  8190. } catch (ex) {}
  8191. for (const [name, listener] of this._internalEvents) {
  8192. this._eventBus._off(name, listener);
  8193. }
  8194. this._internalEvents.clear();
  8195. this._pageOpenPending.clear();
  8196. this._visitedPages.clear();
  8197. this._scripting = null;
  8198. this._ready = false;
  8199. this._destroyCapability?.resolve();
  8200. }
  8201. }
  8202. exports.PDFScriptingManager = PDFScriptingManager;
  8203. /***/
  8204. },
  8205. /* 25 */
  8206. /***/ (__unused_webpack_module, exports, __webpack_require__) => {
  8207. Object.defineProperty(exports, "__esModule", {
  8208. value: true,
  8209. });
  8210. exports.PDFSidebar = void 0;
  8211. var _ui_utils = __webpack_require__(3);
  8212. const UI_NOTIFICATION_CLASS = "pdfSidebarNotification";
  8213. class PDFSidebar {
  8214. constructor({
  8215. elements,
  8216. pdfViewer,
  8217. pdfThumbnailViewer,
  8218. eventBus,
  8219. l10n,
  8220. }) {
  8221. this.isOpen = false;
  8222. this.active = _ui_utils.SidebarView.THUMBS;
  8223. this.isInitialViewSet = false;
  8224. this.isInitialEventDispatched = false;
  8225. this.onToggled = null;
  8226. this.pdfViewer = pdfViewer;
  8227. this.pdfThumbnailViewer = pdfThumbnailViewer;
  8228. this.outerContainer = elements.outerContainer;
  8229. this.sidebarContainer = elements.sidebarContainer;
  8230. this.toggleButton = elements.toggleButton;
  8231. this.thumbnailButton = elements.thumbnailButton;
  8232. this.outlineButton = elements.outlineButton;
  8233. this.attachmentsButton = elements.attachmentsButton;
  8234. this.layersButton = elements.layersButton;
  8235. this.thumbnailView = elements.thumbnailView;
  8236. this.outlineView = elements.outlineView;
  8237. this.attachmentsView = elements.attachmentsView;
  8238. this.layersView = elements.layersView;
  8239. this._outlineOptionsContainer = elements.outlineOptionsContainer;
  8240. this._currentOutlineItemButton = elements.currentOutlineItemButton;
  8241. this.eventBus = eventBus;
  8242. this.l10n = l10n;
  8243. this.#addEventListeners();
  8244. }
  8245. reset() {
  8246. this.isInitialViewSet = false;
  8247. this.isInitialEventDispatched = false;
  8248. this.#hideUINotification(true);
  8249. this.switchView(_ui_utils.SidebarView.THUMBS);
  8250. this.outlineButton.disabled = false;
  8251. this.attachmentsButton.disabled = false;
  8252. this.layersButton.disabled = false;
  8253. this._currentOutlineItemButton.disabled = true;
  8254. }
  8255. get visibleView() {
  8256. return this.isOpen ? this.active : _ui_utils.SidebarView.NONE;
  8257. }
  8258. setInitialView(view = _ui_utils.SidebarView.NONE) {
  8259. if (this.isInitialViewSet) {
  8260. return;
  8261. }
  8262. this.isInitialViewSet = true;
  8263. if (
  8264. view === _ui_utils.SidebarView.NONE ||
  8265. view === _ui_utils.SidebarView.UNKNOWN
  8266. ) {
  8267. this.#dispatchEvent();
  8268. return;
  8269. }
  8270. this.switchView(view, true);
  8271. if (!this.isInitialEventDispatched) {
  8272. this.#dispatchEvent();
  8273. }
  8274. }
  8275. switchView(view, forceOpen = false) {
  8276. const isViewChanged = view !== this.active;
  8277. let shouldForceRendering = false;
  8278. switch (view) {
  8279. case _ui_utils.SidebarView.NONE:
  8280. if (this.isOpen) {
  8281. this.close();
  8282. }
  8283. return;
  8284. case _ui_utils.SidebarView.THUMBS:
  8285. if (this.isOpen && isViewChanged) {
  8286. shouldForceRendering = true;
  8287. }
  8288. break;
  8289. case _ui_utils.SidebarView.OUTLINE:
  8290. if (this.outlineButton.disabled) {
  8291. return;
  8292. }
  8293. break;
  8294. case _ui_utils.SidebarView.ATTACHMENTS:
  8295. if (this.attachmentsButton.disabled) {
  8296. return;
  8297. }
  8298. break;
  8299. case _ui_utils.SidebarView.LAYERS:
  8300. if (this.layersButton.disabled) {
  8301. return;
  8302. }
  8303. break;
  8304. default:
  8305. console.error(
  8306. `PDFSidebar.switchView: "${view}" is not a valid view.`
  8307. );
  8308. return;
  8309. }
  8310. this.active = view;
  8311. const isThumbs = view === _ui_utils.SidebarView.THUMBS,
  8312. isOutline = view === _ui_utils.SidebarView.OUTLINE,
  8313. isAttachments = view === _ui_utils.SidebarView.ATTACHMENTS,
  8314. isLayers = view === _ui_utils.SidebarView.LAYERS;
  8315. this.thumbnailButton.classList.toggle("toggled", isThumbs);
  8316. this.outlineButton.classList.toggle("toggled", isOutline);
  8317. this.attachmentsButton.classList.toggle("toggled", isAttachments);
  8318. this.layersButton.classList.toggle("toggled", isLayers);
  8319. this.thumbnailButton.setAttribute("aria-checked", isThumbs);
  8320. this.outlineButton.setAttribute("aria-checked", isOutline);
  8321. this.attachmentsButton.setAttribute("aria-checked", isAttachments);
  8322. this.layersButton.setAttribute("aria-checked", isLayers);
  8323. this.thumbnailView.classList.toggle("hidden", !isThumbs);
  8324. this.outlineView.classList.toggle("hidden", !isOutline);
  8325. this.attachmentsView.classList.toggle("hidden", !isAttachments);
  8326. this.layersView.classList.toggle("hidden", !isLayers);
  8327. this._outlineOptionsContainer.classList.toggle("hidden", !isOutline);
  8328. if (forceOpen && !this.isOpen) {
  8329. this.open();
  8330. return;
  8331. }
  8332. if (shouldForceRendering) {
  8333. this.#updateThumbnailViewer();
  8334. this.#forceRendering();
  8335. }
  8336. if (isViewChanged) {
  8337. this.#dispatchEvent();
  8338. }
  8339. }
  8340. open() {
  8341. if (this.isOpen) {
  8342. return;
  8343. }
  8344. this.isOpen = true;
  8345. this.toggleButton.classList.add("toggled");
  8346. this.toggleButton.setAttribute("aria-expanded", "true");
  8347. this.outerContainer.classList.add("sidebarMoving", "sidebarOpen");
  8348. if (this.active === _ui_utils.SidebarView.THUMBS) {
  8349. this.#updateThumbnailViewer();
  8350. }
  8351. this.#forceRendering();
  8352. this.#dispatchEvent();
  8353. this.#hideUINotification();
  8354. }
  8355. close() {
  8356. if (!this.isOpen) {
  8357. return;
  8358. }
  8359. this.isOpen = false;
  8360. this.toggleButton.classList.remove("toggled");
  8361. this.toggleButton.setAttribute("aria-expanded", "false");
  8362. this.outerContainer.classList.add("sidebarMoving");
  8363. this.outerContainer.classList.remove("sidebarOpen");
  8364. this.#forceRendering();
  8365. this.#dispatchEvent();
  8366. }
  8367. toggle() {
  8368. if (this.isOpen) {
  8369. this.close();
  8370. } else {
  8371. this.open();
  8372. }
  8373. }
  8374. #dispatchEvent() {
  8375. if (this.isInitialViewSet && !this.isInitialEventDispatched) {
  8376. this.isInitialEventDispatched = true;
  8377. }
  8378. this.eventBus.dispatch("sidebarviewchanged", {
  8379. source: this,
  8380. view: this.visibleView,
  8381. });
  8382. }
  8383. #forceRendering() {
  8384. if (this.onToggled) {
  8385. this.onToggled();
  8386. } else {
  8387. this.pdfViewer.forceRendering();
  8388. this.pdfThumbnailViewer.forceRendering();
  8389. }
  8390. }
  8391. #updateThumbnailViewer() {
  8392. const { pdfViewer, pdfThumbnailViewer } = this;
  8393. const pagesCount = pdfViewer.pagesCount;
  8394. for (let pageIndex = 0; pageIndex < pagesCount; pageIndex++) {
  8395. const pageView = pdfViewer.getPageView(pageIndex);
  8396. if (
  8397. pageView?.renderingState === _ui_utils.RenderingStates.FINISHED
  8398. ) {
  8399. const thumbnailView = pdfThumbnailViewer.getThumbnail(pageIndex);
  8400. thumbnailView.setImage(pageView);
  8401. }
  8402. }
  8403. pdfThumbnailViewer.scrollThumbnailIntoView(
  8404. pdfViewer.currentPageNumber
  8405. );
  8406. }
  8407. #showUINotification() {
  8408. this.toggleButton.setAttribute(
  8409. "data-l10n-id",
  8410. "toggle_sidebar_notification2"
  8411. );
  8412. this.l10n.translate(this.toggleButton);
  8413. if (!this.isOpen) {
  8414. this.toggleButton.classList.add(UI_NOTIFICATION_CLASS);
  8415. }
  8416. }
  8417. #hideUINotification(reset = false) {
  8418. if (this.isOpen || reset) {
  8419. this.toggleButton.classList.remove(UI_NOTIFICATION_CLASS);
  8420. }
  8421. if (reset) {
  8422. this.toggleButton.setAttribute("data-l10n-id", "toggle_sidebar");
  8423. this.l10n.translate(this.toggleButton);
  8424. }
  8425. }
  8426. #addEventListeners() {
  8427. this.sidebarContainer.addEventListener("transitionend", (evt) => {
  8428. if (evt.target === this.sidebarContainer) {
  8429. this.outerContainer.classList.remove("sidebarMoving");
  8430. }
  8431. });
  8432. this.toggleButton.addEventListener("click", () => {
  8433. this.toggle();
  8434. });
  8435. this.thumbnailButton.addEventListener("click", () => {
  8436. this.switchView(_ui_utils.SidebarView.THUMBS);
  8437. });
  8438. this.outlineButton.addEventListener("click", () => {
  8439. this.switchView(_ui_utils.SidebarView.OUTLINE);
  8440. });
  8441. this.outlineButton.addEventListener("dblclick", () => {
  8442. this.eventBus.dispatch("toggleoutlinetree", {
  8443. source: this,
  8444. });
  8445. });
  8446. this.attachmentsButton.addEventListener("click", () => {
  8447. this.switchView(_ui_utils.SidebarView.ATTACHMENTS);
  8448. });
  8449. this.layersButton.addEventListener("click", () => {
  8450. this.switchView(_ui_utils.SidebarView.LAYERS);
  8451. });
  8452. this.layersButton.addEventListener("dblclick", () => {
  8453. this.eventBus.dispatch("resetlayers", {
  8454. source: this,
  8455. });
  8456. });
  8457. this._currentOutlineItemButton.addEventListener("click", () => {
  8458. this.eventBus.dispatch("currentoutlineitem", {
  8459. source: this,
  8460. });
  8461. });
  8462. const onTreeLoaded = (count, button, view) => {
  8463. button.disabled = !count;
  8464. if (count) {
  8465. this.#showUINotification();
  8466. } else if (this.active === view) {
  8467. this.switchView(_ui_utils.SidebarView.THUMBS);
  8468. }
  8469. };
  8470. this.eventBus._on("outlineloaded", (evt) => {
  8471. onTreeLoaded(
  8472. evt.outlineCount,
  8473. this.outlineButton,
  8474. _ui_utils.SidebarView.OUTLINE
  8475. );
  8476. evt.currentOutlineItemPromise.then((enabled) => {
  8477. if (!this.isInitialViewSet) {
  8478. return;
  8479. }
  8480. this._currentOutlineItemButton.disabled = !enabled;
  8481. });
  8482. });
  8483. this.eventBus._on("attachmentsloaded", (evt) => {
  8484. onTreeLoaded(
  8485. evt.attachmentsCount,
  8486. this.attachmentsButton,
  8487. _ui_utils.SidebarView.ATTACHMENTS
  8488. );
  8489. });
  8490. this.eventBus._on("layersloaded", (evt) => {
  8491. onTreeLoaded(
  8492. evt.layersCount,
  8493. this.layersButton,
  8494. _ui_utils.SidebarView.LAYERS
  8495. );
  8496. });
  8497. this.eventBus._on("presentationmodechanged", (evt) => {
  8498. if (
  8499. evt.state === _ui_utils.PresentationModeState.NORMAL &&
  8500. this.visibleView === _ui_utils.SidebarView.THUMBS
  8501. ) {
  8502. this.#updateThumbnailViewer();
  8503. }
  8504. });
  8505. }
  8506. }
  8507. exports.PDFSidebar = PDFSidebar;
  8508. /***/
  8509. },
  8510. /* 26 */
  8511. /***/ (__unused_webpack_module, exports, __webpack_require__) => {
  8512. Object.defineProperty(exports, "__esModule", {
  8513. value: true,
  8514. });
  8515. exports.PDFSidebarResizer = void 0;
  8516. var _ui_utils = __webpack_require__(3);
  8517. const SIDEBAR_WIDTH_VAR = "--sidebar-width";
  8518. const SIDEBAR_MIN_WIDTH = 200;
  8519. const SIDEBAR_RESIZING_CLASS = "sidebarResizing";
  8520. class PDFSidebarResizer {
  8521. constructor(options, eventBus, l10n) {
  8522. this.isRTL = false;
  8523. this.sidebarOpen = false;
  8524. this._width = null;
  8525. this._outerContainerWidth = null;
  8526. this._boundEvents = Object.create(null);
  8527. this.outerContainer = options.outerContainer;
  8528. this.resizer = options.resizer;
  8529. this.eventBus = eventBus;
  8530. l10n.getDirection().then((dir) => {
  8531. this.isRTL = dir === "rtl";
  8532. });
  8533. this._addEventListeners();
  8534. }
  8535. get outerContainerWidth() {
  8536. return (this._outerContainerWidth ||=
  8537. this.outerContainer.clientWidth);
  8538. }
  8539. _updateWidth(width = 0) {
  8540. const maxWidth = Math.floor(this.outerContainerWidth / 2);
  8541. if (width > maxWidth) {
  8542. width = maxWidth;
  8543. }
  8544. if (width < SIDEBAR_MIN_WIDTH) {
  8545. width = SIDEBAR_MIN_WIDTH;
  8546. }
  8547. if (width === this._width) {
  8548. return false;
  8549. }
  8550. this._width = width;
  8551. _ui_utils.docStyle.setProperty(SIDEBAR_WIDTH_VAR, `${width}px`);
  8552. return true;
  8553. }
  8554. _mouseMove(evt) {
  8555. let width = evt.clientX;
  8556. if (this.isRTL) {
  8557. width = this.outerContainerWidth - width;
  8558. }
  8559. this._updateWidth(width);
  8560. }
  8561. _mouseUp(evt) {
  8562. this.outerContainer.classList.remove(SIDEBAR_RESIZING_CLASS);
  8563. this.eventBus.dispatch("resize", {
  8564. source: this,
  8565. });
  8566. const _boundEvents = this._boundEvents;
  8567. window.removeEventListener("mousemove", _boundEvents.mouseMove);
  8568. window.removeEventListener("mouseup", _boundEvents.mouseUp);
  8569. }
  8570. _addEventListeners() {
  8571. const _boundEvents = this._boundEvents;
  8572. _boundEvents.mouseMove = this._mouseMove.bind(this);
  8573. _boundEvents.mouseUp = this._mouseUp.bind(this);
  8574. this.resizer.addEventListener("mousedown", (evt) => {
  8575. if (evt.button !== 0) {
  8576. return;
  8577. }
  8578. this.outerContainer.classList.add(SIDEBAR_RESIZING_CLASS);
  8579. window.addEventListener("mousemove", _boundEvents.mouseMove);
  8580. window.addEventListener("mouseup", _boundEvents.mouseUp);
  8581. });
  8582. this.eventBus._on("sidebarviewchanged", (evt) => {
  8583. this.sidebarOpen = !!evt?.view;
  8584. });
  8585. this.eventBus._on("resize", (evt) => {
  8586. if (evt?.source !== window) {
  8587. return;
  8588. }
  8589. this._outerContainerWidth = null;
  8590. if (!this._width) {
  8591. return;
  8592. }
  8593. if (!this.sidebarOpen) {
  8594. this._updateWidth(this._width);
  8595. return;
  8596. }
  8597. this.outerContainer.classList.add(SIDEBAR_RESIZING_CLASS);
  8598. const updated = this._updateWidth(this._width);
  8599. Promise.resolve().then(() => {
  8600. this.outerContainer.classList.remove(SIDEBAR_RESIZING_CLASS);
  8601. if (updated) {
  8602. this.eventBus.dispatch("resize", {
  8603. source: this,
  8604. });
  8605. }
  8606. });
  8607. });
  8608. }
  8609. }
  8610. exports.PDFSidebarResizer = PDFSidebarResizer;
  8611. /***/
  8612. },
  8613. /* 27 */
  8614. /***/ (__unused_webpack_module, exports, __webpack_require__) => {
  8615. Object.defineProperty(exports, "__esModule", {
  8616. value: true,
  8617. });
  8618. exports.PDFThumbnailViewer = void 0;
  8619. var _ui_utils = __webpack_require__(3);
  8620. var _pdf_thumbnail_view = __webpack_require__(28);
  8621. const THUMBNAIL_SCROLL_MARGIN = -19;
  8622. const THUMBNAIL_SELECTED_CLASS = "selected";
  8623. class PDFThumbnailViewer {
  8624. constructor({
  8625. container,
  8626. linkService,
  8627. renderingQueue,
  8628. l10n,
  8629. pageColors,
  8630. }) {
  8631. this.container = container;
  8632. this.linkService = linkService;
  8633. this.renderingQueue = renderingQueue;
  8634. this.l10n = l10n;
  8635. this.pageColors = pageColors || null;
  8636. if (
  8637. this.pageColors &&
  8638. !(
  8639. CSS.supports("color", this.pageColors.background) &&
  8640. CSS.supports("color", this.pageColors.foreground)
  8641. )
  8642. ) {
  8643. if (this.pageColors.background || this.pageColors.foreground) {
  8644. console.warn(
  8645. "PDFThumbnailViewer: Ignoring `pageColors`-option, since the browser doesn't support the values used."
  8646. );
  8647. }
  8648. this.pageColors = null;
  8649. }
  8650. this.scroll = (0, _ui_utils.watchScroll)(
  8651. this.container,
  8652. this._scrollUpdated.bind(this)
  8653. );
  8654. this._resetView();
  8655. }
  8656. _scrollUpdated() {
  8657. this.renderingQueue.renderHighestPriority();
  8658. }
  8659. getThumbnail(index) {
  8660. return this._thumbnails[index];
  8661. }
  8662. _getVisibleThumbs() {
  8663. return (0, _ui_utils.getVisibleElements)({
  8664. scrollEl: this.container,
  8665. views: this._thumbnails,
  8666. });
  8667. }
  8668. scrollThumbnailIntoView(pageNumber) {
  8669. if (!this.pdfDocument) {
  8670. return;
  8671. }
  8672. const thumbnailView = this._thumbnails[pageNumber - 1];
  8673. if (!thumbnailView) {
  8674. console.error(
  8675. 'scrollThumbnailIntoView: Invalid "pageNumber" parameter.'
  8676. );
  8677. return;
  8678. }
  8679. if (pageNumber !== this._currentPageNumber) {
  8680. const prevThumbnailView =
  8681. this._thumbnails[this._currentPageNumber - 1];
  8682. prevThumbnailView.div.classList.remove(THUMBNAIL_SELECTED_CLASS);
  8683. thumbnailView.div.classList.add(THUMBNAIL_SELECTED_CLASS);
  8684. }
  8685. const { first, last, views } = this._getVisibleThumbs();
  8686. if (views.length > 0) {
  8687. let shouldScroll = false;
  8688. if (pageNumber <= first.id || pageNumber >= last.id) {
  8689. shouldScroll = true;
  8690. } else {
  8691. for (const { id, percent } of views) {
  8692. if (id !== pageNumber) {
  8693. continue;
  8694. }
  8695. shouldScroll = percent < 100;
  8696. break;
  8697. }
  8698. }
  8699. if (shouldScroll) {
  8700. (0, _ui_utils.scrollIntoView)(thumbnailView.div, {
  8701. top: THUMBNAIL_SCROLL_MARGIN,
  8702. });
  8703. }
  8704. }
  8705. this._currentPageNumber = pageNumber;
  8706. }
  8707. get pagesRotation() {
  8708. return this._pagesRotation;
  8709. }
  8710. set pagesRotation(rotation) {
  8711. if (!(0, _ui_utils.isValidRotation)(rotation)) {
  8712. throw new Error("Invalid thumbnails rotation angle.");
  8713. }
  8714. if (!this.pdfDocument) {
  8715. return;
  8716. }
  8717. if (this._pagesRotation === rotation) {
  8718. return;
  8719. }
  8720. this._pagesRotation = rotation;
  8721. const updateArgs = {
  8722. rotation,
  8723. };
  8724. for (const thumbnail of this._thumbnails) {
  8725. thumbnail.update(updateArgs);
  8726. }
  8727. }
  8728. cleanup() {
  8729. for (const thumbnail of this._thumbnails) {
  8730. if (
  8731. thumbnail.renderingState !== _ui_utils.RenderingStates.FINISHED
  8732. ) {
  8733. thumbnail.reset();
  8734. }
  8735. }
  8736. _pdf_thumbnail_view.TempImageFactory.destroyCanvas();
  8737. }
  8738. _resetView() {
  8739. this._thumbnails = [];
  8740. this._currentPageNumber = 1;
  8741. this._pageLabels = null;
  8742. this._pagesRotation = 0;
  8743. this.container.textContent = "";
  8744. }
  8745. setDocument(pdfDocument) {
  8746. if (this.pdfDocument) {
  8747. this._cancelRendering();
  8748. this._resetView();
  8749. }
  8750. this.pdfDocument = pdfDocument;
  8751. if (!pdfDocument) {
  8752. return;
  8753. }
  8754. const firstPagePromise = pdfDocument.getPage(1);
  8755. const optionalContentConfigPromise =
  8756. pdfDocument.getOptionalContentConfig();
  8757. firstPagePromise
  8758. .then((firstPdfPage) => {
  8759. const pagesCount = pdfDocument.numPages;
  8760. const viewport = firstPdfPage.getViewport({
  8761. scale: 1,
  8762. });
  8763. for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) {
  8764. const thumbnail = new _pdf_thumbnail_view.PDFThumbnailView({
  8765. container: this.container,
  8766. id: pageNum,
  8767. defaultViewport: viewport.clone(),
  8768. optionalContentConfigPromise,
  8769. linkService: this.linkService,
  8770. renderingQueue: this.renderingQueue,
  8771. l10n: this.l10n,
  8772. pageColors: this.pageColors,
  8773. });
  8774. this._thumbnails.push(thumbnail);
  8775. }
  8776. this._thumbnails[0]?.setPdfPage(firstPdfPage);
  8777. const thumbnailView =
  8778. this._thumbnails[this._currentPageNumber - 1];
  8779. thumbnailView.div.classList.add(THUMBNAIL_SELECTED_CLASS);
  8780. })
  8781. .catch((reason) => {
  8782. console.error("Unable to initialize thumbnail viewer", reason);
  8783. });
  8784. }
  8785. _cancelRendering() {
  8786. for (const thumbnail of this._thumbnails) {
  8787. thumbnail.cancelRendering();
  8788. }
  8789. }
  8790. setPageLabels(labels) {
  8791. if (!this.pdfDocument) {
  8792. return;
  8793. }
  8794. if (!labels) {
  8795. this._pageLabels = null;
  8796. } else if (
  8797. !(
  8798. Array.isArray(labels) &&
  8799. this.pdfDocument.numPages === labels.length
  8800. )
  8801. ) {
  8802. this._pageLabels = null;
  8803. console.error(
  8804. "PDFThumbnailViewer_setPageLabels: Invalid page labels."
  8805. );
  8806. } else {
  8807. this._pageLabels = labels;
  8808. }
  8809. for (let i = 0, ii = this._thumbnails.length; i < ii; i++) {
  8810. this._thumbnails[i].setPageLabel(this._pageLabels?.[i] ?? null);
  8811. }
  8812. }
  8813. async #ensurePdfPageLoaded(thumbView) {
  8814. if (thumbView.pdfPage) {
  8815. return thumbView.pdfPage;
  8816. }
  8817. try {
  8818. const pdfPage = await this.pdfDocument.getPage(thumbView.id);
  8819. if (!thumbView.pdfPage) {
  8820. thumbView.setPdfPage(pdfPage);
  8821. }
  8822. return pdfPage;
  8823. } catch (reason) {
  8824. console.error("Unable to get page for thumb view", reason);
  8825. return null;
  8826. }
  8827. }
  8828. #getScrollAhead(visible) {
  8829. if (visible.first?.id === 1) {
  8830. return true;
  8831. } else if (visible.last?.id === this._thumbnails.length) {
  8832. return false;
  8833. }
  8834. return this.scroll.down;
  8835. }
  8836. forceRendering() {
  8837. const visibleThumbs = this._getVisibleThumbs();
  8838. const scrollAhead = this.#getScrollAhead(visibleThumbs);
  8839. const thumbView = this.renderingQueue.getHighestPriority(
  8840. visibleThumbs,
  8841. this._thumbnails,
  8842. scrollAhead
  8843. );
  8844. if (thumbView) {
  8845. this.#ensurePdfPageLoaded(thumbView).then(() => {
  8846. this.renderingQueue.renderView(thumbView);
  8847. });
  8848. return true;
  8849. }
  8850. return false;
  8851. }
  8852. }
  8853. exports.PDFThumbnailViewer = PDFThumbnailViewer;
  8854. /***/
  8855. },
  8856. /* 28 */
  8857. /***/ (__unused_webpack_module, exports, __webpack_require__) => {
  8858. Object.defineProperty(exports, "__esModule", {
  8859. value: true,
  8860. });
  8861. exports.TempImageFactory = exports.PDFThumbnailView = void 0;
  8862. var _ui_utils = __webpack_require__(3);
  8863. var _pdfjsLib = __webpack_require__(4);
  8864. const DRAW_UPSCALE_FACTOR = 2;
  8865. const MAX_NUM_SCALING_STEPS = 3;
  8866. const THUMBNAIL_CANVAS_BORDER_WIDTH = 1;
  8867. const THUMBNAIL_WIDTH = 98;
  8868. class TempImageFactory {
  8869. static #tempCanvas = null;
  8870. static getCanvas(width, height) {
  8871. const tempCanvas = (this.#tempCanvas ||=
  8872. document.createElement("canvas"));
  8873. tempCanvas.width = width;
  8874. tempCanvas.height = height;
  8875. const ctx = tempCanvas.getContext("2d", {
  8876. alpha: false,
  8877. });
  8878. ctx.save();
  8879. ctx.fillStyle = "rgb(255, 255, 255)";
  8880. ctx.fillRect(0, 0, width, height);
  8881. ctx.restore();
  8882. return [tempCanvas, tempCanvas.getContext("2d")];
  8883. }
  8884. static destroyCanvas() {
  8885. const tempCanvas = this.#tempCanvas;
  8886. if (tempCanvas) {
  8887. tempCanvas.width = 0;
  8888. tempCanvas.height = 0;
  8889. }
  8890. this.#tempCanvas = null;
  8891. }
  8892. }
  8893. exports.TempImageFactory = TempImageFactory;
  8894. class PDFThumbnailView {
  8895. constructor({
  8896. container,
  8897. id,
  8898. defaultViewport,
  8899. optionalContentConfigPromise,
  8900. linkService,
  8901. renderingQueue,
  8902. l10n,
  8903. pageColors,
  8904. }) {
  8905. this.id = id;
  8906. this.renderingId = "thumbnail" + id;
  8907. this.pageLabel = null;
  8908. this.pdfPage = null;
  8909. this.rotation = 0;
  8910. this.viewport = defaultViewport;
  8911. this.pdfPageRotate = defaultViewport.rotation;
  8912. this._optionalContentConfigPromise =
  8913. optionalContentConfigPromise || null;
  8914. this.pageColors = pageColors || null;
  8915. this.linkService = linkService;
  8916. this.renderingQueue = renderingQueue;
  8917. this.renderTask = null;
  8918. this.renderingState = _ui_utils.RenderingStates.INITIAL;
  8919. this.resume = null;
  8920. const pageWidth = this.viewport.width,
  8921. pageHeight = this.viewport.height,
  8922. pageRatio = pageWidth / pageHeight;
  8923. this.canvasWidth = THUMBNAIL_WIDTH;
  8924. this.canvasHeight = (this.canvasWidth / pageRatio) | 0;
  8925. this.scale = this.canvasWidth / pageWidth;
  8926. this.l10n = l10n;
  8927. const anchor = document.createElement("a");
  8928. anchor.href = linkService.getAnchorUrl("#page=" + id);
  8929. this._thumbPageTitle.then((msg) => {
  8930. anchor.title = msg;
  8931. });
  8932. anchor.onclick = function () {
  8933. linkService.goToPage(id);
  8934. return false;
  8935. };
  8936. this.anchor = anchor;
  8937. const div = document.createElement("div");
  8938. div.className = "thumbnail";
  8939. div.setAttribute("data-page-number", this.id);
  8940. this.div = div;
  8941. const ring = document.createElement("div");
  8942. ring.className = "thumbnailSelectionRing";
  8943. const borderAdjustment = 2 * THUMBNAIL_CANVAS_BORDER_WIDTH;
  8944. ring.style.width = this.canvasWidth + borderAdjustment + "px";
  8945. ring.style.height = this.canvasHeight + borderAdjustment + "px";
  8946. this.ring = ring;
  8947. div.append(ring);
  8948. anchor.append(div);
  8949. container.append(anchor);
  8950. }
  8951. setPdfPage(pdfPage) {
  8952. this.pdfPage = pdfPage;
  8953. this.pdfPageRotate = pdfPage.rotate;
  8954. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  8955. this.viewport = pdfPage.getViewport({
  8956. scale: 1,
  8957. rotation: totalRotation,
  8958. });
  8959. this.reset();
  8960. }
  8961. reset() {
  8962. this.cancelRendering();
  8963. this.renderingState = _ui_utils.RenderingStates.INITIAL;
  8964. const pageWidth = this.viewport.width,
  8965. pageHeight = this.viewport.height,
  8966. pageRatio = pageWidth / pageHeight;
  8967. this.canvasHeight = (this.canvasWidth / pageRatio) | 0;
  8968. this.scale = this.canvasWidth / pageWidth;
  8969. this.div.removeAttribute("data-loaded");
  8970. const ring = this.ring;
  8971. ring.textContent = "";
  8972. const borderAdjustment = 2 * THUMBNAIL_CANVAS_BORDER_WIDTH;
  8973. ring.style.width = this.canvasWidth + borderAdjustment + "px";
  8974. ring.style.height = this.canvasHeight + borderAdjustment + "px";
  8975. if (this.canvas) {
  8976. this.canvas.width = 0;
  8977. this.canvas.height = 0;
  8978. delete this.canvas;
  8979. }
  8980. if (this.image) {
  8981. this.image.removeAttribute("src");
  8982. delete this.image;
  8983. }
  8984. }
  8985. update({ rotation = null }) {
  8986. if (typeof rotation === "number") {
  8987. this.rotation = rotation;
  8988. }
  8989. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  8990. this.viewport = this.viewport.clone({
  8991. scale: 1,
  8992. rotation: totalRotation,
  8993. });
  8994. this.reset();
  8995. }
  8996. cancelRendering() {
  8997. if (this.renderTask) {
  8998. this.renderTask.cancel();
  8999. this.renderTask = null;
  9000. }
  9001. this.resume = null;
  9002. }
  9003. _getPageDrawContext(upscaleFactor = 1) {
  9004. const canvas = document.createElement("canvas");
  9005. const ctx = canvas.getContext("2d", {
  9006. alpha: false,
  9007. });
  9008. const outputScale = new _ui_utils.OutputScale();
  9009. canvas.width =
  9010. (upscaleFactor * this.canvasWidth * outputScale.sx) | 0;
  9011. canvas.height =
  9012. (upscaleFactor * this.canvasHeight * outputScale.sy) | 0;
  9013. const transform = outputScale.scaled
  9014. ? [outputScale.sx, 0, 0, outputScale.sy, 0, 0]
  9015. : null;
  9016. return {
  9017. ctx,
  9018. canvas,
  9019. transform,
  9020. };
  9021. }
  9022. _convertCanvasToImage(canvas) {
  9023. if (this.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  9024. throw new Error(
  9025. "_convertCanvasToImage: Rendering has not finished."
  9026. );
  9027. }
  9028. const reducedCanvas = this._reduceImage(canvas);
  9029. const image = document.createElement("img");
  9030. image.className = "thumbnailImage";
  9031. this._thumbPageCanvas.then((msg) => {
  9032. image.setAttribute("aria-label", msg);
  9033. });
  9034. image.style.width = this.canvasWidth + "px";
  9035. image.style.height = this.canvasHeight + "px";
  9036. image.src = reducedCanvas.toDataURL();
  9037. this.image = image;
  9038. this.div.setAttribute("data-loaded", true);
  9039. this.ring.append(image);
  9040. reducedCanvas.width = 0;
  9041. reducedCanvas.height = 0;
  9042. }
  9043. draw() {
  9044. if (this.renderingState !== _ui_utils.RenderingStates.INITIAL) {
  9045. console.error("Must be in new state before drawing");
  9046. return Promise.resolve();
  9047. }
  9048. const { pdfPage } = this;
  9049. if (!pdfPage) {
  9050. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  9051. return Promise.reject(new Error("pdfPage is not loaded"));
  9052. }
  9053. this.renderingState = _ui_utils.RenderingStates.RUNNING;
  9054. const finishRenderTask = async (error = null) => {
  9055. if (renderTask === this.renderTask) {
  9056. this.renderTask = null;
  9057. }
  9058. if (error instanceof _pdfjsLib.RenderingCancelledException) {
  9059. return;
  9060. }
  9061. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  9062. this._convertCanvasToImage(canvas);
  9063. if (error) {
  9064. throw error;
  9065. }
  9066. };
  9067. const { ctx, canvas, transform } =
  9068. this._getPageDrawContext(DRAW_UPSCALE_FACTOR);
  9069. const drawViewport = this.viewport.clone({
  9070. scale: DRAW_UPSCALE_FACTOR * this.scale,
  9071. });
  9072. const renderContinueCallback = (cont) => {
  9073. if (!this.renderingQueue.isHighestPriority(this)) {
  9074. this.renderingState = _ui_utils.RenderingStates.PAUSED;
  9075. this.resume = () => {
  9076. this.renderingState = _ui_utils.RenderingStates.RUNNING;
  9077. cont();
  9078. };
  9079. return;
  9080. }
  9081. cont();
  9082. };
  9083. const renderContext = {
  9084. canvasContext: ctx,
  9085. transform,
  9086. viewport: drawViewport,
  9087. optionalContentConfigPromise: this._optionalContentConfigPromise,
  9088. pageColors: this.pageColors,
  9089. };
  9090. const renderTask = (this.renderTask = pdfPage.render(renderContext));
  9091. renderTask.onContinue = renderContinueCallback;
  9092. const resultPromise = renderTask.promise.then(
  9093. function () {
  9094. return finishRenderTask(null);
  9095. },
  9096. function (error) {
  9097. return finishRenderTask(error);
  9098. }
  9099. );
  9100. resultPromise.finally(() => {
  9101. canvas.width = 0;
  9102. canvas.height = 0;
  9103. const pageCached = this.linkService.isPageCached(this.id);
  9104. if (!pageCached) {
  9105. this.pdfPage?.cleanup();
  9106. }
  9107. });
  9108. return resultPromise;
  9109. }
  9110. setImage(pageView) {
  9111. if (this.renderingState !== _ui_utils.RenderingStates.INITIAL) {
  9112. return;
  9113. }
  9114. const { thumbnailCanvas: canvas, pdfPage, scale } = pageView;
  9115. if (!canvas) {
  9116. return;
  9117. }
  9118. if (!this.pdfPage) {
  9119. this.setPdfPage(pdfPage);
  9120. }
  9121. if (scale < this.scale) {
  9122. return;
  9123. }
  9124. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  9125. this._convertCanvasToImage(canvas);
  9126. }
  9127. _reduceImage(img) {
  9128. const { ctx, canvas } = this._getPageDrawContext();
  9129. if (img.width <= 2 * canvas.width) {
  9130. ctx.drawImage(
  9131. img,
  9132. 0,
  9133. 0,
  9134. img.width,
  9135. img.height,
  9136. 0,
  9137. 0,
  9138. canvas.width,
  9139. canvas.height
  9140. );
  9141. return canvas;
  9142. }
  9143. let reducedWidth = canvas.width << MAX_NUM_SCALING_STEPS;
  9144. let reducedHeight = canvas.height << MAX_NUM_SCALING_STEPS;
  9145. const [reducedImage, reducedImageCtx] = TempImageFactory.getCanvas(
  9146. reducedWidth,
  9147. reducedHeight
  9148. );
  9149. while (reducedWidth > img.width || reducedHeight > img.height) {
  9150. reducedWidth >>= 1;
  9151. reducedHeight >>= 1;
  9152. }
  9153. reducedImageCtx.drawImage(
  9154. img,
  9155. 0,
  9156. 0,
  9157. img.width,
  9158. img.height,
  9159. 0,
  9160. 0,
  9161. reducedWidth,
  9162. reducedHeight
  9163. );
  9164. while (reducedWidth > 2 * canvas.width) {
  9165. reducedImageCtx.drawImage(
  9166. reducedImage,
  9167. 0,
  9168. 0,
  9169. reducedWidth,
  9170. reducedHeight,
  9171. 0,
  9172. 0,
  9173. reducedWidth >> 1,
  9174. reducedHeight >> 1
  9175. );
  9176. reducedWidth >>= 1;
  9177. reducedHeight >>= 1;
  9178. }
  9179. ctx.drawImage(
  9180. reducedImage,
  9181. 0,
  9182. 0,
  9183. reducedWidth,
  9184. reducedHeight,
  9185. 0,
  9186. 0,
  9187. canvas.width,
  9188. canvas.height
  9189. );
  9190. return canvas;
  9191. }
  9192. get _thumbPageTitle() {
  9193. return this.l10n.get("thumb_page_title", {
  9194. page: this.pageLabel ?? this.id,
  9195. });
  9196. }
  9197. get _thumbPageCanvas() {
  9198. return this.l10n.get("thumb_page_canvas", {
  9199. page: this.pageLabel ?? this.id,
  9200. });
  9201. }
  9202. setPageLabel(label) {
  9203. this.pageLabel = typeof label === "string" ? label : null;
  9204. this._thumbPageTitle.then((msg) => {
  9205. this.anchor.title = msg;
  9206. });
  9207. if (this.renderingState !== _ui_utils.RenderingStates.FINISHED) {
  9208. return;
  9209. }
  9210. this._thumbPageCanvas.then((msg) => {
  9211. this.image?.setAttribute("aria-label", msg);
  9212. });
  9213. }
  9214. }
  9215. exports.PDFThumbnailView = PDFThumbnailView;
  9216. /***/
  9217. },
  9218. /* 29 */
  9219. /***/ (__unused_webpack_module, exports, __webpack_require__) => {
  9220. Object.defineProperty(exports, "__esModule", {
  9221. value: true,
  9222. });
  9223. exports.PagesCountLimit =
  9224. exports.PDFViewer =
  9225. exports.PDFPageViewBuffer =
  9226. void 0;
  9227. var _pdfjsLib = __webpack_require__(4);
  9228. var _ui_utils = __webpack_require__(3);
  9229. var _l10n_utils = __webpack_require__(30);
  9230. var _pdf_page_view = __webpack_require__(31);
  9231. var _pdf_rendering_queue = __webpack_require__(23);
  9232. var _pdf_link_service = __webpack_require__(7);
  9233. const DEFAULT_CACHE_SIZE = 10;
  9234. const ENABLE_PERMISSIONS_CLASS = "enablePermissions";
  9235. const PagesCountLimit = {
  9236. FORCE_SCROLL_MODE_PAGE: 15000,
  9237. FORCE_LAZY_PAGE_INIT: 7500,
  9238. PAUSE_EAGER_PAGE_INIT: 250,
  9239. };
  9240. exports.PagesCountLimit = PagesCountLimit;
  9241. function isValidAnnotationEditorMode(mode) {
  9242. return (
  9243. Object.values(_pdfjsLib.AnnotationEditorType).includes(mode) &&
  9244. mode !== _pdfjsLib.AnnotationEditorType.DISABLE
  9245. );
  9246. }
  9247. class PDFPageViewBuffer {
  9248. #buf = new Set();
  9249. #size = 0;
  9250. constructor(size) {
  9251. this.#size = size;
  9252. }
  9253. push(view) {
  9254. const buf = this.#buf;
  9255. if (buf.has(view)) {
  9256. buf.delete(view);
  9257. }
  9258. buf.add(view);
  9259. if (buf.size > this.#size) {
  9260. this.#destroyFirstView();
  9261. }
  9262. }
  9263. resize(newSize, idsToKeep = null) {
  9264. this.#size = newSize;
  9265. const buf = this.#buf;
  9266. if (idsToKeep) {
  9267. const ii = buf.size;
  9268. let i = 1;
  9269. for (const view of buf) {
  9270. if (idsToKeep.has(view.id)) {
  9271. buf.delete(view);
  9272. buf.add(view);
  9273. }
  9274. if (++i > ii) {
  9275. break;
  9276. }
  9277. }
  9278. }
  9279. while (buf.size > this.#size) {
  9280. this.#destroyFirstView();
  9281. }
  9282. }
  9283. has(view) {
  9284. return this.#buf.has(view);
  9285. }
  9286. [Symbol.iterator]() {
  9287. return this.#buf.keys();
  9288. }
  9289. #destroyFirstView() {
  9290. const firstView = this.#buf.keys().next().value;
  9291. firstView?.destroy();
  9292. this.#buf.delete(firstView);
  9293. }
  9294. }
  9295. exports.PDFPageViewBuffer = PDFPageViewBuffer;
  9296. class PDFViewer {
  9297. #buffer = null;
  9298. #annotationEditorMode = _pdfjsLib.AnnotationEditorType.NONE;
  9299. #annotationEditorUIManager = null;
  9300. #annotationMode = _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  9301. #containerTopLeft = null;
  9302. #enablePermissions = false;
  9303. #previousContainerHeight = 0;
  9304. #resizeObserver = new ResizeObserver(
  9305. this.#resizeObserverCallback.bind(this)
  9306. );
  9307. #scrollModePageState = null;
  9308. #onVisibilityChange = null;
  9309. #scaleTimeoutId = null;
  9310. constructor(options) {
  9311. const viewerVersion = "3.5.141";
  9312. if (_pdfjsLib.version !== viewerVersion) {
  9313. throw new Error(
  9314. `The API version "${_pdfjsLib.version}" does not match the Viewer version "${viewerVersion}".`
  9315. );
  9316. }
  9317. this.container = options.container;
  9318. this.viewer = options.viewer || options.container.firstElementChild;
  9319. if (
  9320. this.container?.tagName !== "DIV" ||
  9321. this.viewer?.tagName !== "DIV"
  9322. ) {
  9323. throw new Error("Invalid `container` and/or `viewer` option.");
  9324. }
  9325. if (
  9326. this.container.offsetParent &&
  9327. getComputedStyle(this.container).position !== "absolute"
  9328. ) {
  9329. throw new Error("The `container` must be absolutely positioned.");
  9330. }
  9331. this.#resizeObserver.observe(this.container);
  9332. this.eventBus = options.eventBus;
  9333. this.linkService =
  9334. options.linkService || new _pdf_link_service.SimpleLinkService();
  9335. this.downloadManager = options.downloadManager || null;
  9336. this.findController = options.findController || null;
  9337. this._scriptingManager = options.scriptingManager || null;
  9338. this.textLayerMode =
  9339. options.textLayerMode ?? _ui_utils.TextLayerMode.ENABLE;
  9340. this.#annotationMode =
  9341. options.annotationMode ?? _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  9342. this.#annotationEditorMode =
  9343. options.annotationEditorMode ?? _pdfjsLib.AnnotationEditorType.NONE;
  9344. this.imageResourcesPath = options.imageResourcesPath || "";
  9345. this.enablePrintAutoRotate = options.enablePrintAutoRotate || false;
  9346. this.removePageBorders = options.removePageBorders || false;
  9347. this.renderer = options.renderer || _ui_utils.RendererType.CANVAS;
  9348. this.useOnlyCssZoom = options.useOnlyCssZoom || false;
  9349. this.isOffscreenCanvasSupported =
  9350. options.isOffscreenCanvasSupported ?? true;
  9351. this.maxCanvasPixels = options.maxCanvasPixels;
  9352. this.l10n = options.l10n || _l10n_utils.NullL10n;
  9353. this.#enablePermissions = options.enablePermissions || false;
  9354. this.pageColors = options.pageColors || null;
  9355. if (
  9356. this.pageColors &&
  9357. !(
  9358. CSS.supports("color", this.pageColors.background) &&
  9359. CSS.supports("color", this.pageColors.foreground)
  9360. )
  9361. ) {
  9362. if (this.pageColors.background || this.pageColors.foreground) {
  9363. console.warn(
  9364. "PDFViewer: Ignoring `pageColors`-option, since the browser doesn't support the values used."
  9365. );
  9366. }
  9367. this.pageColors = null;
  9368. }
  9369. this.defaultRenderingQueue = !options.renderingQueue;
  9370. if (this.defaultRenderingQueue) {
  9371. this.renderingQueue = new _pdf_rendering_queue.PDFRenderingQueue();
  9372. this.renderingQueue.setViewer(this);
  9373. } else {
  9374. this.renderingQueue = options.renderingQueue;
  9375. }
  9376. this.scroll = (0, _ui_utils.watchScroll)(
  9377. this.container,
  9378. this._scrollUpdate.bind(this)
  9379. );
  9380. this.presentationModeState = _ui_utils.PresentationModeState.UNKNOWN;
  9381. this._onBeforeDraw = this._onAfterDraw = null;
  9382. this._resetView();
  9383. if (this.removePageBorders) {
  9384. this.viewer.classList.add("removePageBorders");
  9385. }
  9386. this.#updateContainerHeightCss();
  9387. }
  9388. get pagesCount() {
  9389. return this._pages.length;
  9390. }
  9391. getPageView(index) {
  9392. return this._pages[index];
  9393. }
  9394. get pageViewsReady() {
  9395. if (!this._pagesCapability.settled) {
  9396. return false;
  9397. }
  9398. return this._pages.every(function (pageView) {
  9399. return pageView?.pdfPage;
  9400. });
  9401. }
  9402. get renderForms() {
  9403. return this.#annotationMode === _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  9404. }
  9405. get enableScripting() {
  9406. return !!this._scriptingManager;
  9407. }
  9408. get currentPageNumber() {
  9409. return this._currentPageNumber;
  9410. }
  9411. set currentPageNumber(val) {
  9412. if (!Number.isInteger(val)) {
  9413. throw new Error("Invalid page number.");
  9414. }
  9415. if (!this.pdfDocument) {
  9416. return;
  9417. }
  9418. if (!this._setCurrentPageNumber(val, true)) {
  9419. console.error(`currentPageNumber: "${val}" is not a valid page.`);
  9420. }
  9421. }
  9422. _setCurrentPageNumber(val, resetCurrentPageView = false) {
  9423. if (this._currentPageNumber === val) {
  9424. if (resetCurrentPageView) {
  9425. this.#resetCurrentPageView();
  9426. }
  9427. return true;
  9428. }
  9429. if (!(0 < val && val <= this.pagesCount)) {
  9430. return false;
  9431. }
  9432. const previous = this._currentPageNumber;
  9433. this._currentPageNumber = val;
  9434. this.eventBus.dispatch("pagechanging", {
  9435. source: this,
  9436. pageNumber: val,
  9437. pageLabel: this._pageLabels?.[val - 1] ?? null,
  9438. previous,
  9439. });
  9440. if (resetCurrentPageView) {
  9441. this.#resetCurrentPageView();
  9442. }
  9443. return true;
  9444. }
  9445. get currentPageLabel() {
  9446. return this._pageLabels?.[this._currentPageNumber - 1] ?? null;
  9447. }
  9448. set currentPageLabel(val) {
  9449. if (!this.pdfDocument) {
  9450. return;
  9451. }
  9452. let page = val | 0;
  9453. if (this._pageLabels) {
  9454. const i = this._pageLabels.indexOf(val);
  9455. if (i >= 0) {
  9456. page = i + 1;
  9457. }
  9458. }
  9459. if (!this._setCurrentPageNumber(page, true)) {
  9460. console.error(`currentPageLabel: "${val}" is not a valid page.`);
  9461. }
  9462. }
  9463. get currentScale() {
  9464. return this._currentScale !== _ui_utils.UNKNOWN_SCALE
  9465. ? this._currentScale
  9466. : _ui_utils.DEFAULT_SCALE;
  9467. }
  9468. set currentScale(val) {
  9469. if (isNaN(val)) {
  9470. throw new Error("Invalid numeric scale.");
  9471. }
  9472. if (!this.pdfDocument) {
  9473. return;
  9474. }
  9475. this.#setScale(val, {
  9476. noScroll: false,
  9477. });
  9478. }
  9479. get currentScaleValue() {
  9480. return this._currentScaleValue;
  9481. }
  9482. set currentScaleValue(val) {
  9483. if (!this.pdfDocument) {
  9484. return;
  9485. }
  9486. this.#setScale(val, {
  9487. noScroll: false,
  9488. });
  9489. }
  9490. get pagesRotation() {
  9491. return this._pagesRotation;
  9492. }
  9493. set pagesRotation(rotation) {
  9494. if (!(0, _ui_utils.isValidRotation)(rotation)) {
  9495. throw new Error("Invalid pages rotation angle.");
  9496. }
  9497. if (!this.pdfDocument) {
  9498. return;
  9499. }
  9500. rotation %= 360;
  9501. if (rotation < 0) {
  9502. rotation += 360;
  9503. }
  9504. if (this._pagesRotation === rotation) {
  9505. return;
  9506. }
  9507. this._pagesRotation = rotation;
  9508. const pageNumber = this._currentPageNumber;
  9509. this.refresh(true, {
  9510. rotation,
  9511. });
  9512. if (this._currentScaleValue) {
  9513. this.#setScale(this._currentScaleValue, {
  9514. noScroll: true,
  9515. });
  9516. }
  9517. this.eventBus.dispatch("rotationchanging", {
  9518. source: this,
  9519. pagesRotation: rotation,
  9520. pageNumber,
  9521. });
  9522. if (this.defaultRenderingQueue) {
  9523. this.update();
  9524. }
  9525. }
  9526. get firstPagePromise() {
  9527. return this.pdfDocument ? this._firstPageCapability.promise : null;
  9528. }
  9529. get onePageRendered() {
  9530. return this.pdfDocument
  9531. ? this._onePageRenderedCapability.promise
  9532. : null;
  9533. }
  9534. get pagesPromise() {
  9535. return this.pdfDocument ? this._pagesCapability.promise : null;
  9536. }
  9537. #layerProperties() {
  9538. const self = this;
  9539. return {
  9540. get annotationEditorUIManager() {
  9541. return self.#annotationEditorUIManager;
  9542. },
  9543. get annotationStorage() {
  9544. return self.pdfDocument?.annotationStorage;
  9545. },
  9546. get downloadManager() {
  9547. return self.downloadManager;
  9548. },
  9549. get enableScripting() {
  9550. return !!self._scriptingManager;
  9551. },
  9552. get fieldObjectsPromise() {
  9553. return self.pdfDocument?.getFieldObjects();
  9554. },
  9555. get findController() {
  9556. return self.findController;
  9557. },
  9558. get hasJSActionsPromise() {
  9559. return self.pdfDocument?.hasJSActions();
  9560. },
  9561. get linkService() {
  9562. return self.linkService;
  9563. },
  9564. };
  9565. }
  9566. #initializePermissions(permissions) {
  9567. const params = {
  9568. annotationEditorMode: this.#annotationEditorMode,
  9569. annotationMode: this.#annotationMode,
  9570. textLayerMode: this.textLayerMode,
  9571. };
  9572. if (!permissions) {
  9573. return params;
  9574. }
  9575. if (!permissions.includes(_pdfjsLib.PermissionFlag.COPY)) {
  9576. this.viewer.classList.add(ENABLE_PERMISSIONS_CLASS);
  9577. }
  9578. if (!permissions.includes(_pdfjsLib.PermissionFlag.MODIFY_CONTENTS)) {
  9579. params.annotationEditorMode =
  9580. _pdfjsLib.AnnotationEditorType.DISABLE;
  9581. }
  9582. if (
  9583. !permissions.includes(
  9584. _pdfjsLib.PermissionFlag.MODIFY_ANNOTATIONS
  9585. ) &&
  9586. !permissions.includes(
  9587. _pdfjsLib.PermissionFlag.FILL_INTERACTIVE_FORMS
  9588. ) &&
  9589. this.#annotationMode === _pdfjsLib.AnnotationMode.ENABLE_FORMS
  9590. ) {
  9591. params.annotationMode = _pdfjsLib.AnnotationMode.ENABLE;
  9592. }
  9593. return params;
  9594. }
  9595. #onePageRenderedOrForceFetch() {
  9596. if (
  9597. document.visibilityState === "hidden" ||
  9598. !this.container.offsetParent ||
  9599. this._getVisiblePages().views.length === 0
  9600. ) {
  9601. return Promise.resolve();
  9602. }
  9603. const visibilityChangePromise = new Promise((resolve) => {
  9604. this.#onVisibilityChange = () => {
  9605. if (document.visibilityState !== "hidden") {
  9606. return;
  9607. }
  9608. resolve();
  9609. document.removeEventListener(
  9610. "visibilitychange",
  9611. this.#onVisibilityChange
  9612. );
  9613. this.#onVisibilityChange = null;
  9614. };
  9615. document.addEventListener(
  9616. "visibilitychange",
  9617. this.#onVisibilityChange
  9618. );
  9619. });
  9620. return Promise.race([
  9621. this._onePageRenderedCapability.promise,
  9622. visibilityChangePromise,
  9623. ]);
  9624. }
  9625. setDocument(pdfDocument) {
  9626. if (this.pdfDocument) {
  9627. this.eventBus.dispatch("pagesdestroy", {
  9628. source: this,
  9629. });
  9630. this._cancelRendering();
  9631. this._resetView();
  9632. this.findController?.setDocument(null);
  9633. this._scriptingManager?.setDocument(null);
  9634. if (this.#annotationEditorUIManager) {
  9635. this.#annotationEditorUIManager.destroy();
  9636. this.#annotationEditorUIManager = null;
  9637. }
  9638. }
  9639. this.pdfDocument = pdfDocument;
  9640. if (!pdfDocument) {
  9641. return;
  9642. }
  9643. const pagesCount = pdfDocument.numPages;
  9644. const firstPagePromise = pdfDocument.getPage(1);
  9645. const optionalContentConfigPromise =
  9646. pdfDocument.getOptionalContentConfig();
  9647. const permissionsPromise = this.#enablePermissions
  9648. ? pdfDocument.getPermissions()
  9649. : Promise.resolve();
  9650. if (pagesCount > PagesCountLimit.FORCE_SCROLL_MODE_PAGE) {
  9651. console.warn(
  9652. "Forcing PAGE-scrolling for performance reasons, given the length of the document."
  9653. );
  9654. const mode = (this._scrollMode = _ui_utils.ScrollMode.PAGE);
  9655. this.eventBus.dispatch("scrollmodechanged", {
  9656. source: this,
  9657. mode,
  9658. });
  9659. }
  9660. this._pagesCapability.promise.then(
  9661. () => {
  9662. this.eventBus.dispatch("pagesloaded", {
  9663. source: this,
  9664. pagesCount,
  9665. });
  9666. },
  9667. () => {}
  9668. );
  9669. this._onBeforeDraw = (evt) => {
  9670. const pageView = this._pages[evt.pageNumber - 1];
  9671. if (!pageView) {
  9672. return;
  9673. }
  9674. this.#buffer.push(pageView);
  9675. };
  9676. this.eventBus._on("pagerender", this._onBeforeDraw);
  9677. this._onAfterDraw = (evt) => {
  9678. if (evt.cssTransform || this._onePageRenderedCapability.settled) {
  9679. return;
  9680. }
  9681. this._onePageRenderedCapability.resolve({
  9682. timestamp: evt.timestamp,
  9683. });
  9684. this.eventBus._off("pagerendered", this._onAfterDraw);
  9685. this._onAfterDraw = null;
  9686. if (this.#onVisibilityChange) {
  9687. document.removeEventListener(
  9688. "visibilitychange",
  9689. this.#onVisibilityChange
  9690. );
  9691. this.#onVisibilityChange = null;
  9692. }
  9693. };
  9694. this.eventBus._on("pagerendered", this._onAfterDraw);
  9695. Promise.all([firstPagePromise, permissionsPromise])
  9696. .then(([firstPdfPage, permissions]) => {
  9697. if (pdfDocument !== this.pdfDocument) {
  9698. return;
  9699. }
  9700. this._firstPageCapability.resolve(firstPdfPage);
  9701. this._optionalContentConfigPromise = optionalContentConfigPromise;
  9702. const { annotationEditorMode, annotationMode, textLayerMode } =
  9703. this.#initializePermissions(permissions);
  9704. if (
  9705. annotationEditorMode !== _pdfjsLib.AnnotationEditorType.DISABLE
  9706. ) {
  9707. const mode = annotationEditorMode;
  9708. if (pdfDocument.isPureXfa) {
  9709. console.warn("Warning: XFA-editing is not implemented.");
  9710. } else if (isValidAnnotationEditorMode(mode)) {
  9711. this.#annotationEditorUIManager =
  9712. new _pdfjsLib.AnnotationEditorUIManager(
  9713. this.container,
  9714. this.eventBus,
  9715. pdfDocument?.annotationStorage
  9716. );
  9717. if (mode !== _pdfjsLib.AnnotationEditorType.NONE) {
  9718. this.#annotationEditorUIManager.updateMode(mode);
  9719. }
  9720. } else {
  9721. console.error(`Invalid AnnotationEditor mode: ${mode}`);
  9722. }
  9723. }
  9724. const layerProperties = this.#layerProperties.bind(this);
  9725. const viewerElement =
  9726. this._scrollMode === _ui_utils.ScrollMode.PAGE
  9727. ? null
  9728. : this.viewer;
  9729. const scale = this.currentScale;
  9730. const viewport = firstPdfPage.getViewport({
  9731. scale: scale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS,
  9732. });
  9733. this.viewer.style.setProperty("--scale-factor", viewport.scale);
  9734. for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) {
  9735. const pageView = new _pdf_page_view.PDFPageView({
  9736. container: viewerElement,
  9737. eventBus: this.eventBus,
  9738. id: pageNum,
  9739. scale,
  9740. defaultViewport: viewport.clone(),
  9741. optionalContentConfigPromise,
  9742. renderingQueue: this.renderingQueue,
  9743. textLayerMode,
  9744. annotationMode,
  9745. imageResourcesPath: this.imageResourcesPath,
  9746. renderer: this.renderer,
  9747. useOnlyCssZoom: this.useOnlyCssZoom,
  9748. isOffscreenCanvasSupported: this.isOffscreenCanvasSupported,
  9749. maxCanvasPixels: this.maxCanvasPixels,
  9750. pageColors: this.pageColors,
  9751. l10n: this.l10n,
  9752. layerProperties,
  9753. });
  9754. this._pages.push(pageView);
  9755. }
  9756. const firstPageView = this._pages[0];
  9757. if (firstPageView) {
  9758. firstPageView.setPdfPage(firstPdfPage);
  9759. this.linkService.cachePageRef(1, firstPdfPage.ref);
  9760. }
  9761. if (this._scrollMode === _ui_utils.ScrollMode.PAGE) {
  9762. this.#ensurePageViewVisible();
  9763. } else if (this._spreadMode !== _ui_utils.SpreadMode.NONE) {
  9764. this._updateSpreadMode();
  9765. }
  9766. this.#onePageRenderedOrForceFetch().then(async () => {
  9767. this.findController?.setDocument(pdfDocument);
  9768. this._scriptingManager?.setDocument(pdfDocument);
  9769. if (this.#annotationEditorUIManager) {
  9770. this.eventBus.dispatch("annotationeditormodechanged", {
  9771. source: this,
  9772. mode: this.#annotationEditorMode,
  9773. });
  9774. }
  9775. if (
  9776. pdfDocument.loadingParams.disableAutoFetch ||
  9777. pagesCount > PagesCountLimit.FORCE_LAZY_PAGE_INIT
  9778. ) {
  9779. this._pagesCapability.resolve();
  9780. return;
  9781. }
  9782. let getPagesLeft = pagesCount - 1;
  9783. if (getPagesLeft <= 0) {
  9784. this._pagesCapability.resolve();
  9785. return;
  9786. }
  9787. for (let pageNum = 2; pageNum <= pagesCount; ++pageNum) {
  9788. const promise = pdfDocument.getPage(pageNum).then(
  9789. (pdfPage) => {
  9790. const pageView = this._pages[pageNum - 1];
  9791. if (!pageView.pdfPage) {
  9792. pageView.setPdfPage(pdfPage);
  9793. }
  9794. this.linkService.cachePageRef(pageNum, pdfPage.ref);
  9795. if (--getPagesLeft === 0) {
  9796. this._pagesCapability.resolve();
  9797. }
  9798. },
  9799. (reason) => {
  9800. console.error(
  9801. `Unable to get page ${pageNum} to initialize viewer`,
  9802. reason
  9803. );
  9804. if (--getPagesLeft === 0) {
  9805. this._pagesCapability.resolve();
  9806. }
  9807. }
  9808. );
  9809. if (pageNum % PagesCountLimit.PAUSE_EAGER_PAGE_INIT === 0) {
  9810. await promise;
  9811. }
  9812. }
  9813. });
  9814. this.eventBus.dispatch("pagesinit", {
  9815. source: this,
  9816. });
  9817. pdfDocument.getMetadata().then(({ info }) => {
  9818. if (pdfDocument !== this.pdfDocument) {
  9819. return;
  9820. }
  9821. if (info.Language) {
  9822. this.viewer.lang = info.Language;
  9823. }
  9824. });
  9825. if (this.defaultRenderingQueue) {
  9826. this.update();
  9827. }
  9828. })
  9829. .catch((reason) => {
  9830. console.error("Unable to initialize viewer", reason);
  9831. this._pagesCapability.reject(reason);
  9832. });
  9833. }
  9834. setPageLabels(labels) {
  9835. if (!this.pdfDocument) {
  9836. return;
  9837. }
  9838. if (!labels) {
  9839. this._pageLabels = null;
  9840. } else if (
  9841. !(
  9842. Array.isArray(labels) &&
  9843. this.pdfDocument.numPages === labels.length
  9844. )
  9845. ) {
  9846. this._pageLabels = null;
  9847. console.error(`setPageLabels: Invalid page labels.`);
  9848. } else {
  9849. this._pageLabels = labels;
  9850. }
  9851. for (let i = 0, ii = this._pages.length; i < ii; i++) {
  9852. this._pages[i].setPageLabel(this._pageLabels?.[i] ?? null);
  9853. }
  9854. }
  9855. _resetView() {
  9856. this._pages = [];
  9857. this._currentPageNumber = 1;
  9858. this._currentScale = _ui_utils.UNKNOWN_SCALE;
  9859. this._currentScaleValue = null;
  9860. this._pageLabels = null;
  9861. this.#buffer = new PDFPageViewBuffer(DEFAULT_CACHE_SIZE);
  9862. this._location = null;
  9863. this._pagesRotation = 0;
  9864. this._optionalContentConfigPromise = null;
  9865. this._firstPageCapability = (0, _pdfjsLib.createPromiseCapability)();
  9866. this._onePageRenderedCapability = (0,
  9867. _pdfjsLib.createPromiseCapability)();
  9868. this._pagesCapability = (0, _pdfjsLib.createPromiseCapability)();
  9869. this._scrollMode = _ui_utils.ScrollMode.VERTICAL;
  9870. this._previousScrollMode = _ui_utils.ScrollMode.UNKNOWN;
  9871. this._spreadMode = _ui_utils.SpreadMode.NONE;
  9872. this.#scrollModePageState = {
  9873. previousPageNumber: 1,
  9874. scrollDown: true,
  9875. pages: [],
  9876. };
  9877. if (this._onBeforeDraw) {
  9878. this.eventBus._off("pagerender", this._onBeforeDraw);
  9879. this._onBeforeDraw = null;
  9880. }
  9881. if (this._onAfterDraw) {
  9882. this.eventBus._off("pagerendered", this._onAfterDraw);
  9883. this._onAfterDraw = null;
  9884. }
  9885. if (this.#onVisibilityChange) {
  9886. document.removeEventListener(
  9887. "visibilitychange",
  9888. this.#onVisibilityChange
  9889. );
  9890. this.#onVisibilityChange = null;
  9891. }
  9892. this.viewer.textContent = "";
  9893. this._updateScrollMode();
  9894. this.viewer.removeAttribute("lang");
  9895. this.viewer.classList.remove(ENABLE_PERMISSIONS_CLASS);
  9896. }
  9897. #ensurePageViewVisible() {
  9898. if (this._scrollMode !== _ui_utils.ScrollMode.PAGE) {
  9899. throw new Error(
  9900. "#ensurePageViewVisible: Invalid scrollMode value."
  9901. );
  9902. }
  9903. const pageNumber = this._currentPageNumber,
  9904. state = this.#scrollModePageState,
  9905. viewer = this.viewer;
  9906. viewer.textContent = "";
  9907. state.pages.length = 0;
  9908. if (
  9909. this._spreadMode === _ui_utils.SpreadMode.NONE &&
  9910. !this.isInPresentationMode
  9911. ) {
  9912. const pageView = this._pages[pageNumber - 1];
  9913. viewer.append(pageView.div);
  9914. state.pages.push(pageView);
  9915. } else {
  9916. const pageIndexSet = new Set(),
  9917. parity = this._spreadMode - 1;
  9918. if (parity === -1) {
  9919. pageIndexSet.add(pageNumber - 1);
  9920. } else if (pageNumber % 2 !== parity) {
  9921. pageIndexSet.add(pageNumber - 1);
  9922. pageIndexSet.add(pageNumber);
  9923. } else {
  9924. pageIndexSet.add(pageNumber - 2);
  9925. pageIndexSet.add(pageNumber - 1);
  9926. }
  9927. const spread = document.createElement("div");
  9928. spread.className = "spread";
  9929. if (this.isInPresentationMode) {
  9930. const dummyPage = document.createElement("div");
  9931. dummyPage.className = "dummyPage";
  9932. spread.append(dummyPage);
  9933. }
  9934. for (const i of pageIndexSet) {
  9935. const pageView = this._pages[i];
  9936. if (!pageView) {
  9937. continue;
  9938. }
  9939. spread.append(pageView.div);
  9940. state.pages.push(pageView);
  9941. }
  9942. viewer.append(spread);
  9943. }
  9944. state.scrollDown = pageNumber >= state.previousPageNumber;
  9945. state.previousPageNumber = pageNumber;
  9946. }
  9947. _scrollUpdate() {
  9948. if (this.pagesCount === 0) {
  9949. return;
  9950. }
  9951. this.update();
  9952. }
  9953. #scrollIntoView(pageView, pageSpot = null) {
  9954. const { div, id } = pageView;
  9955. if (this._currentPageNumber !== id) {
  9956. this._setCurrentPageNumber(id);
  9957. }
  9958. if (this._scrollMode === _ui_utils.ScrollMode.PAGE) {
  9959. this.#ensurePageViewVisible();
  9960. this.update();
  9961. }
  9962. if (!pageSpot && !this.isInPresentationMode) {
  9963. const left = div.offsetLeft + div.clientLeft,
  9964. right = left + div.clientWidth;
  9965. const { scrollLeft, clientWidth } = this.container;
  9966. if (
  9967. this._scrollMode === _ui_utils.ScrollMode.HORIZONTAL ||
  9968. left < scrollLeft ||
  9969. right > scrollLeft + clientWidth
  9970. ) {
  9971. pageSpot = {
  9972. left: 0,
  9973. top: 0,
  9974. };
  9975. }
  9976. }
  9977. (0, _ui_utils.scrollIntoView)(div, pageSpot);
  9978. if (!this._currentScaleValue && this._location) {
  9979. this._location = null;
  9980. }
  9981. }
  9982. #isSameScale(newScale) {
  9983. return (
  9984. newScale === this._currentScale ||
  9985. Math.abs(newScale - this._currentScale) < 1e-15
  9986. );
  9987. }
  9988. #setScaleUpdatePages(
  9989. newScale,
  9990. newValue,
  9991. { noScroll = false, preset = false, drawingDelay = -1 }
  9992. ) {
  9993. this._currentScaleValue = newValue.toString();
  9994. if (this.#isSameScale(newScale)) {
  9995. if (preset) {
  9996. this.eventBus.dispatch("scalechanging", {
  9997. source: this,
  9998. scale: newScale,
  9999. presetValue: newValue,
  10000. });
  10001. }
  10002. return;
  10003. }
  10004. this.viewer.style.setProperty(
  10005. "--scale-factor",
  10006. newScale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS
  10007. );
  10008. const postponeDrawing = drawingDelay >= 0 && drawingDelay < 1000;
  10009. this.refresh(true, {
  10010. scale: newScale,
  10011. drawingDelay: postponeDrawing ? drawingDelay : -1,
  10012. });
  10013. if (postponeDrawing) {
  10014. this.#scaleTimeoutId = setTimeout(() => {
  10015. this.#scaleTimeoutId = null;
  10016. this.refresh();
  10017. }, drawingDelay);
  10018. }
  10019. this._currentScale = newScale;
  10020. if (!noScroll) {
  10021. let page = this._currentPageNumber,
  10022. dest;
  10023. if (
  10024. this._location &&
  10025. !(this.isInPresentationMode || this.isChangingPresentationMode)
  10026. ) {
  10027. page = this._location.pageNumber;
  10028. dest = [
  10029. null,
  10030. {
  10031. name: "XYZ",
  10032. },
  10033. this._location.left,
  10034. this._location.top,
  10035. null,
  10036. ];
  10037. }
  10038. this.scrollPageIntoView({
  10039. pageNumber: page,
  10040. destArray: dest,
  10041. allowNegativeOffset: true,
  10042. });
  10043. }
  10044. this.eventBus.dispatch("scalechanging", {
  10045. source: this,
  10046. scale: newScale,
  10047. presetValue: preset ? newValue : undefined,
  10048. });
  10049. if (this.defaultRenderingQueue) {
  10050. this.update();
  10051. }
  10052. }
  10053. get #pageWidthScaleFactor() {
  10054. if (
  10055. this._spreadMode !== _ui_utils.SpreadMode.NONE &&
  10056. this._scrollMode !== _ui_utils.ScrollMode.HORIZONTAL
  10057. ) {
  10058. return 2;
  10059. }
  10060. return 1;
  10061. }
  10062. #setScale(value, options) {
  10063. let scale = parseFloat(value);
  10064. if (scale > 0) {
  10065. options.preset = false;
  10066. this.#setScaleUpdatePages(scale, value, options);
  10067. } else {
  10068. const currentPage = this._pages[this._currentPageNumber - 1];
  10069. if (!currentPage) {
  10070. return;
  10071. }
  10072. let hPadding = _ui_utils.SCROLLBAR_PADDING,
  10073. vPadding = _ui_utils.VERTICAL_PADDING;
  10074. if (this.isInPresentationMode) {
  10075. hPadding = vPadding = 4;
  10076. if (this._spreadMode !== _ui_utils.SpreadMode.NONE) {
  10077. hPadding *= 2;
  10078. }
  10079. } else if (this.removePageBorders) {
  10080. hPadding = vPadding = 0;
  10081. } else if (this._scrollMode === _ui_utils.ScrollMode.HORIZONTAL) {
  10082. [hPadding, vPadding] = [vPadding, hPadding];
  10083. }
  10084. const pageWidthScale =
  10085. (((this.container.clientWidth - hPadding) / currentPage.width) *
  10086. currentPage.scale) /
  10087. this.#pageWidthScaleFactor;
  10088. const pageHeightScale =
  10089. ((this.container.clientHeight - vPadding) / currentPage.height) *
  10090. currentPage.scale;
  10091. switch (value) {
  10092. case "page-actual":
  10093. scale = 1;
  10094. break;
  10095. case "page-width":
  10096. scale = pageWidthScale;
  10097. break;
  10098. case "page-height":
  10099. scale = pageHeightScale;
  10100. break;
  10101. case "page-fit":
  10102. scale = Math.min(pageWidthScale, pageHeightScale);
  10103. break;
  10104. case "auto":
  10105. const horizontalScale = (0, _ui_utils.isPortraitOrientation)(
  10106. currentPage
  10107. )
  10108. ? pageWidthScale
  10109. : Math.min(pageHeightScale, pageWidthScale);
  10110. scale = Math.min(_ui_utils.MAX_AUTO_SCALE, horizontalScale);
  10111. break;
  10112. default:
  10113. console.error(
  10114. `#setScale: "${value}" is an unknown zoom value.`
  10115. );
  10116. return;
  10117. }
  10118. options.preset = true;
  10119. this.#setScaleUpdatePages(scale, value, options);
  10120. }
  10121. }
  10122. #resetCurrentPageView() {
  10123. const pageView = this._pages[this._currentPageNumber - 1];
  10124. if (this.isInPresentationMode) {
  10125. this.#setScale(this._currentScaleValue, {
  10126. noScroll: true,
  10127. });
  10128. }
  10129. this.#scrollIntoView(pageView);
  10130. }
  10131. pageLabelToPageNumber(label) {
  10132. if (!this._pageLabels) {
  10133. return null;
  10134. }
  10135. const i = this._pageLabels.indexOf(label);
  10136. if (i < 0) {
  10137. return null;
  10138. }
  10139. return i + 1;
  10140. }
  10141. scrollPageIntoView({
  10142. pageNumber,
  10143. destArray = null,
  10144. allowNegativeOffset = false,
  10145. ignoreDestinationZoom = false,
  10146. }) {
  10147. if (!this.pdfDocument) {
  10148. return;
  10149. }
  10150. const pageView =
  10151. Number.isInteger(pageNumber) && this._pages[pageNumber - 1];
  10152. if (!pageView) {
  10153. console.error(
  10154. `scrollPageIntoView: "${pageNumber}" is not a valid pageNumber parameter.`
  10155. );
  10156. return;
  10157. }
  10158. if (this.isInPresentationMode || !destArray) {
  10159. this._setCurrentPageNumber(pageNumber, true);
  10160. return;
  10161. }
  10162. let x = 0,
  10163. y = 0;
  10164. let width = 0,
  10165. height = 0,
  10166. widthScale,
  10167. heightScale;
  10168. const changeOrientation = pageView.rotation % 180 !== 0;
  10169. const pageWidth =
  10170. (changeOrientation ? pageView.height : pageView.width) /
  10171. pageView.scale /
  10172. _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
  10173. const pageHeight =
  10174. (changeOrientation ? pageView.width : pageView.height) /
  10175. pageView.scale /
  10176. _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
  10177. let scale = 0;
  10178. switch (destArray[1].name) {
  10179. case "XYZ":
  10180. x = destArray[2];
  10181. y = destArray[3];
  10182. scale = destArray[4];
  10183. x = x !== null ? x : 0;
  10184. y = y !== null ? y : pageHeight;
  10185. break;
  10186. case "Fit":
  10187. case "FitB":
  10188. scale = "page-fit";
  10189. break;
  10190. case "FitH":
  10191. case "FitBH":
  10192. y = destArray[2];
  10193. scale = "page-width";
  10194. if (y === null && this._location) {
  10195. x = this._location.left;
  10196. y = this._location.top;
  10197. } else if (typeof y !== "number" || y < 0) {
  10198. y = pageHeight;
  10199. }
  10200. break;
  10201. case "FitV":
  10202. case "FitBV":
  10203. x = destArray[2];
  10204. width = pageWidth;
  10205. height = pageHeight;
  10206. scale = "page-height";
  10207. break;
  10208. case "FitR":
  10209. x = destArray[2];
  10210. y = destArray[3];
  10211. width = destArray[4] - x;
  10212. height = destArray[5] - y;
  10213. let hPadding = _ui_utils.SCROLLBAR_PADDING,
  10214. vPadding = _ui_utils.VERTICAL_PADDING;
  10215. if (this.removePageBorders) {
  10216. hPadding = vPadding = 0;
  10217. }
  10218. widthScale =
  10219. (this.container.clientWidth - hPadding) /
  10220. width /
  10221. _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
  10222. heightScale =
  10223. (this.container.clientHeight - vPadding) /
  10224. height /
  10225. _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS;
  10226. scale = Math.min(Math.abs(widthScale), Math.abs(heightScale));
  10227. break;
  10228. default:
  10229. console.error(
  10230. `scrollPageIntoView: "${destArray[1].name}" is not a valid destination type.`
  10231. );
  10232. return;
  10233. }
  10234. if (!ignoreDestinationZoom) {
  10235. if (scale && scale !== this._currentScale) {
  10236. this.currentScaleValue = scale;
  10237. } else if (this._currentScale === _ui_utils.UNKNOWN_SCALE) {
  10238. this.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  10239. }
  10240. }
  10241. if (scale === "page-fit" && !destArray[4]) {
  10242. this.#scrollIntoView(pageView);
  10243. return;
  10244. }
  10245. const boundingRect = [
  10246. pageView.viewport.convertToViewportPoint(x, y),
  10247. pageView.viewport.convertToViewportPoint(x + width, y + height),
  10248. ];
  10249. let left = Math.min(boundingRect[0][0], boundingRect[1][0]);
  10250. let top = Math.min(boundingRect[0][1], boundingRect[1][1]);
  10251. if (!allowNegativeOffset) {
  10252. left = Math.max(left, 0);
  10253. top = Math.max(top, 0);
  10254. }
  10255. this.#scrollIntoView(pageView, {
  10256. left,
  10257. top,
  10258. });
  10259. }
  10260. _updateLocation(firstPage) {
  10261. const currentScale = this._currentScale;
  10262. const currentScaleValue = this._currentScaleValue;
  10263. const normalizedScaleValue =
  10264. parseFloat(currentScaleValue) === currentScale
  10265. ? Math.round(currentScale * 10000) / 100
  10266. : currentScaleValue;
  10267. const pageNumber = firstPage.id;
  10268. const currentPageView = this._pages[pageNumber - 1];
  10269. const container = this.container;
  10270. const topLeft = currentPageView.getPagePoint(
  10271. container.scrollLeft - firstPage.x,
  10272. container.scrollTop - firstPage.y
  10273. );
  10274. const intLeft = Math.round(topLeft[0]);
  10275. const intTop = Math.round(topLeft[1]);
  10276. let pdfOpenParams = `#page=${pageNumber}`;
  10277. if (!this.isInPresentationMode) {
  10278. pdfOpenParams += `&zoom=${normalizedScaleValue},${intLeft},${intTop}`;
  10279. }
  10280. this._location = {
  10281. pageNumber,
  10282. scale: normalizedScaleValue,
  10283. top: intTop,
  10284. left: intLeft,
  10285. rotation: this._pagesRotation,
  10286. pdfOpenParams,
  10287. };
  10288. }
  10289. update() {
  10290. const visible = this._getVisiblePages();
  10291. const visiblePages = visible.views,
  10292. numVisiblePages = visiblePages.length;
  10293. if (numVisiblePages === 0) {
  10294. return;
  10295. }
  10296. const newCacheSize = Math.max(
  10297. DEFAULT_CACHE_SIZE,
  10298. 2 * numVisiblePages + 1
  10299. );
  10300. this.#buffer.resize(newCacheSize, visible.ids);
  10301. this.renderingQueue.renderHighestPriority(visible);
  10302. const isSimpleLayout =
  10303. this._spreadMode === _ui_utils.SpreadMode.NONE &&
  10304. (this._scrollMode === _ui_utils.ScrollMode.PAGE ||
  10305. this._scrollMode === _ui_utils.ScrollMode.VERTICAL);
  10306. const currentId = this._currentPageNumber;
  10307. let stillFullyVisible = false;
  10308. for (const page of visiblePages) {
  10309. if (page.percent < 100) {
  10310. break;
  10311. }
  10312. if (page.id === currentId && isSimpleLayout) {
  10313. stillFullyVisible = true;
  10314. break;
  10315. }
  10316. }
  10317. this._setCurrentPageNumber(
  10318. stillFullyVisible ? currentId : visiblePages[0].id
  10319. );
  10320. this._updateLocation(visible.first);
  10321. this.eventBus.dispatch("updateviewarea", {
  10322. source: this,
  10323. location: this._location,
  10324. });
  10325. }
  10326. containsElement(element) {
  10327. return this.container.contains(element);
  10328. }
  10329. focus() {
  10330. this.container.focus();
  10331. }
  10332. get _isContainerRtl() {
  10333. return getComputedStyle(this.container).direction === "rtl";
  10334. }
  10335. get isInPresentationMode() {
  10336. return (
  10337. this.presentationModeState ===
  10338. _ui_utils.PresentationModeState.FULLSCREEN
  10339. );
  10340. }
  10341. get isChangingPresentationMode() {
  10342. return (
  10343. this.presentationModeState ===
  10344. _ui_utils.PresentationModeState.CHANGING
  10345. );
  10346. }
  10347. get isHorizontalScrollbarEnabled() {
  10348. return this.isInPresentationMode
  10349. ? false
  10350. : this.container.scrollWidth > this.container.clientWidth;
  10351. }
  10352. get isVerticalScrollbarEnabled() {
  10353. return this.isInPresentationMode
  10354. ? false
  10355. : this.container.scrollHeight > this.container.clientHeight;
  10356. }
  10357. _getVisiblePages() {
  10358. const views =
  10359. this._scrollMode === _ui_utils.ScrollMode.PAGE
  10360. ? this.#scrollModePageState.pages
  10361. : this._pages,
  10362. horizontal = this._scrollMode === _ui_utils.ScrollMode.HORIZONTAL,
  10363. rtl = horizontal && this._isContainerRtl;
  10364. return (0, _ui_utils.getVisibleElements)({
  10365. scrollEl: this.container,
  10366. views,
  10367. sortByVisibility: true,
  10368. horizontal,
  10369. rtl,
  10370. });
  10371. }
  10372. isPageVisible(pageNumber) {
  10373. if (!this.pdfDocument) {
  10374. return false;
  10375. }
  10376. if (
  10377. !(
  10378. Number.isInteger(pageNumber) &&
  10379. pageNumber > 0 &&
  10380. pageNumber <= this.pagesCount
  10381. )
  10382. ) {
  10383. console.error(
  10384. `isPageVisible: "${pageNumber}" is not a valid page.`
  10385. );
  10386. return false;
  10387. }
  10388. return this._getVisiblePages().ids.has(pageNumber);
  10389. }
  10390. isPageCached(pageNumber) {
  10391. if (!this.pdfDocument) {
  10392. return false;
  10393. }
  10394. if (
  10395. !(
  10396. Number.isInteger(pageNumber) &&
  10397. pageNumber > 0 &&
  10398. pageNumber <= this.pagesCount
  10399. )
  10400. ) {
  10401. console.error(`isPageCached: "${pageNumber}" is not a valid page.`);
  10402. return false;
  10403. }
  10404. const pageView = this._pages[pageNumber - 1];
  10405. return this.#buffer.has(pageView);
  10406. }
  10407. cleanup() {
  10408. for (const pageView of this._pages) {
  10409. if (
  10410. pageView.renderingState !== _ui_utils.RenderingStates.FINISHED
  10411. ) {
  10412. pageView.reset();
  10413. }
  10414. }
  10415. }
  10416. _cancelRendering() {
  10417. for (const pageView of this._pages) {
  10418. pageView.cancelRendering();
  10419. }
  10420. }
  10421. async #ensurePdfPageLoaded(pageView) {
  10422. if (pageView.pdfPage) {
  10423. return pageView.pdfPage;
  10424. }
  10425. try {
  10426. const pdfPage = await this.pdfDocument.getPage(pageView.id);
  10427. if (!pageView.pdfPage) {
  10428. pageView.setPdfPage(pdfPage);
  10429. }
  10430. if (!this.linkService._cachedPageNumber?.(pdfPage.ref)) {
  10431. this.linkService.cachePageRef(pageView.id, pdfPage.ref);
  10432. }
  10433. return pdfPage;
  10434. } catch (reason) {
  10435. console.error("Unable to get page for page view", reason);
  10436. return null;
  10437. }
  10438. }
  10439. #getScrollAhead(visible) {
  10440. if (visible.first?.id === 1) {
  10441. return true;
  10442. } else if (visible.last?.id === this.pagesCount) {
  10443. return false;
  10444. }
  10445. switch (this._scrollMode) {
  10446. case _ui_utils.ScrollMode.PAGE:
  10447. return this.#scrollModePageState.scrollDown;
  10448. case _ui_utils.ScrollMode.HORIZONTAL:
  10449. return this.scroll.right;
  10450. }
  10451. return this.scroll.down;
  10452. }
  10453. forceRendering(currentlyVisiblePages) {
  10454. const visiblePages = currentlyVisiblePages || this._getVisiblePages();
  10455. const scrollAhead = this.#getScrollAhead(visiblePages);
  10456. const preRenderExtra =
  10457. this._spreadMode !== _ui_utils.SpreadMode.NONE &&
  10458. this._scrollMode !== _ui_utils.ScrollMode.HORIZONTAL;
  10459. const pageView = this.renderingQueue.getHighestPriority(
  10460. visiblePages,
  10461. this._pages,
  10462. scrollAhead,
  10463. preRenderExtra
  10464. );
  10465. if (pageView) {
  10466. this.#ensurePdfPageLoaded(pageView).then(() => {
  10467. this.renderingQueue.renderView(pageView);
  10468. });
  10469. return true;
  10470. }
  10471. return false;
  10472. }
  10473. get hasEqualPageSizes() {
  10474. const firstPageView = this._pages[0];
  10475. for (let i = 1, ii = this._pages.length; i < ii; ++i) {
  10476. const pageView = this._pages[i];
  10477. if (
  10478. pageView.width !== firstPageView.width ||
  10479. pageView.height !== firstPageView.height
  10480. ) {
  10481. return false;
  10482. }
  10483. }
  10484. return true;
  10485. }
  10486. getPagesOverview() {
  10487. return this._pages.map((pageView) => {
  10488. const viewport = pageView.pdfPage.getViewport({
  10489. scale: 1,
  10490. });
  10491. if (
  10492. !this.enablePrintAutoRotate ||
  10493. (0, _ui_utils.isPortraitOrientation)(viewport)
  10494. ) {
  10495. return {
  10496. width: viewport.width,
  10497. height: viewport.height,
  10498. rotation: viewport.rotation,
  10499. };
  10500. }
  10501. return {
  10502. width: viewport.height,
  10503. height: viewport.width,
  10504. rotation: (viewport.rotation - 90) % 360,
  10505. };
  10506. });
  10507. }
  10508. get optionalContentConfigPromise() {
  10509. if (!this.pdfDocument) {
  10510. return Promise.resolve(null);
  10511. }
  10512. if (!this._optionalContentConfigPromise) {
  10513. console.error("optionalContentConfigPromise: Not initialized yet.");
  10514. return this.pdfDocument.getOptionalContentConfig();
  10515. }
  10516. return this._optionalContentConfigPromise;
  10517. }
  10518. set optionalContentConfigPromise(promise) {
  10519. if (!(promise instanceof Promise)) {
  10520. throw new Error(`Invalid optionalContentConfigPromise: ${promise}`);
  10521. }
  10522. if (!this.pdfDocument) {
  10523. return;
  10524. }
  10525. if (!this._optionalContentConfigPromise) {
  10526. return;
  10527. }
  10528. this._optionalContentConfigPromise = promise;
  10529. this.refresh(false, {
  10530. optionalContentConfigPromise: promise,
  10531. });
  10532. this.eventBus.dispatch("optionalcontentconfigchanged", {
  10533. source: this,
  10534. promise,
  10535. });
  10536. }
  10537. get scrollMode() {
  10538. return this._scrollMode;
  10539. }
  10540. set scrollMode(mode) {
  10541. if (this._scrollMode === mode) {
  10542. return;
  10543. }
  10544. if (!(0, _ui_utils.isValidScrollMode)(mode)) {
  10545. throw new Error(`Invalid scroll mode: ${mode}`);
  10546. }
  10547. if (this.pagesCount > PagesCountLimit.FORCE_SCROLL_MODE_PAGE) {
  10548. return;
  10549. }
  10550. this._previousScrollMode = this._scrollMode;
  10551. this._scrollMode = mode;
  10552. this.eventBus.dispatch("scrollmodechanged", {
  10553. source: this,
  10554. mode,
  10555. });
  10556. this._updateScrollMode(this._currentPageNumber);
  10557. }
  10558. _updateScrollMode(pageNumber = null) {
  10559. const scrollMode = this._scrollMode,
  10560. viewer = this.viewer;
  10561. viewer.classList.toggle(
  10562. "scrollHorizontal",
  10563. scrollMode === _ui_utils.ScrollMode.HORIZONTAL
  10564. );
  10565. viewer.classList.toggle(
  10566. "scrollWrapped",
  10567. scrollMode === _ui_utils.ScrollMode.WRAPPED
  10568. );
  10569. if (!this.pdfDocument || !pageNumber) {
  10570. return;
  10571. }
  10572. if (scrollMode === _ui_utils.ScrollMode.PAGE) {
  10573. this.#ensurePageViewVisible();
  10574. } else if (this._previousScrollMode === _ui_utils.ScrollMode.PAGE) {
  10575. this._updateSpreadMode();
  10576. }
  10577. if (this._currentScaleValue && isNaN(this._currentScaleValue)) {
  10578. this.#setScale(this._currentScaleValue, {
  10579. noScroll: true,
  10580. });
  10581. }
  10582. this._setCurrentPageNumber(pageNumber, true);
  10583. this.update();
  10584. }
  10585. get spreadMode() {
  10586. return this._spreadMode;
  10587. }
  10588. set spreadMode(mode) {
  10589. if (this._spreadMode === mode) {
  10590. return;
  10591. }
  10592. if (!(0, _ui_utils.isValidSpreadMode)(mode)) {
  10593. throw new Error(`Invalid spread mode: ${mode}`);
  10594. }
  10595. this._spreadMode = mode;
  10596. this.eventBus.dispatch("spreadmodechanged", {
  10597. source: this,
  10598. mode,
  10599. });
  10600. this._updateSpreadMode(this._currentPageNumber);
  10601. }
  10602. _updateSpreadMode(pageNumber = null) {
  10603. if (!this.pdfDocument) {
  10604. return;
  10605. }
  10606. const viewer = this.viewer,
  10607. pages = this._pages;
  10608. if (this._scrollMode === _ui_utils.ScrollMode.PAGE) {
  10609. this.#ensurePageViewVisible();
  10610. } else {
  10611. viewer.textContent = "";
  10612. if (this._spreadMode === _ui_utils.SpreadMode.NONE) {
  10613. for (const pageView of this._pages) {
  10614. viewer.append(pageView.div);
  10615. }
  10616. } else {
  10617. const parity = this._spreadMode - 1;
  10618. let spread = null;
  10619. for (let i = 0, ii = pages.length; i < ii; ++i) {
  10620. if (spread === null) {
  10621. spread = document.createElement("div");
  10622. spread.className = "spread";
  10623. viewer.append(spread);
  10624. } else if (i % 2 === parity) {
  10625. spread = spread.cloneNode(false);
  10626. viewer.append(spread);
  10627. }
  10628. spread.append(pages[i].div);
  10629. }
  10630. }
  10631. }
  10632. if (!pageNumber) {
  10633. return;
  10634. }
  10635. if (this._currentScaleValue && isNaN(this._currentScaleValue)) {
  10636. this.#setScale(this._currentScaleValue, {
  10637. noScroll: true,
  10638. });
  10639. }
  10640. this._setCurrentPageNumber(pageNumber, true);
  10641. this.update();
  10642. }
  10643. _getPageAdvance(currentPageNumber, previous = false) {
  10644. switch (this._scrollMode) {
  10645. case _ui_utils.ScrollMode.WRAPPED: {
  10646. const { views } = this._getVisiblePages(),
  10647. pageLayout = new Map();
  10648. for (const { id, y, percent, widthPercent } of views) {
  10649. if (percent === 0 || widthPercent < 100) {
  10650. continue;
  10651. }
  10652. let yArray = pageLayout.get(y);
  10653. if (!yArray) {
  10654. pageLayout.set(y, (yArray ||= []));
  10655. }
  10656. yArray.push(id);
  10657. }
  10658. for (const yArray of pageLayout.values()) {
  10659. const currentIndex = yArray.indexOf(currentPageNumber);
  10660. if (currentIndex === -1) {
  10661. continue;
  10662. }
  10663. const numPages = yArray.length;
  10664. if (numPages === 1) {
  10665. break;
  10666. }
  10667. if (previous) {
  10668. for (let i = currentIndex - 1, ii = 0; i >= ii; i--) {
  10669. const currentId = yArray[i],
  10670. expectedId = yArray[i + 1] - 1;
  10671. if (currentId < expectedId) {
  10672. return currentPageNumber - expectedId;
  10673. }
  10674. }
  10675. } else {
  10676. for (let i = currentIndex + 1, ii = numPages; i < ii; i++) {
  10677. const currentId = yArray[i],
  10678. expectedId = yArray[i - 1] + 1;
  10679. if (currentId > expectedId) {
  10680. return expectedId - currentPageNumber;
  10681. }
  10682. }
  10683. }
  10684. if (previous) {
  10685. const firstId = yArray[0];
  10686. if (firstId < currentPageNumber) {
  10687. return currentPageNumber - firstId + 1;
  10688. }
  10689. } else {
  10690. const lastId = yArray[numPages - 1];
  10691. if (lastId > currentPageNumber) {
  10692. return lastId - currentPageNumber + 1;
  10693. }
  10694. }
  10695. break;
  10696. }
  10697. break;
  10698. }
  10699. case _ui_utils.ScrollMode.HORIZONTAL: {
  10700. break;
  10701. }
  10702. case _ui_utils.ScrollMode.PAGE:
  10703. case _ui_utils.ScrollMode.VERTICAL: {
  10704. if (this._spreadMode === _ui_utils.SpreadMode.NONE) {
  10705. break;
  10706. }
  10707. const parity = this._spreadMode - 1;
  10708. if (previous && currentPageNumber % 2 !== parity) {
  10709. break;
  10710. } else if (!previous && currentPageNumber % 2 === parity) {
  10711. break;
  10712. }
  10713. const { views } = this._getVisiblePages(),
  10714. expectedId = previous
  10715. ? currentPageNumber - 1
  10716. : currentPageNumber + 1;
  10717. for (const { id, percent, widthPercent } of views) {
  10718. if (id !== expectedId) {
  10719. continue;
  10720. }
  10721. if (percent > 0 && widthPercent === 100) {
  10722. return 2;
  10723. }
  10724. break;
  10725. }
  10726. break;
  10727. }
  10728. }
  10729. return 1;
  10730. }
  10731. nextPage() {
  10732. const currentPageNumber = this._currentPageNumber,
  10733. pagesCount = this.pagesCount;
  10734. if (currentPageNumber >= pagesCount) {
  10735. return false;
  10736. }
  10737. const advance = this._getPageAdvance(currentPageNumber, false) || 1;
  10738. this.currentPageNumber = Math.min(
  10739. currentPageNumber + advance,
  10740. pagesCount
  10741. );
  10742. return true;
  10743. }
  10744. previousPage() {
  10745. const currentPageNumber = this._currentPageNumber;
  10746. if (currentPageNumber <= 1) {
  10747. return false;
  10748. }
  10749. const advance = this._getPageAdvance(currentPageNumber, true) || 1;
  10750. this.currentPageNumber = Math.max(currentPageNumber - advance, 1);
  10751. return true;
  10752. }
  10753. increaseScale({ drawingDelay, scaleFactor, steps } = {}) {
  10754. if (!this.pdfDocument) {
  10755. return;
  10756. }
  10757. let newScale = this._currentScale;
  10758. if (scaleFactor > 1) {
  10759. newScale = Math.round(newScale * scaleFactor * 100) / 100;
  10760. } else {
  10761. steps ??= 1;
  10762. do {
  10763. newScale =
  10764. Math.ceil(
  10765. (newScale * _ui_utils.DEFAULT_SCALE_DELTA).toFixed(2) * 10
  10766. ) / 10;
  10767. } while (--steps > 0 && newScale < _ui_utils.MAX_SCALE);
  10768. }
  10769. this.#setScale(Math.min(_ui_utils.MAX_SCALE, newScale), {
  10770. noScroll: false,
  10771. drawingDelay,
  10772. });
  10773. }
  10774. decreaseScale({ drawingDelay, scaleFactor, steps } = {}) {
  10775. if (!this.pdfDocument) {
  10776. return;
  10777. }
  10778. let newScale = this._currentScale;
  10779. if (scaleFactor > 0 && scaleFactor < 1) {
  10780. newScale = Math.round(newScale * scaleFactor * 100) / 100;
  10781. } else {
  10782. steps ??= 1;
  10783. do {
  10784. newScale =
  10785. Math.floor(
  10786. (newScale / _ui_utils.DEFAULT_SCALE_DELTA).toFixed(2) * 10
  10787. ) / 10;
  10788. } while (--steps > 0 && newScale > _ui_utils.MIN_SCALE);
  10789. }
  10790. this.#setScale(Math.max(_ui_utils.MIN_SCALE, newScale), {
  10791. noScroll: false,
  10792. drawingDelay,
  10793. });
  10794. }
  10795. #updateContainerHeightCss(height = this.container.clientHeight) {
  10796. if (height !== this.#previousContainerHeight) {
  10797. this.#previousContainerHeight = height;
  10798. _ui_utils.docStyle.setProperty(
  10799. "--viewer-container-height",
  10800. `${height}px`
  10801. );
  10802. }
  10803. }
  10804. #resizeObserverCallback(entries) {
  10805. for (const entry of entries) {
  10806. if (entry.target === this.container) {
  10807. this.#updateContainerHeightCss(
  10808. Math.floor(entry.borderBoxSize[0].blockSize)
  10809. );
  10810. this.#containerTopLeft = null;
  10811. break;
  10812. }
  10813. }
  10814. }
  10815. get containerTopLeft() {
  10816. return (this.#containerTopLeft ||= [
  10817. this.container.offsetTop,
  10818. this.container.offsetLeft,
  10819. ]);
  10820. }
  10821. get annotationEditorMode() {
  10822. return this.#annotationEditorUIManager
  10823. ? this.#annotationEditorMode
  10824. : _pdfjsLib.AnnotationEditorType.DISABLE;
  10825. }
  10826. set annotationEditorMode(mode) {
  10827. if (!this.#annotationEditorUIManager) {
  10828. throw new Error(`The AnnotationEditor is not enabled.`);
  10829. }
  10830. if (this.#annotationEditorMode === mode) {
  10831. return;
  10832. }
  10833. if (!isValidAnnotationEditorMode(mode)) {
  10834. throw new Error(`Invalid AnnotationEditor mode: ${mode}`);
  10835. }
  10836. if (!this.pdfDocument) {
  10837. return;
  10838. }
  10839. this.#annotationEditorMode = mode;
  10840. this.eventBus.dispatch("annotationeditormodechanged", {
  10841. source: this,
  10842. mode,
  10843. });
  10844. this.#annotationEditorUIManager.updateMode(mode);
  10845. }
  10846. set annotationEditorParams({ type, value }) {
  10847. if (!this.#annotationEditorUIManager) {
  10848. throw new Error(`The AnnotationEditor is not enabled.`);
  10849. }
  10850. this.#annotationEditorUIManager.updateParams(type, value);
  10851. }
  10852. refresh(noUpdate = false, updateArgs = Object.create(null)) {
  10853. if (!this.pdfDocument) {
  10854. return;
  10855. }
  10856. for (const pageView of this._pages) {
  10857. pageView.update(updateArgs);
  10858. }
  10859. if (this.#scaleTimeoutId !== null) {
  10860. clearTimeout(this.#scaleTimeoutId);
  10861. this.#scaleTimeoutId = null;
  10862. }
  10863. if (!noUpdate) {
  10864. this.update();
  10865. }
  10866. }
  10867. }
  10868. exports.PDFViewer = PDFViewer;
  10869. /***/
  10870. },
  10871. /* 30 */
  10872. /***/ (__unused_webpack_module, exports) => {
  10873. Object.defineProperty(exports, "__esModule", {
  10874. value: true,
  10875. });
  10876. exports.NullL10n = void 0;
  10877. exports.fixupLangCode = fixupLangCode;
  10878. exports.getL10nFallback = getL10nFallback;
  10879. const DEFAULT_L10N_STRINGS = {
  10880. of_pages: "of {{pagesCount}}",
  10881. page_of_pages: "({{pageNumber}} of {{pagesCount}})",
  10882. document_properties_kb: "{{size_kb}} KB ({{size_b}} bytes)",
  10883. document_properties_mb: "{{size_mb}} MB ({{size_b}} bytes)",
  10884. document_properties_date_string: "{{date}}, {{time}}",
  10885. document_properties_page_size_unit_inches: "in",
  10886. document_properties_page_size_unit_millimeters: "mm",
  10887. document_properties_page_size_orientation_portrait: "portrait",
  10888. document_properties_page_size_orientation_landscape: "landscape",
  10889. document_properties_page_size_name_a3: "A3",
  10890. document_properties_page_size_name_a4: "A4",
  10891. document_properties_page_size_name_letter: "Letter",
  10892. document_properties_page_size_name_legal: "Legal",
  10893. document_properties_page_size_dimension_string:
  10894. "{{width}} × {{height}} {{unit}} ({{orientation}})",
  10895. document_properties_page_size_dimension_name_string:
  10896. "{{width}} × {{height}} {{unit}} ({{name}}, {{orientation}})",
  10897. document_properties_linearized_yes: "Yes",
  10898. document_properties_linearized_no: "No",
  10899. additional_layers: "Additional Layers",
  10900. page_landmark: "Page {{page}}",
  10901. thumb_page_title: "Page {{page}}",
  10902. thumb_page_canvas: "Thumbnail of Page {{page}}",
  10903. find_reached_top: "Reached top of document, continued from bottom",
  10904. find_reached_bottom: "Reached end of document, continued from top",
  10905. "find_match_count[one]": "{{current}} of {{total}} match",
  10906. "find_match_count[other]": "{{current}} of {{total}} matches",
  10907. "find_match_count_limit[one]": "More than {{limit}} match",
  10908. "find_match_count_limit[other]": "More than {{limit}} matches",
  10909. find_not_found: "Phrase not found",
  10910. page_scale_width: "Page Width",
  10911. page_scale_fit: "Page Fit",
  10912. page_scale_auto: "Automatic Zoom",
  10913. page_scale_actual: "Actual Size",
  10914. page_scale_percent: "{{scale}}%",
  10915. loading_error: "An error occurred while loading the PDF.",
  10916. invalid_file_error: "Invalid or corrupted PDF file.",
  10917. missing_file_error: "Missing PDF file.",
  10918. unexpected_response_error: "Unexpected server response.",
  10919. rendering_error: "An error occurred while rendering the page.",
  10920. printing_not_supported:
  10921. "Warning: Printing is not fully supported by this browser.",
  10922. printing_not_ready:
  10923. "Warning: The PDF is not fully loaded for printing.",
  10924. web_fonts_disabled:
  10925. "Web fonts are disabled: unable to use embedded PDF fonts.",
  10926. free_text2_default_content: "Start typing…",
  10927. editor_free_text2_aria_label: "Text Editor",
  10928. editor_ink2_aria_label: "Draw Editor",
  10929. editor_ink_canvas_aria_label: "User-created image",
  10930. };
  10931. {
  10932. DEFAULT_L10N_STRINGS.print_progress_percent = "{{progress}}%";
  10933. }
  10934. function getL10nFallback(key, args) {
  10935. switch (key) {
  10936. case "find_match_count":
  10937. key = `find_match_count[${args.total === 1 ? "one" : "other"}]`;
  10938. break;
  10939. case "find_match_count_limit":
  10940. key = `find_match_count_limit[${
  10941. args.limit === 1 ? "one" : "other"
  10942. }]`;
  10943. break;
  10944. }
  10945. return DEFAULT_L10N_STRINGS[key] || "";
  10946. }
  10947. const PARTIAL_LANG_CODES = {
  10948. en: "en-US",
  10949. es: "es-ES",
  10950. fy: "fy-NL",
  10951. ga: "ga-IE",
  10952. gu: "gu-IN",
  10953. hi: "hi-IN",
  10954. hy: "hy-AM",
  10955. nb: "nb-NO",
  10956. ne: "ne-NP",
  10957. nn: "nn-NO",
  10958. pa: "pa-IN",
  10959. pt: "pt-PT",
  10960. sv: "sv-SE",
  10961. zh: "zh-CN",
  10962. };
  10963. function fixupLangCode(langCode) {
  10964. return PARTIAL_LANG_CODES[langCode?.toLowerCase()] || langCode;
  10965. }
  10966. function formatL10nValue(text, args) {
  10967. if (!args) {
  10968. return text;
  10969. }
  10970. return text.replaceAll(/\{\{\s*(\w+)\s*\}\}/g, (all, name) => {
  10971. return name in args ? args[name] : "{{" + name + "}}";
  10972. });
  10973. }
  10974. const NullL10n = {
  10975. async getLanguage() {
  10976. return "en-us";
  10977. },
  10978. async getDirection() {
  10979. return "ltr";
  10980. },
  10981. async get(key, args = null, fallback = getL10nFallback(key, args)) {
  10982. return formatL10nValue(fallback, args);
  10983. },
  10984. async translate(element) {},
  10985. };
  10986. exports.NullL10n = NullL10n;
  10987. /***/
  10988. },
  10989. /* 31 */
  10990. /***/ (__unused_webpack_module, exports, __webpack_require__) => {
  10991. Object.defineProperty(exports, "__esModule", {
  10992. value: true,
  10993. });
  10994. exports.PDFPageView = void 0;
  10995. var _pdfjsLib = __webpack_require__(4);
  10996. var _ui_utils = __webpack_require__(3);
  10997. var _annotation_editor_layer_builder = __webpack_require__(32);
  10998. var _annotation_layer_builder = __webpack_require__(33);
  10999. var _app_options = __webpack_require__(5);
  11000. var _l10n_utils = __webpack_require__(30);
  11001. var _pdf_link_service = __webpack_require__(7);
  11002. var _struct_tree_layer_builder = __webpack_require__(34);
  11003. var _text_accessibility = __webpack_require__(35);
  11004. var _text_highlighter = __webpack_require__(36);
  11005. var _text_layer_builder = __webpack_require__(37);
  11006. var _xfa_layer_builder = __webpack_require__(38);
  11007. const MAX_CANVAS_PIXELS =
  11008. _app_options.compatibilityParams.maxCanvasPixels || 16777216;
  11009. const DEFAULT_LAYER_PROPERTIES = () => {
  11010. return null;
  11011. };
  11012. class PDFPageView {
  11013. #annotationMode = _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  11014. #layerProperties = null;
  11015. #loadingId = null;
  11016. #previousRotation = null;
  11017. #renderingState = _ui_utils.RenderingStates.INITIAL;
  11018. #useThumbnailCanvas = {
  11019. initialOptionalContent: true,
  11020. regularAnnotations: true,
  11021. };
  11022. constructor(options) {
  11023. const container = options.container;
  11024. const defaultViewport = options.defaultViewport;
  11025. this.id = options.id;
  11026. this.renderingId = "page" + this.id;
  11027. this.#layerProperties =
  11028. options.layerProperties || DEFAULT_LAYER_PROPERTIES;
  11029. this.pdfPage = null;
  11030. this.pageLabel = null;
  11031. this.rotation = 0;
  11032. this.scale = options.scale || _ui_utils.DEFAULT_SCALE;
  11033. this.viewport = defaultViewport;
  11034. this.pdfPageRotate = defaultViewport.rotation;
  11035. this._optionalContentConfigPromise =
  11036. options.optionalContentConfigPromise || null;
  11037. this.hasRestrictedScaling = false;
  11038. this.textLayerMode =
  11039. options.textLayerMode ?? _ui_utils.TextLayerMode.ENABLE;
  11040. this.#annotationMode =
  11041. options.annotationMode ?? _pdfjsLib.AnnotationMode.ENABLE_FORMS;
  11042. this.imageResourcesPath = options.imageResourcesPath || "";
  11043. this.useOnlyCssZoom = options.useOnlyCssZoom || false;
  11044. this.isOffscreenCanvasSupported =
  11045. options.isOffscreenCanvasSupported ?? true;
  11046. this.maxCanvasPixels = options.maxCanvasPixels || MAX_CANVAS_PIXELS;
  11047. this.pageColors = options.pageColors || null;
  11048. this.eventBus = options.eventBus;
  11049. this.renderingQueue = options.renderingQueue;
  11050. this.renderer = options.renderer || _ui_utils.RendererType.CANVAS;
  11051. this.l10n = options.l10n || _l10n_utils.NullL10n;
  11052. this.paintTask = null;
  11053. this.paintedViewportMap = new WeakMap();
  11054. this.resume = null;
  11055. this._renderError = null;
  11056. this._isStandalone = !this.renderingQueue?.hasViewer();
  11057. this._annotationCanvasMap = null;
  11058. this.annotationLayer = null;
  11059. this.annotationEditorLayer = null;
  11060. this.textLayer = null;
  11061. this.zoomLayer = null;
  11062. this.xfaLayer = null;
  11063. this.structTreeLayer = null;
  11064. const div = document.createElement("div");
  11065. div.className = "page";
  11066. div.setAttribute("data-page-number", this.id);
  11067. div.setAttribute("role", "region");
  11068. this.l10n
  11069. .get("page_landmark", {
  11070. page: this.id,
  11071. })
  11072. .then((msg) => {
  11073. div.setAttribute("aria-label", msg);
  11074. });
  11075. this.div = div;
  11076. this.#setDimensions();
  11077. container?.append(div);
  11078. if (this._isStandalone) {
  11079. container?.style.setProperty(
  11080. "--scale-factor",
  11081. this.scale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS
  11082. );
  11083. const { optionalContentConfigPromise } = options;
  11084. if (optionalContentConfigPromise) {
  11085. optionalContentConfigPromise.then((optionalContentConfig) => {
  11086. if (
  11087. optionalContentConfigPromise !==
  11088. this._optionalContentConfigPromise
  11089. ) {
  11090. return;
  11091. }
  11092. this.#useThumbnailCanvas.initialOptionalContent =
  11093. optionalContentConfig.hasInitialVisibility;
  11094. });
  11095. }
  11096. }
  11097. }
  11098. get renderingState() {
  11099. return this.#renderingState;
  11100. }
  11101. set renderingState(state) {
  11102. if (state === this.#renderingState) {
  11103. return;
  11104. }
  11105. this.#renderingState = state;
  11106. if (this.#loadingId) {
  11107. clearTimeout(this.#loadingId);
  11108. this.#loadingId = null;
  11109. }
  11110. switch (state) {
  11111. case _ui_utils.RenderingStates.PAUSED:
  11112. this.div.classList.remove("loading");
  11113. break;
  11114. case _ui_utils.RenderingStates.RUNNING:
  11115. this.div.classList.add("loadingIcon");
  11116. this.#loadingId = setTimeout(() => {
  11117. this.div.classList.add("loading");
  11118. this.#loadingId = null;
  11119. }, 0);
  11120. break;
  11121. case _ui_utils.RenderingStates.INITIAL:
  11122. case _ui_utils.RenderingStates.FINISHED:
  11123. this.div.classList.remove("loadingIcon", "loading");
  11124. break;
  11125. }
  11126. }
  11127. #setDimensions() {
  11128. const { viewport } = this;
  11129. if (this.pdfPage) {
  11130. if (this.#previousRotation === viewport.rotation) {
  11131. return;
  11132. }
  11133. this.#previousRotation = viewport.rotation;
  11134. }
  11135. (0, _pdfjsLib.setLayerDimensions)(this.div, viewport, true, false);
  11136. }
  11137. setPdfPage(pdfPage) {
  11138. this.pdfPage = pdfPage;
  11139. this.pdfPageRotate = pdfPage.rotate;
  11140. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  11141. this.viewport = pdfPage.getViewport({
  11142. scale: this.scale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS,
  11143. rotation: totalRotation,
  11144. });
  11145. this.#setDimensions();
  11146. this.reset();
  11147. }
  11148. destroy() {
  11149. this.reset();
  11150. this.pdfPage?.cleanup();
  11151. }
  11152. get _textHighlighter() {
  11153. return (0, _pdfjsLib.shadow)(
  11154. this,
  11155. "_textHighlighter",
  11156. new _text_highlighter.TextHighlighter({
  11157. pageIndex: this.id - 1,
  11158. eventBus: this.eventBus,
  11159. findController: this.#layerProperties().findController,
  11160. })
  11161. );
  11162. }
  11163. async #renderAnnotationLayer() {
  11164. let error = null;
  11165. try {
  11166. await this.annotationLayer.render(this.viewport, "display");
  11167. } catch (ex) {
  11168. console.error(`#renderAnnotationLayer: "${ex}".`);
  11169. error = ex;
  11170. } finally {
  11171. this.eventBus.dispatch("annotationlayerrendered", {
  11172. source: this,
  11173. pageNumber: this.id,
  11174. error,
  11175. });
  11176. }
  11177. }
  11178. async #renderAnnotationEditorLayer() {
  11179. let error = null;
  11180. try {
  11181. await this.annotationEditorLayer.render(this.viewport, "display");
  11182. } catch (ex) {
  11183. console.error(`#renderAnnotationEditorLayer: "${ex}".`);
  11184. error = ex;
  11185. } finally {
  11186. this.eventBus.dispatch("annotationeditorlayerrendered", {
  11187. source: this,
  11188. pageNumber: this.id,
  11189. error,
  11190. });
  11191. }
  11192. }
  11193. async #renderXfaLayer() {
  11194. let error = null;
  11195. try {
  11196. const result = await this.xfaLayer.render(this.viewport, "display");
  11197. if (result?.textDivs && this._textHighlighter) {
  11198. this.#buildXfaTextContentItems(result.textDivs);
  11199. }
  11200. } catch (ex) {
  11201. console.error(`#renderXfaLayer: "${ex}".`);
  11202. error = ex;
  11203. } finally {
  11204. this.eventBus.dispatch("xfalayerrendered", {
  11205. source: this,
  11206. pageNumber: this.id,
  11207. error,
  11208. });
  11209. }
  11210. }
  11211. async #renderTextLayer() {
  11212. const { pdfPage, textLayer, viewport } = this;
  11213. if (!textLayer) {
  11214. return;
  11215. }
  11216. let error = null;
  11217. try {
  11218. if (!textLayer.renderingDone) {
  11219. const readableStream = pdfPage.streamTextContent({
  11220. includeMarkedContent: true,
  11221. });
  11222. textLayer.setTextContentSource(readableStream);
  11223. }
  11224. await textLayer.render(viewport);
  11225. } catch (ex) {
  11226. if (ex instanceof _pdfjsLib.AbortException) {
  11227. return;
  11228. }
  11229. console.error(`#renderTextLayer: "${ex}".`);
  11230. error = ex;
  11231. }
  11232. this.eventBus.dispatch("textlayerrendered", {
  11233. source: this,
  11234. pageNumber: this.id,
  11235. numTextDivs: textLayer.numTextDivs,
  11236. error,
  11237. });
  11238. this.#renderStructTreeLayer();
  11239. }
  11240. async #renderStructTreeLayer() {
  11241. if (!this.textLayer) {
  11242. return;
  11243. }
  11244. this.structTreeLayer ||=
  11245. new _struct_tree_layer_builder.StructTreeLayerBuilder();
  11246. const tree = await (!this.structTreeLayer.renderingDone
  11247. ? this.pdfPage.getStructTree()
  11248. : null);
  11249. const treeDom = this.structTreeLayer?.render(tree);
  11250. if (treeDom) {
  11251. this.canvas?.append(treeDom);
  11252. }
  11253. this.structTreeLayer?.show();
  11254. }
  11255. async #buildXfaTextContentItems(textDivs) {
  11256. const text = await this.pdfPage.getTextContent();
  11257. const items = [];
  11258. for (const item of text.items) {
  11259. items.push(item.str);
  11260. }
  11261. this._textHighlighter.setTextMapping(textDivs, items);
  11262. this._textHighlighter.enable();
  11263. }
  11264. _resetZoomLayer(removeFromDOM = false) {
  11265. if (!this.zoomLayer) {
  11266. return;
  11267. }
  11268. const zoomLayerCanvas = this.zoomLayer.firstChild;
  11269. this.paintedViewportMap.delete(zoomLayerCanvas);
  11270. zoomLayerCanvas.width = 0;
  11271. zoomLayerCanvas.height = 0;
  11272. if (removeFromDOM) {
  11273. this.zoomLayer.remove();
  11274. }
  11275. this.zoomLayer = null;
  11276. }
  11277. reset({
  11278. keepZoomLayer = false,
  11279. keepAnnotationLayer = false,
  11280. keepAnnotationEditorLayer = false,
  11281. keepXfaLayer = false,
  11282. keepTextLayer = false,
  11283. } = {}) {
  11284. this.cancelRendering({
  11285. keepAnnotationLayer,
  11286. keepAnnotationEditorLayer,
  11287. keepXfaLayer,
  11288. keepTextLayer,
  11289. });
  11290. this.renderingState = _ui_utils.RenderingStates.INITIAL;
  11291. const div = this.div;
  11292. const childNodes = div.childNodes,
  11293. zoomLayerNode = (keepZoomLayer && this.zoomLayer) || null,
  11294. annotationLayerNode =
  11295. (keepAnnotationLayer && this.annotationLayer?.div) || null,
  11296. annotationEditorLayerNode =
  11297. (keepAnnotationEditorLayer && this.annotationEditorLayer?.div) ||
  11298. null,
  11299. xfaLayerNode = (keepXfaLayer && this.xfaLayer?.div) || null,
  11300. textLayerNode = (keepTextLayer && this.textLayer?.div) || null;
  11301. for (let i = childNodes.length - 1; i >= 0; i--) {
  11302. const node = childNodes[i];
  11303. switch (node) {
  11304. case zoomLayerNode:
  11305. case annotationLayerNode:
  11306. case annotationEditorLayerNode:
  11307. case xfaLayerNode:
  11308. case textLayerNode:
  11309. continue;
  11310. }
  11311. node.remove();
  11312. }
  11313. div.removeAttribute("data-loaded");
  11314. if (annotationLayerNode) {
  11315. this.annotationLayer.hide();
  11316. }
  11317. if (annotationEditorLayerNode) {
  11318. this.annotationEditorLayer.hide();
  11319. }
  11320. if (xfaLayerNode) {
  11321. this.xfaLayer.hide();
  11322. }
  11323. if (textLayerNode) {
  11324. this.textLayer.hide();
  11325. }
  11326. this.structTreeLayer?.hide();
  11327. if (!zoomLayerNode) {
  11328. if (this.canvas) {
  11329. this.paintedViewportMap.delete(this.canvas);
  11330. this.canvas.width = 0;
  11331. this.canvas.height = 0;
  11332. delete this.canvas;
  11333. }
  11334. this._resetZoomLayer();
  11335. }
  11336. if (this.svg) {
  11337. this.paintedViewportMap.delete(this.svg);
  11338. delete this.svg;
  11339. }
  11340. }
  11341. update({
  11342. scale = 0,
  11343. rotation = null,
  11344. optionalContentConfigPromise = null,
  11345. drawingDelay = -1,
  11346. }) {
  11347. this.scale = scale || this.scale;
  11348. if (typeof rotation === "number") {
  11349. this.rotation = rotation;
  11350. }
  11351. if (optionalContentConfigPromise instanceof Promise) {
  11352. this._optionalContentConfigPromise = optionalContentConfigPromise;
  11353. optionalContentConfigPromise.then((optionalContentConfig) => {
  11354. if (
  11355. optionalContentConfigPromise !==
  11356. this._optionalContentConfigPromise
  11357. ) {
  11358. return;
  11359. }
  11360. this.#useThumbnailCanvas.initialOptionalContent =
  11361. optionalContentConfig.hasInitialVisibility;
  11362. });
  11363. }
  11364. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  11365. this.viewport = this.viewport.clone({
  11366. scale: this.scale * _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS,
  11367. rotation: totalRotation,
  11368. });
  11369. this.#setDimensions();
  11370. if (this._isStandalone) {
  11371. this.div.parentNode?.style.setProperty(
  11372. "--scale-factor",
  11373. this.viewport.scale
  11374. );
  11375. }
  11376. if (this.svg) {
  11377. this.cssTransform({
  11378. target: this.svg,
  11379. redrawAnnotationLayer: true,
  11380. redrawAnnotationEditorLayer: true,
  11381. redrawXfaLayer: true,
  11382. redrawTextLayer: true,
  11383. });
  11384. this.eventBus.dispatch("pagerendered", {
  11385. source: this,
  11386. pageNumber: this.id,
  11387. cssTransform: true,
  11388. timestamp: performance.now(),
  11389. error: this._renderError,
  11390. });
  11391. return;
  11392. }
  11393. let isScalingRestricted = false;
  11394. if (this.canvas && this.maxCanvasPixels > 0) {
  11395. const outputScale = this.outputScale;
  11396. if (
  11397. ((Math.floor(this.viewport.width) * outputScale.sx) | 0) *
  11398. ((Math.floor(this.viewport.height) * outputScale.sy) | 0) >
  11399. this.maxCanvasPixels
  11400. ) {
  11401. isScalingRestricted = true;
  11402. }
  11403. }
  11404. const onlyCssZoom =
  11405. this.useOnlyCssZoom ||
  11406. (this.hasRestrictedScaling && isScalingRestricted);
  11407. const postponeDrawing =
  11408. !onlyCssZoom && drawingDelay >= 0 && drawingDelay < 1000;
  11409. if (this.canvas) {
  11410. if (postponeDrawing || onlyCssZoom) {
  11411. if (
  11412. postponeDrawing &&
  11413. this.renderingState !== _ui_utils.RenderingStates.FINISHED
  11414. ) {
  11415. this.cancelRendering({
  11416. keepZoomLayer: true,
  11417. keepAnnotationLayer: true,
  11418. keepAnnotationEditorLayer: true,
  11419. keepXfaLayer: true,
  11420. keepTextLayer: true,
  11421. cancelExtraDelay: drawingDelay,
  11422. });
  11423. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  11424. }
  11425. this.cssTransform({
  11426. target: this.canvas,
  11427. redrawAnnotationLayer: true,
  11428. redrawAnnotationEditorLayer: true,
  11429. redrawXfaLayer: true,
  11430. redrawTextLayer: !postponeDrawing,
  11431. hideTextLayer: postponeDrawing,
  11432. });
  11433. this.eventBus.dispatch("pagerendered", {
  11434. source: this,
  11435. pageNumber: this.id,
  11436. cssTransform: true,
  11437. timestamp: performance.now(),
  11438. error: this._renderError,
  11439. });
  11440. return;
  11441. }
  11442. if (!this.zoomLayer && !this.canvas.hidden) {
  11443. this.zoomLayer = this.canvas.parentNode;
  11444. this.zoomLayer.style.position = "absolute";
  11445. }
  11446. }
  11447. if (this.zoomLayer) {
  11448. this.cssTransform({
  11449. target: this.zoomLayer.firstChild,
  11450. });
  11451. }
  11452. this.reset({
  11453. keepZoomLayer: true,
  11454. keepAnnotationLayer: true,
  11455. keepAnnotationEditorLayer: true,
  11456. keepXfaLayer: true,
  11457. keepTextLayer: true,
  11458. });
  11459. }
  11460. cancelRendering({
  11461. keepAnnotationLayer = false,
  11462. keepAnnotationEditorLayer = false,
  11463. keepXfaLayer = false,
  11464. keepTextLayer = false,
  11465. cancelExtraDelay = 0,
  11466. } = {}) {
  11467. if (this.paintTask) {
  11468. this.paintTask.cancel(cancelExtraDelay);
  11469. this.paintTask = null;
  11470. }
  11471. this.resume = null;
  11472. if (this.textLayer && (!keepTextLayer || !this.textLayer.div)) {
  11473. this.textLayer.cancel();
  11474. this.textLayer = null;
  11475. }
  11476. if (this.structTreeLayer && !this.textLayer) {
  11477. this.structTreeLayer = null;
  11478. }
  11479. if (
  11480. this.annotationLayer &&
  11481. (!keepAnnotationLayer || !this.annotationLayer.div)
  11482. ) {
  11483. this.annotationLayer.cancel();
  11484. this.annotationLayer = null;
  11485. this._annotationCanvasMap = null;
  11486. }
  11487. if (
  11488. this.annotationEditorLayer &&
  11489. (!keepAnnotationEditorLayer || !this.annotationEditorLayer.div)
  11490. ) {
  11491. this.annotationEditorLayer.cancel();
  11492. this.annotationEditorLayer = null;
  11493. }
  11494. if (this.xfaLayer && (!keepXfaLayer || !this.xfaLayer.div)) {
  11495. this.xfaLayer.cancel();
  11496. this.xfaLayer = null;
  11497. this._textHighlighter?.disable();
  11498. }
  11499. }
  11500. cssTransform({
  11501. target,
  11502. redrawAnnotationLayer = false,
  11503. redrawAnnotationEditorLayer = false,
  11504. redrawXfaLayer = false,
  11505. redrawTextLayer = false,
  11506. hideTextLayer = false,
  11507. }) {
  11508. if (target instanceof HTMLCanvasElement) {
  11509. if (!target.hasAttribute("zooming")) {
  11510. target.setAttribute("zooming", true);
  11511. const { style } = target;
  11512. style.width = style.height = "";
  11513. }
  11514. } else {
  11515. const div = this.div;
  11516. const { width, height } = this.viewport;
  11517. target.style.width =
  11518. target.parentNode.style.width =
  11519. div.style.width =
  11520. Math.floor(width) + "px";
  11521. target.style.height =
  11522. target.parentNode.style.height =
  11523. div.style.height =
  11524. Math.floor(height) + "px";
  11525. }
  11526. const originalViewport = this.paintedViewportMap.get(target);
  11527. if (this.viewport !== originalViewport) {
  11528. const relativeRotation =
  11529. this.viewport.rotation - originalViewport.rotation;
  11530. const absRotation = Math.abs(relativeRotation);
  11531. let scaleX = 1,
  11532. scaleY = 1;
  11533. if (absRotation === 90 || absRotation === 270) {
  11534. const { width, height } = this.viewport;
  11535. scaleX = height / width;
  11536. scaleY = width / height;
  11537. }
  11538. target.style.transform = `rotate(${relativeRotation}deg) scale(${scaleX}, ${scaleY})`;
  11539. }
  11540. if (redrawAnnotationLayer && this.annotationLayer) {
  11541. this.#renderAnnotationLayer();
  11542. }
  11543. if (redrawAnnotationEditorLayer && this.annotationEditorLayer) {
  11544. this.#renderAnnotationEditorLayer();
  11545. }
  11546. if (redrawXfaLayer && this.xfaLayer) {
  11547. this.#renderXfaLayer();
  11548. }
  11549. if (this.textLayer) {
  11550. if (hideTextLayer) {
  11551. this.textLayer.hide();
  11552. this.structTreeLayer?.hide();
  11553. } else if (redrawTextLayer) {
  11554. this.#renderTextLayer();
  11555. }
  11556. }
  11557. }
  11558. get width() {
  11559. return this.viewport.width;
  11560. }
  11561. get height() {
  11562. return this.viewport.height;
  11563. }
  11564. getPagePoint(x, y) {
  11565. return this.viewport.convertToPdfPoint(x, y);
  11566. }
  11567. draw() {
  11568. if (this.renderingState !== _ui_utils.RenderingStates.INITIAL) {
  11569. console.error("Must be in new state before drawing");
  11570. this.reset();
  11571. }
  11572. const { div, pdfPage } = this;
  11573. if (!pdfPage) {
  11574. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  11575. return Promise.reject(new Error("pdfPage is not loaded"));
  11576. }
  11577. this.renderingState = _ui_utils.RenderingStates.RUNNING;
  11578. const canvasWrapper = document.createElement("div");
  11579. canvasWrapper.classList.add("canvasWrapper");
  11580. div.append(canvasWrapper);
  11581. if (
  11582. !this.textLayer &&
  11583. this.textLayerMode !== _ui_utils.TextLayerMode.DISABLE &&
  11584. !pdfPage.isPureXfa
  11585. ) {
  11586. this._accessibilityManager ||=
  11587. new _text_accessibility.TextAccessibilityManager();
  11588. this.textLayer = new _text_layer_builder.TextLayerBuilder({
  11589. highlighter: this._textHighlighter,
  11590. accessibilityManager: this._accessibilityManager,
  11591. isOffscreenCanvasSupported: this.isOffscreenCanvasSupported,
  11592. });
  11593. div.append(this.textLayer.div);
  11594. }
  11595. if (
  11596. !this.annotationLayer &&
  11597. this.#annotationMode !== _pdfjsLib.AnnotationMode.DISABLE
  11598. ) {
  11599. const {
  11600. annotationStorage,
  11601. downloadManager,
  11602. enableScripting,
  11603. fieldObjectsPromise,
  11604. hasJSActionsPromise,
  11605. linkService,
  11606. } = this.#layerProperties();
  11607. this._annotationCanvasMap ||= new Map();
  11608. this.annotationLayer =
  11609. new _annotation_layer_builder.AnnotationLayerBuilder({
  11610. pageDiv: div,
  11611. pdfPage,
  11612. annotationStorage,
  11613. imageResourcesPath: this.imageResourcesPath,
  11614. renderForms:
  11615. this.#annotationMode ===
  11616. _pdfjsLib.AnnotationMode.ENABLE_FORMS,
  11617. linkService,
  11618. downloadManager,
  11619. l10n: this.l10n,
  11620. enableScripting,
  11621. hasJSActionsPromise,
  11622. fieldObjectsPromise,
  11623. annotationCanvasMap: this._annotationCanvasMap,
  11624. accessibilityManager: this._accessibilityManager,
  11625. });
  11626. }
  11627. let renderContinueCallback = null;
  11628. if (this.renderingQueue) {
  11629. renderContinueCallback = (cont) => {
  11630. if (!this.renderingQueue.isHighestPriority(this)) {
  11631. this.renderingState = _ui_utils.RenderingStates.PAUSED;
  11632. this.resume = () => {
  11633. this.renderingState = _ui_utils.RenderingStates.RUNNING;
  11634. cont();
  11635. };
  11636. return;
  11637. }
  11638. cont();
  11639. };
  11640. }
  11641. const finishPaintTask = async (error = null) => {
  11642. if (paintTask === this.paintTask) {
  11643. this.paintTask = null;
  11644. }
  11645. if (error instanceof _pdfjsLib.RenderingCancelledException) {
  11646. this._renderError = null;
  11647. return;
  11648. }
  11649. this._renderError = error;
  11650. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  11651. this._resetZoomLayer(true);
  11652. this.#useThumbnailCanvas.regularAnnotations =
  11653. !paintTask.separateAnnots;
  11654. this.eventBus.dispatch("pagerendered", {
  11655. source: this,
  11656. pageNumber: this.id,
  11657. cssTransform: false,
  11658. timestamp: performance.now(),
  11659. error: this._renderError,
  11660. });
  11661. if (error) {
  11662. throw error;
  11663. }
  11664. };
  11665. const paintTask =
  11666. this.renderer === _ui_utils.RendererType.SVG
  11667. ? this.paintOnSvg(canvasWrapper)
  11668. : this.paintOnCanvas(canvasWrapper);
  11669. paintTask.onRenderContinue = renderContinueCallback;
  11670. this.paintTask = paintTask;
  11671. const resultPromise = paintTask.promise.then(
  11672. () => {
  11673. return finishPaintTask(null).then(async () => {
  11674. this.#renderTextLayer();
  11675. if (this.annotationLayer) {
  11676. await this.#renderAnnotationLayer();
  11677. }
  11678. if (!this.annotationEditorLayer) {
  11679. const { annotationEditorUIManager } = this.#layerProperties();
  11680. if (!annotationEditorUIManager) {
  11681. return;
  11682. }
  11683. this.annotationEditorLayer =
  11684. new _annotation_editor_layer_builder.AnnotationEditorLayerBuilder(
  11685. {
  11686. uiManager: annotationEditorUIManager,
  11687. pageDiv: div,
  11688. pdfPage,
  11689. l10n: this.l10n,
  11690. accessibilityManager: this._accessibilityManager,
  11691. }
  11692. );
  11693. }
  11694. this.#renderAnnotationEditorLayer();
  11695. });
  11696. },
  11697. function (reason) {
  11698. return finishPaintTask(reason);
  11699. }
  11700. );
  11701. if (pdfPage.isPureXfa) {
  11702. if (!this.xfaLayer) {
  11703. const { annotationStorage, linkService } =
  11704. this.#layerProperties();
  11705. this.xfaLayer = new _xfa_layer_builder.XfaLayerBuilder({
  11706. pageDiv: div,
  11707. pdfPage,
  11708. annotationStorage,
  11709. linkService,
  11710. });
  11711. } else if (this.xfaLayer.div) {
  11712. div.append(this.xfaLayer.div);
  11713. }
  11714. this.#renderXfaLayer();
  11715. }
  11716. div.setAttribute("data-loaded", true);
  11717. this.eventBus.dispatch("pagerender", {
  11718. source: this,
  11719. pageNumber: this.id,
  11720. });
  11721. return resultPromise;
  11722. }
  11723. paintOnCanvas(canvasWrapper) {
  11724. const renderCapability = (0, _pdfjsLib.createPromiseCapability)();
  11725. const result = {
  11726. promise: renderCapability.promise,
  11727. onRenderContinue(cont) {
  11728. cont();
  11729. },
  11730. cancel(extraDelay = 0) {
  11731. renderTask.cancel(extraDelay);
  11732. },
  11733. get separateAnnots() {
  11734. return renderTask.separateAnnots;
  11735. },
  11736. };
  11737. const viewport = this.viewport;
  11738. const { width, height } = viewport;
  11739. const canvas = document.createElement("canvas");
  11740. canvas.setAttribute("role", "presentation");
  11741. canvas.hidden = true;
  11742. let isCanvasHidden = true;
  11743. const hasHCM = !!(
  11744. this.pageColors?.background && this.pageColors?.foreground
  11745. );
  11746. const showCanvas = function (isLastShow) {
  11747. if (isCanvasHidden && (!hasHCM || isLastShow)) {
  11748. canvas.hidden = false;
  11749. isCanvasHidden = false;
  11750. }
  11751. };
  11752. canvasWrapper.append(canvas);
  11753. this.canvas = canvas;
  11754. const ctx = canvas.getContext("2d", {
  11755. alpha: false,
  11756. });
  11757. const outputScale = (this.outputScale = new _ui_utils.OutputScale());
  11758. if (this.useOnlyCssZoom) {
  11759. const actualSizeViewport = viewport.clone({
  11760. scale: _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS,
  11761. });
  11762. outputScale.sx *= actualSizeViewport.width / width;
  11763. outputScale.sy *= actualSizeViewport.height / height;
  11764. }
  11765. if (this.maxCanvasPixels > 0) {
  11766. const pixelsInViewport = width * height;
  11767. const maxScale = Math.sqrt(this.maxCanvasPixels / pixelsInViewport);
  11768. if (outputScale.sx > maxScale || outputScale.sy > maxScale) {
  11769. outputScale.sx = maxScale;
  11770. outputScale.sy = maxScale;
  11771. this.hasRestrictedScaling = true;
  11772. } else {
  11773. this.hasRestrictedScaling = false;
  11774. }
  11775. }
  11776. const sfx = (0, _ui_utils.approximateFraction)(outputScale.sx);
  11777. const sfy = (0, _ui_utils.approximateFraction)(outputScale.sy);
  11778. canvas.width = (0, _ui_utils.roundToDivide)(
  11779. viewport.width * outputScale.sx,
  11780. sfx[0]
  11781. );
  11782. canvas.height = (0, _ui_utils.roundToDivide)(
  11783. viewport.height * outputScale.sy,
  11784. sfy[0]
  11785. );
  11786. const { style } = canvas;
  11787. style.width =
  11788. (0, _ui_utils.roundToDivide)(viewport.width, sfx[1]) + "px";
  11789. style.height =
  11790. (0, _ui_utils.roundToDivide)(viewport.height, sfy[1]) + "px";
  11791. this.paintedViewportMap.set(canvas, viewport);
  11792. const transform = outputScale.scaled
  11793. ? [outputScale.sx, 0, 0, outputScale.sy, 0, 0]
  11794. : null;
  11795. const renderContext = {
  11796. canvasContext: ctx,
  11797. transform,
  11798. viewport,
  11799. annotationMode: this.#annotationMode,
  11800. optionalContentConfigPromise: this._optionalContentConfigPromise,
  11801. annotationCanvasMap: this._annotationCanvasMap,
  11802. pageColors: this.pageColors,
  11803. };
  11804. const renderTask = this.pdfPage.render(renderContext);
  11805. renderTask.onContinue = function (cont) {
  11806. showCanvas(false);
  11807. if (result.onRenderContinue) {
  11808. result.onRenderContinue(cont);
  11809. } else {
  11810. cont();
  11811. }
  11812. };
  11813. renderTask.promise.then(
  11814. function () {
  11815. showCanvas(true);
  11816. renderCapability.resolve();
  11817. },
  11818. function (error) {
  11819. if (!(error instanceof _pdfjsLib.RenderingCancelledException)) {
  11820. showCanvas(true);
  11821. }
  11822. renderCapability.reject(error);
  11823. }
  11824. );
  11825. return result;
  11826. }
  11827. paintOnSvg(wrapper) {
  11828. let cancelled = false;
  11829. const ensureNotCancelled = () => {
  11830. if (cancelled) {
  11831. throw new _pdfjsLib.RenderingCancelledException(
  11832. `Rendering cancelled, page ${this.id}`,
  11833. "svg"
  11834. );
  11835. }
  11836. };
  11837. const pdfPage = this.pdfPage;
  11838. const actualSizeViewport = this.viewport.clone({
  11839. scale: _pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS,
  11840. });
  11841. const promise = pdfPage
  11842. .getOperatorList({
  11843. annotationMode: this.#annotationMode,
  11844. })
  11845. .then((opList) => {
  11846. ensureNotCancelled();
  11847. const svgGfx = new _pdfjsLib.SVGGraphics(
  11848. pdfPage.commonObjs,
  11849. pdfPage.objs
  11850. );
  11851. return svgGfx.getSVG(opList, actualSizeViewport).then((svg) => {
  11852. ensureNotCancelled();
  11853. this.svg = svg;
  11854. this.paintedViewportMap.set(svg, actualSizeViewport);
  11855. svg.style.width = wrapper.style.width;
  11856. svg.style.height = wrapper.style.height;
  11857. this.renderingState = _ui_utils.RenderingStates.FINISHED;
  11858. wrapper.append(svg);
  11859. });
  11860. });
  11861. return {
  11862. promise,
  11863. onRenderContinue(cont) {
  11864. cont();
  11865. },
  11866. cancel() {
  11867. cancelled = true;
  11868. },
  11869. get separateAnnots() {
  11870. return false;
  11871. },
  11872. };
  11873. }
  11874. setPageLabel(label) {
  11875. this.pageLabel = typeof label === "string" ? label : null;
  11876. if (this.pageLabel !== null) {
  11877. this.div.setAttribute("data-page-label", this.pageLabel);
  11878. } else {
  11879. this.div.removeAttribute("data-page-label");
  11880. }
  11881. }
  11882. get thumbnailCanvas() {
  11883. const { initialOptionalContent, regularAnnotations } =
  11884. this.#useThumbnailCanvas;
  11885. return initialOptionalContent && regularAnnotations
  11886. ? this.canvas
  11887. : null;
  11888. }
  11889. }
  11890. exports.PDFPageView = PDFPageView;
  11891. /***/
  11892. },
  11893. /* 32 */
  11894. /***/ (__unused_webpack_module, exports, __webpack_require__) => {
  11895. Object.defineProperty(exports, "__esModule", {
  11896. value: true,
  11897. });
  11898. exports.AnnotationEditorLayerBuilder = void 0;
  11899. var _pdfjsLib = __webpack_require__(4);
  11900. var _l10n_utils = __webpack_require__(30);
  11901. class AnnotationEditorLayerBuilder {
  11902. #uiManager;
  11903. constructor(options) {
  11904. this.pageDiv = options.pageDiv;
  11905. this.pdfPage = options.pdfPage;
  11906. this.accessibilityManager = options.accessibilityManager;
  11907. this.l10n = options.l10n || _l10n_utils.NullL10n;
  11908. this.annotationEditorLayer = null;
  11909. this.div = null;
  11910. this._cancelled = false;
  11911. this.#uiManager = options.uiManager;
  11912. }
  11913. async render(viewport, intent = "display") {
  11914. if (intent !== "display") {
  11915. return;
  11916. }
  11917. if (this._cancelled) {
  11918. return;
  11919. }
  11920. const clonedViewport = viewport.clone({
  11921. dontFlip: true,
  11922. });
  11923. if (this.div) {
  11924. this.annotationEditorLayer.update({
  11925. viewport: clonedViewport,
  11926. });
  11927. this.show();
  11928. return;
  11929. }
  11930. const div = (this.div = document.createElement("div"));
  11931. div.className = "annotationEditorLayer";
  11932. div.tabIndex = 0;
  11933. div.hidden = true;
  11934. this.pageDiv.append(div);
  11935. this.annotationEditorLayer = new _pdfjsLib.AnnotationEditorLayer({
  11936. uiManager: this.#uiManager,
  11937. div,
  11938. accessibilityManager: this.accessibilityManager,
  11939. pageIndex: this.pdfPage.pageNumber - 1,
  11940. l10n: this.l10n,
  11941. viewport: clonedViewport,
  11942. });
  11943. const parameters = {
  11944. viewport: clonedViewport,
  11945. div,
  11946. annotations: null,
  11947. intent,
  11948. };
  11949. this.annotationEditorLayer.render(parameters);
  11950. this.show();
  11951. }
  11952. cancel() {
  11953. this._cancelled = true;
  11954. if (!this.div) {
  11955. return;
  11956. }
  11957. this.pageDiv = null;
  11958. this.annotationEditorLayer.destroy();
  11959. this.div.remove();
  11960. }
  11961. hide() {
  11962. if (!this.div) {
  11963. return;
  11964. }
  11965. this.div.hidden = true;
  11966. }
  11967. show() {
  11968. if (!this.div || this.annotationEditorLayer.isEmpty) {
  11969. return;
  11970. }
  11971. this.div.hidden = false;
  11972. }
  11973. }
  11974. exports.AnnotationEditorLayerBuilder = AnnotationEditorLayerBuilder;
  11975. /***/
  11976. },
  11977. /* 33 */
  11978. /***/ (__unused_webpack_module, exports, __webpack_require__) => {
  11979. Object.defineProperty(exports, "__esModule", {
  11980. value: true,
  11981. });
  11982. exports.AnnotationLayerBuilder = void 0;
  11983. var _pdfjsLib = __webpack_require__(4);
  11984. var _l10n_utils = __webpack_require__(30);
  11985. var _ui_utils = __webpack_require__(3);
  11986. class AnnotationLayerBuilder {
  11987. #numAnnotations = 0;
  11988. #onPresentationModeChanged = null;
  11989. constructor({
  11990. pageDiv,
  11991. pdfPage,
  11992. linkService,
  11993. downloadManager,
  11994. annotationStorage = null,
  11995. imageResourcesPath = "",
  11996. renderForms = true,
  11997. l10n = _l10n_utils.NullL10n,
  11998. enableScripting = false,
  11999. hasJSActionsPromise = null,
  12000. fieldObjectsPromise = null,
  12001. annotationCanvasMap = null,
  12002. accessibilityManager = null,
  12003. }) {
  12004. this.pageDiv = pageDiv;
  12005. this.pdfPage = pdfPage;
  12006. this.linkService = linkService;
  12007. this.downloadManager = downloadManager;
  12008. this.imageResourcesPath = imageResourcesPath;
  12009. this.renderForms = renderForms;
  12010. this.l10n = l10n;
  12011. this.annotationStorage = annotationStorage;
  12012. this.enableScripting = enableScripting;
  12013. this._hasJSActionsPromise =
  12014. hasJSActionsPromise || Promise.resolve(false);
  12015. this._fieldObjectsPromise =
  12016. fieldObjectsPromise || Promise.resolve(null);
  12017. this._annotationCanvasMap = annotationCanvasMap;
  12018. this._accessibilityManager = accessibilityManager;
  12019. this.div = null;
  12020. this._cancelled = false;
  12021. this._eventBus = linkService.eventBus;
  12022. }
  12023. async render(viewport, intent = "display") {
  12024. if (this.div) {
  12025. if (this._cancelled || this.#numAnnotations === 0) {
  12026. return;
  12027. }
  12028. _pdfjsLib.AnnotationLayer.update({
  12029. viewport: viewport.clone({
  12030. dontFlip: true,
  12031. }),
  12032. div: this.div,
  12033. annotationCanvasMap: this._annotationCanvasMap,
  12034. });
  12035. return;
  12036. }
  12037. const [annotations, hasJSActions, fieldObjects] = await Promise.all([
  12038. this.pdfPage.getAnnotations({
  12039. intent,
  12040. }),
  12041. this._hasJSActionsPromise,
  12042. this._fieldObjectsPromise,
  12043. ]);
  12044. if (this._cancelled) {
  12045. return;
  12046. }
  12047. this.#numAnnotations = annotations.length;
  12048. this.div = document.createElement("div");
  12049. this.div.className = "annotationLayer";
  12050. this.pageDiv.append(this.div);
  12051. if (this.#numAnnotations === 0) {
  12052. this.hide();
  12053. return;
  12054. }
  12055. _pdfjsLib.AnnotationLayer.render({
  12056. viewport: viewport.clone({
  12057. dontFlip: true,
  12058. }),
  12059. div: this.div,
  12060. annotations,
  12061. page: this.pdfPage,
  12062. imageResourcesPath: this.imageResourcesPath,
  12063. renderForms: this.renderForms,
  12064. linkService: this.linkService,
  12065. downloadManager: this.downloadManager,
  12066. annotationStorage: this.annotationStorage,
  12067. enableScripting: this.enableScripting,
  12068. hasJSActions,
  12069. fieldObjects,
  12070. annotationCanvasMap: this._annotationCanvasMap,
  12071. accessibilityManager: this._accessibilityManager,
  12072. });
  12073. this.l10n.translate(this.div);
  12074. if (this.linkService.isInPresentationMode) {
  12075. this.#updatePresentationModeState(
  12076. _ui_utils.PresentationModeState.FULLSCREEN
  12077. );
  12078. }
  12079. if (!this.#onPresentationModeChanged) {
  12080. this.#onPresentationModeChanged = (evt) => {
  12081. this.#updatePresentationModeState(evt.state);
  12082. };
  12083. this._eventBus?._on(
  12084. "presentationmodechanged",
  12085. this.#onPresentationModeChanged
  12086. );
  12087. }
  12088. }
  12089. cancel() {
  12090. this._cancelled = true;
  12091. if (this.#onPresentationModeChanged) {
  12092. this._eventBus?._off(
  12093. "presentationmodechanged",
  12094. this.#onPresentationModeChanged
  12095. );
  12096. this.#onPresentationModeChanged = null;
  12097. }
  12098. }
  12099. hide() {
  12100. if (!this.div) {
  12101. return;
  12102. }
  12103. this.div.hidden = true;
  12104. }
  12105. #updatePresentationModeState(state) {
  12106. if (!this.div) {
  12107. return;
  12108. }
  12109. let disableFormElements = false;
  12110. switch (state) {
  12111. case _ui_utils.PresentationModeState.FULLSCREEN:
  12112. disableFormElements = true;
  12113. break;
  12114. case _ui_utils.PresentationModeState.NORMAL:
  12115. break;
  12116. default:
  12117. return;
  12118. }
  12119. for (const section of this.div.childNodes) {
  12120. if (section.hasAttribute("data-internal-link")) {
  12121. continue;
  12122. }
  12123. section.inert = disableFormElements;
  12124. }
  12125. }
  12126. }
  12127. exports.AnnotationLayerBuilder = AnnotationLayerBuilder;
  12128. /***/
  12129. },
  12130. /* 34 */
  12131. /***/ (__unused_webpack_module, exports) => {
  12132. Object.defineProperty(exports, "__esModule", {
  12133. value: true,
  12134. });
  12135. exports.StructTreeLayerBuilder = void 0;
  12136. const PDF_ROLE_TO_HTML_ROLE = {
  12137. Document: null,
  12138. DocumentFragment: null,
  12139. Part: "group",
  12140. Sect: "group",
  12141. Div: "group",
  12142. Aside: "note",
  12143. NonStruct: "none",
  12144. P: null,
  12145. H: "heading",
  12146. Title: null,
  12147. FENote: "note",
  12148. Sub: "group",
  12149. Lbl: null,
  12150. Span: null,
  12151. Em: null,
  12152. Strong: null,
  12153. Link: "link",
  12154. Annot: "note",
  12155. Form: "form",
  12156. Ruby: null,
  12157. RB: null,
  12158. RT: null,
  12159. RP: null,
  12160. Warichu: null,
  12161. WT: null,
  12162. WP: null,
  12163. L: "list",
  12164. LI: "listitem",
  12165. LBody: null,
  12166. Table: "table",
  12167. TR: "row",
  12168. TH: "columnheader",
  12169. TD: "cell",
  12170. THead: "columnheader",
  12171. TBody: null,
  12172. TFoot: null,
  12173. Caption: null,
  12174. Figure: "figure",
  12175. Formula: null,
  12176. Artifact: null,
  12177. };
  12178. const HEADING_PATTERN = /^H(\d+)$/;
  12179. class StructTreeLayerBuilder {
  12180. #treeDom = undefined;
  12181. get renderingDone() {
  12182. return this.#treeDom !== undefined;
  12183. }
  12184. render(structTree) {
  12185. if (this.#treeDom !== undefined) {
  12186. return this.#treeDom;
  12187. }
  12188. const treeDom = this.#walk(structTree);
  12189. treeDom?.classList.add("structTree");
  12190. return (this.#treeDom = treeDom);
  12191. }
  12192. hide() {
  12193. if (this.#treeDom && !this.#treeDom.hidden) {
  12194. this.#treeDom.hidden = true;
  12195. }
  12196. }
  12197. show() {
  12198. if (this.#treeDom?.hidden) {
  12199. this.#treeDom.hidden = false;
  12200. }
  12201. }
  12202. #setAttributes(structElement, htmlElement) {
  12203. if (structElement.alt !== undefined) {
  12204. htmlElement.setAttribute("aria-label", structElement.alt);
  12205. }
  12206. if (structElement.id !== undefined) {
  12207. htmlElement.setAttribute("aria-owns", structElement.id);
  12208. }
  12209. if (structElement.lang !== undefined) {
  12210. htmlElement.setAttribute("lang", structElement.lang);
  12211. }
  12212. }
  12213. #walk(node) {
  12214. if (!node) {
  12215. return null;
  12216. }
  12217. const element = document.createElement("span");
  12218. if ("role" in node) {
  12219. const { role } = node;
  12220. const match = role.match(HEADING_PATTERN);
  12221. if (match) {
  12222. element.setAttribute("role", "heading");
  12223. element.setAttribute("aria-level", match[1]);
  12224. } else if (PDF_ROLE_TO_HTML_ROLE[role]) {
  12225. element.setAttribute("role", PDF_ROLE_TO_HTML_ROLE[role]);
  12226. }
  12227. }
  12228. this.#setAttributes(node, element);
  12229. if (node.children) {
  12230. if (node.children.length === 1 && "id" in node.children[0]) {
  12231. this.#setAttributes(node.children[0], element);
  12232. } else {
  12233. for (const kid of node.children) {
  12234. element.append(this.#walk(kid));
  12235. }
  12236. }
  12237. }
  12238. return element;
  12239. }
  12240. }
  12241. exports.StructTreeLayerBuilder = StructTreeLayerBuilder;
  12242. /***/
  12243. },
  12244. /* 35 */
  12245. /***/ (__unused_webpack_module, exports, __webpack_require__) => {
  12246. Object.defineProperty(exports, "__esModule", {
  12247. value: true,
  12248. });
  12249. exports.TextAccessibilityManager = void 0;
  12250. var _ui_utils = __webpack_require__(3);
  12251. class TextAccessibilityManager {
  12252. #enabled = false;
  12253. #textChildren = null;
  12254. #textNodes = new Map();
  12255. #waitingElements = new Map();
  12256. setTextMapping(textDivs) {
  12257. this.#textChildren = textDivs;
  12258. }
  12259. static #compareElementPositions(e1, e2) {
  12260. const rect1 = e1.getBoundingClientRect();
  12261. const rect2 = e2.getBoundingClientRect();
  12262. if (rect1.width === 0 && rect1.height === 0) {
  12263. return +1;
  12264. }
  12265. if (rect2.width === 0 && rect2.height === 0) {
  12266. return -1;
  12267. }
  12268. const top1 = rect1.y;
  12269. const bot1 = rect1.y + rect1.height;
  12270. const mid1 = rect1.y + rect1.height / 2;
  12271. const top2 = rect2.y;
  12272. const bot2 = rect2.y + rect2.height;
  12273. const mid2 = rect2.y + rect2.height / 2;
  12274. if (mid1 <= top2 && mid2 >= bot1) {
  12275. return -1;
  12276. }
  12277. if (mid2 <= top1 && mid1 >= bot2) {
  12278. return +1;
  12279. }
  12280. const centerX1 = rect1.x + rect1.width / 2;
  12281. const centerX2 = rect2.x + rect2.width / 2;
  12282. return centerX1 - centerX2;
  12283. }
  12284. enable() {
  12285. if (this.#enabled) {
  12286. throw new Error("TextAccessibilityManager is already enabled.");
  12287. }
  12288. if (!this.#textChildren) {
  12289. throw new Error("Text divs and strings have not been set.");
  12290. }
  12291. this.#enabled = true;
  12292. this.#textChildren = this.#textChildren.slice();
  12293. this.#textChildren.sort(
  12294. TextAccessibilityManager.#compareElementPositions
  12295. );
  12296. if (this.#textNodes.size > 0) {
  12297. const textChildren = this.#textChildren;
  12298. for (const [id, nodeIndex] of this.#textNodes) {
  12299. const element = document.getElementById(id);
  12300. if (!element) {
  12301. this.#textNodes.delete(id);
  12302. continue;
  12303. }
  12304. this.#addIdToAriaOwns(id, textChildren[nodeIndex]);
  12305. }
  12306. }
  12307. for (const [element, isRemovable] of this.#waitingElements) {
  12308. this.addPointerInTextLayer(element, isRemovable);
  12309. }
  12310. this.#waitingElements.clear();
  12311. }
  12312. disable() {
  12313. if (!this.#enabled) {
  12314. return;
  12315. }
  12316. this.#waitingElements.clear();
  12317. this.#textChildren = null;
  12318. this.#enabled = false;
  12319. }
  12320. removePointerInTextLayer(element) {
  12321. if (!this.#enabled) {
  12322. this.#waitingElements.delete(element);
  12323. return;
  12324. }
  12325. const children = this.#textChildren;
  12326. if (!children || children.length === 0) {
  12327. return;
  12328. }
  12329. const { id } = element;
  12330. const nodeIndex = this.#textNodes.get(id);
  12331. if (nodeIndex === undefined) {
  12332. return;
  12333. }
  12334. const node = children[nodeIndex];
  12335. this.#textNodes.delete(id);
  12336. let owns = node.getAttribute("aria-owns");
  12337. if (owns?.includes(id)) {
  12338. owns = owns
  12339. .split(" ")
  12340. .filter((x) => x !== id)
  12341. .join(" ");
  12342. if (owns) {
  12343. node.setAttribute("aria-owns", owns);
  12344. } else {
  12345. node.removeAttribute("aria-owns");
  12346. node.setAttribute("role", "presentation");
  12347. }
  12348. }
  12349. }
  12350. #addIdToAriaOwns(id, node) {
  12351. const owns = node.getAttribute("aria-owns");
  12352. if (!owns?.includes(id)) {
  12353. node.setAttribute("aria-owns", owns ? `${owns} ${id}` : id);
  12354. }
  12355. node.removeAttribute("role");
  12356. }
  12357. addPointerInTextLayer(element, isRemovable) {
  12358. const { id } = element;
  12359. if (!id) {
  12360. return;
  12361. }
  12362. if (!this.#enabled) {
  12363. this.#waitingElements.set(element, isRemovable);
  12364. return;
  12365. }
  12366. if (isRemovable) {
  12367. this.removePointerInTextLayer(element);
  12368. }
  12369. const children = this.#textChildren;
  12370. if (!children || children.length === 0) {
  12371. return;
  12372. }
  12373. const index = (0, _ui_utils.binarySearchFirstItem)(
  12374. children,
  12375. (node) =>
  12376. TextAccessibilityManager.#compareElementPositions(element, node) <
  12377. 0
  12378. );
  12379. const nodeIndex = Math.max(0, index - 1);
  12380. this.#addIdToAriaOwns(id, children[nodeIndex]);
  12381. this.#textNodes.set(id, nodeIndex);
  12382. }
  12383. moveElementInDOM(container, element, contentElement, isRemovable) {
  12384. this.addPointerInTextLayer(contentElement, isRemovable);
  12385. if (!container.hasChildNodes()) {
  12386. container.append(element);
  12387. return;
  12388. }
  12389. const children = Array.from(container.childNodes).filter(
  12390. (node) => node !== element
  12391. );
  12392. if (children.length === 0) {
  12393. return;
  12394. }
  12395. const elementToCompare = contentElement || element;
  12396. const index = (0, _ui_utils.binarySearchFirstItem)(
  12397. children,
  12398. (node) =>
  12399. TextAccessibilityManager.#compareElementPositions(
  12400. elementToCompare,
  12401. node
  12402. ) < 0
  12403. );
  12404. if (index === 0) {
  12405. children[0].before(element);
  12406. } else {
  12407. children[index - 1].after(element);
  12408. }
  12409. }
  12410. }
  12411. exports.TextAccessibilityManager = TextAccessibilityManager;
  12412. /***/
  12413. },
  12414. /* 36 */
  12415. /***/ (__unused_webpack_module, exports) => {
  12416. Object.defineProperty(exports, "__esModule", {
  12417. value: true,
  12418. });
  12419. exports.TextHighlighter = void 0;
  12420. class TextHighlighter {
  12421. constructor({ findController, eventBus, pageIndex }) {
  12422. this.findController = findController;
  12423. this.matches = [];
  12424. this.eventBus = eventBus;
  12425. this.pageIdx = pageIndex;
  12426. this._onUpdateTextLayerMatches = null;
  12427. this.textDivs = null;
  12428. this.textContentItemsStr = null;
  12429. this.enabled = false;
  12430. }
  12431. setTextMapping(divs, texts) {
  12432. this.textDivs = divs;
  12433. this.textContentItemsStr = texts;
  12434. }
  12435. enable() {
  12436. if (!this.textDivs || !this.textContentItemsStr) {
  12437. throw new Error("Text divs and strings have not been set.");
  12438. }
  12439. if (this.enabled) {
  12440. throw new Error("TextHighlighter is already enabled.");
  12441. }
  12442. this.enabled = true;
  12443. if (!this._onUpdateTextLayerMatches) {
  12444. this._onUpdateTextLayerMatches = (evt) => {
  12445. if (evt.pageIndex === this.pageIdx || evt.pageIndex === -1) {
  12446. this._updateMatches();
  12447. }
  12448. };
  12449. this.eventBus._on(
  12450. "updatetextlayermatches",
  12451. this._onUpdateTextLayerMatches
  12452. );
  12453. }
  12454. this._updateMatches();
  12455. }
  12456. disable() {
  12457. if (!this.enabled) {
  12458. return;
  12459. }
  12460. this.enabled = false;
  12461. if (this._onUpdateTextLayerMatches) {
  12462. this.eventBus._off(
  12463. "updatetextlayermatches",
  12464. this._onUpdateTextLayerMatches
  12465. );
  12466. this._onUpdateTextLayerMatches = null;
  12467. }
  12468. this._updateMatches(true);
  12469. }
  12470. _convertMatches(matches, matchesLength) {
  12471. if (!matches) {
  12472. return [];
  12473. }
  12474. const { textContentItemsStr } = this;
  12475. let i = 0,
  12476. iIndex = 0;
  12477. const end = textContentItemsStr.length - 1;
  12478. const result = [];
  12479. for (let m = 0, mm = matches.length; m < mm; m++) {
  12480. let matchIdx = matches[m];
  12481. while (
  12482. i !== end &&
  12483. matchIdx >= iIndex + textContentItemsStr[i].length
  12484. ) {
  12485. iIndex += textContentItemsStr[i].length;
  12486. i++;
  12487. }
  12488. if (i === textContentItemsStr.length) {
  12489. console.error("Could not find a matching mapping");
  12490. }
  12491. const match = {
  12492. begin: {
  12493. divIdx: i,
  12494. offset: matchIdx - iIndex,
  12495. },
  12496. };
  12497. matchIdx += matchesLength[m];
  12498. while (
  12499. i !== end &&
  12500. matchIdx > iIndex + textContentItemsStr[i].length
  12501. ) {
  12502. iIndex += textContentItemsStr[i].length;
  12503. i++;
  12504. }
  12505. match.end = {
  12506. divIdx: i,
  12507. offset: matchIdx - iIndex,
  12508. };
  12509. result.push(match);
  12510. }
  12511. return result;
  12512. }
  12513. _renderMatches(matches) {
  12514. if (matches.length === 0) {
  12515. return;
  12516. }
  12517. const { findController, pageIdx } = this;
  12518. const { textContentItemsStr, textDivs } = this;
  12519. const isSelectedPage = pageIdx === findController.selected.pageIdx;
  12520. const selectedMatchIdx = findController.selected.matchIdx;
  12521. const highlightAll = findController.state.highlightAll;
  12522. let prevEnd = null;
  12523. const infinity = {
  12524. divIdx: -1,
  12525. offset: undefined,
  12526. };
  12527. function beginText(begin, className) {
  12528. const divIdx = begin.divIdx;
  12529. textDivs[divIdx].textContent = "";
  12530. return appendTextToDiv(divIdx, 0, begin.offset, className);
  12531. }
  12532. function appendTextToDiv(divIdx, fromOffset, toOffset, className) {
  12533. let div = textDivs[divIdx];
  12534. if (div.nodeType === Node.TEXT_NODE) {
  12535. const span = document.createElement("span");
  12536. div.before(span);
  12537. span.append(div);
  12538. textDivs[divIdx] = span;
  12539. div = span;
  12540. }
  12541. const content = textContentItemsStr[divIdx].substring(
  12542. fromOffset,
  12543. toOffset
  12544. );
  12545. const node = document.createTextNode(content);
  12546. if (className) {
  12547. const span = document.createElement("span");
  12548. span.className = `${className} appended`;
  12549. span.append(node);
  12550. div.append(span);
  12551. return className.includes("selected") ? span.offsetLeft : 0;
  12552. }
  12553. div.append(node);
  12554. return 0;
  12555. }
  12556. let i0 = selectedMatchIdx,
  12557. i1 = i0 + 1;
  12558. if (highlightAll) {
  12559. i0 = 0;
  12560. i1 = matches.length;
  12561. } else if (!isSelectedPage) {
  12562. return;
  12563. }
  12564. for (let i = i0; i < i1; i++) {
  12565. const match = matches[i];
  12566. const begin = match.begin;
  12567. const end = match.end;
  12568. const isSelected = isSelectedPage && i === selectedMatchIdx;
  12569. const highlightSuffix = isSelected ? " selected" : "";
  12570. let selectedLeft = 0;
  12571. if (!prevEnd || begin.divIdx !== prevEnd.divIdx) {
  12572. if (prevEnd !== null) {
  12573. appendTextToDiv(
  12574. prevEnd.divIdx,
  12575. prevEnd.offset,
  12576. infinity.offset
  12577. );
  12578. }
  12579. beginText(begin);
  12580. } else {
  12581. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, begin.offset);
  12582. }
  12583. if (begin.divIdx === end.divIdx) {
  12584. selectedLeft = appendTextToDiv(
  12585. begin.divIdx,
  12586. begin.offset,
  12587. end.offset,
  12588. "highlight" + highlightSuffix
  12589. );
  12590. } else {
  12591. selectedLeft = appendTextToDiv(
  12592. begin.divIdx,
  12593. begin.offset,
  12594. infinity.offset,
  12595. "highlight begin" + highlightSuffix
  12596. );
  12597. for (let n0 = begin.divIdx + 1, n1 = end.divIdx; n0 < n1; n0++) {
  12598. textDivs[n0].className = "highlight middle" + highlightSuffix;
  12599. }
  12600. beginText(end, "highlight end" + highlightSuffix);
  12601. }
  12602. prevEnd = end;
  12603. if (isSelected) {
  12604. findController.scrollMatchIntoView({
  12605. element: textDivs[begin.divIdx],
  12606. selectedLeft,
  12607. pageIndex: pageIdx,
  12608. matchIndex: selectedMatchIdx,
  12609. });
  12610. }
  12611. }
  12612. if (prevEnd) {
  12613. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset);
  12614. }
  12615. }
  12616. _updateMatches(reset = false) {
  12617. if (!this.enabled && !reset) {
  12618. return;
  12619. }
  12620. const { findController, matches, pageIdx } = this;
  12621. const { textContentItemsStr, textDivs } = this;
  12622. let clearedUntilDivIdx = -1;
  12623. for (const match of matches) {
  12624. const begin = Math.max(clearedUntilDivIdx, match.begin.divIdx);
  12625. for (let n = begin, end = match.end.divIdx; n <= end; n++) {
  12626. const div = textDivs[n];
  12627. div.textContent = textContentItemsStr[n];
  12628. div.className = "";
  12629. }
  12630. clearedUntilDivIdx = match.end.divIdx + 1;
  12631. }
  12632. if (!findController?.highlightMatches || reset) {
  12633. return;
  12634. }
  12635. const pageMatches = findController.pageMatches[pageIdx] || null;
  12636. const pageMatchesLength =
  12637. findController.pageMatchesLength[pageIdx] || null;
  12638. this.matches = this._convertMatches(pageMatches, pageMatchesLength);
  12639. this._renderMatches(this.matches);
  12640. }
  12641. }
  12642. exports.TextHighlighter = TextHighlighter;
  12643. /***/
  12644. },
  12645. /* 37 */
  12646. /***/ (__unused_webpack_module, exports, __webpack_require__) => {
  12647. Object.defineProperty(exports, "__esModule", {
  12648. value: true,
  12649. });
  12650. exports.TextLayerBuilder = void 0;
  12651. var _pdfjsLib = __webpack_require__(4);
  12652. class TextLayerBuilder {
  12653. #rotation = 0;
  12654. #scale = 0;
  12655. #textContentSource = null;
  12656. constructor({
  12657. highlighter = null,
  12658. accessibilityManager = null,
  12659. isOffscreenCanvasSupported = true,
  12660. }) {
  12661. this.textContentItemsStr = [];
  12662. this.renderingDone = false;
  12663. this.textDivs = [];
  12664. this.textDivProperties = new WeakMap();
  12665. this.textLayerRenderTask = null;
  12666. this.highlighter = highlighter;
  12667. this.accessibilityManager = accessibilityManager;
  12668. this.isOffscreenCanvasSupported = isOffscreenCanvasSupported;
  12669. this.div = document.createElement("div");
  12670. this.div.className = "textLayer";
  12671. this.hide();
  12672. }
  12673. #finishRendering() {
  12674. this.renderingDone = true;
  12675. const endOfContent = document.createElement("div");
  12676. endOfContent.className = "endOfContent";
  12677. this.div.append(endOfContent);
  12678. this.#bindMouse();
  12679. }
  12680. get numTextDivs() {
  12681. return this.textDivs.length;
  12682. }
  12683. async render(viewport) {
  12684. if (!this.#textContentSource) {
  12685. throw new Error('No "textContentSource" parameter specified.');
  12686. }
  12687. const scale = viewport.scale * (globalThis.devicePixelRatio || 1);
  12688. const { rotation } = viewport;
  12689. if (this.renderingDone) {
  12690. const mustRotate = rotation !== this.#rotation;
  12691. const mustRescale = scale !== this.#scale;
  12692. if (mustRotate || mustRescale) {
  12693. this.hide();
  12694. (0, _pdfjsLib.updateTextLayer)({
  12695. container: this.div,
  12696. viewport,
  12697. textDivs: this.textDivs,
  12698. textDivProperties: this.textDivProperties,
  12699. isOffscreenCanvasSupported: this.isOffscreenCanvasSupported,
  12700. mustRescale,
  12701. mustRotate,
  12702. });
  12703. this.#scale = scale;
  12704. this.#rotation = rotation;
  12705. }
  12706. this.show();
  12707. return;
  12708. }
  12709. this.cancel();
  12710. this.highlighter?.setTextMapping(
  12711. this.textDivs,
  12712. this.textContentItemsStr
  12713. );
  12714. this.accessibilityManager?.setTextMapping(this.textDivs);
  12715. this.textLayerRenderTask = (0, _pdfjsLib.renderTextLayer)({
  12716. textContentSource: this.#textContentSource,
  12717. container: this.div,
  12718. viewport,
  12719. textDivs: this.textDivs,
  12720. textDivProperties: this.textDivProperties,
  12721. textContentItemsStr: this.textContentItemsStr,
  12722. isOffscreenCanvasSupported: this.isOffscreenCanvasSupported,
  12723. });
  12724. await this.textLayerRenderTask.promise;
  12725. this.#finishRendering();
  12726. this.#scale = scale;
  12727. this.#rotation = rotation;
  12728. this.show();
  12729. this.accessibilityManager?.enable();
  12730. }
  12731. hide() {
  12732. if (!this.div.hidden) {
  12733. this.highlighter?.disable();
  12734. this.div.hidden = true;
  12735. }
  12736. }
  12737. show() {
  12738. if (this.div.hidden && this.renderingDone) {
  12739. this.div.hidden = false;
  12740. this.highlighter?.enable();
  12741. }
  12742. }
  12743. cancel() {
  12744. if (this.textLayerRenderTask) {
  12745. this.textLayerRenderTask.cancel();
  12746. this.textLayerRenderTask = null;
  12747. }
  12748. this.highlighter?.disable();
  12749. this.accessibilityManager?.disable();
  12750. this.textContentItemsStr.length = 0;
  12751. this.textDivs.length = 0;
  12752. this.textDivProperties = new WeakMap();
  12753. }
  12754. setTextContentSource(source) {
  12755. this.cancel();
  12756. this.#textContentSource = source;
  12757. }
  12758. #bindMouse() {
  12759. const { div } = this;
  12760. div.addEventListener("mousedown", (evt) => {
  12761. const end = div.querySelector(".endOfContent");
  12762. if (!end) {
  12763. return;
  12764. }
  12765. let adjustTop = evt.target !== div;
  12766. adjustTop &&=
  12767. getComputedStyle(end).getPropertyValue("-moz-user-select") !==
  12768. "none";
  12769. if (adjustTop) {
  12770. const divBounds = div.getBoundingClientRect();
  12771. const r = Math.max(
  12772. 0,
  12773. (evt.pageY - divBounds.top) / divBounds.height
  12774. );
  12775. end.style.top = (r * 100).toFixed(2) + "%";
  12776. }
  12777. end.classList.add("active");
  12778. });
  12779. div.addEventListener("mouseup", () => {
  12780. const end = div.querySelector(".endOfContent");
  12781. if (!end) {
  12782. return;
  12783. }
  12784. end.style.top = "";
  12785. end.classList.remove("active");
  12786. });
  12787. }
  12788. }
  12789. exports.TextLayerBuilder = TextLayerBuilder;
  12790. /***/
  12791. },
  12792. /* 38 */
  12793. /***/ (__unused_webpack_module, exports, __webpack_require__) => {
  12794. Object.defineProperty(exports, "__esModule", {
  12795. value: true,
  12796. });
  12797. exports.XfaLayerBuilder = void 0;
  12798. var _pdfjsLib = __webpack_require__(4);
  12799. class XfaLayerBuilder {
  12800. constructor({
  12801. pageDiv,
  12802. pdfPage,
  12803. annotationStorage = null,
  12804. linkService,
  12805. xfaHtml = null,
  12806. }) {
  12807. this.pageDiv = pageDiv;
  12808. this.pdfPage = pdfPage;
  12809. this.annotationStorage = annotationStorage;
  12810. this.linkService = linkService;
  12811. this.xfaHtml = xfaHtml;
  12812. this.div = null;
  12813. this._cancelled = false;
  12814. }
  12815. async render(viewport, intent = "display") {
  12816. if (intent === "print") {
  12817. const parameters = {
  12818. viewport: viewport.clone({
  12819. dontFlip: true,
  12820. }),
  12821. div: this.div,
  12822. xfaHtml: this.xfaHtml,
  12823. annotationStorage: this.annotationStorage,
  12824. linkService: this.linkService,
  12825. intent,
  12826. };
  12827. const div = document.createElement("div");
  12828. this.pageDiv.append(div);
  12829. parameters.div = div;
  12830. return _pdfjsLib.XfaLayer.render(parameters);
  12831. }
  12832. const xfaHtml = await this.pdfPage.getXfa();
  12833. if (this._cancelled || !xfaHtml) {
  12834. return {
  12835. textDivs: [],
  12836. };
  12837. }
  12838. const parameters = {
  12839. viewport: viewport.clone({
  12840. dontFlip: true,
  12841. }),
  12842. div: this.div,
  12843. xfaHtml,
  12844. annotationStorage: this.annotationStorage,
  12845. linkService: this.linkService,
  12846. intent,
  12847. };
  12848. if (this.div) {
  12849. return _pdfjsLib.XfaLayer.update(parameters);
  12850. }
  12851. this.div = document.createElement("div");
  12852. this.pageDiv.append(this.div);
  12853. parameters.div = this.div;
  12854. return _pdfjsLib.XfaLayer.render(parameters);
  12855. }
  12856. cancel() {
  12857. this._cancelled = true;
  12858. }
  12859. hide() {
  12860. if (!this.div) {
  12861. return;
  12862. }
  12863. this.div.hidden = true;
  12864. }
  12865. }
  12866. exports.XfaLayerBuilder = XfaLayerBuilder;
  12867. /***/
  12868. },
  12869. /* 39 */
  12870. /***/ (__unused_webpack_module, exports, __webpack_require__) => {
  12871. Object.defineProperty(exports, "__esModule", {
  12872. value: true,
  12873. });
  12874. exports.SecondaryToolbar = void 0;
  12875. var _ui_utils = __webpack_require__(3);
  12876. var _pdf_viewer = __webpack_require__(29);
  12877. class SecondaryToolbar {
  12878. constructor(options, eventBus, externalServices) {
  12879. this.toolbar = options.toolbar;
  12880. this.toggleButton = options.toggleButton;
  12881. this.buttons = [
  12882. {
  12883. element: options.presentationModeButton,
  12884. eventName: "presentationmode",
  12885. close: true,
  12886. },
  12887. {
  12888. element: options.printButton,
  12889. eventName: "print",
  12890. close: true,
  12891. },
  12892. {
  12893. element: options.downloadButton,
  12894. eventName: "download",
  12895. close: true,
  12896. },
  12897. {
  12898. element: options.viewBookmarkButton,
  12899. eventName: null,
  12900. close: true,
  12901. },
  12902. {
  12903. element: options.firstPageButton,
  12904. eventName: "firstpage",
  12905. close: true,
  12906. },
  12907. {
  12908. element: options.lastPageButton,
  12909. eventName: "lastpage",
  12910. close: true,
  12911. },
  12912. {
  12913. element: options.pageRotateCwButton,
  12914. eventName: "rotatecw",
  12915. close: false,
  12916. },
  12917. {
  12918. element: options.pageRotateCcwButton,
  12919. eventName: "rotateccw",
  12920. close: false,
  12921. },
  12922. {
  12923. element: options.cursorSelectToolButton,
  12924. eventName: "switchcursortool",
  12925. eventDetails: {
  12926. tool: _ui_utils.CursorTool.SELECT,
  12927. },
  12928. close: true,
  12929. },
  12930. {
  12931. element: options.cursorHandToolButton,
  12932. eventName: "switchcursortool",
  12933. eventDetails: {
  12934. tool: _ui_utils.CursorTool.HAND,
  12935. },
  12936. close: true,
  12937. },
  12938. {
  12939. element: options.scrollPageButton,
  12940. eventName: "switchscrollmode",
  12941. eventDetails: {
  12942. mode: _ui_utils.ScrollMode.PAGE,
  12943. },
  12944. close: true,
  12945. },
  12946. {
  12947. element: options.scrollVerticalButton,
  12948. eventName: "switchscrollmode",
  12949. eventDetails: {
  12950. mode: _ui_utils.ScrollMode.VERTICAL,
  12951. },
  12952. close: true,
  12953. },
  12954. {
  12955. element: options.scrollHorizontalButton,
  12956. eventName: "switchscrollmode",
  12957. eventDetails: {
  12958. mode: _ui_utils.ScrollMode.HORIZONTAL,
  12959. },
  12960. close: true,
  12961. },
  12962. {
  12963. element: options.scrollWrappedButton,
  12964. eventName: "switchscrollmode",
  12965. eventDetails: {
  12966. mode: _ui_utils.ScrollMode.WRAPPED,
  12967. },
  12968. close: true,
  12969. },
  12970. {
  12971. element: options.spreadNoneButton,
  12972. eventName: "switchspreadmode",
  12973. eventDetails: {
  12974. mode: _ui_utils.SpreadMode.NONE,
  12975. },
  12976. close: true,
  12977. },
  12978. {
  12979. element: options.spreadOddButton,
  12980. eventName: "switchspreadmode",
  12981. eventDetails: {
  12982. mode: _ui_utils.SpreadMode.ODD,
  12983. },
  12984. close: true,
  12985. },
  12986. {
  12987. element: options.spreadEvenButton,
  12988. eventName: "switchspreadmode",
  12989. eventDetails: {
  12990. mode: _ui_utils.SpreadMode.EVEN,
  12991. },
  12992. close: true,
  12993. },
  12994. {
  12995. element: options.documentPropertiesButton,
  12996. eventName: "documentproperties",
  12997. close: true,
  12998. },
  12999. ];
  13000. this.buttons.push({
  13001. element: options.openFileButton,
  13002. eventName: "openfile",
  13003. close: true,
  13004. });
  13005. this.items = {
  13006. firstPage: options.firstPageButton,
  13007. lastPage: options.lastPageButton,
  13008. pageRotateCw: options.pageRotateCwButton,
  13009. pageRotateCcw: options.pageRotateCcwButton,
  13010. };
  13011. this.eventBus = eventBus;
  13012. this.externalServices = externalServices;
  13013. this.opened = false;
  13014. this.#bindClickListeners();
  13015. this.#bindCursorToolsListener(options);
  13016. this.#bindScrollModeListener(options);
  13017. this.#bindSpreadModeListener(options);
  13018. this.reset();
  13019. }
  13020. get isOpen() {
  13021. return this.opened;
  13022. }
  13023. setPageNumber(pageNumber) {
  13024. this.pageNumber = pageNumber;
  13025. this.#updateUIState();
  13026. }
  13027. setPagesCount(pagesCount) {
  13028. this.pagesCount = pagesCount;
  13029. this.#updateUIState();
  13030. }
  13031. reset() {
  13032. this.pageNumber = 0;
  13033. this.pagesCount = 0;
  13034. this.#updateUIState();
  13035. this.eventBus.dispatch("secondarytoolbarreset", {
  13036. source: this,
  13037. });
  13038. }
  13039. #updateUIState() {
  13040. this.items.firstPage.disabled = this.pageNumber <= 1;
  13041. this.items.lastPage.disabled = this.pageNumber >= this.pagesCount;
  13042. this.items.pageRotateCw.disabled = this.pagesCount === 0;
  13043. this.items.pageRotateCcw.disabled = this.pagesCount === 0;
  13044. }
  13045. #bindClickListeners() {
  13046. this.toggleButton.addEventListener("click", this.toggle.bind(this));
  13047. for (const { element, eventName, close, eventDetails } of this
  13048. .buttons) {
  13049. element.addEventListener("click", (evt) => {
  13050. if (eventName !== null) {
  13051. this.eventBus.dispatch(eventName, {
  13052. source: this,
  13053. ...eventDetails,
  13054. });
  13055. }
  13056. if (close) {
  13057. this.close();
  13058. }
  13059. this.externalServices.reportTelemetry({
  13060. type: "buttons",
  13061. data: {
  13062. id: element.id,
  13063. },
  13064. });
  13065. });
  13066. }
  13067. }
  13068. #bindCursorToolsListener({
  13069. cursorSelectToolButton,
  13070. cursorHandToolButton,
  13071. }) {
  13072. this.eventBus._on("cursortoolchanged", function ({ tool }) {
  13073. const isSelect = tool === _ui_utils.CursorTool.SELECT,
  13074. isHand = tool === _ui_utils.CursorTool.HAND;
  13075. cursorSelectToolButton.classList.toggle("toggled", isSelect);
  13076. cursorHandToolButton.classList.toggle("toggled", isHand);
  13077. cursorSelectToolButton.setAttribute("aria-checked", isSelect);
  13078. cursorHandToolButton.setAttribute("aria-checked", isHand);
  13079. });
  13080. }
  13081. #bindScrollModeListener({
  13082. scrollPageButton,
  13083. scrollVerticalButton,
  13084. scrollHorizontalButton,
  13085. scrollWrappedButton,
  13086. spreadNoneButton,
  13087. spreadOddButton,
  13088. spreadEvenButton,
  13089. }) {
  13090. const scrollModeChanged = ({ mode }) => {
  13091. const isPage = mode === _ui_utils.ScrollMode.PAGE,
  13092. isVertical = mode === _ui_utils.ScrollMode.VERTICAL,
  13093. isHorizontal = mode === _ui_utils.ScrollMode.HORIZONTAL,
  13094. isWrapped = mode === _ui_utils.ScrollMode.WRAPPED;
  13095. scrollPageButton.classList.toggle("toggled", isPage);
  13096. scrollVerticalButton.classList.toggle("toggled", isVertical);
  13097. scrollHorizontalButton.classList.toggle("toggled", isHorizontal);
  13098. scrollWrappedButton.classList.toggle("toggled", isWrapped);
  13099. scrollPageButton.setAttribute("aria-checked", isPage);
  13100. scrollVerticalButton.setAttribute("aria-checked", isVertical);
  13101. scrollHorizontalButton.setAttribute("aria-checked", isHorizontal);
  13102. scrollWrappedButton.setAttribute("aria-checked", isWrapped);
  13103. const forceScrollModePage =
  13104. this.pagesCount >
  13105. _pdf_viewer.PagesCountLimit.FORCE_SCROLL_MODE_PAGE;
  13106. scrollPageButton.disabled = forceScrollModePage;
  13107. scrollVerticalButton.disabled = forceScrollModePage;
  13108. scrollHorizontalButton.disabled = forceScrollModePage;
  13109. scrollWrappedButton.disabled = forceScrollModePage;
  13110. spreadNoneButton.disabled = isHorizontal;
  13111. spreadOddButton.disabled = isHorizontal;
  13112. spreadEvenButton.disabled = isHorizontal;
  13113. };
  13114. this.eventBus._on("scrollmodechanged", scrollModeChanged);
  13115. this.eventBus._on("secondarytoolbarreset", (evt) => {
  13116. if (evt.source === this) {
  13117. scrollModeChanged({
  13118. mode: _ui_utils.ScrollMode.VERTICAL,
  13119. });
  13120. }
  13121. });
  13122. }
  13123. #bindSpreadModeListener({
  13124. spreadNoneButton,
  13125. spreadOddButton,
  13126. spreadEvenButton,
  13127. }) {
  13128. function spreadModeChanged({ mode }) {
  13129. const isNone = mode === _ui_utils.SpreadMode.NONE,
  13130. isOdd = mode === _ui_utils.SpreadMode.ODD,
  13131. isEven = mode === _ui_utils.SpreadMode.EVEN;
  13132. spreadNoneButton.classList.toggle("toggled", isNone);
  13133. spreadOddButton.classList.toggle("toggled", isOdd);
  13134. spreadEvenButton.classList.toggle("toggled", isEven);
  13135. spreadNoneButton.setAttribute("aria-checked", isNone);
  13136. spreadOddButton.setAttribute("aria-checked", isOdd);
  13137. spreadEvenButton.setAttribute("aria-checked", isEven);
  13138. }
  13139. this.eventBus._on("spreadmodechanged", spreadModeChanged);
  13140. this.eventBus._on("secondarytoolbarreset", (evt) => {
  13141. if (evt.source === this) {
  13142. spreadModeChanged({
  13143. mode: _ui_utils.SpreadMode.NONE,
  13144. });
  13145. }
  13146. });
  13147. }
  13148. open() {
  13149. if (this.opened) {
  13150. return;
  13151. }
  13152. this.opened = true;
  13153. this.toggleButton.classList.add("toggled");
  13154. this.toggleButton.setAttribute("aria-expanded", "true");
  13155. this.toolbar.classList.remove("hidden");
  13156. }
  13157. close() {
  13158. if (!this.opened) {
  13159. return;
  13160. }
  13161. this.opened = false;
  13162. this.toolbar.classList.add("hidden");
  13163. this.toggleButton.classList.remove("toggled");
  13164. this.toggleButton.setAttribute("aria-expanded", "false");
  13165. }
  13166. toggle() {
  13167. if (this.opened) {
  13168. this.close();
  13169. } else {
  13170. this.open();
  13171. }
  13172. }
  13173. }
  13174. exports.SecondaryToolbar = SecondaryToolbar;
  13175. /***/
  13176. },
  13177. /* 40 */
  13178. /***/ (__unused_webpack_module, exports, __webpack_require__) => {
  13179. Object.defineProperty(exports, "__esModule", {
  13180. value: true,
  13181. });
  13182. exports.Toolbar = void 0;
  13183. var _ui_utils = __webpack_require__(3);
  13184. var _pdfjsLib = __webpack_require__(4);
  13185. const PAGE_NUMBER_LOADING_INDICATOR = "visiblePageIsLoading";
  13186. class Toolbar {
  13187. #wasLocalized = false;
  13188. constructor(options, eventBus, l10n) {
  13189. this.toolbar = options.container;
  13190. this.eventBus = eventBus;
  13191. this.l10n = l10n;
  13192. this.buttons = [
  13193. {
  13194. element: options.previous,
  13195. eventName: "previouspage",
  13196. },
  13197. {
  13198. element: options.next,
  13199. eventName: "nextpage",
  13200. },
  13201. {
  13202. element: options.zoomIn,
  13203. eventName: "zoomin",
  13204. },
  13205. {
  13206. element: options.zoomOut,
  13207. eventName: "zoomout",
  13208. },
  13209. {
  13210. element: options.print,
  13211. eventName: "print",
  13212. },
  13213. {
  13214. element: options.download,
  13215. eventName: "download",
  13216. },
  13217. {
  13218. element: options.editorFreeTextButton,
  13219. eventName: "switchannotationeditormode",
  13220. eventDetails: {
  13221. get mode() {
  13222. const { classList } = options.editorFreeTextButton;
  13223. return classList.contains("toggled")
  13224. ? _pdfjsLib.AnnotationEditorType.NONE
  13225. : _pdfjsLib.AnnotationEditorType.FREETEXT;
  13226. },
  13227. },
  13228. },
  13229. {
  13230. element: options.editorInkButton,
  13231. eventName: "switchannotationeditormode",
  13232. eventDetails: {
  13233. get mode() {
  13234. const { classList } = options.editorInkButton;
  13235. return classList.contains("toggled")
  13236. ? _pdfjsLib.AnnotationEditorType.NONE
  13237. : _pdfjsLib.AnnotationEditorType.INK;
  13238. },
  13239. },
  13240. },
  13241. ];
  13242. this.buttons.push({
  13243. element: options.openFile,
  13244. eventName: "openfile",
  13245. });
  13246. this.items = {
  13247. numPages: options.numPages,
  13248. pageNumber: options.pageNumber,
  13249. scaleSelect: options.scaleSelect,
  13250. customScaleOption: options.customScaleOption,
  13251. previous: options.previous,
  13252. next: options.next,
  13253. zoomIn: options.zoomIn,
  13254. zoomOut: options.zoomOut,
  13255. };
  13256. this.#bindListeners(options);
  13257. this.reset();
  13258. }
  13259. setPageNumber(pageNumber, pageLabel) {
  13260. this.pageNumber = pageNumber;
  13261. this.pageLabel = pageLabel;
  13262. this.#updateUIState(false);
  13263. }
  13264. setPagesCount(pagesCount, hasPageLabels) {
  13265. this.pagesCount = pagesCount;
  13266. this.hasPageLabels = hasPageLabels;
  13267. this.#updateUIState(true);
  13268. }
  13269. setPageScale(pageScaleValue, pageScale) {
  13270. this.pageScaleValue = (pageScaleValue || pageScale).toString();
  13271. this.pageScale = pageScale;
  13272. this.#updateUIState(false);
  13273. }
  13274. reset() {
  13275. this.pageNumber = 0;
  13276. this.pageLabel = null;
  13277. this.hasPageLabels = false;
  13278. this.pagesCount = 0;
  13279. this.pageScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  13280. this.pageScale = _ui_utils.DEFAULT_SCALE;
  13281. this.#updateUIState(true);
  13282. this.updateLoadingIndicatorState();
  13283. this.eventBus.dispatch("toolbarreset", {
  13284. source: this,
  13285. });
  13286. }
  13287. #bindListeners(options) {
  13288. const { pageNumber, scaleSelect } = this.items;
  13289. const self = this;
  13290. for (const { element, eventName, eventDetails } of this.buttons) {
  13291. element.addEventListener("click", (evt) => {
  13292. if (eventName !== null) {
  13293. this.eventBus.dispatch(eventName, {
  13294. source: this,
  13295. ...eventDetails,
  13296. });
  13297. }
  13298. });
  13299. }
  13300. pageNumber.addEventListener("click", function () {
  13301. this.select();
  13302. });
  13303. pageNumber.addEventListener("change", function () {
  13304. self.eventBus.dispatch("pagenumberchanged", {
  13305. source: self,
  13306. value: this.value,
  13307. });
  13308. });
  13309. scaleSelect.addEventListener("change", function () {
  13310. if (this.value === "custom") {
  13311. return;
  13312. }
  13313. self.eventBus.dispatch("scalechanged", {
  13314. source: self,
  13315. value: this.value,
  13316. });
  13317. });
  13318. scaleSelect.addEventListener("click", function (evt) {
  13319. const target = evt.target;
  13320. if (
  13321. this.value === self.pageScaleValue &&
  13322. target.tagName.toUpperCase() === "OPTION"
  13323. ) {
  13324. this.blur();
  13325. }
  13326. });
  13327. scaleSelect.oncontextmenu = _ui_utils.noContextMenuHandler;
  13328. this.eventBus._on("localized", () => {
  13329. this.#wasLocalized = true;
  13330. this.#adjustScaleWidth();
  13331. this.#updateUIState(true);
  13332. });
  13333. this.#bindEditorToolsListener(options);
  13334. }
  13335. #bindEditorToolsListener({
  13336. editorFreeTextButton,
  13337. editorFreeTextParamsToolbar,
  13338. editorInkButton,
  13339. editorInkParamsToolbar,
  13340. }) {
  13341. const editorModeChanged = (evt, disableButtons = false) => {
  13342. const editorButtons = [
  13343. {
  13344. mode: _pdfjsLib.AnnotationEditorType.FREETEXT,
  13345. button: editorFreeTextButton,
  13346. toolbar: editorFreeTextParamsToolbar,
  13347. },
  13348. {
  13349. mode: _pdfjsLib.AnnotationEditorType.INK,
  13350. button: editorInkButton,
  13351. toolbar: editorInkParamsToolbar,
  13352. },
  13353. ];
  13354. for (const { mode, button, toolbar } of editorButtons) {
  13355. const checked = mode === evt.mode;
  13356. button.classList.toggle("toggled", checked);
  13357. button.setAttribute("aria-checked", checked);
  13358. button.disabled = disableButtons;
  13359. toolbar?.classList.toggle("hidden", !checked);
  13360. }
  13361. };
  13362. this.eventBus._on("annotationeditormodechanged", editorModeChanged);
  13363. this.eventBus._on("toolbarreset", (evt) => {
  13364. if (evt.source === this) {
  13365. editorModeChanged(
  13366. {
  13367. mode: _pdfjsLib.AnnotationEditorType.NONE,
  13368. },
  13369. true
  13370. );
  13371. }
  13372. });
  13373. }
  13374. #updateUIState(resetNumPages = false) {
  13375. if (!this.#wasLocalized) {
  13376. return;
  13377. }
  13378. const { pageNumber, pagesCount, pageScaleValue, pageScale, items } =
  13379. this;
  13380. if (resetNumPages) {
  13381. if (this.hasPageLabels) {
  13382. items.pageNumber.type = "text";
  13383. } else {
  13384. items.pageNumber.type = "number";
  13385. this.l10n
  13386. .get("of_pages", {
  13387. pagesCount,
  13388. })
  13389. .then((msg) => {
  13390. items.numPages.textContent = msg;
  13391. });
  13392. }
  13393. items.pageNumber.max = pagesCount;
  13394. }
  13395. if (this.hasPageLabels) {
  13396. items.pageNumber.value = this.pageLabel;
  13397. this.l10n
  13398. .get("page_of_pages", {
  13399. pageNumber,
  13400. pagesCount,
  13401. })
  13402. .then((msg) => {
  13403. items.numPages.textContent = msg;
  13404. });
  13405. } else {
  13406. items.pageNumber.value = pageNumber;
  13407. }
  13408. items.previous.disabled = pageNumber <= 1;
  13409. items.next.disabled = pageNumber >= pagesCount;
  13410. items.zoomOut.disabled = pageScale <= _ui_utils.MIN_SCALE;
  13411. items.zoomIn.disabled = pageScale >= _ui_utils.MAX_SCALE;
  13412. this.l10n
  13413. .get("page_scale_percent", {
  13414. scale: Math.round(pageScale * 10000) / 100,
  13415. })
  13416. .then((msg) => {
  13417. let predefinedValueFound = false;
  13418. for (const option of items.scaleSelect.options) {
  13419. if (option.value !== pageScaleValue) {
  13420. option.selected = false;
  13421. continue;
  13422. }
  13423. option.selected = true;
  13424. predefinedValueFound = true;
  13425. }
  13426. if (!predefinedValueFound) {
  13427. items.customScaleOption.textContent = msg;
  13428. items.customScaleOption.selected = true;
  13429. }
  13430. });
  13431. }
  13432. updateLoadingIndicatorState(loading = false) {
  13433. const { pageNumber } = this.items;
  13434. pageNumber.classList.toggle(PAGE_NUMBER_LOADING_INDICATOR, loading);
  13435. }
  13436. async #adjustScaleWidth() {
  13437. const { items, l10n } = this;
  13438. const predefinedValuesPromise = Promise.all([
  13439. l10n.get("page_scale_auto"),
  13440. l10n.get("page_scale_actual"),
  13441. l10n.get("page_scale_fit"),
  13442. l10n.get("page_scale_width"),
  13443. ]);
  13444. await _ui_utils.animationStarted;
  13445. const style = getComputedStyle(items.scaleSelect);
  13446. const scaleSelectWidth = parseFloat(
  13447. style.getPropertyValue("--scale-select-width")
  13448. );
  13449. const canvas = document.createElement("canvas");
  13450. const ctx = canvas.getContext("2d", {
  13451. alpha: false,
  13452. });
  13453. ctx.font = `${style.fontSize} ${style.fontFamily}`;
  13454. let maxWidth = 0;
  13455. for (const predefinedValue of await predefinedValuesPromise) {
  13456. const { width } = ctx.measureText(predefinedValue);
  13457. if (width > maxWidth) {
  13458. maxWidth = width;
  13459. }
  13460. }
  13461. maxWidth += 0.3 * scaleSelectWidth;
  13462. if (maxWidth > scaleSelectWidth) {
  13463. const container = items.scaleSelect.parentNode;
  13464. container.style.setProperty(
  13465. "--scale-select-width",
  13466. `${maxWidth}px`
  13467. );
  13468. }
  13469. canvas.width = 0;
  13470. canvas.height = 0;
  13471. }
  13472. }
  13473. exports.Toolbar = Toolbar;
  13474. /***/
  13475. },
  13476. /* 41 */
  13477. /***/ (__unused_webpack_module, exports) => {
  13478. Object.defineProperty(exports, "__esModule", {
  13479. value: true,
  13480. });
  13481. exports.ViewHistory = void 0;
  13482. const DEFAULT_VIEW_HISTORY_CACHE_SIZE = 20;
  13483. class ViewHistory {
  13484. constructor(fingerprint, cacheSize = DEFAULT_VIEW_HISTORY_CACHE_SIZE) {
  13485. this.fingerprint = fingerprint;
  13486. this.cacheSize = cacheSize;
  13487. this._initializedPromise = this._readFromStorage().then(
  13488. (databaseStr) => {
  13489. const database = JSON.parse(databaseStr || "{}");
  13490. let index = -1;
  13491. if (!Array.isArray(database.files)) {
  13492. database.files = [];
  13493. } else {
  13494. while (database.files.length >= this.cacheSize) {
  13495. database.files.shift();
  13496. }
  13497. for (let i = 0, ii = database.files.length; i < ii; i++) {
  13498. const branch = database.files[i];
  13499. if (branch.fingerprint === this.fingerprint) {
  13500. index = i;
  13501. break;
  13502. }
  13503. }
  13504. }
  13505. if (index === -1) {
  13506. index =
  13507. database.files.push({
  13508. fingerprint: this.fingerprint,
  13509. }) - 1;
  13510. }
  13511. this.file = database.files[index];
  13512. this.database = database;
  13513. }
  13514. );
  13515. }
  13516. async _writeToStorage() {
  13517. const databaseStr = JSON.stringify(this.database);
  13518. localStorage.setItem("pdfjs.history", databaseStr);
  13519. }
  13520. async _readFromStorage() {
  13521. return localStorage.getItem("pdfjs.history");
  13522. }
  13523. async set(name, val) {
  13524. await this._initializedPromise;
  13525. this.file[name] = val;
  13526. return this._writeToStorage();
  13527. }
  13528. async setMultiple(properties) {
  13529. await this._initializedPromise;
  13530. for (const name in properties) {
  13531. this.file[name] = properties[name];
  13532. }
  13533. return this._writeToStorage();
  13534. }
  13535. async get(name, defaultValue) {
  13536. await this._initializedPromise;
  13537. const val = this.file[name];
  13538. return val !== undefined ? val : defaultValue;
  13539. }
  13540. async getMultiple(properties) {
  13541. await this._initializedPromise;
  13542. const values = Object.create(null);
  13543. for (const name in properties) {
  13544. const val = this.file[name];
  13545. values[name] = val !== undefined ? val : properties[name];
  13546. }
  13547. return values;
  13548. }
  13549. }
  13550. exports.ViewHistory = ViewHistory;
  13551. /***/
  13552. },
  13553. /* 42 */
  13554. /***/ (__unused_webpack_module, exports, __webpack_require__) => {
  13555. Object.defineProperty(exports, "__esModule", {
  13556. value: true,
  13557. });
  13558. exports.BasePreferences = void 0;
  13559. var _app_options = __webpack_require__(5);
  13560. class BasePreferences {
  13561. #defaults = Object.freeze({
  13562. annotationEditorMode: 0,
  13563. annotationMode: 2,
  13564. cursorToolOnLoad: 0,
  13565. defaultZoomDelay: 400,
  13566. defaultZoomValue: "",
  13567. disablePageLabels: false,
  13568. enablePermissions: false,
  13569. enablePrintAutoRotate: true,
  13570. enableScripting: true,
  13571. externalLinkTarget: 0,
  13572. historyUpdateUrl: false,
  13573. ignoreDestinationZoom: false,
  13574. forcePageColors: false,
  13575. pageColorsBackground: "Canvas",
  13576. pageColorsForeground: "CanvasText",
  13577. pdfBugEnabled: false,
  13578. sidebarViewOnLoad: -1,
  13579. scrollModeOnLoad: -1,
  13580. spreadModeOnLoad: -1,
  13581. textLayerMode: 1,
  13582. useOnlyCssZoom: false,
  13583. viewerCssTheme: 0,
  13584. viewOnLoad: 0,
  13585. disableAutoFetch: false,
  13586. disableFontFace: false,
  13587. disableRange: false,
  13588. disableStream: false,
  13589. enableXfa: true,
  13590. renderer: "canvas",
  13591. });
  13592. #prefs = Object.create(null);
  13593. #initializedPromise = null;
  13594. constructor() {
  13595. if (this.constructor === BasePreferences) {
  13596. throw new Error("Cannot initialize BasePreferences.");
  13597. }
  13598. this.#initializedPromise = this._readFromStorage(this.#defaults).then(
  13599. (prefs) => {
  13600. for (const name in this.#defaults) {
  13601. const prefValue = prefs?.[name];
  13602. if (typeof prefValue === typeof this.#defaults[name]) {
  13603. this.#prefs[name] = prefValue;
  13604. }
  13605. }
  13606. }
  13607. );
  13608. }
  13609. async _writeToStorage(prefObj) {
  13610. throw new Error("Not implemented: _writeToStorage");
  13611. }
  13612. async _readFromStorage(prefObj) {
  13613. throw new Error("Not implemented: _readFromStorage");
  13614. }
  13615. async reset() {
  13616. await this.#initializedPromise;
  13617. const prefs = this.#prefs;
  13618. this.#prefs = Object.create(null);
  13619. return this._writeToStorage(this.#defaults).catch((reason) => {
  13620. this.#prefs = prefs;
  13621. throw reason;
  13622. });
  13623. }
  13624. async set(name, value) {
  13625. await this.#initializedPromise;
  13626. const defaultValue = this.#defaults[name],
  13627. prefs = this.#prefs;
  13628. if (defaultValue === undefined) {
  13629. throw new Error(`Set preference: "${name}" is undefined.`);
  13630. } else if (value === undefined) {
  13631. throw new Error("Set preference: no value is specified.");
  13632. }
  13633. const valueType = typeof value,
  13634. defaultType = typeof defaultValue;
  13635. if (valueType !== defaultType) {
  13636. if (valueType === "number" && defaultType === "string") {
  13637. value = value.toString();
  13638. } else {
  13639. throw new Error(
  13640. `Set preference: "${value}" is a ${valueType}, expected a ${defaultType}.`
  13641. );
  13642. }
  13643. } else {
  13644. if (valueType === "number" && !Number.isInteger(value)) {
  13645. throw new Error(`Set preference: "${value}" must be an integer.`);
  13646. }
  13647. }
  13648. this.#prefs[name] = value;
  13649. return this._writeToStorage(this.#prefs).catch((reason) => {
  13650. this.#prefs = prefs;
  13651. throw reason;
  13652. });
  13653. }
  13654. async get(name) {
  13655. await this.#initializedPromise;
  13656. const defaultValue = this.#defaults[name];
  13657. if (defaultValue === undefined) {
  13658. throw new Error(`Get preference: "${name}" is undefined.`);
  13659. }
  13660. return this.#prefs[name] ?? defaultValue;
  13661. }
  13662. async getAll() {
  13663. await this.#initializedPromise;
  13664. const obj = Object.create(null);
  13665. for (const name in this.#defaults) {
  13666. obj[name] = this.#prefs[name] ?? this.#defaults[name];
  13667. }
  13668. return obj;
  13669. }
  13670. }
  13671. exports.BasePreferences = BasePreferences;
  13672. /***/
  13673. },
  13674. /* 43 */
  13675. /***/ (__unused_webpack_module, exports, __webpack_require__) => {
  13676. Object.defineProperty(exports, "__esModule", {
  13677. value: true,
  13678. });
  13679. exports.DownloadManager = void 0;
  13680. var _pdfjsLib = __webpack_require__(4);
  13681. function download(blobUrl, filename) {
  13682. const a = document.createElement("a");
  13683. if (!a.click) {
  13684. throw new Error('DownloadManager: "a.click()" is not supported.');
  13685. }
  13686. a.href = blobUrl;
  13687. a.target = "_parent";
  13688. if ("download" in a) {
  13689. a.download = filename;
  13690. }
  13691. (document.body || document.documentElement).append(a);
  13692. a.click();
  13693. a.remove();
  13694. }
  13695. class DownloadManager {
  13696. #openBlobUrls = new WeakMap();
  13697. downloadUrl(url, filename) {
  13698. if (
  13699. !(0, _pdfjsLib.createValidAbsoluteUrl)(url, "http://example.com")
  13700. ) {
  13701. console.error(`downloadUrl - not a valid URL: ${url}`);
  13702. return;
  13703. }
  13704. download(url + "#pdfjs.action=download", filename);
  13705. }
  13706. downloadData(data, filename, contentType) {
  13707. const blobUrl = URL.createObjectURL(
  13708. new Blob([data], {
  13709. type: contentType,
  13710. })
  13711. );
  13712. download(blobUrl, filename);
  13713. }
  13714. openOrDownloadData(element, data, filename) {
  13715. const isPdfData = (0, _pdfjsLib.isPdfFile)(filename);
  13716. const contentType = isPdfData ? "application/pdf" : "";
  13717. if (isPdfData) {
  13718. let blobUrl = this.#openBlobUrls.get(element);
  13719. if (!blobUrl) {
  13720. blobUrl = URL.createObjectURL(
  13721. new Blob([data], {
  13722. type: contentType,
  13723. })
  13724. );
  13725. this.#openBlobUrls.set(element, blobUrl);
  13726. }
  13727. let viewerUrl;
  13728. viewerUrl = "?file=" + encodeURIComponent(blobUrl + "#" + filename);
  13729. try {
  13730. window.open(viewerUrl);
  13731. return true;
  13732. } catch (ex) {
  13733. console.error(`openOrDownloadData: ${ex}`);
  13734. URL.revokeObjectURL(blobUrl);
  13735. this.#openBlobUrls.delete(element);
  13736. }
  13737. }
  13738. this.downloadData(data, filename, contentType);
  13739. return false;
  13740. }
  13741. download(blob, url, filename) {
  13742. const blobUrl = URL.createObjectURL(blob);
  13743. download(blobUrl, filename);
  13744. }
  13745. }
  13746. exports.DownloadManager = DownloadManager;
  13747. /***/
  13748. },
  13749. /* 44 */
  13750. /***/ (__unused_webpack_module, exports, __webpack_require__) => {
  13751. Object.defineProperty(exports, "__esModule", {
  13752. value: true,
  13753. });
  13754. exports.GenericL10n = void 0;
  13755. __webpack_require__(45);
  13756. var _l10n_utils = __webpack_require__(30);
  13757. const webL10n = document.webL10n;
  13758. class GenericL10n {
  13759. constructor(lang) {
  13760. this._lang = lang;
  13761. this._ready = new Promise((resolve, reject) => {
  13762. webL10n.setLanguage((0, _l10n_utils.fixupLangCode)(lang), () => {
  13763. resolve(webL10n);
  13764. });
  13765. });
  13766. }
  13767. async getLanguage() {
  13768. const l10n = await this._ready;
  13769. return l10n.getLanguage();
  13770. }
  13771. async getDirection() {
  13772. const l10n = await this._ready;
  13773. return l10n.getDirection();
  13774. }
  13775. async get(
  13776. key,
  13777. args = null,
  13778. fallback = (0, _l10n_utils.getL10nFallback)(key, args)
  13779. ) {
  13780. const l10n = await this._ready;
  13781. return l10n.get(key, args, fallback);
  13782. }
  13783. async translate(element) {
  13784. const l10n = await this._ready;
  13785. return l10n.translate(element);
  13786. }
  13787. }
  13788. exports.GenericL10n = GenericL10n;
  13789. /***/
  13790. },
  13791. /* 45 */
  13792. /***/ () => {
  13793. document.webL10n = (function (window, document, undefined) {
  13794. var gL10nData = {};
  13795. var gTextData = "";
  13796. var gTextProp = "textContent";
  13797. var gLanguage = "";
  13798. var gMacros = {};
  13799. var gReadyState = "loading";
  13800. var gAsyncResourceLoading = true;
  13801. function getL10nResourceLinks() {
  13802. return document.querySelectorAll('link[type="application/l10n"]');
  13803. }
  13804. function getL10nDictionary() {
  13805. var script = document.querySelector(
  13806. 'script[type="application/l10n"]'
  13807. );
  13808. return script ? JSON.parse(script.innerHTML) : null;
  13809. }
  13810. function getTranslatableChildren(element) {
  13811. return element ? element.querySelectorAll("*[data-l10n-id]") : [];
  13812. }
  13813. function getL10nAttributes(element) {
  13814. if (!element) return {};
  13815. var l10nId = element.getAttribute("data-l10n-id");
  13816. var l10nArgs = element.getAttribute("data-l10n-args");
  13817. var args = {};
  13818. if (l10nArgs) {
  13819. try {
  13820. args = JSON.parse(l10nArgs);
  13821. } catch (e) {
  13822. console.warn("could not parse arguments for #" + l10nId);
  13823. }
  13824. }
  13825. return {
  13826. id: l10nId,
  13827. args: args,
  13828. };
  13829. }
  13830. function xhrLoadText(url, onSuccess, onFailure) {
  13831. onSuccess = onSuccess || function _onSuccess(data) {};
  13832. onFailure = onFailure || function _onFailure() {};
  13833. var xhr = new XMLHttpRequest();
  13834. xhr.open("GET", url, gAsyncResourceLoading);
  13835. if (xhr.overrideMimeType) {
  13836. xhr.overrideMimeType("text/plain; charset=utf-8");
  13837. }
  13838. xhr.onreadystatechange = function () {
  13839. if (xhr.readyState == 4) {
  13840. if (xhr.status == 200 || xhr.status === 0) {
  13841. onSuccess(xhr.responseText);
  13842. } else {
  13843. onFailure();
  13844. }
  13845. }
  13846. };
  13847. xhr.onerror = onFailure;
  13848. xhr.ontimeout = onFailure;
  13849. try {
  13850. xhr.send(null);
  13851. } catch (e) {
  13852. onFailure();
  13853. }
  13854. }
  13855. function parseResource(href, lang, successCallback, failureCallback) {
  13856. var baseURL = href.replace(/[^\/]*$/, "") || "./";
  13857. function evalString(text) {
  13858. if (text.lastIndexOf("\\") < 0) return text;
  13859. return text
  13860. .replace(/\\\\/g, "\\")
  13861. .replace(/\\n/g, "\n")
  13862. .replace(/\\r/g, "\r")
  13863. .replace(/\\t/g, "\t")
  13864. .replace(/\\b/g, "\b")
  13865. .replace(/\\f/g, "\f")
  13866. .replace(/\\{/g, "{")
  13867. .replace(/\\}/g, "}")
  13868. .replace(/\\"/g, '"')
  13869. .replace(/\\'/g, "'");
  13870. }
  13871. function parseProperties(text, parsedPropertiesCallback) {
  13872. var dictionary = {};
  13873. var reBlank = /^\s*|\s*$/;
  13874. var reComment = /^\s*#|^\s*$/;
  13875. var reSection = /^\s*\[(.*)\]\s*$/;
  13876. var reImport = /^\s*@import\s+url\((.*)\)\s*$/i;
  13877. var reSplit = /^([^=\s]*)\s*=\s*(.+)$/;
  13878. function parseRawLines(
  13879. rawText,
  13880. extendedSyntax,
  13881. parsedRawLinesCallback
  13882. ) {
  13883. var entries = rawText.replace(reBlank, "").split(/[\r\n]+/);
  13884. var currentLang = "*";
  13885. var genericLang = lang.split("-", 1)[0];
  13886. var skipLang = false;
  13887. var match = "";
  13888. function nextEntry() {
  13889. while (true) {
  13890. if (!entries.length) {
  13891. parsedRawLinesCallback();
  13892. return;
  13893. }
  13894. var line = entries.shift();
  13895. if (reComment.test(line)) continue;
  13896. if (extendedSyntax) {
  13897. match = reSection.exec(line);
  13898. if (match) {
  13899. currentLang = match[1].toLowerCase();
  13900. skipLang =
  13901. currentLang !== "*" &&
  13902. currentLang !== lang &&
  13903. currentLang !== genericLang;
  13904. continue;
  13905. } else if (skipLang) {
  13906. continue;
  13907. }
  13908. match = reImport.exec(line);
  13909. if (match) {
  13910. loadImport(baseURL + match[1], nextEntry);
  13911. return;
  13912. }
  13913. }
  13914. var tmp = line.match(reSplit);
  13915. if (tmp && tmp.length == 3) {
  13916. dictionary[tmp[1]] = evalString(tmp[2]);
  13917. }
  13918. }
  13919. }
  13920. nextEntry();
  13921. }
  13922. function loadImport(url, callback) {
  13923. xhrLoadText(
  13924. url,
  13925. function (content) {
  13926. parseRawLines(content, false, callback);
  13927. },
  13928. function () {
  13929. console.warn(url + " not found.");
  13930. callback();
  13931. }
  13932. );
  13933. }
  13934. parseRawLines(text, true, function () {
  13935. parsedPropertiesCallback(dictionary);
  13936. });
  13937. }
  13938. xhrLoadText(
  13939. href,
  13940. function (response) {
  13941. gTextData += response;
  13942. parseProperties(response, function (data) {
  13943. for (var key in data) {
  13944. var id,
  13945. prop,
  13946. index = key.lastIndexOf(".");
  13947. if (index > 0) {
  13948. id = key.substring(0, index);
  13949. prop = key.substring(index + 1);
  13950. } else {
  13951. id = key;
  13952. prop = gTextProp;
  13953. }
  13954. if (!gL10nData[id]) {
  13955. gL10nData[id] = {};
  13956. }
  13957. gL10nData[id][prop] = data[key];
  13958. }
  13959. if (successCallback) {
  13960. successCallback();
  13961. }
  13962. });
  13963. },
  13964. failureCallback
  13965. );
  13966. }
  13967. function loadLocale(lang, callback) {
  13968. if (lang) {
  13969. lang = lang.toLowerCase();
  13970. }
  13971. callback = callback || function _callback() {};
  13972. clear();
  13973. gLanguage = lang;
  13974. var langLinks = getL10nResourceLinks();
  13975. var langCount = langLinks.length;
  13976. if (langCount === 0) {
  13977. var dict = getL10nDictionary();
  13978. if (dict && dict.locales && dict.default_locale) {
  13979. console.log("using the embedded JSON directory, early way out");
  13980. gL10nData = dict.locales[lang];
  13981. if (!gL10nData) {
  13982. var defaultLocale = dict.default_locale.toLowerCase();
  13983. for (var anyCaseLang in dict.locales) {
  13984. anyCaseLang = anyCaseLang.toLowerCase();
  13985. if (anyCaseLang === lang) {
  13986. gL10nData = dict.locales[lang];
  13987. break;
  13988. } else if (anyCaseLang === defaultLocale) {
  13989. gL10nData = dict.locales[defaultLocale];
  13990. }
  13991. }
  13992. }
  13993. callback();
  13994. } else {
  13995. console.log("no resource to load, early way out");
  13996. }
  13997. gReadyState = "complete";
  13998. return;
  13999. }
  14000. var onResourceLoaded = null;
  14001. var gResourceCount = 0;
  14002. onResourceLoaded = function () {
  14003. gResourceCount++;
  14004. if (gResourceCount >= langCount) {
  14005. callback();
  14006. gReadyState = "complete";
  14007. }
  14008. };
  14009. function L10nResourceLink(link) {
  14010. var href = link.href;
  14011. this.load = function (lang, callback) {
  14012. parseResource(href, lang, callback, function () {
  14013. console.warn(href + " not found.");
  14014. console.warn('"' + lang + '" resource not found');
  14015. gLanguage = "";
  14016. callback();
  14017. });
  14018. };
  14019. }
  14020. for (var i = 0; i < langCount; i++) {
  14021. var resource = new L10nResourceLink(langLinks[i]);
  14022. resource.load(lang, onResourceLoaded);
  14023. }
  14024. }
  14025. function clear() {
  14026. gL10nData = {};
  14027. gTextData = "";
  14028. gLanguage = "";
  14029. }
  14030. function getPluralRules(lang) {
  14031. var locales2rules = {
  14032. af: 3,
  14033. ak: 4,
  14034. am: 4,
  14035. ar: 1,
  14036. asa: 3,
  14037. az: 0,
  14038. be: 11,
  14039. bem: 3,
  14040. bez: 3,
  14041. bg: 3,
  14042. bh: 4,
  14043. bm: 0,
  14044. bn: 3,
  14045. bo: 0,
  14046. br: 20,
  14047. brx: 3,
  14048. bs: 11,
  14049. ca: 3,
  14050. cgg: 3,
  14051. chr: 3,
  14052. cs: 12,
  14053. cy: 17,
  14054. da: 3,
  14055. de: 3,
  14056. dv: 3,
  14057. dz: 0,
  14058. ee: 3,
  14059. el: 3,
  14060. en: 3,
  14061. eo: 3,
  14062. es: 3,
  14063. et: 3,
  14064. eu: 3,
  14065. fa: 0,
  14066. ff: 5,
  14067. fi: 3,
  14068. fil: 4,
  14069. fo: 3,
  14070. fr: 5,
  14071. fur: 3,
  14072. fy: 3,
  14073. ga: 8,
  14074. gd: 24,
  14075. gl: 3,
  14076. gsw: 3,
  14077. gu: 3,
  14078. guw: 4,
  14079. gv: 23,
  14080. ha: 3,
  14081. haw: 3,
  14082. he: 2,
  14083. hi: 4,
  14084. hr: 11,
  14085. hu: 0,
  14086. id: 0,
  14087. ig: 0,
  14088. ii: 0,
  14089. is: 3,
  14090. it: 3,
  14091. iu: 7,
  14092. ja: 0,
  14093. jmc: 3,
  14094. jv: 0,
  14095. ka: 0,
  14096. kab: 5,
  14097. kaj: 3,
  14098. kcg: 3,
  14099. kde: 0,
  14100. kea: 0,
  14101. kk: 3,
  14102. kl: 3,
  14103. km: 0,
  14104. kn: 0,
  14105. ko: 0,
  14106. ksb: 3,
  14107. ksh: 21,
  14108. ku: 3,
  14109. kw: 7,
  14110. lag: 18,
  14111. lb: 3,
  14112. lg: 3,
  14113. ln: 4,
  14114. lo: 0,
  14115. lt: 10,
  14116. lv: 6,
  14117. mas: 3,
  14118. mg: 4,
  14119. mk: 16,
  14120. ml: 3,
  14121. mn: 3,
  14122. mo: 9,
  14123. mr: 3,
  14124. ms: 0,
  14125. mt: 15,
  14126. my: 0,
  14127. nah: 3,
  14128. naq: 7,
  14129. nb: 3,
  14130. nd: 3,
  14131. ne: 3,
  14132. nl: 3,
  14133. nn: 3,
  14134. no: 3,
  14135. nr: 3,
  14136. nso: 4,
  14137. ny: 3,
  14138. nyn: 3,
  14139. om: 3,
  14140. or: 3,
  14141. pa: 3,
  14142. pap: 3,
  14143. pl: 13,
  14144. ps: 3,
  14145. pt: 3,
  14146. rm: 3,
  14147. ro: 9,
  14148. rof: 3,
  14149. ru: 11,
  14150. rwk: 3,
  14151. sah: 0,
  14152. saq: 3,
  14153. se: 7,
  14154. seh: 3,
  14155. ses: 0,
  14156. sg: 0,
  14157. sh: 11,
  14158. shi: 19,
  14159. sk: 12,
  14160. sl: 14,
  14161. sma: 7,
  14162. smi: 7,
  14163. smj: 7,
  14164. smn: 7,
  14165. sms: 7,
  14166. sn: 3,
  14167. so: 3,
  14168. sq: 3,
  14169. sr: 11,
  14170. ss: 3,
  14171. ssy: 3,
  14172. st: 3,
  14173. sv: 3,
  14174. sw: 3,
  14175. syr: 3,
  14176. ta: 3,
  14177. te: 3,
  14178. teo: 3,
  14179. th: 0,
  14180. ti: 4,
  14181. tig: 3,
  14182. tk: 3,
  14183. tl: 4,
  14184. tn: 3,
  14185. to: 0,
  14186. tr: 0,
  14187. ts: 3,
  14188. tzm: 22,
  14189. uk: 11,
  14190. ur: 3,
  14191. ve: 3,
  14192. vi: 0,
  14193. vun: 3,
  14194. wa: 4,
  14195. wae: 3,
  14196. wo: 0,
  14197. xh: 3,
  14198. xog: 3,
  14199. yo: 0,
  14200. zh: 0,
  14201. zu: 3,
  14202. };
  14203. function isIn(n, list) {
  14204. return list.indexOf(n) !== -1;
  14205. }
  14206. function isBetween(n, start, end) {
  14207. return start <= n && n <= end;
  14208. }
  14209. var pluralRules = {
  14210. 0: function (n) {
  14211. return "other";
  14212. },
  14213. 1: function (n) {
  14214. if (isBetween(n % 100, 3, 10)) return "few";
  14215. if (n === 0) return "zero";
  14216. if (isBetween(n % 100, 11, 99)) return "many";
  14217. if (n == 2) return "two";
  14218. if (n == 1) return "one";
  14219. return "other";
  14220. },
  14221. 2: function (n) {
  14222. if (n !== 0 && n % 10 === 0) return "many";
  14223. if (n == 2) return "two";
  14224. if (n == 1) return "one";
  14225. return "other";
  14226. },
  14227. 3: function (n) {
  14228. if (n == 1) return "one";
  14229. return "other";
  14230. },
  14231. 4: function (n) {
  14232. if (isBetween(n, 0, 1)) return "one";
  14233. return "other";
  14234. },
  14235. 5: function (n) {
  14236. if (isBetween(n, 0, 2) && n != 2) return "one";
  14237. return "other";
  14238. },
  14239. 6: function (n) {
  14240. if (n === 0) return "zero";
  14241. if (n % 10 == 1 && n % 100 != 11) return "one";
  14242. return "other";
  14243. },
  14244. 7: function (n) {
  14245. if (n == 2) return "two";
  14246. if (n == 1) return "one";
  14247. return "other";
  14248. },
  14249. 8: function (n) {
  14250. if (isBetween(n, 3, 6)) return "few";
  14251. if (isBetween(n, 7, 10)) return "many";
  14252. if (n == 2) return "two";
  14253. if (n == 1) return "one";
  14254. return "other";
  14255. },
  14256. 9: function (n) {
  14257. if (n === 0 || (n != 1 && isBetween(n % 100, 1, 19)))
  14258. return "few";
  14259. if (n == 1) return "one";
  14260. return "other";
  14261. },
  14262. 10: function (n) {
  14263. if (isBetween(n % 10, 2, 9) && !isBetween(n % 100, 11, 19))
  14264. return "few";
  14265. if (n % 10 == 1 && !isBetween(n % 100, 11, 19)) return "one";
  14266. return "other";
  14267. },
  14268. 11: function (n) {
  14269. if (isBetween(n % 10, 2, 4) && !isBetween(n % 100, 12, 14))
  14270. return "few";
  14271. if (
  14272. n % 10 === 0 ||
  14273. isBetween(n % 10, 5, 9) ||
  14274. isBetween(n % 100, 11, 14)
  14275. )
  14276. return "many";
  14277. if (n % 10 == 1 && n % 100 != 11) return "one";
  14278. return "other";
  14279. },
  14280. 12: function (n) {
  14281. if (isBetween(n, 2, 4)) return "few";
  14282. if (n == 1) return "one";
  14283. return "other";
  14284. },
  14285. 13: function (n) {
  14286. if (isBetween(n % 10, 2, 4) && !isBetween(n % 100, 12, 14))
  14287. return "few";
  14288. if (
  14289. (n != 1 && isBetween(n % 10, 0, 1)) ||
  14290. isBetween(n % 10, 5, 9) ||
  14291. isBetween(n % 100, 12, 14)
  14292. )
  14293. return "many";
  14294. if (n == 1) return "one";
  14295. return "other";
  14296. },
  14297. 14: function (n) {
  14298. if (isBetween(n % 100, 3, 4)) return "few";
  14299. if (n % 100 == 2) return "two";
  14300. if (n % 100 == 1) return "one";
  14301. return "other";
  14302. },
  14303. 15: function (n) {
  14304. if (n === 0 || isBetween(n % 100, 2, 10)) return "few";
  14305. if (isBetween(n % 100, 11, 19)) return "many";
  14306. if (n == 1) return "one";
  14307. return "other";
  14308. },
  14309. 16: function (n) {
  14310. if (n % 10 == 1 && n != 11) return "one";
  14311. return "other";
  14312. },
  14313. 17: function (n) {
  14314. if (n == 3) return "few";
  14315. if (n === 0) return "zero";
  14316. if (n == 6) return "many";
  14317. if (n == 2) return "two";
  14318. if (n == 1) return "one";
  14319. return "other";
  14320. },
  14321. 18: function (n) {
  14322. if (n === 0) return "zero";
  14323. if (isBetween(n, 0, 2) && n !== 0 && n != 2) return "one";
  14324. return "other";
  14325. },
  14326. 19: function (n) {
  14327. if (isBetween(n, 2, 10)) return "few";
  14328. if (isBetween(n, 0, 1)) return "one";
  14329. return "other";
  14330. },
  14331. 20: function (n) {
  14332. if (
  14333. (isBetween(n % 10, 3, 4) || n % 10 == 9) &&
  14334. !(
  14335. isBetween(n % 100, 10, 19) ||
  14336. isBetween(n % 100, 70, 79) ||
  14337. isBetween(n % 100, 90, 99)
  14338. )
  14339. )
  14340. return "few";
  14341. if (n % 1000000 === 0 && n !== 0) return "many";
  14342. if (n % 10 == 2 && !isIn(n % 100, [12, 72, 92])) return "two";
  14343. if (n % 10 == 1 && !isIn(n % 100, [11, 71, 91])) return "one";
  14344. return "other";
  14345. },
  14346. 21: function (n) {
  14347. if (n === 0) return "zero";
  14348. if (n == 1) return "one";
  14349. return "other";
  14350. },
  14351. 22: function (n) {
  14352. if (isBetween(n, 0, 1) || isBetween(n, 11, 99)) return "one";
  14353. return "other";
  14354. },
  14355. 23: function (n) {
  14356. if (isBetween(n % 10, 1, 2) || n % 20 === 0) return "one";
  14357. return "other";
  14358. },
  14359. 24: function (n) {
  14360. if (isBetween(n, 3, 10) || isBetween(n, 13, 19)) return "few";
  14361. if (isIn(n, [2, 12])) return "two";
  14362. if (isIn(n, [1, 11])) return "one";
  14363. return "other";
  14364. },
  14365. };
  14366. var index = locales2rules[lang.replace(/-.*$/, "")];
  14367. if (!(index in pluralRules)) {
  14368. console.warn("plural form unknown for [" + lang + "]");
  14369. return function () {
  14370. return "other";
  14371. };
  14372. }
  14373. return pluralRules[index];
  14374. }
  14375. gMacros.plural = function (str, param, key, prop) {
  14376. var n = parseFloat(param);
  14377. if (isNaN(n)) return str;
  14378. if (prop != gTextProp) return str;
  14379. if (!gMacros._pluralRules) {
  14380. gMacros._pluralRules = getPluralRules(gLanguage);
  14381. }
  14382. var index = "[" + gMacros._pluralRules(n) + "]";
  14383. if (n === 0 && key + "[zero]" in gL10nData) {
  14384. str = gL10nData[key + "[zero]"][prop];
  14385. } else if (n == 1 && key + "[one]" in gL10nData) {
  14386. str = gL10nData[key + "[one]"][prop];
  14387. } else if (n == 2 && key + "[two]" in gL10nData) {
  14388. str = gL10nData[key + "[two]"][prop];
  14389. } else if (key + index in gL10nData) {
  14390. str = gL10nData[key + index][prop];
  14391. } else if (key + "[other]" in gL10nData) {
  14392. str = gL10nData[key + "[other]"][prop];
  14393. }
  14394. return str;
  14395. };
  14396. function getL10nData(key, args, fallback) {
  14397. var data = gL10nData[key];
  14398. if (!data) {
  14399. console.warn("#" + key + " is undefined.");
  14400. if (!fallback) {
  14401. return null;
  14402. }
  14403. data = fallback;
  14404. }
  14405. var rv = {};
  14406. for (var prop in data) {
  14407. var str = data[prop];
  14408. str = substIndexes(str, args, key, prop);
  14409. str = substArguments(str, args, key);
  14410. rv[prop] = str;
  14411. }
  14412. return rv;
  14413. }
  14414. function substIndexes(str, args, key, prop) {
  14415. var reIndex = /\{\[\s*([a-zA-Z]+)\(([a-zA-Z]+)\)\s*\]\}/;
  14416. var reMatch = reIndex.exec(str);
  14417. if (!reMatch || !reMatch.length) return str;
  14418. var macroName = reMatch[1];
  14419. var paramName = reMatch[2];
  14420. var param;
  14421. if (args && paramName in args) {
  14422. param = args[paramName];
  14423. } else if (paramName in gL10nData) {
  14424. param = gL10nData[paramName];
  14425. }
  14426. if (macroName in gMacros) {
  14427. var macro = gMacros[macroName];
  14428. str = macro(str, param, key, prop);
  14429. }
  14430. return str;
  14431. }
  14432. function substArguments(str, args, key) {
  14433. var reArgs = /\{\{\s*(.+?)\s*\}\}/g;
  14434. return str.replace(reArgs, function (matched_text, arg) {
  14435. if (args && arg in args) {
  14436. return args[arg];
  14437. }
  14438. if (arg in gL10nData) {
  14439. return gL10nData[arg];
  14440. }
  14441. console.log(
  14442. "argument {{" + arg + "}} for #" + key + " is undefined."
  14443. );
  14444. return matched_text;
  14445. });
  14446. }
  14447. function translateElement(element) {
  14448. var l10n = getL10nAttributes(element);
  14449. if (!l10n.id) return;
  14450. var data = getL10nData(l10n.id, l10n.args);
  14451. if (!data) {
  14452. console.warn("#" + l10n.id + " is undefined.");
  14453. return;
  14454. }
  14455. if (data[gTextProp]) {
  14456. if (getChildElementCount(element) === 0) {
  14457. element[gTextProp] = data[gTextProp];
  14458. } else {
  14459. var children = element.childNodes;
  14460. var found = false;
  14461. for (var i = 0, l = children.length; i < l; i++) {
  14462. if (
  14463. children[i].nodeType === 3 &&
  14464. /\S/.test(children[i].nodeValue)
  14465. ) {
  14466. if (found) {
  14467. children[i].nodeValue = "";
  14468. } else {
  14469. children[i].nodeValue = data[gTextProp];
  14470. found = true;
  14471. }
  14472. }
  14473. }
  14474. if (!found) {
  14475. var textNode = document.createTextNode(data[gTextProp]);
  14476. element.prepend(textNode);
  14477. }
  14478. }
  14479. delete data[gTextProp];
  14480. }
  14481. for (var k in data) {
  14482. element[k] = data[k];
  14483. }
  14484. }
  14485. function getChildElementCount(element) {
  14486. if (element.children) {
  14487. return element.children.length;
  14488. }
  14489. if (typeof element.childElementCount !== "undefined") {
  14490. return element.childElementCount;
  14491. }
  14492. var count = 0;
  14493. for (var i = 0; i < element.childNodes.length; i++) {
  14494. count += element.nodeType === 1 ? 1 : 0;
  14495. }
  14496. return count;
  14497. }
  14498. function translateFragment(element) {
  14499. element = element || document.documentElement;
  14500. var children = getTranslatableChildren(element);
  14501. var elementCount = children.length;
  14502. for (var i = 0; i < elementCount; i++) {
  14503. translateElement(children[i]);
  14504. }
  14505. translateElement(element);
  14506. }
  14507. return {
  14508. get: function (key, args, fallbackString) {
  14509. var index = key.lastIndexOf(".");
  14510. var prop = gTextProp;
  14511. if (index > 0) {
  14512. prop = key.substring(index + 1);
  14513. key = key.substring(0, index);
  14514. }
  14515. var fallback;
  14516. if (fallbackString) {
  14517. fallback = {};
  14518. fallback[prop] = fallbackString;
  14519. }
  14520. var data = getL10nData(key, args, fallback);
  14521. if (data && prop in data) {
  14522. return data[prop];
  14523. }
  14524. return "{{" + key + "}}";
  14525. },
  14526. getData: function () {
  14527. return gL10nData;
  14528. },
  14529. getText: function () {
  14530. return gTextData;
  14531. },
  14532. getLanguage: function () {
  14533. return gLanguage;
  14534. },
  14535. setLanguage: function (lang, callback) {
  14536. loadLocale(lang, function () {
  14537. if (callback) callback();
  14538. });
  14539. },
  14540. getDirection: function () {
  14541. var rtlList = ["ar", "he", "fa", "ps", "ur"];
  14542. var shortCode = gLanguage.split("-", 1)[0];
  14543. return rtlList.indexOf(shortCode) >= 0 ? "rtl" : "ltr";
  14544. },
  14545. translate: translateFragment,
  14546. getReadyState: function () {
  14547. return gReadyState;
  14548. },
  14549. ready: function (callback) {
  14550. if (!callback) {
  14551. return;
  14552. } else if (
  14553. gReadyState == "complete" ||
  14554. gReadyState == "interactive"
  14555. ) {
  14556. window.setTimeout(function () {
  14557. callback();
  14558. });
  14559. } else if (document.addEventListener) {
  14560. document.addEventListener("localized", function once() {
  14561. document.removeEventListener("localized", once);
  14562. callback();
  14563. });
  14564. }
  14565. },
  14566. };
  14567. })(window, document);
  14568. /***/
  14569. },
  14570. /* 46 */
  14571. /***/ (__unused_webpack_module, exports, __webpack_require__) => {
  14572. Object.defineProperty(exports, "__esModule", {
  14573. value: true,
  14574. });
  14575. exports.GenericScripting = void 0;
  14576. exports.docPropertiesLookup = docPropertiesLookup;
  14577. var _pdfjsLib = __webpack_require__(4);
  14578. async function docPropertiesLookup(pdfDocument) {
  14579. const url = "",
  14580. baseUrl = url.split("#")[0];
  14581. let { info, metadata, contentDispositionFilename, contentLength } =
  14582. await pdfDocument.getMetadata();
  14583. if (!contentLength) {
  14584. const { length } = await pdfDocument.getDownloadInfo();
  14585. contentLength = length;
  14586. }
  14587. return {
  14588. ...info,
  14589. baseURL: baseUrl,
  14590. filesize: contentLength,
  14591. filename:
  14592. contentDispositionFilename ||
  14593. (0, _pdfjsLib.getPdfFilenameFromUrl)(url),
  14594. metadata: metadata?.getRaw(),
  14595. authors: metadata?.get("dc:creator"),
  14596. numPages: pdfDocument.numPages,
  14597. URL: url,
  14598. };
  14599. }
  14600. class GenericScripting {
  14601. constructor(sandboxBundleSrc) {
  14602. this._ready = (0, _pdfjsLib.loadScript)(sandboxBundleSrc, true).then(
  14603. () => {
  14604. return window.pdfjsSandbox.QuickJSSandbox();
  14605. }
  14606. );
  14607. }
  14608. async createSandbox(data) {
  14609. const sandbox = await this._ready;
  14610. sandbox.create(data);
  14611. }
  14612. async dispatchEventInSandbox(event) {
  14613. const sandbox = await this._ready;
  14614. setTimeout(() => sandbox.dispatchEvent(event), 0);
  14615. }
  14616. async destroySandbox() {
  14617. const sandbox = await this._ready;
  14618. sandbox.nukeSandbox();
  14619. }
  14620. }
  14621. exports.GenericScripting = GenericScripting;
  14622. /***/
  14623. },
  14624. /* 47 */
  14625. /***/ (__unused_webpack_module, exports, __webpack_require__) => {
  14626. Object.defineProperty(exports, "__esModule", {
  14627. value: true,
  14628. });
  14629. exports.PDFPrintService = PDFPrintService;
  14630. var _pdfjsLib = __webpack_require__(4);
  14631. var _app = __webpack_require__(2);
  14632. var _print_utils = __webpack_require__(48);
  14633. let activeService = null;
  14634. let dialog = null;
  14635. let overlayManager = null;
  14636. function renderPage(
  14637. activeServiceOnEntry,
  14638. pdfDocument,
  14639. pageNumber,
  14640. size,
  14641. printResolution,
  14642. optionalContentConfigPromise,
  14643. printAnnotationStoragePromise
  14644. ) {
  14645. const scratchCanvas = activeService.scratchCanvas;
  14646. const PRINT_UNITS = printResolution / _pdfjsLib.PixelsPerInch.PDF;
  14647. scratchCanvas.width = Math.floor(size.width * PRINT_UNITS);
  14648. scratchCanvas.height = Math.floor(size.height * PRINT_UNITS);
  14649. const ctx = scratchCanvas.getContext("2d");
  14650. ctx.save();
  14651. ctx.fillStyle = "rgb(255, 255, 255)";
  14652. ctx.fillRect(0, 0, scratchCanvas.width, scratchCanvas.height);
  14653. ctx.restore();
  14654. return Promise.all([
  14655. pdfDocument.getPage(pageNumber),
  14656. printAnnotationStoragePromise,
  14657. ]).then(function ([pdfPage, printAnnotationStorage]) {
  14658. const renderContext = {
  14659. canvasContext: ctx,
  14660. transform: [PRINT_UNITS, 0, 0, PRINT_UNITS, 0, 0],
  14661. viewport: pdfPage.getViewport({
  14662. scale: 1,
  14663. rotation: size.rotation,
  14664. }),
  14665. intent: "print",
  14666. annotationMode: _pdfjsLib.AnnotationMode.ENABLE_STORAGE,
  14667. optionalContentConfigPromise,
  14668. printAnnotationStorage,
  14669. };
  14670. return pdfPage.render(renderContext).promise;
  14671. });
  14672. }
  14673. function PDFPrintService(
  14674. pdfDocument,
  14675. pagesOverview,
  14676. printContainer,
  14677. printResolution,
  14678. optionalContentConfigPromise = null,
  14679. printAnnotationStoragePromise = null,
  14680. l10n
  14681. ) {
  14682. this.pdfDocument = pdfDocument;
  14683. this.pagesOverview = pagesOverview;
  14684. this.printContainer = printContainer;
  14685. this._printResolution = printResolution || 150;
  14686. this._optionalContentConfigPromise =
  14687. optionalContentConfigPromise ||
  14688. pdfDocument.getOptionalContentConfig();
  14689. this._printAnnotationStoragePromise =
  14690. printAnnotationStoragePromise || Promise.resolve();
  14691. this.l10n = l10n;
  14692. this.currentPage = -1;
  14693. this.scratchCanvas = document.createElement("canvas");
  14694. }
  14695. PDFPrintService.prototype = {
  14696. layout() {
  14697. this.throwIfInactive();
  14698. const body = document.querySelector("body");
  14699. body.setAttribute("data-pdfjsprinting", true);
  14700. const hasEqualPageSizes = this.pagesOverview.every(function (size) {
  14701. return (
  14702. size.width === this.pagesOverview[0].width &&
  14703. size.height === this.pagesOverview[0].height
  14704. );
  14705. }, this);
  14706. if (!hasEqualPageSizes) {
  14707. console.warn(
  14708. "Not all pages have the same size. The printed " +
  14709. "result may be incorrect!"
  14710. );
  14711. }
  14712. this.pageStyleSheet = document.createElement("style");
  14713. const pageSize = this.pagesOverview[0];
  14714. this.pageStyleSheet.textContent =
  14715. "@page { size: " +
  14716. pageSize.width +
  14717. "pt " +
  14718. pageSize.height +
  14719. "pt;}";
  14720. body.append(this.pageStyleSheet);
  14721. },
  14722. destroy() {
  14723. if (activeService !== this) {
  14724. return;
  14725. }
  14726. this.printContainer.textContent = "";
  14727. const body = document.querySelector("body");
  14728. body.removeAttribute("data-pdfjsprinting");
  14729. if (this.pageStyleSheet) {
  14730. this.pageStyleSheet.remove();
  14731. this.pageStyleSheet = null;
  14732. }
  14733. this.scratchCanvas.width = this.scratchCanvas.height = 0;
  14734. this.scratchCanvas = null;
  14735. activeService = null;
  14736. ensureOverlay().then(function () {
  14737. if (overlayManager.active === dialog) {
  14738. overlayManager.close(dialog);
  14739. }
  14740. });
  14741. },
  14742. renderPages() {
  14743. if (this.pdfDocument.isPureXfa) {
  14744. (0, _print_utils.getXfaHtmlForPrinting)(
  14745. this.printContainer,
  14746. this.pdfDocument
  14747. );
  14748. return Promise.resolve();
  14749. }
  14750. const pageCount = this.pagesOverview.length;
  14751. const renderNextPage = (resolve, reject) => {
  14752. this.throwIfInactive();
  14753. if (++this.currentPage >= pageCount) {
  14754. renderProgress(pageCount, pageCount, this.l10n);
  14755. resolve();
  14756. return;
  14757. }
  14758. const index = this.currentPage;
  14759. renderProgress(index, pageCount, this.l10n);
  14760. renderPage(
  14761. this,
  14762. this.pdfDocument,
  14763. index + 1,
  14764. this.pagesOverview[index],
  14765. this._printResolution,
  14766. this._optionalContentConfigPromise,
  14767. this._printAnnotationStoragePromise
  14768. )
  14769. .then(this.useRenderedPage.bind(this))
  14770. .then(function () {
  14771. renderNextPage(resolve, reject);
  14772. }, reject);
  14773. };
  14774. return new Promise(renderNextPage);
  14775. },
  14776. useRenderedPage() {
  14777. this.throwIfInactive();
  14778. const img = document.createElement("img");
  14779. const scratchCanvas = this.scratchCanvas;
  14780. if ("toBlob" in scratchCanvas) {
  14781. scratchCanvas.toBlob(function (blob) {
  14782. img.src = URL.createObjectURL(blob);
  14783. });
  14784. } else {
  14785. img.src = scratchCanvas.toDataURL();
  14786. }
  14787. const wrapper = document.createElement("div");
  14788. wrapper.className = "printedPage";
  14789. wrapper.append(img);
  14790. this.printContainer.append(wrapper);
  14791. return new Promise(function (resolve, reject) {
  14792. img.onload = resolve;
  14793. img.onerror = reject;
  14794. });
  14795. },
  14796. performPrint() {
  14797. this.throwIfInactive();
  14798. return new Promise((resolve) => {
  14799. setTimeout(() => {
  14800. if (!this.active) {
  14801. resolve();
  14802. return;
  14803. }
  14804. print.call(window);
  14805. setTimeout(resolve, 20);
  14806. }, 0);
  14807. });
  14808. },
  14809. get active() {
  14810. return this === activeService;
  14811. },
  14812. throwIfInactive() {
  14813. if (!this.active) {
  14814. throw new Error("This print request was cancelled or completed.");
  14815. }
  14816. },
  14817. };
  14818. const print = window.print;
  14819. window.print = function () {
  14820. if (activeService) {
  14821. console.warn(
  14822. "Ignored window.print() because of a pending print job."
  14823. );
  14824. return;
  14825. }
  14826. ensureOverlay().then(function () {
  14827. if (activeService) {
  14828. overlayManager.open(dialog);
  14829. }
  14830. });
  14831. try {
  14832. dispatchEvent("beforeprint");
  14833. } finally {
  14834. if (!activeService) {
  14835. console.error("Expected print service to be initialized.");
  14836. ensureOverlay().then(function () {
  14837. if (overlayManager.active === dialog) {
  14838. overlayManager.close(dialog);
  14839. }
  14840. });
  14841. return;
  14842. }
  14843. const activeServiceOnEntry = activeService;
  14844. activeService
  14845. .renderPages()
  14846. .then(function () {
  14847. return activeServiceOnEntry.performPrint();
  14848. })
  14849. .catch(function () {})
  14850. .then(function () {
  14851. if (activeServiceOnEntry.active) {
  14852. abort();
  14853. }
  14854. });
  14855. }
  14856. };
  14857. function dispatchEvent(eventType) {
  14858. const event = document.createEvent("CustomEvent");
  14859. event.initCustomEvent(eventType, false, false, "custom");
  14860. window.dispatchEvent(event);
  14861. }
  14862. function abort() {
  14863. if (activeService) {
  14864. activeService.destroy();
  14865. dispatchEvent("afterprint");
  14866. }
  14867. }
  14868. function renderProgress(index, total, l10n) {
  14869. dialog ||= document.getElementById("printServiceDialog");
  14870. const progress = Math.round((100 * index) / total);
  14871. const progressBar = dialog.querySelector("progress");
  14872. const progressPerc = dialog.querySelector(".relative-progress");
  14873. progressBar.value = progress;
  14874. l10n
  14875. .get("print_progress_percent", {
  14876. progress,
  14877. })
  14878. .then((msg) => {
  14879. progressPerc.textContent = msg;
  14880. });
  14881. }
  14882. window.addEventListener(
  14883. "keydown",
  14884. function (event) {
  14885. if (
  14886. event.keyCode === 80 &&
  14887. (event.ctrlKey || event.metaKey) &&
  14888. !event.altKey &&
  14889. (!event.shiftKey || window.chrome || window.opera)
  14890. ) {
  14891. window.print();
  14892. event.preventDefault();
  14893. event.stopImmediatePropagation();
  14894. }
  14895. },
  14896. true
  14897. );
  14898. if ("onbeforeprint" in window) {
  14899. const stopPropagationIfNeeded = function (event) {
  14900. if (event.detail !== "custom") {
  14901. event.stopImmediatePropagation();
  14902. }
  14903. };
  14904. window.addEventListener("beforeprint", stopPropagationIfNeeded);
  14905. window.addEventListener("afterprint", stopPropagationIfNeeded);
  14906. }
  14907. let overlayPromise;
  14908. function ensureOverlay() {
  14909. if (!overlayPromise) {
  14910. overlayManager = _app.PDFViewerApplication.overlayManager;
  14911. if (!overlayManager) {
  14912. throw new Error(
  14913. "The overlay manager has not yet been initialized."
  14914. );
  14915. }
  14916. dialog ||= document.getElementById("printServiceDialog");
  14917. overlayPromise = overlayManager.register(dialog, true);
  14918. document.getElementById("printCancel").onclick = abort;
  14919. dialog.addEventListener("close", abort);
  14920. }
  14921. return overlayPromise;
  14922. }
  14923. _app.PDFPrintServiceFactory.instance = {
  14924. supportsPrinting: true,
  14925. createPrintService(
  14926. pdfDocument,
  14927. pagesOverview,
  14928. printContainer,
  14929. printResolution,
  14930. optionalContentConfigPromise,
  14931. printAnnotationStoragePromise,
  14932. l10n
  14933. ) {
  14934. if (activeService) {
  14935. throw new Error("The print service is created and active.");
  14936. }
  14937. activeService = new PDFPrintService(
  14938. pdfDocument,
  14939. pagesOverview,
  14940. printContainer,
  14941. printResolution,
  14942. optionalContentConfigPromise,
  14943. printAnnotationStoragePromise,
  14944. l10n
  14945. );
  14946. return activeService;
  14947. },
  14948. };
  14949. /***/
  14950. },
  14951. /* 48 */
  14952. /***/ (__unused_webpack_module, exports, __webpack_require__) => {
  14953. Object.defineProperty(exports, "__esModule", {
  14954. value: true,
  14955. });
  14956. exports.getXfaHtmlForPrinting = getXfaHtmlForPrinting;
  14957. var _pdfjsLib = __webpack_require__(4);
  14958. var _pdf_link_service = __webpack_require__(7);
  14959. var _xfa_layer_builder = __webpack_require__(38);
  14960. function getXfaHtmlForPrinting(printContainer, pdfDocument) {
  14961. const xfaHtml = pdfDocument.allXfaHtml;
  14962. const linkService = new _pdf_link_service.SimpleLinkService();
  14963. const scale =
  14964. Math.round(_pdfjsLib.PixelsPerInch.PDF_TO_CSS_UNITS * 100) / 100;
  14965. for (const xfaPage of xfaHtml.children) {
  14966. const page = document.createElement("div");
  14967. page.className = "xfaPrintedPage";
  14968. printContainer.append(page);
  14969. const builder = new _xfa_layer_builder.XfaLayerBuilder({
  14970. pageDiv: page,
  14971. pdfPage: null,
  14972. annotationStorage: pdfDocument.annotationStorage,
  14973. linkService,
  14974. xfaHtml: xfaPage,
  14975. });
  14976. const viewport = (0, _pdfjsLib.getXfaPageViewport)(xfaPage, {
  14977. scale,
  14978. });
  14979. builder.render(viewport, "print");
  14980. }
  14981. }
  14982. /***/
  14983. },
  14984. /******/
  14985. ];
  14986. /************************************************************************/
  14987. /******/ // The module cache
  14988. /******/ var __webpack_module_cache__ = {};
  14989. /******/
  14990. /******/ // The require function
  14991. /******/ function __webpack_require__(moduleId) {
  14992. /******/ // Check if module is in cache
  14993. /******/ var cachedModule = __webpack_module_cache__[moduleId];
  14994. /******/ if (cachedModule !== undefined) {
  14995. /******/ return cachedModule.exports;
  14996. /******/
  14997. }
  14998. /******/ // Create a new module (and put it into the cache)
  14999. /******/ var module = (__webpack_module_cache__[moduleId] = {
  15000. /******/ // no module.id needed
  15001. /******/ // no module.loaded needed
  15002. /******/ exports: {},
  15003. /******/
  15004. });
  15005. /******/
  15006. /******/ // Execute the module function
  15007. /******/ __webpack_modules__[moduleId](
  15008. module,
  15009. module.exports,
  15010. __webpack_require__
  15011. );
  15012. /******/
  15013. /******/ // Return the exports of the module
  15014. /******/ return module.exports;
  15015. /******/
  15016. }
  15017. /******/
  15018. /************************************************************************/
  15019. var __webpack_exports__ = {};
  15020. // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
  15021. (() => {
  15022. var exports = __webpack_exports__;
  15023. Object.defineProperty(exports, "__esModule", {
  15024. value: true,
  15025. });
  15026. Object.defineProperty(exports, "PDFViewerApplication", {
  15027. enumerable: true,
  15028. get: function () {
  15029. return _app.PDFViewerApplication;
  15030. },
  15031. });
  15032. exports.PDFViewerApplicationConstants = void 0;
  15033. Object.defineProperty(exports, "PDFViewerApplicationOptions", {
  15034. enumerable: true,
  15035. get: function () {
  15036. return _app_options.AppOptions;
  15037. },
  15038. });
  15039. __webpack_require__(1);
  15040. __webpack_require__(47);
  15041. var _ui_utils = __webpack_require__(3);
  15042. var _app_options = __webpack_require__(5);
  15043. var _pdf_link_service = __webpack_require__(7);
  15044. var _app = __webpack_require__(2);
  15045. const pdfjsVersion = "3.5.141";
  15046. const pdfjsBuild = "be0f6ee08";
  15047. const AppConstants = {
  15048. LinkTarget: _pdf_link_service.LinkTarget,
  15049. RenderingStates: _ui_utils.RenderingStates,
  15050. ScrollMode: _ui_utils.ScrollMode,
  15051. SpreadMode: _ui_utils.SpreadMode,
  15052. };
  15053. exports.PDFViewerApplicationConstants = AppConstants;
  15054. window.PDFViewerApplication = _app.PDFViewerApplication;
  15055. window.PDFViewerApplicationConstants = AppConstants;
  15056. window.PDFViewerApplicationOptions = _app_options.AppOptions;
  15057. function getViewerConfiguration() {
  15058. return {
  15059. appContainer: document.body,
  15060. mainContainer: document.getElementById("viewerContainer"),
  15061. viewerContainer: document.getElementById("viewer"),
  15062. toolbar: {
  15063. container: document.getElementById("toolbarViewer"),
  15064. numPages: document.getElementById("numPages"),
  15065. pageNumber: document.getElementById("pageNumber"),
  15066. scaleSelect: document.getElementById("scaleSelect"),
  15067. customScaleOption: document.getElementById("customScaleOption"),
  15068. previous: document.getElementById("previous"),
  15069. next: document.getElementById("next"),
  15070. zoomIn: document.getElementById("zoomIn"),
  15071. zoomOut: document.getElementById("zoomOut"),
  15072. viewFind: document.getElementById("viewFind"),
  15073. openFile: document.getElementById("openFile"),
  15074. print: document.getElementById("print"),
  15075. editorFreeTextButton: document.getElementById("editorFreeText"),
  15076. editorFreeTextParamsToolbar: document.getElementById(
  15077. "editorFreeTextParamsToolbar"
  15078. ),
  15079. editorInkButton: document.getElementById("editorInk"),
  15080. editorInkParamsToolbar: document.getElementById(
  15081. "editorInkParamsToolbar"
  15082. ),
  15083. download: document.getElementById("download"),
  15084. },
  15085. secondaryToolbar: {
  15086. toolbar: document.getElementById("secondaryToolbar"),
  15087. toggleButton: document.getElementById("secondaryToolbarToggle"),
  15088. presentationModeButton: document.getElementById("presentationMode"),
  15089. openFileButton: document.getElementById("secondaryOpenFile"),
  15090. printButton: document.getElementById("secondaryPrint"),
  15091. downloadButton: document.getElementById("secondaryDownload"),
  15092. viewBookmarkButton: document.getElementById("viewBookmark"),
  15093. firstPageButton: document.getElementById("firstPage"),
  15094. lastPageButton: document.getElementById("lastPage"),
  15095. pageRotateCwButton: document.getElementById("pageRotateCw"),
  15096. pageRotateCcwButton: document.getElementById("pageRotateCcw"),
  15097. cursorSelectToolButton: document.getElementById("cursorSelectTool"),
  15098. cursorHandToolButton: document.getElementById("cursorHandTool"),
  15099. scrollPageButton: document.getElementById("scrollPage"),
  15100. scrollVerticalButton: document.getElementById("scrollVertical"),
  15101. scrollHorizontalButton: document.getElementById("scrollHorizontal"),
  15102. scrollWrappedButton: document.getElementById("scrollWrapped"),
  15103. spreadNoneButton: document.getElementById("spreadNone"),
  15104. spreadOddButton: document.getElementById("spreadOdd"),
  15105. spreadEvenButton: document.getElementById("spreadEven"),
  15106. documentPropertiesButton:
  15107. document.getElementById("documentProperties"),
  15108. },
  15109. sidebar: {
  15110. outerContainer: document.getElementById("outerContainer"),
  15111. sidebarContainer: document.getElementById("sidebarContainer"),
  15112. toggleButton: document.getElementById("sidebarToggle"),
  15113. thumbnailButton: document.getElementById("viewThumbnail"),
  15114. outlineButton: document.getElementById("viewOutline"),
  15115. attachmentsButton: document.getElementById("viewAttachments"),
  15116. layersButton: document.getElementById("viewLayers"),
  15117. thumbnailView: document.getElementById("thumbnailView"),
  15118. outlineView: document.getElementById("outlineView"),
  15119. attachmentsView: document.getElementById("attachmentsView"),
  15120. layersView: document.getElementById("layersView"),
  15121. outlineOptionsContainer: document.getElementById(
  15122. "outlineOptionsContainer"
  15123. ),
  15124. currentOutlineItemButton:
  15125. document.getElementById("currentOutlineItem"),
  15126. },
  15127. sidebarResizer: {
  15128. outerContainer: document.getElementById("outerContainer"),
  15129. resizer: document.getElementById("sidebarResizer"),
  15130. },
  15131. findBar: {
  15132. bar: document.getElementById("findbar"),
  15133. toggleButton: document.getElementById("viewFind"),
  15134. findField: document.getElementById("findInput"),
  15135. highlightAllCheckbox: document.getElementById("findHighlightAll"),
  15136. caseSensitiveCheckbox: document.getElementById("findMatchCase"),
  15137. matchDiacriticsCheckbox: document.getElementById(
  15138. "findMatchDiacritics"
  15139. ),
  15140. entireWordCheckbox: document.getElementById("findEntireWord"),
  15141. findMsg: document.getElementById("findMsg"),
  15142. findResultsCount: document.getElementById("findResultsCount"),
  15143. findPreviousButton: document.getElementById("findPrevious"),
  15144. findNextButton: document.getElementById("findNext"),
  15145. },
  15146. passwordOverlay: {
  15147. dialog: document.getElementById("passwordDialog"),
  15148. label: document.getElementById("passwordText"),
  15149. input: document.getElementById("password"),
  15150. submitButton: document.getElementById("passwordSubmit"),
  15151. cancelButton: document.getElementById("passwordCancel"),
  15152. },
  15153. documentProperties: {
  15154. dialog: document.getElementById("documentPropertiesDialog"),
  15155. closeButton: document.getElementById("documentPropertiesClose"),
  15156. fields: {
  15157. fileName: document.getElementById("fileNameField"),
  15158. fileSize: document.getElementById("fileSizeField"),
  15159. title: document.getElementById("titleField"),
  15160. author: document.getElementById("authorField"),
  15161. subject: document.getElementById("subjectField"),
  15162. keywords: document.getElementById("keywordsField"),
  15163. creationDate: document.getElementById("creationDateField"),
  15164. modificationDate: document.getElementById("modificationDateField"),
  15165. creator: document.getElementById("creatorField"),
  15166. producer: document.getElementById("producerField"),
  15167. version: document.getElementById("versionField"),
  15168. pageCount: document.getElementById("pageCountField"),
  15169. pageSize: document.getElementById("pageSizeField"),
  15170. linearized: document.getElementById("linearizedField"),
  15171. },
  15172. },
  15173. annotationEditorParams: {
  15174. editorFreeTextFontSize: document.getElementById(
  15175. "editorFreeTextFontSize"
  15176. ),
  15177. editorFreeTextColor: document.getElementById("editorFreeTextColor"),
  15178. editorInkColor: document.getElementById("editorInkColor"),
  15179. editorInkThickness: document.getElementById("editorInkThickness"),
  15180. editorInkOpacity: document.getElementById("editorInkOpacity"),
  15181. },
  15182. printContainer: document.getElementById("printContainer"),
  15183. openFileInput: document.getElementById("fileInput"),
  15184. debuggerScriptPath: "./debugger.js",
  15185. };
  15186. }
  15187. function webViewerLoad() {
  15188. const config = getViewerConfiguration();
  15189. const event = document.createEvent("CustomEvent");
  15190. event.initCustomEvent("webviewerloaded", true, true, {
  15191. source: window,
  15192. });
  15193. try {
  15194. parent.document.dispatchEvent(event);
  15195. } catch (ex) {
  15196. console.error(`webviewerloaded: ${ex}`);
  15197. document.dispatchEvent(event);
  15198. }
  15199. _app.PDFViewerApplication.run(config);
  15200. }
  15201. document.blockUnblockOnload?.(true);
  15202. if (
  15203. document.readyState === "interactive" ||
  15204. document.readyState === "complete"
  15205. ) {
  15206. webViewerLoad();
  15207. } else {
  15208. document.addEventListener("DOMContentLoaded", webViewerLoad, true);
  15209. }
  15210. })();
  15211. /******/
  15212. })();
  15213. //# sourceMappingURL=viewer.js.map