pdfviewer.js 386 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * Javascript code in this page
  4. *
  5. * Copyright 2021 Mozilla Foundation
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. *
  19. * @licend The above is the entire license notice for the
  20. * Javascript code in this page
  21. */
  22. /******/ (() => { // webpackBootstrap
  23. /******/ "use strict";
  24. /******/ var __webpack_modules__ = ([
  25. /* 0 */,
  26. /* 1 */
  27. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  28. Object.defineProperty(exports, "__esModule", ({
  29. value: true
  30. }));
  31. exports.OptionKind = exports.AppOptions = void 0;
  32. var _viewer_compatibility = __webpack_require__(2);
  33. const OptionKind = {
  34. VIEWER: 0x02,
  35. API: 0x04,
  36. WORKER: 0x08,
  37. PREFERENCE: 0x80
  38. };
  39. exports.OptionKind = OptionKind;
  40. const defaultOptions = {
  41. cursorToolOnLoad: {
  42. value: 0,
  43. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  44. },
  45. defaultUrl: {
  46. value: "compressed.tracemonkey-pldi-09.pdf",
  47. kind: OptionKind.VIEWER
  48. },
  49. defaultZoomValue: {
  50. value: "",
  51. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  52. },
  53. disableHistory: {
  54. value: false,
  55. kind: OptionKind.VIEWER
  56. },
  57. disablePageLabels: {
  58. value: false,
  59. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  60. },
  61. enablePermissions: {
  62. value: false,
  63. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  64. },
  65. enablePrintAutoRotate: {
  66. value: true,
  67. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  68. },
  69. enableScripting: {
  70. value: true,
  71. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  72. },
  73. externalLinkRel: {
  74. value: "noopener noreferrer nofollow",
  75. kind: OptionKind.VIEWER
  76. },
  77. externalLinkTarget: {
  78. value: 0,
  79. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  80. },
  81. historyUpdateUrl: {
  82. value: false,
  83. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  84. },
  85. ignoreDestinationZoom: {
  86. value: false,
  87. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  88. },
  89. imageResourcesPath: {
  90. value: "./images/",
  91. kind: OptionKind.VIEWER
  92. },
  93. maxCanvasPixels: {
  94. value: 16777216,
  95. compatibility: _viewer_compatibility.viewerCompatibilityParams.maxCanvasPixels,
  96. kind: OptionKind.VIEWER
  97. },
  98. pdfBugEnabled: {
  99. value: false,
  100. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  101. },
  102. printResolution: {
  103. value: 150,
  104. kind: OptionKind.VIEWER
  105. },
  106. renderer: {
  107. value: "canvas",
  108. kind: OptionKind.VIEWER
  109. },
  110. renderInteractiveForms: {
  111. value: true,
  112. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  113. },
  114. sidebarViewOnLoad: {
  115. value: -1,
  116. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  117. },
  118. scrollModeOnLoad: {
  119. value: -1,
  120. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  121. },
  122. spreadModeOnLoad: {
  123. value: -1,
  124. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  125. },
  126. textLayerMode: {
  127. value: 1,
  128. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  129. },
  130. useOnlyCssZoom: {
  131. value: false,
  132. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  133. },
  134. viewerCssTheme: {
  135. value: 0,
  136. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  137. },
  138. viewOnLoad: {
  139. value: 0,
  140. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  141. },
  142. cMapPacked: {
  143. value: true,
  144. kind: OptionKind.API
  145. },
  146. cMapUrl: {
  147. value: "../web/cmaps/",
  148. kind: OptionKind.API
  149. },
  150. disableAutoFetch: {
  151. value: false,
  152. kind: OptionKind.API + OptionKind.PREFERENCE
  153. },
  154. disableFontFace: {
  155. value: false,
  156. kind: OptionKind.API + OptionKind.PREFERENCE
  157. },
  158. disableRange: {
  159. value: false,
  160. kind: OptionKind.API + OptionKind.PREFERENCE
  161. },
  162. disableStream: {
  163. value: false,
  164. kind: OptionKind.API + OptionKind.PREFERENCE
  165. },
  166. docBaseUrl: {
  167. value: "",
  168. kind: OptionKind.API
  169. },
  170. enableXfa: {
  171. value: false,
  172. kind: OptionKind.API + OptionKind.PREFERENCE
  173. },
  174. fontExtraProperties: {
  175. value: false,
  176. kind: OptionKind.API
  177. },
  178. isEvalSupported: {
  179. value: true,
  180. kind: OptionKind.API
  181. },
  182. maxImageSize: {
  183. value: -1,
  184. kind: OptionKind.API
  185. },
  186. pdfBug: {
  187. value: false,
  188. kind: OptionKind.API
  189. },
  190. standardFontDataUrl: {
  191. value: "../web/standard_fonts/",
  192. kind: OptionKind.API
  193. },
  194. verbosity: {
  195. value: 1,
  196. kind: OptionKind.API
  197. },
  198. workerPort: {
  199. value: null,
  200. kind: OptionKind.WORKER
  201. },
  202. workerSrc: {
  203. value: "../build/pdf.worker.js",
  204. kind: OptionKind.WORKER
  205. }
  206. };
  207. {
  208. defaultOptions.disablePreferences = {
  209. value: false,
  210. kind: OptionKind.VIEWER
  211. };
  212. defaultOptions.locale = {
  213. value: typeof navigator !== "undefined" ? navigator.language : "en-US",
  214. kind: OptionKind.VIEWER
  215. };
  216. defaultOptions.sandboxBundleSrc = {
  217. value: "../build/pdf.sandbox.js",
  218. kind: OptionKind.VIEWER
  219. };
  220. defaultOptions.renderer.kind += OptionKind.PREFERENCE;
  221. }
  222. const userOptions = Object.create(null);
  223. class AppOptions {
  224. constructor() {
  225. throw new Error("Cannot initialize AppOptions.");
  226. }
  227. static get(name) {
  228. const userOption = userOptions[name];
  229. if (userOption !== undefined) {
  230. return userOption;
  231. }
  232. const defaultOption = defaultOptions[name];
  233. if (defaultOption !== undefined) {
  234. return defaultOption.compatibility ?? defaultOption.value;
  235. }
  236. return undefined;
  237. }
  238. static getAll(kind = null) {
  239. const options = Object.create(null);
  240. for (const name in defaultOptions) {
  241. const defaultOption = defaultOptions[name];
  242. if (kind) {
  243. if ((kind & defaultOption.kind) === 0) {
  244. continue;
  245. }
  246. if (kind === OptionKind.PREFERENCE) {
  247. const value = defaultOption.value,
  248. valueType = typeof value;
  249. if (valueType === "boolean" || valueType === "string" || valueType === "number" && Number.isInteger(value)) {
  250. options[name] = value;
  251. continue;
  252. }
  253. throw new Error(`Invalid type for preference: ${name}`);
  254. }
  255. }
  256. const userOption = userOptions[name];
  257. options[name] = userOption !== undefined ? userOption : defaultOption.compatibility ?? defaultOption.value;
  258. }
  259. return options;
  260. }
  261. static set(name, value) {
  262. userOptions[name] = value;
  263. }
  264. static setAll(options) {
  265. for (const name in options) {
  266. userOptions[name] = options[name];
  267. }
  268. }
  269. static remove(name) {
  270. delete userOptions[name];
  271. }
  272. }
  273. exports.AppOptions = AppOptions;
  274. /***/ }),
  275. /* 2 */
  276. /***/ ((__unused_webpack_module, exports) => {
  277. Object.defineProperty(exports, "__esModule", ({
  278. value: true
  279. }));
  280. exports.viewerCompatibilityParams = void 0;
  281. const compatibilityParams = Object.create(null);
  282. {
  283. const userAgent = typeof navigator !== "undefined" && navigator.userAgent || "";
  284. const platform = typeof navigator !== "undefined" && navigator.platform || "";
  285. const maxTouchPoints = typeof navigator !== "undefined" && navigator.maxTouchPoints || 1;
  286. const isAndroid = /Android/.test(userAgent);
  287. const isIOS = /\b(iPad|iPhone|iPod)(?=;)/.test(userAgent) || platform === "MacIntel" && maxTouchPoints > 1;
  288. const isIOSChrome = /CriOS/.test(userAgent);
  289. (function checkOnBlobSupport() {
  290. if (isIOSChrome) {
  291. compatibilityParams.disableCreateObjectURL = true;
  292. }
  293. })();
  294. (function checkCanvasSizeLimitation() {
  295. if (isIOS || isAndroid) {
  296. compatibilityParams.maxCanvasPixels = 5242880;
  297. }
  298. })();
  299. }
  300. const viewerCompatibilityParams = Object.freeze(compatibilityParams);
  301. exports.viewerCompatibilityParams = viewerCompatibilityParams;
  302. /***/ }),
  303. /* 3 */
  304. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  305. Object.defineProperty(exports, "__esModule", ({
  306. value: true
  307. }));
  308. exports.PDFViewerApplication = exports.PDFPrintServiceFactory = exports.DefaultExternalServices = void 0;
  309. var _ui_utils = __webpack_require__(4);
  310. var _app_options = __webpack_require__(1);
  311. var _pdfjsLib = __webpack_require__(5);
  312. var _pdf_cursor_tools = __webpack_require__(6);
  313. var _pdf_rendering_queue = __webpack_require__(8);
  314. var _overlay_manager = __webpack_require__(9);
  315. var _password_prompt = __webpack_require__(10);
  316. var _pdf_attachment_viewer = __webpack_require__(11);
  317. var _pdf_document_properties = __webpack_require__(13);
  318. var _pdf_find_bar = __webpack_require__(14);
  319. var _pdf_find_controller = __webpack_require__(15);
  320. var _pdf_history = __webpack_require__(17);
  321. var _pdf_layer_viewer = __webpack_require__(18);
  322. var _pdf_link_service = __webpack_require__(19);
  323. var _pdf_outline_viewer = __webpack_require__(20);
  324. var _pdf_presentation_mode = __webpack_require__(21);
  325. var _pdf_scripting_manager = __webpack_require__(22);
  326. var _pdf_sidebar = __webpack_require__(23);
  327. var _pdf_sidebar_resizer = __webpack_require__(24);
  328. var _pdf_thumbnail_viewer = __webpack_require__(25);
  329. var _pdf_viewer = __webpack_require__(27);
  330. var _secondary_toolbar = __webpack_require__(35);
  331. var _toolbar = __webpack_require__(37);
  332. var _viewer_compatibility = __webpack_require__(2);
  333. var _view_history = __webpack_require__(38);
  334. const DEFAULT_SCALE_DELTA = 1.1;
  335. const DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT = 5000;
  336. const FORCE_PAGES_LOADED_TIMEOUT = 10000;
  337. const WHEEL_ZOOM_DISABLED_TIMEOUT = 1000;
  338. const ENABLE_PERMISSIONS_CLASS = "enablePermissions";
  339. const ViewOnLoad = {
  340. UNKNOWN: -1,
  341. PREVIOUS: 0,
  342. INITIAL: 1
  343. };
  344. const ViewerCssTheme = {
  345. AUTOMATIC: 0,
  346. LIGHT: 1,
  347. DARK: 2
  348. };
  349. const KNOWN_VERSIONS = ["1.0", "1.1", "1.2", "1.3", "1.4", "1.5", "1.6", "1.7", "1.8", "1.9", "2.0", "2.1", "2.2", "2.3"];
  350. const KNOWN_GENERATORS = ["acrobat distiller", "acrobat pdfwriter", "adobe livecycle", "adobe pdf library", "adobe photoshop", "ghostscript", "tcpdf", "cairo", "dvipdfm", "dvips", "pdftex", "pdfkit", "itext", "prince", "quarkxpress", "mac os x", "microsoft", "openoffice", "oracle", "luradocument", "pdf-xchange", "antenna house", "aspose.cells", "fpdf"];
  351. class DefaultExternalServices {
  352. constructor() {
  353. throw new Error("Cannot initialize DefaultExternalServices.");
  354. }
  355. static updateFindControlState(data) {}
  356. static updateFindMatchesCount(data) {}
  357. static initPassiveLoading(callbacks) {}
  358. static async fallback(data) {}
  359. static reportTelemetry(data) {}
  360. static createDownloadManager(options) {
  361. throw new Error("Not implemented: createDownloadManager");
  362. }
  363. static createPreferences() {
  364. throw new Error("Not implemented: createPreferences");
  365. }
  366. static createL10n(options) {
  367. throw new Error("Not implemented: createL10n");
  368. }
  369. static createScripting(options) {
  370. throw new Error("Not implemented: createScripting");
  371. }
  372. static get supportsIntegratedFind() {
  373. return (0, _pdfjsLib.shadow)(this, "supportsIntegratedFind", false);
  374. }
  375. static get supportsDocumentFonts() {
  376. return (0, _pdfjsLib.shadow)(this, "supportsDocumentFonts", true);
  377. }
  378. static get supportedMouseWheelZoomModifierKeys() {
  379. return (0, _pdfjsLib.shadow)(this, "supportedMouseWheelZoomModifierKeys", {
  380. ctrlKey: true,
  381. metaKey: true
  382. });
  383. }
  384. static get isInAutomation() {
  385. return (0, _pdfjsLib.shadow)(this, "isInAutomation", false);
  386. }
  387. }
  388. exports.DefaultExternalServices = DefaultExternalServices;
  389. const PDFViewerApplication = {
  390. initialBookmark: document.location.hash.substring(1),
  391. _initializedCapability: (0, _pdfjsLib.createPromiseCapability)(),
  392. _fellback: false,
  393. appConfig: null,
  394. pdfDocument: null,
  395. pdfLoadingTask: null,
  396. printService: null,
  397. pdfViewer: null,
  398. pdfThumbnailViewer: null,
  399. pdfRenderingQueue: null,
  400. pdfPresentationMode: null,
  401. pdfDocumentProperties: null,
  402. pdfLinkService: null,
  403. pdfHistory: null,
  404. pdfSidebar: null,
  405. pdfSidebarResizer: null,
  406. pdfOutlineViewer: null,
  407. pdfAttachmentViewer: null,
  408. pdfLayerViewer: null,
  409. pdfCursorTools: null,
  410. pdfScriptingManager: null,
  411. store: null,
  412. downloadManager: null,
  413. overlayManager: null,
  414. preferences: null,
  415. toolbar: null,
  416. secondaryToolbar: null,
  417. eventBus: null,
  418. l10n: null,
  419. isInitialViewSet: false,
  420. downloadComplete: false,
  421. isViewerEmbedded: window.parent !== window,
  422. url: "",
  423. baseUrl: "",
  424. externalServices: DefaultExternalServices,
  425. _boundEvents: Object.create(null),
  426. documentInfo: null,
  427. metadata: null,
  428. _contentDispositionFilename: null,
  429. _contentLength: null,
  430. _saveInProgress: false,
  431. _wheelUnusedTicks: 0,
  432. _idleCallbacks: new Set(),
  433. async initialize(appConfig) {
  434. this.preferences = this.externalServices.createPreferences();
  435. this.appConfig = appConfig;
  436. await this._readPreferences();
  437. await this._parseHashParameters();
  438. this._forceCssTheme();
  439. await this._initializeL10n();
  440. if (this.isViewerEmbedded && _app_options.AppOptions.get("externalLinkTarget") === _pdfjsLib.LinkTarget.NONE) {
  441. _app_options.AppOptions.set("externalLinkTarget", _pdfjsLib.LinkTarget.TOP);
  442. }
  443. await this._initializeViewerComponents();
  444. this.bindEvents();
  445. this.bindWindowEvents();
  446. const appContainer = appConfig.appContainer || document.documentElement;
  447. this.l10n.translate(appContainer).then(() => {
  448. this.eventBus.dispatch("localized", {
  449. source: this
  450. });
  451. });
  452. this._initializedCapability.resolve();
  453. },
  454. async _readPreferences() {
  455. if (_app_options.AppOptions.get("disablePreferences")) {
  456. return;
  457. }
  458. try {
  459. _app_options.AppOptions.setAll(await this.preferences.getAll());
  460. } catch (reason) {
  461. console.error(`_readPreferences: "${reason?.message}".`);
  462. }
  463. },
  464. async _parseHashParameters() {
  465. if (!_app_options.AppOptions.get("pdfBugEnabled")) {
  466. return undefined;
  467. }
  468. const hash = document.location.hash.substring(1);
  469. if (!hash) {
  470. return undefined;
  471. }
  472. const hashParams = (0, _ui_utils.parseQueryString)(hash),
  473. waitOn = [];
  474. if ("disableworker" in hashParams && hashParams.disableworker === "true") {
  475. waitOn.push(loadFakeWorker());
  476. }
  477. if ("disablerange" in hashParams) {
  478. _app_options.AppOptions.set("disableRange", hashParams.disablerange === "true");
  479. }
  480. if ("disablestream" in hashParams) {
  481. _app_options.AppOptions.set("disableStream", hashParams.disablestream === "true");
  482. }
  483. if ("disableautofetch" in hashParams) {
  484. _app_options.AppOptions.set("disableAutoFetch", hashParams.disableautofetch === "true");
  485. }
  486. if ("disablefontface" in hashParams) {
  487. _app_options.AppOptions.set("disableFontFace", hashParams.disablefontface === "true");
  488. }
  489. if ("disablehistory" in hashParams) {
  490. _app_options.AppOptions.set("disableHistory", hashParams.disablehistory === "true");
  491. }
  492. if ("verbosity" in hashParams) {
  493. _app_options.AppOptions.set("verbosity", hashParams.verbosity | 0);
  494. }
  495. if ("textlayer" in hashParams) {
  496. switch (hashParams.textlayer) {
  497. case "off":
  498. _app_options.AppOptions.set("textLayerMode", _ui_utils.TextLayerMode.DISABLE);
  499. break;
  500. case "visible":
  501. case "shadow":
  502. case "hover":
  503. const viewer = this.appConfig.viewerContainer;
  504. viewer.classList.add("textLayer-" + hashParams.textlayer);
  505. break;
  506. }
  507. }
  508. if ("pdfbug" in hashParams) {
  509. _app_options.AppOptions.set("pdfBug", true);
  510. _app_options.AppOptions.set("fontExtraProperties", true);
  511. const enabled = hashParams.pdfbug.split(",");
  512. waitOn.push(loadAndEnablePDFBug(enabled));
  513. }
  514. if ("locale" in hashParams) {
  515. _app_options.AppOptions.set("locale", hashParams.locale);
  516. }
  517. if (waitOn.length === 0) {
  518. return undefined;
  519. }
  520. return Promise.all(waitOn).catch(reason => {
  521. console.error(`_parseHashParameters: "${reason.message}".`);
  522. });
  523. },
  524. async _initializeL10n() {
  525. this.l10n = this.externalServices.createL10n({
  526. locale: _app_options.AppOptions.get("locale")
  527. });
  528. const dir = await this.l10n.getDirection();
  529. document.getElementsByTagName("html")[0].dir = dir;
  530. },
  531. _forceCssTheme() {
  532. const cssTheme = _app_options.AppOptions.get("viewerCssTheme");
  533. if (cssTheme === ViewerCssTheme.AUTOMATIC || !Object.values(ViewerCssTheme).includes(cssTheme)) {
  534. return;
  535. }
  536. try {
  537. const styleSheet = document.styleSheets[0];
  538. const cssRules = styleSheet?.cssRules || [];
  539. const mediaMatcher = "prefers-color-scheme";
  540. const mediaRule = `(${mediaMatcher}: dark)`;
  541. const mediaRegex = new RegExp(`^@media \\(${mediaMatcher}: dark\\) {\\n\\s*([\\w\\s-.,:;/\\\\{}()]+)\\n}$`);
  542. for (let i = 0, ii = cssRules.length; i < ii; i++) {
  543. const rule = cssRules[i];
  544. if (rule instanceof CSSMediaRule && rule.media?.[0] === mediaRule) {
  545. if (cssTheme === ViewerCssTheme.LIGHT) {
  546. styleSheet.deleteRule(i);
  547. return;
  548. }
  549. const darkRules = mediaRegex.exec(rule.cssText);
  550. if (darkRules?.[1]) {
  551. styleSheet.deleteRule(i);
  552. styleSheet.insertRule(darkRules[1], i);
  553. }
  554. return;
  555. }
  556. }
  557. } catch (reason) {
  558. console.error(`_forceCssTheme: "${reason?.message}".`);
  559. }
  560. },
  561. async _initializeViewerComponents() {
  562. const appConfig = this.appConfig;
  563. const eventBus = appConfig.eventBus || new _ui_utils.EventBus({
  564. isInAutomation: this.externalServices.isInAutomation
  565. });
  566. this.eventBus = eventBus;
  567. this.overlayManager = new _overlay_manager.OverlayManager();
  568. const pdfRenderingQueue = new _pdf_rendering_queue.PDFRenderingQueue();
  569. pdfRenderingQueue.onIdle = this._cleanup.bind(this);
  570. this.pdfRenderingQueue = pdfRenderingQueue;
  571. const pdfLinkService = new _pdf_link_service.PDFLinkService({
  572. eventBus,
  573. externalLinkTarget: _app_options.AppOptions.get("externalLinkTarget"),
  574. externalLinkRel: _app_options.AppOptions.get("externalLinkRel"),
  575. ignoreDestinationZoom: _app_options.AppOptions.get("ignoreDestinationZoom")
  576. });
  577. this.pdfLinkService = pdfLinkService;
  578. const downloadManager = this.externalServices.createDownloadManager();
  579. this.downloadManager = downloadManager;
  580. const findController = new _pdf_find_controller.PDFFindController({
  581. linkService: pdfLinkService,
  582. eventBus
  583. });
  584. this.findController = findController;
  585. const pdfScriptingManager = new _pdf_scripting_manager.PDFScriptingManager({
  586. eventBus,
  587. sandboxBundleSrc: _app_options.AppOptions.get("sandboxBundleSrc"),
  588. scriptingFactory: this.externalServices,
  589. docPropertiesLookup: this._scriptingDocProperties.bind(this)
  590. });
  591. this.pdfScriptingManager = pdfScriptingManager;
  592. const container = appConfig.mainContainer;
  593. const viewer = appConfig.viewerContainer;
  594. this.pdfViewer = new _pdf_viewer.PDFViewer({
  595. container,
  596. viewer,
  597. eventBus,
  598. renderingQueue: pdfRenderingQueue,
  599. linkService: pdfLinkService,
  600. downloadManager,
  601. findController,
  602. scriptingManager: pdfScriptingManager,
  603. renderer: _app_options.AppOptions.get("renderer"),
  604. l10n: this.l10n,
  605. textLayerMode: _app_options.AppOptions.get("textLayerMode"),
  606. imageResourcesPath: _app_options.AppOptions.get("imageResourcesPath"),
  607. renderInteractiveForms: _app_options.AppOptions.get("renderInteractiveForms"),
  608. enablePrintAutoRotate: _app_options.AppOptions.get("enablePrintAutoRotate"),
  609. useOnlyCssZoom: _app_options.AppOptions.get("useOnlyCssZoom"),
  610. maxCanvasPixels: _app_options.AppOptions.get("maxCanvasPixels"),
  611. enableScripting: _app_options.AppOptions.get("enableScripting")
  612. });
  613. pdfRenderingQueue.setViewer(this.pdfViewer);
  614. pdfLinkService.setViewer(this.pdfViewer);
  615. pdfScriptingManager.setViewer(this.pdfViewer);
  616. this.pdfThumbnailViewer = new _pdf_thumbnail_viewer.PDFThumbnailViewer({
  617. container: appConfig.sidebar.thumbnailView,
  618. eventBus,
  619. renderingQueue: pdfRenderingQueue,
  620. linkService: pdfLinkService,
  621. l10n: this.l10n
  622. });
  623. pdfRenderingQueue.setThumbnailViewer(this.pdfThumbnailViewer);
  624. this.pdfHistory = new _pdf_history.PDFHistory({
  625. linkService: pdfLinkService,
  626. eventBus
  627. });
  628. pdfLinkService.setHistory(this.pdfHistory);
  629. if (!this.supportsIntegratedFind) {
  630. this.findBar = new _pdf_find_bar.PDFFindBar(appConfig.findBar, eventBus, this.l10n);
  631. }
  632. this.pdfDocumentProperties = new _pdf_document_properties.PDFDocumentProperties(appConfig.documentProperties, this.overlayManager, eventBus, this.l10n);
  633. this.pdfCursorTools = new _pdf_cursor_tools.PDFCursorTools({
  634. container,
  635. eventBus,
  636. cursorToolOnLoad: _app_options.AppOptions.get("cursorToolOnLoad")
  637. });
  638. this.toolbar = new _toolbar.Toolbar(appConfig.toolbar, eventBus, this.l10n);
  639. this.secondaryToolbar = new _secondary_toolbar.SecondaryToolbar(appConfig.secondaryToolbar, container, eventBus);
  640. if (this.supportsFullscreen) {
  641. this.pdfPresentationMode = new _pdf_presentation_mode.PDFPresentationMode({
  642. container,
  643. pdfViewer: this.pdfViewer,
  644. eventBus
  645. });
  646. }
  647. this.passwordPrompt = new _password_prompt.PasswordPrompt(appConfig.passwordOverlay, this.overlayManager, this.l10n, this.isViewerEmbedded);
  648. this.pdfOutlineViewer = new _pdf_outline_viewer.PDFOutlineViewer({
  649. container: appConfig.sidebar.outlineView,
  650. eventBus,
  651. linkService: pdfLinkService
  652. });
  653. this.pdfAttachmentViewer = new _pdf_attachment_viewer.PDFAttachmentViewer({
  654. container: appConfig.sidebar.attachmentsView,
  655. eventBus,
  656. downloadManager
  657. });
  658. this.pdfLayerViewer = new _pdf_layer_viewer.PDFLayerViewer({
  659. container: appConfig.sidebar.layersView,
  660. eventBus,
  661. l10n: this.l10n
  662. });
  663. this.pdfSidebar = new _pdf_sidebar.PDFSidebar({
  664. elements: appConfig.sidebar,
  665. pdfViewer: this.pdfViewer,
  666. pdfThumbnailViewer: this.pdfThumbnailViewer,
  667. eventBus,
  668. l10n: this.l10n
  669. });
  670. this.pdfSidebar.onToggled = this.forceRendering.bind(this);
  671. this.pdfSidebarResizer = new _pdf_sidebar_resizer.PDFSidebarResizer(appConfig.sidebarResizer, eventBus, this.l10n);
  672. },
  673. run(config) {
  674. this.initialize(config).then(webViewerInitialized);
  675. },
  676. get initialized() {
  677. return this._initializedCapability.settled;
  678. },
  679. get initializedPromise() {
  680. return this._initializedCapability.promise;
  681. },
  682. zoomIn(ticks) {
  683. if (this.pdfViewer.isInPresentationMode) {
  684. return;
  685. }
  686. let newScale = this.pdfViewer.currentScale;
  687. do {
  688. newScale = (newScale * DEFAULT_SCALE_DELTA).toFixed(2);
  689. newScale = Math.ceil(newScale * 10) / 10;
  690. newScale = Math.min(_ui_utils.MAX_SCALE, newScale);
  691. } while (--ticks > 0 && newScale < _ui_utils.MAX_SCALE);
  692. this.pdfViewer.currentScaleValue = newScale;
  693. },
  694. zoomOut(ticks) {
  695. if (this.pdfViewer.isInPresentationMode) {
  696. return;
  697. }
  698. let newScale = this.pdfViewer.currentScale;
  699. do {
  700. newScale = (newScale / DEFAULT_SCALE_DELTA).toFixed(2);
  701. newScale = Math.floor(newScale * 10) / 10;
  702. newScale = Math.max(_ui_utils.MIN_SCALE, newScale);
  703. } while (--ticks > 0 && newScale > _ui_utils.MIN_SCALE);
  704. this.pdfViewer.currentScaleValue = newScale;
  705. },
  706. zoomReset() {
  707. if (this.pdfViewer.isInPresentationMode) {
  708. return;
  709. }
  710. this.pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  711. },
  712. get pagesCount() {
  713. return this.pdfDocument ? this.pdfDocument.numPages : 0;
  714. },
  715. get page() {
  716. return this.pdfViewer.currentPageNumber;
  717. },
  718. set page(val) {
  719. this.pdfViewer.currentPageNumber = val;
  720. },
  721. get supportsPrinting() {
  722. return PDFPrintServiceFactory.instance.supportsPrinting;
  723. },
  724. get supportsFullscreen() {
  725. const doc = document.documentElement;
  726. let support = !!(doc.requestFullscreen || doc.mozRequestFullScreen || doc.webkitRequestFullScreen);
  727. if (document.fullscreenEnabled === false || document.mozFullScreenEnabled === false || document.webkitFullscreenEnabled === false) {
  728. support = false;
  729. }
  730. return (0, _pdfjsLib.shadow)(this, "supportsFullscreen", support);
  731. },
  732. get supportsIntegratedFind() {
  733. return this.externalServices.supportsIntegratedFind;
  734. },
  735. get supportsDocumentFonts() {
  736. return this.externalServices.supportsDocumentFonts;
  737. },
  738. get loadingBar() {
  739. const bar = new _ui_utils.ProgressBar("#loadingBar");
  740. return (0, _pdfjsLib.shadow)(this, "loadingBar", bar);
  741. },
  742. get supportedMouseWheelZoomModifierKeys() {
  743. return this.externalServices.supportedMouseWheelZoomModifierKeys;
  744. },
  745. initPassiveLoading() {
  746. throw new Error("Not implemented: initPassiveLoading");
  747. },
  748. setTitleUsingUrl(url = "") {
  749. this.url = url;
  750. this.baseUrl = url.split("#")[0];
  751. let title = (0, _pdfjsLib.getPdfFilenameFromUrl)(url, "");
  752. if (!title) {
  753. try {
  754. title = decodeURIComponent((0, _pdfjsLib.getFilenameFromUrl)(url)) || url;
  755. } catch (ex) {
  756. title = url;
  757. }
  758. }
  759. this.setTitle(title);
  760. },
  761. setTitle(title) {
  762. if (this.isViewerEmbedded) {
  763. return;
  764. }
  765. document.title = title;
  766. },
  767. get _docFilename() {
  768. return this._contentDispositionFilename || (0, _pdfjsLib.getPdfFilenameFromUrl)(this.url);
  769. },
  770. _cancelIdleCallbacks() {
  771. if (!this._idleCallbacks.size) {
  772. return;
  773. }
  774. for (const callback of this._idleCallbacks) {
  775. window.cancelIdleCallback(callback);
  776. }
  777. this._idleCallbacks.clear();
  778. },
  779. async close() {
  780. this._unblockDocumentLoadEvent();
  781. const {
  782. container
  783. } = this.appConfig.errorWrapper;
  784. container.hidden = true;
  785. if (!this.pdfLoadingTask) {
  786. return;
  787. }
  788. if (this.pdfDocument?.annotationStorage.size > 0 && this._annotationStorageModified) {
  789. try {
  790. await this.save({
  791. sourceEventType: "save"
  792. });
  793. } catch (reason) {}
  794. }
  795. const promises = [];
  796. promises.push(this.pdfLoadingTask.destroy());
  797. this.pdfLoadingTask = null;
  798. if (this.pdfDocument) {
  799. this.pdfDocument = null;
  800. this.pdfThumbnailViewer.setDocument(null);
  801. this.pdfViewer.setDocument(null);
  802. this.pdfLinkService.setDocument(null);
  803. this.pdfDocumentProperties.setDocument(null);
  804. }
  805. webViewerResetPermissions();
  806. this.pdfLinkService.externalLinkEnabled = true;
  807. this._fellback = false;
  808. this.store = null;
  809. this.isInitialViewSet = false;
  810. this.downloadComplete = false;
  811. this.url = "";
  812. this.baseUrl = "";
  813. this.documentInfo = null;
  814. this.metadata = null;
  815. this._contentDispositionFilename = null;
  816. this._contentLength = null;
  817. this._saveInProgress = false;
  818. this._cancelIdleCallbacks();
  819. promises.push(this.pdfScriptingManager.destroyPromise);
  820. this.pdfSidebar.reset();
  821. this.pdfOutlineViewer.reset();
  822. this.pdfAttachmentViewer.reset();
  823. this.pdfLayerViewer.reset();
  824. if (this.pdfHistory) {
  825. this.pdfHistory.reset();
  826. }
  827. if (this.findBar) {
  828. this.findBar.reset();
  829. }
  830. this.toolbar.reset();
  831. this.secondaryToolbar.reset();
  832. if (typeof PDFBug !== "undefined") {
  833. PDFBug.cleanup();
  834. }
  835. await Promise.all(promises);
  836. },
  837. async open(file, args) {
  838. if (this.pdfLoadingTask) {
  839. await this.close();
  840. }
  841. const workerParameters = _app_options.AppOptions.getAll(_app_options.OptionKind.WORKER);
  842. for (const key in workerParameters) {
  843. _pdfjsLib.GlobalWorkerOptions[key] = workerParameters[key];
  844. }
  845. const parameters = Object.create(null);
  846. if (typeof file === "string") {
  847. this.setTitleUsingUrl(file);
  848. parameters.url = file;
  849. } else if (file && "byteLength" in file) {
  850. parameters.data = file;
  851. } else if (file.url && file.originalUrl) {
  852. this.setTitleUsingUrl(file.originalUrl);
  853. parameters.url = file.url;
  854. }
  855. const apiParameters = _app_options.AppOptions.getAll(_app_options.OptionKind.API);
  856. for (const key in apiParameters) {
  857. let value = apiParameters[key];
  858. if (key === "docBaseUrl" && !value) {}
  859. parameters[key] = value;
  860. }
  861. if (args) {
  862. for (const key in args) {
  863. parameters[key] = args[key];
  864. }
  865. }
  866. const loadingTask = (0, _pdfjsLib.getDocument)(parameters);
  867. this.pdfLoadingTask = loadingTask;
  868. loadingTask.onPassword = (updateCallback, reason) => {
  869. this.pdfLinkService.externalLinkEnabled = false;
  870. this.passwordPrompt.setUpdateCallback(updateCallback, reason);
  871. this.passwordPrompt.open();
  872. };
  873. loadingTask.onProgress = ({
  874. loaded,
  875. total
  876. }) => {
  877. this.progress(loaded / total);
  878. };
  879. loadingTask.onUnsupportedFeature = this.fallback.bind(this);
  880. return loadingTask.promise.then(pdfDocument => {
  881. this.load(pdfDocument);
  882. }, exception => {
  883. if (loadingTask !== this.pdfLoadingTask) {
  884. return undefined;
  885. }
  886. let key = "loading_error";
  887. if (exception instanceof _pdfjsLib.InvalidPDFException) {
  888. key = "invalid_file_error";
  889. } else if (exception instanceof _pdfjsLib.MissingPDFException) {
  890. key = "missing_file_error";
  891. } else if (exception instanceof _pdfjsLib.UnexpectedResponseException) {
  892. key = "unexpected_response_error";
  893. }
  894. return this.l10n.get(key).then(msg => {
  895. this._documentError(msg, {
  896. message: exception?.message
  897. });
  898. throw exception;
  899. });
  900. });
  901. },
  902. _ensureDownloadComplete() {
  903. if (this.pdfDocument && this.downloadComplete) {
  904. return;
  905. }
  906. throw new Error("PDF document not downloaded.");
  907. },
  908. async download({
  909. sourceEventType = "download"
  910. } = {}) {
  911. const url = this.baseUrl,
  912. filename = this._docFilename;
  913. try {
  914. this._ensureDownloadComplete();
  915. const data = await this.pdfDocument.getData();
  916. const blob = new Blob([data], {
  917. type: "application/pdf"
  918. });
  919. await this.downloadManager.download(blob, url, filename, sourceEventType);
  920. } catch (reason) {
  921. await this.downloadManager.downloadUrl(url, filename);
  922. }
  923. },
  924. async save({
  925. sourceEventType = "download"
  926. } = {}) {
  927. if (this._saveInProgress) {
  928. return;
  929. }
  930. this._saveInProgress = true;
  931. await this.pdfScriptingManager.dispatchWillSave();
  932. const url = this.baseUrl,
  933. filename = this._docFilename;
  934. try {
  935. this._ensureDownloadComplete();
  936. const data = await this.pdfDocument.saveDocument();
  937. const blob = new Blob([data], {
  938. type: "application/pdf"
  939. });
  940. await this.downloadManager.download(blob, url, filename, sourceEventType);
  941. } catch (reason) {
  942. await this.download({
  943. sourceEventType
  944. });
  945. } finally {
  946. await this.pdfScriptingManager.dispatchDidSave();
  947. this._saveInProgress = false;
  948. }
  949. },
  950. downloadOrSave(options) {
  951. if (this.pdfDocument?.annotationStorage.size > 0) {
  952. this.save(options);
  953. } else {
  954. this.download(options);
  955. }
  956. },
  957. fallback(featureId) {
  958. this.externalServices.reportTelemetry({
  959. type: "unsupportedFeature",
  960. featureId
  961. });
  962. if (this._fellback) {
  963. return;
  964. }
  965. this._fellback = true;
  966. this.externalServices.fallback({
  967. featureId,
  968. url: this.baseUrl
  969. }).then(download => {
  970. if (!download) {
  971. return;
  972. }
  973. this.download({
  974. sourceEventType: "download"
  975. });
  976. });
  977. },
  978. _documentError(message, moreInfo = null) {
  979. this._unblockDocumentLoadEvent();
  980. this._otherError(message, moreInfo);
  981. },
  982. _otherError(message, moreInfo = null) {
  983. const moreInfoText = [this.l10n.get("error_version_info", {
  984. version: _pdfjsLib.version || "?",
  985. build: _pdfjsLib.build || "?"
  986. })];
  987. if (moreInfo) {
  988. moreInfoText.push(this.l10n.get("error_message", {
  989. message: moreInfo.message
  990. }));
  991. if (moreInfo.stack) {
  992. moreInfoText.push(this.l10n.get("error_stack", {
  993. stack: moreInfo.stack
  994. }));
  995. } else {
  996. if (moreInfo.filename) {
  997. moreInfoText.push(this.l10n.get("error_file", {
  998. file: moreInfo.filename
  999. }));
  1000. }
  1001. if (moreInfo.lineNumber) {
  1002. moreInfoText.push(this.l10n.get("error_line", {
  1003. line: moreInfo.lineNumber
  1004. }));
  1005. }
  1006. }
  1007. }
  1008. const errorWrapperConfig = this.appConfig.errorWrapper;
  1009. const errorWrapper = errorWrapperConfig.container;
  1010. errorWrapper.hidden = false;
  1011. const errorMessage = errorWrapperConfig.errorMessage;
  1012. errorMessage.textContent = message;
  1013. const closeButton = errorWrapperConfig.closeButton;
  1014. closeButton.onclick = function () {
  1015. errorWrapper.hidden = true;
  1016. };
  1017. const errorMoreInfo = errorWrapperConfig.errorMoreInfo;
  1018. const moreInfoButton = errorWrapperConfig.moreInfoButton;
  1019. const lessInfoButton = errorWrapperConfig.lessInfoButton;
  1020. moreInfoButton.onclick = function () {
  1021. errorMoreInfo.hidden = false;
  1022. moreInfoButton.hidden = true;
  1023. lessInfoButton.hidden = false;
  1024. errorMoreInfo.style.height = errorMoreInfo.scrollHeight + "px";
  1025. };
  1026. lessInfoButton.onclick = function () {
  1027. errorMoreInfo.hidden = true;
  1028. moreInfoButton.hidden = false;
  1029. lessInfoButton.hidden = true;
  1030. };
  1031. moreInfoButton.oncontextmenu = _ui_utils.noContextMenuHandler;
  1032. lessInfoButton.oncontextmenu = _ui_utils.noContextMenuHandler;
  1033. closeButton.oncontextmenu = _ui_utils.noContextMenuHandler;
  1034. moreInfoButton.hidden = false;
  1035. lessInfoButton.hidden = true;
  1036. Promise.all(moreInfoText).then(parts => {
  1037. errorMoreInfo.value = parts.join("\n");
  1038. });
  1039. },
  1040. progress(level) {
  1041. if (this.downloadComplete) {
  1042. return;
  1043. }
  1044. const percent = Math.round(level * 100);
  1045. if (percent > this.loadingBar.percent || isNaN(percent)) {
  1046. this.loadingBar.percent = percent;
  1047. const disableAutoFetch = this.pdfDocument ? this.pdfDocument.loadingParams.disableAutoFetch : _app_options.AppOptions.get("disableAutoFetch");
  1048. if (disableAutoFetch && percent) {
  1049. if (this.disableAutoFetchLoadingBarTimeout) {
  1050. clearTimeout(this.disableAutoFetchLoadingBarTimeout);
  1051. this.disableAutoFetchLoadingBarTimeout = null;
  1052. }
  1053. this.loadingBar.show();
  1054. this.disableAutoFetchLoadingBarTimeout = setTimeout(() => {
  1055. this.loadingBar.hide();
  1056. this.disableAutoFetchLoadingBarTimeout = null;
  1057. }, DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT);
  1058. }
  1059. }
  1060. },
  1061. load(pdfDocument) {
  1062. this.pdfDocument = pdfDocument;
  1063. pdfDocument.getDownloadInfo().then(({
  1064. length
  1065. }) => {
  1066. this._contentLength = length;
  1067. this.downloadComplete = true;
  1068. this.loadingBar.hide();
  1069. firstPagePromise.then(() => {
  1070. this.eventBus.dispatch("documentloaded", {
  1071. source: this
  1072. });
  1073. });
  1074. });
  1075. const pageLayoutPromise = pdfDocument.getPageLayout().catch(function () {});
  1076. const pageModePromise = pdfDocument.getPageMode().catch(function () {});
  1077. const openActionPromise = pdfDocument.getOpenAction().catch(function () {});
  1078. this.toolbar.setPagesCount(pdfDocument.numPages, false);
  1079. this.secondaryToolbar.setPagesCount(pdfDocument.numPages);
  1080. let baseDocumentUrl;
  1081. baseDocumentUrl = null;
  1082. this.pdfLinkService.setDocument(pdfDocument, baseDocumentUrl);
  1083. this.pdfDocumentProperties.setDocument(pdfDocument, this.url);
  1084. const pdfViewer = this.pdfViewer;
  1085. pdfViewer.setDocument(pdfDocument);
  1086. const {
  1087. firstPagePromise,
  1088. onePageRendered,
  1089. pagesPromise
  1090. } = pdfViewer;
  1091. const pdfThumbnailViewer = this.pdfThumbnailViewer;
  1092. pdfThumbnailViewer.setDocument(pdfDocument);
  1093. const storedPromise = (this.store = new _view_history.ViewHistory(pdfDocument.fingerprints[0])).getMultiple({
  1094. page: null,
  1095. zoom: _ui_utils.DEFAULT_SCALE_VALUE,
  1096. scrollLeft: "0",
  1097. scrollTop: "0",
  1098. rotation: null,
  1099. sidebarView: _ui_utils.SidebarView.UNKNOWN,
  1100. scrollMode: _ui_utils.ScrollMode.UNKNOWN,
  1101. spreadMode: _ui_utils.SpreadMode.UNKNOWN
  1102. }).catch(() => {
  1103. return Object.create(null);
  1104. });
  1105. firstPagePromise.then(pdfPage => {
  1106. this.loadingBar.setWidth(this.appConfig.viewerContainer);
  1107. this._initializeAnnotationStorageCallbacks(pdfDocument);
  1108. Promise.all([_ui_utils.animationStarted, storedPromise, pageLayoutPromise, pageModePromise, openActionPromise]).then(async ([timeStamp, stored, pageLayout, pageMode, openAction]) => {
  1109. const viewOnLoad = _app_options.AppOptions.get("viewOnLoad");
  1110. this._initializePdfHistory({
  1111. fingerprint: pdfDocument.fingerprints[0],
  1112. viewOnLoad,
  1113. initialDest: openAction?.dest
  1114. });
  1115. const initialBookmark = this.initialBookmark;
  1116. const zoom = _app_options.AppOptions.get("defaultZoomValue");
  1117. let hash = zoom ? `zoom=${zoom}` : null;
  1118. let rotation = null;
  1119. let sidebarView = _app_options.AppOptions.get("sidebarViewOnLoad");
  1120. let scrollMode = _app_options.AppOptions.get("scrollModeOnLoad");
  1121. let spreadMode = _app_options.AppOptions.get("spreadModeOnLoad");
  1122. if (stored.page && viewOnLoad !== ViewOnLoad.INITIAL) {
  1123. hash = `page=${stored.page}&zoom=${zoom || stored.zoom},` + `${stored.scrollLeft},${stored.scrollTop}`;
  1124. rotation = parseInt(stored.rotation, 10);
  1125. if (sidebarView === _ui_utils.SidebarView.UNKNOWN) {
  1126. sidebarView = stored.sidebarView | 0;
  1127. }
  1128. if (scrollMode === _ui_utils.ScrollMode.UNKNOWN) {
  1129. scrollMode = stored.scrollMode | 0;
  1130. }
  1131. if (spreadMode === _ui_utils.SpreadMode.UNKNOWN) {
  1132. spreadMode = stored.spreadMode | 0;
  1133. }
  1134. }
  1135. if (pageMode && sidebarView === _ui_utils.SidebarView.UNKNOWN) {
  1136. sidebarView = (0, _ui_utils.apiPageModeToSidebarView)(pageMode);
  1137. }
  1138. if (pageLayout && spreadMode === _ui_utils.SpreadMode.UNKNOWN) {
  1139. spreadMode = (0, _ui_utils.apiPageLayoutToSpreadMode)(pageLayout);
  1140. }
  1141. this.setInitialView(hash, {
  1142. rotation,
  1143. sidebarView,
  1144. scrollMode,
  1145. spreadMode
  1146. });
  1147. this.eventBus.dispatch("documentinit", {
  1148. source: this
  1149. });
  1150. if (!this.isViewerEmbedded) {
  1151. pdfViewer.focus();
  1152. }
  1153. this._initializePermissions(pdfDocument);
  1154. await Promise.race([pagesPromise, new Promise(resolve => {
  1155. setTimeout(resolve, FORCE_PAGES_LOADED_TIMEOUT);
  1156. })]);
  1157. if (!initialBookmark && !hash) {
  1158. return;
  1159. }
  1160. if (pdfViewer.hasEqualPageSizes) {
  1161. return;
  1162. }
  1163. this.initialBookmark = initialBookmark;
  1164. pdfViewer.currentScaleValue = pdfViewer.currentScaleValue;
  1165. this.setInitialView(hash);
  1166. }).catch(() => {
  1167. this.setInitialView();
  1168. }).then(function () {
  1169. pdfViewer.update();
  1170. });
  1171. });
  1172. pagesPromise.then(() => {
  1173. this._unblockDocumentLoadEvent();
  1174. this._initializeAutoPrint(pdfDocument, openActionPromise);
  1175. });
  1176. onePageRendered.then(() => {
  1177. pdfDocument.getOutline().then(outline => {
  1178. if (pdfDocument !== this.pdfDocument) {
  1179. return;
  1180. }
  1181. this.pdfOutlineViewer.render({
  1182. outline,
  1183. pdfDocument
  1184. });
  1185. });
  1186. pdfDocument.getAttachments().then(attachments => {
  1187. if (pdfDocument !== this.pdfDocument) {
  1188. return;
  1189. }
  1190. this.pdfAttachmentViewer.render({
  1191. attachments
  1192. });
  1193. });
  1194. pdfViewer.optionalContentConfigPromise.then(optionalContentConfig => {
  1195. if (pdfDocument !== this.pdfDocument) {
  1196. return;
  1197. }
  1198. this.pdfLayerViewer.render({
  1199. optionalContentConfig,
  1200. pdfDocument
  1201. });
  1202. });
  1203. if ("requestIdleCallback" in window) {
  1204. const callback = window.requestIdleCallback(() => {
  1205. this._collectTelemetry(pdfDocument);
  1206. this._idleCallbacks.delete(callback);
  1207. }, {
  1208. timeout: 1000
  1209. });
  1210. this._idleCallbacks.add(callback);
  1211. }
  1212. });
  1213. this._initializePageLabels(pdfDocument);
  1214. this._initializeMetadata(pdfDocument);
  1215. },
  1216. async _scriptingDocProperties(pdfDocument) {
  1217. if (!this.documentInfo) {
  1218. await new Promise(resolve => {
  1219. this.eventBus._on("metadataloaded", resolve, {
  1220. once: true
  1221. });
  1222. });
  1223. if (pdfDocument !== this.pdfDocument) {
  1224. return null;
  1225. }
  1226. }
  1227. if (!this._contentLength) {
  1228. await new Promise(resolve => {
  1229. this.eventBus._on("documentloaded", resolve, {
  1230. once: true
  1231. });
  1232. });
  1233. if (pdfDocument !== this.pdfDocument) {
  1234. return null;
  1235. }
  1236. }
  1237. return { ...this.documentInfo,
  1238. baseURL: this.baseUrl,
  1239. filesize: this._contentLength,
  1240. filename: this._docFilename,
  1241. metadata: this.metadata?.getRaw(),
  1242. authors: this.metadata?.get("dc:creator"),
  1243. numPages: this.pagesCount,
  1244. URL: this.url
  1245. };
  1246. },
  1247. async _collectTelemetry(pdfDocument) {
  1248. const markInfo = await this.pdfDocument.getMarkInfo();
  1249. if (pdfDocument !== this.pdfDocument) {
  1250. return;
  1251. }
  1252. const tagged = markInfo?.Marked || false;
  1253. this.externalServices.reportTelemetry({
  1254. type: "tagged",
  1255. tagged
  1256. });
  1257. },
  1258. async _initializeAutoPrint(pdfDocument, openActionPromise) {
  1259. const [openAction, javaScript] = await Promise.all([openActionPromise, !this.pdfViewer.enableScripting ? pdfDocument.getJavaScript() : null]);
  1260. if (pdfDocument !== this.pdfDocument) {
  1261. return;
  1262. }
  1263. let triggerAutoPrint = false;
  1264. if (openAction?.action === "Print") {
  1265. triggerAutoPrint = true;
  1266. }
  1267. if (javaScript) {
  1268. javaScript.some(js => {
  1269. if (!js) {
  1270. return false;
  1271. }
  1272. console.warn("Warning: JavaScript support is not enabled");
  1273. this.fallback(_pdfjsLib.UNSUPPORTED_FEATURES.javaScript);
  1274. return true;
  1275. });
  1276. if (!triggerAutoPrint) {
  1277. for (const js of javaScript) {
  1278. if (js && _ui_utils.AutoPrintRegExp.test(js)) {
  1279. triggerAutoPrint = true;
  1280. break;
  1281. }
  1282. }
  1283. }
  1284. }
  1285. if (triggerAutoPrint) {
  1286. this.triggerPrinting();
  1287. }
  1288. },
  1289. async _initializeMetadata(pdfDocument) {
  1290. const {
  1291. info,
  1292. metadata,
  1293. contentDispositionFilename,
  1294. contentLength
  1295. } = await pdfDocument.getMetadata();
  1296. if (pdfDocument !== this.pdfDocument) {
  1297. return;
  1298. }
  1299. this.documentInfo = info;
  1300. this.metadata = metadata;
  1301. this._contentDispositionFilename ?? (this._contentDispositionFilename = contentDispositionFilename);
  1302. this._contentLength ?? (this._contentLength = contentLength);
  1303. console.log(`PDF ${pdfDocument.fingerprints[0]} [${info.PDFFormatVersion} ` + `${(info.Producer || "-").trim()} / ${(info.Creator || "-").trim()}] ` + `(PDF.js: ${_pdfjsLib.version || "-"})`);
  1304. let pdfTitle = info?.Title;
  1305. const metadataTitle = metadata?.get("dc:title");
  1306. if (metadataTitle) {
  1307. if (metadataTitle !== "Untitled" && !/[\uFFF0-\uFFFF]/g.test(metadataTitle)) {
  1308. pdfTitle = metadataTitle;
  1309. }
  1310. }
  1311. if (pdfTitle) {
  1312. this.setTitle(`${pdfTitle} - ${contentDispositionFilename || document.title}`);
  1313. } else if (contentDispositionFilename) {
  1314. this.setTitle(contentDispositionFilename);
  1315. }
  1316. if (info.IsXFAPresent && !info.IsAcroFormPresent && !pdfDocument.isPureXfa) {
  1317. console.warn("Warning: XFA support is not enabled");
  1318. this.fallback(_pdfjsLib.UNSUPPORTED_FEATURES.forms);
  1319. } else if ((info.IsAcroFormPresent || info.IsXFAPresent) && !this.pdfViewer.renderInteractiveForms) {
  1320. console.warn("Warning: Interactive form support is not enabled");
  1321. this.fallback(_pdfjsLib.UNSUPPORTED_FEATURES.forms);
  1322. }
  1323. if (info.IsSignaturesPresent) {
  1324. console.warn("Warning: Digital signatures validation is not supported");
  1325. this.fallback(_pdfjsLib.UNSUPPORTED_FEATURES.signatures);
  1326. }
  1327. let versionId = "other";
  1328. if (KNOWN_VERSIONS.includes(info.PDFFormatVersion)) {
  1329. versionId = `v${info.PDFFormatVersion.replace(".", "_")}`;
  1330. }
  1331. let generatorId = "other";
  1332. if (info.Producer) {
  1333. const producer = info.Producer.toLowerCase();
  1334. KNOWN_GENERATORS.some(function (generator) {
  1335. if (!producer.includes(generator)) {
  1336. return false;
  1337. }
  1338. generatorId = generator.replace(/[ .-]/g, "_");
  1339. return true;
  1340. });
  1341. }
  1342. let formType = null;
  1343. if (info.IsXFAPresent) {
  1344. formType = "xfa";
  1345. } else if (info.IsAcroFormPresent) {
  1346. formType = "acroform";
  1347. }
  1348. this.externalServices.reportTelemetry({
  1349. type: "documentInfo",
  1350. version: versionId,
  1351. generator: generatorId,
  1352. formType
  1353. });
  1354. this.eventBus.dispatch("metadataloaded", {
  1355. source: this
  1356. });
  1357. },
  1358. async _initializePageLabels(pdfDocument) {
  1359. const labels = await pdfDocument.getPageLabels();
  1360. if (pdfDocument !== this.pdfDocument) {
  1361. return;
  1362. }
  1363. if (!labels || _app_options.AppOptions.get("disablePageLabels")) {
  1364. return;
  1365. }
  1366. const numLabels = labels.length;
  1367. if (numLabels !== this.pagesCount) {
  1368. console.error("The number of Page Labels does not match the number of pages in the document.");
  1369. return;
  1370. }
  1371. let i = 0;
  1372. while (i < numLabels && labels[i] === (i + 1).toString()) {
  1373. i++;
  1374. }
  1375. if (i === numLabels) {
  1376. return;
  1377. }
  1378. const {
  1379. pdfViewer,
  1380. pdfThumbnailViewer,
  1381. toolbar
  1382. } = this;
  1383. pdfViewer.setPageLabels(labels);
  1384. pdfThumbnailViewer.setPageLabels(labels);
  1385. toolbar.setPagesCount(numLabels, true);
  1386. toolbar.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
  1387. },
  1388. _initializePdfHistory({
  1389. fingerprint,
  1390. viewOnLoad,
  1391. initialDest = null
  1392. }) {
  1393. if (this.isViewerEmbedded || _app_options.AppOptions.get("disableHistory")) {
  1394. return;
  1395. }
  1396. this.pdfHistory.initialize({
  1397. fingerprint,
  1398. resetHistory: viewOnLoad === ViewOnLoad.INITIAL,
  1399. updateUrl: _app_options.AppOptions.get("historyUpdateUrl")
  1400. });
  1401. if (this.pdfHistory.initialBookmark) {
  1402. this.initialBookmark = this.pdfHistory.initialBookmark;
  1403. this.initialRotation = this.pdfHistory.initialRotation;
  1404. }
  1405. if (initialDest && !this.initialBookmark && viewOnLoad === ViewOnLoad.UNKNOWN) {
  1406. this.initialBookmark = JSON.stringify(initialDest);
  1407. this.pdfHistory.push({
  1408. explicitDest: initialDest,
  1409. pageNumber: null
  1410. });
  1411. }
  1412. },
  1413. async _initializePermissions(pdfDocument) {
  1414. const permissions = await pdfDocument.getPermissions();
  1415. if (pdfDocument !== this.pdfDocument) {
  1416. return;
  1417. }
  1418. if (!permissions || !_app_options.AppOptions.get("enablePermissions")) {
  1419. return;
  1420. }
  1421. if (!permissions.includes(_pdfjsLib.PermissionFlag.COPY)) {
  1422. this.appConfig.viewerContainer.classList.add(ENABLE_PERMISSIONS_CLASS);
  1423. }
  1424. },
  1425. _initializeAnnotationStorageCallbacks(pdfDocument) {
  1426. if (pdfDocument !== this.pdfDocument) {
  1427. return;
  1428. }
  1429. const {
  1430. annotationStorage
  1431. } = pdfDocument;
  1432. annotationStorage.onSetModified = () => {
  1433. window.addEventListener("beforeunload", beforeUnload);
  1434. this._annotationStorageModified = true;
  1435. };
  1436. annotationStorage.onResetModified = () => {
  1437. window.removeEventListener("beforeunload", beforeUnload);
  1438. delete this._annotationStorageModified;
  1439. };
  1440. },
  1441. setInitialView(storedHash, {
  1442. rotation,
  1443. sidebarView,
  1444. scrollMode,
  1445. spreadMode
  1446. } = {}) {
  1447. const setRotation = angle => {
  1448. if ((0, _ui_utils.isValidRotation)(angle)) {
  1449. this.pdfViewer.pagesRotation = angle;
  1450. }
  1451. };
  1452. const setViewerModes = (scroll, spread) => {
  1453. if ((0, _ui_utils.isValidScrollMode)(scroll)) {
  1454. this.pdfViewer.scrollMode = scroll;
  1455. }
  1456. if ((0, _ui_utils.isValidSpreadMode)(spread)) {
  1457. this.pdfViewer.spreadMode = spread;
  1458. }
  1459. };
  1460. this.isInitialViewSet = true;
  1461. this.pdfSidebar.setInitialView(sidebarView);
  1462. setViewerModes(scrollMode, spreadMode);
  1463. if (this.initialBookmark) {
  1464. setRotation(this.initialRotation);
  1465. delete this.initialRotation;
  1466. this.pdfLinkService.setHash(this.initialBookmark);
  1467. this.initialBookmark = null;
  1468. } else if (storedHash) {
  1469. setRotation(rotation);
  1470. this.pdfLinkService.setHash(storedHash);
  1471. }
  1472. this.toolbar.setPageNumber(this.pdfViewer.currentPageNumber, this.pdfViewer.currentPageLabel);
  1473. this.secondaryToolbar.setPageNumber(this.pdfViewer.currentPageNumber);
  1474. if (!this.pdfViewer.currentScaleValue) {
  1475. this.pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  1476. }
  1477. },
  1478. _cleanup() {
  1479. if (!this.pdfDocument) {
  1480. return;
  1481. }
  1482. this.pdfViewer.cleanup();
  1483. this.pdfThumbnailViewer.cleanup();
  1484. this.pdfDocument.cleanup(this.pdfViewer.renderer === _ui_utils.RendererType.SVG);
  1485. },
  1486. forceRendering() {
  1487. this.pdfRenderingQueue.printing = !!this.printService;
  1488. this.pdfRenderingQueue.isThumbnailViewEnabled = this.pdfSidebar.isThumbnailViewVisible;
  1489. this.pdfRenderingQueue.renderHighestPriority();
  1490. },
  1491. beforePrint() {
  1492. this.pdfScriptingManager.dispatchWillPrint();
  1493. if (this.printService) {
  1494. return;
  1495. }
  1496. if (!this.supportsPrinting) {
  1497. this.l10n.get("printing_not_supported").then(msg => {
  1498. this._otherError(msg);
  1499. });
  1500. return;
  1501. }
  1502. if (!this.pdfViewer.pageViewsReady) {
  1503. this.l10n.get("printing_not_ready").then(msg => {
  1504. window.alert(msg);
  1505. });
  1506. return;
  1507. }
  1508. const pagesOverview = this.pdfViewer.getPagesOverview();
  1509. const printContainer = this.appConfig.printContainer;
  1510. const printResolution = _app_options.AppOptions.get("printResolution");
  1511. const optionalContentConfigPromise = this.pdfViewer.optionalContentConfigPromise;
  1512. const printService = PDFPrintServiceFactory.instance.createPrintService(this.pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise, this.l10n);
  1513. this.printService = printService;
  1514. this.forceRendering();
  1515. printService.layout();
  1516. this.externalServices.reportTelemetry({
  1517. type: "print"
  1518. });
  1519. },
  1520. afterPrint() {
  1521. this.pdfScriptingManager.dispatchDidPrint();
  1522. if (this.printService) {
  1523. this.printService.destroy();
  1524. this.printService = null;
  1525. if (this.pdfDocument) {
  1526. this.pdfDocument.annotationStorage.resetModified();
  1527. }
  1528. }
  1529. this.forceRendering();
  1530. },
  1531. rotatePages(delta) {
  1532. this.pdfViewer.pagesRotation += delta;
  1533. },
  1534. requestPresentationMode() {
  1535. if (!this.pdfPresentationMode) {
  1536. return;
  1537. }
  1538. this.pdfPresentationMode.request();
  1539. },
  1540. triggerPrinting() {
  1541. if (!this.supportsPrinting) {
  1542. return;
  1543. }
  1544. window.print();
  1545. },
  1546. bindEvents() {
  1547. const {
  1548. eventBus,
  1549. _boundEvents
  1550. } = this;
  1551. _boundEvents.beforePrint = this.beforePrint.bind(this);
  1552. _boundEvents.afterPrint = this.afterPrint.bind(this);
  1553. eventBus._on("resize", webViewerResize);
  1554. eventBus._on("hashchange", webViewerHashchange);
  1555. eventBus._on("beforeprint", _boundEvents.beforePrint);
  1556. eventBus._on("afterprint", _boundEvents.afterPrint);
  1557. eventBus._on("pagerendered", webViewerPageRendered);
  1558. eventBus._on("updateviewarea", webViewerUpdateViewarea);
  1559. eventBus._on("pagechanging", webViewerPageChanging);
  1560. eventBus._on("scalechanging", webViewerScaleChanging);
  1561. eventBus._on("rotationchanging", webViewerRotationChanging);
  1562. eventBus._on("sidebarviewchanged", webViewerSidebarViewChanged);
  1563. eventBus._on("pagemode", webViewerPageMode);
  1564. eventBus._on("namedaction", webViewerNamedAction);
  1565. eventBus._on("presentationmodechanged", webViewerPresentationModeChanged);
  1566. eventBus._on("presentationmode", webViewerPresentationMode);
  1567. eventBus._on("print", webViewerPrint);
  1568. eventBus._on("download", webViewerDownload);
  1569. eventBus._on("save", webViewerSave);
  1570. eventBus._on("firstpage", webViewerFirstPage);
  1571. eventBus._on("lastpage", webViewerLastPage);
  1572. eventBus._on("nextpage", webViewerNextPage);
  1573. eventBus._on("previouspage", webViewerPreviousPage);
  1574. eventBus._on("zoomin", webViewerZoomIn);
  1575. eventBus._on("zoomout", webViewerZoomOut);
  1576. eventBus._on("zoomreset", webViewerZoomReset);
  1577. eventBus._on("pagenumberchanged", webViewerPageNumberChanged);
  1578. eventBus._on("scalechanged", webViewerScaleChanged);
  1579. eventBus._on("rotatecw", webViewerRotateCw);
  1580. eventBus._on("rotateccw", webViewerRotateCcw);
  1581. eventBus._on("optionalcontentconfig", webViewerOptionalContentConfig);
  1582. eventBus._on("switchscrollmode", webViewerSwitchScrollMode);
  1583. eventBus._on("scrollmodechanged", webViewerScrollModeChanged);
  1584. eventBus._on("switchspreadmode", webViewerSwitchSpreadMode);
  1585. eventBus._on("spreadmodechanged", webViewerSpreadModeChanged);
  1586. eventBus._on("documentproperties", webViewerDocumentProperties);
  1587. eventBus._on("find", webViewerFind);
  1588. eventBus._on("findfromurlhash", webViewerFindFromUrlHash);
  1589. eventBus._on("updatefindmatchescount", webViewerUpdateFindMatchesCount);
  1590. eventBus._on("updatefindcontrolstate", webViewerUpdateFindControlState);
  1591. if (_app_options.AppOptions.get("pdfBug")) {
  1592. _boundEvents.reportPageStatsPDFBug = reportPageStatsPDFBug;
  1593. eventBus._on("pagerendered", _boundEvents.reportPageStatsPDFBug);
  1594. eventBus._on("pagechanging", _boundEvents.reportPageStatsPDFBug);
  1595. }
  1596. eventBus._on("fileinputchange", webViewerFileInputChange);
  1597. eventBus._on("openfile", webViewerOpenFile);
  1598. },
  1599. bindWindowEvents() {
  1600. const {
  1601. eventBus,
  1602. _boundEvents
  1603. } = this;
  1604. _boundEvents.windowResize = () => {
  1605. eventBus.dispatch("resize", {
  1606. source: window
  1607. });
  1608. };
  1609. _boundEvents.windowHashChange = () => {
  1610. eventBus.dispatch("hashchange", {
  1611. source: window,
  1612. hash: document.location.hash.substring(1)
  1613. });
  1614. };
  1615. _boundEvents.windowBeforePrint = () => {
  1616. eventBus.dispatch("beforeprint", {
  1617. source: window
  1618. });
  1619. };
  1620. _boundEvents.windowAfterPrint = () => {
  1621. eventBus.dispatch("afterprint", {
  1622. source: window
  1623. });
  1624. };
  1625. _boundEvents.windowUpdateFromSandbox = event => {
  1626. eventBus.dispatch("updatefromsandbox", {
  1627. source: window,
  1628. detail: event.detail
  1629. });
  1630. };
  1631. window.addEventListener("visibilitychange", webViewerVisibilityChange);
  1632. window.addEventListener("wheel", webViewerWheel, {
  1633. passive: false
  1634. });
  1635. window.addEventListener("touchstart", webViewerTouchStart, {
  1636. passive: false
  1637. });
  1638. window.addEventListener("click", webViewerClick);
  1639. window.addEventListener("keydown", webViewerKeyDown);
  1640. window.addEventListener("resize", _boundEvents.windowResize);
  1641. window.addEventListener("hashchange", _boundEvents.windowHashChange);
  1642. window.addEventListener("beforeprint", _boundEvents.windowBeforePrint);
  1643. window.addEventListener("afterprint", _boundEvents.windowAfterPrint);
  1644. window.addEventListener("updatefromsandbox", _boundEvents.windowUpdateFromSandbox);
  1645. },
  1646. unbindEvents() {
  1647. const {
  1648. eventBus,
  1649. _boundEvents
  1650. } = this;
  1651. eventBus._off("resize", webViewerResize);
  1652. eventBus._off("hashchange", webViewerHashchange);
  1653. eventBus._off("beforeprint", _boundEvents.beforePrint);
  1654. eventBus._off("afterprint", _boundEvents.afterPrint);
  1655. eventBus._off("pagerendered", webViewerPageRendered);
  1656. eventBus._off("updateviewarea", webViewerUpdateViewarea);
  1657. eventBus._off("pagechanging", webViewerPageChanging);
  1658. eventBus._off("scalechanging", webViewerScaleChanging);
  1659. eventBus._off("rotationchanging", webViewerRotationChanging);
  1660. eventBus._off("sidebarviewchanged", webViewerSidebarViewChanged);
  1661. eventBus._off("pagemode", webViewerPageMode);
  1662. eventBus._off("namedaction", webViewerNamedAction);
  1663. eventBus._off("presentationmodechanged", webViewerPresentationModeChanged);
  1664. eventBus._off("presentationmode", webViewerPresentationMode);
  1665. eventBus._off("print", webViewerPrint);
  1666. eventBus._off("download", webViewerDownload);
  1667. eventBus._off("save", webViewerSave);
  1668. eventBus._off("firstpage", webViewerFirstPage);
  1669. eventBus._off("lastpage", webViewerLastPage);
  1670. eventBus._off("nextpage", webViewerNextPage);
  1671. eventBus._off("previouspage", webViewerPreviousPage);
  1672. eventBus._off("zoomin", webViewerZoomIn);
  1673. eventBus._off("zoomout", webViewerZoomOut);
  1674. eventBus._off("zoomreset", webViewerZoomReset);
  1675. eventBus._off("pagenumberchanged", webViewerPageNumberChanged);
  1676. eventBus._off("scalechanged", webViewerScaleChanged);
  1677. eventBus._off("rotatecw", webViewerRotateCw);
  1678. eventBus._off("rotateccw", webViewerRotateCcw);
  1679. eventBus._off("optionalcontentconfig", webViewerOptionalContentConfig);
  1680. eventBus._off("switchscrollmode", webViewerSwitchScrollMode);
  1681. eventBus._off("scrollmodechanged", webViewerScrollModeChanged);
  1682. eventBus._off("switchspreadmode", webViewerSwitchSpreadMode);
  1683. eventBus._off("spreadmodechanged", webViewerSpreadModeChanged);
  1684. eventBus._off("documentproperties", webViewerDocumentProperties);
  1685. eventBus._off("find", webViewerFind);
  1686. eventBus._off("findfromurlhash", webViewerFindFromUrlHash);
  1687. eventBus._off("updatefindmatchescount", webViewerUpdateFindMatchesCount);
  1688. eventBus._off("updatefindcontrolstate", webViewerUpdateFindControlState);
  1689. if (_boundEvents.reportPageStatsPDFBug) {
  1690. eventBus._off("pagerendered", _boundEvents.reportPageStatsPDFBug);
  1691. eventBus._off("pagechanging", _boundEvents.reportPageStatsPDFBug);
  1692. _boundEvents.reportPageStatsPDFBug = null;
  1693. }
  1694. eventBus._off("fileinputchange", webViewerFileInputChange);
  1695. eventBus._off("openfile", webViewerOpenFile);
  1696. _boundEvents.beforePrint = null;
  1697. _boundEvents.afterPrint = null;
  1698. },
  1699. unbindWindowEvents() {
  1700. const {
  1701. _boundEvents
  1702. } = this;
  1703. window.removeEventListener("visibilitychange", webViewerVisibilityChange);
  1704. window.removeEventListener("wheel", webViewerWheel, {
  1705. passive: false
  1706. });
  1707. window.removeEventListener("touchstart", webViewerTouchStart, {
  1708. passive: false
  1709. });
  1710. window.removeEventListener("click", webViewerClick);
  1711. window.removeEventListener("keydown", webViewerKeyDown);
  1712. window.removeEventListener("resize", _boundEvents.windowResize);
  1713. window.removeEventListener("hashchange", _boundEvents.windowHashChange);
  1714. window.removeEventListener("beforeprint", _boundEvents.windowBeforePrint);
  1715. window.removeEventListener("afterprint", _boundEvents.windowAfterPrint);
  1716. window.removeEventListener("updatefromsandbox", _boundEvents.windowUpdateFromSandbox);
  1717. _boundEvents.windowResize = null;
  1718. _boundEvents.windowHashChange = null;
  1719. _boundEvents.windowBeforePrint = null;
  1720. _boundEvents.windowAfterPrint = null;
  1721. _boundEvents.windowUpdateFromSandbox = null;
  1722. },
  1723. accumulateWheelTicks(ticks) {
  1724. if (this._wheelUnusedTicks > 0 && ticks < 0 || this._wheelUnusedTicks < 0 && ticks > 0) {
  1725. this._wheelUnusedTicks = 0;
  1726. }
  1727. this._wheelUnusedTicks += ticks;
  1728. const wholeTicks = Math.sign(this._wheelUnusedTicks) * Math.floor(Math.abs(this._wheelUnusedTicks));
  1729. this._wheelUnusedTicks -= wholeTicks;
  1730. return wholeTicks;
  1731. },
  1732. _unblockDocumentLoadEvent() {
  1733. if (document.blockUnblockOnload) {
  1734. document.blockUnblockOnload(false);
  1735. }
  1736. this._unblockDocumentLoadEvent = () => {};
  1737. },
  1738. get scriptingReady() {
  1739. return this.pdfScriptingManager.ready;
  1740. }
  1741. };
  1742. exports.PDFViewerApplication = PDFViewerApplication;
  1743. let validateFileURL = function (file) {return;};
  1744. async function loadFakeWorker() {
  1745. if (!_pdfjsLib.GlobalWorkerOptions.workerSrc) {
  1746. _pdfjsLib.GlobalWorkerOptions.workerSrc = _app_options.AppOptions.get("workerSrc");
  1747. }
  1748. return (0, _pdfjsLib.loadScript)(_pdfjsLib.PDFWorker.getWorkerSrc());
  1749. }
  1750. function loadAndEnablePDFBug(enabledTabs) {
  1751. const appConfig = PDFViewerApplication.appConfig;
  1752. return (0, _pdfjsLib.loadScript)(appConfig.debuggerScriptPath).then(function () {
  1753. PDFBug.enable(enabledTabs);
  1754. PDFBug.init({
  1755. OPS: _pdfjsLib.OPS
  1756. }, appConfig.mainContainer);
  1757. });
  1758. }
  1759. function reportPageStatsPDFBug({
  1760. pageNumber
  1761. }) {
  1762. if (typeof Stats === "undefined" || !Stats.enabled) {
  1763. return;
  1764. }
  1765. const pageView = PDFViewerApplication.pdfViewer.getPageView(pageNumber - 1);
  1766. const pageStats = pageView?.pdfPage?.stats;
  1767. if (!pageStats) {
  1768. return;
  1769. }
  1770. Stats.add(pageNumber, pageStats);
  1771. }
  1772. function webViewerInitialized() {
  1773. const appConfig = PDFViewerApplication.appConfig;
  1774. let file;
  1775. const queryString = document.location.search.substring(1);
  1776. const params = (0, _ui_utils.parseQueryString)(queryString);
  1777. file = "file" in params ? params.file : _app_options.AppOptions.get("defaultUrl");
  1778. validateFileURL(file);
  1779. const fileInput = document.createElement("input");
  1780. fileInput.id = appConfig.openFileInputName;
  1781. fileInput.className = "fileInput";
  1782. fileInput.setAttribute("type", "file");
  1783. fileInput.oncontextmenu = _ui_utils.noContextMenuHandler;
  1784. document.body.appendChild(fileInput);
  1785. if (!window.File || !window.FileReader || !window.FileList || !window.Blob) {
  1786. appConfig.toolbar.openFile.hidden = true;
  1787. appConfig.secondaryToolbar.openFileButton.hidden = true;
  1788. } else {
  1789. fileInput.value = null;
  1790. }
  1791. fileInput.addEventListener("change", function (evt) {
  1792. const files = evt.target.files;
  1793. if (!files || files.length === 0) {
  1794. return;
  1795. }
  1796. PDFViewerApplication.eventBus.dispatch("fileinputchange", {
  1797. source: this,
  1798. fileInput: evt.target
  1799. });
  1800. });
  1801. appConfig.mainContainer.addEventListener("dragover", function (evt) {
  1802. evt.preventDefault();
  1803. evt.dataTransfer.dropEffect = "move";
  1804. });
  1805. appConfig.mainContainer.addEventListener("drop", function (evt) {
  1806. evt.preventDefault();
  1807. const files = evt.dataTransfer.files;
  1808. if (!files || files.length === 0) {
  1809. return;
  1810. }
  1811. PDFViewerApplication.eventBus.dispatch("fileinputchange", {
  1812. source: this,
  1813. fileInput: evt.dataTransfer
  1814. });
  1815. });
  1816. if (!PDFViewerApplication.supportsDocumentFonts) {
  1817. _app_options.AppOptions.set("disableFontFace", true);
  1818. PDFViewerApplication.l10n.get("web_fonts_disabled").then(msg => {
  1819. console.warn(msg);
  1820. });
  1821. }
  1822. if (!PDFViewerApplication.supportsPrinting) {
  1823. appConfig.toolbar.print.classList.add("hidden");
  1824. appConfig.secondaryToolbar.printButton.classList.add("hidden");
  1825. }
  1826. if (!PDFViewerApplication.supportsFullscreen) {
  1827. appConfig.toolbar.presentationModeButton.classList.add("hidden");
  1828. appConfig.secondaryToolbar.presentationModeButton.classList.add("hidden");
  1829. }
  1830. if (PDFViewerApplication.supportsIntegratedFind) {
  1831. appConfig.toolbar.viewFind.classList.add("hidden");
  1832. }
  1833. appConfig.mainContainer.addEventListener("transitionend", function (evt) {
  1834. if (evt.target === this) {
  1835. PDFViewerApplication.eventBus.dispatch("resize", {
  1836. source: this
  1837. });
  1838. }
  1839. }, true);
  1840. try {
  1841. webViewerOpenFileViaURL(file);
  1842. } catch (reason) {
  1843. PDFViewerApplication.l10n.get("loading_error").then(msg => {
  1844. PDFViewerApplication._documentError(msg, reason);
  1845. });
  1846. }
  1847. }
  1848. function webViewerOpenFileViaURL(file) {
  1849. if (file) {
  1850. PDFViewerApplication.open(file);
  1851. }
  1852. }
  1853. function webViewerResetPermissions() {
  1854. const {
  1855. appConfig
  1856. } = PDFViewerApplication;
  1857. if (!appConfig) {
  1858. return;
  1859. }
  1860. appConfig.viewerContainer.classList.remove(ENABLE_PERMISSIONS_CLASS);
  1861. }
  1862. function webViewerPageRendered({
  1863. pageNumber,
  1864. timestamp,
  1865. error
  1866. }) {
  1867. if (pageNumber === PDFViewerApplication.page) {
  1868. PDFViewerApplication.toolbar.updateLoadingIndicatorState(false);
  1869. }
  1870. if (PDFViewerApplication.pdfSidebar.isThumbnailViewVisible) {
  1871. const pageView = PDFViewerApplication.pdfViewer.getPageView(pageNumber - 1);
  1872. const thumbnailView = PDFViewerApplication.pdfThumbnailViewer.getThumbnail(pageNumber - 1);
  1873. if (pageView && thumbnailView) {
  1874. thumbnailView.setImage(pageView);
  1875. }
  1876. }
  1877. if (error) {
  1878. PDFViewerApplication.l10n.get("rendering_error").then(msg => {
  1879. PDFViewerApplication._otherError(msg, error);
  1880. });
  1881. }
  1882. PDFViewerApplication.externalServices.reportTelemetry({
  1883. type: "pageInfo",
  1884. timestamp
  1885. });
  1886. PDFViewerApplication.pdfDocument.getStats().then(function (stats) {
  1887. PDFViewerApplication.externalServices.reportTelemetry({
  1888. type: "documentStats",
  1889. stats
  1890. });
  1891. });
  1892. }
  1893. function webViewerPageMode({
  1894. mode
  1895. }) {
  1896. let view;
  1897. switch (mode) {
  1898. case "thumbs":
  1899. view = _ui_utils.SidebarView.THUMBS;
  1900. break;
  1901. case "bookmarks":
  1902. case "outline":
  1903. view = _ui_utils.SidebarView.OUTLINE;
  1904. break;
  1905. case "attachments":
  1906. view = _ui_utils.SidebarView.ATTACHMENTS;
  1907. break;
  1908. case "layers":
  1909. view = _ui_utils.SidebarView.LAYERS;
  1910. break;
  1911. case "none":
  1912. view = _ui_utils.SidebarView.NONE;
  1913. break;
  1914. default:
  1915. console.error('Invalid "pagemode" hash parameter: ' + mode);
  1916. return;
  1917. }
  1918. PDFViewerApplication.pdfSidebar.switchView(view, true);
  1919. }
  1920. function webViewerNamedAction(evt) {
  1921. switch (evt.action) {
  1922. case "GoToPage":
  1923. PDFViewerApplication.appConfig.toolbar.pageNumber.select();
  1924. break;
  1925. case "Find":
  1926. if (!PDFViewerApplication.supportsIntegratedFind) {
  1927. PDFViewerApplication.findBar.toggle();
  1928. }
  1929. break;
  1930. case "Print":
  1931. PDFViewerApplication.triggerPrinting();
  1932. break;
  1933. case "SaveAs":
  1934. webViewerSave();
  1935. break;
  1936. }
  1937. }
  1938. function webViewerPresentationModeChanged(evt) {
  1939. PDFViewerApplication.pdfViewer.presentationModeState = evt.state;
  1940. }
  1941. function webViewerSidebarViewChanged(evt) {
  1942. PDFViewerApplication.pdfRenderingQueue.isThumbnailViewEnabled = PDFViewerApplication.pdfSidebar.isThumbnailViewVisible;
  1943. const store = PDFViewerApplication.store;
  1944. if (store && PDFViewerApplication.isInitialViewSet) {
  1945. store.set("sidebarView", evt.view).catch(function () {});
  1946. }
  1947. }
  1948. function webViewerUpdateViewarea(evt) {
  1949. const location = evt.location,
  1950. store = PDFViewerApplication.store;
  1951. if (store && PDFViewerApplication.isInitialViewSet) {
  1952. store.setMultiple({
  1953. page: location.pageNumber,
  1954. zoom: location.scale,
  1955. scrollLeft: location.left,
  1956. scrollTop: location.top,
  1957. rotation: location.rotation
  1958. }).catch(function () {});
  1959. }
  1960. const href = PDFViewerApplication.pdfLinkService.getAnchorUrl(location.pdfOpenParams);
  1961. PDFViewerApplication.appConfig.toolbar.viewBookmark.href = href;
  1962. PDFViewerApplication.appConfig.secondaryToolbar.viewBookmarkButton.href = href;
  1963. const currentPage = PDFViewerApplication.pdfViewer.getPageView(PDFViewerApplication.page - 1);
  1964. const loading = currentPage?.renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED;
  1965. PDFViewerApplication.toolbar.updateLoadingIndicatorState(loading);
  1966. }
  1967. function webViewerScrollModeChanged(evt) {
  1968. const store = PDFViewerApplication.store;
  1969. if (store && PDFViewerApplication.isInitialViewSet) {
  1970. store.set("scrollMode", evt.mode).catch(function () {});
  1971. }
  1972. }
  1973. function webViewerSpreadModeChanged(evt) {
  1974. const store = PDFViewerApplication.store;
  1975. if (store && PDFViewerApplication.isInitialViewSet) {
  1976. store.set("spreadMode", evt.mode).catch(function () {});
  1977. }
  1978. }
  1979. function webViewerResize() {
  1980. const {
  1981. pdfDocument,
  1982. pdfViewer
  1983. } = PDFViewerApplication;
  1984. if (!pdfDocument) {
  1985. return;
  1986. }
  1987. const currentScaleValue = pdfViewer.currentScaleValue;
  1988. if (currentScaleValue === "auto" || currentScaleValue === "page-fit" || currentScaleValue === "page-width") {
  1989. pdfViewer.currentScaleValue = currentScaleValue;
  1990. }
  1991. pdfViewer.update();
  1992. }
  1993. function webViewerHashchange(evt) {
  1994. const hash = evt.hash;
  1995. if (!hash) {
  1996. return;
  1997. }
  1998. if (!PDFViewerApplication.isInitialViewSet) {
  1999. PDFViewerApplication.initialBookmark = hash;
  2000. } else if (!PDFViewerApplication.pdfHistory.popStateInProgress) {
  2001. PDFViewerApplication.pdfLinkService.setHash(hash);
  2002. }
  2003. }
  2004. let webViewerFileInputChange, webViewerOpenFile;
  2005. {
  2006. webViewerFileInputChange = function (evt) {
  2007. if (PDFViewerApplication.pdfViewer?.isInPresentationMode) {
  2008. return;
  2009. }
  2010. const file = evt.fileInput.files[0];
  2011. if (!_viewer_compatibility.viewerCompatibilityParams.disableCreateObjectURL) {
  2012. let url = URL.createObjectURL(file);
  2013. if (file.name) {
  2014. url = {
  2015. url,
  2016. originalUrl: file.name
  2017. };
  2018. }
  2019. PDFViewerApplication.open(url);
  2020. } else {
  2021. PDFViewerApplication.setTitleUsingUrl(file.name);
  2022. const fileReader = new FileReader();
  2023. fileReader.onload = function webViewerChangeFileReaderOnload(event) {
  2024. const buffer = event.target.result;
  2025. PDFViewerApplication.open(new Uint8Array(buffer));
  2026. };
  2027. fileReader.readAsArrayBuffer(file);
  2028. }
  2029. const appConfig = PDFViewerApplication.appConfig;
  2030. appConfig.toolbar.viewBookmark.hidden = true;
  2031. appConfig.secondaryToolbar.viewBookmarkButton.hidden = true;
  2032. appConfig.toolbar.download.hidden = true;
  2033. appConfig.secondaryToolbar.downloadButton.hidden = true;
  2034. };
  2035. webViewerOpenFile = function (evt) {
  2036. const openFileInputName = PDFViewerApplication.appConfig.openFileInputName;
  2037. document.getElementById(openFileInputName).click();
  2038. };
  2039. }
  2040. function webViewerPresentationMode() {
  2041. PDFViewerApplication.requestPresentationMode();
  2042. }
  2043. function webViewerPrint() {
  2044. PDFViewerApplication.triggerPrinting();
  2045. }
  2046. function webViewerDownload() {
  2047. PDFViewerApplication.downloadOrSave({
  2048. sourceEventType: "download"
  2049. });
  2050. }
  2051. function webViewerSave() {
  2052. PDFViewerApplication.downloadOrSave({
  2053. sourceEventType: "save"
  2054. });
  2055. }
  2056. function webViewerFirstPage() {
  2057. if (PDFViewerApplication.pdfDocument) {
  2058. PDFViewerApplication.page = 1;
  2059. }
  2060. }
  2061. function webViewerLastPage() {
  2062. if (PDFViewerApplication.pdfDocument) {
  2063. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  2064. }
  2065. }
  2066. function webViewerNextPage() {
  2067. PDFViewerApplication.pdfViewer.nextPage();
  2068. }
  2069. function webViewerPreviousPage() {
  2070. PDFViewerApplication.pdfViewer.previousPage();
  2071. }
  2072. function webViewerZoomIn() {
  2073. PDFViewerApplication.zoomIn();
  2074. }
  2075. function webViewerZoomOut() {
  2076. PDFViewerApplication.zoomOut();
  2077. }
  2078. function webViewerZoomReset() {
  2079. PDFViewerApplication.zoomReset();
  2080. }
  2081. function webViewerPageNumberChanged(evt) {
  2082. const pdfViewer = PDFViewerApplication.pdfViewer;
  2083. if (evt.value !== "") {
  2084. PDFViewerApplication.pdfLinkService.goToPage(evt.value);
  2085. }
  2086. if (evt.value !== pdfViewer.currentPageNumber.toString() && evt.value !== pdfViewer.currentPageLabel) {
  2087. PDFViewerApplication.toolbar.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
  2088. }
  2089. }
  2090. function webViewerScaleChanged(evt) {
  2091. PDFViewerApplication.pdfViewer.currentScaleValue = evt.value;
  2092. }
  2093. function webViewerRotateCw() {
  2094. PDFViewerApplication.rotatePages(90);
  2095. }
  2096. function webViewerRotateCcw() {
  2097. PDFViewerApplication.rotatePages(-90);
  2098. }
  2099. function webViewerOptionalContentConfig(evt) {
  2100. PDFViewerApplication.pdfViewer.optionalContentConfigPromise = evt.promise;
  2101. }
  2102. function webViewerSwitchScrollMode(evt) {
  2103. PDFViewerApplication.pdfViewer.scrollMode = evt.mode;
  2104. }
  2105. function webViewerSwitchSpreadMode(evt) {
  2106. PDFViewerApplication.pdfViewer.spreadMode = evt.mode;
  2107. }
  2108. function webViewerDocumentProperties() {
  2109. PDFViewerApplication.pdfDocumentProperties.open();
  2110. }
  2111. function webViewerFind(evt) {
  2112. PDFViewerApplication.findController.executeCommand("find" + evt.type, {
  2113. query: evt.query,
  2114. phraseSearch: evt.phraseSearch,
  2115. caseSensitive: evt.caseSensitive,
  2116. entireWord: evt.entireWord,
  2117. highlightAll: evt.highlightAll,
  2118. findPrevious: evt.findPrevious
  2119. });
  2120. }
  2121. function webViewerFindFromUrlHash(evt) {
  2122. PDFViewerApplication.findController.executeCommand("find", {
  2123. query: evt.query,
  2124. phraseSearch: evt.phraseSearch,
  2125. caseSensitive: false,
  2126. entireWord: false,
  2127. highlightAll: true,
  2128. findPrevious: false
  2129. });
  2130. }
  2131. function webViewerUpdateFindMatchesCount({
  2132. matchesCount
  2133. }) {
  2134. if (PDFViewerApplication.supportsIntegratedFind) {
  2135. PDFViewerApplication.externalServices.updateFindMatchesCount(matchesCount);
  2136. } else {
  2137. PDFViewerApplication.findBar.updateResultsCount(matchesCount);
  2138. }
  2139. }
  2140. function webViewerUpdateFindControlState({
  2141. state,
  2142. previous,
  2143. matchesCount,
  2144. rawQuery
  2145. }) {
  2146. if (PDFViewerApplication.supportsIntegratedFind) {
  2147. PDFViewerApplication.externalServices.updateFindControlState({
  2148. result: state,
  2149. findPrevious: previous,
  2150. matchesCount,
  2151. rawQuery
  2152. });
  2153. } else {
  2154. PDFViewerApplication.findBar.updateUIState(state, previous, matchesCount);
  2155. }
  2156. }
  2157. function webViewerScaleChanging(evt) {
  2158. PDFViewerApplication.toolbar.setPageScale(evt.presetValue, evt.scale);
  2159. PDFViewerApplication.pdfViewer.update();
  2160. }
  2161. function webViewerRotationChanging(evt) {
  2162. PDFViewerApplication.pdfThumbnailViewer.pagesRotation = evt.pagesRotation;
  2163. PDFViewerApplication.forceRendering();
  2164. PDFViewerApplication.pdfViewer.currentPageNumber = evt.pageNumber;
  2165. }
  2166. function webViewerPageChanging({
  2167. pageNumber,
  2168. pageLabel
  2169. }) {
  2170. PDFViewerApplication.toolbar.setPageNumber(pageNumber, pageLabel);
  2171. PDFViewerApplication.secondaryToolbar.setPageNumber(pageNumber);
  2172. if (PDFViewerApplication.pdfSidebar.isThumbnailViewVisible) {
  2173. PDFViewerApplication.pdfThumbnailViewer.scrollThumbnailIntoView(pageNumber);
  2174. }
  2175. }
  2176. function webViewerVisibilityChange(evt) {
  2177. if (document.visibilityState === "visible") {
  2178. setZoomDisabledTimeout();
  2179. }
  2180. }
  2181. let zoomDisabledTimeout = null;
  2182. function setZoomDisabledTimeout() {
  2183. if (zoomDisabledTimeout) {
  2184. clearTimeout(zoomDisabledTimeout);
  2185. }
  2186. zoomDisabledTimeout = setTimeout(function () {
  2187. zoomDisabledTimeout = null;
  2188. }, WHEEL_ZOOM_DISABLED_TIMEOUT);
  2189. }
  2190. function webViewerWheel(evt) {
  2191. const {
  2192. pdfViewer,
  2193. supportedMouseWheelZoomModifierKeys
  2194. } = PDFViewerApplication;
  2195. if (pdfViewer.isInPresentationMode) {
  2196. return;
  2197. }
  2198. if (evt.ctrlKey && supportedMouseWheelZoomModifierKeys.ctrlKey || evt.metaKey && supportedMouseWheelZoomModifierKeys.metaKey) {
  2199. evt.preventDefault();
  2200. if (zoomDisabledTimeout || document.visibilityState === "hidden") {
  2201. return;
  2202. }
  2203. const previousScale = pdfViewer.currentScale;
  2204. const delta = (0, _ui_utils.normalizeWheelEventDirection)(evt);
  2205. let ticks = 0;
  2206. if (evt.deltaMode === WheelEvent.DOM_DELTA_LINE || evt.deltaMode === WheelEvent.DOM_DELTA_PAGE) {
  2207. if (Math.abs(delta) >= 1) {
  2208. ticks = Math.sign(delta);
  2209. } else {
  2210. ticks = PDFViewerApplication.accumulateWheelTicks(delta);
  2211. }
  2212. } else {
  2213. const PIXELS_PER_LINE_SCALE = 30;
  2214. ticks = PDFViewerApplication.accumulateWheelTicks(delta / PIXELS_PER_LINE_SCALE);
  2215. }
  2216. if (ticks < 0) {
  2217. PDFViewerApplication.zoomOut(-ticks);
  2218. } else if (ticks > 0) {
  2219. PDFViewerApplication.zoomIn(ticks);
  2220. }
  2221. const currentScale = pdfViewer.currentScale;
  2222. if (previousScale !== currentScale) {
  2223. const scaleCorrectionFactor = currentScale / previousScale - 1;
  2224. const rect = pdfViewer.container.getBoundingClientRect();
  2225. const dx = evt.clientX - rect.left;
  2226. const dy = evt.clientY - rect.top;
  2227. pdfViewer.container.scrollLeft += dx * scaleCorrectionFactor;
  2228. pdfViewer.container.scrollTop += dy * scaleCorrectionFactor;
  2229. }
  2230. } else {
  2231. setZoomDisabledTimeout();
  2232. }
  2233. }
  2234. function webViewerTouchStart(evt) {
  2235. if (evt.touches.length > 1) {
  2236. evt.preventDefault();
  2237. }
  2238. }
  2239. function webViewerClick(evt) {
  2240. if (!PDFViewerApplication.secondaryToolbar.isOpen) {
  2241. return;
  2242. }
  2243. const appConfig = PDFViewerApplication.appConfig;
  2244. if (PDFViewerApplication.pdfViewer.containsElement(evt.target) || appConfig.toolbar.container.contains(evt.target) && evt.target !== appConfig.secondaryToolbar.toggleButton) {
  2245. PDFViewerApplication.secondaryToolbar.close();
  2246. }
  2247. }
  2248. function webViewerKeyDown(evt) {
  2249. if (PDFViewerApplication.overlayManager.active) {
  2250. return;
  2251. }
  2252. let handled = false,
  2253. ensureViewerFocused = false;
  2254. const cmd = (evt.ctrlKey ? 1 : 0) | (evt.altKey ? 2 : 0) | (evt.shiftKey ? 4 : 0) | (evt.metaKey ? 8 : 0);
  2255. const pdfViewer = PDFViewerApplication.pdfViewer;
  2256. const isViewerInPresentationMode = pdfViewer?.isInPresentationMode;
  2257. if (cmd === 1 || cmd === 8 || cmd === 5 || cmd === 12) {
  2258. switch (evt.keyCode) {
  2259. case 70:
  2260. if (!PDFViewerApplication.supportsIntegratedFind && !evt.shiftKey) {
  2261. PDFViewerApplication.findBar.open();
  2262. handled = true;
  2263. }
  2264. break;
  2265. case 71:
  2266. if (!PDFViewerApplication.supportsIntegratedFind) {
  2267. const findState = PDFViewerApplication.findController.state;
  2268. if (findState) {
  2269. PDFViewerApplication.findController.executeCommand("findagain", {
  2270. query: findState.query,
  2271. phraseSearch: findState.phraseSearch,
  2272. caseSensitive: findState.caseSensitive,
  2273. entireWord: findState.entireWord,
  2274. highlightAll: findState.highlightAll,
  2275. findPrevious: cmd === 5 || cmd === 12
  2276. });
  2277. }
  2278. handled = true;
  2279. }
  2280. break;
  2281. case 61:
  2282. case 107:
  2283. case 187:
  2284. case 171:
  2285. if (!isViewerInPresentationMode) {
  2286. PDFViewerApplication.zoomIn();
  2287. }
  2288. handled = true;
  2289. break;
  2290. case 173:
  2291. case 109:
  2292. case 189:
  2293. if (!isViewerInPresentationMode) {
  2294. PDFViewerApplication.zoomOut();
  2295. }
  2296. handled = true;
  2297. break;
  2298. case 48:
  2299. case 96:
  2300. if (!isViewerInPresentationMode) {
  2301. setTimeout(function () {
  2302. PDFViewerApplication.zoomReset();
  2303. });
  2304. handled = false;
  2305. }
  2306. break;
  2307. case 38:
  2308. if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
  2309. PDFViewerApplication.page = 1;
  2310. handled = true;
  2311. ensureViewerFocused = true;
  2312. }
  2313. break;
  2314. case 40:
  2315. if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  2316. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  2317. handled = true;
  2318. ensureViewerFocused = true;
  2319. }
  2320. break;
  2321. }
  2322. }
  2323. const {
  2324. eventBus
  2325. } = PDFViewerApplication;
  2326. if (cmd === 1 || cmd === 8) {
  2327. switch (evt.keyCode) {
  2328. case 83:
  2329. eventBus.dispatch("download", {
  2330. source: window
  2331. });
  2332. handled = true;
  2333. break;
  2334. case 79:
  2335. {
  2336. eventBus.dispatch("openfile", {
  2337. source: window
  2338. });
  2339. handled = true;
  2340. }
  2341. break;
  2342. }
  2343. }
  2344. if (cmd === 3 || cmd === 10) {
  2345. switch (evt.keyCode) {
  2346. case 80:
  2347. PDFViewerApplication.requestPresentationMode();
  2348. handled = true;
  2349. break;
  2350. case 71:
  2351. PDFViewerApplication.appConfig.toolbar.pageNumber.select();
  2352. handled = true;
  2353. break;
  2354. }
  2355. }
  2356. if (handled) {
  2357. if (ensureViewerFocused && !isViewerInPresentationMode) {
  2358. pdfViewer.focus();
  2359. }
  2360. evt.preventDefault();
  2361. return;
  2362. }
  2363. const curElement = (0, _ui_utils.getActiveOrFocusedElement)();
  2364. const curElementTagName = curElement?.tagName.toUpperCase();
  2365. if (curElementTagName === "INPUT" || curElementTagName === "TEXTAREA" || curElementTagName === "SELECT" || curElement?.isContentEditable) {
  2366. if (evt.keyCode !== 27) {
  2367. return;
  2368. }
  2369. }
  2370. if (cmd === 0) {
  2371. let turnPage = 0,
  2372. turnOnlyIfPageFit = false;
  2373. switch (evt.keyCode) {
  2374. case 38:
  2375. case 33:
  2376. if (pdfViewer.isVerticalScrollbarEnabled) {
  2377. turnOnlyIfPageFit = true;
  2378. }
  2379. turnPage = -1;
  2380. break;
  2381. case 8:
  2382. if (!isViewerInPresentationMode) {
  2383. turnOnlyIfPageFit = true;
  2384. }
  2385. turnPage = -1;
  2386. break;
  2387. case 37:
  2388. if (pdfViewer.isHorizontalScrollbarEnabled) {
  2389. turnOnlyIfPageFit = true;
  2390. }
  2391. case 75:
  2392. case 80:
  2393. turnPage = -1;
  2394. break;
  2395. case 27:
  2396. if (PDFViewerApplication.secondaryToolbar.isOpen) {
  2397. PDFViewerApplication.secondaryToolbar.close();
  2398. handled = true;
  2399. }
  2400. if (!PDFViewerApplication.supportsIntegratedFind && PDFViewerApplication.findBar.opened) {
  2401. PDFViewerApplication.findBar.close();
  2402. handled = true;
  2403. }
  2404. break;
  2405. case 40:
  2406. case 34:
  2407. if (pdfViewer.isVerticalScrollbarEnabled) {
  2408. turnOnlyIfPageFit = true;
  2409. }
  2410. turnPage = 1;
  2411. break;
  2412. case 13:
  2413. case 32:
  2414. if (!isViewerInPresentationMode) {
  2415. turnOnlyIfPageFit = true;
  2416. }
  2417. turnPage = 1;
  2418. break;
  2419. case 39:
  2420. if (pdfViewer.isHorizontalScrollbarEnabled) {
  2421. turnOnlyIfPageFit = true;
  2422. }
  2423. case 74:
  2424. case 78:
  2425. turnPage = 1;
  2426. break;
  2427. case 36:
  2428. if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
  2429. PDFViewerApplication.page = 1;
  2430. handled = true;
  2431. ensureViewerFocused = true;
  2432. }
  2433. break;
  2434. case 35:
  2435. if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  2436. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  2437. handled = true;
  2438. ensureViewerFocused = true;
  2439. }
  2440. break;
  2441. case 83:
  2442. PDFViewerApplication.pdfCursorTools.switchTool(_pdf_cursor_tools.CursorTool.SELECT);
  2443. break;
  2444. case 72:
  2445. PDFViewerApplication.pdfCursorTools.switchTool(_pdf_cursor_tools.CursorTool.HAND);
  2446. break;
  2447. case 82:
  2448. PDFViewerApplication.rotatePages(90);
  2449. break;
  2450. case 115:
  2451. PDFViewerApplication.pdfSidebar.toggle();
  2452. break;
  2453. }
  2454. if (turnPage !== 0 && (!turnOnlyIfPageFit || pdfViewer.currentScaleValue === "page-fit")) {
  2455. if (turnPage > 0) {
  2456. pdfViewer.nextPage();
  2457. } else {
  2458. pdfViewer.previousPage();
  2459. }
  2460. handled = true;
  2461. }
  2462. }
  2463. if (cmd === 4) {
  2464. switch (evt.keyCode) {
  2465. case 13:
  2466. case 32:
  2467. if (!isViewerInPresentationMode && pdfViewer.currentScaleValue !== "page-fit") {
  2468. break;
  2469. }
  2470. if (PDFViewerApplication.page > 1) {
  2471. PDFViewerApplication.page--;
  2472. }
  2473. handled = true;
  2474. break;
  2475. case 82:
  2476. PDFViewerApplication.rotatePages(-90);
  2477. break;
  2478. }
  2479. }
  2480. if (!handled && !isViewerInPresentationMode) {
  2481. if (evt.keyCode >= 33 && evt.keyCode <= 40 || evt.keyCode === 32 && curElementTagName !== "BUTTON") {
  2482. ensureViewerFocused = true;
  2483. }
  2484. }
  2485. if (ensureViewerFocused && !pdfViewer.containsElement(curElement)) {
  2486. pdfViewer.focus();
  2487. }
  2488. if (handled) {
  2489. evt.preventDefault();
  2490. }
  2491. }
  2492. function beforeUnload(evt) {
  2493. evt.preventDefault();
  2494. evt.returnValue = "";
  2495. return false;
  2496. }
  2497. const PDFPrintServiceFactory = {
  2498. instance: {
  2499. supportsPrinting: false,
  2500. createPrintService() {
  2501. throw new Error("Not implemented: createPrintService");
  2502. }
  2503. }
  2504. };
  2505. exports.PDFPrintServiceFactory = PDFPrintServiceFactory;
  2506. /***/ }),
  2507. /* 4 */
  2508. /***/ ((__unused_webpack_module, exports) => {
  2509. Object.defineProperty(exports, "__esModule", ({
  2510. value: true
  2511. }));
  2512. exports.apiPageLayoutToSpreadMode = apiPageLayoutToSpreadMode;
  2513. exports.apiPageModeToSidebarView = apiPageModeToSidebarView;
  2514. exports.approximateFraction = approximateFraction;
  2515. exports.backtrackBeforeAllVisibleElements = backtrackBeforeAllVisibleElements;
  2516. exports.binarySearchFirstItem = binarySearchFirstItem;
  2517. exports.getActiveOrFocusedElement = getActiveOrFocusedElement;
  2518. exports.getOutputScale = getOutputScale;
  2519. exports.getPageSizeInches = getPageSizeInches;
  2520. exports.getVisibleElements = getVisibleElements;
  2521. exports.isPortraitOrientation = isPortraitOrientation;
  2522. exports.isValidRotation = isValidRotation;
  2523. exports.isValidScrollMode = isValidScrollMode;
  2524. exports.isValidSpreadMode = isValidSpreadMode;
  2525. exports.moveToEndOfArray = moveToEndOfArray;
  2526. exports.noContextMenuHandler = noContextMenuHandler;
  2527. exports.normalizeWheelEventDelta = normalizeWheelEventDelta;
  2528. exports.normalizeWheelEventDirection = normalizeWheelEventDirection;
  2529. exports.parseQueryString = parseQueryString;
  2530. exports.roundToDivide = roundToDivide;
  2531. exports.scrollIntoView = scrollIntoView;
  2532. exports.waitOnEventOrTimeout = waitOnEventOrTimeout;
  2533. exports.watchScroll = watchScroll;
  2534. exports.WaitOnType = exports.VERTICAL_PADDING = exports.UNKNOWN_SCALE = exports.TextLayerMode = exports.SpreadMode = exports.SidebarView = exports.ScrollMode = exports.SCROLLBAR_PADDING = exports.RendererType = exports.ProgressBar = exports.PresentationModeState = exports.MIN_SCALE = exports.MAX_SCALE = exports.MAX_AUTO_SCALE = exports.EventBus = exports.DEFAULT_SCALE_VALUE = exports.DEFAULT_SCALE = exports.CSS_UNITS = exports.AutoPrintRegExp = exports.animationStarted = void 0;
  2535. const CSS_UNITS = 96.0 / 72.0;
  2536. exports.CSS_UNITS = CSS_UNITS;
  2537. const DEFAULT_SCALE_VALUE = "auto";
  2538. exports.DEFAULT_SCALE_VALUE = DEFAULT_SCALE_VALUE;
  2539. const DEFAULT_SCALE = 1.0;
  2540. exports.DEFAULT_SCALE = DEFAULT_SCALE;
  2541. const MIN_SCALE = 0.1;
  2542. exports.MIN_SCALE = MIN_SCALE;
  2543. const MAX_SCALE = 10.0;
  2544. exports.MAX_SCALE = MAX_SCALE;
  2545. const UNKNOWN_SCALE = 0;
  2546. exports.UNKNOWN_SCALE = UNKNOWN_SCALE;
  2547. const MAX_AUTO_SCALE = 1.25;
  2548. exports.MAX_AUTO_SCALE = MAX_AUTO_SCALE;
  2549. const SCROLLBAR_PADDING = 40;
  2550. exports.SCROLLBAR_PADDING = SCROLLBAR_PADDING;
  2551. const VERTICAL_PADDING = 5;
  2552. exports.VERTICAL_PADDING = VERTICAL_PADDING;
  2553. const LOADINGBAR_END_OFFSET_VAR = "--loadingBar-end-offset";
  2554. const PresentationModeState = {
  2555. UNKNOWN: 0,
  2556. NORMAL: 1,
  2557. CHANGING: 2,
  2558. FULLSCREEN: 3
  2559. };
  2560. exports.PresentationModeState = PresentationModeState;
  2561. const SidebarView = {
  2562. UNKNOWN: -1,
  2563. NONE: 0,
  2564. THUMBS: 1,
  2565. OUTLINE: 2,
  2566. ATTACHMENTS: 3,
  2567. LAYERS: 4
  2568. };
  2569. exports.SidebarView = SidebarView;
  2570. const RendererType = {
  2571. CANVAS: "canvas",
  2572. SVG: "svg"
  2573. };
  2574. exports.RendererType = RendererType;
  2575. const TextLayerMode = {
  2576. DISABLE: 0,
  2577. ENABLE: 1,
  2578. ENABLE_ENHANCE: 2
  2579. };
  2580. exports.TextLayerMode = TextLayerMode;
  2581. const ScrollMode = {
  2582. UNKNOWN: -1,
  2583. VERTICAL: 0,
  2584. HORIZONTAL: 1,
  2585. WRAPPED: 2
  2586. };
  2587. exports.ScrollMode = ScrollMode;
  2588. const SpreadMode = {
  2589. UNKNOWN: -1,
  2590. NONE: 0,
  2591. ODD: 1,
  2592. EVEN: 2
  2593. };
  2594. exports.SpreadMode = SpreadMode;
  2595. const AutoPrintRegExp = /\bprint\s*\(/;
  2596. exports.AutoPrintRegExp = AutoPrintRegExp;
  2597. function getOutputScale(ctx) {
  2598. const devicePixelRatio = window.devicePixelRatio || 1;
  2599. const backingStoreRatio = ctx.webkitBackingStorePixelRatio || ctx.mozBackingStorePixelRatio || ctx.backingStorePixelRatio || 1;
  2600. const pixelRatio = devicePixelRatio / backingStoreRatio;
  2601. return {
  2602. sx: pixelRatio,
  2603. sy: pixelRatio,
  2604. scaled: pixelRatio !== 1
  2605. };
  2606. }
  2607. function scrollIntoView(element, spot, scrollMatches = false) {
  2608. let parent = element.offsetParent;
  2609. if (!parent) {
  2610. console.error("offsetParent is not set -- cannot scroll");
  2611. return;
  2612. }
  2613. let offsetY = element.offsetTop + element.clientTop;
  2614. let offsetX = element.offsetLeft + element.clientLeft;
  2615. while (parent.clientHeight === parent.scrollHeight && parent.clientWidth === parent.scrollWidth || scrollMatches && (parent.classList.contains("markedContent") || getComputedStyle(parent).overflow === "hidden")) {
  2616. offsetY += parent.offsetTop;
  2617. offsetX += parent.offsetLeft;
  2618. parent = parent.offsetParent;
  2619. if (!parent) {
  2620. return;
  2621. }
  2622. }
  2623. if (spot) {
  2624. if (spot.top !== undefined) {
  2625. offsetY += spot.top;
  2626. }
  2627. if (spot.left !== undefined) {
  2628. offsetX += spot.left;
  2629. parent.scrollLeft = offsetX;
  2630. }
  2631. }
  2632. parent.scrollTop = offsetY;
  2633. }
  2634. function watchScroll(viewAreaElement, callback) {
  2635. const debounceScroll = function (evt) {
  2636. if (rAF) {
  2637. return;
  2638. }
  2639. rAF = window.requestAnimationFrame(function viewAreaElementScrolled() {
  2640. rAF = null;
  2641. const currentX = viewAreaElement.scrollLeft;
  2642. const lastX = state.lastX;
  2643. if (currentX !== lastX) {
  2644. state.right = currentX > lastX;
  2645. }
  2646. state.lastX = currentX;
  2647. const currentY = viewAreaElement.scrollTop;
  2648. const lastY = state.lastY;
  2649. if (currentY !== lastY) {
  2650. state.down = currentY > lastY;
  2651. }
  2652. state.lastY = currentY;
  2653. callback(state);
  2654. });
  2655. };
  2656. const state = {
  2657. right: true,
  2658. down: true,
  2659. lastX: viewAreaElement.scrollLeft,
  2660. lastY: viewAreaElement.scrollTop,
  2661. _eventHandler: debounceScroll
  2662. };
  2663. let rAF = null;
  2664. viewAreaElement.addEventListener("scroll", debounceScroll, true);
  2665. return state;
  2666. }
  2667. function parseQueryString(query) {
  2668. const parts = query.split("&");
  2669. const params = Object.create(null);
  2670. for (let i = 0, ii = parts.length; i < ii; ++i) {
  2671. const param = parts[i].split("=");
  2672. const key = param[0].toLowerCase();
  2673. const value = param.length > 1 ? param[1] : null;
  2674. params[decodeURIComponent(key)] = decodeURIComponent(value);
  2675. }
  2676. return params;
  2677. }
  2678. function binarySearchFirstItem(items, condition) {
  2679. let minIndex = 0;
  2680. let maxIndex = items.length - 1;
  2681. if (maxIndex < 0 || !condition(items[maxIndex])) {
  2682. return items.length;
  2683. }
  2684. if (condition(items[minIndex])) {
  2685. return minIndex;
  2686. }
  2687. while (minIndex < maxIndex) {
  2688. const currentIndex = minIndex + maxIndex >> 1;
  2689. const currentItem = items[currentIndex];
  2690. if (condition(currentItem)) {
  2691. maxIndex = currentIndex;
  2692. } else {
  2693. minIndex = currentIndex + 1;
  2694. }
  2695. }
  2696. return minIndex;
  2697. }
  2698. function approximateFraction(x) {
  2699. if (Math.floor(x) === x) {
  2700. return [x, 1];
  2701. }
  2702. const xinv = 1 / x;
  2703. const limit = 8;
  2704. if (xinv > limit) {
  2705. return [1, limit];
  2706. } else if (Math.floor(xinv) === xinv) {
  2707. return [1, xinv];
  2708. }
  2709. const x_ = x > 1 ? xinv : x;
  2710. let a = 0,
  2711. b = 1,
  2712. c = 1,
  2713. d = 1;
  2714. while (true) {
  2715. const p = a + c,
  2716. q = b + d;
  2717. if (q > limit) {
  2718. break;
  2719. }
  2720. if (x_ <= p / q) {
  2721. c = p;
  2722. d = q;
  2723. } else {
  2724. a = p;
  2725. b = q;
  2726. }
  2727. }
  2728. let result;
  2729. if (x_ - a / b < c / d - x_) {
  2730. result = x_ === x ? [a, b] : [b, a];
  2731. } else {
  2732. result = x_ === x ? [c, d] : [d, c];
  2733. }
  2734. return result;
  2735. }
  2736. function roundToDivide(x, div) {
  2737. const r = x % div;
  2738. return r === 0 ? x : Math.round(x - r + div);
  2739. }
  2740. function getPageSizeInches({
  2741. view,
  2742. userUnit,
  2743. rotate
  2744. }) {
  2745. const [x1, y1, x2, y2] = view;
  2746. const changeOrientation = rotate % 180 !== 0;
  2747. const width = (x2 - x1) / 72 * userUnit;
  2748. const height = (y2 - y1) / 72 * userUnit;
  2749. return {
  2750. width: changeOrientation ? height : width,
  2751. height: changeOrientation ? width : height
  2752. };
  2753. }
  2754. function backtrackBeforeAllVisibleElements(index, views, top) {
  2755. if (index < 2) {
  2756. return index;
  2757. }
  2758. let elt = views[index].div;
  2759. let pageTop = elt.offsetTop + elt.clientTop;
  2760. if (pageTop >= top) {
  2761. elt = views[index - 1].div;
  2762. pageTop = elt.offsetTop + elt.clientTop;
  2763. }
  2764. for (let i = index - 2; i >= 0; --i) {
  2765. elt = views[i].div;
  2766. if (elt.offsetTop + elt.clientTop + elt.clientHeight <= pageTop) {
  2767. break;
  2768. }
  2769. index = i;
  2770. }
  2771. return index;
  2772. }
  2773. function getVisibleElements({
  2774. scrollEl,
  2775. views,
  2776. sortByVisibility = false,
  2777. horizontal = false,
  2778. rtl = false
  2779. }) {
  2780. const top = scrollEl.scrollTop,
  2781. bottom = top + scrollEl.clientHeight;
  2782. const left = scrollEl.scrollLeft,
  2783. right = left + scrollEl.clientWidth;
  2784. function isElementBottomAfterViewTop(view) {
  2785. const element = view.div;
  2786. const elementBottom = element.offsetTop + element.clientTop + element.clientHeight;
  2787. return elementBottom > top;
  2788. }
  2789. function isElementNextAfterViewHorizontally(view) {
  2790. const element = view.div;
  2791. const elementLeft = element.offsetLeft + element.clientLeft;
  2792. const elementRight = elementLeft + element.clientWidth;
  2793. return rtl ? elementLeft < right : elementRight > left;
  2794. }
  2795. const visible = [],
  2796. numViews = views.length;
  2797. let firstVisibleElementInd = binarySearchFirstItem(views, horizontal ? isElementNextAfterViewHorizontally : isElementBottomAfterViewTop);
  2798. if (firstVisibleElementInd > 0 && firstVisibleElementInd < numViews && !horizontal) {
  2799. firstVisibleElementInd = backtrackBeforeAllVisibleElements(firstVisibleElementInd, views, top);
  2800. }
  2801. let lastEdge = horizontal ? right : -1;
  2802. for (let i = firstVisibleElementInd; i < numViews; i++) {
  2803. const view = views[i],
  2804. element = view.div;
  2805. const currentWidth = element.offsetLeft + element.clientLeft;
  2806. const currentHeight = element.offsetTop + element.clientTop;
  2807. const viewWidth = element.clientWidth,
  2808. viewHeight = element.clientHeight;
  2809. const viewRight = currentWidth + viewWidth;
  2810. const viewBottom = currentHeight + viewHeight;
  2811. if (lastEdge === -1) {
  2812. if (viewBottom >= bottom) {
  2813. lastEdge = viewBottom;
  2814. }
  2815. } else if ((horizontal ? currentWidth : currentHeight) > lastEdge) {
  2816. break;
  2817. }
  2818. if (viewBottom <= top || currentHeight >= bottom || viewRight <= left || currentWidth >= right) {
  2819. continue;
  2820. }
  2821. const hiddenHeight = Math.max(0, top - currentHeight) + Math.max(0, viewBottom - bottom);
  2822. const hiddenWidth = Math.max(0, left - currentWidth) + Math.max(0, viewRight - right);
  2823. const fractionHeight = (viewHeight - hiddenHeight) / viewHeight,
  2824. fractionWidth = (viewWidth - hiddenWidth) / viewWidth;
  2825. const percent = fractionHeight * fractionWidth * 100 | 0;
  2826. visible.push({
  2827. id: view.id,
  2828. x: currentWidth,
  2829. y: currentHeight,
  2830. view,
  2831. percent,
  2832. widthPercent: fractionWidth * 100 | 0
  2833. });
  2834. }
  2835. const first = visible[0],
  2836. last = visible[visible.length - 1];
  2837. if (sortByVisibility) {
  2838. visible.sort(function (a, b) {
  2839. const pc = a.percent - b.percent;
  2840. if (Math.abs(pc) > 0.001) {
  2841. return -pc;
  2842. }
  2843. return a.id - b.id;
  2844. });
  2845. }
  2846. return {
  2847. first,
  2848. last,
  2849. views: visible
  2850. };
  2851. }
  2852. function noContextMenuHandler(evt) {
  2853. evt.preventDefault();
  2854. }
  2855. function normalizeWheelEventDirection(evt) {
  2856. let delta = Math.hypot(evt.deltaX, evt.deltaY);
  2857. const angle = Math.atan2(evt.deltaY, evt.deltaX);
  2858. if (-0.25 * Math.PI < angle && angle < 0.75 * Math.PI) {
  2859. delta = -delta;
  2860. }
  2861. return delta;
  2862. }
  2863. function normalizeWheelEventDelta(evt) {
  2864. let delta = normalizeWheelEventDirection(evt);
  2865. const MOUSE_DOM_DELTA_PIXEL_MODE = 0;
  2866. const MOUSE_DOM_DELTA_LINE_MODE = 1;
  2867. const MOUSE_PIXELS_PER_LINE = 30;
  2868. const MOUSE_LINES_PER_PAGE = 30;
  2869. if (evt.deltaMode === MOUSE_DOM_DELTA_PIXEL_MODE) {
  2870. delta /= MOUSE_PIXELS_PER_LINE * MOUSE_LINES_PER_PAGE;
  2871. } else if (evt.deltaMode === MOUSE_DOM_DELTA_LINE_MODE) {
  2872. delta /= MOUSE_LINES_PER_PAGE;
  2873. }
  2874. return delta;
  2875. }
  2876. function isValidRotation(angle) {
  2877. return Number.isInteger(angle) && angle % 90 === 0;
  2878. }
  2879. function isValidScrollMode(mode) {
  2880. return Number.isInteger(mode) && Object.values(ScrollMode).includes(mode) && mode !== ScrollMode.UNKNOWN;
  2881. }
  2882. function isValidSpreadMode(mode) {
  2883. return Number.isInteger(mode) && Object.values(SpreadMode).includes(mode) && mode !== SpreadMode.UNKNOWN;
  2884. }
  2885. function isPortraitOrientation(size) {
  2886. return size.width <= size.height;
  2887. }
  2888. const WaitOnType = {
  2889. EVENT: "event",
  2890. TIMEOUT: "timeout"
  2891. };
  2892. exports.WaitOnType = WaitOnType;
  2893. function waitOnEventOrTimeout({
  2894. target,
  2895. name,
  2896. delay = 0
  2897. }) {
  2898. return new Promise(function (resolve, reject) {
  2899. if (typeof target !== "object" || !(name && typeof name === "string") || !(Number.isInteger(delay) && delay >= 0)) {
  2900. throw new Error("waitOnEventOrTimeout - invalid parameters.");
  2901. }
  2902. function handler(type) {
  2903. if (target instanceof EventBus) {
  2904. target._off(name, eventHandler);
  2905. } else {
  2906. target.removeEventListener(name, eventHandler);
  2907. }
  2908. if (timeout) {
  2909. clearTimeout(timeout);
  2910. }
  2911. resolve(type);
  2912. }
  2913. const eventHandler = handler.bind(null, WaitOnType.EVENT);
  2914. if (target instanceof EventBus) {
  2915. target._on(name, eventHandler);
  2916. } else {
  2917. target.addEventListener(name, eventHandler);
  2918. }
  2919. const timeoutHandler = handler.bind(null, WaitOnType.TIMEOUT);
  2920. const timeout = setTimeout(timeoutHandler, delay);
  2921. });
  2922. }
  2923. const animationStarted = new Promise(function (resolve) {
  2924. window.requestAnimationFrame(resolve);
  2925. });
  2926. exports.animationStarted = animationStarted;
  2927. function dispatchDOMEvent(eventName, args = null) {
  2928. throw new Error("Not implemented: dispatchDOMEvent");
  2929. }
  2930. class EventBus {
  2931. constructor(options) {
  2932. this._listeners = Object.create(null);
  2933. }
  2934. on(eventName, listener, options = null) {
  2935. this._on(eventName, listener, {
  2936. external: true,
  2937. once: options?.once
  2938. });
  2939. }
  2940. off(eventName, listener, options = null) {
  2941. this._off(eventName, listener, {
  2942. external: true,
  2943. once: options?.once
  2944. });
  2945. }
  2946. dispatch(eventName) {
  2947. const eventListeners = this._listeners[eventName];
  2948. if (!eventListeners || eventListeners.length === 0) {
  2949. return;
  2950. }
  2951. const args = Array.prototype.slice.call(arguments, 1);
  2952. let externalListeners;
  2953. for (const {
  2954. listener,
  2955. external,
  2956. once
  2957. } of eventListeners.slice(0)) {
  2958. if (once) {
  2959. this._off(eventName, listener);
  2960. }
  2961. if (external) {
  2962. (externalListeners || (externalListeners = [])).push(listener);
  2963. continue;
  2964. }
  2965. listener.apply(null, args);
  2966. }
  2967. if (externalListeners) {
  2968. for (const listener of externalListeners) {
  2969. listener.apply(null, args);
  2970. }
  2971. externalListeners = null;
  2972. }
  2973. }
  2974. _on(eventName, listener, options = null) {
  2975. var _this$_listeners;
  2976. const eventListeners = (_this$_listeners = this._listeners)[eventName] || (_this$_listeners[eventName] = []);
  2977. eventListeners.push({
  2978. listener,
  2979. external: options?.external === true,
  2980. once: options?.once === true
  2981. });
  2982. }
  2983. _off(eventName, listener, options = null) {
  2984. const eventListeners = this._listeners[eventName];
  2985. if (!eventListeners) {
  2986. return;
  2987. }
  2988. for (let i = 0, ii = eventListeners.length; i < ii; i++) {
  2989. if (eventListeners[i].listener === listener) {
  2990. eventListeners.splice(i, 1);
  2991. return;
  2992. }
  2993. }
  2994. }
  2995. }
  2996. exports.EventBus = EventBus;
  2997. function clamp(v, min, max) {
  2998. return Math.min(Math.max(v, min), max);
  2999. }
  3000. class ProgressBar {
  3001. constructor(id, {
  3002. height,
  3003. width,
  3004. units
  3005. } = {}) {
  3006. this.visible = true;
  3007. this.div = document.querySelector(id + " .progress");
  3008. this.bar = this.div.parentNode;
  3009. this.height = height || 100;
  3010. this.width = width || 100;
  3011. this.units = units || "%";
  3012. this.div.style.height = this.height + this.units;
  3013. this.percent = 0;
  3014. }
  3015. _updateBar() {
  3016. if (this._indeterminate) {
  3017. this.div.classList.add("indeterminate");
  3018. this.div.style.width = this.width + this.units;
  3019. return;
  3020. }
  3021. this.div.classList.remove("indeterminate");
  3022. const progressSize = this.width * this._percent / 100;
  3023. this.div.style.width = progressSize + this.units;
  3024. }
  3025. get percent() {
  3026. return this._percent;
  3027. }
  3028. set percent(val) {
  3029. this._indeterminate = isNaN(val);
  3030. this._percent = clamp(val, 0, 100);
  3031. this._updateBar();
  3032. }
  3033. setWidth(viewer) {
  3034. if (!viewer) {
  3035. return;
  3036. }
  3037. const container = viewer.parentNode;
  3038. const scrollbarWidth = container.offsetWidth - viewer.offsetWidth;
  3039. if (scrollbarWidth > 0) {
  3040. const doc = document.documentElement;
  3041. doc.style.setProperty(LOADINGBAR_END_OFFSET_VAR, `${scrollbarWidth}px`);
  3042. }
  3043. }
  3044. hide() {
  3045. if (!this.visible) {
  3046. return;
  3047. }
  3048. this.visible = false;
  3049. this.bar.classList.add("hidden");
  3050. }
  3051. show() {
  3052. if (this.visible) {
  3053. return;
  3054. }
  3055. this.visible = true;
  3056. this.bar.classList.remove("hidden");
  3057. }
  3058. }
  3059. exports.ProgressBar = ProgressBar;
  3060. function moveToEndOfArray(arr, condition) {
  3061. const moved = [],
  3062. len = arr.length;
  3063. let write = 0;
  3064. for (let read = 0; read < len; ++read) {
  3065. if (condition(arr[read])) {
  3066. moved.push(arr[read]);
  3067. } else {
  3068. arr[write] = arr[read];
  3069. ++write;
  3070. }
  3071. }
  3072. for (let read = 0; write < len; ++read, ++write) {
  3073. arr[write] = moved[read];
  3074. }
  3075. }
  3076. function getActiveOrFocusedElement() {
  3077. let curRoot = document;
  3078. let curActiveOrFocused = curRoot.activeElement || curRoot.querySelector(":focus");
  3079. while (curActiveOrFocused?.shadowRoot) {
  3080. curRoot = curActiveOrFocused.shadowRoot;
  3081. curActiveOrFocused = curRoot.activeElement || curRoot.querySelector(":focus");
  3082. }
  3083. return curActiveOrFocused;
  3084. }
  3085. function apiPageLayoutToSpreadMode(layout) {
  3086. switch (layout) {
  3087. case "SinglePage":
  3088. case "OneColumn":
  3089. return SpreadMode.NONE;
  3090. case "TwoColumnLeft":
  3091. case "TwoPageLeft":
  3092. return SpreadMode.ODD;
  3093. case "TwoColumnRight":
  3094. case "TwoPageRight":
  3095. return SpreadMode.EVEN;
  3096. }
  3097. return SpreadMode.NONE;
  3098. }
  3099. function apiPageModeToSidebarView(mode) {
  3100. switch (mode) {
  3101. case "UseNone":
  3102. return SidebarView.NONE;
  3103. case "UseThumbs":
  3104. return SidebarView.THUMBS;
  3105. case "UseOutlines":
  3106. return SidebarView.OUTLINE;
  3107. case "UseAttachments":
  3108. return SidebarView.ATTACHMENTS;
  3109. case "UseOC":
  3110. return SidebarView.LAYERS;
  3111. }
  3112. return SidebarView.NONE;
  3113. }
  3114. /***/ }),
  3115. /* 5 */
  3116. /***/ ((module) => {
  3117. let pdfjsLib;
  3118. if (typeof window !== "undefined" && window["pdfjs-dist/build/pdf"]) {
  3119. pdfjsLib = window["pdfjs-dist/build/pdf"];
  3120. } else {
  3121. pdfjsLib = require("../build/pdf.js");
  3122. }
  3123. module.exports = pdfjsLib;
  3124. /***/ }),
  3125. /* 6 */
  3126. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3127. Object.defineProperty(exports, "__esModule", ({
  3128. value: true
  3129. }));
  3130. exports.PDFCursorTools = exports.CursorTool = void 0;
  3131. var _grab_to_pan = __webpack_require__(7);
  3132. var _ui_utils = __webpack_require__(4);
  3133. const CursorTool = {
  3134. SELECT: 0,
  3135. HAND: 1,
  3136. ZOOM: 2
  3137. };
  3138. exports.CursorTool = CursorTool;
  3139. class PDFCursorTools {
  3140. constructor({
  3141. container,
  3142. eventBus,
  3143. cursorToolOnLoad = CursorTool.SELECT
  3144. }) {
  3145. this.container = container;
  3146. this.eventBus = eventBus;
  3147. this.active = CursorTool.SELECT;
  3148. this.activeBeforePresentationMode = null;
  3149. this.handTool = new _grab_to_pan.GrabToPan({
  3150. element: this.container
  3151. });
  3152. this._addEventListeners();
  3153. Promise.resolve().then(() => {
  3154. this.switchTool(cursorToolOnLoad);
  3155. });
  3156. }
  3157. get activeTool() {
  3158. return this.active;
  3159. }
  3160. switchTool(tool) {
  3161. if (this.activeBeforePresentationMode !== null) {
  3162. return;
  3163. }
  3164. if (tool === this.active) {
  3165. return;
  3166. }
  3167. const disableActiveTool = () => {
  3168. switch (this.active) {
  3169. case CursorTool.SELECT:
  3170. break;
  3171. case CursorTool.HAND:
  3172. this.handTool.deactivate();
  3173. break;
  3174. case CursorTool.ZOOM:
  3175. }
  3176. };
  3177. switch (tool) {
  3178. case CursorTool.SELECT:
  3179. disableActiveTool();
  3180. break;
  3181. case CursorTool.HAND:
  3182. disableActiveTool();
  3183. this.handTool.activate();
  3184. break;
  3185. case CursorTool.ZOOM:
  3186. default:
  3187. console.error(`switchTool: "${tool}" is an unsupported value.`);
  3188. return;
  3189. }
  3190. this.active = tool;
  3191. this._dispatchEvent();
  3192. }
  3193. _dispatchEvent() {
  3194. this.eventBus.dispatch("cursortoolchanged", {
  3195. source: this,
  3196. tool: this.active
  3197. });
  3198. }
  3199. _addEventListeners() {
  3200. this.eventBus._on("switchcursortool", evt => {
  3201. this.switchTool(evt.tool);
  3202. });
  3203. this.eventBus._on("presentationmodechanged", evt => {
  3204. switch (evt.state) {
  3205. case _ui_utils.PresentationModeState.FULLSCREEN:
  3206. {
  3207. const previouslyActive = this.active;
  3208. this.switchTool(CursorTool.SELECT);
  3209. this.activeBeforePresentationMode = previouslyActive;
  3210. break;
  3211. }
  3212. case _ui_utils.PresentationModeState.NORMAL:
  3213. {
  3214. const previouslyActive = this.activeBeforePresentationMode;
  3215. this.activeBeforePresentationMode = null;
  3216. this.switchTool(previouslyActive);
  3217. break;
  3218. }
  3219. }
  3220. });
  3221. }
  3222. }
  3223. exports.PDFCursorTools = PDFCursorTools;
  3224. /***/ }),
  3225. /* 7 */
  3226. /***/ ((__unused_webpack_module, exports) => {
  3227. Object.defineProperty(exports, "__esModule", ({
  3228. value: true
  3229. }));
  3230. exports.GrabToPan = GrabToPan;
  3231. function GrabToPan(options) {
  3232. this.element = options.element;
  3233. this.document = options.element.ownerDocument;
  3234. if (typeof options.ignoreTarget === "function") {
  3235. this.ignoreTarget = options.ignoreTarget;
  3236. }
  3237. this.onActiveChanged = options.onActiveChanged;
  3238. this.activate = this.activate.bind(this);
  3239. this.deactivate = this.deactivate.bind(this);
  3240. this.toggle = this.toggle.bind(this);
  3241. this._onmousedown = this._onmousedown.bind(this);
  3242. this._onmousemove = this._onmousemove.bind(this);
  3243. this._endPan = this._endPan.bind(this);
  3244. const overlay = this.overlay = document.createElement("div");
  3245. overlay.className = "grab-to-pan-grabbing";
  3246. }
  3247. GrabToPan.prototype = {
  3248. CSS_CLASS_GRAB: "grab-to-pan-grab",
  3249. activate: function GrabToPan_activate() {
  3250. if (!this.active) {
  3251. this.active = true;
  3252. this.element.addEventListener("mousedown", this._onmousedown, true);
  3253. this.element.classList.add(this.CSS_CLASS_GRAB);
  3254. if (this.onActiveChanged) {
  3255. this.onActiveChanged(true);
  3256. }
  3257. }
  3258. },
  3259. deactivate: function GrabToPan_deactivate() {
  3260. if (this.active) {
  3261. this.active = false;
  3262. this.element.removeEventListener("mousedown", this._onmousedown, true);
  3263. this._endPan();
  3264. this.element.classList.remove(this.CSS_CLASS_GRAB);
  3265. if (this.onActiveChanged) {
  3266. this.onActiveChanged(false);
  3267. }
  3268. }
  3269. },
  3270. toggle: function GrabToPan_toggle() {
  3271. if (this.active) {
  3272. this.deactivate();
  3273. } else {
  3274. this.activate();
  3275. }
  3276. },
  3277. ignoreTarget: function GrabToPan_ignoreTarget(node) {
  3278. return node.matches("a[href], a[href] *, input, textarea, button, button *, select, option");
  3279. },
  3280. _onmousedown: function GrabToPan__onmousedown(event) {
  3281. if (event.button !== 0 || this.ignoreTarget(event.target)) {
  3282. return;
  3283. }
  3284. if (event.originalTarget) {
  3285. try {
  3286. event.originalTarget.tagName;
  3287. } catch (e) {
  3288. return;
  3289. }
  3290. }
  3291. this.scrollLeftStart = this.element.scrollLeft;
  3292. this.scrollTopStart = this.element.scrollTop;
  3293. this.clientXStart = event.clientX;
  3294. this.clientYStart = event.clientY;
  3295. this.document.addEventListener("mousemove", this._onmousemove, true);
  3296. this.document.addEventListener("mouseup", this._endPan, true);
  3297. this.element.addEventListener("scroll", this._endPan, true);
  3298. event.preventDefault();
  3299. event.stopPropagation();
  3300. const focusedElement = document.activeElement;
  3301. if (focusedElement && !focusedElement.contains(event.target)) {
  3302. focusedElement.blur();
  3303. }
  3304. },
  3305. _onmousemove: function GrabToPan__onmousemove(event) {
  3306. this.element.removeEventListener("scroll", this._endPan, true);
  3307. if (isLeftMouseReleased(event)) {
  3308. this._endPan();
  3309. return;
  3310. }
  3311. const xDiff = event.clientX - this.clientXStart;
  3312. const yDiff = event.clientY - this.clientYStart;
  3313. const scrollTop = this.scrollTopStart - yDiff;
  3314. const scrollLeft = this.scrollLeftStart - xDiff;
  3315. if (this.element.scrollTo) {
  3316. this.element.scrollTo({
  3317. top: scrollTop,
  3318. left: scrollLeft,
  3319. behavior: "instant"
  3320. });
  3321. } else {
  3322. this.element.scrollTop = scrollTop;
  3323. this.element.scrollLeft = scrollLeft;
  3324. }
  3325. if (!this.overlay.parentNode) {
  3326. document.body.appendChild(this.overlay);
  3327. }
  3328. },
  3329. _endPan: function GrabToPan__endPan() {
  3330. this.element.removeEventListener("scroll", this._endPan, true);
  3331. this.document.removeEventListener("mousemove", this._onmousemove, true);
  3332. this.document.removeEventListener("mouseup", this._endPan, true);
  3333. this.overlay.remove();
  3334. }
  3335. };
  3336. function isLeftMouseReleased(event) {
  3337. if ("buttons" in event) {
  3338. return !(event.buttons & 1);
  3339. }
  3340. const chrome = window.chrome;
  3341. const isChrome15OrOpera15plus = chrome && (chrome.webstore || chrome.app);
  3342. const isSafari6plus = /Apple/.test(navigator.vendor) && /Version\/([6-9]\d*|[1-5]\d+)/.test(navigator.userAgent);
  3343. if (isChrome15OrOpera15plus || isSafari6plus) {
  3344. return event.which === 0;
  3345. }
  3346. return false;
  3347. }
  3348. /***/ }),
  3349. /* 8 */
  3350. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3351. Object.defineProperty(exports, "__esModule", ({
  3352. value: true
  3353. }));
  3354. exports.RenderingStates = exports.PDFRenderingQueue = void 0;
  3355. var _pdfjsLib = __webpack_require__(5);
  3356. const CLEANUP_TIMEOUT = 30000;
  3357. const RenderingStates = {
  3358. INITIAL: 0,
  3359. RUNNING: 1,
  3360. PAUSED: 2,
  3361. FINISHED: 3
  3362. };
  3363. exports.RenderingStates = RenderingStates;
  3364. class PDFRenderingQueue {
  3365. constructor() {
  3366. this.pdfViewer = null;
  3367. this.pdfThumbnailViewer = null;
  3368. this.onIdle = null;
  3369. this.highestPriorityPage = null;
  3370. this.idleTimeout = null;
  3371. this.printing = false;
  3372. this.isThumbnailViewEnabled = false;
  3373. }
  3374. setViewer(pdfViewer) {
  3375. this.pdfViewer = pdfViewer;
  3376. }
  3377. setThumbnailViewer(pdfThumbnailViewer) {
  3378. this.pdfThumbnailViewer = pdfThumbnailViewer;
  3379. }
  3380. isHighestPriority(view) {
  3381. return this.highestPriorityPage === view.renderingId;
  3382. }
  3383. renderHighestPriority(currentlyVisiblePages) {
  3384. if (this.idleTimeout) {
  3385. clearTimeout(this.idleTimeout);
  3386. this.idleTimeout = null;
  3387. }
  3388. if (this.pdfViewer.forceRendering(currentlyVisiblePages)) {
  3389. return;
  3390. }
  3391. if (this.pdfThumbnailViewer && this.isThumbnailViewEnabled) {
  3392. if (this.pdfThumbnailViewer.forceRendering()) {
  3393. return;
  3394. }
  3395. }
  3396. if (this.printing) {
  3397. return;
  3398. }
  3399. if (this.onIdle) {
  3400. this.idleTimeout = setTimeout(this.onIdle.bind(this), CLEANUP_TIMEOUT);
  3401. }
  3402. }
  3403. getHighestPriority(visible, views, scrolledDown) {
  3404. const visibleViews = visible.views;
  3405. const numVisible = visibleViews.length;
  3406. if (numVisible === 0) {
  3407. return null;
  3408. }
  3409. for (let i = 0; i < numVisible; ++i) {
  3410. const view = visibleViews[i].view;
  3411. if (!this.isViewFinished(view)) {
  3412. return view;
  3413. }
  3414. }
  3415. if (scrolledDown) {
  3416. const nextPageIndex = visible.last.id;
  3417. if (views[nextPageIndex] && !this.isViewFinished(views[nextPageIndex])) {
  3418. return views[nextPageIndex];
  3419. }
  3420. } else {
  3421. const previousPageIndex = visible.first.id - 2;
  3422. if (views[previousPageIndex] && !this.isViewFinished(views[previousPageIndex])) {
  3423. return views[previousPageIndex];
  3424. }
  3425. }
  3426. return null;
  3427. }
  3428. isViewFinished(view) {
  3429. return view.renderingState === RenderingStates.FINISHED;
  3430. }
  3431. renderView(view) {
  3432. switch (view.renderingState) {
  3433. case RenderingStates.FINISHED:
  3434. return false;
  3435. case RenderingStates.PAUSED:
  3436. this.highestPriorityPage = view.renderingId;
  3437. view.resume();
  3438. break;
  3439. case RenderingStates.RUNNING:
  3440. this.highestPriorityPage = view.renderingId;
  3441. break;
  3442. case RenderingStates.INITIAL:
  3443. this.highestPriorityPage = view.renderingId;
  3444. view.draw().finally(() => {
  3445. this.renderHighestPriority();
  3446. }).catch(reason => {
  3447. if (reason instanceof _pdfjsLib.RenderingCancelledException) {
  3448. return;
  3449. }
  3450. console.error(`renderView: "${reason}"`);
  3451. });
  3452. break;
  3453. }
  3454. return true;
  3455. }
  3456. }
  3457. exports.PDFRenderingQueue = PDFRenderingQueue;
  3458. /***/ }),
  3459. /* 9 */
  3460. /***/ ((__unused_webpack_module, exports) => {
  3461. Object.defineProperty(exports, "__esModule", ({
  3462. value: true
  3463. }));
  3464. exports.OverlayManager = void 0;
  3465. class OverlayManager {
  3466. constructor() {
  3467. this._overlays = {};
  3468. this._active = null;
  3469. this._keyDownBound = this._keyDown.bind(this);
  3470. }
  3471. get active() {
  3472. return this._active;
  3473. }
  3474. async register(name, element, callerCloseMethod = null, canForceClose = false) {
  3475. let container;
  3476. if (!name || !element || !(container = element.parentNode)) {
  3477. throw new Error("Not enough parameters.");
  3478. } else if (this._overlays[name]) {
  3479. throw new Error("The overlay is already registered.");
  3480. }
  3481. this._overlays[name] = {
  3482. element,
  3483. container,
  3484. callerCloseMethod,
  3485. canForceClose
  3486. };
  3487. }
  3488. async unregister(name) {
  3489. if (!this._overlays[name]) {
  3490. throw new Error("The overlay does not exist.");
  3491. } else if (this._active === name) {
  3492. throw new Error("The overlay cannot be removed while it is active.");
  3493. }
  3494. delete this._overlays[name];
  3495. }
  3496. async open(name) {
  3497. if (!this._overlays[name]) {
  3498. throw new Error("The overlay does not exist.");
  3499. } else if (this._active) {
  3500. if (this._overlays[name].canForceClose) {
  3501. this._closeThroughCaller();
  3502. } else if (this._active === name) {
  3503. throw new Error("The overlay is already active.");
  3504. } else {
  3505. throw new Error("Another overlay is currently active.");
  3506. }
  3507. }
  3508. this._active = name;
  3509. this._overlays[this._active].element.classList.remove("hidden");
  3510. this._overlays[this._active].container.classList.remove("hidden");
  3511. window.addEventListener("keydown", this._keyDownBound);
  3512. }
  3513. async close(name) {
  3514. if (!this._overlays[name]) {
  3515. throw new Error("The overlay does not exist.");
  3516. } else if (!this._active) {
  3517. throw new Error("The overlay is currently not active.");
  3518. } else if (this._active !== name) {
  3519. throw new Error("Another overlay is currently active.");
  3520. }
  3521. this._overlays[this._active].container.classList.add("hidden");
  3522. this._overlays[this._active].element.classList.add("hidden");
  3523. this._active = null;
  3524. window.removeEventListener("keydown", this._keyDownBound);
  3525. }
  3526. _keyDown(evt) {
  3527. if (this._active && evt.keyCode === 27) {
  3528. this._closeThroughCaller();
  3529. evt.preventDefault();
  3530. }
  3531. }
  3532. _closeThroughCaller() {
  3533. if (this._overlays[this._active].callerCloseMethod) {
  3534. this._overlays[this._active].callerCloseMethod();
  3535. }
  3536. if (this._active) {
  3537. this.close(this._active);
  3538. }
  3539. }
  3540. }
  3541. exports.OverlayManager = OverlayManager;
  3542. /***/ }),
  3543. /* 10 */
  3544. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3545. Object.defineProperty(exports, "__esModule", ({
  3546. value: true
  3547. }));
  3548. exports.PasswordPrompt = void 0;
  3549. var _pdfjsLib = __webpack_require__(5);
  3550. class PasswordPrompt {
  3551. constructor(options, overlayManager, l10n, isViewerEmbedded = false) {
  3552. this.overlayName = options.overlayName;
  3553. this.container = options.container;
  3554. this.label = options.label;
  3555. this.input = options.input;
  3556. this.submitButton = options.submitButton;
  3557. this.cancelButton = options.cancelButton;
  3558. this.overlayManager = overlayManager;
  3559. this.l10n = l10n;
  3560. this._isViewerEmbedded = isViewerEmbedded;
  3561. this.updateCallback = null;
  3562. this.reason = null;
  3563. this.submitButton.addEventListener("click", this.verify.bind(this));
  3564. this.cancelButton.addEventListener("click", this.close.bind(this));
  3565. this.input.addEventListener("keydown", e => {
  3566. if (e.keyCode === 13) {
  3567. this.verify();
  3568. }
  3569. });
  3570. this.overlayManager.register(this.overlayName, this.container, this.close.bind(this), true);
  3571. }
  3572. async open() {
  3573. await this.overlayManager.open(this.overlayName);
  3574. const passwordIncorrect = this.reason === _pdfjsLib.PasswordResponses.INCORRECT_PASSWORD;
  3575. if (!this._isViewerEmbedded || passwordIncorrect) {
  3576. this.input.focus();
  3577. }
  3578. this.label.textContent = await this.l10n.get(`password_${passwordIncorrect ? "invalid" : "label"}`);
  3579. }
  3580. close() {
  3581. this.overlayManager.close(this.overlayName).then(() => {
  3582. this.input.value = "";
  3583. });
  3584. }
  3585. verify() {
  3586. const password = this.input.value;
  3587. if (password?.length > 0) {
  3588. this.close();
  3589. this.updateCallback(password);
  3590. }
  3591. }
  3592. setUpdateCallback(updateCallback, reason) {
  3593. this.updateCallback = updateCallback;
  3594. this.reason = reason;
  3595. }
  3596. }
  3597. exports.PasswordPrompt = PasswordPrompt;
  3598. /***/ }),
  3599. /* 11 */
  3600. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3601. Object.defineProperty(exports, "__esModule", ({
  3602. value: true
  3603. }));
  3604. exports.PDFAttachmentViewer = void 0;
  3605. var _pdfjsLib = __webpack_require__(5);
  3606. var _base_tree_viewer = __webpack_require__(12);
  3607. class PDFAttachmentViewer extends _base_tree_viewer.BaseTreeViewer {
  3608. constructor(options) {
  3609. super(options);
  3610. this.downloadManager = options.downloadManager;
  3611. this.eventBus._on("fileattachmentannotation", this._appendAttachment.bind(this));
  3612. }
  3613. reset(keepRenderedCapability = false) {
  3614. super.reset();
  3615. this._attachments = null;
  3616. if (!keepRenderedCapability) {
  3617. this._renderedCapability = (0, _pdfjsLib.createPromiseCapability)();
  3618. }
  3619. if (this._pendingDispatchEvent) {
  3620. clearTimeout(this._pendingDispatchEvent);
  3621. }
  3622. this._pendingDispatchEvent = null;
  3623. }
  3624. _dispatchEvent(attachmentsCount) {
  3625. this._renderedCapability.resolve();
  3626. if (this._pendingDispatchEvent) {
  3627. clearTimeout(this._pendingDispatchEvent);
  3628. this._pendingDispatchEvent = null;
  3629. }
  3630. if (attachmentsCount === 0) {
  3631. this._pendingDispatchEvent = setTimeout(() => {
  3632. this.eventBus.dispatch("attachmentsloaded", {
  3633. source: this,
  3634. attachmentsCount: 0
  3635. });
  3636. this._pendingDispatchEvent = null;
  3637. });
  3638. return;
  3639. }
  3640. this.eventBus.dispatch("attachmentsloaded", {
  3641. source: this,
  3642. attachmentsCount
  3643. });
  3644. }
  3645. _bindLink(element, {
  3646. content,
  3647. filename
  3648. }) {
  3649. element.onclick = () => {
  3650. this.downloadManager.openOrDownloadData(element, content, filename);
  3651. return false;
  3652. };
  3653. }
  3654. render({
  3655. attachments,
  3656. keepRenderedCapability = false
  3657. }) {
  3658. if (this._attachments) {
  3659. this.reset(keepRenderedCapability);
  3660. }
  3661. this._attachments = attachments || null;
  3662. if (!attachments) {
  3663. this._dispatchEvent(0);
  3664. return;
  3665. }
  3666. const names = Object.keys(attachments).sort(function (a, b) {
  3667. return a.toLowerCase().localeCompare(b.toLowerCase());
  3668. });
  3669. const fragment = document.createDocumentFragment();
  3670. let attachmentsCount = 0;
  3671. for (const name of names) {
  3672. const item = attachments[name];
  3673. const content = item.content,
  3674. filename = (0, _pdfjsLib.getFilenameFromUrl)(item.filename);
  3675. const div = document.createElement("div");
  3676. div.className = "treeItem";
  3677. const element = document.createElement("a");
  3678. this._bindLink(element, {
  3679. content,
  3680. filename
  3681. });
  3682. element.textContent = this._normalizeTextContent(filename);
  3683. div.appendChild(element);
  3684. fragment.appendChild(div);
  3685. attachmentsCount++;
  3686. }
  3687. this._finishRendering(fragment, attachmentsCount);
  3688. }
  3689. _appendAttachment({
  3690. id,
  3691. filename,
  3692. content
  3693. }) {
  3694. const renderedPromise = this._renderedCapability.promise;
  3695. renderedPromise.then(() => {
  3696. if (renderedPromise !== this._renderedCapability.promise) {
  3697. return;
  3698. }
  3699. let attachments = this._attachments;
  3700. if (!attachments) {
  3701. attachments = Object.create(null);
  3702. } else {
  3703. for (const name in attachments) {
  3704. if (id === name) {
  3705. return;
  3706. }
  3707. }
  3708. }
  3709. attachments[id] = {
  3710. filename,
  3711. content
  3712. };
  3713. this.render({
  3714. attachments,
  3715. keepRenderedCapability: true
  3716. });
  3717. });
  3718. }
  3719. }
  3720. exports.PDFAttachmentViewer = PDFAttachmentViewer;
  3721. /***/ }),
  3722. /* 12 */
  3723. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3724. Object.defineProperty(exports, "__esModule", ({
  3725. value: true
  3726. }));
  3727. exports.BaseTreeViewer = void 0;
  3728. var _pdfjsLib = __webpack_require__(5);
  3729. const TREEITEM_OFFSET_TOP = -100;
  3730. const TREEITEM_SELECTED_CLASS = "selected";
  3731. class BaseTreeViewer {
  3732. constructor(options) {
  3733. if (this.constructor === BaseTreeViewer) {
  3734. throw new Error("Cannot initialize BaseTreeViewer.");
  3735. }
  3736. this.container = options.container;
  3737. this.eventBus = options.eventBus;
  3738. this.reset();
  3739. }
  3740. reset() {
  3741. this._pdfDocument = null;
  3742. this._lastToggleIsShow = true;
  3743. this._currentTreeItem = null;
  3744. this.container.textContent = "";
  3745. this.container.classList.remove("treeWithDeepNesting");
  3746. }
  3747. _dispatchEvent(count) {
  3748. throw new Error("Not implemented: _dispatchEvent");
  3749. }
  3750. _bindLink(element, params) {
  3751. throw new Error("Not implemented: _bindLink");
  3752. }
  3753. _normalizeTextContent(str) {
  3754. return (0, _pdfjsLib.removeNullCharacters)(str) || "\u2013";
  3755. }
  3756. _addToggleButton(div, hidden = false) {
  3757. const toggler = document.createElement("div");
  3758. toggler.className = "treeItemToggler";
  3759. if (hidden) {
  3760. toggler.classList.add("treeItemsHidden");
  3761. }
  3762. toggler.onclick = evt => {
  3763. evt.stopPropagation();
  3764. toggler.classList.toggle("treeItemsHidden");
  3765. if (evt.shiftKey) {
  3766. const shouldShowAll = !toggler.classList.contains("treeItemsHidden");
  3767. this._toggleTreeItem(div, shouldShowAll);
  3768. }
  3769. };
  3770. div.insertBefore(toggler, div.firstChild);
  3771. }
  3772. _toggleTreeItem(root, show = false) {
  3773. this._lastToggleIsShow = show;
  3774. for (const toggler of root.querySelectorAll(".treeItemToggler")) {
  3775. toggler.classList.toggle("treeItemsHidden", !show);
  3776. }
  3777. }
  3778. _toggleAllTreeItems() {
  3779. this._toggleTreeItem(this.container, !this._lastToggleIsShow);
  3780. }
  3781. _finishRendering(fragment, count, hasAnyNesting = false) {
  3782. if (hasAnyNesting) {
  3783. this.container.classList.add("treeWithDeepNesting");
  3784. this._lastToggleIsShow = !fragment.querySelector(".treeItemsHidden");
  3785. }
  3786. this.container.appendChild(fragment);
  3787. this._dispatchEvent(count);
  3788. }
  3789. render(params) {
  3790. throw new Error("Not implemented: render");
  3791. }
  3792. _updateCurrentTreeItem(treeItem = null) {
  3793. if (this._currentTreeItem) {
  3794. this._currentTreeItem.classList.remove(TREEITEM_SELECTED_CLASS);
  3795. this._currentTreeItem = null;
  3796. }
  3797. if (treeItem) {
  3798. treeItem.classList.add(TREEITEM_SELECTED_CLASS);
  3799. this._currentTreeItem = treeItem;
  3800. }
  3801. }
  3802. _scrollToCurrentTreeItem(treeItem) {
  3803. if (!treeItem) {
  3804. return;
  3805. }
  3806. let currentNode = treeItem.parentNode;
  3807. while (currentNode && currentNode !== this.container) {
  3808. if (currentNode.classList.contains("treeItem")) {
  3809. const toggler = currentNode.firstElementChild;
  3810. toggler?.classList.remove("treeItemsHidden");
  3811. }
  3812. currentNode = currentNode.parentNode;
  3813. }
  3814. this._updateCurrentTreeItem(treeItem);
  3815. this.container.scrollTo(treeItem.offsetLeft, treeItem.offsetTop + TREEITEM_OFFSET_TOP);
  3816. }
  3817. }
  3818. exports.BaseTreeViewer = BaseTreeViewer;
  3819. /***/ }),
  3820. /* 13 */
  3821. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3822. Object.defineProperty(exports, "__esModule", ({
  3823. value: true
  3824. }));
  3825. exports.PDFDocumentProperties = void 0;
  3826. var _pdfjsLib = __webpack_require__(5);
  3827. var _ui_utils = __webpack_require__(4);
  3828. const DEFAULT_FIELD_CONTENT = "-";
  3829. const NON_METRIC_LOCALES = ["en-us", "en-lr", "my"];
  3830. const US_PAGE_NAMES = {
  3831. "8.5x11": "Letter",
  3832. "8.5x14": "Legal"
  3833. };
  3834. const METRIC_PAGE_NAMES = {
  3835. "297x420": "A3",
  3836. "210x297": "A4"
  3837. };
  3838. function getPageName(size, isPortrait, pageNames) {
  3839. const width = isPortrait ? size.width : size.height;
  3840. const height = isPortrait ? size.height : size.width;
  3841. return pageNames[`${width}x${height}`];
  3842. }
  3843. class PDFDocumentProperties {
  3844. constructor({
  3845. overlayName,
  3846. fields,
  3847. container,
  3848. closeButton
  3849. }, overlayManager, eventBus, l10n) {
  3850. this.overlayName = overlayName;
  3851. this.fields = fields;
  3852. this.container = container;
  3853. this.overlayManager = overlayManager;
  3854. this.l10n = l10n;
  3855. this._reset();
  3856. closeButton.addEventListener("click", this.close.bind(this));
  3857. this.overlayManager.register(this.overlayName, this.container, this.close.bind(this));
  3858. eventBus._on("pagechanging", evt => {
  3859. this._currentPageNumber = evt.pageNumber;
  3860. });
  3861. eventBus._on("rotationchanging", evt => {
  3862. this._pagesRotation = evt.pagesRotation;
  3863. });
  3864. this._isNonMetricLocale = true;
  3865. l10n.getLanguage().then(locale => {
  3866. this._isNonMetricLocale = NON_METRIC_LOCALES.includes(locale);
  3867. });
  3868. }
  3869. async open() {
  3870. const freezeFieldData = data => {
  3871. Object.defineProperty(this, "fieldData", {
  3872. value: Object.freeze(data),
  3873. writable: false,
  3874. enumerable: true,
  3875. configurable: true
  3876. });
  3877. };
  3878. await Promise.all([this.overlayManager.open(this.overlayName), this._dataAvailableCapability.promise]);
  3879. const currentPageNumber = this._currentPageNumber;
  3880. const pagesRotation = this._pagesRotation;
  3881. if (this.fieldData && currentPageNumber === this.fieldData._currentPageNumber && pagesRotation === this.fieldData._pagesRotation) {
  3882. this._updateUI();
  3883. return;
  3884. }
  3885. const {
  3886. info,
  3887. contentDispositionFilename,
  3888. contentLength
  3889. } = await this.pdfDocument.getMetadata();
  3890. const [fileName, fileSize, creationDate, modificationDate, pageSize, isLinearized] = await Promise.all([contentDispositionFilename || (0, _pdfjsLib.getPdfFilenameFromUrl)(this.url), this._parseFileSize(contentLength), this._parseDate(info.CreationDate), this._parseDate(info.ModDate), this.pdfDocument.getPage(currentPageNumber).then(pdfPage => {
  3891. return this._parsePageSize((0, _ui_utils.getPageSizeInches)(pdfPage), pagesRotation);
  3892. }), this._parseLinearization(info.IsLinearized)]);
  3893. freezeFieldData({
  3894. fileName,
  3895. fileSize,
  3896. title: info.Title,
  3897. author: info.Author,
  3898. subject: info.Subject,
  3899. keywords: info.Keywords,
  3900. creationDate,
  3901. modificationDate,
  3902. creator: info.Creator,
  3903. producer: info.Producer,
  3904. version: info.PDFFormatVersion,
  3905. pageCount: this.pdfDocument.numPages,
  3906. pageSize,
  3907. linearized: isLinearized,
  3908. _currentPageNumber: currentPageNumber,
  3909. _pagesRotation: pagesRotation
  3910. });
  3911. this._updateUI();
  3912. const {
  3913. length
  3914. } = await this.pdfDocument.getDownloadInfo();
  3915. if (contentLength === length) {
  3916. return;
  3917. }
  3918. const data = Object.assign(Object.create(null), this.fieldData);
  3919. data.fileSize = await this._parseFileSize(length);
  3920. freezeFieldData(data);
  3921. this._updateUI();
  3922. }
  3923. close() {
  3924. this.overlayManager.close(this.overlayName);
  3925. }
  3926. setDocument(pdfDocument, url = null) {
  3927. if (this.pdfDocument) {
  3928. this._reset();
  3929. this._updateUI(true);
  3930. }
  3931. if (!pdfDocument) {
  3932. return;
  3933. }
  3934. this.pdfDocument = pdfDocument;
  3935. this.url = url;
  3936. this._dataAvailableCapability.resolve();
  3937. }
  3938. _reset() {
  3939. this.pdfDocument = null;
  3940. this.url = null;
  3941. delete this.fieldData;
  3942. this._dataAvailableCapability = (0, _pdfjsLib.createPromiseCapability)();
  3943. this._currentPageNumber = 1;
  3944. this._pagesRotation = 0;
  3945. }
  3946. _updateUI(reset = false) {
  3947. if (reset || !this.fieldData) {
  3948. for (const id in this.fields) {
  3949. this.fields[id].textContent = DEFAULT_FIELD_CONTENT;
  3950. }
  3951. return;
  3952. }
  3953. if (this.overlayManager.active !== this.overlayName) {
  3954. return;
  3955. }
  3956. for (const id in this.fields) {
  3957. const content = this.fieldData[id];
  3958. this.fields[id].textContent = content || content === 0 ? content : DEFAULT_FIELD_CONTENT;
  3959. }
  3960. }
  3961. async _parseFileSize(fileSize = 0) {
  3962. const kb = fileSize / 1024,
  3963. mb = kb / 1024;
  3964. if (!kb) {
  3965. return undefined;
  3966. }
  3967. return this.l10n.get(`document_properties_${mb >= 1 ? "mb" : "kb"}`, {
  3968. size_mb: mb >= 1 && (+mb.toPrecision(3)).toLocaleString(),
  3969. size_kb: mb < 1 && (+kb.toPrecision(3)).toLocaleString(),
  3970. size_b: fileSize.toLocaleString()
  3971. });
  3972. }
  3973. async _parsePageSize(pageSizeInches, pagesRotation) {
  3974. if (!pageSizeInches) {
  3975. return undefined;
  3976. }
  3977. if (pagesRotation % 180 !== 0) {
  3978. pageSizeInches = {
  3979. width: pageSizeInches.height,
  3980. height: pageSizeInches.width
  3981. };
  3982. }
  3983. const isPortrait = (0, _ui_utils.isPortraitOrientation)(pageSizeInches);
  3984. let sizeInches = {
  3985. width: Math.round(pageSizeInches.width * 100) / 100,
  3986. height: Math.round(pageSizeInches.height * 100) / 100
  3987. };
  3988. let sizeMillimeters = {
  3989. width: Math.round(pageSizeInches.width * 25.4 * 10) / 10,
  3990. height: Math.round(pageSizeInches.height * 25.4 * 10) / 10
  3991. };
  3992. let rawName = getPageName(sizeInches, isPortrait, US_PAGE_NAMES) || getPageName(sizeMillimeters, isPortrait, METRIC_PAGE_NAMES);
  3993. if (!rawName && !(Number.isInteger(sizeMillimeters.width) && Number.isInteger(sizeMillimeters.height))) {
  3994. const exactMillimeters = {
  3995. width: pageSizeInches.width * 25.4,
  3996. height: pageSizeInches.height * 25.4
  3997. };
  3998. const intMillimeters = {
  3999. width: Math.round(sizeMillimeters.width),
  4000. height: Math.round(sizeMillimeters.height)
  4001. };
  4002. if (Math.abs(exactMillimeters.width - intMillimeters.width) < 0.1 && Math.abs(exactMillimeters.height - intMillimeters.height) < 0.1) {
  4003. rawName = getPageName(intMillimeters, isPortrait, METRIC_PAGE_NAMES);
  4004. if (rawName) {
  4005. sizeInches = {
  4006. width: Math.round(intMillimeters.width / 25.4 * 100) / 100,
  4007. height: Math.round(intMillimeters.height / 25.4 * 100) / 100
  4008. };
  4009. sizeMillimeters = intMillimeters;
  4010. }
  4011. }
  4012. }
  4013. const [{
  4014. width,
  4015. height
  4016. }, unit, name, orientation] = await Promise.all([this._isNonMetricLocale ? sizeInches : sizeMillimeters, this.l10n.get(`document_properties_page_size_unit_${this._isNonMetricLocale ? "inches" : "millimeters"}`), rawName && this.l10n.get(`document_properties_page_size_name_${rawName.toLowerCase()}`), this.l10n.get(`document_properties_page_size_orientation_${isPortrait ? "portrait" : "landscape"}`)]);
  4017. return this.l10n.get(`document_properties_page_size_dimension_${name ? "name_" : ""}string`, {
  4018. width: width.toLocaleString(),
  4019. height: height.toLocaleString(),
  4020. unit,
  4021. name,
  4022. orientation
  4023. });
  4024. }
  4025. async _parseDate(inputDate) {
  4026. const dateObject = _pdfjsLib.PDFDateString.toDateObject(inputDate);
  4027. if (!dateObject) {
  4028. return undefined;
  4029. }
  4030. return this.l10n.get("document_properties_date_string", {
  4031. date: dateObject.toLocaleDateString(),
  4032. time: dateObject.toLocaleTimeString()
  4033. });
  4034. }
  4035. _parseLinearization(isLinearized) {
  4036. return this.l10n.get(`document_properties_linearized_${isLinearized ? "yes" : "no"}`);
  4037. }
  4038. }
  4039. exports.PDFDocumentProperties = PDFDocumentProperties;
  4040. /***/ }),
  4041. /* 14 */
  4042. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4043. Object.defineProperty(exports, "__esModule", ({
  4044. value: true
  4045. }));
  4046. exports.PDFFindBar = void 0;
  4047. var _pdf_find_controller = __webpack_require__(15);
  4048. const MATCHES_COUNT_LIMIT = 1000;
  4049. class PDFFindBar {
  4050. constructor(options, eventBus, l10n) {
  4051. this.opened = false;
  4052. this.bar = options.bar;
  4053. this.toggleButton = options.toggleButton;
  4054. this.findField = options.findField;
  4055. this.highlightAll = options.highlightAllCheckbox;
  4056. this.caseSensitive = options.caseSensitiveCheckbox;
  4057. this.entireWord = options.entireWordCheckbox;
  4058. this.findMsg = options.findMsg;
  4059. this.findResultsCount = options.findResultsCount;
  4060. this.findPreviousButton = options.findPreviousButton;
  4061. this.findNextButton = options.findNextButton;
  4062. this.eventBus = eventBus;
  4063. this.l10n = l10n;
  4064. this.toggleButton.addEventListener("click", () => {
  4065. this.toggle();
  4066. });
  4067. this.findField.addEventListener("input", () => {
  4068. this.dispatchEvent("");
  4069. });
  4070. this.bar.addEventListener("keydown", e => {
  4071. switch (e.keyCode) {
  4072. case 13:
  4073. if (e.target === this.findField) {
  4074. this.dispatchEvent("again", e.shiftKey);
  4075. }
  4076. break;
  4077. case 27:
  4078. this.close();
  4079. break;
  4080. }
  4081. });
  4082. this.findPreviousButton.addEventListener("click", () => {
  4083. this.dispatchEvent("again", true);
  4084. });
  4085. this.findNextButton.addEventListener("click", () => {
  4086. this.dispatchEvent("again", false);
  4087. });
  4088. this.highlightAll.addEventListener("click", () => {
  4089. this.dispatchEvent("highlightallchange");
  4090. });
  4091. this.caseSensitive.addEventListener("click", () => {
  4092. this.dispatchEvent("casesensitivitychange");
  4093. });
  4094. this.entireWord.addEventListener("click", () => {
  4095. this.dispatchEvent("entirewordchange");
  4096. });
  4097. this.eventBus._on("resize", this._adjustWidth.bind(this));
  4098. }
  4099. reset() {
  4100. this.updateUIState();
  4101. }
  4102. dispatchEvent(type, findPrev) {
  4103. this.eventBus.dispatch("find", {
  4104. source: this,
  4105. type,
  4106. query: this.findField.value,
  4107. phraseSearch: true,
  4108. caseSensitive: this.caseSensitive.checked,
  4109. entireWord: this.entireWord.checked,
  4110. highlightAll: this.highlightAll.checked,
  4111. findPrevious: findPrev
  4112. });
  4113. }
  4114. updateUIState(state, previous, matchesCount) {
  4115. let findMsg = Promise.resolve("");
  4116. let status = "";
  4117. switch (state) {
  4118. case _pdf_find_controller.FindState.FOUND:
  4119. break;
  4120. case _pdf_find_controller.FindState.PENDING:
  4121. status = "pending";
  4122. break;
  4123. case _pdf_find_controller.FindState.NOT_FOUND:
  4124. findMsg = this.l10n.get("find_not_found");
  4125. status = "notFound";
  4126. break;
  4127. case _pdf_find_controller.FindState.WRAPPED:
  4128. findMsg = this.l10n.get(`find_reached_${previous ? "top" : "bottom"}`);
  4129. break;
  4130. }
  4131. this.findField.setAttribute("data-status", status);
  4132. findMsg.then(msg => {
  4133. this.findMsg.textContent = msg;
  4134. this._adjustWidth();
  4135. });
  4136. this.updateResultsCount(matchesCount);
  4137. }
  4138. updateResultsCount({
  4139. current = 0,
  4140. total = 0
  4141. } = {}) {
  4142. const limit = MATCHES_COUNT_LIMIT;
  4143. let matchCountMsg = Promise.resolve("");
  4144. if (total > 0) {
  4145. if (total > limit) {
  4146. let key = "find_match_count_limit";
  4147. matchCountMsg = this.l10n.get(key, {
  4148. limit
  4149. });
  4150. } else {
  4151. let key = "find_match_count";
  4152. matchCountMsg = this.l10n.get(key, {
  4153. current,
  4154. total
  4155. });
  4156. }
  4157. }
  4158. matchCountMsg.then(msg => {
  4159. this.findResultsCount.textContent = msg;
  4160. this.findResultsCount.classList.toggle("hidden", !total);
  4161. this._adjustWidth();
  4162. });
  4163. }
  4164. open() {
  4165. if (!this.opened) {
  4166. this.opened = true;
  4167. this.toggleButton.classList.add("toggled");
  4168. this.toggleButton.setAttribute("aria-expanded", "true");
  4169. this.bar.classList.remove("hidden");
  4170. }
  4171. this.findField.select();
  4172. this.findField.focus();
  4173. this._adjustWidth();
  4174. }
  4175. close() {
  4176. if (!this.opened) {
  4177. return;
  4178. }
  4179. this.opened = false;
  4180. this.toggleButton.classList.remove("toggled");
  4181. this.toggleButton.setAttribute("aria-expanded", "false");
  4182. this.bar.classList.add("hidden");
  4183. this.eventBus.dispatch("findbarclose", {
  4184. source: this
  4185. });
  4186. }
  4187. toggle() {
  4188. if (this.opened) {
  4189. this.close();
  4190. } else {
  4191. this.open();
  4192. }
  4193. }
  4194. _adjustWidth() {
  4195. if (!this.opened) {
  4196. return;
  4197. }
  4198. this.bar.classList.remove("wrapContainers");
  4199. const findbarHeight = this.bar.clientHeight;
  4200. const inputContainerHeight = this.bar.firstElementChild.clientHeight;
  4201. if (findbarHeight > inputContainerHeight) {
  4202. this.bar.classList.add("wrapContainers");
  4203. }
  4204. }
  4205. }
  4206. exports.PDFFindBar = PDFFindBar;
  4207. /***/ }),
  4208. /* 15 */
  4209. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4210. Object.defineProperty(exports, "__esModule", ({
  4211. value: true
  4212. }));
  4213. exports.PDFFindController = exports.FindState = void 0;
  4214. var _pdfjsLib = __webpack_require__(5);
  4215. var _pdf_find_utils = __webpack_require__(16);
  4216. var _ui_utils = __webpack_require__(4);
  4217. const FindState = {
  4218. FOUND: 0,
  4219. NOT_FOUND: 1,
  4220. WRAPPED: 2,
  4221. PENDING: 3
  4222. };
  4223. exports.FindState = FindState;
  4224. const FIND_TIMEOUT = 250;
  4225. const MATCH_SCROLL_OFFSET_TOP = -50;
  4226. const MATCH_SCROLL_OFFSET_LEFT = -400;
  4227. const CHARACTERS_TO_NORMALIZE = {
  4228. "\u2010": "-",
  4229. "\u2018": "'",
  4230. "\u2019": "'",
  4231. "\u201A": "'",
  4232. "\u201B": "'",
  4233. "\u201C": '"',
  4234. "\u201D": '"',
  4235. "\u201E": '"',
  4236. "\u201F": '"',
  4237. "\u00BC": "1/4",
  4238. "\u00BD": "1/2",
  4239. "\u00BE": "3/4"
  4240. };
  4241. let normalizationRegex = null;
  4242. function normalize(text) {
  4243. if (!normalizationRegex) {
  4244. const replace = Object.keys(CHARACTERS_TO_NORMALIZE).join("");
  4245. normalizationRegex = new RegExp(`[${replace}]`, "g");
  4246. }
  4247. let diffs = null;
  4248. const normalizedText = text.replace(normalizationRegex, function (ch, index) {
  4249. const normalizedCh = CHARACTERS_TO_NORMALIZE[ch],
  4250. diff = normalizedCh.length - ch.length;
  4251. if (diff !== 0) {
  4252. (diffs || (diffs = [])).push([index, diff]);
  4253. }
  4254. return normalizedCh;
  4255. });
  4256. return [normalizedText, diffs];
  4257. }
  4258. function getOriginalIndex(matchIndex, diffs = null) {
  4259. if (!diffs) {
  4260. return matchIndex;
  4261. }
  4262. let totalDiff = 0;
  4263. for (const [index, diff] of diffs) {
  4264. const currentIndex = index + totalDiff;
  4265. if (currentIndex >= matchIndex) {
  4266. break;
  4267. }
  4268. if (currentIndex + diff > matchIndex) {
  4269. totalDiff += matchIndex - currentIndex;
  4270. break;
  4271. }
  4272. totalDiff += diff;
  4273. }
  4274. return matchIndex - totalDiff;
  4275. }
  4276. class PDFFindController {
  4277. constructor({
  4278. linkService,
  4279. eventBus
  4280. }) {
  4281. this._linkService = linkService;
  4282. this._eventBus = eventBus;
  4283. this._reset();
  4284. eventBus._on("findbarclose", this._onFindBarClose.bind(this));
  4285. }
  4286. get highlightMatches() {
  4287. return this._highlightMatches;
  4288. }
  4289. get pageMatches() {
  4290. return this._pageMatches;
  4291. }
  4292. get pageMatchesLength() {
  4293. return this._pageMatchesLength;
  4294. }
  4295. get selected() {
  4296. return this._selected;
  4297. }
  4298. get state() {
  4299. return this._state;
  4300. }
  4301. setDocument(pdfDocument) {
  4302. if (this._pdfDocument) {
  4303. this._reset();
  4304. }
  4305. if (!pdfDocument) {
  4306. return;
  4307. }
  4308. this._pdfDocument = pdfDocument;
  4309. this._firstPageCapability.resolve();
  4310. }
  4311. executeCommand(cmd, state) {
  4312. if (!state) {
  4313. return;
  4314. }
  4315. const pdfDocument = this._pdfDocument;
  4316. if (this._state === null || this._shouldDirtyMatch(cmd, state)) {
  4317. this._dirtyMatch = true;
  4318. }
  4319. this._state = state;
  4320. if (cmd !== "findhighlightallchange") {
  4321. this._updateUIState(FindState.PENDING);
  4322. }
  4323. this._firstPageCapability.promise.then(() => {
  4324. if (!this._pdfDocument || pdfDocument && this._pdfDocument !== pdfDocument) {
  4325. return;
  4326. }
  4327. this._extractText();
  4328. const findbarClosed = !this._highlightMatches;
  4329. const pendingTimeout = !!this._findTimeout;
  4330. if (this._findTimeout) {
  4331. clearTimeout(this._findTimeout);
  4332. this._findTimeout = null;
  4333. }
  4334. if (cmd === "find") {
  4335. this._findTimeout = setTimeout(() => {
  4336. this._nextMatch();
  4337. this._findTimeout = null;
  4338. }, FIND_TIMEOUT);
  4339. } else if (this._dirtyMatch) {
  4340. this._nextMatch();
  4341. } else if (cmd === "findagain") {
  4342. this._nextMatch();
  4343. if (findbarClosed && this._state.highlightAll) {
  4344. this._updateAllPages();
  4345. }
  4346. } else if (cmd === "findhighlightallchange") {
  4347. if (pendingTimeout) {
  4348. this._nextMatch();
  4349. } else {
  4350. this._highlightMatches = true;
  4351. }
  4352. this._updateAllPages();
  4353. } else {
  4354. this._nextMatch();
  4355. }
  4356. });
  4357. }
  4358. scrollMatchIntoView({
  4359. element = null,
  4360. selectedLeft = 0,
  4361. pageIndex = -1,
  4362. matchIndex = -1
  4363. }) {
  4364. if (!this._scrollMatches || !element) {
  4365. return;
  4366. } else if (matchIndex === -1 || matchIndex !== this._selected.matchIdx) {
  4367. return;
  4368. } else if (pageIndex === -1 || pageIndex !== this._selected.pageIdx) {
  4369. return;
  4370. }
  4371. this._scrollMatches = false;
  4372. const spot = {
  4373. top: MATCH_SCROLL_OFFSET_TOP,
  4374. left: selectedLeft + MATCH_SCROLL_OFFSET_LEFT
  4375. };
  4376. (0, _ui_utils.scrollIntoView)(element, spot, true);
  4377. }
  4378. _reset() {
  4379. this._highlightMatches = false;
  4380. this._scrollMatches = false;
  4381. this._pdfDocument = null;
  4382. this._pageMatches = [];
  4383. this._pageMatchesLength = [];
  4384. this._state = null;
  4385. this._selected = {
  4386. pageIdx: -1,
  4387. matchIdx: -1
  4388. };
  4389. this._offset = {
  4390. pageIdx: null,
  4391. matchIdx: null,
  4392. wrapped: false
  4393. };
  4394. this._extractTextPromises = [];
  4395. this._pageContents = [];
  4396. this._pageDiffs = [];
  4397. this._matchesCountTotal = 0;
  4398. this._pagesToSearch = null;
  4399. this._pendingFindMatches = new Set();
  4400. this._resumePageIdx = null;
  4401. this._dirtyMatch = false;
  4402. clearTimeout(this._findTimeout);
  4403. this._findTimeout = null;
  4404. this._firstPageCapability = (0, _pdfjsLib.createPromiseCapability)();
  4405. }
  4406. get _query() {
  4407. if (this._state.query !== this._rawQuery) {
  4408. this._rawQuery = this._state.query;
  4409. [this._normalizedQuery] = normalize(this._state.query);
  4410. }
  4411. return this._normalizedQuery;
  4412. }
  4413. _shouldDirtyMatch(cmd, state) {
  4414. if (state.query !== this._state.query) {
  4415. return true;
  4416. }
  4417. switch (cmd) {
  4418. case "findagain":
  4419. const pageNumber = this._selected.pageIdx + 1;
  4420. const linkService = this._linkService;
  4421. if (pageNumber >= 1 && pageNumber <= linkService.pagesCount && pageNumber !== linkService.page && !linkService.isPageVisible(pageNumber)) {
  4422. return true;
  4423. }
  4424. return false;
  4425. case "findhighlightallchange":
  4426. return false;
  4427. }
  4428. return true;
  4429. }
  4430. _prepareMatches(matchesWithLength, matches, matchesLength) {
  4431. function isSubTerm(currentIndex) {
  4432. const currentElem = matchesWithLength[currentIndex];
  4433. const nextElem = matchesWithLength[currentIndex + 1];
  4434. if (currentIndex < matchesWithLength.length - 1 && currentElem.match === nextElem.match) {
  4435. currentElem.skipped = true;
  4436. return true;
  4437. }
  4438. for (let i = currentIndex - 1; i >= 0; i--) {
  4439. const prevElem = matchesWithLength[i];
  4440. if (prevElem.skipped) {
  4441. continue;
  4442. }
  4443. if (prevElem.match + prevElem.matchLength < currentElem.match) {
  4444. break;
  4445. }
  4446. if (prevElem.match + prevElem.matchLength >= currentElem.match + currentElem.matchLength) {
  4447. currentElem.skipped = true;
  4448. return true;
  4449. }
  4450. }
  4451. return false;
  4452. }
  4453. matchesWithLength.sort(function (a, b) {
  4454. return a.match === b.match ? a.matchLength - b.matchLength : a.match - b.match;
  4455. });
  4456. for (let i = 0, len = matchesWithLength.length; i < len; i++) {
  4457. if (isSubTerm(i)) {
  4458. continue;
  4459. }
  4460. matches.push(matchesWithLength[i].match);
  4461. matchesLength.push(matchesWithLength[i].matchLength);
  4462. }
  4463. }
  4464. _isEntireWord(content, startIdx, length) {
  4465. if (startIdx > 0) {
  4466. const first = content.charCodeAt(startIdx);
  4467. const limit = content.charCodeAt(startIdx - 1);
  4468. if ((0, _pdf_find_utils.getCharacterType)(first) === (0, _pdf_find_utils.getCharacterType)(limit)) {
  4469. return false;
  4470. }
  4471. }
  4472. const endIdx = startIdx + length - 1;
  4473. if (endIdx < content.length - 1) {
  4474. const last = content.charCodeAt(endIdx);
  4475. const limit = content.charCodeAt(endIdx + 1);
  4476. if ((0, _pdf_find_utils.getCharacterType)(last) === (0, _pdf_find_utils.getCharacterType)(limit)) {
  4477. return false;
  4478. }
  4479. }
  4480. return true;
  4481. }
  4482. _calculatePhraseMatch(query, pageIndex, pageContent, pageDiffs, entireWord) {
  4483. const matches = [],
  4484. matchesLength = [];
  4485. const queryLen = query.length;
  4486. let matchIdx = -queryLen;
  4487. while (true) {
  4488. matchIdx = pageContent.indexOf(query, matchIdx + queryLen);
  4489. if (matchIdx === -1) {
  4490. break;
  4491. }
  4492. if (entireWord && !this._isEntireWord(pageContent, matchIdx, queryLen)) {
  4493. continue;
  4494. }
  4495. const originalMatchIdx = getOriginalIndex(matchIdx, pageDiffs),
  4496. matchEnd = matchIdx + queryLen - 1,
  4497. originalQueryLen = getOriginalIndex(matchEnd, pageDiffs) - originalMatchIdx + 1;
  4498. matches.push(originalMatchIdx);
  4499. matchesLength.push(originalQueryLen);
  4500. }
  4501. this._pageMatches[pageIndex] = matches;
  4502. this._pageMatchesLength[pageIndex] = matchesLength;
  4503. }
  4504. _calculateWordMatch(query, pageIndex, pageContent, pageDiffs, entireWord) {
  4505. const matchesWithLength = [];
  4506. const queryArray = query.match(/\S+/g);
  4507. for (let i = 0, len = queryArray.length; i < len; i++) {
  4508. const subquery = queryArray[i];
  4509. const subqueryLen = subquery.length;
  4510. let matchIdx = -subqueryLen;
  4511. while (true) {
  4512. matchIdx = pageContent.indexOf(subquery, matchIdx + subqueryLen);
  4513. if (matchIdx === -1) {
  4514. break;
  4515. }
  4516. if (entireWord && !this._isEntireWord(pageContent, matchIdx, subqueryLen)) {
  4517. continue;
  4518. }
  4519. const originalMatchIdx = getOriginalIndex(matchIdx, pageDiffs),
  4520. matchEnd = matchIdx + subqueryLen - 1,
  4521. originalQueryLen = getOriginalIndex(matchEnd, pageDiffs) - originalMatchIdx + 1;
  4522. matchesWithLength.push({
  4523. match: originalMatchIdx,
  4524. matchLength: originalQueryLen,
  4525. skipped: false
  4526. });
  4527. }
  4528. }
  4529. this._pageMatchesLength[pageIndex] = [];
  4530. this._pageMatches[pageIndex] = [];
  4531. this._prepareMatches(matchesWithLength, this._pageMatches[pageIndex], this._pageMatchesLength[pageIndex]);
  4532. }
  4533. _calculateMatch(pageIndex) {
  4534. let pageContent = this._pageContents[pageIndex];
  4535. const pageDiffs = this._pageDiffs[pageIndex];
  4536. let query = this._query;
  4537. const {
  4538. caseSensitive,
  4539. entireWord,
  4540. phraseSearch
  4541. } = this._state;
  4542. if (query.length === 0) {
  4543. return;
  4544. }
  4545. if (!caseSensitive) {
  4546. pageContent = pageContent.toLowerCase();
  4547. query = query.toLowerCase();
  4548. }
  4549. if (phraseSearch) {
  4550. this._calculatePhraseMatch(query, pageIndex, pageContent, pageDiffs, entireWord);
  4551. } else {
  4552. this._calculateWordMatch(query, pageIndex, pageContent, pageDiffs, entireWord);
  4553. }
  4554. if (this._state.highlightAll) {
  4555. this._updatePage(pageIndex);
  4556. }
  4557. if (this._resumePageIdx === pageIndex) {
  4558. this._resumePageIdx = null;
  4559. this._nextPageMatch();
  4560. }
  4561. const pageMatchesCount = this._pageMatches[pageIndex].length;
  4562. if (pageMatchesCount > 0) {
  4563. this._matchesCountTotal += pageMatchesCount;
  4564. this._updateUIResultsCount();
  4565. }
  4566. }
  4567. _extractText() {
  4568. if (this._extractTextPromises.length > 0) {
  4569. return;
  4570. }
  4571. let promise = Promise.resolve();
  4572. for (let i = 0, ii = this._linkService.pagesCount; i < ii; i++) {
  4573. const extractTextCapability = (0, _pdfjsLib.createPromiseCapability)();
  4574. this._extractTextPromises[i] = extractTextCapability.promise;
  4575. promise = promise.then(() => {
  4576. return this._pdfDocument.getPage(i + 1).then(pdfPage => {
  4577. return pdfPage.getTextContent({
  4578. normalizeWhitespace: true
  4579. });
  4580. }).then(textContent => {
  4581. const textItems = textContent.items;
  4582. const strBuf = [];
  4583. for (let j = 0, jj = textItems.length; j < jj; j++) {
  4584. strBuf.push(textItems[j].str);
  4585. }
  4586. [this._pageContents[i], this._pageDiffs[i]] = normalize(strBuf.join(""));
  4587. extractTextCapability.resolve(i);
  4588. }, reason => {
  4589. console.error(`Unable to get text content for page ${i + 1}`, reason);
  4590. this._pageContents[i] = "";
  4591. this._pageDiffs[i] = null;
  4592. extractTextCapability.resolve(i);
  4593. });
  4594. });
  4595. }
  4596. }
  4597. _updatePage(index) {
  4598. if (this._scrollMatches && this._selected.pageIdx === index) {
  4599. this._linkService.page = index + 1;
  4600. }
  4601. this._eventBus.dispatch("updatetextlayermatches", {
  4602. source: this,
  4603. pageIndex: index
  4604. });
  4605. }
  4606. _updateAllPages() {
  4607. this._eventBus.dispatch("updatetextlayermatches", {
  4608. source: this,
  4609. pageIndex: -1
  4610. });
  4611. }
  4612. _nextMatch() {
  4613. const previous = this._state.findPrevious;
  4614. const currentPageIndex = this._linkService.page - 1;
  4615. const numPages = this._linkService.pagesCount;
  4616. this._highlightMatches = true;
  4617. if (this._dirtyMatch) {
  4618. this._dirtyMatch = false;
  4619. this._selected.pageIdx = this._selected.matchIdx = -1;
  4620. this._offset.pageIdx = currentPageIndex;
  4621. this._offset.matchIdx = null;
  4622. this._offset.wrapped = false;
  4623. this._resumePageIdx = null;
  4624. this._pageMatches.length = 0;
  4625. this._pageMatchesLength.length = 0;
  4626. this._matchesCountTotal = 0;
  4627. this._updateAllPages();
  4628. for (let i = 0; i < numPages; i++) {
  4629. if (this._pendingFindMatches.has(i)) {
  4630. continue;
  4631. }
  4632. this._pendingFindMatches.add(i);
  4633. this._extractTextPromises[i].then(pageIdx => {
  4634. this._pendingFindMatches.delete(pageIdx);
  4635. this._calculateMatch(pageIdx);
  4636. });
  4637. }
  4638. }
  4639. if (this._query === "") {
  4640. this._updateUIState(FindState.FOUND);
  4641. return;
  4642. }
  4643. if (this._resumePageIdx) {
  4644. return;
  4645. }
  4646. const offset = this._offset;
  4647. this._pagesToSearch = numPages;
  4648. if (offset.matchIdx !== null) {
  4649. const numPageMatches = this._pageMatches[offset.pageIdx].length;
  4650. if (!previous && offset.matchIdx + 1 < numPageMatches || previous && offset.matchIdx > 0) {
  4651. offset.matchIdx = previous ? offset.matchIdx - 1 : offset.matchIdx + 1;
  4652. this._updateMatch(true);
  4653. return;
  4654. }
  4655. this._advanceOffsetPage(previous);
  4656. }
  4657. this._nextPageMatch();
  4658. }
  4659. _matchesReady(matches) {
  4660. const offset = this._offset;
  4661. const numMatches = matches.length;
  4662. const previous = this._state.findPrevious;
  4663. if (numMatches) {
  4664. offset.matchIdx = previous ? numMatches - 1 : 0;
  4665. this._updateMatch(true);
  4666. return true;
  4667. }
  4668. this._advanceOffsetPage(previous);
  4669. if (offset.wrapped) {
  4670. offset.matchIdx = null;
  4671. if (this._pagesToSearch < 0) {
  4672. this._updateMatch(false);
  4673. return true;
  4674. }
  4675. }
  4676. return false;
  4677. }
  4678. _nextPageMatch() {
  4679. if (this._resumePageIdx !== null) {
  4680. console.error("There can only be one pending page.");
  4681. }
  4682. let matches = null;
  4683. do {
  4684. const pageIdx = this._offset.pageIdx;
  4685. matches = this._pageMatches[pageIdx];
  4686. if (!matches) {
  4687. this._resumePageIdx = pageIdx;
  4688. break;
  4689. }
  4690. } while (!this._matchesReady(matches));
  4691. }
  4692. _advanceOffsetPage(previous) {
  4693. const offset = this._offset;
  4694. const numPages = this._linkService.pagesCount;
  4695. offset.pageIdx = previous ? offset.pageIdx - 1 : offset.pageIdx + 1;
  4696. offset.matchIdx = null;
  4697. this._pagesToSearch--;
  4698. if (offset.pageIdx >= numPages || offset.pageIdx < 0) {
  4699. offset.pageIdx = previous ? numPages - 1 : 0;
  4700. offset.wrapped = true;
  4701. }
  4702. }
  4703. _updateMatch(found = false) {
  4704. let state = FindState.NOT_FOUND;
  4705. const wrapped = this._offset.wrapped;
  4706. this._offset.wrapped = false;
  4707. if (found) {
  4708. const previousPage = this._selected.pageIdx;
  4709. this._selected.pageIdx = this._offset.pageIdx;
  4710. this._selected.matchIdx = this._offset.matchIdx;
  4711. state = wrapped ? FindState.WRAPPED : FindState.FOUND;
  4712. if (previousPage !== -1 && previousPage !== this._selected.pageIdx) {
  4713. this._updatePage(previousPage);
  4714. }
  4715. }
  4716. this._updateUIState(state, this._state.findPrevious);
  4717. if (this._selected.pageIdx !== -1) {
  4718. this._scrollMatches = true;
  4719. this._updatePage(this._selected.pageIdx);
  4720. }
  4721. }
  4722. _onFindBarClose(evt) {
  4723. const pdfDocument = this._pdfDocument;
  4724. this._firstPageCapability.promise.then(() => {
  4725. if (!this._pdfDocument || pdfDocument && this._pdfDocument !== pdfDocument) {
  4726. return;
  4727. }
  4728. if (this._findTimeout) {
  4729. clearTimeout(this._findTimeout);
  4730. this._findTimeout = null;
  4731. }
  4732. if (this._resumePageIdx) {
  4733. this._resumePageIdx = null;
  4734. this._dirtyMatch = true;
  4735. }
  4736. this._updateUIState(FindState.FOUND);
  4737. this._highlightMatches = false;
  4738. this._updateAllPages();
  4739. });
  4740. }
  4741. _requestMatchesCount() {
  4742. const {
  4743. pageIdx,
  4744. matchIdx
  4745. } = this._selected;
  4746. let current = 0,
  4747. total = this._matchesCountTotal;
  4748. if (matchIdx !== -1) {
  4749. for (let i = 0; i < pageIdx; i++) {
  4750. current += this._pageMatches[i]?.length || 0;
  4751. }
  4752. current += matchIdx + 1;
  4753. }
  4754. if (current < 1 || current > total) {
  4755. current = total = 0;
  4756. }
  4757. return {
  4758. current,
  4759. total
  4760. };
  4761. }
  4762. _updateUIResultsCount() {
  4763. this._eventBus.dispatch("updatefindmatchescount", {
  4764. source: this,
  4765. matchesCount: this._requestMatchesCount()
  4766. });
  4767. }
  4768. _updateUIState(state, previous) {
  4769. this._eventBus.dispatch("updatefindcontrolstate", {
  4770. source: this,
  4771. state,
  4772. previous,
  4773. matchesCount: this._requestMatchesCount(),
  4774. rawQuery: this._state?.query ?? null
  4775. });
  4776. }
  4777. }
  4778. exports.PDFFindController = PDFFindController;
  4779. /***/ }),
  4780. /* 16 */
  4781. /***/ ((__unused_webpack_module, exports) => {
  4782. Object.defineProperty(exports, "__esModule", ({
  4783. value: true
  4784. }));
  4785. exports.getCharacterType = getCharacterType;
  4786. exports.CharacterType = void 0;
  4787. const CharacterType = {
  4788. SPACE: 0,
  4789. ALPHA_LETTER: 1,
  4790. PUNCT: 2,
  4791. HAN_LETTER: 3,
  4792. KATAKANA_LETTER: 4,
  4793. HIRAGANA_LETTER: 5,
  4794. HALFWIDTH_KATAKANA_LETTER: 6,
  4795. THAI_LETTER: 7
  4796. };
  4797. exports.CharacterType = CharacterType;
  4798. function isAlphabeticalScript(charCode) {
  4799. return charCode < 0x2e80;
  4800. }
  4801. function isAscii(charCode) {
  4802. return (charCode & 0xff80) === 0;
  4803. }
  4804. function isAsciiAlpha(charCode) {
  4805. return charCode >= 0x61 && charCode <= 0x7a || charCode >= 0x41 && charCode <= 0x5a;
  4806. }
  4807. function isAsciiDigit(charCode) {
  4808. return charCode >= 0x30 && charCode <= 0x39;
  4809. }
  4810. function isAsciiSpace(charCode) {
  4811. return charCode === 0x20 || charCode === 0x09 || charCode === 0x0d || charCode === 0x0a;
  4812. }
  4813. function isHan(charCode) {
  4814. return charCode >= 0x3400 && charCode <= 0x9fff || charCode >= 0xf900 && charCode <= 0xfaff;
  4815. }
  4816. function isKatakana(charCode) {
  4817. return charCode >= 0x30a0 && charCode <= 0x30ff;
  4818. }
  4819. function isHiragana(charCode) {
  4820. return charCode >= 0x3040 && charCode <= 0x309f;
  4821. }
  4822. function isHalfwidthKatakana(charCode) {
  4823. return charCode >= 0xff60 && charCode <= 0xff9f;
  4824. }
  4825. function isThai(charCode) {
  4826. return (charCode & 0xff80) === 0x0e00;
  4827. }
  4828. function getCharacterType(charCode) {
  4829. if (isAlphabeticalScript(charCode)) {
  4830. if (isAscii(charCode)) {
  4831. if (isAsciiSpace(charCode)) {
  4832. return CharacterType.SPACE;
  4833. } else if (isAsciiAlpha(charCode) || isAsciiDigit(charCode) || charCode === 0x5f) {
  4834. return CharacterType.ALPHA_LETTER;
  4835. }
  4836. return CharacterType.PUNCT;
  4837. } else if (isThai(charCode)) {
  4838. return CharacterType.THAI_LETTER;
  4839. } else if (charCode === 0xa0) {
  4840. return CharacterType.SPACE;
  4841. }
  4842. return CharacterType.ALPHA_LETTER;
  4843. }
  4844. if (isHan(charCode)) {
  4845. return CharacterType.HAN_LETTER;
  4846. } else if (isKatakana(charCode)) {
  4847. return CharacterType.KATAKANA_LETTER;
  4848. } else if (isHiragana(charCode)) {
  4849. return CharacterType.HIRAGANA_LETTER;
  4850. } else if (isHalfwidthKatakana(charCode)) {
  4851. return CharacterType.HALFWIDTH_KATAKANA_LETTER;
  4852. }
  4853. return CharacterType.ALPHA_LETTER;
  4854. }
  4855. /***/ }),
  4856. /* 17 */
  4857. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4858. Object.defineProperty(exports, "__esModule", ({
  4859. value: true
  4860. }));
  4861. exports.isDestArraysEqual = isDestArraysEqual;
  4862. exports.isDestHashesEqual = isDestHashesEqual;
  4863. exports.PDFHistory = void 0;
  4864. var _ui_utils = __webpack_require__(4);
  4865. const HASH_CHANGE_TIMEOUT = 1000;
  4866. const POSITION_UPDATED_THRESHOLD = 50;
  4867. const UPDATE_VIEWAREA_TIMEOUT = 1000;
  4868. function getCurrentHash() {
  4869. return document.location.hash;
  4870. }
  4871. class PDFHistory {
  4872. constructor({
  4873. linkService,
  4874. eventBus
  4875. }) {
  4876. this.linkService = linkService;
  4877. this.eventBus = eventBus;
  4878. this._initialized = false;
  4879. this._fingerprint = "";
  4880. this.reset();
  4881. this._boundEvents = null;
  4882. this._isViewerInPresentationMode = false;
  4883. this.eventBus._on("presentationmodechanged", evt => {
  4884. this._isViewerInPresentationMode = evt.state !== _ui_utils.PresentationModeState.NORMAL;
  4885. });
  4886. this.eventBus._on("pagesinit", () => {
  4887. this._isPagesLoaded = false;
  4888. this.eventBus._on("pagesloaded", evt => {
  4889. this._isPagesLoaded = !!evt.pagesCount;
  4890. }, {
  4891. once: true
  4892. });
  4893. });
  4894. }
  4895. initialize({
  4896. fingerprint,
  4897. resetHistory = false,
  4898. updateUrl = false
  4899. }) {
  4900. if (!fingerprint || typeof fingerprint !== "string") {
  4901. console.error('PDFHistory.initialize: The "fingerprint" must be a non-empty string.');
  4902. return;
  4903. }
  4904. if (this._initialized) {
  4905. this.reset();
  4906. }
  4907. const reInitialized = this._fingerprint !== "" && this._fingerprint !== fingerprint;
  4908. this._fingerprint = fingerprint;
  4909. this._updateUrl = updateUrl === true;
  4910. this._initialized = true;
  4911. this._bindEvents();
  4912. const state = window.history.state;
  4913. this._popStateInProgress = false;
  4914. this._blockHashChange = 0;
  4915. this._currentHash = getCurrentHash();
  4916. this._numPositionUpdates = 0;
  4917. this._uid = this._maxUid = 0;
  4918. this._destination = null;
  4919. this._position = null;
  4920. if (!this._isValidState(state, true) || resetHistory) {
  4921. const {
  4922. hash,
  4923. page,
  4924. rotation
  4925. } = this._parseCurrentHash(true);
  4926. if (!hash || reInitialized || resetHistory) {
  4927. this._pushOrReplaceState(null, true);
  4928. return;
  4929. }
  4930. this._pushOrReplaceState({
  4931. hash,
  4932. page,
  4933. rotation
  4934. }, true);
  4935. return;
  4936. }
  4937. const destination = state.destination;
  4938. this._updateInternalState(destination, state.uid, true);
  4939. if (destination.rotation !== undefined) {
  4940. this._initialRotation = destination.rotation;
  4941. }
  4942. if (destination.dest) {
  4943. this._initialBookmark = JSON.stringify(destination.dest);
  4944. this._destination.page = null;
  4945. } else if (destination.hash) {
  4946. this._initialBookmark = destination.hash;
  4947. } else if (destination.page) {
  4948. this._initialBookmark = `page=${destination.page}`;
  4949. }
  4950. }
  4951. reset() {
  4952. if (this._initialized) {
  4953. this._pageHide();
  4954. this._initialized = false;
  4955. this._unbindEvents();
  4956. }
  4957. if (this._updateViewareaTimeout) {
  4958. clearTimeout(this._updateViewareaTimeout);
  4959. this._updateViewareaTimeout = null;
  4960. }
  4961. this._initialBookmark = null;
  4962. this._initialRotation = null;
  4963. }
  4964. push({
  4965. namedDest = null,
  4966. explicitDest,
  4967. pageNumber
  4968. }) {
  4969. if (!this._initialized) {
  4970. return;
  4971. }
  4972. if (namedDest && typeof namedDest !== "string") {
  4973. console.error("PDFHistory.push: " + `"${namedDest}" is not a valid namedDest parameter.`);
  4974. return;
  4975. } else if (!Array.isArray(explicitDest)) {
  4976. console.error("PDFHistory.push: " + `"${explicitDest}" is not a valid explicitDest parameter.`);
  4977. return;
  4978. } else if (!this._isValidPage(pageNumber)) {
  4979. if (pageNumber !== null || this._destination) {
  4980. console.error("PDFHistory.push: " + `"${pageNumber}" is not a valid pageNumber parameter.`);
  4981. return;
  4982. }
  4983. }
  4984. const hash = namedDest || JSON.stringify(explicitDest);
  4985. if (!hash) {
  4986. return;
  4987. }
  4988. let forceReplace = false;
  4989. if (this._destination && (isDestHashesEqual(this._destination.hash, hash) || isDestArraysEqual(this._destination.dest, explicitDest))) {
  4990. if (this._destination.page) {
  4991. return;
  4992. }
  4993. forceReplace = true;
  4994. }
  4995. if (this._popStateInProgress && !forceReplace) {
  4996. return;
  4997. }
  4998. this._pushOrReplaceState({
  4999. dest: explicitDest,
  5000. hash,
  5001. page: pageNumber,
  5002. rotation: this.linkService.rotation
  5003. }, forceReplace);
  5004. if (!this._popStateInProgress) {
  5005. this._popStateInProgress = true;
  5006. Promise.resolve().then(() => {
  5007. this._popStateInProgress = false;
  5008. });
  5009. }
  5010. }
  5011. pushPage(pageNumber) {
  5012. if (!this._initialized) {
  5013. return;
  5014. }
  5015. if (!this._isValidPage(pageNumber)) {
  5016. console.error(`PDFHistory.pushPage: "${pageNumber}" is not a valid page number.`);
  5017. return;
  5018. }
  5019. if (this._destination?.page === pageNumber) {
  5020. return;
  5021. }
  5022. if (this._popStateInProgress) {
  5023. return;
  5024. }
  5025. this._pushOrReplaceState({
  5026. dest: null,
  5027. hash: `page=${pageNumber}`,
  5028. page: pageNumber,
  5029. rotation: this.linkService.rotation
  5030. });
  5031. if (!this._popStateInProgress) {
  5032. this._popStateInProgress = true;
  5033. Promise.resolve().then(() => {
  5034. this._popStateInProgress = false;
  5035. });
  5036. }
  5037. }
  5038. pushCurrentPosition() {
  5039. if (!this._initialized || this._popStateInProgress) {
  5040. return;
  5041. }
  5042. this._tryPushCurrentPosition();
  5043. }
  5044. back() {
  5045. if (!this._initialized || this._popStateInProgress) {
  5046. return;
  5047. }
  5048. const state = window.history.state;
  5049. if (this._isValidState(state) && state.uid > 0) {
  5050. window.history.back();
  5051. }
  5052. }
  5053. forward() {
  5054. if (!this._initialized || this._popStateInProgress) {
  5055. return;
  5056. }
  5057. const state = window.history.state;
  5058. if (this._isValidState(state) && state.uid < this._maxUid) {
  5059. window.history.forward();
  5060. }
  5061. }
  5062. get popStateInProgress() {
  5063. return this._initialized && (this._popStateInProgress || this._blockHashChange > 0);
  5064. }
  5065. get initialBookmark() {
  5066. return this._initialized ? this._initialBookmark : null;
  5067. }
  5068. get initialRotation() {
  5069. return this._initialized ? this._initialRotation : null;
  5070. }
  5071. _pushOrReplaceState(destination, forceReplace = false) {
  5072. const shouldReplace = forceReplace || !this._destination;
  5073. const newState = {
  5074. fingerprint: this._fingerprint,
  5075. uid: shouldReplace ? this._uid : this._uid + 1,
  5076. destination
  5077. };
  5078. this._updateInternalState(destination, newState.uid);
  5079. let newUrl;
  5080. if (this._updateUrl && destination?.hash) {
  5081. const baseUrl = document.location.href.split("#")[0];
  5082. if (!baseUrl.startsWith("file://")) {
  5083. newUrl = `${baseUrl}#${destination.hash}`;
  5084. }
  5085. }
  5086. if (shouldReplace) {
  5087. window.history.replaceState(newState, "", newUrl);
  5088. } else {
  5089. window.history.pushState(newState, "", newUrl);
  5090. }
  5091. }
  5092. _tryPushCurrentPosition(temporary = false) {
  5093. if (!this._position) {
  5094. return;
  5095. }
  5096. let position = this._position;
  5097. if (temporary) {
  5098. position = Object.assign(Object.create(null), this._position);
  5099. position.temporary = true;
  5100. }
  5101. if (!this._destination) {
  5102. this._pushOrReplaceState(position);
  5103. return;
  5104. }
  5105. if (this._destination.temporary) {
  5106. this._pushOrReplaceState(position, true);
  5107. return;
  5108. }
  5109. if (this._destination.hash === position.hash) {
  5110. return;
  5111. }
  5112. if (!this._destination.page && (POSITION_UPDATED_THRESHOLD <= 0 || this._numPositionUpdates <= POSITION_UPDATED_THRESHOLD)) {
  5113. return;
  5114. }
  5115. let forceReplace = false;
  5116. if (this._destination.page >= position.first && this._destination.page <= position.page) {
  5117. if (this._destination.dest !== undefined || !this._destination.first) {
  5118. return;
  5119. }
  5120. forceReplace = true;
  5121. }
  5122. this._pushOrReplaceState(position, forceReplace);
  5123. }
  5124. _isValidPage(val) {
  5125. return Number.isInteger(val) && val > 0 && val <= this.linkService.pagesCount;
  5126. }
  5127. _isValidState(state, checkReload = false) {
  5128. if (!state) {
  5129. return false;
  5130. }
  5131. if (state.fingerprint !== this._fingerprint) {
  5132. if (checkReload) {
  5133. if (typeof state.fingerprint !== "string" || state.fingerprint.length !== this._fingerprint.length) {
  5134. return false;
  5135. }
  5136. const [perfEntry] = performance.getEntriesByType("navigation");
  5137. if (perfEntry?.type !== "reload") {
  5138. return false;
  5139. }
  5140. } else {
  5141. return false;
  5142. }
  5143. }
  5144. if (!Number.isInteger(state.uid) || state.uid < 0) {
  5145. return false;
  5146. }
  5147. if (state.destination === null || typeof state.destination !== "object") {
  5148. return false;
  5149. }
  5150. return true;
  5151. }
  5152. _updateInternalState(destination, uid, removeTemporary = false) {
  5153. if (this._updateViewareaTimeout) {
  5154. clearTimeout(this._updateViewareaTimeout);
  5155. this._updateViewareaTimeout = null;
  5156. }
  5157. if (removeTemporary && destination?.temporary) {
  5158. delete destination.temporary;
  5159. }
  5160. this._destination = destination;
  5161. this._uid = uid;
  5162. this._maxUid = Math.max(this._maxUid, uid);
  5163. this._numPositionUpdates = 0;
  5164. }
  5165. _parseCurrentHash(checkNameddest = false) {
  5166. const hash = unescape(getCurrentHash()).substring(1);
  5167. const params = (0, _ui_utils.parseQueryString)(hash);
  5168. const nameddest = params.nameddest || "";
  5169. let page = params.page | 0;
  5170. if (!this._isValidPage(page) || checkNameddest && nameddest.length > 0) {
  5171. page = null;
  5172. }
  5173. return {
  5174. hash,
  5175. page,
  5176. rotation: this.linkService.rotation
  5177. };
  5178. }
  5179. _updateViewarea({
  5180. location
  5181. }) {
  5182. if (this._updateViewareaTimeout) {
  5183. clearTimeout(this._updateViewareaTimeout);
  5184. this._updateViewareaTimeout = null;
  5185. }
  5186. this._position = {
  5187. hash: this._isViewerInPresentationMode ? `page=${location.pageNumber}` : location.pdfOpenParams.substring(1),
  5188. page: this.linkService.page,
  5189. first: location.pageNumber,
  5190. rotation: location.rotation
  5191. };
  5192. if (this._popStateInProgress) {
  5193. return;
  5194. }
  5195. if (POSITION_UPDATED_THRESHOLD > 0 && this._isPagesLoaded && this._destination && !this._destination.page) {
  5196. this._numPositionUpdates++;
  5197. }
  5198. if (UPDATE_VIEWAREA_TIMEOUT > 0) {
  5199. this._updateViewareaTimeout = setTimeout(() => {
  5200. if (!this._popStateInProgress) {
  5201. this._tryPushCurrentPosition(true);
  5202. }
  5203. this._updateViewareaTimeout = null;
  5204. }, UPDATE_VIEWAREA_TIMEOUT);
  5205. }
  5206. }
  5207. _popState({
  5208. state
  5209. }) {
  5210. const newHash = getCurrentHash(),
  5211. hashChanged = this._currentHash !== newHash;
  5212. this._currentHash = newHash;
  5213. if (!state) {
  5214. this._uid++;
  5215. const {
  5216. hash,
  5217. page,
  5218. rotation
  5219. } = this._parseCurrentHash();
  5220. this._pushOrReplaceState({
  5221. hash,
  5222. page,
  5223. rotation
  5224. }, true);
  5225. return;
  5226. }
  5227. if (!this._isValidState(state)) {
  5228. return;
  5229. }
  5230. this._popStateInProgress = true;
  5231. if (hashChanged) {
  5232. this._blockHashChange++;
  5233. (0, _ui_utils.waitOnEventOrTimeout)({
  5234. target: window,
  5235. name: "hashchange",
  5236. delay: HASH_CHANGE_TIMEOUT
  5237. }).then(() => {
  5238. this._blockHashChange--;
  5239. });
  5240. }
  5241. const destination = state.destination;
  5242. this._updateInternalState(destination, state.uid, true);
  5243. if ((0, _ui_utils.isValidRotation)(destination.rotation)) {
  5244. this.linkService.rotation = destination.rotation;
  5245. }
  5246. if (destination.dest) {
  5247. this.linkService.goToDestination(destination.dest);
  5248. } else if (destination.hash) {
  5249. this.linkService.setHash(destination.hash);
  5250. } else if (destination.page) {
  5251. this.linkService.page = destination.page;
  5252. }
  5253. Promise.resolve().then(() => {
  5254. this._popStateInProgress = false;
  5255. });
  5256. }
  5257. _pageHide() {
  5258. if (!this._destination || this._destination.temporary) {
  5259. this._tryPushCurrentPosition();
  5260. }
  5261. }
  5262. _bindEvents() {
  5263. if (this._boundEvents) {
  5264. return;
  5265. }
  5266. this._boundEvents = {
  5267. updateViewarea: this._updateViewarea.bind(this),
  5268. popState: this._popState.bind(this),
  5269. pageHide: this._pageHide.bind(this)
  5270. };
  5271. this.eventBus._on("updateviewarea", this._boundEvents.updateViewarea);
  5272. window.addEventListener("popstate", this._boundEvents.popState);
  5273. window.addEventListener("pagehide", this._boundEvents.pageHide);
  5274. }
  5275. _unbindEvents() {
  5276. if (!this._boundEvents) {
  5277. return;
  5278. }
  5279. this.eventBus._off("updateviewarea", this._boundEvents.updateViewarea);
  5280. window.removeEventListener("popstate", this._boundEvents.popState);
  5281. window.removeEventListener("pagehide", this._boundEvents.pageHide);
  5282. this._boundEvents = null;
  5283. }
  5284. }
  5285. exports.PDFHistory = PDFHistory;
  5286. function isDestHashesEqual(destHash, pushHash) {
  5287. if (typeof destHash !== "string" || typeof pushHash !== "string") {
  5288. return false;
  5289. }
  5290. if (destHash === pushHash) {
  5291. return true;
  5292. }
  5293. const {
  5294. nameddest
  5295. } = (0, _ui_utils.parseQueryString)(destHash);
  5296. if (nameddest === pushHash) {
  5297. return true;
  5298. }
  5299. return false;
  5300. }
  5301. function isDestArraysEqual(firstDest, secondDest) {
  5302. function isEntryEqual(first, second) {
  5303. if (typeof first !== typeof second) {
  5304. return false;
  5305. }
  5306. if (Array.isArray(first) || Array.isArray(second)) {
  5307. return false;
  5308. }
  5309. if (first !== null && typeof first === "object" && second !== null) {
  5310. if (Object.keys(first).length !== Object.keys(second).length) {
  5311. return false;
  5312. }
  5313. for (const key in first) {
  5314. if (!isEntryEqual(first[key], second[key])) {
  5315. return false;
  5316. }
  5317. }
  5318. return true;
  5319. }
  5320. return first === second || Number.isNaN(first) && Number.isNaN(second);
  5321. }
  5322. if (!(Array.isArray(firstDest) && Array.isArray(secondDest))) {
  5323. return false;
  5324. }
  5325. if (firstDest.length !== secondDest.length) {
  5326. return false;
  5327. }
  5328. for (let i = 0, ii = firstDest.length; i < ii; i++) {
  5329. if (!isEntryEqual(firstDest[i], secondDest[i])) {
  5330. return false;
  5331. }
  5332. }
  5333. return true;
  5334. }
  5335. /***/ }),
  5336. /* 18 */
  5337. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  5338. Object.defineProperty(exports, "__esModule", ({
  5339. value: true
  5340. }));
  5341. exports.PDFLayerViewer = void 0;
  5342. var _base_tree_viewer = __webpack_require__(12);
  5343. class PDFLayerViewer extends _base_tree_viewer.BaseTreeViewer {
  5344. constructor(options) {
  5345. super(options);
  5346. this.l10n = options.l10n;
  5347. this.eventBus._on("resetlayers", this._resetLayers.bind(this));
  5348. this.eventBus._on("togglelayerstree", this._toggleAllTreeItems.bind(this));
  5349. }
  5350. reset() {
  5351. super.reset();
  5352. this._optionalContentConfig = null;
  5353. }
  5354. _dispatchEvent(layersCount) {
  5355. this.eventBus.dispatch("layersloaded", {
  5356. source: this,
  5357. layersCount
  5358. });
  5359. }
  5360. _bindLink(element, {
  5361. groupId,
  5362. input
  5363. }) {
  5364. const setVisibility = () => {
  5365. this._optionalContentConfig.setVisibility(groupId, input.checked);
  5366. this.eventBus.dispatch("optionalcontentconfig", {
  5367. source: this,
  5368. promise: Promise.resolve(this._optionalContentConfig)
  5369. });
  5370. };
  5371. element.onclick = evt => {
  5372. if (evt.target === input) {
  5373. setVisibility();
  5374. return true;
  5375. } else if (evt.target !== element) {
  5376. return true;
  5377. }
  5378. input.checked = !input.checked;
  5379. setVisibility();
  5380. return false;
  5381. };
  5382. }
  5383. async _setNestedName(element, {
  5384. name = null
  5385. }) {
  5386. if (typeof name === "string") {
  5387. element.textContent = this._normalizeTextContent(name);
  5388. return;
  5389. }
  5390. element.textContent = await this.l10n.get("additional_layers");
  5391. element.style.fontStyle = "italic";
  5392. }
  5393. _addToggleButton(div, {
  5394. name = null
  5395. }) {
  5396. super._addToggleButton(div, name === null);
  5397. }
  5398. _toggleAllTreeItems() {
  5399. if (!this._optionalContentConfig) {
  5400. return;
  5401. }
  5402. super._toggleAllTreeItems();
  5403. }
  5404. render({
  5405. optionalContentConfig,
  5406. pdfDocument
  5407. }) {
  5408. if (this._optionalContentConfig) {
  5409. this.reset();
  5410. }
  5411. this._optionalContentConfig = optionalContentConfig || null;
  5412. this._pdfDocument = pdfDocument || null;
  5413. const groups = optionalContentConfig?.getOrder();
  5414. if (!groups) {
  5415. this._dispatchEvent(0);
  5416. return;
  5417. }
  5418. const fragment = document.createDocumentFragment(),
  5419. queue = [{
  5420. parent: fragment,
  5421. groups
  5422. }];
  5423. let layersCount = 0,
  5424. hasAnyNesting = false;
  5425. while (queue.length > 0) {
  5426. const levelData = queue.shift();
  5427. for (const groupId of levelData.groups) {
  5428. const div = document.createElement("div");
  5429. div.className = "treeItem";
  5430. const element = document.createElement("a");
  5431. div.appendChild(element);
  5432. if (typeof groupId === "object") {
  5433. hasAnyNesting = true;
  5434. this._addToggleButton(div, groupId);
  5435. this._setNestedName(element, groupId);
  5436. const itemsDiv = document.createElement("div");
  5437. itemsDiv.className = "treeItems";
  5438. div.appendChild(itemsDiv);
  5439. queue.push({
  5440. parent: itemsDiv,
  5441. groups: groupId.order
  5442. });
  5443. } else {
  5444. const group = optionalContentConfig.getGroup(groupId);
  5445. const input = document.createElement("input");
  5446. this._bindLink(element, {
  5447. groupId,
  5448. input
  5449. });
  5450. input.type = "checkbox";
  5451. input.id = groupId;
  5452. input.checked = group.visible;
  5453. const label = document.createElement("label");
  5454. label.setAttribute("for", groupId);
  5455. label.textContent = this._normalizeTextContent(group.name);
  5456. element.appendChild(input);
  5457. element.appendChild(label);
  5458. layersCount++;
  5459. }
  5460. levelData.parent.appendChild(div);
  5461. }
  5462. }
  5463. this._finishRendering(fragment, layersCount, hasAnyNesting);
  5464. }
  5465. async _resetLayers() {
  5466. if (!this._optionalContentConfig) {
  5467. return;
  5468. }
  5469. const optionalContentConfig = await this._pdfDocument.getOptionalContentConfig();
  5470. this.eventBus.dispatch("optionalcontentconfig", {
  5471. source: this,
  5472. promise: Promise.resolve(optionalContentConfig)
  5473. });
  5474. this.render({
  5475. optionalContentConfig,
  5476. pdfDocument: this._pdfDocument
  5477. });
  5478. }
  5479. }
  5480. exports.PDFLayerViewer = PDFLayerViewer;
  5481. /***/ }),
  5482. /* 19 */
  5483. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  5484. Object.defineProperty(exports, "__esModule", ({
  5485. value: true
  5486. }));
  5487. exports.SimpleLinkService = exports.PDFLinkService = void 0;
  5488. var _ui_utils = __webpack_require__(4);
  5489. class PDFLinkService {
  5490. constructor({
  5491. eventBus,
  5492. externalLinkTarget = null,
  5493. externalLinkRel = null,
  5494. ignoreDestinationZoom = false
  5495. } = {}) {
  5496. this.eventBus = eventBus;
  5497. this.externalLinkTarget = externalLinkTarget;
  5498. this.externalLinkRel = externalLinkRel;
  5499. this.externalLinkEnabled = true;
  5500. this._ignoreDestinationZoom = ignoreDestinationZoom;
  5501. this.baseUrl = null;
  5502. this.pdfDocument = null;
  5503. this.pdfViewer = null;
  5504. this.pdfHistory = null;
  5505. this._pagesRefCache = null;
  5506. }
  5507. setDocument(pdfDocument, baseUrl = null) {
  5508. this.baseUrl = baseUrl;
  5509. this.pdfDocument = pdfDocument;
  5510. this._pagesRefCache = Object.create(null);
  5511. }
  5512. setViewer(pdfViewer) {
  5513. this.pdfViewer = pdfViewer;
  5514. }
  5515. setHistory(pdfHistory) {
  5516. this.pdfHistory = pdfHistory;
  5517. }
  5518. get pagesCount() {
  5519. return this.pdfDocument ? this.pdfDocument.numPages : 0;
  5520. }
  5521. get page() {
  5522. return this.pdfViewer.currentPageNumber;
  5523. }
  5524. set page(value) {
  5525. this.pdfViewer.currentPageNumber = value;
  5526. }
  5527. get rotation() {
  5528. return this.pdfViewer.pagesRotation;
  5529. }
  5530. set rotation(value) {
  5531. this.pdfViewer.pagesRotation = value;
  5532. }
  5533. _goToDestinationHelper(rawDest, namedDest = null, explicitDest) {
  5534. const destRef = explicitDest[0];
  5535. let pageNumber;
  5536. if (typeof destRef === "object" && destRef !== null) {
  5537. pageNumber = this._cachedPageNumber(destRef);
  5538. if (pageNumber === null) {
  5539. this.pdfDocument.getPageIndex(destRef).then(pageIndex => {
  5540. this.cachePageRef(pageIndex + 1, destRef);
  5541. this._goToDestinationHelper(rawDest, namedDest, explicitDest);
  5542. }).catch(() => {
  5543. console.error(`PDFLinkService._goToDestinationHelper: "${destRef}" is not ` + `a valid page reference, for dest="${rawDest}".`);
  5544. });
  5545. return;
  5546. }
  5547. } else if (Number.isInteger(destRef)) {
  5548. pageNumber = destRef + 1;
  5549. } else {
  5550. console.error(`PDFLinkService._goToDestinationHelper: "${destRef}" is not ` + `a valid destination reference, for dest="${rawDest}".`);
  5551. return;
  5552. }
  5553. if (!pageNumber || pageNumber < 1 || pageNumber > this.pagesCount) {
  5554. console.error(`PDFLinkService._goToDestinationHelper: "${pageNumber}" is not ` + `a valid page number, for dest="${rawDest}".`);
  5555. return;
  5556. }
  5557. if (this.pdfHistory) {
  5558. this.pdfHistory.pushCurrentPosition();
  5559. this.pdfHistory.push({
  5560. namedDest,
  5561. explicitDest,
  5562. pageNumber
  5563. });
  5564. }
  5565. this.pdfViewer.scrollPageIntoView({
  5566. pageNumber,
  5567. destArray: explicitDest,
  5568. ignoreDestinationZoom: this._ignoreDestinationZoom
  5569. });
  5570. }
  5571. async goToDestination(dest) {
  5572. if (!this.pdfDocument) {
  5573. return;
  5574. }
  5575. let namedDest, explicitDest;
  5576. if (typeof dest === "string") {
  5577. namedDest = dest;
  5578. explicitDest = await this.pdfDocument.getDestination(dest);
  5579. } else {
  5580. namedDest = null;
  5581. explicitDest = await dest;
  5582. }
  5583. if (!Array.isArray(explicitDest)) {
  5584. console.error(`PDFLinkService.goToDestination: "${explicitDest}" is not ` + `a valid destination array, for dest="${dest}".`);
  5585. return;
  5586. }
  5587. this._goToDestinationHelper(dest, namedDest, explicitDest);
  5588. }
  5589. goToPage(val) {
  5590. if (!this.pdfDocument) {
  5591. return;
  5592. }
  5593. const pageNumber = typeof val === "string" && this.pdfViewer.pageLabelToPageNumber(val) || val | 0;
  5594. if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) {
  5595. console.error(`PDFLinkService.goToPage: "${val}" is not a valid page.`);
  5596. return;
  5597. }
  5598. if (this.pdfHistory) {
  5599. this.pdfHistory.pushCurrentPosition();
  5600. this.pdfHistory.pushPage(pageNumber);
  5601. }
  5602. this.pdfViewer.scrollPageIntoView({
  5603. pageNumber
  5604. });
  5605. }
  5606. getDestinationHash(dest) {
  5607. if (typeof dest === "string") {
  5608. if (dest.length > 0) {
  5609. return this.getAnchorUrl("#" + escape(dest));
  5610. }
  5611. } else if (Array.isArray(dest)) {
  5612. const str = JSON.stringify(dest);
  5613. if (str.length > 0) {
  5614. return this.getAnchorUrl("#" + escape(str));
  5615. }
  5616. }
  5617. return this.getAnchorUrl("");
  5618. }
  5619. getAnchorUrl(anchor) {
  5620. return (this.baseUrl || "") + anchor;
  5621. }
  5622. setHash(hash) {
  5623. if (!this.pdfDocument) {
  5624. return;
  5625. }
  5626. let pageNumber, dest;
  5627. if (hash.includes("=")) {
  5628. const params = (0, _ui_utils.parseQueryString)(hash);
  5629. if ("search" in params) {
  5630. this.eventBus.dispatch("findfromurlhash", {
  5631. source: this,
  5632. query: params.search.replace(/"/g, ""),
  5633. phraseSearch: params.phrase === "true"
  5634. });
  5635. }
  5636. if ("page" in params) {
  5637. pageNumber = params.page | 0 || 1;
  5638. }
  5639. if ("zoom" in params) {
  5640. const zoomArgs = params.zoom.split(",");
  5641. const zoomArg = zoomArgs[0];
  5642. const zoomArgNumber = parseFloat(zoomArg);
  5643. if (!zoomArg.includes("Fit")) {
  5644. dest = [null, {
  5645. name: "XYZ"
  5646. }, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null, zoomArgs.length > 2 ? zoomArgs[2] | 0 : null, zoomArgNumber ? zoomArgNumber / 100 : zoomArg];
  5647. } else {
  5648. if (zoomArg === "Fit" || zoomArg === "FitB") {
  5649. dest = [null, {
  5650. name: zoomArg
  5651. }];
  5652. } else if (zoomArg === "FitH" || zoomArg === "FitBH" || zoomArg === "FitV" || zoomArg === "FitBV") {
  5653. dest = [null, {
  5654. name: zoomArg
  5655. }, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null];
  5656. } else if (zoomArg === "FitR") {
  5657. if (zoomArgs.length !== 5) {
  5658. console.error('PDFLinkService.setHash: Not enough parameters for "FitR".');
  5659. } else {
  5660. dest = [null, {
  5661. name: zoomArg
  5662. }, zoomArgs[1] | 0, zoomArgs[2] | 0, zoomArgs[3] | 0, zoomArgs[4] | 0];
  5663. }
  5664. } else {
  5665. console.error(`PDFLinkService.setHash: "${zoomArg}" is not ` + "a valid zoom value.");
  5666. }
  5667. }
  5668. }
  5669. if (dest) {
  5670. this.pdfViewer.scrollPageIntoView({
  5671. pageNumber: pageNumber || this.page,
  5672. destArray: dest,
  5673. allowNegativeOffset: true
  5674. });
  5675. } else if (pageNumber) {
  5676. this.page = pageNumber;
  5677. }
  5678. if ("pagemode" in params) {
  5679. this.eventBus.dispatch("pagemode", {
  5680. source: this,
  5681. mode: params.pagemode
  5682. });
  5683. }
  5684. if ("nameddest" in params) {
  5685. this.goToDestination(params.nameddest);
  5686. }
  5687. } else {
  5688. dest = unescape(hash);
  5689. try {
  5690. dest = JSON.parse(dest);
  5691. if (!Array.isArray(dest)) {
  5692. dest = dest.toString();
  5693. }
  5694. } catch (ex) {}
  5695. if (typeof dest === "string" || isValidExplicitDestination(dest)) {
  5696. this.goToDestination(dest);
  5697. return;
  5698. }
  5699. console.error(`PDFLinkService.setHash: "${unescape(hash)}" is not ` + "a valid destination.");
  5700. }
  5701. }
  5702. executeNamedAction(action) {
  5703. switch (action) {
  5704. case "GoBack":
  5705. if (this.pdfHistory) {
  5706. this.pdfHistory.back();
  5707. }
  5708. break;
  5709. case "GoForward":
  5710. if (this.pdfHistory) {
  5711. this.pdfHistory.forward();
  5712. }
  5713. break;
  5714. case "NextPage":
  5715. this.pdfViewer.nextPage();
  5716. break;
  5717. case "PrevPage":
  5718. this.pdfViewer.previousPage();
  5719. break;
  5720. case "LastPage":
  5721. this.page = this.pagesCount;
  5722. break;
  5723. case "FirstPage":
  5724. this.page = 1;
  5725. break;
  5726. default:
  5727. break;
  5728. }
  5729. this.eventBus.dispatch("namedaction", {
  5730. source: this,
  5731. action
  5732. });
  5733. }
  5734. cachePageRef(pageNum, pageRef) {
  5735. if (!pageRef) {
  5736. return;
  5737. }
  5738. const refStr = pageRef.gen === 0 ? `${pageRef.num}R` : `${pageRef.num}R${pageRef.gen}`;
  5739. this._pagesRefCache[refStr] = pageNum;
  5740. }
  5741. _cachedPageNumber(pageRef) {
  5742. const refStr = pageRef.gen === 0 ? `${pageRef.num}R` : `${pageRef.num}R${pageRef.gen}`;
  5743. return this._pagesRefCache?.[refStr] || null;
  5744. }
  5745. isPageVisible(pageNumber) {
  5746. return this.pdfViewer.isPageVisible(pageNumber);
  5747. }
  5748. isPageCached(pageNumber) {
  5749. return this.pdfViewer.isPageCached(pageNumber);
  5750. }
  5751. }
  5752. exports.PDFLinkService = PDFLinkService;
  5753. function isValidExplicitDestination(dest) {
  5754. if (!Array.isArray(dest)) {
  5755. return false;
  5756. }
  5757. const destLength = dest.length;
  5758. if (destLength < 2) {
  5759. return false;
  5760. }
  5761. const page = dest[0];
  5762. if (!(typeof page === "object" && Number.isInteger(page.num) && Number.isInteger(page.gen)) && !(Number.isInteger(page) && page >= 0)) {
  5763. return false;
  5764. }
  5765. const zoom = dest[1];
  5766. if (!(typeof zoom === "object" && typeof zoom.name === "string")) {
  5767. return false;
  5768. }
  5769. let allowNull = true;
  5770. switch (zoom.name) {
  5771. case "XYZ":
  5772. if (destLength !== 5) {
  5773. return false;
  5774. }
  5775. break;
  5776. case "Fit":
  5777. case "FitB":
  5778. return destLength === 2;
  5779. case "FitH":
  5780. case "FitBH":
  5781. case "FitV":
  5782. case "FitBV":
  5783. if (destLength !== 3) {
  5784. return false;
  5785. }
  5786. break;
  5787. case "FitR":
  5788. if (destLength !== 6) {
  5789. return false;
  5790. }
  5791. allowNull = false;
  5792. break;
  5793. default:
  5794. return false;
  5795. }
  5796. for (let i = 2; i < destLength; i++) {
  5797. const param = dest[i];
  5798. if (!(typeof param === "number" || allowNull && param === null)) {
  5799. return false;
  5800. }
  5801. }
  5802. return true;
  5803. }
  5804. class SimpleLinkService {
  5805. constructor() {
  5806. this.externalLinkTarget = null;
  5807. this.externalLinkRel = null;
  5808. this.externalLinkEnabled = true;
  5809. this._ignoreDestinationZoom = false;
  5810. }
  5811. get pagesCount() {
  5812. return 0;
  5813. }
  5814. get page() {
  5815. return 0;
  5816. }
  5817. set page(value) {}
  5818. get rotation() {
  5819. return 0;
  5820. }
  5821. set rotation(value) {}
  5822. async goToDestination(dest) {}
  5823. goToPage(val) {}
  5824. getDestinationHash(dest) {
  5825. return "#";
  5826. }
  5827. getAnchorUrl(hash) {
  5828. return "#";
  5829. }
  5830. setHash(hash) {}
  5831. executeNamedAction(action) {}
  5832. cachePageRef(pageNum, pageRef) {}
  5833. isPageVisible(pageNumber) {
  5834. return true;
  5835. }
  5836. isPageCached(pageNumber) {
  5837. return true;
  5838. }
  5839. }
  5840. exports.SimpleLinkService = SimpleLinkService;
  5841. /***/ }),
  5842. /* 20 */
  5843. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  5844. Object.defineProperty(exports, "__esModule", ({
  5845. value: true
  5846. }));
  5847. exports.PDFOutlineViewer = void 0;
  5848. var _pdfjsLib = __webpack_require__(5);
  5849. var _base_tree_viewer = __webpack_require__(12);
  5850. var _ui_utils = __webpack_require__(4);
  5851. class PDFOutlineViewer extends _base_tree_viewer.BaseTreeViewer {
  5852. constructor(options) {
  5853. super(options);
  5854. this.linkService = options.linkService;
  5855. this.eventBus._on("toggleoutlinetree", this._toggleAllTreeItems.bind(this));
  5856. this.eventBus._on("currentoutlineitem", this._currentOutlineItem.bind(this));
  5857. this.eventBus._on("pagechanging", evt => {
  5858. this._currentPageNumber = evt.pageNumber;
  5859. });
  5860. this.eventBus._on("pagesloaded", evt => {
  5861. this._isPagesLoaded = !!evt.pagesCount;
  5862. if (this._currentOutlineItemCapability && !this._currentOutlineItemCapability.settled) {
  5863. this._currentOutlineItemCapability.resolve(this._isPagesLoaded);
  5864. }
  5865. });
  5866. this.eventBus._on("sidebarviewchanged", evt => {
  5867. this._sidebarView = evt.view;
  5868. });
  5869. }
  5870. reset() {
  5871. super.reset();
  5872. this._outline = null;
  5873. this._pageNumberToDestHashCapability = null;
  5874. this._currentPageNumber = 1;
  5875. this._isPagesLoaded = false;
  5876. if (this._currentOutlineItemCapability && !this._currentOutlineItemCapability.settled) {
  5877. this._currentOutlineItemCapability.resolve(false);
  5878. }
  5879. this._currentOutlineItemCapability = null;
  5880. }
  5881. _dispatchEvent(outlineCount) {
  5882. this._currentOutlineItemCapability = (0, _pdfjsLib.createPromiseCapability)();
  5883. if (outlineCount === 0 || this._pdfDocument?.loadingParams.disableAutoFetch) {
  5884. this._currentOutlineItemCapability.resolve(false);
  5885. } else if (this._isPagesLoaded) {
  5886. this._currentOutlineItemCapability.resolve(true);
  5887. }
  5888. this.eventBus.dispatch("outlineloaded", {
  5889. source: this,
  5890. outlineCount,
  5891. currentOutlineItemPromise: this._currentOutlineItemCapability.promise
  5892. });
  5893. }
  5894. _bindLink(element, {
  5895. url,
  5896. newWindow,
  5897. dest
  5898. }) {
  5899. const {
  5900. linkService
  5901. } = this;
  5902. if (url) {
  5903. (0, _pdfjsLib.addLinkAttributes)(element, {
  5904. url,
  5905. target: newWindow ? _pdfjsLib.LinkTarget.BLANK : linkService.externalLinkTarget,
  5906. rel: linkService.externalLinkRel,
  5907. enabled: linkService.externalLinkEnabled
  5908. });
  5909. return;
  5910. }
  5911. element.href = linkService.getDestinationHash(dest);
  5912. element.onclick = evt => {
  5913. this._updateCurrentTreeItem(evt.target.parentNode);
  5914. if (dest) {
  5915. linkService.goToDestination(dest);
  5916. }
  5917. return false;
  5918. };
  5919. }
  5920. _setStyles(element, {
  5921. bold,
  5922. italic
  5923. }) {
  5924. if (bold) {
  5925. element.style.fontWeight = "bold";
  5926. }
  5927. if (italic) {
  5928. element.style.fontStyle = "italic";
  5929. }
  5930. }
  5931. _addToggleButton(div, {
  5932. count,
  5933. items
  5934. }) {
  5935. let hidden = false;
  5936. if (count < 0) {
  5937. let totalCount = items.length;
  5938. if (totalCount > 0) {
  5939. const queue = [...items];
  5940. while (queue.length > 0) {
  5941. const {
  5942. count: nestedCount,
  5943. items: nestedItems
  5944. } = queue.shift();
  5945. if (nestedCount > 0 && nestedItems.length > 0) {
  5946. totalCount += nestedItems.length;
  5947. queue.push(...nestedItems);
  5948. }
  5949. }
  5950. }
  5951. if (Math.abs(count) === totalCount) {
  5952. hidden = true;
  5953. }
  5954. }
  5955. super._addToggleButton(div, hidden);
  5956. }
  5957. _toggleAllTreeItems() {
  5958. if (!this._outline) {
  5959. return;
  5960. }
  5961. super._toggleAllTreeItems();
  5962. }
  5963. render({
  5964. outline,
  5965. pdfDocument
  5966. }) {
  5967. if (this._outline) {
  5968. this.reset();
  5969. }
  5970. this._outline = outline || null;
  5971. this._pdfDocument = pdfDocument || null;
  5972. if (!outline) {
  5973. this._dispatchEvent(0);
  5974. return;
  5975. }
  5976. const fragment = document.createDocumentFragment();
  5977. const queue = [{
  5978. parent: fragment,
  5979. items: outline
  5980. }];
  5981. let outlineCount = 0,
  5982. hasAnyNesting = false;
  5983. while (queue.length > 0) {
  5984. const levelData = queue.shift();
  5985. for (const item of levelData.items) {
  5986. const div = document.createElement("div");
  5987. div.className = "treeItem";
  5988. const element = document.createElement("a");
  5989. this._bindLink(element, item);
  5990. this._setStyles(element, item);
  5991. element.textContent = this._normalizeTextContent(item.title);
  5992. div.appendChild(element);
  5993. if (item.items.length > 0) {
  5994. hasAnyNesting = true;
  5995. this._addToggleButton(div, item);
  5996. const itemsDiv = document.createElement("div");
  5997. itemsDiv.className = "treeItems";
  5998. div.appendChild(itemsDiv);
  5999. queue.push({
  6000. parent: itemsDiv,
  6001. items: item.items
  6002. });
  6003. }
  6004. levelData.parent.appendChild(div);
  6005. outlineCount++;
  6006. }
  6007. }
  6008. this._finishRendering(fragment, outlineCount, hasAnyNesting);
  6009. }
  6010. async _currentOutlineItem() {
  6011. if (!this._isPagesLoaded) {
  6012. throw new Error("_currentOutlineItem: All pages have not been loaded.");
  6013. }
  6014. if (!this._outline || !this._pdfDocument) {
  6015. return;
  6016. }
  6017. const pageNumberToDestHash = await this._getPageNumberToDestHash(this._pdfDocument);
  6018. if (!pageNumberToDestHash) {
  6019. return;
  6020. }
  6021. this._updateCurrentTreeItem(null);
  6022. if (this._sidebarView !== _ui_utils.SidebarView.OUTLINE) {
  6023. return;
  6024. }
  6025. for (let i = this._currentPageNumber; i > 0; i--) {
  6026. const destHash = pageNumberToDestHash.get(i);
  6027. if (!destHash) {
  6028. continue;
  6029. }
  6030. const linkElement = this.container.querySelector(`a[href="${destHash}"]`);
  6031. if (!linkElement) {
  6032. continue;
  6033. }
  6034. this._scrollToCurrentTreeItem(linkElement.parentNode);
  6035. break;
  6036. }
  6037. }
  6038. async _getPageNumberToDestHash(pdfDocument) {
  6039. if (this._pageNumberToDestHashCapability) {
  6040. return this._pageNumberToDestHashCapability.promise;
  6041. }
  6042. this._pageNumberToDestHashCapability = (0, _pdfjsLib.createPromiseCapability)();
  6043. const pageNumberToDestHash = new Map(),
  6044. pageNumberNesting = new Map();
  6045. const queue = [{
  6046. nesting: 0,
  6047. items: this._outline
  6048. }];
  6049. while (queue.length > 0) {
  6050. const levelData = queue.shift(),
  6051. currentNesting = levelData.nesting;
  6052. for (const {
  6053. dest,
  6054. items
  6055. } of levelData.items) {
  6056. let explicitDest, pageNumber;
  6057. if (typeof dest === "string") {
  6058. explicitDest = await pdfDocument.getDestination(dest);
  6059. if (pdfDocument !== this._pdfDocument) {
  6060. return null;
  6061. }
  6062. } else {
  6063. explicitDest = dest;
  6064. }
  6065. if (Array.isArray(explicitDest)) {
  6066. const [destRef] = explicitDest;
  6067. if (typeof destRef === "object" && destRef !== null) {
  6068. pageNumber = this.linkService._cachedPageNumber(destRef);
  6069. if (!pageNumber) {
  6070. try {
  6071. pageNumber = (await pdfDocument.getPageIndex(destRef)) + 1;
  6072. if (pdfDocument !== this._pdfDocument) {
  6073. return null;
  6074. }
  6075. this.linkService.cachePageRef(pageNumber, destRef);
  6076. } catch (ex) {}
  6077. }
  6078. } else if (Number.isInteger(destRef)) {
  6079. pageNumber = destRef + 1;
  6080. }
  6081. if (Number.isInteger(pageNumber) && (!pageNumberToDestHash.has(pageNumber) || currentNesting > pageNumberNesting.get(pageNumber))) {
  6082. const destHash = this.linkService.getDestinationHash(dest);
  6083. pageNumberToDestHash.set(pageNumber, destHash);
  6084. pageNumberNesting.set(pageNumber, currentNesting);
  6085. }
  6086. }
  6087. if (items.length > 0) {
  6088. queue.push({
  6089. nesting: currentNesting + 1,
  6090. items
  6091. });
  6092. }
  6093. }
  6094. }
  6095. this._pageNumberToDestHashCapability.resolve(pageNumberToDestHash.size > 0 ? pageNumberToDestHash : null);
  6096. return this._pageNumberToDestHashCapability.promise;
  6097. }
  6098. }
  6099. exports.PDFOutlineViewer = PDFOutlineViewer;
  6100. /***/ }),
  6101. /* 21 */
  6102. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6103. Object.defineProperty(exports, "__esModule", ({
  6104. value: true
  6105. }));
  6106. exports.PDFPresentationMode = void 0;
  6107. var _ui_utils = __webpack_require__(4);
  6108. const DELAY_BEFORE_RESETTING_SWITCH_IN_PROGRESS = 1500;
  6109. const DELAY_BEFORE_HIDING_CONTROLS = 3000;
  6110. const ACTIVE_SELECTOR = "pdfPresentationMode";
  6111. const CONTROLS_SELECTOR = "pdfPresentationModeControls";
  6112. const MOUSE_SCROLL_COOLDOWN_TIME = 50;
  6113. const PAGE_SWITCH_THRESHOLD = 0.1;
  6114. const SWIPE_MIN_DISTANCE_THRESHOLD = 50;
  6115. const SWIPE_ANGLE_THRESHOLD = Math.PI / 6;
  6116. class PDFPresentationMode {
  6117. constructor({
  6118. container,
  6119. pdfViewer,
  6120. eventBus
  6121. }) {
  6122. this.container = container;
  6123. this.pdfViewer = pdfViewer;
  6124. this.eventBus = eventBus;
  6125. this.active = false;
  6126. this.args = null;
  6127. this.contextMenuOpen = false;
  6128. this.mouseScrollTimeStamp = 0;
  6129. this.mouseScrollDelta = 0;
  6130. this.touchSwipeState = null;
  6131. }
  6132. request() {
  6133. if (this.switchInProgress || this.active || !this.pdfViewer.pagesCount) {
  6134. return false;
  6135. }
  6136. this._addFullscreenChangeListeners();
  6137. this._setSwitchInProgress();
  6138. this._notifyStateChange();
  6139. if (this.container.requestFullscreen) {
  6140. this.container.requestFullscreen();
  6141. } else if (this.container.mozRequestFullScreen) {
  6142. this.container.mozRequestFullScreen();
  6143. } else if (this.container.webkitRequestFullscreen) {
  6144. this.container.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
  6145. } else {
  6146. return false;
  6147. }
  6148. this.args = {
  6149. page: this.pdfViewer.currentPageNumber,
  6150. previousScale: this.pdfViewer.currentScaleValue
  6151. };
  6152. return true;
  6153. }
  6154. _mouseWheel(evt) {
  6155. if (!this.active) {
  6156. return;
  6157. }
  6158. evt.preventDefault();
  6159. const delta = (0, _ui_utils.normalizeWheelEventDelta)(evt);
  6160. const currentTime = Date.now();
  6161. const storedTime = this.mouseScrollTimeStamp;
  6162. if (currentTime > storedTime && currentTime - storedTime < MOUSE_SCROLL_COOLDOWN_TIME) {
  6163. return;
  6164. }
  6165. if (this.mouseScrollDelta > 0 && delta < 0 || this.mouseScrollDelta < 0 && delta > 0) {
  6166. this._resetMouseScrollState();
  6167. }
  6168. this.mouseScrollDelta += delta;
  6169. if (Math.abs(this.mouseScrollDelta) >= PAGE_SWITCH_THRESHOLD) {
  6170. const totalDelta = this.mouseScrollDelta;
  6171. this._resetMouseScrollState();
  6172. const success = totalDelta > 0 ? this.pdfViewer.previousPage() : this.pdfViewer.nextPage();
  6173. if (success) {
  6174. this.mouseScrollTimeStamp = currentTime;
  6175. }
  6176. }
  6177. }
  6178. get isFullscreen() {
  6179. return !!(document.fullscreenElement || document.mozFullScreen || document.webkitIsFullScreen);
  6180. }
  6181. _notifyStateChange() {
  6182. let state = _ui_utils.PresentationModeState.NORMAL;
  6183. if (this.switchInProgress) {
  6184. state = _ui_utils.PresentationModeState.CHANGING;
  6185. } else if (this.active) {
  6186. state = _ui_utils.PresentationModeState.FULLSCREEN;
  6187. }
  6188. this.eventBus.dispatch("presentationmodechanged", {
  6189. source: this,
  6190. state
  6191. });
  6192. }
  6193. _setSwitchInProgress() {
  6194. if (this.switchInProgress) {
  6195. clearTimeout(this.switchInProgress);
  6196. }
  6197. this.switchInProgress = setTimeout(() => {
  6198. this._removeFullscreenChangeListeners();
  6199. delete this.switchInProgress;
  6200. this._notifyStateChange();
  6201. }, DELAY_BEFORE_RESETTING_SWITCH_IN_PROGRESS);
  6202. }
  6203. _resetSwitchInProgress() {
  6204. if (this.switchInProgress) {
  6205. clearTimeout(this.switchInProgress);
  6206. delete this.switchInProgress;
  6207. }
  6208. }
  6209. _enter() {
  6210. this.active = true;
  6211. this._resetSwitchInProgress();
  6212. this._notifyStateChange();
  6213. this.container.classList.add(ACTIVE_SELECTOR);
  6214. setTimeout(() => {
  6215. this.pdfViewer.currentPageNumber = this.args.page;
  6216. this.pdfViewer.currentScaleValue = "page-fit";
  6217. }, 0);
  6218. this._addWindowListeners();
  6219. this._showControls();
  6220. this.contextMenuOpen = false;
  6221. window.getSelection().removeAllRanges();
  6222. }
  6223. _exit() {
  6224. const page = this.pdfViewer.currentPageNumber;
  6225. this.container.classList.remove(ACTIVE_SELECTOR);
  6226. setTimeout(() => {
  6227. this.active = false;
  6228. this._removeFullscreenChangeListeners();
  6229. this._notifyStateChange();
  6230. this.pdfViewer.currentScaleValue = this.args.previousScale;
  6231. this.pdfViewer.currentPageNumber = page;
  6232. this.args = null;
  6233. }, 0);
  6234. this._removeWindowListeners();
  6235. this._hideControls();
  6236. this._resetMouseScrollState();
  6237. this.contextMenuOpen = false;
  6238. }
  6239. _mouseDown(evt) {
  6240. if (this.contextMenuOpen) {
  6241. this.contextMenuOpen = false;
  6242. evt.preventDefault();
  6243. return;
  6244. }
  6245. if (evt.button === 0) {
  6246. const isInternalLink = evt.target.href && evt.target.classList.contains("internalLink");
  6247. if (!isInternalLink) {
  6248. evt.preventDefault();
  6249. if (evt.shiftKey) {
  6250. this.pdfViewer.previousPage();
  6251. } else {
  6252. this.pdfViewer.nextPage();
  6253. }
  6254. }
  6255. }
  6256. }
  6257. _contextMenu() {
  6258. this.contextMenuOpen = true;
  6259. }
  6260. _showControls() {
  6261. if (this.controlsTimeout) {
  6262. clearTimeout(this.controlsTimeout);
  6263. } else {
  6264. this.container.classList.add(CONTROLS_SELECTOR);
  6265. }
  6266. this.controlsTimeout = setTimeout(() => {
  6267. this.container.classList.remove(CONTROLS_SELECTOR);
  6268. delete this.controlsTimeout;
  6269. }, DELAY_BEFORE_HIDING_CONTROLS);
  6270. }
  6271. _hideControls() {
  6272. if (!this.controlsTimeout) {
  6273. return;
  6274. }
  6275. clearTimeout(this.controlsTimeout);
  6276. this.container.classList.remove(CONTROLS_SELECTOR);
  6277. delete this.controlsTimeout;
  6278. }
  6279. _resetMouseScrollState() {
  6280. this.mouseScrollTimeStamp = 0;
  6281. this.mouseScrollDelta = 0;
  6282. }
  6283. _touchSwipe(evt) {
  6284. if (!this.active) {
  6285. return;
  6286. }
  6287. if (evt.touches.length > 1) {
  6288. this.touchSwipeState = null;
  6289. return;
  6290. }
  6291. switch (evt.type) {
  6292. case "touchstart":
  6293. this.touchSwipeState = {
  6294. startX: evt.touches[0].pageX,
  6295. startY: evt.touches[0].pageY,
  6296. endX: evt.touches[0].pageX,
  6297. endY: evt.touches[0].pageY
  6298. };
  6299. break;
  6300. case "touchmove":
  6301. if (this.touchSwipeState === null) {
  6302. return;
  6303. }
  6304. this.touchSwipeState.endX = evt.touches[0].pageX;
  6305. this.touchSwipeState.endY = evt.touches[0].pageY;
  6306. evt.preventDefault();
  6307. break;
  6308. case "touchend":
  6309. if (this.touchSwipeState === null) {
  6310. return;
  6311. }
  6312. let delta = 0;
  6313. const dx = this.touchSwipeState.endX - this.touchSwipeState.startX;
  6314. const dy = this.touchSwipeState.endY - this.touchSwipeState.startY;
  6315. const absAngle = Math.abs(Math.atan2(dy, dx));
  6316. if (Math.abs(dx) > SWIPE_MIN_DISTANCE_THRESHOLD && (absAngle <= SWIPE_ANGLE_THRESHOLD || absAngle >= Math.PI - SWIPE_ANGLE_THRESHOLD)) {
  6317. delta = dx;
  6318. } else if (Math.abs(dy) > SWIPE_MIN_DISTANCE_THRESHOLD && Math.abs(absAngle - Math.PI / 2) <= SWIPE_ANGLE_THRESHOLD) {
  6319. delta = dy;
  6320. }
  6321. if (delta > 0) {
  6322. this.pdfViewer.previousPage();
  6323. } else if (delta < 0) {
  6324. this.pdfViewer.nextPage();
  6325. }
  6326. break;
  6327. }
  6328. }
  6329. _addWindowListeners() {
  6330. this.showControlsBind = this._showControls.bind(this);
  6331. this.mouseDownBind = this._mouseDown.bind(this);
  6332. this.mouseWheelBind = this._mouseWheel.bind(this);
  6333. this.resetMouseScrollStateBind = this._resetMouseScrollState.bind(this);
  6334. this.contextMenuBind = this._contextMenu.bind(this);
  6335. this.touchSwipeBind = this._touchSwipe.bind(this);
  6336. window.addEventListener("mousemove", this.showControlsBind);
  6337. window.addEventListener("mousedown", this.mouseDownBind);
  6338. window.addEventListener("wheel", this.mouseWheelBind, {
  6339. passive: false
  6340. });
  6341. window.addEventListener("keydown", this.resetMouseScrollStateBind);
  6342. window.addEventListener("contextmenu", this.contextMenuBind);
  6343. window.addEventListener("touchstart", this.touchSwipeBind);
  6344. window.addEventListener("touchmove", this.touchSwipeBind);
  6345. window.addEventListener("touchend", this.touchSwipeBind);
  6346. }
  6347. _removeWindowListeners() {
  6348. window.removeEventListener("mousemove", this.showControlsBind);
  6349. window.removeEventListener("mousedown", this.mouseDownBind);
  6350. window.removeEventListener("wheel", this.mouseWheelBind, {
  6351. passive: false
  6352. });
  6353. window.removeEventListener("keydown", this.resetMouseScrollStateBind);
  6354. window.removeEventListener("contextmenu", this.contextMenuBind);
  6355. window.removeEventListener("touchstart", this.touchSwipeBind);
  6356. window.removeEventListener("touchmove", this.touchSwipeBind);
  6357. window.removeEventListener("touchend", this.touchSwipeBind);
  6358. delete this.showControlsBind;
  6359. delete this.mouseDownBind;
  6360. delete this.mouseWheelBind;
  6361. delete this.resetMouseScrollStateBind;
  6362. delete this.contextMenuBind;
  6363. delete this.touchSwipeBind;
  6364. }
  6365. _fullscreenChange() {
  6366. if (this.isFullscreen) {
  6367. this._enter();
  6368. } else {
  6369. this._exit();
  6370. }
  6371. }
  6372. _addFullscreenChangeListeners() {
  6373. this.fullscreenChangeBind = this._fullscreenChange.bind(this);
  6374. window.addEventListener("fullscreenchange", this.fullscreenChangeBind);
  6375. window.addEventListener("mozfullscreenchange", this.fullscreenChangeBind);
  6376. window.addEventListener("webkitfullscreenchange", this.fullscreenChangeBind);
  6377. }
  6378. _removeFullscreenChangeListeners() {
  6379. window.removeEventListener("fullscreenchange", this.fullscreenChangeBind);
  6380. window.removeEventListener("mozfullscreenchange", this.fullscreenChangeBind);
  6381. window.removeEventListener("webkitfullscreenchange", this.fullscreenChangeBind);
  6382. delete this.fullscreenChangeBind;
  6383. }
  6384. }
  6385. exports.PDFPresentationMode = PDFPresentationMode;
  6386. /***/ }),
  6387. /* 22 */
  6388. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6389. Object.defineProperty(exports, "__esModule", ({
  6390. value: true
  6391. }));
  6392. exports.PDFScriptingManager = void 0;
  6393. var _pdfjsLib = __webpack_require__(5);
  6394. var _ui_utils = __webpack_require__(4);
  6395. var _pdf_rendering_queue = __webpack_require__(8);
  6396. class PDFScriptingManager {
  6397. constructor({
  6398. eventBus,
  6399. sandboxBundleSrc = null,
  6400. scriptingFactory = null,
  6401. docPropertiesLookup = null
  6402. }) {
  6403. this._pdfDocument = null;
  6404. this._pdfViewer = null;
  6405. this._closeCapability = null;
  6406. this._destroyCapability = null;
  6407. this._scripting = null;
  6408. this._mouseState = Object.create(null);
  6409. this._ready = false;
  6410. this._eventBus = eventBus;
  6411. this._sandboxBundleSrc = sandboxBundleSrc;
  6412. this._scriptingFactory = scriptingFactory;
  6413. this._docPropertiesLookup = docPropertiesLookup;
  6414. }
  6415. setViewer(pdfViewer) {
  6416. this._pdfViewer = pdfViewer;
  6417. }
  6418. async setDocument(pdfDocument) {
  6419. if (this._pdfDocument) {
  6420. await this._destroyScripting();
  6421. }
  6422. this._pdfDocument = pdfDocument;
  6423. if (!pdfDocument) {
  6424. return;
  6425. }
  6426. const [objects, calculationOrder, docActions] = await Promise.all([pdfDocument.getFieldObjects(), pdfDocument.getCalculationOrderIds(), pdfDocument.getJSActions()]);
  6427. if (!objects && !docActions) {
  6428. await this._destroyScripting();
  6429. return;
  6430. }
  6431. if (pdfDocument !== this._pdfDocument) {
  6432. return;
  6433. }
  6434. try {
  6435. this._scripting = this._createScripting();
  6436. } catch (error) {
  6437. console.error(`PDFScriptingManager.setDocument: "${error?.message}".`);
  6438. await this._destroyScripting();
  6439. return;
  6440. }
  6441. this._internalEvents.set("updatefromsandbox", event => {
  6442. if (event?.source !== window) {
  6443. return;
  6444. }
  6445. this._updateFromSandbox(event.detail);
  6446. });
  6447. this._internalEvents.set("dispatcheventinsandbox", event => {
  6448. this._scripting?.dispatchEventInSandbox(event.detail);
  6449. });
  6450. this._internalEvents.set("pagechanging", ({
  6451. pageNumber,
  6452. previous
  6453. }) => {
  6454. if (pageNumber === previous) {
  6455. return;
  6456. }
  6457. this._dispatchPageClose(previous);
  6458. this._dispatchPageOpen(pageNumber);
  6459. });
  6460. this._internalEvents.set("pagerendered", ({
  6461. pageNumber
  6462. }) => {
  6463. if (!this._pageOpenPending.has(pageNumber)) {
  6464. return;
  6465. }
  6466. if (pageNumber !== this._pdfViewer.currentPageNumber) {
  6467. return;
  6468. }
  6469. this._dispatchPageOpen(pageNumber);
  6470. });
  6471. this._internalEvents.set("pagesdestroy", async event => {
  6472. await this._dispatchPageClose(this._pdfViewer.currentPageNumber);
  6473. await this._scripting?.dispatchEventInSandbox({
  6474. id: "doc",
  6475. name: "WillClose"
  6476. });
  6477. this._closeCapability?.resolve();
  6478. });
  6479. this._domEvents.set("mousedown", event => {
  6480. this._mouseState.isDown = true;
  6481. });
  6482. this._domEvents.set("mouseup", event => {
  6483. this._mouseState.isDown = false;
  6484. });
  6485. for (const [name, listener] of this._internalEvents) {
  6486. this._eventBus._on(name, listener);
  6487. }
  6488. for (const [name, listener] of this._domEvents) {
  6489. window.addEventListener(name, listener);
  6490. }
  6491. try {
  6492. const docProperties = await this._getDocProperties();
  6493. if (pdfDocument !== this._pdfDocument) {
  6494. return;
  6495. }
  6496. await this._scripting.createSandbox({
  6497. objects,
  6498. calculationOrder,
  6499. appInfo: {
  6500. platform: navigator.platform,
  6501. language: navigator.language
  6502. },
  6503. docInfo: { ...docProperties,
  6504. actions: docActions
  6505. }
  6506. });
  6507. this._eventBus.dispatch("sandboxcreated", {
  6508. source: this
  6509. });
  6510. } catch (error) {
  6511. console.error(`PDFScriptingManager.setDocument: "${error?.message}".`);
  6512. await this._destroyScripting();
  6513. return;
  6514. }
  6515. await this._scripting?.dispatchEventInSandbox({
  6516. id: "doc",
  6517. name: "Open"
  6518. });
  6519. await this._dispatchPageOpen(this._pdfViewer.currentPageNumber, true);
  6520. Promise.resolve().then(() => {
  6521. if (pdfDocument === this._pdfDocument) {
  6522. this._ready = true;
  6523. }
  6524. });
  6525. }
  6526. async dispatchWillSave(detail) {
  6527. return this._scripting?.dispatchEventInSandbox({
  6528. id: "doc",
  6529. name: "WillSave"
  6530. });
  6531. }
  6532. async dispatchDidSave(detail) {
  6533. return this._scripting?.dispatchEventInSandbox({
  6534. id: "doc",
  6535. name: "DidSave"
  6536. });
  6537. }
  6538. async dispatchWillPrint(detail) {
  6539. return this._scripting?.dispatchEventInSandbox({
  6540. id: "doc",
  6541. name: "WillPrint"
  6542. });
  6543. }
  6544. async dispatchDidPrint(detail) {
  6545. return this._scripting?.dispatchEventInSandbox({
  6546. id: "doc",
  6547. name: "DidPrint"
  6548. });
  6549. }
  6550. get mouseState() {
  6551. return this._mouseState;
  6552. }
  6553. get destroyPromise() {
  6554. return this._destroyCapability?.promise || null;
  6555. }
  6556. get ready() {
  6557. return this._ready;
  6558. }
  6559. get _internalEvents() {
  6560. return (0, _pdfjsLib.shadow)(this, "_internalEvents", new Map());
  6561. }
  6562. get _domEvents() {
  6563. return (0, _pdfjsLib.shadow)(this, "_domEvents", new Map());
  6564. }
  6565. get _pageOpenPending() {
  6566. return (0, _pdfjsLib.shadow)(this, "_pageOpenPending", new Set());
  6567. }
  6568. get _visitedPages() {
  6569. return (0, _pdfjsLib.shadow)(this, "_visitedPages", new Map());
  6570. }
  6571. async _updateFromSandbox(detail) {
  6572. const isInPresentationMode = this._pdfViewer.isInPresentationMode || this._pdfViewer.isChangingPresentationMode;
  6573. const {
  6574. id,
  6575. siblings,
  6576. command,
  6577. value
  6578. } = detail;
  6579. if (!id) {
  6580. switch (command) {
  6581. case "clear":
  6582. console.clear();
  6583. break;
  6584. case "error":
  6585. console.error(value);
  6586. break;
  6587. case "layout":
  6588. this._pdfViewer.spreadMode = (0, _ui_utils.apiPageLayoutToSpreadMode)(value);
  6589. break;
  6590. case "page-num":
  6591. this._pdfViewer.currentPageNumber = value + 1;
  6592. break;
  6593. case "print":
  6594. await this._pdfViewer.pagesPromise;
  6595. this._eventBus.dispatch("print", {
  6596. source: this
  6597. });
  6598. break;
  6599. case "println":
  6600. console.log(value);
  6601. break;
  6602. case "zoom":
  6603. if (isInPresentationMode) {
  6604. return;
  6605. }
  6606. this._pdfViewer.currentScaleValue = value;
  6607. break;
  6608. }
  6609. return;
  6610. }
  6611. if (isInPresentationMode) {
  6612. if (detail.focus) {
  6613. return;
  6614. }
  6615. }
  6616. delete detail.id;
  6617. delete detail.siblings;
  6618. const ids = siblings ? [id, ...siblings] : [id];
  6619. for (const elementId of ids) {
  6620. const element = document.getElementById(elementId);
  6621. if (element) {
  6622. element.dispatchEvent(new CustomEvent("updatefromsandbox", {
  6623. detail
  6624. }));
  6625. } else {
  6626. this._pdfDocument?.annotationStorage.setValue(elementId, detail);
  6627. }
  6628. }
  6629. }
  6630. async _dispatchPageOpen(pageNumber, initialize = false) {
  6631. const pdfDocument = this._pdfDocument,
  6632. visitedPages = this._visitedPages;
  6633. if (initialize) {
  6634. this._closeCapability = (0, _pdfjsLib.createPromiseCapability)();
  6635. }
  6636. if (!this._closeCapability) {
  6637. return;
  6638. }
  6639. const pageView = this._pdfViewer.getPageView(pageNumber - 1);
  6640. if (pageView?.renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED) {
  6641. this._pageOpenPending.add(pageNumber);
  6642. return;
  6643. }
  6644. this._pageOpenPending.delete(pageNumber);
  6645. const actionsPromise = (async () => {
  6646. const actions = await (!visitedPages.has(pageNumber) ? pageView.pdfPage?.getJSActions() : null);
  6647. if (pdfDocument !== this._pdfDocument) {
  6648. return;
  6649. }
  6650. await this._scripting?.dispatchEventInSandbox({
  6651. id: "page",
  6652. name: "PageOpen",
  6653. pageNumber,
  6654. actions
  6655. });
  6656. })();
  6657. visitedPages.set(pageNumber, actionsPromise);
  6658. }
  6659. async _dispatchPageClose(pageNumber) {
  6660. const pdfDocument = this._pdfDocument,
  6661. visitedPages = this._visitedPages;
  6662. if (!this._closeCapability) {
  6663. return;
  6664. }
  6665. if (this._pageOpenPending.has(pageNumber)) {
  6666. return;
  6667. }
  6668. const actionsPromise = visitedPages.get(pageNumber);
  6669. if (!actionsPromise) {
  6670. return;
  6671. }
  6672. visitedPages.set(pageNumber, null);
  6673. await actionsPromise;
  6674. if (pdfDocument !== this._pdfDocument) {
  6675. return;
  6676. }
  6677. await this._scripting?.dispatchEventInSandbox({
  6678. id: "page",
  6679. name: "PageClose",
  6680. pageNumber
  6681. });
  6682. }
  6683. async _getDocProperties() {
  6684. if (this._docPropertiesLookup) {
  6685. return this._docPropertiesLookup(this._pdfDocument);
  6686. }
  6687. throw new Error("_getDocProperties: Unable to lookup properties.");
  6688. }
  6689. _createScripting() {
  6690. this._destroyCapability = (0, _pdfjsLib.createPromiseCapability)();
  6691. if (this._scripting) {
  6692. throw new Error("_createScripting: Scripting already exists.");
  6693. }
  6694. if (this._scriptingFactory) {
  6695. return this._scriptingFactory.createScripting({
  6696. sandboxBundleSrc: this._sandboxBundleSrc
  6697. });
  6698. }
  6699. throw new Error("_createScripting: Cannot create scripting.");
  6700. }
  6701. async _destroyScripting() {
  6702. if (!this._scripting) {
  6703. this._pdfDocument = null;
  6704. this._destroyCapability?.resolve();
  6705. return;
  6706. }
  6707. if (this._closeCapability) {
  6708. await Promise.race([this._closeCapability.promise, new Promise(resolve => {
  6709. setTimeout(resolve, 1000);
  6710. })]).catch(reason => {});
  6711. this._closeCapability = null;
  6712. }
  6713. this._pdfDocument = null;
  6714. try {
  6715. await this._scripting.destroySandbox();
  6716. } catch (ex) {}
  6717. for (const [name, listener] of this._internalEvents) {
  6718. this._eventBus._off(name, listener);
  6719. }
  6720. this._internalEvents.clear();
  6721. for (const [name, listener] of this._domEvents) {
  6722. window.removeEventListener(name, listener);
  6723. }
  6724. this._domEvents.clear();
  6725. this._pageOpenPending.clear();
  6726. this._visitedPages.clear();
  6727. this._scripting = null;
  6728. delete this._mouseState.isDown;
  6729. this._ready = false;
  6730. this._destroyCapability?.resolve();
  6731. }
  6732. }
  6733. exports.PDFScriptingManager = PDFScriptingManager;
  6734. /***/ }),
  6735. /* 23 */
  6736. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6737. Object.defineProperty(exports, "__esModule", ({
  6738. value: true
  6739. }));
  6740. exports.PDFSidebar = void 0;
  6741. var _ui_utils = __webpack_require__(4);
  6742. var _pdf_rendering_queue = __webpack_require__(8);
  6743. const UI_NOTIFICATION_CLASS = "pdfSidebarNotification";
  6744. class PDFSidebar {
  6745. constructor({
  6746. elements,
  6747. pdfViewer,
  6748. pdfThumbnailViewer,
  6749. eventBus,
  6750. l10n
  6751. }) {
  6752. this.isOpen = false;
  6753. this.active = _ui_utils.SidebarView.THUMBS;
  6754. this.isInitialViewSet = false;
  6755. this.onToggled = null;
  6756. this.pdfViewer = pdfViewer;
  6757. this.pdfThumbnailViewer = pdfThumbnailViewer;
  6758. this.outerContainer = elements.outerContainer;
  6759. this.viewerContainer = elements.viewerContainer;
  6760. this.toggleButton = elements.toggleButton;
  6761. this.thumbnailButton = elements.thumbnailButton;
  6762. this.outlineButton = elements.outlineButton;
  6763. this.attachmentsButton = elements.attachmentsButton;
  6764. this.layersButton = elements.layersButton;
  6765. this.thumbnailView = elements.thumbnailView;
  6766. this.outlineView = elements.outlineView;
  6767. this.attachmentsView = elements.attachmentsView;
  6768. this.layersView = elements.layersView;
  6769. this._outlineOptionsContainer = elements.outlineOptionsContainer;
  6770. this._currentOutlineItemButton = elements.currentOutlineItemButton;
  6771. this.eventBus = eventBus;
  6772. this.l10n = l10n;
  6773. this._addEventListeners();
  6774. }
  6775. reset() {
  6776. this.isInitialViewSet = false;
  6777. this._hideUINotification(true);
  6778. this.switchView(_ui_utils.SidebarView.THUMBS);
  6779. this.outlineButton.disabled = false;
  6780. this.attachmentsButton.disabled = false;
  6781. this.layersButton.disabled = false;
  6782. this._currentOutlineItemButton.disabled = true;
  6783. }
  6784. get visibleView() {
  6785. return this.isOpen ? this.active : _ui_utils.SidebarView.NONE;
  6786. }
  6787. get isThumbnailViewVisible() {
  6788. return this.isOpen && this.active === _ui_utils.SidebarView.THUMBS;
  6789. }
  6790. get isOutlineViewVisible() {
  6791. return this.isOpen && this.active === _ui_utils.SidebarView.OUTLINE;
  6792. }
  6793. get isAttachmentsViewVisible() {
  6794. return this.isOpen && this.active === _ui_utils.SidebarView.ATTACHMENTS;
  6795. }
  6796. get isLayersViewVisible() {
  6797. return this.isOpen && this.active === _ui_utils.SidebarView.LAYERS;
  6798. }
  6799. setInitialView(view = _ui_utils.SidebarView.NONE) {
  6800. if (this.isInitialViewSet) {
  6801. return;
  6802. }
  6803. this.isInitialViewSet = true;
  6804. if (view === _ui_utils.SidebarView.NONE || view === _ui_utils.SidebarView.UNKNOWN) {
  6805. this._dispatchEvent();
  6806. return;
  6807. }
  6808. if (!this._switchView(view, true)) {
  6809. this._dispatchEvent();
  6810. }
  6811. }
  6812. switchView(view, forceOpen = false) {
  6813. this._switchView(view, forceOpen);
  6814. }
  6815. _switchView(view, forceOpen = false) {
  6816. const isViewChanged = view !== this.active;
  6817. let shouldForceRendering = false;
  6818. switch (view) {
  6819. case _ui_utils.SidebarView.NONE:
  6820. if (this.isOpen) {
  6821. this.close();
  6822. return true;
  6823. }
  6824. return false;
  6825. case _ui_utils.SidebarView.THUMBS:
  6826. if (this.isOpen && isViewChanged) {
  6827. shouldForceRendering = true;
  6828. }
  6829. break;
  6830. case _ui_utils.SidebarView.OUTLINE:
  6831. if (this.outlineButton.disabled) {
  6832. return false;
  6833. }
  6834. break;
  6835. case _ui_utils.SidebarView.ATTACHMENTS:
  6836. if (this.attachmentsButton.disabled) {
  6837. return false;
  6838. }
  6839. break;
  6840. case _ui_utils.SidebarView.LAYERS:
  6841. if (this.layersButton.disabled) {
  6842. return false;
  6843. }
  6844. break;
  6845. default:
  6846. console.error(`PDFSidebar._switchView: "${view}" is not a valid view.`);
  6847. return false;
  6848. }
  6849. this.active = view;
  6850. this.thumbnailButton.classList.toggle("toggled", view === _ui_utils.SidebarView.THUMBS);
  6851. this.outlineButton.classList.toggle("toggled", view === _ui_utils.SidebarView.OUTLINE);
  6852. this.attachmentsButton.classList.toggle("toggled", view === _ui_utils.SidebarView.ATTACHMENTS);
  6853. this.layersButton.classList.toggle("toggled", view === _ui_utils.SidebarView.LAYERS);
  6854. this.thumbnailView.classList.toggle("hidden", view !== _ui_utils.SidebarView.THUMBS);
  6855. this.outlineView.classList.toggle("hidden", view !== _ui_utils.SidebarView.OUTLINE);
  6856. this.attachmentsView.classList.toggle("hidden", view !== _ui_utils.SidebarView.ATTACHMENTS);
  6857. this.layersView.classList.toggle("hidden", view !== _ui_utils.SidebarView.LAYERS);
  6858. this._outlineOptionsContainer.classList.toggle("hidden", view !== _ui_utils.SidebarView.OUTLINE);
  6859. if (forceOpen && !this.isOpen) {
  6860. this.open();
  6861. return true;
  6862. }
  6863. if (shouldForceRendering) {
  6864. this._updateThumbnailViewer();
  6865. this._forceRendering();
  6866. }
  6867. if (isViewChanged) {
  6868. this._dispatchEvent();
  6869. }
  6870. return isViewChanged;
  6871. }
  6872. open() {
  6873. if (this.isOpen) {
  6874. return;
  6875. }
  6876. this.isOpen = true;
  6877. this.toggleButton.classList.add("toggled");
  6878. this.toggleButton.setAttribute("aria-expanded", "true");
  6879. this.outerContainer.classList.add("sidebarMoving", "sidebarOpen");
  6880. if (this.active === _ui_utils.SidebarView.THUMBS) {
  6881. this._updateThumbnailViewer();
  6882. }
  6883. this._forceRendering();
  6884. this._dispatchEvent();
  6885. this._hideUINotification();
  6886. }
  6887. close() {
  6888. if (!this.isOpen) {
  6889. return;
  6890. }
  6891. this.isOpen = false;
  6892. this.toggleButton.classList.remove("toggled");
  6893. this.toggleButton.setAttribute("aria-expanded", "false");
  6894. this.outerContainer.classList.add("sidebarMoving");
  6895. this.outerContainer.classList.remove("sidebarOpen");
  6896. this._forceRendering();
  6897. this._dispatchEvent();
  6898. }
  6899. toggle() {
  6900. if (this.isOpen) {
  6901. this.close();
  6902. } else {
  6903. this.open();
  6904. }
  6905. }
  6906. _dispatchEvent() {
  6907. this.eventBus.dispatch("sidebarviewchanged", {
  6908. source: this,
  6909. view: this.visibleView
  6910. });
  6911. }
  6912. _forceRendering() {
  6913. if (this.onToggled) {
  6914. this.onToggled();
  6915. } else {
  6916. this.pdfViewer.forceRendering();
  6917. this.pdfThumbnailViewer.forceRendering();
  6918. }
  6919. }
  6920. _updateThumbnailViewer() {
  6921. const {
  6922. pdfViewer,
  6923. pdfThumbnailViewer
  6924. } = this;
  6925. const pagesCount = pdfViewer.pagesCount;
  6926. for (let pageIndex = 0; pageIndex < pagesCount; pageIndex++) {
  6927. const pageView = pdfViewer.getPageView(pageIndex);
  6928. if (pageView?.renderingState === _pdf_rendering_queue.RenderingStates.FINISHED) {
  6929. const thumbnailView = pdfThumbnailViewer.getThumbnail(pageIndex);
  6930. thumbnailView.setImage(pageView);
  6931. }
  6932. }
  6933. pdfThumbnailViewer.scrollThumbnailIntoView(pdfViewer.currentPageNumber);
  6934. }
  6935. _showUINotification() {
  6936. this.l10n.get("toggle_sidebar_notification2.title").then(msg => {
  6937. this.toggleButton.title = msg;
  6938. });
  6939. if (!this.isOpen) {
  6940. this.toggleButton.classList.add(UI_NOTIFICATION_CLASS);
  6941. }
  6942. }
  6943. _hideUINotification(reset = false) {
  6944. if (this.isOpen || reset) {
  6945. this.toggleButton.classList.remove(UI_NOTIFICATION_CLASS);
  6946. }
  6947. if (reset) {
  6948. this.l10n.get("toggle_sidebar.title").then(msg => {
  6949. this.toggleButton.title = msg;
  6950. });
  6951. }
  6952. }
  6953. _addEventListeners() {
  6954. this.viewerContainer.addEventListener("transitionend", evt => {
  6955. if (evt.target === this.viewerContainer) {
  6956. this.outerContainer.classList.remove("sidebarMoving");
  6957. }
  6958. });
  6959. this.toggleButton.addEventListener("click", () => {
  6960. this.toggle();
  6961. });
  6962. this.thumbnailButton.addEventListener("click", () => {
  6963. this.switchView(_ui_utils.SidebarView.THUMBS);
  6964. });
  6965. this.outlineButton.addEventListener("click", () => {
  6966. this.switchView(_ui_utils.SidebarView.OUTLINE);
  6967. });
  6968. this.outlineButton.addEventListener("dblclick", () => {
  6969. this.eventBus.dispatch("toggleoutlinetree", {
  6970. source: this
  6971. });
  6972. });
  6973. this.attachmentsButton.addEventListener("click", () => {
  6974. this.switchView(_ui_utils.SidebarView.ATTACHMENTS);
  6975. });
  6976. this.layersButton.addEventListener("click", () => {
  6977. this.switchView(_ui_utils.SidebarView.LAYERS);
  6978. });
  6979. this.layersButton.addEventListener("dblclick", () => {
  6980. this.eventBus.dispatch("resetlayers", {
  6981. source: this
  6982. });
  6983. });
  6984. this._currentOutlineItemButton.addEventListener("click", () => {
  6985. this.eventBus.dispatch("currentoutlineitem", {
  6986. source: this
  6987. });
  6988. });
  6989. const onTreeLoaded = (count, button, view) => {
  6990. button.disabled = !count;
  6991. if (count) {
  6992. this._showUINotification();
  6993. } else if (this.active === view) {
  6994. this.switchView(_ui_utils.SidebarView.THUMBS);
  6995. }
  6996. };
  6997. this.eventBus._on("outlineloaded", evt => {
  6998. onTreeLoaded(evt.outlineCount, this.outlineButton, _ui_utils.SidebarView.OUTLINE);
  6999. evt.currentOutlineItemPromise.then(enabled => {
  7000. if (!this.isInitialViewSet) {
  7001. return;
  7002. }
  7003. this._currentOutlineItemButton.disabled = !enabled;
  7004. });
  7005. });
  7006. this.eventBus._on("attachmentsloaded", evt => {
  7007. onTreeLoaded(evt.attachmentsCount, this.attachmentsButton, _ui_utils.SidebarView.ATTACHMENTS);
  7008. });
  7009. this.eventBus._on("layersloaded", evt => {
  7010. onTreeLoaded(evt.layersCount, this.layersButton, _ui_utils.SidebarView.LAYERS);
  7011. });
  7012. this.eventBus._on("presentationmodechanged", evt => {
  7013. if (evt.state === _ui_utils.PresentationModeState.NORMAL && this.isThumbnailViewVisible) {
  7014. this._updateThumbnailViewer();
  7015. }
  7016. });
  7017. }
  7018. }
  7019. exports.PDFSidebar = PDFSidebar;
  7020. /***/ }),
  7021. /* 24 */
  7022. /***/ ((__unused_webpack_module, exports) => {
  7023. Object.defineProperty(exports, "__esModule", ({
  7024. value: true
  7025. }));
  7026. exports.PDFSidebarResizer = void 0;
  7027. const SIDEBAR_WIDTH_VAR = "--sidebar-width";
  7028. const SIDEBAR_MIN_WIDTH = 200;
  7029. const SIDEBAR_RESIZING_CLASS = "sidebarResizing";
  7030. class PDFSidebarResizer {
  7031. constructor(options, eventBus, l10n) {
  7032. this.isRTL = false;
  7033. this.sidebarOpen = false;
  7034. this.doc = document.documentElement;
  7035. this._width = null;
  7036. this._outerContainerWidth = null;
  7037. this._boundEvents = Object.create(null);
  7038. this.outerContainer = options.outerContainer;
  7039. this.resizer = options.resizer;
  7040. this.eventBus = eventBus;
  7041. l10n.getDirection().then(dir => {
  7042. this.isRTL = dir === "rtl";
  7043. });
  7044. this._addEventListeners();
  7045. }
  7046. get outerContainerWidth() {
  7047. return this._outerContainerWidth || (this._outerContainerWidth = this.outerContainer.clientWidth);
  7048. }
  7049. _updateWidth(width = 0) {
  7050. const maxWidth = Math.floor(this.outerContainerWidth / 2);
  7051. if (width > maxWidth) {
  7052. width = maxWidth;
  7053. }
  7054. if (width < SIDEBAR_MIN_WIDTH) {
  7055. width = SIDEBAR_MIN_WIDTH;
  7056. }
  7057. if (width === this._width) {
  7058. return false;
  7059. }
  7060. this._width = width;
  7061. this.doc.style.setProperty(SIDEBAR_WIDTH_VAR, `${width}px`);
  7062. return true;
  7063. }
  7064. _mouseMove(evt) {
  7065. let width = evt.clientX;
  7066. if (this.isRTL) {
  7067. width = this.outerContainerWidth - width;
  7068. }
  7069. this._updateWidth(width);
  7070. }
  7071. _mouseUp(evt) {
  7072. this.outerContainer.classList.remove(SIDEBAR_RESIZING_CLASS);
  7073. this.eventBus.dispatch("resize", {
  7074. source: this
  7075. });
  7076. const _boundEvents = this._boundEvents;
  7077. window.removeEventListener("mousemove", _boundEvents.mouseMove);
  7078. window.removeEventListener("mouseup", _boundEvents.mouseUp);
  7079. }
  7080. _addEventListeners() {
  7081. const _boundEvents = this._boundEvents;
  7082. _boundEvents.mouseMove = this._mouseMove.bind(this);
  7083. _boundEvents.mouseUp = this._mouseUp.bind(this);
  7084. this.resizer.addEventListener("mousedown", evt => {
  7085. if (evt.button !== 0) {
  7086. return;
  7087. }
  7088. this.outerContainer.classList.add(SIDEBAR_RESIZING_CLASS);
  7089. window.addEventListener("mousemove", _boundEvents.mouseMove);
  7090. window.addEventListener("mouseup", _boundEvents.mouseUp);
  7091. });
  7092. this.eventBus._on("sidebarviewchanged", evt => {
  7093. this.sidebarOpen = !!evt?.view;
  7094. });
  7095. this.eventBus._on("resize", evt => {
  7096. if (evt?.source !== window) {
  7097. return;
  7098. }
  7099. this._outerContainerWidth = null;
  7100. if (!this._width) {
  7101. return;
  7102. }
  7103. if (!this.sidebarOpen) {
  7104. this._updateWidth(this._width);
  7105. return;
  7106. }
  7107. this.outerContainer.classList.add(SIDEBAR_RESIZING_CLASS);
  7108. const updated = this._updateWidth(this._width);
  7109. Promise.resolve().then(() => {
  7110. this.outerContainer.classList.remove(SIDEBAR_RESIZING_CLASS);
  7111. if (updated) {
  7112. this.eventBus.dispatch("resize", {
  7113. source: this
  7114. });
  7115. }
  7116. });
  7117. });
  7118. }
  7119. }
  7120. exports.PDFSidebarResizer = PDFSidebarResizer;
  7121. /***/ }),
  7122. /* 25 */
  7123. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7124. Object.defineProperty(exports, "__esModule", ({
  7125. value: true
  7126. }));
  7127. exports.PDFThumbnailViewer = void 0;
  7128. var _ui_utils = __webpack_require__(4);
  7129. var _pdf_thumbnail_view = __webpack_require__(26);
  7130. var _pdf_rendering_queue = __webpack_require__(8);
  7131. const THUMBNAIL_SCROLL_MARGIN = -19;
  7132. const THUMBNAIL_SELECTED_CLASS = "selected";
  7133. class PDFThumbnailViewer {
  7134. constructor({
  7135. container,
  7136. eventBus,
  7137. linkService,
  7138. renderingQueue,
  7139. l10n
  7140. }) {
  7141. this.container = container;
  7142. this.linkService = linkService;
  7143. this.renderingQueue = renderingQueue;
  7144. this.l10n = l10n;
  7145. this.scroll = (0, _ui_utils.watchScroll)(this.container, this._scrollUpdated.bind(this));
  7146. this._resetView();
  7147. eventBus._on("optionalcontentconfigchanged", () => {
  7148. this._setImageDisabled = true;
  7149. });
  7150. }
  7151. _scrollUpdated() {
  7152. this.renderingQueue.renderHighestPriority();
  7153. }
  7154. getThumbnail(index) {
  7155. return this._thumbnails[index];
  7156. }
  7157. _getVisibleThumbs() {
  7158. return (0, _ui_utils.getVisibleElements)({
  7159. scrollEl: this.container,
  7160. views: this._thumbnails
  7161. });
  7162. }
  7163. scrollThumbnailIntoView(pageNumber) {
  7164. if (!this.pdfDocument) {
  7165. return;
  7166. }
  7167. const thumbnailView = this._thumbnails[pageNumber - 1];
  7168. if (!thumbnailView) {
  7169. console.error('scrollThumbnailIntoView: Invalid "pageNumber" parameter.');
  7170. return;
  7171. }
  7172. if (pageNumber !== this._currentPageNumber) {
  7173. const prevThumbnailView = this._thumbnails[this._currentPageNumber - 1];
  7174. prevThumbnailView.div.classList.remove(THUMBNAIL_SELECTED_CLASS);
  7175. thumbnailView.div.classList.add(THUMBNAIL_SELECTED_CLASS);
  7176. }
  7177. const visibleThumbs = this._getVisibleThumbs();
  7178. const numVisibleThumbs = visibleThumbs.views.length;
  7179. if (numVisibleThumbs > 0) {
  7180. const first = visibleThumbs.first.id;
  7181. const last = numVisibleThumbs > 1 ? visibleThumbs.last.id : first;
  7182. let shouldScroll = false;
  7183. if (pageNumber <= first || pageNumber >= last) {
  7184. shouldScroll = true;
  7185. } else {
  7186. visibleThumbs.views.some(function (view) {
  7187. if (view.id !== pageNumber) {
  7188. return false;
  7189. }
  7190. shouldScroll = view.percent < 100;
  7191. return true;
  7192. });
  7193. }
  7194. if (shouldScroll) {
  7195. (0, _ui_utils.scrollIntoView)(thumbnailView.div, {
  7196. top: THUMBNAIL_SCROLL_MARGIN
  7197. });
  7198. }
  7199. }
  7200. this._currentPageNumber = pageNumber;
  7201. }
  7202. get pagesRotation() {
  7203. return this._pagesRotation;
  7204. }
  7205. set pagesRotation(rotation) {
  7206. if (!(0, _ui_utils.isValidRotation)(rotation)) {
  7207. throw new Error("Invalid thumbnails rotation angle.");
  7208. }
  7209. if (!this.pdfDocument) {
  7210. return;
  7211. }
  7212. if (this._pagesRotation === rotation) {
  7213. return;
  7214. }
  7215. this._pagesRotation = rotation;
  7216. for (let i = 0, ii = this._thumbnails.length; i < ii; i++) {
  7217. this._thumbnails[i].update(rotation);
  7218. }
  7219. }
  7220. cleanup() {
  7221. for (let i = 0, ii = this._thumbnails.length; i < ii; i++) {
  7222. if (this._thumbnails[i] && this._thumbnails[i].renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED) {
  7223. this._thumbnails[i].reset();
  7224. }
  7225. }
  7226. _pdf_thumbnail_view.TempImageFactory.destroyCanvas();
  7227. }
  7228. _resetView() {
  7229. this._thumbnails = [];
  7230. this._currentPageNumber = 1;
  7231. this._pageLabels = null;
  7232. this._pagesRotation = 0;
  7233. this._optionalContentConfigPromise = null;
  7234. this._pagesRequests = new WeakMap();
  7235. this._setImageDisabled = false;
  7236. this.container.textContent = "";
  7237. }
  7238. setDocument(pdfDocument) {
  7239. if (this.pdfDocument) {
  7240. this._cancelRendering();
  7241. this._resetView();
  7242. }
  7243. this.pdfDocument = pdfDocument;
  7244. if (!pdfDocument) {
  7245. return;
  7246. }
  7247. const firstPagePromise = pdfDocument.getPage(1);
  7248. const optionalContentConfigPromise = pdfDocument.getOptionalContentConfig();
  7249. firstPagePromise.then(firstPdfPage => {
  7250. this._optionalContentConfigPromise = optionalContentConfigPromise;
  7251. const pagesCount = pdfDocument.numPages;
  7252. const viewport = firstPdfPage.getViewport({
  7253. scale: 1
  7254. });
  7255. const checkSetImageDisabled = () => {
  7256. return this._setImageDisabled;
  7257. };
  7258. for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) {
  7259. const thumbnail = new _pdf_thumbnail_view.PDFThumbnailView({
  7260. container: this.container,
  7261. id: pageNum,
  7262. defaultViewport: viewport.clone(),
  7263. optionalContentConfigPromise,
  7264. linkService: this.linkService,
  7265. renderingQueue: this.renderingQueue,
  7266. checkSetImageDisabled,
  7267. l10n: this.l10n
  7268. });
  7269. this._thumbnails.push(thumbnail);
  7270. }
  7271. const firstThumbnailView = this._thumbnails[0];
  7272. if (firstThumbnailView) {
  7273. firstThumbnailView.setPdfPage(firstPdfPage);
  7274. }
  7275. const thumbnailView = this._thumbnails[this._currentPageNumber - 1];
  7276. thumbnailView.div.classList.add(THUMBNAIL_SELECTED_CLASS);
  7277. }).catch(reason => {
  7278. console.error("Unable to initialize thumbnail viewer", reason);
  7279. });
  7280. }
  7281. _cancelRendering() {
  7282. for (let i = 0, ii = this._thumbnails.length; i < ii; i++) {
  7283. if (this._thumbnails[i]) {
  7284. this._thumbnails[i].cancelRendering();
  7285. }
  7286. }
  7287. }
  7288. setPageLabels(labels) {
  7289. if (!this.pdfDocument) {
  7290. return;
  7291. }
  7292. if (!labels) {
  7293. this._pageLabels = null;
  7294. } else if (!(Array.isArray(labels) && this.pdfDocument.numPages === labels.length)) {
  7295. this._pageLabels = null;
  7296. console.error("PDFThumbnailViewer_setPageLabels: Invalid page labels.");
  7297. } else {
  7298. this._pageLabels = labels;
  7299. }
  7300. for (let i = 0, ii = this._thumbnails.length; i < ii; i++) {
  7301. this._thumbnails[i].setPageLabel(this._pageLabels?.[i] ?? null);
  7302. }
  7303. }
  7304. _ensurePdfPageLoaded(thumbView) {
  7305. if (thumbView.pdfPage) {
  7306. return Promise.resolve(thumbView.pdfPage);
  7307. }
  7308. if (this._pagesRequests.has(thumbView)) {
  7309. return this._pagesRequests.get(thumbView);
  7310. }
  7311. const promise = this.pdfDocument.getPage(thumbView.id).then(pdfPage => {
  7312. if (!thumbView.pdfPage) {
  7313. thumbView.setPdfPage(pdfPage);
  7314. }
  7315. this._pagesRequests.delete(thumbView);
  7316. return pdfPage;
  7317. }).catch(reason => {
  7318. console.error("Unable to get page for thumb view", reason);
  7319. this._pagesRequests.delete(thumbView);
  7320. });
  7321. this._pagesRequests.set(thumbView, promise);
  7322. return promise;
  7323. }
  7324. forceRendering() {
  7325. const visibleThumbs = this._getVisibleThumbs();
  7326. const thumbView = this.renderingQueue.getHighestPriority(visibleThumbs, this._thumbnails, this.scroll.down);
  7327. if (thumbView) {
  7328. this._ensurePdfPageLoaded(thumbView).then(() => {
  7329. this.renderingQueue.renderView(thumbView);
  7330. });
  7331. return true;
  7332. }
  7333. return false;
  7334. }
  7335. }
  7336. exports.PDFThumbnailViewer = PDFThumbnailViewer;
  7337. /***/ }),
  7338. /* 26 */
  7339. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7340. Object.defineProperty(exports, "__esModule", ({
  7341. value: true
  7342. }));
  7343. exports.TempImageFactory = exports.PDFThumbnailView = void 0;
  7344. var _ui_utils = __webpack_require__(4);
  7345. var _pdfjsLib = __webpack_require__(5);
  7346. var _pdf_rendering_queue = __webpack_require__(8);
  7347. const DRAW_UPSCALE_FACTOR = 2;
  7348. const MAX_NUM_SCALING_STEPS = 3;
  7349. const THUMBNAIL_CANVAS_BORDER_WIDTH = 1;
  7350. const THUMBNAIL_WIDTH = 98;
  7351. const TempImageFactory = function TempImageFactoryClosure() {
  7352. let tempCanvasCache = null;
  7353. return {
  7354. getCanvas(width, height) {
  7355. let tempCanvas = tempCanvasCache;
  7356. if (!tempCanvas) {
  7357. tempCanvas = document.createElement("canvas");
  7358. tempCanvasCache = tempCanvas;
  7359. }
  7360. tempCanvas.width = width;
  7361. tempCanvas.height = height;
  7362. tempCanvas.mozOpaque = true;
  7363. const ctx = tempCanvas.getContext("2d", {
  7364. alpha: false
  7365. });
  7366. ctx.save();
  7367. ctx.fillStyle = "rgb(255, 255, 255)";
  7368. ctx.fillRect(0, 0, width, height);
  7369. ctx.restore();
  7370. return [tempCanvas, tempCanvas.getContext("2d")];
  7371. },
  7372. destroyCanvas() {
  7373. const tempCanvas = tempCanvasCache;
  7374. if (tempCanvas) {
  7375. tempCanvas.width = 0;
  7376. tempCanvas.height = 0;
  7377. }
  7378. tempCanvasCache = null;
  7379. }
  7380. };
  7381. }();
  7382. exports.TempImageFactory = TempImageFactory;
  7383. class PDFThumbnailView {
  7384. constructor({
  7385. container,
  7386. id,
  7387. defaultViewport,
  7388. optionalContentConfigPromise,
  7389. linkService,
  7390. renderingQueue,
  7391. checkSetImageDisabled,
  7392. l10n
  7393. }) {
  7394. this.id = id;
  7395. this.renderingId = "thumbnail" + id;
  7396. this.pageLabel = null;
  7397. this.pdfPage = null;
  7398. this.rotation = 0;
  7399. this.viewport = defaultViewport;
  7400. this.pdfPageRotate = defaultViewport.rotation;
  7401. this._optionalContentConfigPromise = optionalContentConfigPromise || null;
  7402. this.linkService = linkService;
  7403. this.renderingQueue = renderingQueue;
  7404. this.renderTask = null;
  7405. this.renderingState = _pdf_rendering_queue.RenderingStates.INITIAL;
  7406. this.resume = null;
  7407. this._checkSetImageDisabled = checkSetImageDisabled || function () {
  7408. return false;
  7409. };
  7410. const pageWidth = this.viewport.width,
  7411. pageHeight = this.viewport.height,
  7412. pageRatio = pageWidth / pageHeight;
  7413. this.canvasWidth = THUMBNAIL_WIDTH;
  7414. this.canvasHeight = this.canvasWidth / pageRatio | 0;
  7415. this.scale = this.canvasWidth / pageWidth;
  7416. this.l10n = l10n;
  7417. const anchor = document.createElement("a");
  7418. anchor.href = linkService.getAnchorUrl("#page=" + id);
  7419. this._thumbPageTitle.then(msg => {
  7420. anchor.title = msg;
  7421. });
  7422. anchor.onclick = function () {
  7423. linkService.goToPage(id);
  7424. return false;
  7425. };
  7426. this.anchor = anchor;
  7427. const div = document.createElement("div");
  7428. div.className = "thumbnail";
  7429. div.setAttribute("data-page-number", this.id);
  7430. this.div = div;
  7431. const ring = document.createElement("div");
  7432. ring.className = "thumbnailSelectionRing";
  7433. const borderAdjustment = 2 * THUMBNAIL_CANVAS_BORDER_WIDTH;
  7434. ring.style.width = this.canvasWidth + borderAdjustment + "px";
  7435. ring.style.height = this.canvasHeight + borderAdjustment + "px";
  7436. this.ring = ring;
  7437. div.appendChild(ring);
  7438. anchor.appendChild(div);
  7439. container.appendChild(anchor);
  7440. }
  7441. setPdfPage(pdfPage) {
  7442. this.pdfPage = pdfPage;
  7443. this.pdfPageRotate = pdfPage.rotate;
  7444. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  7445. this.viewport = pdfPage.getViewport({
  7446. scale: 1,
  7447. rotation: totalRotation
  7448. });
  7449. this.reset();
  7450. }
  7451. reset() {
  7452. this.cancelRendering();
  7453. this.renderingState = _pdf_rendering_queue.RenderingStates.INITIAL;
  7454. const pageWidth = this.viewport.width,
  7455. pageHeight = this.viewport.height,
  7456. pageRatio = pageWidth / pageHeight;
  7457. this.canvasHeight = this.canvasWidth / pageRatio | 0;
  7458. this.scale = this.canvasWidth / pageWidth;
  7459. this.div.removeAttribute("data-loaded");
  7460. const ring = this.ring;
  7461. ring.textContent = "";
  7462. const borderAdjustment = 2 * THUMBNAIL_CANVAS_BORDER_WIDTH;
  7463. ring.style.width = this.canvasWidth + borderAdjustment + "px";
  7464. ring.style.height = this.canvasHeight + borderAdjustment + "px";
  7465. if (this.canvas) {
  7466. this.canvas.width = 0;
  7467. this.canvas.height = 0;
  7468. delete this.canvas;
  7469. }
  7470. if (this.image) {
  7471. this.image.removeAttribute("src");
  7472. delete this.image;
  7473. }
  7474. }
  7475. update(rotation) {
  7476. if (typeof rotation !== "undefined") {
  7477. this.rotation = rotation;
  7478. }
  7479. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  7480. this.viewport = this.viewport.clone({
  7481. scale: 1,
  7482. rotation: totalRotation
  7483. });
  7484. this.reset();
  7485. }
  7486. cancelRendering() {
  7487. if (this.renderTask) {
  7488. this.renderTask.cancel();
  7489. this.renderTask = null;
  7490. }
  7491. this.resume = null;
  7492. }
  7493. _getPageDrawContext(upscaleFactor = 1) {
  7494. const canvas = document.createElement("canvas");
  7495. canvas.mozOpaque = true;
  7496. const ctx = canvas.getContext("2d", {
  7497. alpha: false
  7498. });
  7499. const outputScale = (0, _ui_utils.getOutputScale)(ctx);
  7500. canvas.width = upscaleFactor * this.canvasWidth * outputScale.sx | 0;
  7501. canvas.height = upscaleFactor * this.canvasHeight * outputScale.sy | 0;
  7502. const transform = outputScale.scaled ? [outputScale.sx, 0, 0, outputScale.sy, 0, 0] : null;
  7503. return {
  7504. ctx,
  7505. canvas,
  7506. transform
  7507. };
  7508. }
  7509. _convertCanvasToImage(canvas) {
  7510. if (this.renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED) {
  7511. throw new Error("_convertCanvasToImage: Rendering has not finished.");
  7512. }
  7513. const reducedCanvas = this._reduceImage(canvas);
  7514. const image = document.createElement("img");
  7515. image.className = "thumbnailImage";
  7516. this._thumbPageCanvas.then(msg => {
  7517. image.setAttribute("aria-label", msg);
  7518. });
  7519. image.style.width = this.canvasWidth + "px";
  7520. image.style.height = this.canvasHeight + "px";
  7521. image.src = reducedCanvas.toDataURL();
  7522. this.image = image;
  7523. this.div.setAttribute("data-loaded", true);
  7524. this.ring.appendChild(image);
  7525. reducedCanvas.width = 0;
  7526. reducedCanvas.height = 0;
  7527. }
  7528. draw() {
  7529. if (this.renderingState !== _pdf_rendering_queue.RenderingStates.INITIAL) {
  7530. console.error("Must be in new state before drawing");
  7531. return Promise.resolve(undefined);
  7532. }
  7533. const {
  7534. pdfPage
  7535. } = this;
  7536. if (!pdfPage) {
  7537. this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
  7538. return Promise.reject(new Error("pdfPage is not loaded"));
  7539. }
  7540. this.renderingState = _pdf_rendering_queue.RenderingStates.RUNNING;
  7541. const finishRenderTask = async (error = null) => {
  7542. if (renderTask === this.renderTask) {
  7543. this.renderTask = null;
  7544. }
  7545. if (error instanceof _pdfjsLib.RenderingCancelledException) {
  7546. return;
  7547. }
  7548. this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
  7549. this._convertCanvasToImage(canvas);
  7550. if (error) {
  7551. throw error;
  7552. }
  7553. };
  7554. const {
  7555. ctx,
  7556. canvas,
  7557. transform
  7558. } = this._getPageDrawContext(DRAW_UPSCALE_FACTOR);
  7559. const drawViewport = this.viewport.clone({
  7560. scale: DRAW_UPSCALE_FACTOR * this.scale
  7561. });
  7562. const renderContinueCallback = cont => {
  7563. if (!this.renderingQueue.isHighestPriority(this)) {
  7564. this.renderingState = _pdf_rendering_queue.RenderingStates.PAUSED;
  7565. this.resume = () => {
  7566. this.renderingState = _pdf_rendering_queue.RenderingStates.RUNNING;
  7567. cont();
  7568. };
  7569. return;
  7570. }
  7571. cont();
  7572. };
  7573. const renderContext = {
  7574. canvasContext: ctx,
  7575. transform,
  7576. viewport: drawViewport,
  7577. optionalContentConfigPromise: this._optionalContentConfigPromise
  7578. };
  7579. const renderTask = this.renderTask = pdfPage.render(renderContext);
  7580. renderTask.onContinue = renderContinueCallback;
  7581. const resultPromise = renderTask.promise.then(function () {
  7582. return finishRenderTask(null);
  7583. }, function (error) {
  7584. return finishRenderTask(error);
  7585. });
  7586. resultPromise.finally(() => {
  7587. canvas.width = 0;
  7588. canvas.height = 0;
  7589. const pageCached = this.linkService.isPageCached(this.id);
  7590. if (!pageCached) {
  7591. this.pdfPage?.cleanup();
  7592. }
  7593. });
  7594. return resultPromise;
  7595. }
  7596. setImage(pageView) {
  7597. if (this._checkSetImageDisabled()) {
  7598. return;
  7599. }
  7600. if (this.renderingState !== _pdf_rendering_queue.RenderingStates.INITIAL) {
  7601. return;
  7602. }
  7603. const {
  7604. canvas,
  7605. pdfPage
  7606. } = pageView;
  7607. if (!canvas) {
  7608. return;
  7609. }
  7610. if (!this.pdfPage) {
  7611. this.setPdfPage(pdfPage);
  7612. }
  7613. this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
  7614. this._convertCanvasToImage(canvas);
  7615. }
  7616. _reduceImage(img) {
  7617. const {
  7618. ctx,
  7619. canvas
  7620. } = this._getPageDrawContext();
  7621. if (img.width <= 2 * canvas.width) {
  7622. ctx.drawImage(img, 0, 0, img.width, img.height, 0, 0, canvas.width, canvas.height);
  7623. return canvas;
  7624. }
  7625. let reducedWidth = canvas.width << MAX_NUM_SCALING_STEPS;
  7626. let reducedHeight = canvas.height << MAX_NUM_SCALING_STEPS;
  7627. const [reducedImage, reducedImageCtx] = TempImageFactory.getCanvas(reducedWidth, reducedHeight);
  7628. while (reducedWidth > img.width || reducedHeight > img.height) {
  7629. reducedWidth >>= 1;
  7630. reducedHeight >>= 1;
  7631. }
  7632. reducedImageCtx.drawImage(img, 0, 0, img.width, img.height, 0, 0, reducedWidth, reducedHeight);
  7633. while (reducedWidth > 2 * canvas.width) {
  7634. reducedImageCtx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, reducedWidth >> 1, reducedHeight >> 1);
  7635. reducedWidth >>= 1;
  7636. reducedHeight >>= 1;
  7637. }
  7638. ctx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, canvas.width, canvas.height);
  7639. return canvas;
  7640. }
  7641. get _thumbPageTitle() {
  7642. return this.l10n.get("thumb_page_title", {
  7643. page: this.pageLabel ?? this.id
  7644. });
  7645. }
  7646. get _thumbPageCanvas() {
  7647. return this.l10n.get("thumb_page_canvas", {
  7648. page: this.pageLabel ?? this.id
  7649. });
  7650. }
  7651. setPageLabel(label) {
  7652. this.pageLabel = typeof label === "string" ? label : null;
  7653. this._thumbPageTitle.then(msg => {
  7654. this.anchor.title = msg;
  7655. });
  7656. if (this.renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED) {
  7657. return;
  7658. }
  7659. this._thumbPageCanvas.then(msg => {
  7660. this.image?.setAttribute("aria-label", msg);
  7661. });
  7662. }
  7663. }
  7664. exports.PDFThumbnailView = PDFThumbnailView;
  7665. /***/ }),
  7666. /* 27 */
  7667. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7668. Object.defineProperty(exports, "__esModule", ({
  7669. value: true
  7670. }));
  7671. exports.PDFViewer = void 0;
  7672. var _ui_utils = __webpack_require__(4);
  7673. var _base_viewer = __webpack_require__(28);
  7674. var _pdfjsLib = __webpack_require__(5);
  7675. class PDFViewer extends _base_viewer.BaseViewer {
  7676. get _viewerElement() {
  7677. return (0, _pdfjsLib.shadow)(this, "_viewerElement", this.viewer);
  7678. }
  7679. _scrollIntoView({
  7680. pageDiv,
  7681. pageSpot = null,
  7682. pageNumber = null
  7683. }) {
  7684. if (!pageSpot && !this.isInPresentationMode) {
  7685. const left = pageDiv.offsetLeft + pageDiv.clientLeft;
  7686. const right = left + pageDiv.clientWidth;
  7687. const {
  7688. scrollLeft,
  7689. clientWidth
  7690. } = this.container;
  7691. if (this._isScrollModeHorizontal || left < scrollLeft || right > scrollLeft + clientWidth) {
  7692. pageSpot = {
  7693. left: 0,
  7694. top: 0
  7695. };
  7696. }
  7697. }
  7698. super._scrollIntoView({
  7699. pageDiv,
  7700. pageSpot,
  7701. pageNumber
  7702. });
  7703. }
  7704. _getVisiblePages() {
  7705. if (this.isInPresentationMode) {
  7706. return this._getCurrentVisiblePage();
  7707. }
  7708. return super._getVisiblePages();
  7709. }
  7710. _updateHelper(visiblePages) {
  7711. if (this.isInPresentationMode) {
  7712. return;
  7713. }
  7714. let currentId = this._currentPageNumber;
  7715. let stillFullyVisible = false;
  7716. for (const page of visiblePages) {
  7717. if (page.percent < 100) {
  7718. break;
  7719. }
  7720. if (page.id === currentId && this._scrollMode === _ui_utils.ScrollMode.VERTICAL && this._spreadMode === _ui_utils.SpreadMode.NONE) {
  7721. stillFullyVisible = true;
  7722. break;
  7723. }
  7724. }
  7725. if (!stillFullyVisible) {
  7726. currentId = visiblePages[0].id;
  7727. }
  7728. this._setCurrentPageNumber(currentId);
  7729. }
  7730. }
  7731. exports.PDFViewer = PDFViewer;
  7732. /***/ }),
  7733. /* 28 */
  7734. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7735. Object.defineProperty(exports, "__esModule", ({
  7736. value: true
  7737. }));
  7738. exports.BaseViewer = void 0;
  7739. var _pdfjsLib = __webpack_require__(5);
  7740. var _ui_utils = __webpack_require__(4);
  7741. var _pdf_rendering_queue = __webpack_require__(8);
  7742. var _annotation_layer_builder = __webpack_require__(29);
  7743. var _l10n_utils = __webpack_require__(30);
  7744. var _pdf_page_view = __webpack_require__(31);
  7745. var _pdf_link_service = __webpack_require__(19);
  7746. var _struct_tree_layer_builder = __webpack_require__(32);
  7747. var _text_layer_builder = __webpack_require__(33);
  7748. var _xfa_layer_builder = __webpack_require__(34);
  7749. const DEFAULT_CACHE_SIZE = 10;
  7750. function PDFPageViewBuffer(size) {
  7751. const data = [];
  7752. this.push = function (view) {
  7753. const i = data.indexOf(view);
  7754. if (i >= 0) {
  7755. data.splice(i, 1);
  7756. }
  7757. data.push(view);
  7758. if (data.length > size) {
  7759. data.shift().destroy();
  7760. }
  7761. };
  7762. this.resize = function (newSize, pagesToKeep) {
  7763. size = newSize;
  7764. if (pagesToKeep) {
  7765. const pageIdsToKeep = new Set();
  7766. for (let i = 0, iMax = pagesToKeep.length; i < iMax; ++i) {
  7767. pageIdsToKeep.add(pagesToKeep[i].id);
  7768. }
  7769. (0, _ui_utils.moveToEndOfArray)(data, function (page) {
  7770. return pageIdsToKeep.has(page.id);
  7771. });
  7772. }
  7773. while (data.length > size) {
  7774. data.shift().destroy();
  7775. }
  7776. };
  7777. this.has = function (view) {
  7778. return data.includes(view);
  7779. };
  7780. }
  7781. function isSameScale(oldScale, newScale) {
  7782. if (newScale === oldScale) {
  7783. return true;
  7784. }
  7785. if (Math.abs(newScale - oldScale) < 1e-15) {
  7786. return true;
  7787. }
  7788. return false;
  7789. }
  7790. class BaseViewer {
  7791. constructor(options) {
  7792. if (this.constructor === BaseViewer) {
  7793. throw new Error("Cannot initialize BaseViewer.");
  7794. }
  7795. const viewerVersion = '2.10.377';
  7796. if (_pdfjsLib.version !== viewerVersion) {
  7797. throw new Error(`The API version "${_pdfjsLib.version}" does not match the Viewer version "${viewerVersion}".`);
  7798. }
  7799. this._name = this.constructor.name;
  7800. this.container = options.container;
  7801. this.viewer = options.viewer || options.container.firstElementChild;
  7802. if (!(this.container?.tagName.toUpperCase() === "DIV" && this.viewer?.tagName.toUpperCase() === "DIV")) {
  7803. throw new Error("Invalid `container` and/or `viewer` option.");
  7804. }
  7805. if (this.container.offsetParent && getComputedStyle(this.container).position !== "absolute") {
  7806. throw new Error("The `container` must be absolutely positioned.");
  7807. }
  7808. this.eventBus = options.eventBus;
  7809. this.linkService = options.linkService || new _pdf_link_service.SimpleLinkService();
  7810. this.downloadManager = options.downloadManager || null;
  7811. this.findController = options.findController || null;
  7812. this._scriptingManager = options.scriptingManager || null;
  7813. this.removePageBorders = options.removePageBorders || false;
  7814. this.textLayerMode = Number.isInteger(options.textLayerMode) ? options.textLayerMode : _ui_utils.TextLayerMode.ENABLE;
  7815. this.imageResourcesPath = options.imageResourcesPath || "";
  7816. this.renderInteractiveForms = options.renderInteractiveForms !== false;
  7817. this.enablePrintAutoRotate = options.enablePrintAutoRotate || false;
  7818. this.renderer = options.renderer || _ui_utils.RendererType.CANVAS;
  7819. this.useOnlyCssZoom = options.useOnlyCssZoom || false;
  7820. this.maxCanvasPixels = options.maxCanvasPixels;
  7821. this.l10n = options.l10n || _l10n_utils.NullL10n;
  7822. this.enableScripting = options.enableScripting === true && !!this._scriptingManager;
  7823. this.defaultRenderingQueue = !options.renderingQueue;
  7824. if (this.defaultRenderingQueue) {
  7825. this.renderingQueue = new _pdf_rendering_queue.PDFRenderingQueue();
  7826. this.renderingQueue.setViewer(this);
  7827. } else {
  7828. this.renderingQueue = options.renderingQueue;
  7829. }
  7830. this.scroll = (0, _ui_utils.watchScroll)(this.container, this._scrollUpdate.bind(this));
  7831. this.presentationModeState = _ui_utils.PresentationModeState.UNKNOWN;
  7832. this._onBeforeDraw = this._onAfterDraw = null;
  7833. this._resetView();
  7834. if (this.removePageBorders) {
  7835. this.viewer.classList.add("removePageBorders");
  7836. }
  7837. Promise.resolve().then(() => {
  7838. this.eventBus.dispatch("baseviewerinit", {
  7839. source: this
  7840. });
  7841. });
  7842. }
  7843. get pagesCount() {
  7844. return this._pages.length;
  7845. }
  7846. getPageView(index) {
  7847. return this._pages[index];
  7848. }
  7849. get pageViewsReady() {
  7850. if (!this._pagesCapability.settled) {
  7851. return false;
  7852. }
  7853. return this._pages.every(function (pageView) {
  7854. return pageView?.pdfPage;
  7855. });
  7856. }
  7857. get currentPageNumber() {
  7858. return this._currentPageNumber;
  7859. }
  7860. set currentPageNumber(val) {
  7861. if (!Number.isInteger(val)) {
  7862. throw new Error("Invalid page number.");
  7863. }
  7864. if (!this.pdfDocument) {
  7865. return;
  7866. }
  7867. if (!this._setCurrentPageNumber(val, true)) {
  7868. console.error(`${this._name}.currentPageNumber: "${val}" is not a valid page.`);
  7869. }
  7870. }
  7871. _setCurrentPageNumber(val, resetCurrentPageView = false) {
  7872. if (this._currentPageNumber === val) {
  7873. if (resetCurrentPageView) {
  7874. this._resetCurrentPageView();
  7875. }
  7876. return true;
  7877. }
  7878. if (!(0 < val && val <= this.pagesCount)) {
  7879. return false;
  7880. }
  7881. const previous = this._currentPageNumber;
  7882. this._currentPageNumber = val;
  7883. this.eventBus.dispatch("pagechanging", {
  7884. source: this,
  7885. pageNumber: val,
  7886. pageLabel: this._pageLabels?.[val - 1] ?? null,
  7887. previous
  7888. });
  7889. if (resetCurrentPageView) {
  7890. this._resetCurrentPageView();
  7891. }
  7892. return true;
  7893. }
  7894. get currentPageLabel() {
  7895. return this._pageLabels?.[this._currentPageNumber - 1] ?? null;
  7896. }
  7897. set currentPageLabel(val) {
  7898. if (!this.pdfDocument) {
  7899. return;
  7900. }
  7901. let page = val | 0;
  7902. if (this._pageLabels) {
  7903. const i = this._pageLabels.indexOf(val);
  7904. if (i >= 0) {
  7905. page = i + 1;
  7906. }
  7907. }
  7908. if (!this._setCurrentPageNumber(page, true)) {
  7909. console.error(`${this._name}.currentPageLabel: "${val}" is not a valid page.`);
  7910. }
  7911. }
  7912. get currentScale() {
  7913. return this._currentScale !== _ui_utils.UNKNOWN_SCALE ? this._currentScale : _ui_utils.DEFAULT_SCALE;
  7914. }
  7915. set currentScale(val) {
  7916. if (isNaN(val)) {
  7917. throw new Error("Invalid numeric scale.");
  7918. }
  7919. if (!this.pdfDocument) {
  7920. return;
  7921. }
  7922. this._setScale(val, false);
  7923. }
  7924. get currentScaleValue() {
  7925. return this._currentScaleValue;
  7926. }
  7927. set currentScaleValue(val) {
  7928. if (!this.pdfDocument) {
  7929. return;
  7930. }
  7931. this._setScale(val, false);
  7932. }
  7933. get pagesRotation() {
  7934. return this._pagesRotation;
  7935. }
  7936. set pagesRotation(rotation) {
  7937. if (!(0, _ui_utils.isValidRotation)(rotation)) {
  7938. throw new Error("Invalid pages rotation angle.");
  7939. }
  7940. if (!this.pdfDocument) {
  7941. return;
  7942. }
  7943. rotation %= 360;
  7944. if (rotation < 0) {
  7945. rotation += 360;
  7946. }
  7947. if (this._pagesRotation === rotation) {
  7948. return;
  7949. }
  7950. this._pagesRotation = rotation;
  7951. const pageNumber = this._currentPageNumber;
  7952. for (let i = 0, ii = this._pages.length; i < ii; i++) {
  7953. const pageView = this._pages[i];
  7954. pageView.update(pageView.scale, rotation);
  7955. }
  7956. if (this._currentScaleValue) {
  7957. this._setScale(this._currentScaleValue, true);
  7958. }
  7959. this.eventBus.dispatch("rotationchanging", {
  7960. source: this,
  7961. pagesRotation: rotation,
  7962. pageNumber
  7963. });
  7964. if (this.defaultRenderingQueue) {
  7965. this.update();
  7966. }
  7967. }
  7968. get firstPagePromise() {
  7969. return this.pdfDocument ? this._firstPageCapability.promise : null;
  7970. }
  7971. get onePageRendered() {
  7972. return this.pdfDocument ? this._onePageRenderedCapability.promise : null;
  7973. }
  7974. get pagesPromise() {
  7975. return this.pdfDocument ? this._pagesCapability.promise : null;
  7976. }
  7977. get _viewerElement() {
  7978. throw new Error("Not implemented: _viewerElement");
  7979. }
  7980. _onePageRenderedOrForceFetch() {
  7981. if (!this.container.offsetParent || this._getVisiblePages().views.length === 0) {
  7982. return Promise.resolve();
  7983. }
  7984. return this._onePageRenderedCapability.promise;
  7985. }
  7986. setDocument(pdfDocument) {
  7987. if (this.pdfDocument) {
  7988. this.eventBus.dispatch("pagesdestroy", {
  7989. source: this
  7990. });
  7991. this._cancelRendering();
  7992. this._resetView();
  7993. if (this.findController) {
  7994. this.findController.setDocument(null);
  7995. }
  7996. if (this._scriptingManager) {
  7997. this._scriptingManager.setDocument(null);
  7998. }
  7999. }
  8000. this.pdfDocument = pdfDocument;
  8001. if (!pdfDocument) {
  8002. return;
  8003. }
  8004. const isPureXfa = pdfDocument.isPureXfa;
  8005. const pagesCount = pdfDocument.numPages;
  8006. const firstPagePromise = pdfDocument.getPage(1);
  8007. const optionalContentConfigPromise = pdfDocument.getOptionalContentConfig();
  8008. this._pagesCapability.promise.then(() => {
  8009. this.eventBus.dispatch("pagesloaded", {
  8010. source: this,
  8011. pagesCount
  8012. });
  8013. });
  8014. this._onBeforeDraw = evt => {
  8015. const pageView = this._pages[evt.pageNumber - 1];
  8016. if (!pageView) {
  8017. return;
  8018. }
  8019. this._buffer.push(pageView);
  8020. };
  8021. this.eventBus._on("pagerender", this._onBeforeDraw);
  8022. this._onAfterDraw = evt => {
  8023. if (evt.cssTransform || this._onePageRenderedCapability.settled) {
  8024. return;
  8025. }
  8026. this._onePageRenderedCapability.resolve();
  8027. this.eventBus._off("pagerendered", this._onAfterDraw);
  8028. this._onAfterDraw = null;
  8029. };
  8030. this.eventBus._on("pagerendered", this._onAfterDraw);
  8031. firstPagePromise.then(firstPdfPage => {
  8032. this._firstPageCapability.resolve(firstPdfPage);
  8033. this._optionalContentConfigPromise = optionalContentConfigPromise;
  8034. const scale = this.currentScale;
  8035. const viewport = firstPdfPage.getViewport({
  8036. scale: scale * _ui_utils.CSS_UNITS
  8037. });
  8038. const textLayerFactory = this.textLayerMode !== _ui_utils.TextLayerMode.DISABLE ? this : null;
  8039. const xfaLayerFactory = isPureXfa ? this : null;
  8040. for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) {
  8041. const pageView = new _pdf_page_view.PDFPageView({
  8042. container: this._viewerElement,
  8043. eventBus: this.eventBus,
  8044. id: pageNum,
  8045. scale,
  8046. defaultViewport: viewport.clone(),
  8047. optionalContentConfigPromise,
  8048. renderingQueue: this.renderingQueue,
  8049. textLayerFactory,
  8050. textLayerMode: this.textLayerMode,
  8051. annotationLayerFactory: this,
  8052. xfaLayerFactory,
  8053. structTreeLayerFactory: this,
  8054. imageResourcesPath: this.imageResourcesPath,
  8055. renderInteractiveForms: this.renderInteractiveForms,
  8056. renderer: this.renderer,
  8057. useOnlyCssZoom: this.useOnlyCssZoom,
  8058. maxCanvasPixels: this.maxCanvasPixels,
  8059. l10n: this.l10n
  8060. });
  8061. this._pages.push(pageView);
  8062. }
  8063. const firstPageView = this._pages[0];
  8064. if (firstPageView) {
  8065. firstPageView.setPdfPage(firstPdfPage);
  8066. this.linkService.cachePageRef(1, firstPdfPage.ref);
  8067. }
  8068. if (this._spreadMode !== _ui_utils.SpreadMode.NONE) {
  8069. this._updateSpreadMode();
  8070. }
  8071. this._onePageRenderedOrForceFetch().then(() => {
  8072. if (this.findController) {
  8073. this.findController.setDocument(pdfDocument);
  8074. }
  8075. if (this.enableScripting) {
  8076. this._scriptingManager.setDocument(pdfDocument);
  8077. }
  8078. if (pdfDocument.loadingParams.disableAutoFetch || pagesCount > 7500) {
  8079. this._pagesCapability.resolve();
  8080. return;
  8081. }
  8082. let getPagesLeft = pagesCount - 1;
  8083. if (getPagesLeft <= 0) {
  8084. this._pagesCapability.resolve();
  8085. return;
  8086. }
  8087. for (let pageNum = 2; pageNum <= pagesCount; ++pageNum) {
  8088. pdfDocument.getPage(pageNum).then(pdfPage => {
  8089. const pageView = this._pages[pageNum - 1];
  8090. if (!pageView.pdfPage) {
  8091. pageView.setPdfPage(pdfPage);
  8092. }
  8093. this.linkService.cachePageRef(pageNum, pdfPage.ref);
  8094. if (--getPagesLeft === 0) {
  8095. this._pagesCapability.resolve();
  8096. }
  8097. }, reason => {
  8098. console.error(`Unable to get page ${pageNum} to initialize viewer`, reason);
  8099. if (--getPagesLeft === 0) {
  8100. this._pagesCapability.resolve();
  8101. }
  8102. });
  8103. }
  8104. });
  8105. this.eventBus.dispatch("pagesinit", {
  8106. source: this
  8107. });
  8108. if (this.defaultRenderingQueue) {
  8109. this.update();
  8110. }
  8111. }).catch(reason => {
  8112. console.error("Unable to initialize viewer", reason);
  8113. });
  8114. }
  8115. setPageLabels(labels) {
  8116. if (!this.pdfDocument) {
  8117. return;
  8118. }
  8119. if (!labels) {
  8120. this._pageLabels = null;
  8121. } else if (!(Array.isArray(labels) && this.pdfDocument.numPages === labels.length)) {
  8122. this._pageLabels = null;
  8123. console.error(`${this._name}.setPageLabels: Invalid page labels.`);
  8124. } else {
  8125. this._pageLabels = labels;
  8126. }
  8127. for (let i = 0, ii = this._pages.length; i < ii; i++) {
  8128. this._pages[i].setPageLabel(this._pageLabels?.[i] ?? null);
  8129. }
  8130. }
  8131. _resetView() {
  8132. this._pages = [];
  8133. this._currentPageNumber = 1;
  8134. this._currentScale = _ui_utils.UNKNOWN_SCALE;
  8135. this._currentScaleValue = null;
  8136. this._pageLabels = null;
  8137. this._buffer = new PDFPageViewBuffer(DEFAULT_CACHE_SIZE);
  8138. this._location = null;
  8139. this._pagesRotation = 0;
  8140. this._optionalContentConfigPromise = null;
  8141. this._pagesRequests = new WeakMap();
  8142. this._firstPageCapability = (0, _pdfjsLib.createPromiseCapability)();
  8143. this._onePageRenderedCapability = (0, _pdfjsLib.createPromiseCapability)();
  8144. this._pagesCapability = (0, _pdfjsLib.createPromiseCapability)();
  8145. this._scrollMode = _ui_utils.ScrollMode.VERTICAL;
  8146. this._spreadMode = _ui_utils.SpreadMode.NONE;
  8147. if (this._onBeforeDraw) {
  8148. this.eventBus._off("pagerender", this._onBeforeDraw);
  8149. this._onBeforeDraw = null;
  8150. }
  8151. if (this._onAfterDraw) {
  8152. this.eventBus._off("pagerendered", this._onAfterDraw);
  8153. this._onAfterDraw = null;
  8154. }
  8155. this.viewer.textContent = "";
  8156. this._updateScrollMode();
  8157. }
  8158. _scrollUpdate() {
  8159. if (this.pagesCount === 0) {
  8160. return;
  8161. }
  8162. this.update();
  8163. }
  8164. _scrollIntoView({
  8165. pageDiv,
  8166. pageSpot = null,
  8167. pageNumber = null
  8168. }) {
  8169. (0, _ui_utils.scrollIntoView)(pageDiv, pageSpot);
  8170. }
  8171. _setScaleUpdatePages(newScale, newValue, noScroll = false, preset = false) {
  8172. this._currentScaleValue = newValue.toString();
  8173. if (isSameScale(this._currentScale, newScale)) {
  8174. if (preset) {
  8175. this.eventBus.dispatch("scalechanging", {
  8176. source: this,
  8177. scale: newScale,
  8178. presetValue: newValue
  8179. });
  8180. }
  8181. return;
  8182. }
  8183. for (let i = 0, ii = this._pages.length; i < ii; i++) {
  8184. this._pages[i].update(newScale);
  8185. }
  8186. this._currentScale = newScale;
  8187. if (!noScroll) {
  8188. let page = this._currentPageNumber,
  8189. dest;
  8190. if (this._location && !(this.isInPresentationMode || this.isChangingPresentationMode)) {
  8191. page = this._location.pageNumber;
  8192. dest = [null, {
  8193. name: "XYZ"
  8194. }, this._location.left, this._location.top, null];
  8195. }
  8196. this.scrollPageIntoView({
  8197. pageNumber: page,
  8198. destArray: dest,
  8199. allowNegativeOffset: true
  8200. });
  8201. }
  8202. this.eventBus.dispatch("scalechanging", {
  8203. source: this,
  8204. scale: newScale,
  8205. presetValue: preset ? newValue : undefined
  8206. });
  8207. if (this.defaultRenderingQueue) {
  8208. this.update();
  8209. }
  8210. }
  8211. get _pageWidthScaleFactor() {
  8212. if (this._spreadMode !== _ui_utils.SpreadMode.NONE && this._scrollMode !== _ui_utils.ScrollMode.HORIZONTAL && !this.isInPresentationMode) {
  8213. return 2;
  8214. }
  8215. return 1;
  8216. }
  8217. _setScale(value, noScroll = false) {
  8218. let scale = parseFloat(value);
  8219. if (scale > 0) {
  8220. this._setScaleUpdatePages(scale, value, noScroll, false);
  8221. } else {
  8222. const currentPage = this._pages[this._currentPageNumber - 1];
  8223. if (!currentPage) {
  8224. return;
  8225. }
  8226. const noPadding = this.isInPresentationMode || this.removePageBorders;
  8227. let hPadding = noPadding ? 0 : _ui_utils.SCROLLBAR_PADDING;
  8228. let vPadding = noPadding ? 0 : _ui_utils.VERTICAL_PADDING;
  8229. if (!noPadding && this._isScrollModeHorizontal) {
  8230. [hPadding, vPadding] = [vPadding, hPadding];
  8231. }
  8232. const pageWidthScale = (this.container.clientWidth - hPadding) / currentPage.width * currentPage.scale / this._pageWidthScaleFactor;
  8233. const pageHeightScale = (this.container.clientHeight - vPadding) / currentPage.height * currentPage.scale;
  8234. switch (value) {
  8235. case "page-actual":
  8236. scale = 1;
  8237. break;
  8238. case "page-width":
  8239. scale = pageWidthScale;
  8240. break;
  8241. case "page-height":
  8242. scale = pageHeightScale;
  8243. break;
  8244. case "page-fit":
  8245. scale = Math.min(pageWidthScale, pageHeightScale);
  8246. break;
  8247. case "auto":
  8248. const horizontalScale = (0, _ui_utils.isPortraitOrientation)(currentPage) ? pageWidthScale : Math.min(pageHeightScale, pageWidthScale);
  8249. scale = Math.min(_ui_utils.MAX_AUTO_SCALE, horizontalScale);
  8250. break;
  8251. default:
  8252. console.error(`${this._name}._setScale: "${value}" is an unknown zoom value.`);
  8253. return;
  8254. }
  8255. this._setScaleUpdatePages(scale, value, noScroll, true);
  8256. }
  8257. }
  8258. _resetCurrentPageView() {
  8259. if (this.isInPresentationMode) {
  8260. this._setScale(this._currentScaleValue, true);
  8261. }
  8262. const pageView = this._pages[this._currentPageNumber - 1];
  8263. this._scrollIntoView({
  8264. pageDiv: pageView.div
  8265. });
  8266. }
  8267. pageLabelToPageNumber(label) {
  8268. if (!this._pageLabels) {
  8269. return null;
  8270. }
  8271. const i = this._pageLabels.indexOf(label);
  8272. if (i < 0) {
  8273. return null;
  8274. }
  8275. return i + 1;
  8276. }
  8277. scrollPageIntoView({
  8278. pageNumber,
  8279. destArray = null,
  8280. allowNegativeOffset = false,
  8281. ignoreDestinationZoom = false
  8282. }) {
  8283. if (!this.pdfDocument) {
  8284. return;
  8285. }
  8286. const pageView = Number.isInteger(pageNumber) && this._pages[pageNumber - 1];
  8287. if (!pageView) {
  8288. console.error(`${this._name}.scrollPageIntoView: ` + `"${pageNumber}" is not a valid pageNumber parameter.`);
  8289. return;
  8290. }
  8291. if (this.isInPresentationMode || !destArray) {
  8292. this._setCurrentPageNumber(pageNumber, true);
  8293. return;
  8294. }
  8295. let x = 0,
  8296. y = 0;
  8297. let width = 0,
  8298. height = 0,
  8299. widthScale,
  8300. heightScale;
  8301. const changeOrientation = pageView.rotation % 180 !== 0;
  8302. const pageWidth = (changeOrientation ? pageView.height : pageView.width) / pageView.scale / _ui_utils.CSS_UNITS;
  8303. const pageHeight = (changeOrientation ? pageView.width : pageView.height) / pageView.scale / _ui_utils.CSS_UNITS;
  8304. let scale = 0;
  8305. switch (destArray[1].name) {
  8306. case "XYZ":
  8307. x = destArray[2];
  8308. y = destArray[3];
  8309. scale = destArray[4];
  8310. x = x !== null ? x : 0;
  8311. y = y !== null ? y : pageHeight;
  8312. break;
  8313. case "Fit":
  8314. case "FitB":
  8315. scale = "page-fit";
  8316. break;
  8317. case "FitH":
  8318. case "FitBH":
  8319. y = destArray[2];
  8320. scale = "page-width";
  8321. if (y === null && this._location) {
  8322. x = this._location.left;
  8323. y = this._location.top;
  8324. } else if (typeof y !== "number") {
  8325. y = pageHeight;
  8326. }
  8327. break;
  8328. case "FitV":
  8329. case "FitBV":
  8330. x = destArray[2];
  8331. width = pageWidth;
  8332. height = pageHeight;
  8333. scale = "page-height";
  8334. break;
  8335. case "FitR":
  8336. x = destArray[2];
  8337. y = destArray[3];
  8338. width = destArray[4] - x;
  8339. height = destArray[5] - y;
  8340. const hPadding = this.removePageBorders ? 0 : _ui_utils.SCROLLBAR_PADDING;
  8341. const vPadding = this.removePageBorders ? 0 : _ui_utils.VERTICAL_PADDING;
  8342. widthScale = (this.container.clientWidth - hPadding) / width / _ui_utils.CSS_UNITS;
  8343. heightScale = (this.container.clientHeight - vPadding) / height / _ui_utils.CSS_UNITS;
  8344. scale = Math.min(Math.abs(widthScale), Math.abs(heightScale));
  8345. break;
  8346. default:
  8347. console.error(`${this._name}.scrollPageIntoView: ` + `"${destArray[1].name}" is not a valid destination type.`);
  8348. return;
  8349. }
  8350. if (!ignoreDestinationZoom) {
  8351. if (scale && scale !== this._currentScale) {
  8352. this.currentScaleValue = scale;
  8353. } else if (this._currentScale === _ui_utils.UNKNOWN_SCALE) {
  8354. this.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  8355. }
  8356. }
  8357. if (scale === "page-fit" && !destArray[4]) {
  8358. this._scrollIntoView({
  8359. pageDiv: pageView.div,
  8360. pageNumber
  8361. });
  8362. return;
  8363. }
  8364. const boundingRect = [pageView.viewport.convertToViewportPoint(x, y), pageView.viewport.convertToViewportPoint(x + width, y + height)];
  8365. let left = Math.min(boundingRect[0][0], boundingRect[1][0]);
  8366. let top = Math.min(boundingRect[0][1], boundingRect[1][1]);
  8367. if (!allowNegativeOffset) {
  8368. left = Math.max(left, 0);
  8369. top = Math.max(top, 0);
  8370. }
  8371. this._scrollIntoView({
  8372. pageDiv: pageView.div,
  8373. pageSpot: {
  8374. left,
  8375. top
  8376. },
  8377. pageNumber
  8378. });
  8379. }
  8380. _updateLocation(firstPage) {
  8381. const currentScale = this._currentScale;
  8382. const currentScaleValue = this._currentScaleValue;
  8383. const normalizedScaleValue = parseFloat(currentScaleValue) === currentScale ? Math.round(currentScale * 10000) / 100 : currentScaleValue;
  8384. const pageNumber = firstPage.id;
  8385. let pdfOpenParams = "#page=" + pageNumber;
  8386. pdfOpenParams += "&zoom=" + normalizedScaleValue;
  8387. const currentPageView = this._pages[pageNumber - 1];
  8388. const container = this.container;
  8389. const topLeft = currentPageView.getPagePoint(container.scrollLeft - firstPage.x, container.scrollTop - firstPage.y);
  8390. const intLeft = Math.round(topLeft[0]);
  8391. const intTop = Math.round(topLeft[1]);
  8392. pdfOpenParams += "," + intLeft + "," + intTop;
  8393. this._location = {
  8394. pageNumber,
  8395. scale: normalizedScaleValue,
  8396. top: intTop,
  8397. left: intLeft,
  8398. rotation: this._pagesRotation,
  8399. pdfOpenParams
  8400. };
  8401. }
  8402. _updateHelper(visiblePages) {
  8403. throw new Error("Not implemented: _updateHelper");
  8404. }
  8405. update() {
  8406. const visible = this._getVisiblePages();
  8407. const visiblePages = visible.views,
  8408. numVisiblePages = visiblePages.length;
  8409. if (numVisiblePages === 0) {
  8410. return;
  8411. }
  8412. const newCacheSize = Math.max(DEFAULT_CACHE_SIZE, 2 * numVisiblePages + 1);
  8413. this._buffer.resize(newCacheSize, visiblePages);
  8414. this.renderingQueue.renderHighestPriority(visible);
  8415. this._updateHelper(visiblePages);
  8416. this._updateLocation(visible.first);
  8417. this.eventBus.dispatch("updateviewarea", {
  8418. source: this,
  8419. location: this._location
  8420. });
  8421. }
  8422. containsElement(element) {
  8423. return this.container.contains(element);
  8424. }
  8425. focus() {
  8426. this.container.focus();
  8427. }
  8428. get _isScrollModeHorizontal() {
  8429. return this.isInPresentationMode ? false : this._scrollMode === _ui_utils.ScrollMode.HORIZONTAL;
  8430. }
  8431. get _isContainerRtl() {
  8432. return getComputedStyle(this.container).direction === "rtl";
  8433. }
  8434. get isInPresentationMode() {
  8435. return this.presentationModeState === _ui_utils.PresentationModeState.FULLSCREEN;
  8436. }
  8437. get isChangingPresentationMode() {
  8438. return this.presentationModeState === _ui_utils.PresentationModeState.CHANGING;
  8439. }
  8440. get isHorizontalScrollbarEnabled() {
  8441. return this.isInPresentationMode ? false : this.container.scrollWidth > this.container.clientWidth;
  8442. }
  8443. get isVerticalScrollbarEnabled() {
  8444. return this.isInPresentationMode ? false : this.container.scrollHeight > this.container.clientHeight;
  8445. }
  8446. _getCurrentVisiblePage() {
  8447. if (!this.pagesCount) {
  8448. return {
  8449. views: []
  8450. };
  8451. }
  8452. const pageView = this._pages[this._currentPageNumber - 1];
  8453. const element = pageView.div;
  8454. const view = {
  8455. id: pageView.id,
  8456. x: element.offsetLeft + element.clientLeft,
  8457. y: element.offsetTop + element.clientTop,
  8458. view: pageView
  8459. };
  8460. return {
  8461. first: view,
  8462. last: view,
  8463. views: [view]
  8464. };
  8465. }
  8466. _getVisiblePages() {
  8467. return (0, _ui_utils.getVisibleElements)({
  8468. scrollEl: this.container,
  8469. views: this._pages,
  8470. sortByVisibility: true,
  8471. horizontal: this._isScrollModeHorizontal,
  8472. rtl: this._isScrollModeHorizontal && this._isContainerRtl
  8473. });
  8474. }
  8475. isPageVisible(pageNumber) {
  8476. if (!this.pdfDocument) {
  8477. return false;
  8478. }
  8479. if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) {
  8480. console.error(`${this._name}.isPageVisible: "${pageNumber}" is not a valid page.`);
  8481. return false;
  8482. }
  8483. return this._getVisiblePages().views.some(function (view) {
  8484. return view.id === pageNumber;
  8485. });
  8486. }
  8487. isPageCached(pageNumber) {
  8488. if (!this.pdfDocument || !this._buffer) {
  8489. return false;
  8490. }
  8491. if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) {
  8492. console.error(`${this._name}.isPageCached: "${pageNumber}" is not a valid page.`);
  8493. return false;
  8494. }
  8495. const pageView = this._pages[pageNumber - 1];
  8496. if (!pageView) {
  8497. return false;
  8498. }
  8499. return this._buffer.has(pageView);
  8500. }
  8501. cleanup() {
  8502. for (let i = 0, ii = this._pages.length; i < ii; i++) {
  8503. if (this._pages[i] && this._pages[i].renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED) {
  8504. this._pages[i].reset();
  8505. }
  8506. }
  8507. }
  8508. _cancelRendering() {
  8509. for (let i = 0, ii = this._pages.length; i < ii; i++) {
  8510. if (this._pages[i]) {
  8511. this._pages[i].cancelRendering();
  8512. }
  8513. }
  8514. }
  8515. _ensurePdfPageLoaded(pageView) {
  8516. if (pageView.pdfPage) {
  8517. return Promise.resolve(pageView.pdfPage);
  8518. }
  8519. if (this._pagesRequests.has(pageView)) {
  8520. return this._pagesRequests.get(pageView);
  8521. }
  8522. const promise = this.pdfDocument.getPage(pageView.id).then(pdfPage => {
  8523. if (!pageView.pdfPage) {
  8524. pageView.setPdfPage(pdfPage);
  8525. }
  8526. this._pagesRequests.delete(pageView);
  8527. return pdfPage;
  8528. }).catch(reason => {
  8529. console.error("Unable to get page for page view", reason);
  8530. this._pagesRequests.delete(pageView);
  8531. });
  8532. this._pagesRequests.set(pageView, promise);
  8533. return promise;
  8534. }
  8535. forceRendering(currentlyVisiblePages) {
  8536. const visiblePages = currentlyVisiblePages || this._getVisiblePages();
  8537. const scrollAhead = this._isScrollModeHorizontal ? this.scroll.right : this.scroll.down;
  8538. const pageView = this.renderingQueue.getHighestPriority(visiblePages, this._pages, scrollAhead);
  8539. if (pageView) {
  8540. this._ensurePdfPageLoaded(pageView).then(() => {
  8541. this.renderingQueue.renderView(pageView);
  8542. });
  8543. return true;
  8544. }
  8545. return false;
  8546. }
  8547. createTextLayerBuilder(textLayerDiv, pageIndex, viewport, enhanceTextSelection = false, eventBus) {
  8548. return new _text_layer_builder.TextLayerBuilder({
  8549. textLayerDiv,
  8550. eventBus,
  8551. pageIndex,
  8552. viewport,
  8553. findController: this.isInPresentationMode ? null : this.findController,
  8554. enhanceTextSelection: this.isInPresentationMode ? false : enhanceTextSelection
  8555. });
  8556. }
  8557. createAnnotationLayerBuilder(pageDiv, pdfPage, annotationStorage = null, imageResourcesPath = "", renderInteractiveForms = false, l10n = _l10n_utils.NullL10n, enableScripting = null, hasJSActionsPromise = null, mouseState = null) {
  8558. return new _annotation_layer_builder.AnnotationLayerBuilder({
  8559. pageDiv,
  8560. pdfPage,
  8561. annotationStorage: annotationStorage || this.pdfDocument?.annotationStorage,
  8562. imageResourcesPath,
  8563. renderInteractiveForms,
  8564. linkService: this.linkService,
  8565. downloadManager: this.downloadManager,
  8566. l10n,
  8567. enableScripting: enableScripting ?? this.enableScripting,
  8568. hasJSActionsPromise: hasJSActionsPromise || this.pdfDocument?.hasJSActions(),
  8569. mouseState: mouseState || this._scriptingManager?.mouseState
  8570. });
  8571. }
  8572. createXfaLayerBuilder(pageDiv, pdfPage, annotationStorage = null) {
  8573. return new _xfa_layer_builder.XfaLayerBuilder({
  8574. pageDiv,
  8575. pdfPage,
  8576. annotationStorage: annotationStorage || this.pdfDocument?.annotationStorage
  8577. });
  8578. }
  8579. createStructTreeLayerBuilder(pdfPage) {
  8580. return new _struct_tree_layer_builder.StructTreeLayerBuilder({
  8581. pdfPage
  8582. });
  8583. }
  8584. get hasEqualPageSizes() {
  8585. const firstPageView = this._pages[0];
  8586. for (let i = 1, ii = this._pages.length; i < ii; ++i) {
  8587. const pageView = this._pages[i];
  8588. if (pageView.width !== firstPageView.width || pageView.height !== firstPageView.height) {
  8589. return false;
  8590. }
  8591. }
  8592. return true;
  8593. }
  8594. getPagesOverview() {
  8595. return this._pages.map(pageView => {
  8596. const viewport = pageView.pdfPage.getViewport({
  8597. scale: 1
  8598. });
  8599. if (!this.enablePrintAutoRotate || (0, _ui_utils.isPortraitOrientation)(viewport)) {
  8600. return {
  8601. width: viewport.width,
  8602. height: viewport.height,
  8603. rotation: viewport.rotation
  8604. };
  8605. }
  8606. return {
  8607. width: viewport.height,
  8608. height: viewport.width,
  8609. rotation: (viewport.rotation - 90) % 360
  8610. };
  8611. });
  8612. }
  8613. get optionalContentConfigPromise() {
  8614. if (!this.pdfDocument) {
  8615. return Promise.resolve(null);
  8616. }
  8617. if (!this._optionalContentConfigPromise) {
  8618. return this.pdfDocument.getOptionalContentConfig();
  8619. }
  8620. return this._optionalContentConfigPromise;
  8621. }
  8622. set optionalContentConfigPromise(promise) {
  8623. if (!(promise instanceof Promise)) {
  8624. throw new Error(`Invalid optionalContentConfigPromise: ${promise}`);
  8625. }
  8626. if (!this.pdfDocument) {
  8627. return;
  8628. }
  8629. if (!this._optionalContentConfigPromise) {
  8630. return;
  8631. }
  8632. this._optionalContentConfigPromise = promise;
  8633. for (const pageView of this._pages) {
  8634. pageView.update(pageView.scale, pageView.rotation, promise);
  8635. }
  8636. this.update();
  8637. this.eventBus.dispatch("optionalcontentconfigchanged", {
  8638. source: this,
  8639. promise
  8640. });
  8641. }
  8642. get scrollMode() {
  8643. return this._scrollMode;
  8644. }
  8645. set scrollMode(mode) {
  8646. if (this._scrollMode === mode) {
  8647. return;
  8648. }
  8649. if (!(0, _ui_utils.isValidScrollMode)(mode)) {
  8650. throw new Error(`Invalid scroll mode: ${mode}`);
  8651. }
  8652. this._scrollMode = mode;
  8653. this.eventBus.dispatch("scrollmodechanged", {
  8654. source: this,
  8655. mode
  8656. });
  8657. this._updateScrollMode(this._currentPageNumber);
  8658. }
  8659. _updateScrollMode(pageNumber = null) {
  8660. const scrollMode = this._scrollMode,
  8661. viewer = this.viewer;
  8662. viewer.classList.toggle("scrollHorizontal", scrollMode === _ui_utils.ScrollMode.HORIZONTAL);
  8663. viewer.classList.toggle("scrollWrapped", scrollMode === _ui_utils.ScrollMode.WRAPPED);
  8664. if (!this.pdfDocument || !pageNumber) {
  8665. return;
  8666. }
  8667. if (this._currentScaleValue && isNaN(this._currentScaleValue)) {
  8668. this._setScale(this._currentScaleValue, true);
  8669. }
  8670. this._setCurrentPageNumber(pageNumber, true);
  8671. this.update();
  8672. }
  8673. get spreadMode() {
  8674. return this._spreadMode;
  8675. }
  8676. set spreadMode(mode) {
  8677. if (this._spreadMode === mode) {
  8678. return;
  8679. }
  8680. if (!(0, _ui_utils.isValidSpreadMode)(mode)) {
  8681. throw new Error(`Invalid spread mode: ${mode}`);
  8682. }
  8683. this._spreadMode = mode;
  8684. this.eventBus.dispatch("spreadmodechanged", {
  8685. source: this,
  8686. mode
  8687. });
  8688. this._updateSpreadMode(this._currentPageNumber);
  8689. }
  8690. _updateSpreadMode(pageNumber = null) {
  8691. if (!this.pdfDocument) {
  8692. return;
  8693. }
  8694. const viewer = this.viewer,
  8695. pages = this._pages;
  8696. viewer.textContent = "";
  8697. if (this._spreadMode === _ui_utils.SpreadMode.NONE) {
  8698. for (let i = 0, iMax = pages.length; i < iMax; ++i) {
  8699. viewer.appendChild(pages[i].div);
  8700. }
  8701. } else {
  8702. const parity = this._spreadMode - 1;
  8703. let spread = null;
  8704. for (let i = 0, iMax = pages.length; i < iMax; ++i) {
  8705. if (spread === null) {
  8706. spread = document.createElement("div");
  8707. spread.className = "spread";
  8708. viewer.appendChild(spread);
  8709. } else if (i % 2 === parity) {
  8710. spread = spread.cloneNode(false);
  8711. viewer.appendChild(spread);
  8712. }
  8713. spread.appendChild(pages[i].div);
  8714. }
  8715. }
  8716. if (!pageNumber) {
  8717. return;
  8718. }
  8719. if (this._currentScaleValue && isNaN(this._currentScaleValue)) {
  8720. this._setScale(this._currentScaleValue, true);
  8721. }
  8722. this._setCurrentPageNumber(pageNumber, true);
  8723. this.update();
  8724. }
  8725. _getPageAdvance(currentPageNumber, previous = false) {
  8726. if (this.isInPresentationMode) {
  8727. return 1;
  8728. }
  8729. switch (this._scrollMode) {
  8730. case _ui_utils.ScrollMode.WRAPPED:
  8731. {
  8732. const {
  8733. views
  8734. } = this._getVisiblePages(),
  8735. pageLayout = new Map();
  8736. for (const {
  8737. id,
  8738. y,
  8739. percent,
  8740. widthPercent
  8741. } of views) {
  8742. if (percent === 0 || widthPercent < 100) {
  8743. continue;
  8744. }
  8745. let yArray = pageLayout.get(y);
  8746. if (!yArray) {
  8747. pageLayout.set(y, yArray || (yArray = []));
  8748. }
  8749. yArray.push(id);
  8750. }
  8751. for (const yArray of pageLayout.values()) {
  8752. const currentIndex = yArray.indexOf(currentPageNumber);
  8753. if (currentIndex === -1) {
  8754. continue;
  8755. }
  8756. const numPages = yArray.length;
  8757. if (numPages === 1) {
  8758. break;
  8759. }
  8760. if (previous) {
  8761. for (let i = currentIndex - 1, ii = 0; i >= ii; i--) {
  8762. const currentId = yArray[i],
  8763. expectedId = yArray[i + 1] - 1;
  8764. if (currentId < expectedId) {
  8765. return currentPageNumber - expectedId;
  8766. }
  8767. }
  8768. } else {
  8769. for (let i = currentIndex + 1, ii = numPages; i < ii; i++) {
  8770. const currentId = yArray[i],
  8771. expectedId = yArray[i - 1] + 1;
  8772. if (currentId > expectedId) {
  8773. return expectedId - currentPageNumber;
  8774. }
  8775. }
  8776. }
  8777. if (previous) {
  8778. const firstId = yArray[0];
  8779. if (firstId < currentPageNumber) {
  8780. return currentPageNumber - firstId + 1;
  8781. }
  8782. } else {
  8783. const lastId = yArray[numPages - 1];
  8784. if (lastId > currentPageNumber) {
  8785. return lastId - currentPageNumber + 1;
  8786. }
  8787. }
  8788. break;
  8789. }
  8790. break;
  8791. }
  8792. case _ui_utils.ScrollMode.HORIZONTAL:
  8793. {
  8794. break;
  8795. }
  8796. case _ui_utils.ScrollMode.VERTICAL:
  8797. {
  8798. if (this._spreadMode === _ui_utils.SpreadMode.NONE) {
  8799. break;
  8800. }
  8801. const parity = this._spreadMode - 1;
  8802. if (previous && currentPageNumber % 2 !== parity) {
  8803. break;
  8804. } else if (!previous && currentPageNumber % 2 === parity) {
  8805. break;
  8806. }
  8807. const {
  8808. views
  8809. } = this._getVisiblePages(),
  8810. expectedId = previous ? currentPageNumber - 1 : currentPageNumber + 1;
  8811. for (const {
  8812. id,
  8813. percent,
  8814. widthPercent
  8815. } of views) {
  8816. if (id !== expectedId) {
  8817. continue;
  8818. }
  8819. if (percent > 0 && widthPercent === 100) {
  8820. return 2;
  8821. }
  8822. break;
  8823. }
  8824. break;
  8825. }
  8826. }
  8827. return 1;
  8828. }
  8829. nextPage() {
  8830. const currentPageNumber = this._currentPageNumber,
  8831. pagesCount = this.pagesCount;
  8832. if (currentPageNumber >= pagesCount) {
  8833. return false;
  8834. }
  8835. const advance = this._getPageAdvance(currentPageNumber, false) || 1;
  8836. this.currentPageNumber = Math.min(currentPageNumber + advance, pagesCount);
  8837. return true;
  8838. }
  8839. previousPage() {
  8840. const currentPageNumber = this._currentPageNumber;
  8841. if (currentPageNumber <= 1) {
  8842. return false;
  8843. }
  8844. const advance = this._getPageAdvance(currentPageNumber, true) || 1;
  8845. this.currentPageNumber = Math.max(currentPageNumber - advance, 1);
  8846. return true;
  8847. }
  8848. }
  8849. exports.BaseViewer = BaseViewer;
  8850. /***/ }),
  8851. /* 29 */
  8852. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  8853. Object.defineProperty(exports, "__esModule", ({
  8854. value: true
  8855. }));
  8856. exports.DefaultAnnotationLayerFactory = exports.AnnotationLayerBuilder = void 0;
  8857. var _pdfjsLib = __webpack_require__(5);
  8858. var _l10n_utils = __webpack_require__(30);
  8859. var _pdf_link_service = __webpack_require__(19);
  8860. class AnnotationLayerBuilder {
  8861. constructor({
  8862. pageDiv,
  8863. pdfPage,
  8864. linkService,
  8865. downloadManager,
  8866. annotationStorage = null,
  8867. imageResourcesPath = "",
  8868. renderInteractiveForms = true,
  8869. l10n = _l10n_utils.NullL10n,
  8870. enableScripting = false,
  8871. hasJSActionsPromise = null,
  8872. mouseState = null
  8873. }) {
  8874. this.pageDiv = pageDiv;
  8875. this.pdfPage = pdfPage;
  8876. this.linkService = linkService;
  8877. this.downloadManager = downloadManager;
  8878. this.imageResourcesPath = imageResourcesPath;
  8879. this.renderInteractiveForms = renderInteractiveForms;
  8880. this.l10n = l10n;
  8881. this.annotationStorage = annotationStorage;
  8882. this.enableScripting = enableScripting;
  8883. this._hasJSActionsPromise = hasJSActionsPromise;
  8884. this._mouseState = mouseState;
  8885. this.div = null;
  8886. this._cancelled = false;
  8887. }
  8888. render(viewport, intent = "display") {
  8889. return Promise.all([this.pdfPage.getAnnotations({
  8890. intent
  8891. }), this._hasJSActionsPromise]).then(([annotations, hasJSActions = false]) => {
  8892. if (this._cancelled) {
  8893. return;
  8894. }
  8895. if (annotations.length === 0) {
  8896. return;
  8897. }
  8898. const parameters = {
  8899. viewport: viewport.clone({
  8900. dontFlip: true
  8901. }),
  8902. div: this.div,
  8903. annotations,
  8904. page: this.pdfPage,
  8905. imageResourcesPath: this.imageResourcesPath,
  8906. renderInteractiveForms: this.renderInteractiveForms,
  8907. linkService: this.linkService,
  8908. downloadManager: this.downloadManager,
  8909. annotationStorage: this.annotationStorage,
  8910. enableScripting: this.enableScripting,
  8911. hasJSActions,
  8912. mouseState: this._mouseState
  8913. };
  8914. if (this.div) {
  8915. _pdfjsLib.AnnotationLayer.update(parameters);
  8916. } else {
  8917. this.div = document.createElement("div");
  8918. this.div.className = "annotationLayer";
  8919. this.pageDiv.appendChild(this.div);
  8920. parameters.div = this.div;
  8921. _pdfjsLib.AnnotationLayer.render(parameters);
  8922. this.l10n.translate(this.div);
  8923. }
  8924. });
  8925. }
  8926. cancel() {
  8927. this._cancelled = true;
  8928. }
  8929. hide() {
  8930. if (!this.div) {
  8931. return;
  8932. }
  8933. this.div.hidden = true;
  8934. }
  8935. }
  8936. exports.AnnotationLayerBuilder = AnnotationLayerBuilder;
  8937. class DefaultAnnotationLayerFactory {
  8938. createAnnotationLayerBuilder(pageDiv, pdfPage, annotationStorage = null, imageResourcesPath = "", renderInteractiveForms = true, l10n = _l10n_utils.NullL10n, enableScripting = false, hasJSActionsPromise = null, mouseState = null) {
  8939. return new AnnotationLayerBuilder({
  8940. pageDiv,
  8941. pdfPage,
  8942. imageResourcesPath,
  8943. renderInteractiveForms,
  8944. linkService: new _pdf_link_service.SimpleLinkService(),
  8945. l10n,
  8946. annotationStorage,
  8947. enableScripting,
  8948. hasJSActionsPromise,
  8949. mouseState
  8950. });
  8951. }
  8952. }
  8953. exports.DefaultAnnotationLayerFactory = DefaultAnnotationLayerFactory;
  8954. /***/ }),
  8955. /* 30 */
  8956. /***/ ((__unused_webpack_module, exports) => {
  8957. Object.defineProperty(exports, "__esModule", ({
  8958. value: true
  8959. }));
  8960. exports.fixupLangCode = fixupLangCode;
  8961. exports.getL10nFallback = getL10nFallback;
  8962. exports.NullL10n = void 0;
  8963. const DEFAULT_L10N_STRINGS = {
  8964. of_pages: "of {{pagesCount}}",
  8965. page_of_pages: "({{pageNumber}} of {{pagesCount}})",
  8966. document_properties_kb: "{{size_kb}} KB ({{size_b}} bytes)",
  8967. document_properties_mb: "{{size_mb}} MB ({{size_b}} bytes)",
  8968. document_properties_date_string: "{{date}}, {{time}}",
  8969. document_properties_page_size_unit_inches: "in",
  8970. document_properties_page_size_unit_millimeters: "mm",
  8971. document_properties_page_size_orientation_portrait: "portrait",
  8972. document_properties_page_size_orientation_landscape: "landscape",
  8973. document_properties_page_size_name_a3: "A3",
  8974. document_properties_page_size_name_a4: "A4",
  8975. document_properties_page_size_name_letter: "Letter",
  8976. document_properties_page_size_name_legal: "Legal",
  8977. document_properties_page_size_dimension_string: "{{width}} × {{height}} {{unit}} ({{orientation}})",
  8978. document_properties_page_size_dimension_name_string: "{{width}} × {{height}} {{unit}} ({{name}}, {{orientation}})",
  8979. document_properties_linearized_yes: "Yes",
  8980. document_properties_linearized_no: "No",
  8981. print_progress_percent: "{{progress}}%",
  8982. "toggle_sidebar.title": "Toggle Sidebar",
  8983. "toggle_sidebar_notification2.title": "Toggle Sidebar (document contains outline/attachments/layers)",
  8984. additional_layers: "Additional Layers",
  8985. page_landmark: "Page {{page}}",
  8986. thumb_page_title: "Page {{page}}",
  8987. thumb_page_canvas: "Thumbnail of Page {{page}}",
  8988. find_reached_top: "Reached top of document, continued from bottom",
  8989. find_reached_bottom: "Reached end of document, continued from top",
  8990. "find_match_count[one]": "{{current}} of {{total}} match",
  8991. "find_match_count[other]": "{{current}} of {{total}} matches",
  8992. "find_match_count_limit[one]": "More than {{limit}} match",
  8993. "find_match_count_limit[other]": "More than {{limit}} matches",
  8994. find_not_found: "Phrase not found",
  8995. error_version_info: "PDF.js v{{version}} (build: {{build}})",
  8996. error_message: "Message: {{message}}",
  8997. error_stack: "Stack: {{stack}}",
  8998. error_file: "File: {{file}}",
  8999. error_line: "Line: {{line}}",
  9000. rendering_error: "An error occurred while rendering the page.",
  9001. page_scale_width: "Page Width",
  9002. page_scale_fit: "Page Fit",
  9003. page_scale_auto: "Automatic Zoom",
  9004. page_scale_actual: "Actual Size",
  9005. page_scale_percent: "{{scale}}%",
  9006. loading: "Loading…",
  9007. loading_error: "An error occurred while loading the PDF.",
  9008. invalid_file_error: "Invalid or corrupted PDF file.",
  9009. missing_file_error: "Missing PDF file.",
  9010. unexpected_response_error: "Unexpected server response.",
  9011. printing_not_supported: "Warning: Printing is not fully supported by this browser.",
  9012. printing_not_ready: "Warning: The PDF is not fully loaded for printing.",
  9013. web_fonts_disabled: "Web fonts are disabled: unable to use embedded PDF fonts."
  9014. };
  9015. function getL10nFallback(key, args) {
  9016. switch (key) {
  9017. case "find_match_count":
  9018. key = `find_match_count[${args.total === 1 ? "one" : "other"}]`;
  9019. break;
  9020. case "find_match_count_limit":
  9021. key = `find_match_count_limit[${args.limit === 1 ? "one" : "other"}]`;
  9022. break;
  9023. }
  9024. return DEFAULT_L10N_STRINGS[key] || "";
  9025. }
  9026. const PARTIAL_LANG_CODES = {
  9027. en: "en-US",
  9028. es: "es-ES",
  9029. fy: "fy-NL",
  9030. ga: "ga-IE",
  9031. gu: "gu-IN",
  9032. hi: "hi-IN",
  9033. hy: "hy-AM",
  9034. nb: "nb-NO",
  9035. ne: "ne-NP",
  9036. nn: "nn-NO",
  9037. pa: "pa-IN",
  9038. pt: "pt-PT",
  9039. sv: "sv-SE",
  9040. zh: "zh-CN"
  9041. };
  9042. function fixupLangCode(langCode) {
  9043. return PARTIAL_LANG_CODES[langCode?.toLowerCase()] || langCode;
  9044. }
  9045. function formatL10nValue(text, args) {
  9046. if (!args) {
  9047. return text;
  9048. }
  9049. return text.replace(/\{\{\s*(\w+)\s*\}\}/g, (all, name) => {
  9050. return name in args ? args[name] : "{{" + name + "}}";
  9051. });
  9052. }
  9053. const NullL10n = {
  9054. async getLanguage() {
  9055. return "en-us";
  9056. },
  9057. async getDirection() {
  9058. return "ltr";
  9059. },
  9060. async get(key, args = null, fallback = getL10nFallback(key, args)) {
  9061. return formatL10nValue(fallback, args);
  9062. },
  9063. async translate(element) {}
  9064. };
  9065. exports.NullL10n = NullL10n;
  9066. /***/ }),
  9067. /* 31 */
  9068. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  9069. Object.defineProperty(exports, "__esModule", ({
  9070. value: true
  9071. }));
  9072. exports.PDFPageView = void 0;
  9073. var _ui_utils = __webpack_require__(4);
  9074. var _pdfjsLib = __webpack_require__(5);
  9075. var _l10n_utils = __webpack_require__(30);
  9076. var _pdf_rendering_queue = __webpack_require__(8);
  9077. var _viewer_compatibility = __webpack_require__(2);
  9078. const MAX_CANVAS_PIXELS = _viewer_compatibility.viewerCompatibilityParams.maxCanvasPixels || 16777216;
  9079. class PDFPageView {
  9080. constructor(options) {
  9081. const container = options.container;
  9082. const defaultViewport = options.defaultViewport;
  9083. this.id = options.id;
  9084. this.renderingId = "page" + this.id;
  9085. this.pdfPage = null;
  9086. this.pageLabel = null;
  9087. this.rotation = 0;
  9088. this.scale = options.scale || _ui_utils.DEFAULT_SCALE;
  9089. this.viewport = defaultViewport;
  9090. this.pdfPageRotate = defaultViewport.rotation;
  9091. this._optionalContentConfigPromise = options.optionalContentConfigPromise || null;
  9092. this.hasRestrictedScaling = false;
  9093. this.textLayerMode = Number.isInteger(options.textLayerMode) ? options.textLayerMode : _ui_utils.TextLayerMode.ENABLE;
  9094. this.imageResourcesPath = options.imageResourcesPath || "";
  9095. this.renderInteractiveForms = options.renderInteractiveForms !== false;
  9096. this.useOnlyCssZoom = options.useOnlyCssZoom || false;
  9097. this.maxCanvasPixels = options.maxCanvasPixels || MAX_CANVAS_PIXELS;
  9098. this.eventBus = options.eventBus;
  9099. this.renderingQueue = options.renderingQueue;
  9100. this.textLayerFactory = options.textLayerFactory;
  9101. this.annotationLayerFactory = options.annotationLayerFactory;
  9102. this.xfaLayerFactory = options.xfaLayerFactory;
  9103. this.structTreeLayerFactory = options.structTreeLayerFactory;
  9104. this.renderer = options.renderer || _ui_utils.RendererType.CANVAS;
  9105. this.l10n = options.l10n || _l10n_utils.NullL10n;
  9106. this.paintTask = null;
  9107. this.paintedViewportMap = new WeakMap();
  9108. this.renderingState = _pdf_rendering_queue.RenderingStates.INITIAL;
  9109. this.resume = null;
  9110. this._renderError = null;
  9111. this.annotationLayer = null;
  9112. this.textLayer = null;
  9113. this.zoomLayer = null;
  9114. this.xfaLayer = null;
  9115. this.structTreeLayer = null;
  9116. const div = document.createElement("div");
  9117. div.className = "page";
  9118. div.style.width = Math.floor(this.viewport.width) + "px";
  9119. div.style.height = Math.floor(this.viewport.height) + "px";
  9120. div.setAttribute("data-page-number", this.id);
  9121. div.setAttribute("role", "region");
  9122. this.l10n.get("page_landmark", {
  9123. page: this.id
  9124. }).then(msg => {
  9125. div.setAttribute("aria-label", msg);
  9126. });
  9127. this.div = div;
  9128. container.appendChild(div);
  9129. }
  9130. setPdfPage(pdfPage) {
  9131. this.pdfPage = pdfPage;
  9132. this.pdfPageRotate = pdfPage.rotate;
  9133. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  9134. this.viewport = pdfPage.getViewport({
  9135. scale: this.scale * _ui_utils.CSS_UNITS,
  9136. rotation: totalRotation
  9137. });
  9138. this.reset();
  9139. }
  9140. destroy() {
  9141. this.reset();
  9142. if (this.pdfPage) {
  9143. this.pdfPage.cleanup();
  9144. }
  9145. }
  9146. async _renderAnnotationLayer() {
  9147. let error = null;
  9148. try {
  9149. await this.annotationLayer.render(this.viewport, "display");
  9150. } catch (ex) {
  9151. error = ex;
  9152. } finally {
  9153. this.eventBus.dispatch("annotationlayerrendered", {
  9154. source: this,
  9155. pageNumber: this.id,
  9156. error
  9157. });
  9158. }
  9159. }
  9160. async _renderXfaLayer() {
  9161. let error = null;
  9162. try {
  9163. await this.xfaLayer.render(this.viewport, "display");
  9164. } catch (ex) {
  9165. error = ex;
  9166. } finally {
  9167. this.eventBus.dispatch("xfalayerrendered", {
  9168. source: this,
  9169. pageNumber: this.id,
  9170. error
  9171. });
  9172. }
  9173. }
  9174. _resetZoomLayer(removeFromDOM = false) {
  9175. if (!this.zoomLayer) {
  9176. return;
  9177. }
  9178. const zoomLayerCanvas = this.zoomLayer.firstChild;
  9179. this.paintedViewportMap.delete(zoomLayerCanvas);
  9180. zoomLayerCanvas.width = 0;
  9181. zoomLayerCanvas.height = 0;
  9182. if (removeFromDOM) {
  9183. this.zoomLayer.remove();
  9184. }
  9185. this.zoomLayer = null;
  9186. }
  9187. reset({
  9188. keepZoomLayer = false,
  9189. keepAnnotationLayer = false,
  9190. keepXfaLayer = false
  9191. } = {}) {
  9192. this.cancelRendering({
  9193. keepAnnotationLayer,
  9194. keepXfaLayer
  9195. });
  9196. this.renderingState = _pdf_rendering_queue.RenderingStates.INITIAL;
  9197. const div = this.div;
  9198. div.style.width = Math.floor(this.viewport.width) + "px";
  9199. div.style.height = Math.floor(this.viewport.height) + "px";
  9200. const childNodes = div.childNodes,
  9201. zoomLayerNode = keepZoomLayer && this.zoomLayer || null,
  9202. annotationLayerNode = keepAnnotationLayer && this.annotationLayer?.div || null,
  9203. xfaLayerNode = keepXfaLayer && this.xfaLayer?.div || null;
  9204. for (let i = childNodes.length - 1; i >= 0; i--) {
  9205. const node = childNodes[i];
  9206. switch (node) {
  9207. case zoomLayerNode:
  9208. case annotationLayerNode:
  9209. case xfaLayerNode:
  9210. continue;
  9211. }
  9212. div.removeChild(node);
  9213. }
  9214. div.removeAttribute("data-loaded");
  9215. if (annotationLayerNode) {
  9216. this.annotationLayer.hide();
  9217. }
  9218. if (xfaLayerNode) {
  9219. this.xfaLayer.hide();
  9220. }
  9221. if (!zoomLayerNode) {
  9222. if (this.canvas) {
  9223. this.paintedViewportMap.delete(this.canvas);
  9224. this.canvas.width = 0;
  9225. this.canvas.height = 0;
  9226. delete this.canvas;
  9227. }
  9228. this._resetZoomLayer();
  9229. }
  9230. if (this.svg) {
  9231. this.paintedViewportMap.delete(this.svg);
  9232. delete this.svg;
  9233. }
  9234. this.loadingIconDiv = document.createElement("div");
  9235. this.loadingIconDiv.className = "loadingIcon";
  9236. this.loadingIconDiv.setAttribute("role", "img");
  9237. this.l10n.get("loading").then(msg => {
  9238. this.loadingIconDiv?.setAttribute("aria-label", msg);
  9239. });
  9240. div.appendChild(this.loadingIconDiv);
  9241. }
  9242. update(scale, rotation, optionalContentConfigPromise = null) {
  9243. this.scale = scale || this.scale;
  9244. if (typeof rotation !== "undefined") {
  9245. this.rotation = rotation;
  9246. }
  9247. if (optionalContentConfigPromise instanceof Promise) {
  9248. this._optionalContentConfigPromise = optionalContentConfigPromise;
  9249. }
  9250. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  9251. this.viewport = this.viewport.clone({
  9252. scale: this.scale * _ui_utils.CSS_UNITS,
  9253. rotation: totalRotation
  9254. });
  9255. if (this.svg) {
  9256. this.cssTransform({
  9257. target: this.svg,
  9258. redrawAnnotationLayer: true,
  9259. redrawXfaLayer: true
  9260. });
  9261. this.eventBus.dispatch("pagerendered", {
  9262. source: this,
  9263. pageNumber: this.id,
  9264. cssTransform: true,
  9265. timestamp: performance.now(),
  9266. error: this._renderError
  9267. });
  9268. return;
  9269. }
  9270. let isScalingRestricted = false;
  9271. if (this.canvas && this.maxCanvasPixels > 0) {
  9272. const outputScale = this.outputScale;
  9273. if ((Math.floor(this.viewport.width) * outputScale.sx | 0) * (Math.floor(this.viewport.height) * outputScale.sy | 0) > this.maxCanvasPixels) {
  9274. isScalingRestricted = true;
  9275. }
  9276. }
  9277. if (this.canvas) {
  9278. if (this.useOnlyCssZoom || this.hasRestrictedScaling && isScalingRestricted) {
  9279. this.cssTransform({
  9280. target: this.canvas,
  9281. redrawAnnotationLayer: true,
  9282. redrawXfaLayer: true
  9283. });
  9284. this.eventBus.dispatch("pagerendered", {
  9285. source: this,
  9286. pageNumber: this.id,
  9287. cssTransform: true,
  9288. timestamp: performance.now(),
  9289. error: this._renderError
  9290. });
  9291. return;
  9292. }
  9293. if (!this.zoomLayer && !this.canvas.hidden) {
  9294. this.zoomLayer = this.canvas.parentNode;
  9295. this.zoomLayer.style.position = "absolute";
  9296. }
  9297. }
  9298. if (this.zoomLayer) {
  9299. this.cssTransform({
  9300. target: this.zoomLayer.firstChild
  9301. });
  9302. }
  9303. this.reset({
  9304. keepZoomLayer: true,
  9305. keepAnnotationLayer: true,
  9306. keepXfaLayer: true
  9307. });
  9308. }
  9309. cancelRendering({
  9310. keepAnnotationLayer = false,
  9311. keepXfaLayer = false
  9312. } = {}) {
  9313. if (this.paintTask) {
  9314. this.paintTask.cancel();
  9315. this.paintTask = null;
  9316. }
  9317. this.resume = null;
  9318. if (this.textLayer) {
  9319. this.textLayer.cancel();
  9320. this.textLayer = null;
  9321. }
  9322. if (this.annotationLayer && (!keepAnnotationLayer || !this.annotationLayer.div)) {
  9323. this.annotationLayer.cancel();
  9324. this.annotationLayer = null;
  9325. }
  9326. if (this.xfaLayer && (!keepXfaLayer || !this.xfaLayer.div)) {
  9327. this.xfaLayer.cancel();
  9328. this.xfaLayer = null;
  9329. }
  9330. if (this._onTextLayerRendered) {
  9331. this.eventBus._off("textlayerrendered", this._onTextLayerRendered);
  9332. this._onTextLayerRendered = null;
  9333. }
  9334. }
  9335. cssTransform({
  9336. target,
  9337. redrawAnnotationLayer = false,
  9338. redrawXfaLayer = false
  9339. }) {
  9340. const width = this.viewport.width;
  9341. const height = this.viewport.height;
  9342. const div = this.div;
  9343. target.style.width = target.parentNode.style.width = div.style.width = Math.floor(width) + "px";
  9344. target.style.height = target.parentNode.style.height = div.style.height = Math.floor(height) + "px";
  9345. const relativeRotation = this.viewport.rotation - this.paintedViewportMap.get(target).rotation;
  9346. const absRotation = Math.abs(relativeRotation);
  9347. let scaleX = 1,
  9348. scaleY = 1;
  9349. if (absRotation === 90 || absRotation === 270) {
  9350. scaleX = height / width;
  9351. scaleY = width / height;
  9352. }
  9353. target.style.transform = `rotate(${relativeRotation}deg) scale(${scaleX}, ${scaleY})`;
  9354. if (this.textLayer) {
  9355. const textLayerViewport = this.textLayer.viewport;
  9356. const textRelativeRotation = this.viewport.rotation - textLayerViewport.rotation;
  9357. const textAbsRotation = Math.abs(textRelativeRotation);
  9358. let scale = width / textLayerViewport.width;
  9359. if (textAbsRotation === 90 || textAbsRotation === 270) {
  9360. scale = width / textLayerViewport.height;
  9361. }
  9362. const textLayerDiv = this.textLayer.textLayerDiv;
  9363. let transX, transY;
  9364. switch (textAbsRotation) {
  9365. case 0:
  9366. transX = transY = 0;
  9367. break;
  9368. case 90:
  9369. transX = 0;
  9370. transY = "-" + textLayerDiv.style.height;
  9371. break;
  9372. case 180:
  9373. transX = "-" + textLayerDiv.style.width;
  9374. transY = "-" + textLayerDiv.style.height;
  9375. break;
  9376. case 270:
  9377. transX = "-" + textLayerDiv.style.width;
  9378. transY = 0;
  9379. break;
  9380. default:
  9381. console.error("Bad rotation value.");
  9382. break;
  9383. }
  9384. textLayerDiv.style.transform = `rotate(${textAbsRotation}deg) ` + `scale(${scale}) ` + `translate(${transX}, ${transY})`;
  9385. textLayerDiv.style.transformOrigin = "0% 0%";
  9386. }
  9387. if (redrawAnnotationLayer && this.annotationLayer) {
  9388. this._renderAnnotationLayer();
  9389. }
  9390. if (redrawXfaLayer && this.xfaLayer) {
  9391. this._renderXfaLayer();
  9392. }
  9393. }
  9394. get width() {
  9395. return this.viewport.width;
  9396. }
  9397. get height() {
  9398. return this.viewport.height;
  9399. }
  9400. getPagePoint(x, y) {
  9401. return this.viewport.convertToPdfPoint(x, y);
  9402. }
  9403. draw() {
  9404. if (this.renderingState !== _pdf_rendering_queue.RenderingStates.INITIAL) {
  9405. console.error("Must be in new state before drawing");
  9406. this.reset();
  9407. }
  9408. const {
  9409. div,
  9410. pdfPage
  9411. } = this;
  9412. if (!pdfPage) {
  9413. this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
  9414. if (this.loadingIconDiv) {
  9415. div.removeChild(this.loadingIconDiv);
  9416. delete this.loadingIconDiv;
  9417. }
  9418. return Promise.reject(new Error("pdfPage is not loaded"));
  9419. }
  9420. this.renderingState = _pdf_rendering_queue.RenderingStates.RUNNING;
  9421. const canvasWrapper = document.createElement("div");
  9422. canvasWrapper.style.width = div.style.width;
  9423. canvasWrapper.style.height = div.style.height;
  9424. canvasWrapper.classList.add("canvasWrapper");
  9425. if (this.annotationLayer?.div) {
  9426. div.insertBefore(canvasWrapper, this.annotationLayer.div);
  9427. } else {
  9428. div.appendChild(canvasWrapper);
  9429. }
  9430. let textLayer = null;
  9431. if (this.textLayerMode !== _ui_utils.TextLayerMode.DISABLE && this.textLayerFactory) {
  9432. const textLayerDiv = document.createElement("div");
  9433. textLayerDiv.className = "textLayer";
  9434. textLayerDiv.style.width = canvasWrapper.style.width;
  9435. textLayerDiv.style.height = canvasWrapper.style.height;
  9436. if (this.annotationLayer?.div) {
  9437. div.insertBefore(textLayerDiv, this.annotationLayer.div);
  9438. } else {
  9439. div.appendChild(textLayerDiv);
  9440. }
  9441. textLayer = this.textLayerFactory.createTextLayerBuilder(textLayerDiv, this.id - 1, this.viewport, this.textLayerMode === _ui_utils.TextLayerMode.ENABLE_ENHANCE, this.eventBus);
  9442. }
  9443. this.textLayer = textLayer;
  9444. if (this.xfaLayer?.div) {
  9445. div.appendChild(this.xfaLayer.div);
  9446. }
  9447. let renderContinueCallback = null;
  9448. if (this.renderingQueue) {
  9449. renderContinueCallback = cont => {
  9450. if (!this.renderingQueue.isHighestPriority(this)) {
  9451. this.renderingState = _pdf_rendering_queue.RenderingStates.PAUSED;
  9452. this.resume = () => {
  9453. this.renderingState = _pdf_rendering_queue.RenderingStates.RUNNING;
  9454. cont();
  9455. };
  9456. return;
  9457. }
  9458. cont();
  9459. };
  9460. }
  9461. const finishPaintTask = async (error = null) => {
  9462. if (paintTask === this.paintTask) {
  9463. this.paintTask = null;
  9464. }
  9465. if (error instanceof _pdfjsLib.RenderingCancelledException) {
  9466. this._renderError = null;
  9467. return;
  9468. }
  9469. this._renderError = error;
  9470. this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
  9471. if (this.loadingIconDiv) {
  9472. div.removeChild(this.loadingIconDiv);
  9473. delete this.loadingIconDiv;
  9474. }
  9475. this._resetZoomLayer(true);
  9476. this.eventBus.dispatch("pagerendered", {
  9477. source: this,
  9478. pageNumber: this.id,
  9479. cssTransform: false,
  9480. timestamp: performance.now(),
  9481. error: this._renderError
  9482. });
  9483. if (error) {
  9484. throw error;
  9485. }
  9486. };
  9487. const paintTask = this.renderer === _ui_utils.RendererType.SVG ? this.paintOnSvg(canvasWrapper) : this.paintOnCanvas(canvasWrapper);
  9488. paintTask.onRenderContinue = renderContinueCallback;
  9489. this.paintTask = paintTask;
  9490. const resultPromise = paintTask.promise.then(() => {
  9491. return finishPaintTask(null).then(() => {
  9492. if (textLayer) {
  9493. const readableStream = pdfPage.streamTextContent({
  9494. normalizeWhitespace: true,
  9495. includeMarkedContent: true
  9496. });
  9497. textLayer.setTextContentStream(readableStream);
  9498. textLayer.render();
  9499. }
  9500. });
  9501. }, function (reason) {
  9502. return finishPaintTask(reason);
  9503. });
  9504. if (this.annotationLayerFactory) {
  9505. if (!this.annotationLayer) {
  9506. this.annotationLayer = this.annotationLayerFactory.createAnnotationLayerBuilder(div, pdfPage, null, this.imageResourcesPath, this.renderInteractiveForms, this.l10n, null, null, null);
  9507. }
  9508. this._renderAnnotationLayer();
  9509. }
  9510. if (this.xfaLayerFactory) {
  9511. if (!this.xfaLayer) {
  9512. this.xfaLayer = this.xfaLayerFactory.createXfaLayerBuilder(div, pdfPage, null);
  9513. }
  9514. this._renderXfaLayer();
  9515. }
  9516. if (this.structTreeLayerFactory && this.textLayer && this.canvas) {
  9517. this._onTextLayerRendered = event => {
  9518. if (event.pageNumber !== this.id) {
  9519. return;
  9520. }
  9521. this.eventBus._off("textlayerrendered", this._onTextLayerRendered);
  9522. this._onTextLayerRendered = null;
  9523. if (!this.canvas) {
  9524. return;
  9525. }
  9526. this.pdfPage.getStructTree().then(tree => {
  9527. if (!tree) {
  9528. return;
  9529. }
  9530. if (!this.canvas) {
  9531. return;
  9532. }
  9533. const treeDom = this.structTreeLayer.render(tree);
  9534. treeDom.classList.add("structTree");
  9535. this.canvas.appendChild(treeDom);
  9536. });
  9537. };
  9538. this.eventBus._on("textlayerrendered", this._onTextLayerRendered);
  9539. this.structTreeLayer = this.structTreeLayerFactory.createStructTreeLayerBuilder(pdfPage);
  9540. }
  9541. div.setAttribute("data-loaded", true);
  9542. this.eventBus.dispatch("pagerender", {
  9543. source: this,
  9544. pageNumber: this.id
  9545. });
  9546. return resultPromise;
  9547. }
  9548. paintOnCanvas(canvasWrapper) {
  9549. const renderCapability = (0, _pdfjsLib.createPromiseCapability)();
  9550. const result = {
  9551. promise: renderCapability.promise,
  9552. onRenderContinue(cont) {
  9553. cont();
  9554. },
  9555. cancel() {
  9556. renderTask.cancel();
  9557. }
  9558. };
  9559. const viewport = this.viewport;
  9560. const canvas = document.createElement("canvas");
  9561. canvas.hidden = true;
  9562. let isCanvasHidden = true;
  9563. const showCanvas = function () {
  9564. if (isCanvasHidden) {
  9565. canvas.hidden = false;
  9566. isCanvasHidden = false;
  9567. }
  9568. };
  9569. canvasWrapper.appendChild(canvas);
  9570. this.canvas = canvas;
  9571. canvas.mozOpaque = true;
  9572. const ctx = canvas.getContext("2d", {
  9573. alpha: false
  9574. });
  9575. const outputScale = (0, _ui_utils.getOutputScale)(ctx);
  9576. this.outputScale = outputScale;
  9577. if (this.useOnlyCssZoom) {
  9578. const actualSizeViewport = viewport.clone({
  9579. scale: _ui_utils.CSS_UNITS
  9580. });
  9581. outputScale.sx *= actualSizeViewport.width / viewport.width;
  9582. outputScale.sy *= actualSizeViewport.height / viewport.height;
  9583. outputScale.scaled = true;
  9584. }
  9585. if (this.maxCanvasPixels > 0) {
  9586. const pixelsInViewport = viewport.width * viewport.height;
  9587. const maxScale = Math.sqrt(this.maxCanvasPixels / pixelsInViewport);
  9588. if (outputScale.sx > maxScale || outputScale.sy > maxScale) {
  9589. outputScale.sx = maxScale;
  9590. outputScale.sy = maxScale;
  9591. outputScale.scaled = true;
  9592. this.hasRestrictedScaling = true;
  9593. } else {
  9594. this.hasRestrictedScaling = false;
  9595. }
  9596. }
  9597. const sfx = (0, _ui_utils.approximateFraction)(outputScale.sx);
  9598. const sfy = (0, _ui_utils.approximateFraction)(outputScale.sy);
  9599. canvas.width = (0, _ui_utils.roundToDivide)(viewport.width * outputScale.sx, sfx[0]);
  9600. canvas.height = (0, _ui_utils.roundToDivide)(viewport.height * outputScale.sy, sfy[0]);
  9601. canvas.style.width = (0, _ui_utils.roundToDivide)(viewport.width, sfx[1]) + "px";
  9602. canvas.style.height = (0, _ui_utils.roundToDivide)(viewport.height, sfy[1]) + "px";
  9603. this.paintedViewportMap.set(canvas, viewport);
  9604. const transform = !outputScale.scaled ? null : [outputScale.sx, 0, 0, outputScale.sy, 0, 0];
  9605. const renderContext = {
  9606. canvasContext: ctx,
  9607. transform,
  9608. viewport: this.viewport,
  9609. renderInteractiveForms: this.renderInteractiveForms,
  9610. optionalContentConfigPromise: this._optionalContentConfigPromise
  9611. };
  9612. const renderTask = this.pdfPage.render(renderContext);
  9613. renderTask.onContinue = function (cont) {
  9614. showCanvas();
  9615. if (result.onRenderContinue) {
  9616. result.onRenderContinue(cont);
  9617. } else {
  9618. cont();
  9619. }
  9620. };
  9621. renderTask.promise.then(function () {
  9622. showCanvas();
  9623. renderCapability.resolve(undefined);
  9624. }, function (error) {
  9625. showCanvas();
  9626. renderCapability.reject(error);
  9627. });
  9628. return result;
  9629. }
  9630. paintOnSvg(wrapper) {
  9631. let cancelled = false;
  9632. const ensureNotCancelled = () => {
  9633. if (cancelled) {
  9634. throw new _pdfjsLib.RenderingCancelledException(`Rendering cancelled, page ${this.id}`, "svg");
  9635. }
  9636. };
  9637. const pdfPage = this.pdfPage;
  9638. const actualSizeViewport = this.viewport.clone({
  9639. scale: _ui_utils.CSS_UNITS
  9640. });
  9641. const promise = pdfPage.getOperatorList().then(opList => {
  9642. ensureNotCancelled();
  9643. const svgGfx = new _pdfjsLib.SVGGraphics(pdfPage.commonObjs, pdfPage.objs, _viewer_compatibility.viewerCompatibilityParams.disableCreateObjectURL);
  9644. return svgGfx.getSVG(opList, actualSizeViewport).then(svg => {
  9645. ensureNotCancelled();
  9646. this.svg = svg;
  9647. this.paintedViewportMap.set(svg, actualSizeViewport);
  9648. svg.style.width = wrapper.style.width;
  9649. svg.style.height = wrapper.style.height;
  9650. this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
  9651. wrapper.appendChild(svg);
  9652. });
  9653. });
  9654. return {
  9655. promise,
  9656. onRenderContinue(cont) {
  9657. cont();
  9658. },
  9659. cancel() {
  9660. cancelled = true;
  9661. }
  9662. };
  9663. }
  9664. setPageLabel(label) {
  9665. this.pageLabel = typeof label === "string" ? label : null;
  9666. if (this.pageLabel !== null) {
  9667. this.div.setAttribute("data-page-label", this.pageLabel);
  9668. } else {
  9669. this.div.removeAttribute("data-page-label");
  9670. }
  9671. }
  9672. }
  9673. exports.PDFPageView = PDFPageView;
  9674. /***/ }),
  9675. /* 32 */
  9676. /***/ ((__unused_webpack_module, exports) => {
  9677. Object.defineProperty(exports, "__esModule", ({
  9678. value: true
  9679. }));
  9680. exports.StructTreeLayerBuilder = exports.DefaultStructTreeLayerFactory = void 0;
  9681. const PDF_ROLE_TO_HTML_ROLE = {
  9682. Document: null,
  9683. DocumentFragment: null,
  9684. Part: "group",
  9685. Sect: "group",
  9686. Div: "group",
  9687. Aside: "note",
  9688. NonStruct: "none",
  9689. P: null,
  9690. H: "heading",
  9691. Title: null,
  9692. FENote: "note",
  9693. Sub: "group",
  9694. Lbl: null,
  9695. Span: null,
  9696. Em: null,
  9697. Strong: null,
  9698. Link: "link",
  9699. Annot: "note",
  9700. Form: "form",
  9701. Ruby: null,
  9702. RB: null,
  9703. RT: null,
  9704. RP: null,
  9705. Warichu: null,
  9706. WT: null,
  9707. WP: null,
  9708. L: "list",
  9709. LI: "listitem",
  9710. LBody: null,
  9711. Table: "table",
  9712. TR: "row",
  9713. TH: "columnheader",
  9714. TD: "cell",
  9715. THead: "columnheader",
  9716. TBody: null,
  9717. TFoot: null,
  9718. Caption: null,
  9719. Figure: "figure",
  9720. Formula: null,
  9721. Artifact: null
  9722. };
  9723. const HEADING_PATTERN = /^H(\d+)$/;
  9724. class StructTreeLayerBuilder {
  9725. constructor({
  9726. pdfPage
  9727. }) {
  9728. this.pdfPage = pdfPage;
  9729. }
  9730. render(structTree) {
  9731. return this._walk(structTree);
  9732. }
  9733. _setAttributes(structElement, htmlElement) {
  9734. if (structElement.alt !== undefined) {
  9735. htmlElement.setAttribute("aria-label", structElement.alt);
  9736. }
  9737. if (structElement.id !== undefined) {
  9738. htmlElement.setAttribute("aria-owns", structElement.id);
  9739. }
  9740. }
  9741. _walk(node) {
  9742. if (!node) {
  9743. return null;
  9744. }
  9745. const element = document.createElement("span");
  9746. if ("role" in node) {
  9747. const {
  9748. role
  9749. } = node;
  9750. const match = role.match(HEADING_PATTERN);
  9751. if (match) {
  9752. element.setAttribute("role", "heading");
  9753. element.setAttribute("aria-level", match[1]);
  9754. } else if (PDF_ROLE_TO_HTML_ROLE[role]) {
  9755. element.setAttribute("role", PDF_ROLE_TO_HTML_ROLE[role]);
  9756. }
  9757. }
  9758. this._setAttributes(node, element);
  9759. if (node.children) {
  9760. if (node.children.length === 1 && "id" in node.children[0]) {
  9761. this._setAttributes(node.children[0], element);
  9762. } else {
  9763. for (const kid of node.children) {
  9764. element.appendChild(this._walk(kid));
  9765. }
  9766. }
  9767. }
  9768. return element;
  9769. }
  9770. }
  9771. exports.StructTreeLayerBuilder = StructTreeLayerBuilder;
  9772. class DefaultStructTreeLayerFactory {
  9773. createStructTreeLayerBuilder(pdfPage) {
  9774. return new StructTreeLayerBuilder({
  9775. pdfPage
  9776. });
  9777. }
  9778. }
  9779. exports.DefaultStructTreeLayerFactory = DefaultStructTreeLayerFactory;
  9780. /***/ }),
  9781. /* 33 */
  9782. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  9783. Object.defineProperty(exports, "__esModule", ({
  9784. value: true
  9785. }));
  9786. exports.TextLayerBuilder = exports.DefaultTextLayerFactory = void 0;
  9787. var _pdfjsLib = __webpack_require__(5);
  9788. const EXPAND_DIVS_TIMEOUT = 300;
  9789. class TextLayerBuilder {
  9790. constructor({
  9791. textLayerDiv,
  9792. eventBus,
  9793. pageIndex,
  9794. viewport,
  9795. findController = null,
  9796. enhanceTextSelection = false
  9797. }) {
  9798. this.textLayerDiv = textLayerDiv;
  9799. this.eventBus = eventBus;
  9800. this.textContent = null;
  9801. this.textContentItemsStr = [];
  9802. this.textContentStream = null;
  9803. this.renderingDone = false;
  9804. this.pageIdx = pageIndex;
  9805. this.pageNumber = this.pageIdx + 1;
  9806. this.matches = [];
  9807. this.viewport = viewport;
  9808. this.textDivs = [];
  9809. this.findController = findController;
  9810. this.textLayerRenderTask = null;
  9811. this.enhanceTextSelection = enhanceTextSelection;
  9812. this._onUpdateTextLayerMatches = null;
  9813. this._bindMouse();
  9814. }
  9815. _finishRendering() {
  9816. this.renderingDone = true;
  9817. if (!this.enhanceTextSelection) {
  9818. const endOfContent = document.createElement("div");
  9819. endOfContent.className = "endOfContent";
  9820. this.textLayerDiv.appendChild(endOfContent);
  9821. }
  9822. this.eventBus.dispatch("textlayerrendered", {
  9823. source: this,
  9824. pageNumber: this.pageNumber,
  9825. numTextDivs: this.textDivs.length
  9826. });
  9827. }
  9828. render(timeout = 0) {
  9829. if (!(this.textContent || this.textContentStream) || this.renderingDone) {
  9830. return;
  9831. }
  9832. this.cancel();
  9833. this.textDivs = [];
  9834. const textLayerFrag = document.createDocumentFragment();
  9835. this.textLayerRenderTask = (0, _pdfjsLib.renderTextLayer)({
  9836. textContent: this.textContent,
  9837. textContentStream: this.textContentStream,
  9838. container: textLayerFrag,
  9839. viewport: this.viewport,
  9840. textDivs: this.textDivs,
  9841. textContentItemsStr: this.textContentItemsStr,
  9842. timeout,
  9843. enhanceTextSelection: this.enhanceTextSelection
  9844. });
  9845. this.textLayerRenderTask.promise.then(() => {
  9846. this.textLayerDiv.appendChild(textLayerFrag);
  9847. this._finishRendering();
  9848. this._updateMatches();
  9849. }, function (reason) {});
  9850. if (!this._onUpdateTextLayerMatches) {
  9851. this._onUpdateTextLayerMatches = evt => {
  9852. if (evt.pageIndex === this.pageIdx || evt.pageIndex === -1) {
  9853. this._updateMatches();
  9854. }
  9855. };
  9856. this.eventBus._on("updatetextlayermatches", this._onUpdateTextLayerMatches);
  9857. }
  9858. }
  9859. cancel() {
  9860. if (this.textLayerRenderTask) {
  9861. this.textLayerRenderTask.cancel();
  9862. this.textLayerRenderTask = null;
  9863. }
  9864. if (this._onUpdateTextLayerMatches) {
  9865. this.eventBus._off("updatetextlayermatches", this._onUpdateTextLayerMatches);
  9866. this._onUpdateTextLayerMatches = null;
  9867. }
  9868. }
  9869. setTextContentStream(readableStream) {
  9870. this.cancel();
  9871. this.textContentStream = readableStream;
  9872. }
  9873. setTextContent(textContent) {
  9874. this.cancel();
  9875. this.textContent = textContent;
  9876. }
  9877. _convertMatches(matches, matchesLength) {
  9878. if (!matches) {
  9879. return [];
  9880. }
  9881. const {
  9882. textContentItemsStr
  9883. } = this;
  9884. let i = 0,
  9885. iIndex = 0;
  9886. const end = textContentItemsStr.length - 1;
  9887. const result = [];
  9888. for (let m = 0, mm = matches.length; m < mm; m++) {
  9889. let matchIdx = matches[m];
  9890. while (i !== end && matchIdx >= iIndex + textContentItemsStr[i].length) {
  9891. iIndex += textContentItemsStr[i].length;
  9892. i++;
  9893. }
  9894. if (i === textContentItemsStr.length) {
  9895. console.error("Could not find a matching mapping");
  9896. }
  9897. const match = {
  9898. begin: {
  9899. divIdx: i,
  9900. offset: matchIdx - iIndex
  9901. }
  9902. };
  9903. matchIdx += matchesLength[m];
  9904. while (i !== end && matchIdx > iIndex + textContentItemsStr[i].length) {
  9905. iIndex += textContentItemsStr[i].length;
  9906. i++;
  9907. }
  9908. match.end = {
  9909. divIdx: i,
  9910. offset: matchIdx - iIndex
  9911. };
  9912. result.push(match);
  9913. }
  9914. return result;
  9915. }
  9916. _renderMatches(matches) {
  9917. if (matches.length === 0) {
  9918. return;
  9919. }
  9920. const {
  9921. findController,
  9922. pageIdx,
  9923. textContentItemsStr,
  9924. textDivs
  9925. } = this;
  9926. const isSelectedPage = pageIdx === findController.selected.pageIdx;
  9927. const selectedMatchIdx = findController.selected.matchIdx;
  9928. const highlightAll = findController.state.highlightAll;
  9929. let prevEnd = null;
  9930. const infinity = {
  9931. divIdx: -1,
  9932. offset: undefined
  9933. };
  9934. function beginText(begin, className) {
  9935. const divIdx = begin.divIdx;
  9936. textDivs[divIdx].textContent = "";
  9937. return appendTextToDiv(divIdx, 0, begin.offset, className);
  9938. }
  9939. function appendTextToDiv(divIdx, fromOffset, toOffset, className) {
  9940. const div = textDivs[divIdx];
  9941. const content = textContentItemsStr[divIdx].substring(fromOffset, toOffset);
  9942. const node = document.createTextNode(content);
  9943. if (className) {
  9944. const span = document.createElement("span");
  9945. span.className = `${className} appended`;
  9946. span.appendChild(node);
  9947. div.appendChild(span);
  9948. return className.includes("selected") ? span.offsetLeft : 0;
  9949. }
  9950. div.appendChild(node);
  9951. return 0;
  9952. }
  9953. let i0 = selectedMatchIdx,
  9954. i1 = i0 + 1;
  9955. if (highlightAll) {
  9956. i0 = 0;
  9957. i1 = matches.length;
  9958. } else if (!isSelectedPage) {
  9959. return;
  9960. }
  9961. for (let i = i0; i < i1; i++) {
  9962. const match = matches[i];
  9963. const begin = match.begin;
  9964. const end = match.end;
  9965. const isSelected = isSelectedPage && i === selectedMatchIdx;
  9966. const highlightSuffix = isSelected ? " selected" : "";
  9967. let selectedLeft = 0;
  9968. if (!prevEnd || begin.divIdx !== prevEnd.divIdx) {
  9969. if (prevEnd !== null) {
  9970. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset);
  9971. }
  9972. beginText(begin);
  9973. } else {
  9974. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, begin.offset);
  9975. }
  9976. if (begin.divIdx === end.divIdx) {
  9977. selectedLeft = appendTextToDiv(begin.divIdx, begin.offset, end.offset, "highlight" + highlightSuffix);
  9978. } else {
  9979. selectedLeft = appendTextToDiv(begin.divIdx, begin.offset, infinity.offset, "highlight begin" + highlightSuffix);
  9980. for (let n0 = begin.divIdx + 1, n1 = end.divIdx; n0 < n1; n0++) {
  9981. textDivs[n0].className = "highlight middle" + highlightSuffix;
  9982. }
  9983. beginText(end, "highlight end" + highlightSuffix);
  9984. }
  9985. prevEnd = end;
  9986. if (isSelected) {
  9987. findController.scrollMatchIntoView({
  9988. element: textDivs[begin.divIdx],
  9989. selectedLeft,
  9990. pageIndex: pageIdx,
  9991. matchIndex: selectedMatchIdx
  9992. });
  9993. }
  9994. }
  9995. if (prevEnd) {
  9996. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset);
  9997. }
  9998. }
  9999. _updateMatches() {
  10000. if (!this.renderingDone) {
  10001. return;
  10002. }
  10003. const {
  10004. findController,
  10005. matches,
  10006. pageIdx,
  10007. textContentItemsStr,
  10008. textDivs
  10009. } = this;
  10010. let clearedUntilDivIdx = -1;
  10011. for (let i = 0, ii = matches.length; i < ii; i++) {
  10012. const match = matches[i];
  10013. const begin = Math.max(clearedUntilDivIdx, match.begin.divIdx);
  10014. for (let n = begin, end = match.end.divIdx; n <= end; n++) {
  10015. const div = textDivs[n];
  10016. div.textContent = textContentItemsStr[n];
  10017. div.className = "";
  10018. }
  10019. clearedUntilDivIdx = match.end.divIdx + 1;
  10020. }
  10021. if (!findController?.highlightMatches) {
  10022. return;
  10023. }
  10024. const pageMatches = findController.pageMatches[pageIdx] || null;
  10025. const pageMatchesLength = findController.pageMatchesLength[pageIdx] || null;
  10026. this.matches = this._convertMatches(pageMatches, pageMatchesLength);
  10027. this._renderMatches(this.matches);
  10028. }
  10029. _bindMouse() {
  10030. const div = this.textLayerDiv;
  10031. let expandDivsTimer = null;
  10032. div.addEventListener("mousedown", evt => {
  10033. if (this.enhanceTextSelection && this.textLayerRenderTask) {
  10034. this.textLayerRenderTask.expandTextDivs(true);
  10035. if (expandDivsTimer) {
  10036. clearTimeout(expandDivsTimer);
  10037. expandDivsTimer = null;
  10038. }
  10039. return;
  10040. }
  10041. const end = div.querySelector(".endOfContent");
  10042. if (!end) {
  10043. return;
  10044. }
  10045. let adjustTop = evt.target !== div;
  10046. adjustTop = adjustTop && window.getComputedStyle(end).getPropertyValue("-moz-user-select") !== "none";
  10047. if (adjustTop) {
  10048. const divBounds = div.getBoundingClientRect();
  10049. const r = Math.max(0, (evt.pageY - divBounds.top) / divBounds.height);
  10050. end.style.top = (r * 100).toFixed(2) + "%";
  10051. }
  10052. end.classList.add("active");
  10053. });
  10054. div.addEventListener("mouseup", () => {
  10055. if (this.enhanceTextSelection && this.textLayerRenderTask) {
  10056. expandDivsTimer = setTimeout(() => {
  10057. if (this.textLayerRenderTask) {
  10058. this.textLayerRenderTask.expandTextDivs(false);
  10059. }
  10060. expandDivsTimer = null;
  10061. }, EXPAND_DIVS_TIMEOUT);
  10062. return;
  10063. }
  10064. const end = div.querySelector(".endOfContent");
  10065. if (!end) {
  10066. return;
  10067. }
  10068. end.style.top = "";
  10069. end.classList.remove("active");
  10070. });
  10071. }
  10072. }
  10073. exports.TextLayerBuilder = TextLayerBuilder;
  10074. class DefaultTextLayerFactory {
  10075. createTextLayerBuilder(textLayerDiv, pageIndex, viewport, enhanceTextSelection = false, eventBus) {
  10076. return new TextLayerBuilder({
  10077. textLayerDiv,
  10078. pageIndex,
  10079. viewport,
  10080. enhanceTextSelection,
  10081. eventBus
  10082. });
  10083. }
  10084. }
  10085. exports.DefaultTextLayerFactory = DefaultTextLayerFactory;
  10086. /***/ }),
  10087. /* 34 */
  10088. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10089. Object.defineProperty(exports, "__esModule", ({
  10090. value: true
  10091. }));
  10092. exports.XfaLayerBuilder = exports.DefaultXfaLayerFactory = void 0;
  10093. var _pdfjsLib = __webpack_require__(5);
  10094. class XfaLayerBuilder {
  10095. constructor({
  10096. pageDiv,
  10097. pdfPage,
  10098. xfaHtml,
  10099. annotationStorage
  10100. }) {
  10101. this.pageDiv = pageDiv;
  10102. this.pdfPage = pdfPage;
  10103. this.xfaHtml = xfaHtml;
  10104. this.annotationStorage = annotationStorage;
  10105. this.div = null;
  10106. this._cancelled = false;
  10107. }
  10108. render(viewport, intent = "display") {
  10109. if (intent === "print") {
  10110. const parameters = {
  10111. viewport: viewport.clone({
  10112. dontFlip: true
  10113. }),
  10114. div: this.div,
  10115. xfa: this.xfaHtml,
  10116. page: null,
  10117. annotationStorage: this.annotationStorage,
  10118. intent
  10119. };
  10120. const div = document.createElement("div");
  10121. this.pageDiv.appendChild(div);
  10122. parameters.div = div;
  10123. _pdfjsLib.XfaLayer.render(parameters);
  10124. return Promise.resolve();
  10125. }
  10126. return this.pdfPage.getXfa().then(xfa => {
  10127. if (this._cancelled) {
  10128. return;
  10129. }
  10130. const parameters = {
  10131. viewport: viewport.clone({
  10132. dontFlip: true
  10133. }),
  10134. div: this.div,
  10135. xfa,
  10136. page: this.pdfPage,
  10137. annotationStorage: this.annotationStorage,
  10138. intent
  10139. };
  10140. if (this.div) {
  10141. _pdfjsLib.XfaLayer.update(parameters);
  10142. } else {
  10143. this.div = document.createElement("div");
  10144. this.pageDiv.appendChild(this.div);
  10145. parameters.div = this.div;
  10146. _pdfjsLib.XfaLayer.render(parameters);
  10147. }
  10148. }).catch(error => {
  10149. console.error(error);
  10150. });
  10151. }
  10152. cancel() {
  10153. this._cancelled = true;
  10154. }
  10155. hide() {
  10156. if (!this.div) {
  10157. return;
  10158. }
  10159. this.div.hidden = true;
  10160. }
  10161. }
  10162. exports.XfaLayerBuilder = XfaLayerBuilder;
  10163. class DefaultXfaLayerFactory {
  10164. createXfaLayerBuilder(pageDiv, pdfPage, annotationStorage = null, xfaHtml = null) {
  10165. return new XfaLayerBuilder({
  10166. pageDiv,
  10167. pdfPage,
  10168. annotationStorage,
  10169. xfaHtml
  10170. });
  10171. }
  10172. }
  10173. exports.DefaultXfaLayerFactory = DefaultXfaLayerFactory;
  10174. /***/ }),
  10175. /* 35 */
  10176. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10177. Object.defineProperty(exports, "__esModule", ({
  10178. value: true
  10179. }));
  10180. exports.SecondaryToolbar = void 0;
  10181. var _ui_utils = __webpack_require__(4);
  10182. var _pdf_cursor_tools = __webpack_require__(6);
  10183. var _pdf_single_page_viewer = __webpack_require__(36);
  10184. class SecondaryToolbar {
  10185. constructor(options, mainContainer, eventBus) {
  10186. this.toolbar = options.toolbar;
  10187. this.toggleButton = options.toggleButton;
  10188. this.toolbarButtonContainer = options.toolbarButtonContainer;
  10189. this.buttons = [{
  10190. element: options.presentationModeButton,
  10191. eventName: "presentationmode",
  10192. close: true
  10193. }, {
  10194. element: options.openFileButton,
  10195. eventName: "openfile",
  10196. close: true
  10197. }, {
  10198. element: options.printButton,
  10199. eventName: "print",
  10200. close: true
  10201. }, {
  10202. element: options.downloadButton,
  10203. eventName: "download",
  10204. close: true
  10205. }, {
  10206. element: options.viewBookmarkButton,
  10207. eventName: null,
  10208. close: true
  10209. }, {
  10210. element: options.firstPageButton,
  10211. eventName: "firstpage",
  10212. close: true
  10213. }, {
  10214. element: options.lastPageButton,
  10215. eventName: "lastpage",
  10216. close: true
  10217. }, {
  10218. element: options.pageRotateCwButton,
  10219. eventName: "rotatecw",
  10220. close: false
  10221. }, {
  10222. element: options.pageRotateCcwButton,
  10223. eventName: "rotateccw",
  10224. close: false
  10225. }, {
  10226. element: options.cursorSelectToolButton,
  10227. eventName: "switchcursortool",
  10228. eventDetails: {
  10229. tool: _pdf_cursor_tools.CursorTool.SELECT
  10230. },
  10231. close: true
  10232. }, {
  10233. element: options.cursorHandToolButton,
  10234. eventName: "switchcursortool",
  10235. eventDetails: {
  10236. tool: _pdf_cursor_tools.CursorTool.HAND
  10237. },
  10238. close: true
  10239. }, {
  10240. element: options.scrollVerticalButton,
  10241. eventName: "switchscrollmode",
  10242. eventDetails: {
  10243. mode: _ui_utils.ScrollMode.VERTICAL
  10244. },
  10245. close: true
  10246. }, {
  10247. element: options.scrollHorizontalButton,
  10248. eventName: "switchscrollmode",
  10249. eventDetails: {
  10250. mode: _ui_utils.ScrollMode.HORIZONTAL
  10251. },
  10252. close: true
  10253. }, {
  10254. element: options.scrollWrappedButton,
  10255. eventName: "switchscrollmode",
  10256. eventDetails: {
  10257. mode: _ui_utils.ScrollMode.WRAPPED
  10258. },
  10259. close: true
  10260. }, {
  10261. element: options.spreadNoneButton,
  10262. eventName: "switchspreadmode",
  10263. eventDetails: {
  10264. mode: _ui_utils.SpreadMode.NONE
  10265. },
  10266. close: true
  10267. }, {
  10268. element: options.spreadOddButton,
  10269. eventName: "switchspreadmode",
  10270. eventDetails: {
  10271. mode: _ui_utils.SpreadMode.ODD
  10272. },
  10273. close: true
  10274. }, {
  10275. element: options.spreadEvenButton,
  10276. eventName: "switchspreadmode",
  10277. eventDetails: {
  10278. mode: _ui_utils.SpreadMode.EVEN
  10279. },
  10280. close: true
  10281. }, {
  10282. element: options.documentPropertiesButton,
  10283. eventName: "documentproperties",
  10284. close: true
  10285. }];
  10286. this.items = {
  10287. firstPage: options.firstPageButton,
  10288. lastPage: options.lastPageButton,
  10289. pageRotateCw: options.pageRotateCwButton,
  10290. pageRotateCcw: options.pageRotateCcwButton
  10291. };
  10292. this.mainContainer = mainContainer;
  10293. this.eventBus = eventBus;
  10294. this.opened = false;
  10295. this.containerHeight = null;
  10296. this.previousContainerHeight = null;
  10297. this.reset();
  10298. this._bindClickListeners();
  10299. this._bindCursorToolsListener(options);
  10300. this._bindScrollModeListener(options);
  10301. this._bindSpreadModeListener(options);
  10302. this.eventBus._on("resize", this._setMaxHeight.bind(this));
  10303. this.eventBus._on("baseviewerinit", evt => {
  10304. if (evt.source instanceof _pdf_single_page_viewer.PDFSinglePageViewer) {
  10305. this.toolbarButtonContainer.classList.add("hiddenScrollModeButtons", "hiddenSpreadModeButtons");
  10306. } else {
  10307. this.toolbarButtonContainer.classList.remove("hiddenScrollModeButtons", "hiddenSpreadModeButtons");
  10308. }
  10309. });
  10310. }
  10311. get isOpen() {
  10312. return this.opened;
  10313. }
  10314. setPageNumber(pageNumber) {
  10315. this.pageNumber = pageNumber;
  10316. this._updateUIState();
  10317. }
  10318. setPagesCount(pagesCount) {
  10319. this.pagesCount = pagesCount;
  10320. this._updateUIState();
  10321. }
  10322. reset() {
  10323. this.pageNumber = 0;
  10324. this.pagesCount = 0;
  10325. this._updateUIState();
  10326. this.eventBus.dispatch("secondarytoolbarreset", {
  10327. source: this
  10328. });
  10329. }
  10330. _updateUIState() {
  10331. this.items.firstPage.disabled = this.pageNumber <= 1;
  10332. this.items.lastPage.disabled = this.pageNumber >= this.pagesCount;
  10333. this.items.pageRotateCw.disabled = this.pagesCount === 0;
  10334. this.items.pageRotateCcw.disabled = this.pagesCount === 0;
  10335. }
  10336. _bindClickListeners() {
  10337. this.toggleButton.addEventListener("click", this.toggle.bind(this));
  10338. for (const {
  10339. element,
  10340. eventName,
  10341. close,
  10342. eventDetails
  10343. } of this.buttons) {
  10344. element.addEventListener("click", evt => {
  10345. if (eventName !== null) {
  10346. const details = {
  10347. source: this
  10348. };
  10349. for (const property in eventDetails) {
  10350. details[property] = eventDetails[property];
  10351. }
  10352. this.eventBus.dispatch(eventName, details);
  10353. }
  10354. if (close) {
  10355. this.close();
  10356. }
  10357. });
  10358. }
  10359. }
  10360. _bindCursorToolsListener(buttons) {
  10361. this.eventBus._on("cursortoolchanged", function ({
  10362. tool
  10363. }) {
  10364. buttons.cursorSelectToolButton.classList.toggle("toggled", tool === _pdf_cursor_tools.CursorTool.SELECT);
  10365. buttons.cursorHandToolButton.classList.toggle("toggled", tool === _pdf_cursor_tools.CursorTool.HAND);
  10366. });
  10367. }
  10368. _bindScrollModeListener(buttons) {
  10369. function scrollModeChanged({
  10370. mode
  10371. }) {
  10372. buttons.scrollVerticalButton.classList.toggle("toggled", mode === _ui_utils.ScrollMode.VERTICAL);
  10373. buttons.scrollHorizontalButton.classList.toggle("toggled", mode === _ui_utils.ScrollMode.HORIZONTAL);
  10374. buttons.scrollWrappedButton.classList.toggle("toggled", mode === _ui_utils.ScrollMode.WRAPPED);
  10375. const isScrollModeHorizontal = mode === _ui_utils.ScrollMode.HORIZONTAL;
  10376. buttons.spreadNoneButton.disabled = isScrollModeHorizontal;
  10377. buttons.spreadOddButton.disabled = isScrollModeHorizontal;
  10378. buttons.spreadEvenButton.disabled = isScrollModeHorizontal;
  10379. }
  10380. this.eventBus._on("scrollmodechanged", scrollModeChanged);
  10381. this.eventBus._on("secondarytoolbarreset", evt => {
  10382. if (evt.source === this) {
  10383. scrollModeChanged({
  10384. mode: _ui_utils.ScrollMode.VERTICAL
  10385. });
  10386. }
  10387. });
  10388. }
  10389. _bindSpreadModeListener(buttons) {
  10390. function spreadModeChanged({
  10391. mode
  10392. }) {
  10393. buttons.spreadNoneButton.classList.toggle("toggled", mode === _ui_utils.SpreadMode.NONE);
  10394. buttons.spreadOddButton.classList.toggle("toggled", mode === _ui_utils.SpreadMode.ODD);
  10395. buttons.spreadEvenButton.classList.toggle("toggled", mode === _ui_utils.SpreadMode.EVEN);
  10396. }
  10397. this.eventBus._on("spreadmodechanged", spreadModeChanged);
  10398. this.eventBus._on("secondarytoolbarreset", evt => {
  10399. if (evt.source === this) {
  10400. spreadModeChanged({
  10401. mode: _ui_utils.SpreadMode.NONE
  10402. });
  10403. }
  10404. });
  10405. }
  10406. open() {
  10407. if (this.opened) {
  10408. return;
  10409. }
  10410. this.opened = true;
  10411. this._setMaxHeight();
  10412. this.toggleButton.classList.add("toggled");
  10413. this.toggleButton.setAttribute("aria-expanded", "true");
  10414. this.toolbar.classList.remove("hidden");
  10415. }
  10416. close() {
  10417. if (!this.opened) {
  10418. return;
  10419. }
  10420. this.opened = false;
  10421. this.toolbar.classList.add("hidden");
  10422. this.toggleButton.classList.remove("toggled");
  10423. this.toggleButton.setAttribute("aria-expanded", "false");
  10424. }
  10425. toggle() {
  10426. if (this.opened) {
  10427. this.close();
  10428. } else {
  10429. this.open();
  10430. }
  10431. }
  10432. _setMaxHeight() {
  10433. if (!this.opened) {
  10434. return;
  10435. }
  10436. this.containerHeight = this.mainContainer.clientHeight;
  10437. if (this.containerHeight === this.previousContainerHeight) {
  10438. return;
  10439. }
  10440. this.toolbarButtonContainer.style.maxHeight = `${this.containerHeight - _ui_utils.SCROLLBAR_PADDING}px`;
  10441. this.previousContainerHeight = this.containerHeight;
  10442. }
  10443. }
  10444. exports.SecondaryToolbar = SecondaryToolbar;
  10445. /***/ }),
  10446. /* 36 */
  10447. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10448. Object.defineProperty(exports, "__esModule", ({
  10449. value: true
  10450. }));
  10451. exports.PDFSinglePageViewer = void 0;
  10452. var _base_viewer = __webpack_require__(28);
  10453. var _pdfjsLib = __webpack_require__(5);
  10454. class PDFSinglePageViewer extends _base_viewer.BaseViewer {
  10455. constructor(options) {
  10456. super(options);
  10457. this.eventBus._on("pagesinit", evt => {
  10458. this._ensurePageViewVisible();
  10459. });
  10460. }
  10461. get _viewerElement() {
  10462. return (0, _pdfjsLib.shadow)(this, "_viewerElement", this._shadowViewer);
  10463. }
  10464. get _pageWidthScaleFactor() {
  10465. return 1;
  10466. }
  10467. _resetView() {
  10468. super._resetView();
  10469. this._previousPageNumber = 1;
  10470. this._shadowViewer = document.createDocumentFragment();
  10471. this._updateScrollDown = null;
  10472. }
  10473. _ensurePageViewVisible() {
  10474. const pageView = this._pages[this._currentPageNumber - 1];
  10475. const previousPageView = this._pages[this._previousPageNumber - 1];
  10476. const viewerNodes = this.viewer.childNodes;
  10477. switch (viewerNodes.length) {
  10478. case 0:
  10479. this.viewer.appendChild(pageView.div);
  10480. break;
  10481. case 1:
  10482. if (viewerNodes[0] !== previousPageView.div) {
  10483. throw new Error("_ensurePageViewVisible: Unexpected previously visible page.");
  10484. }
  10485. if (pageView === previousPageView) {
  10486. break;
  10487. }
  10488. this._shadowViewer.appendChild(previousPageView.div);
  10489. this.viewer.appendChild(pageView.div);
  10490. this.container.scrollTop = 0;
  10491. break;
  10492. default:
  10493. throw new Error("_ensurePageViewVisible: Only one page should be visible at a time.");
  10494. }
  10495. this._previousPageNumber = this._currentPageNumber;
  10496. }
  10497. _scrollUpdate() {
  10498. if (this._updateScrollDown) {
  10499. this._updateScrollDown();
  10500. }
  10501. super._scrollUpdate();
  10502. }
  10503. _scrollIntoView({
  10504. pageDiv,
  10505. pageSpot = null,
  10506. pageNumber = null
  10507. }) {
  10508. if (pageNumber) {
  10509. this._setCurrentPageNumber(pageNumber);
  10510. }
  10511. const scrolledDown = this._currentPageNumber >= this._previousPageNumber;
  10512. this._ensurePageViewVisible();
  10513. this.update();
  10514. super._scrollIntoView({
  10515. pageDiv,
  10516. pageSpot,
  10517. pageNumber
  10518. });
  10519. this._updateScrollDown = () => {
  10520. this.scroll.down = scrolledDown;
  10521. this._updateScrollDown = null;
  10522. };
  10523. }
  10524. _getVisiblePages() {
  10525. return this._getCurrentVisiblePage();
  10526. }
  10527. _updateHelper(visiblePages) {}
  10528. get _isScrollModeHorizontal() {
  10529. return (0, _pdfjsLib.shadow)(this, "_isScrollModeHorizontal", false);
  10530. }
  10531. _updateScrollMode() {}
  10532. _updateSpreadMode() {}
  10533. _getPageAdvance() {
  10534. return 1;
  10535. }
  10536. }
  10537. exports.PDFSinglePageViewer = PDFSinglePageViewer;
  10538. /***/ }),
  10539. /* 37 */
  10540. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10541. Object.defineProperty(exports, "__esModule", ({
  10542. value: true
  10543. }));
  10544. exports.Toolbar = void 0;
  10545. var _ui_utils = __webpack_require__(4);
  10546. const PAGE_NUMBER_LOADING_INDICATOR = "visiblePageIsLoading";
  10547. const SCALE_SELECT_CONTAINER_WIDTH = 140;
  10548. const SCALE_SELECT_WIDTH = 162;
  10549. class Toolbar {
  10550. constructor(options, eventBus, l10n) {
  10551. this.toolbar = options.container;
  10552. this.eventBus = eventBus;
  10553. this.l10n = l10n;
  10554. this.buttons = [{
  10555. element: options.previous,
  10556. eventName: "previouspage"
  10557. }, {
  10558. element: options.next,
  10559. eventName: "nextpage"
  10560. }, {
  10561. element: options.zoomIn,
  10562. eventName: "zoomin"
  10563. }, {
  10564. element: options.zoomOut,
  10565. eventName: "zoomout"
  10566. }, {
  10567. element: options.openFile,
  10568. eventName: "openfile"
  10569. }, {
  10570. element: options.print,
  10571. eventName: "print"
  10572. }, {
  10573. element: options.presentationModeButton,
  10574. eventName: "presentationmode"
  10575. }, {
  10576. element: options.download,
  10577. eventName: "download"
  10578. }, {
  10579. element: options.viewBookmark,
  10580. eventName: null
  10581. }];
  10582. this.items = {
  10583. numPages: options.numPages,
  10584. pageNumber: options.pageNumber,
  10585. scaleSelectContainer: options.scaleSelectContainer,
  10586. scaleSelect: options.scaleSelect,
  10587. customScaleOption: options.customScaleOption,
  10588. previous: options.previous,
  10589. next: options.next,
  10590. zoomIn: options.zoomIn,
  10591. zoomOut: options.zoomOut
  10592. };
  10593. this._wasLocalized = false;
  10594. this.reset();
  10595. this._bindListeners();
  10596. }
  10597. setPageNumber(pageNumber, pageLabel) {
  10598. this.pageNumber = pageNumber;
  10599. this.pageLabel = pageLabel;
  10600. this._updateUIState(false);
  10601. }
  10602. setPagesCount(pagesCount, hasPageLabels) {
  10603. this.pagesCount = pagesCount;
  10604. this.hasPageLabels = hasPageLabels;
  10605. this._updateUIState(true);
  10606. }
  10607. setPageScale(pageScaleValue, pageScale) {
  10608. this.pageScaleValue = (pageScaleValue || pageScale).toString();
  10609. this.pageScale = pageScale;
  10610. this._updateUIState(false);
  10611. }
  10612. reset() {
  10613. this.pageNumber = 0;
  10614. this.pageLabel = null;
  10615. this.hasPageLabels = false;
  10616. this.pagesCount = 0;
  10617. this.pageScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  10618. this.pageScale = _ui_utils.DEFAULT_SCALE;
  10619. this._updateUIState(true);
  10620. this.updateLoadingIndicatorState();
  10621. }
  10622. _bindListeners() {
  10623. const {
  10624. pageNumber,
  10625. scaleSelect
  10626. } = this.items;
  10627. const self = this;
  10628. for (const {
  10629. element,
  10630. eventName
  10631. } of this.buttons) {
  10632. element.addEventListener("click", evt => {
  10633. if (eventName !== null) {
  10634. this.eventBus.dispatch(eventName, {
  10635. source: this
  10636. });
  10637. }
  10638. });
  10639. }
  10640. pageNumber.addEventListener("click", function () {
  10641. this.select();
  10642. });
  10643. pageNumber.addEventListener("change", function () {
  10644. self.eventBus.dispatch("pagenumberchanged", {
  10645. source: self,
  10646. value: this.value
  10647. });
  10648. });
  10649. scaleSelect.addEventListener("change", function () {
  10650. if (this.value === "custom") {
  10651. return;
  10652. }
  10653. self.eventBus.dispatch("scalechanged", {
  10654. source: self,
  10655. value: this.value
  10656. });
  10657. });
  10658. scaleSelect.addEventListener("click", function (evt) {
  10659. const target = evt.target;
  10660. if (this.value === self.pageScaleValue && target.tagName.toUpperCase() === "OPTION") {
  10661. this.blur();
  10662. }
  10663. });
  10664. scaleSelect.oncontextmenu = _ui_utils.noContextMenuHandler;
  10665. this.eventBus._on("localized", () => {
  10666. this._wasLocalized = true;
  10667. this._adjustScaleWidth();
  10668. this._updateUIState(true);
  10669. });
  10670. }
  10671. _updateUIState(resetNumPages = false) {
  10672. if (!this._wasLocalized) {
  10673. return;
  10674. }
  10675. const {
  10676. pageNumber,
  10677. pagesCount,
  10678. pageScaleValue,
  10679. pageScale,
  10680. items
  10681. } = this;
  10682. if (resetNumPages) {
  10683. if (this.hasPageLabels) {
  10684. items.pageNumber.type = "text";
  10685. } else {
  10686. items.pageNumber.type = "number";
  10687. this.l10n.get("of_pages", {
  10688. pagesCount
  10689. }).then(msg => {
  10690. items.numPages.textContent = msg;
  10691. });
  10692. }
  10693. items.pageNumber.max = pagesCount;
  10694. }
  10695. if (this.hasPageLabels) {
  10696. items.pageNumber.value = this.pageLabel;
  10697. this.l10n.get("page_of_pages", {
  10698. pageNumber,
  10699. pagesCount
  10700. }).then(msg => {
  10701. items.numPages.textContent = msg;
  10702. });
  10703. } else {
  10704. items.pageNumber.value = pageNumber;
  10705. }
  10706. items.previous.disabled = pageNumber <= 1;
  10707. items.next.disabled = pageNumber >= pagesCount;
  10708. items.zoomOut.disabled = pageScale <= _ui_utils.MIN_SCALE;
  10709. items.zoomIn.disabled = pageScale >= _ui_utils.MAX_SCALE;
  10710. this.l10n.get("page_scale_percent", {
  10711. scale: Math.round(pageScale * 10000) / 100
  10712. }).then(msg => {
  10713. let predefinedValueFound = false;
  10714. for (const option of items.scaleSelect.options) {
  10715. if (option.value !== pageScaleValue) {
  10716. option.selected = false;
  10717. continue;
  10718. }
  10719. option.selected = true;
  10720. predefinedValueFound = true;
  10721. }
  10722. if (!predefinedValueFound) {
  10723. items.customScaleOption.textContent = msg;
  10724. items.customScaleOption.selected = true;
  10725. }
  10726. });
  10727. }
  10728. updateLoadingIndicatorState(loading = false) {
  10729. const pageNumberInput = this.items.pageNumber;
  10730. pageNumberInput.classList.toggle(PAGE_NUMBER_LOADING_INDICATOR, loading);
  10731. }
  10732. async _adjustScaleWidth() {
  10733. const {
  10734. items,
  10735. l10n
  10736. } = this;
  10737. const predefinedValuesPromise = Promise.all([l10n.get("page_scale_auto"), l10n.get("page_scale_actual"), l10n.get("page_scale_fit"), l10n.get("page_scale_width")]);
  10738. let canvas = document.createElement("canvas");
  10739. canvas.mozOpaque = true;
  10740. let ctx = canvas.getContext("2d", {
  10741. alpha: false
  10742. });
  10743. await _ui_utils.animationStarted;
  10744. const {
  10745. fontSize,
  10746. fontFamily
  10747. } = getComputedStyle(items.scaleSelect);
  10748. ctx.font = `${fontSize} ${fontFamily}`;
  10749. let maxWidth = 0;
  10750. for (const predefinedValue of await predefinedValuesPromise) {
  10751. const {
  10752. width
  10753. } = ctx.measureText(predefinedValue);
  10754. if (width > maxWidth) {
  10755. maxWidth = width;
  10756. }
  10757. }
  10758. const overflow = SCALE_SELECT_WIDTH - SCALE_SELECT_CONTAINER_WIDTH;
  10759. maxWidth += 2 * overflow;
  10760. if (maxWidth > SCALE_SELECT_CONTAINER_WIDTH) {
  10761. items.scaleSelect.style.width = `${maxWidth + overflow}px`;
  10762. items.scaleSelectContainer.style.width = `${maxWidth}px`;
  10763. }
  10764. canvas.width = 0;
  10765. canvas.height = 0;
  10766. canvas = ctx = null;
  10767. }
  10768. }
  10769. exports.Toolbar = Toolbar;
  10770. /***/ }),
  10771. /* 38 */
  10772. /***/ ((__unused_webpack_module, exports) => {
  10773. Object.defineProperty(exports, "__esModule", ({
  10774. value: true
  10775. }));
  10776. exports.ViewHistory = void 0;
  10777. const DEFAULT_VIEW_HISTORY_CACHE_SIZE = 20;
  10778. class ViewHistory {
  10779. constructor(fingerprint, cacheSize = DEFAULT_VIEW_HISTORY_CACHE_SIZE) {
  10780. this.fingerprint = fingerprint;
  10781. this.cacheSize = cacheSize;
  10782. this._initializedPromise = this._readFromStorage().then(databaseStr => {
  10783. const database = JSON.parse(databaseStr || "{}");
  10784. let index = -1;
  10785. if (!Array.isArray(database.files)) {
  10786. database.files = [];
  10787. } else {
  10788. while (database.files.length >= this.cacheSize) {
  10789. database.files.shift();
  10790. }
  10791. for (let i = 0, ii = database.files.length; i < ii; i++) {
  10792. const branch = database.files[i];
  10793. if (branch.fingerprint === this.fingerprint) {
  10794. index = i;
  10795. break;
  10796. }
  10797. }
  10798. }
  10799. if (index === -1) {
  10800. index = database.files.push({
  10801. fingerprint: this.fingerprint
  10802. }) - 1;
  10803. }
  10804. this.file = database.files[index];
  10805. this.database = database;
  10806. });
  10807. }
  10808. async _writeToStorage() {
  10809. const databaseStr = JSON.stringify(this.database);
  10810. localStorage.setItem("pdfjs.history", databaseStr);
  10811. }
  10812. async _readFromStorage() {
  10813. return localStorage.getItem("pdfjs.history");
  10814. }
  10815. async set(name, val) {
  10816. await this._initializedPromise;
  10817. this.file[name] = val;
  10818. return this._writeToStorage();
  10819. }
  10820. async setMultiple(properties) {
  10821. await this._initializedPromise;
  10822. for (const name in properties) {
  10823. this.file[name] = properties[name];
  10824. }
  10825. return this._writeToStorage();
  10826. }
  10827. async get(name, defaultValue) {
  10828. await this._initializedPromise;
  10829. const val = this.file[name];
  10830. return val !== undefined ? val : defaultValue;
  10831. }
  10832. async getMultiple(properties) {
  10833. await this._initializedPromise;
  10834. const values = Object.create(null);
  10835. for (const name in properties) {
  10836. const val = this.file[name];
  10837. values[name] = val !== undefined ? val : properties[name];
  10838. }
  10839. return values;
  10840. }
  10841. }
  10842. exports.ViewHistory = ViewHistory;
  10843. /***/ }),
  10844. /* 39 */
  10845. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10846. Object.defineProperty(exports, "__esModule", ({
  10847. value: true
  10848. }));
  10849. exports.GenericCom = void 0;
  10850. var _app = __webpack_require__(3);
  10851. var _preferences = __webpack_require__(40);
  10852. var _download_manager = __webpack_require__(41);
  10853. var _genericl10n = __webpack_require__(42);
  10854. var _generic_scripting = __webpack_require__(44);
  10855. ;
  10856. const GenericCom = {};
  10857. exports.GenericCom = GenericCom;
  10858. class GenericPreferences extends _preferences.BasePreferences {
  10859. async _writeToStorage(prefObj) {
  10860. localStorage.setItem("pdfjs.preferences", JSON.stringify(prefObj));
  10861. }
  10862. async _readFromStorage(prefObj) {
  10863. return JSON.parse(localStorage.getItem("pdfjs.preferences"));
  10864. }
  10865. }
  10866. class GenericExternalServices extends _app.DefaultExternalServices {
  10867. static createDownloadManager(options) {
  10868. return new _download_manager.DownloadManager();
  10869. }
  10870. static createPreferences() {
  10871. return new GenericPreferences();
  10872. }
  10873. static createL10n({
  10874. locale = "en-US"
  10875. }) {
  10876. return new _genericl10n.GenericL10n(locale);
  10877. }
  10878. static createScripting({
  10879. sandboxBundleSrc
  10880. }) {
  10881. return new _generic_scripting.GenericScripting(sandboxBundleSrc);
  10882. }
  10883. }
  10884. _app.PDFViewerApplication.externalServices = GenericExternalServices;
  10885. /***/ }),
  10886. /* 40 */
  10887. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10888. Object.defineProperty(exports, "__esModule", ({
  10889. value: true
  10890. }));
  10891. exports.BasePreferences = void 0;
  10892. var _app_options = __webpack_require__(1);
  10893. class BasePreferences {
  10894. constructor() {
  10895. if (this.constructor === BasePreferences) {
  10896. throw new Error("Cannot initialize BasePreferences.");
  10897. }
  10898. Object.defineProperty(this, "defaults", {
  10899. value: Object.freeze({
  10900. "cursorToolOnLoad": 0,
  10901. "defaultZoomValue": "",
  10902. "disablePageLabels": false,
  10903. "enablePermissions": false,
  10904. "enablePrintAutoRotate": true,
  10905. "enableScripting": true,
  10906. "externalLinkTarget": 0,
  10907. "historyUpdateUrl": false,
  10908. "ignoreDestinationZoom": false,
  10909. "pdfBugEnabled": false,
  10910. "renderer": "canvas",
  10911. "renderInteractiveForms": true,
  10912. "sidebarViewOnLoad": -1,
  10913. "scrollModeOnLoad": -1,
  10914. "spreadModeOnLoad": -1,
  10915. "textLayerMode": 1,
  10916. "useOnlyCssZoom": false,
  10917. "viewerCssTheme": 0,
  10918. "viewOnLoad": 0,
  10919. "disableAutoFetch": false,
  10920. "disableFontFace": false,
  10921. "disableRange": false,
  10922. "disableStream": false,
  10923. "enableXfa": false
  10924. }),
  10925. writable: false,
  10926. enumerable: true,
  10927. configurable: false
  10928. });
  10929. this.prefs = Object.create(null);
  10930. this._initializedPromise = this._readFromStorage(this.defaults).then(prefs => {
  10931. for (const name in this.defaults) {
  10932. const prefValue = prefs?.[name];
  10933. if (typeof prefValue === typeof this.defaults[name]) {
  10934. this.prefs[name] = prefValue;
  10935. }
  10936. }
  10937. });
  10938. }
  10939. async _writeToStorage(prefObj) {
  10940. throw new Error("Not implemented: _writeToStorage");
  10941. }
  10942. async _readFromStorage(prefObj) {
  10943. throw new Error("Not implemented: _readFromStorage");
  10944. }
  10945. async reset() {
  10946. await this._initializedPromise;
  10947. this.prefs = Object.create(null);
  10948. return this._writeToStorage(this.defaults);
  10949. }
  10950. async set(name, value) {
  10951. await this._initializedPromise;
  10952. const defaultValue = this.defaults[name];
  10953. if (defaultValue === undefined) {
  10954. throw new Error(`Set preference: "${name}" is undefined.`);
  10955. } else if (value === undefined) {
  10956. throw new Error("Set preference: no value is specified.");
  10957. }
  10958. const valueType = typeof value;
  10959. const defaultType = typeof defaultValue;
  10960. if (valueType !== defaultType) {
  10961. if (valueType === "number" && defaultType === "string") {
  10962. value = value.toString();
  10963. } else {
  10964. throw new Error(`Set preference: "${value}" is a ${valueType}, expected a ${defaultType}.`);
  10965. }
  10966. } else {
  10967. if (valueType === "number" && !Number.isInteger(value)) {
  10968. throw new Error(`Set preference: "${value}" must be an integer.`);
  10969. }
  10970. }
  10971. this.prefs[name] = value;
  10972. return this._writeToStorage(this.prefs);
  10973. }
  10974. async get(name) {
  10975. await this._initializedPromise;
  10976. const defaultValue = this.defaults[name],
  10977. prefValue = this.prefs[name];
  10978. if (defaultValue === undefined) {
  10979. throw new Error(`Get preference: "${name}" is undefined.`);
  10980. }
  10981. return prefValue !== undefined ? prefValue : defaultValue;
  10982. }
  10983. async getAll() {
  10984. await this._initializedPromise;
  10985. const obj = Object.create(null);
  10986. for (const name in this.defaults) {
  10987. const prefValue = this.prefs[name];
  10988. obj[name] = prefValue !== undefined ? prefValue : this.defaults[name];
  10989. }
  10990. return obj;
  10991. }
  10992. }
  10993. exports.BasePreferences = BasePreferences;
  10994. /***/ }),
  10995. /* 41 */
  10996. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10997. Object.defineProperty(exports, "__esModule", ({
  10998. value: true
  10999. }));
  11000. exports.DownloadManager = void 0;
  11001. var _pdfjsLib = __webpack_require__(5);
  11002. var _viewer_compatibility = __webpack_require__(2);
  11003. ;
  11004. function download(blobUrl, filename) {
  11005. const a = document.createElement("a");
  11006. if (!a.click) {
  11007. throw new Error('DownloadManager: "a.click()" is not supported.');
  11008. }
  11009. a.href = blobUrl;
  11010. a.target = "_parent";
  11011. if ("download" in a) {
  11012. a.download = filename;
  11013. }
  11014. (document.body || document.documentElement).appendChild(a);
  11015. a.click();
  11016. a.remove();
  11017. }
  11018. class DownloadManager {
  11019. constructor() {
  11020. this._openBlobUrls = new WeakMap();
  11021. }
  11022. downloadUrl(url, filename) {
  11023. if (!(0, _pdfjsLib.createValidAbsoluteUrl)(url, "http://example.com")) {
  11024. return;
  11025. }
  11026. download(url + "#pdfjs.action=download", filename);
  11027. }
  11028. downloadData(data, filename, contentType) {
  11029. const blobUrl = (0, _pdfjsLib.createObjectURL)(data, contentType, _viewer_compatibility.viewerCompatibilityParams.disableCreateObjectURL);
  11030. download(blobUrl, filename);
  11031. }
  11032. openOrDownloadData(element, data, filename) {
  11033. const isPdfData = (0, _pdfjsLib.isPdfFile)(filename);
  11034. const contentType = isPdfData ? "application/pdf" : "";
  11035. if (isPdfData && !_viewer_compatibility.viewerCompatibilityParams.disableCreateObjectURL) {
  11036. let blobUrl = this._openBlobUrls.get(element);
  11037. if (!blobUrl) {
  11038. blobUrl = URL.createObjectURL(new Blob([data], {
  11039. type: contentType
  11040. }));
  11041. this._openBlobUrls.set(element, blobUrl);
  11042. }
  11043. let viewerUrl;
  11044. viewerUrl = "?file=" + encodeURIComponent(blobUrl + "#" + filename);
  11045. try {
  11046. window.open(viewerUrl);
  11047. return true;
  11048. } catch (ex) {
  11049. console.error(`openOrDownloadData: ${ex}`);
  11050. URL.revokeObjectURL(blobUrl);
  11051. this._openBlobUrls.delete(element);
  11052. }
  11053. }
  11054. this.downloadData(data, filename, contentType);
  11055. return false;
  11056. }
  11057. download(blob, url, filename, sourceEventType = "download") {
  11058. if (_viewer_compatibility.viewerCompatibilityParams.disableCreateObjectURL) {
  11059. this.downloadUrl(url, filename);
  11060. return;
  11061. }
  11062. const blobUrl = URL.createObjectURL(blob);
  11063. download(blobUrl, filename);
  11064. }
  11065. }
  11066. exports.DownloadManager = DownloadManager;
  11067. /***/ }),
  11068. /* 42 */
  11069. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11070. Object.defineProperty(exports, "__esModule", ({
  11071. value: true
  11072. }));
  11073. exports.GenericL10n = void 0;
  11074. __webpack_require__(43);
  11075. var _l10n_utils = __webpack_require__(30);
  11076. const webL10n = document.webL10n;
  11077. class GenericL10n {
  11078. constructor(lang) {
  11079. this._lang = lang;
  11080. this._ready = new Promise((resolve, reject) => {
  11081. webL10n.setLanguage((0, _l10n_utils.fixupLangCode)(lang), () => {
  11082. resolve(webL10n);
  11083. });
  11084. });
  11085. }
  11086. async getLanguage() {
  11087. const l10n = await this._ready;
  11088. return l10n.getLanguage();
  11089. }
  11090. async getDirection() {
  11091. const l10n = await this._ready;
  11092. return l10n.getDirection();
  11093. }
  11094. async get(key, args = null, fallback = (0, _l10n_utils.getL10nFallback)(key, args)) {
  11095. const l10n = await this._ready;
  11096. return l10n.get(key, args, fallback);
  11097. }
  11098. async translate(element) {
  11099. const l10n = await this._ready;
  11100. return l10n.translate(element);
  11101. }
  11102. }
  11103. exports.GenericL10n = GenericL10n;
  11104. /***/ }),
  11105. /* 43 */
  11106. /***/ (() => {
  11107. document.webL10n = function (window, document, undefined) {
  11108. var gL10nData = {};
  11109. var gTextData = '';
  11110. var gTextProp = 'textContent';
  11111. var gLanguage = '';
  11112. var gMacros = {};
  11113. var gReadyState = 'loading';
  11114. var gAsyncResourceLoading = true;
  11115. function getL10nResourceLinks() {
  11116. return document.querySelectorAll('link[type="application/l10n"]');
  11117. }
  11118. function getL10nDictionary() {
  11119. var script = document.querySelector('script[type="application/l10n"]');
  11120. return script ? JSON.parse(script.innerHTML) : null;
  11121. }
  11122. function getTranslatableChildren(element) {
  11123. return element ? element.querySelectorAll('*[data-l10n-id]') : [];
  11124. }
  11125. function getL10nAttributes(element) {
  11126. if (!element) return {};
  11127. var l10nId = element.getAttribute('data-l10n-id');
  11128. var l10nArgs = element.getAttribute('data-l10n-args');
  11129. var args = {};
  11130. if (l10nArgs) {
  11131. try {
  11132. args = JSON.parse(l10nArgs);
  11133. } catch (e) {
  11134. console.warn('could not parse arguments for #' + l10nId);
  11135. }
  11136. }
  11137. return {
  11138. id: l10nId,
  11139. args: args
  11140. };
  11141. }
  11142. function xhrLoadText(url, onSuccess, onFailure) {
  11143. onSuccess = onSuccess || function _onSuccess(data) {};
  11144. onFailure = onFailure || function _onFailure() {};
  11145. var xhr = new XMLHttpRequest();
  11146. xhr.open('GET', url, gAsyncResourceLoading);
  11147. if (xhr.overrideMimeType) {
  11148. xhr.overrideMimeType('text/plain; charset=utf-8');
  11149. }
  11150. xhr.onreadystatechange = function () {
  11151. if (xhr.readyState == 4) {
  11152. if (xhr.status == 200 || xhr.status === 0) {
  11153. onSuccess(xhr.responseText);
  11154. } else {
  11155. onFailure();
  11156. }
  11157. }
  11158. };
  11159. xhr.onerror = onFailure;
  11160. xhr.ontimeout = onFailure;
  11161. try {
  11162. xhr.send(null);
  11163. } catch (e) {
  11164. onFailure();
  11165. }
  11166. }
  11167. function parseResource(href, lang, successCallback, failureCallback) {
  11168. var baseURL = href.replace(/[^\/]*$/, '') || './';
  11169. function evalString(text) {
  11170. if (text.lastIndexOf('\\') < 0) return text;
  11171. return text.replace(/\\\\/g, '\\').replace(/\\n/g, '\n').replace(/\\r/g, '\r').replace(/\\t/g, '\t').replace(/\\b/g, '\b').replace(/\\f/g, '\f').replace(/\\{/g, '{').replace(/\\}/g, '}').replace(/\\"/g, '"').replace(/\\'/g, "'");
  11172. }
  11173. function parseProperties(text, parsedPropertiesCallback) {
  11174. var dictionary = {};
  11175. var reBlank = /^\s*|\s*$/;
  11176. var reComment = /^\s*#|^\s*$/;
  11177. var reSection = /^\s*\[(.*)\]\s*$/;
  11178. var reImport = /^\s*@import\s+url\((.*)\)\s*$/i;
  11179. var reSplit = /^([^=\s]*)\s*=\s*(.+)$/;
  11180. function parseRawLines(rawText, extendedSyntax, parsedRawLinesCallback) {
  11181. var entries = rawText.replace(reBlank, '').split(/[\r\n]+/);
  11182. var currentLang = '*';
  11183. var genericLang = lang.split('-', 1)[0];
  11184. var skipLang = false;
  11185. var match = '';
  11186. function nextEntry() {
  11187. while (true) {
  11188. if (!entries.length) {
  11189. parsedRawLinesCallback();
  11190. return;
  11191. }
  11192. var line = entries.shift();
  11193. if (reComment.test(line)) continue;
  11194. if (extendedSyntax) {
  11195. match = reSection.exec(line);
  11196. if (match) {
  11197. currentLang = match[1].toLowerCase();
  11198. skipLang = currentLang !== '*' && currentLang !== lang && currentLang !== genericLang;
  11199. continue;
  11200. } else if (skipLang) {
  11201. continue;
  11202. }
  11203. match = reImport.exec(line);
  11204. if (match) {
  11205. loadImport(baseURL + match[1], nextEntry);
  11206. return;
  11207. }
  11208. }
  11209. var tmp = line.match(reSplit);
  11210. if (tmp && tmp.length == 3) {
  11211. dictionary[tmp[1]] = evalString(tmp[2]);
  11212. }
  11213. }
  11214. }
  11215. nextEntry();
  11216. }
  11217. function loadImport(url, callback) {
  11218. xhrLoadText(url, function (content) {
  11219. parseRawLines(content, false, callback);
  11220. }, function () {
  11221. console.warn(url + ' not found.');
  11222. callback();
  11223. });
  11224. }
  11225. parseRawLines(text, true, function () {
  11226. parsedPropertiesCallback(dictionary);
  11227. });
  11228. }
  11229. xhrLoadText(href, function (response) {
  11230. gTextData += response;
  11231. parseProperties(response, function (data) {
  11232. for (var key in data) {
  11233. var id,
  11234. prop,
  11235. index = key.lastIndexOf('.');
  11236. if (index > 0) {
  11237. id = key.substring(0, index);
  11238. prop = key.substring(index + 1);
  11239. } else {
  11240. id = key;
  11241. prop = gTextProp;
  11242. }
  11243. if (!gL10nData[id]) {
  11244. gL10nData[id] = {};
  11245. }
  11246. gL10nData[id][prop] = data[key];
  11247. }
  11248. if (successCallback) {
  11249. successCallback();
  11250. }
  11251. });
  11252. }, failureCallback);
  11253. }
  11254. function loadLocale(lang, callback) {
  11255. if (lang) {
  11256. lang = lang.toLowerCase();
  11257. }
  11258. callback = callback || function _callback() {};
  11259. clear();
  11260. gLanguage = lang;
  11261. var langLinks = getL10nResourceLinks();
  11262. var langCount = langLinks.length;
  11263. if (langCount === 0) {
  11264. var dict = getL10nDictionary();
  11265. if (dict && dict.locales && dict.default_locale) {
  11266. console.log('using the embedded JSON directory, early way out');
  11267. gL10nData = dict.locales[lang];
  11268. if (!gL10nData) {
  11269. var defaultLocale = dict.default_locale.toLowerCase();
  11270. for (var anyCaseLang in dict.locales) {
  11271. anyCaseLang = anyCaseLang.toLowerCase();
  11272. if (anyCaseLang === lang) {
  11273. gL10nData = dict.locales[lang];
  11274. break;
  11275. } else if (anyCaseLang === defaultLocale) {
  11276. gL10nData = dict.locales[defaultLocale];
  11277. }
  11278. }
  11279. }
  11280. callback();
  11281. } else {
  11282. console.log('no resource to load, early way out');
  11283. }
  11284. gReadyState = 'complete';
  11285. return;
  11286. }
  11287. var onResourceLoaded = null;
  11288. var gResourceCount = 0;
  11289. onResourceLoaded = function () {
  11290. gResourceCount++;
  11291. if (gResourceCount >= langCount) {
  11292. callback();
  11293. gReadyState = 'complete';
  11294. }
  11295. };
  11296. function L10nResourceLink(link) {
  11297. var href = link.href;
  11298. this.load = function (lang, callback) {
  11299. parseResource(href, lang, callback, function () {
  11300. console.warn(href + ' not found.');
  11301. console.warn('"' + lang + '" resource not found');
  11302. gLanguage = '';
  11303. callback();
  11304. });
  11305. };
  11306. }
  11307. for (var i = 0; i < langCount; i++) {
  11308. var resource = new L10nResourceLink(langLinks[i]);
  11309. resource.load(lang, onResourceLoaded);
  11310. }
  11311. }
  11312. function clear() {
  11313. gL10nData = {};
  11314. gTextData = '';
  11315. gLanguage = '';
  11316. }
  11317. function getPluralRules(lang) {
  11318. var locales2rules = {
  11319. 'af': 3,
  11320. 'ak': 4,
  11321. 'am': 4,
  11322. 'ar': 1,
  11323. 'asa': 3,
  11324. 'az': 0,
  11325. 'be': 11,
  11326. 'bem': 3,
  11327. 'bez': 3,
  11328. 'bg': 3,
  11329. 'bh': 4,
  11330. 'bm': 0,
  11331. 'bn': 3,
  11332. 'bo': 0,
  11333. 'br': 20,
  11334. 'brx': 3,
  11335. 'bs': 11,
  11336. 'ca': 3,
  11337. 'cgg': 3,
  11338. 'chr': 3,
  11339. 'cs': 12,
  11340. 'cy': 17,
  11341. 'da': 3,
  11342. 'de': 3,
  11343. 'dv': 3,
  11344. 'dz': 0,
  11345. 'ee': 3,
  11346. 'el': 3,
  11347. 'en': 3,
  11348. 'eo': 3,
  11349. 'es': 3,
  11350. 'et': 3,
  11351. 'eu': 3,
  11352. 'fa': 0,
  11353. 'ff': 5,
  11354. 'fi': 3,
  11355. 'fil': 4,
  11356. 'fo': 3,
  11357. 'fr': 5,
  11358. 'fur': 3,
  11359. 'fy': 3,
  11360. 'ga': 8,
  11361. 'gd': 24,
  11362. 'gl': 3,
  11363. 'gsw': 3,
  11364. 'gu': 3,
  11365. 'guw': 4,
  11366. 'gv': 23,
  11367. 'ha': 3,
  11368. 'haw': 3,
  11369. 'he': 2,
  11370. 'hi': 4,
  11371. 'hr': 11,
  11372. 'hu': 0,
  11373. 'id': 0,
  11374. 'ig': 0,
  11375. 'ii': 0,
  11376. 'is': 3,
  11377. 'it': 3,
  11378. 'iu': 7,
  11379. 'ja': 0,
  11380. 'jmc': 3,
  11381. 'jv': 0,
  11382. 'ka': 0,
  11383. 'kab': 5,
  11384. 'kaj': 3,
  11385. 'kcg': 3,
  11386. 'kde': 0,
  11387. 'kea': 0,
  11388. 'kk': 3,
  11389. 'kl': 3,
  11390. 'km': 0,
  11391. 'kn': 0,
  11392. 'ko': 0,
  11393. 'ksb': 3,
  11394. 'ksh': 21,
  11395. 'ku': 3,
  11396. 'kw': 7,
  11397. 'lag': 18,
  11398. 'lb': 3,
  11399. 'lg': 3,
  11400. 'ln': 4,
  11401. 'lo': 0,
  11402. 'lt': 10,
  11403. 'lv': 6,
  11404. 'mas': 3,
  11405. 'mg': 4,
  11406. 'mk': 16,
  11407. 'ml': 3,
  11408. 'mn': 3,
  11409. 'mo': 9,
  11410. 'mr': 3,
  11411. 'ms': 0,
  11412. 'mt': 15,
  11413. 'my': 0,
  11414. 'nah': 3,
  11415. 'naq': 7,
  11416. 'nb': 3,
  11417. 'nd': 3,
  11418. 'ne': 3,
  11419. 'nl': 3,
  11420. 'nn': 3,
  11421. 'no': 3,
  11422. 'nr': 3,
  11423. 'nso': 4,
  11424. 'ny': 3,
  11425. 'nyn': 3,
  11426. 'om': 3,
  11427. 'or': 3,
  11428. 'pa': 3,
  11429. 'pap': 3,
  11430. 'pl': 13,
  11431. 'ps': 3,
  11432. 'pt': 3,
  11433. 'rm': 3,
  11434. 'ro': 9,
  11435. 'rof': 3,
  11436. 'ru': 11,
  11437. 'rwk': 3,
  11438. 'sah': 0,
  11439. 'saq': 3,
  11440. 'se': 7,
  11441. 'seh': 3,
  11442. 'ses': 0,
  11443. 'sg': 0,
  11444. 'sh': 11,
  11445. 'shi': 19,
  11446. 'sk': 12,
  11447. 'sl': 14,
  11448. 'sma': 7,
  11449. 'smi': 7,
  11450. 'smj': 7,
  11451. 'smn': 7,
  11452. 'sms': 7,
  11453. 'sn': 3,
  11454. 'so': 3,
  11455. 'sq': 3,
  11456. 'sr': 11,
  11457. 'ss': 3,
  11458. 'ssy': 3,
  11459. 'st': 3,
  11460. 'sv': 3,
  11461. 'sw': 3,
  11462. 'syr': 3,
  11463. 'ta': 3,
  11464. 'te': 3,
  11465. 'teo': 3,
  11466. 'th': 0,
  11467. 'ti': 4,
  11468. 'tig': 3,
  11469. 'tk': 3,
  11470. 'tl': 4,
  11471. 'tn': 3,
  11472. 'to': 0,
  11473. 'tr': 0,
  11474. 'ts': 3,
  11475. 'tzm': 22,
  11476. 'uk': 11,
  11477. 'ur': 3,
  11478. 've': 3,
  11479. 'vi': 0,
  11480. 'vun': 3,
  11481. 'wa': 4,
  11482. 'wae': 3,
  11483. 'wo': 0,
  11484. 'xh': 3,
  11485. 'xog': 3,
  11486. 'yo': 0,
  11487. 'zh': 0,
  11488. 'zu': 3
  11489. };
  11490. function isIn(n, list) {
  11491. return list.indexOf(n) !== -1;
  11492. }
  11493. function isBetween(n, start, end) {
  11494. return start <= n && n <= end;
  11495. }
  11496. var pluralRules = {
  11497. '0': function (n) {
  11498. return 'other';
  11499. },
  11500. '1': function (n) {
  11501. if (isBetween(n % 100, 3, 10)) return 'few';
  11502. if (n === 0) return 'zero';
  11503. if (isBetween(n % 100, 11, 99)) return 'many';
  11504. if (n == 2) return 'two';
  11505. if (n == 1) return 'one';
  11506. return 'other';
  11507. },
  11508. '2': function (n) {
  11509. if (n !== 0 && n % 10 === 0) return 'many';
  11510. if (n == 2) return 'two';
  11511. if (n == 1) return 'one';
  11512. return 'other';
  11513. },
  11514. '3': function (n) {
  11515. if (n == 1) return 'one';
  11516. return 'other';
  11517. },
  11518. '4': function (n) {
  11519. if (isBetween(n, 0, 1)) return 'one';
  11520. return 'other';
  11521. },
  11522. '5': function (n) {
  11523. if (isBetween(n, 0, 2) && n != 2) return 'one';
  11524. return 'other';
  11525. },
  11526. '6': function (n) {
  11527. if (n === 0) return 'zero';
  11528. if (n % 10 == 1 && n % 100 != 11) return 'one';
  11529. return 'other';
  11530. },
  11531. '7': function (n) {
  11532. if (n == 2) return 'two';
  11533. if (n == 1) return 'one';
  11534. return 'other';
  11535. },
  11536. '8': function (n) {
  11537. if (isBetween(n, 3, 6)) return 'few';
  11538. if (isBetween(n, 7, 10)) return 'many';
  11539. if (n == 2) return 'two';
  11540. if (n == 1) return 'one';
  11541. return 'other';
  11542. },
  11543. '9': function (n) {
  11544. if (n === 0 || n != 1 && isBetween(n % 100, 1, 19)) return 'few';
  11545. if (n == 1) return 'one';
  11546. return 'other';
  11547. },
  11548. '10': function (n) {
  11549. if (isBetween(n % 10, 2, 9) && !isBetween(n % 100, 11, 19)) return 'few';
  11550. if (n % 10 == 1 && !isBetween(n % 100, 11, 19)) return 'one';
  11551. return 'other';
  11552. },
  11553. '11': function (n) {
  11554. if (isBetween(n % 10, 2, 4) && !isBetween(n % 100, 12, 14)) return 'few';
  11555. if (n % 10 === 0 || isBetween(n % 10, 5, 9) || isBetween(n % 100, 11, 14)) return 'many';
  11556. if (n % 10 == 1 && n % 100 != 11) return 'one';
  11557. return 'other';
  11558. },
  11559. '12': function (n) {
  11560. if (isBetween(n, 2, 4)) return 'few';
  11561. if (n == 1) return 'one';
  11562. return 'other';
  11563. },
  11564. '13': function (n) {
  11565. if (isBetween(n % 10, 2, 4) && !isBetween(n % 100, 12, 14)) return 'few';
  11566. if (n != 1 && isBetween(n % 10, 0, 1) || isBetween(n % 10, 5, 9) || isBetween(n % 100, 12, 14)) return 'many';
  11567. if (n == 1) return 'one';
  11568. return 'other';
  11569. },
  11570. '14': function (n) {
  11571. if (isBetween(n % 100, 3, 4)) return 'few';
  11572. if (n % 100 == 2) return 'two';
  11573. if (n % 100 == 1) return 'one';
  11574. return 'other';
  11575. },
  11576. '15': function (n) {
  11577. if (n === 0 || isBetween(n % 100, 2, 10)) return 'few';
  11578. if (isBetween(n % 100, 11, 19)) return 'many';
  11579. if (n == 1) return 'one';
  11580. return 'other';
  11581. },
  11582. '16': function (n) {
  11583. if (n % 10 == 1 && n != 11) return 'one';
  11584. return 'other';
  11585. },
  11586. '17': function (n) {
  11587. if (n == 3) return 'few';
  11588. if (n === 0) return 'zero';
  11589. if (n == 6) return 'many';
  11590. if (n == 2) return 'two';
  11591. if (n == 1) return 'one';
  11592. return 'other';
  11593. },
  11594. '18': function (n) {
  11595. if (n === 0) return 'zero';
  11596. if (isBetween(n, 0, 2) && n !== 0 && n != 2) return 'one';
  11597. return 'other';
  11598. },
  11599. '19': function (n) {
  11600. if (isBetween(n, 2, 10)) return 'few';
  11601. if (isBetween(n, 0, 1)) return 'one';
  11602. return 'other';
  11603. },
  11604. '20': function (n) {
  11605. if ((isBetween(n % 10, 3, 4) || n % 10 == 9) && !(isBetween(n % 100, 10, 19) || isBetween(n % 100, 70, 79) || isBetween(n % 100, 90, 99))) return 'few';
  11606. if (n % 1000000 === 0 && n !== 0) return 'many';
  11607. if (n % 10 == 2 && !isIn(n % 100, [12, 72, 92])) return 'two';
  11608. if (n % 10 == 1 && !isIn(n % 100, [11, 71, 91])) return 'one';
  11609. return 'other';
  11610. },
  11611. '21': function (n) {
  11612. if (n === 0) return 'zero';
  11613. if (n == 1) return 'one';
  11614. return 'other';
  11615. },
  11616. '22': function (n) {
  11617. if (isBetween(n, 0, 1) || isBetween(n, 11, 99)) return 'one';
  11618. return 'other';
  11619. },
  11620. '23': function (n) {
  11621. if (isBetween(n % 10, 1, 2) || n % 20 === 0) return 'one';
  11622. return 'other';
  11623. },
  11624. '24': function (n) {
  11625. if (isBetween(n, 3, 10) || isBetween(n, 13, 19)) return 'few';
  11626. if (isIn(n, [2, 12])) return 'two';
  11627. if (isIn(n, [1, 11])) return 'one';
  11628. return 'other';
  11629. }
  11630. };
  11631. var index = locales2rules[lang.replace(/-.*$/, '')];
  11632. if (!(index in pluralRules)) {
  11633. console.warn('plural form unknown for [' + lang + ']');
  11634. return function () {
  11635. return 'other';
  11636. };
  11637. }
  11638. return pluralRules[index];
  11639. }
  11640. gMacros.plural = function (str, param, key, prop) {
  11641. var n = parseFloat(param);
  11642. if (isNaN(n)) return str;
  11643. if (prop != gTextProp) return str;
  11644. if (!gMacros._pluralRules) {
  11645. gMacros._pluralRules = getPluralRules(gLanguage);
  11646. }
  11647. var index = '[' + gMacros._pluralRules(n) + ']';
  11648. if (n === 0 && key + '[zero]' in gL10nData) {
  11649. str = gL10nData[key + '[zero]'][prop];
  11650. } else if (n == 1 && key + '[one]' in gL10nData) {
  11651. str = gL10nData[key + '[one]'][prop];
  11652. } else if (n == 2 && key + '[two]' in gL10nData) {
  11653. str = gL10nData[key + '[two]'][prop];
  11654. } else if (key + index in gL10nData) {
  11655. str = gL10nData[key + index][prop];
  11656. } else if (key + '[other]' in gL10nData) {
  11657. str = gL10nData[key + '[other]'][prop];
  11658. }
  11659. return str;
  11660. };
  11661. function getL10nData(key, args, fallback) {
  11662. var data = gL10nData[key];
  11663. if (!data) {
  11664. console.warn('#' + key + ' is undefined.');
  11665. if (!fallback) {
  11666. return null;
  11667. }
  11668. data = fallback;
  11669. }
  11670. var rv = {};
  11671. for (var prop in data) {
  11672. var str = data[prop];
  11673. str = substIndexes(str, args, key, prop);
  11674. str = substArguments(str, args, key);
  11675. rv[prop] = str;
  11676. }
  11677. return rv;
  11678. }
  11679. function substIndexes(str, args, key, prop) {
  11680. var reIndex = /\{\[\s*([a-zA-Z]+)\(([a-zA-Z]+)\)\s*\]\}/;
  11681. var reMatch = reIndex.exec(str);
  11682. if (!reMatch || !reMatch.length) return str;
  11683. var macroName = reMatch[1];
  11684. var paramName = reMatch[2];
  11685. var param;
  11686. if (args && paramName in args) {
  11687. param = args[paramName];
  11688. } else if (paramName in gL10nData) {
  11689. param = gL10nData[paramName];
  11690. }
  11691. if (macroName in gMacros) {
  11692. var macro = gMacros[macroName];
  11693. str = macro(str, param, key, prop);
  11694. }
  11695. return str;
  11696. }
  11697. function substArguments(str, args, key) {
  11698. var reArgs = /\{\{\s*(.+?)\s*\}\}/g;
  11699. return str.replace(reArgs, function (matched_text, arg) {
  11700. if (args && arg in args) {
  11701. return args[arg];
  11702. }
  11703. if (arg in gL10nData) {
  11704. return gL10nData[arg];
  11705. }
  11706. console.log('argument {{' + arg + '}} for #' + key + ' is undefined.');
  11707. return matched_text;
  11708. });
  11709. }
  11710. function translateElement(element) {
  11711. var l10n = getL10nAttributes(element);
  11712. if (!l10n.id) return;
  11713. var data = getL10nData(l10n.id, l10n.args);
  11714. if (!data) {
  11715. console.warn('#' + l10n.id + ' is undefined.');
  11716. return;
  11717. }
  11718. if (data[gTextProp]) {
  11719. if (getChildElementCount(element) === 0) {
  11720. element[gTextProp] = data[gTextProp];
  11721. } else {
  11722. var children = element.childNodes;
  11723. var found = false;
  11724. for (var i = 0, l = children.length; i < l; i++) {
  11725. if (children[i].nodeType === 3 && /\S/.test(children[i].nodeValue)) {
  11726. if (found) {
  11727. children[i].nodeValue = '';
  11728. } else {
  11729. children[i].nodeValue = data[gTextProp];
  11730. found = true;
  11731. }
  11732. }
  11733. }
  11734. if (!found) {
  11735. var textNode = document.createTextNode(data[gTextProp]);
  11736. element.insertBefore(textNode, element.firstChild);
  11737. }
  11738. }
  11739. delete data[gTextProp];
  11740. }
  11741. for (var k in data) {
  11742. element[k] = data[k];
  11743. }
  11744. }
  11745. function getChildElementCount(element) {
  11746. if (element.children) {
  11747. return element.children.length;
  11748. }
  11749. if (typeof element.childElementCount !== 'undefined') {
  11750. return element.childElementCount;
  11751. }
  11752. var count = 0;
  11753. for (var i = 0; i < element.childNodes.length; i++) {
  11754. count += element.nodeType === 1 ? 1 : 0;
  11755. }
  11756. return count;
  11757. }
  11758. function translateFragment(element) {
  11759. element = element || document.documentElement;
  11760. var children = getTranslatableChildren(element);
  11761. var elementCount = children.length;
  11762. for (var i = 0; i < elementCount; i++) {
  11763. translateElement(children[i]);
  11764. }
  11765. translateElement(element);
  11766. }
  11767. return {
  11768. get: function (key, args, fallbackString) {
  11769. var index = key.lastIndexOf('.');
  11770. var prop = gTextProp;
  11771. if (index > 0) {
  11772. prop = key.substring(index + 1);
  11773. key = key.substring(0, index);
  11774. }
  11775. var fallback;
  11776. if (fallbackString) {
  11777. fallback = {};
  11778. fallback[prop] = fallbackString;
  11779. }
  11780. var data = getL10nData(key, args, fallback);
  11781. if (data && prop in data) {
  11782. return data[prop];
  11783. }
  11784. return '{{' + key + '}}';
  11785. },
  11786. getData: function () {
  11787. return gL10nData;
  11788. },
  11789. getText: function () {
  11790. return gTextData;
  11791. },
  11792. getLanguage: function () {
  11793. return gLanguage;
  11794. },
  11795. setLanguage: function (lang, callback) {
  11796. loadLocale(lang, function () {
  11797. if (callback) callback();
  11798. });
  11799. },
  11800. getDirection: function () {
  11801. var rtlList = ['ar', 'he', 'fa', 'ps', 'ur'];
  11802. var shortCode = gLanguage.split('-', 1)[0];
  11803. return rtlList.indexOf(shortCode) >= 0 ? 'rtl' : 'ltr';
  11804. },
  11805. translate: translateFragment,
  11806. getReadyState: function () {
  11807. return gReadyState;
  11808. },
  11809. ready: function (callback) {
  11810. if (!callback) {
  11811. return;
  11812. } else if (gReadyState == 'complete' || gReadyState == 'interactive') {
  11813. window.setTimeout(function () {
  11814. callback();
  11815. });
  11816. } else if (document.addEventListener) {
  11817. document.addEventListener('localized', function once() {
  11818. document.removeEventListener('localized', once);
  11819. callback();
  11820. });
  11821. }
  11822. }
  11823. };
  11824. }(window, document);
  11825. /***/ }),
  11826. /* 44 */
  11827. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11828. Object.defineProperty(exports, "__esModule", ({
  11829. value: true
  11830. }));
  11831. exports.docPropertiesLookup = docPropertiesLookup;
  11832. exports.GenericScripting = void 0;
  11833. var _pdfjsLib = __webpack_require__(5);
  11834. async function docPropertiesLookup(pdfDocument) {
  11835. const url = "",
  11836. baseUrl = url.split("#")[0];
  11837. let {
  11838. info,
  11839. metadata,
  11840. contentDispositionFilename,
  11841. contentLength
  11842. } = await pdfDocument.getMetadata();
  11843. if (!contentLength) {
  11844. const {
  11845. length
  11846. } = await pdfDocument.getDownloadInfo();
  11847. contentLength = length;
  11848. }
  11849. return { ...info,
  11850. baseURL: baseUrl,
  11851. filesize: contentLength,
  11852. filename: contentDispositionFilename || (0, _pdfjsLib.getPdfFilenameFromUrl)(url),
  11853. metadata: metadata?.getRaw(),
  11854. authors: metadata?.get("dc:creator"),
  11855. numPages: pdfDocument.numPages,
  11856. URL: url
  11857. };
  11858. }
  11859. class GenericScripting {
  11860. constructor(sandboxBundleSrc) {
  11861. this._ready = (0, _pdfjsLib.loadScript)(sandboxBundleSrc, true).then(() => {
  11862. return window.pdfjsSandbox.QuickJSSandbox();
  11863. });
  11864. }
  11865. async createSandbox(data) {
  11866. const sandbox = await this._ready;
  11867. sandbox.create(data);
  11868. }
  11869. async dispatchEventInSandbox(event) {
  11870. const sandbox = await this._ready;
  11871. sandbox.dispatchEvent(event);
  11872. }
  11873. async destroySandbox() {
  11874. const sandbox = await this._ready;
  11875. sandbox.nukeSandbox();
  11876. }
  11877. }
  11878. exports.GenericScripting = GenericScripting;
  11879. /***/ }),
  11880. /* 45 */
  11881. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11882. Object.defineProperty(exports, "__esModule", ({
  11883. value: true
  11884. }));
  11885. exports.PDFPrintService = PDFPrintService;
  11886. var _app = __webpack_require__(3);
  11887. var _print_utils = __webpack_require__(46);
  11888. var _viewer_compatibility = __webpack_require__(2);
  11889. let activeService = null;
  11890. let overlayManager = null;
  11891. function renderPage(activeServiceOnEntry, pdfDocument, pageNumber, size, printResolution, optionalContentConfigPromise) {
  11892. const scratchCanvas = activeService.scratchCanvas;
  11893. const PRINT_UNITS = printResolution / 72.0;
  11894. scratchCanvas.width = Math.floor(size.width * PRINT_UNITS);
  11895. scratchCanvas.height = Math.floor(size.height * PRINT_UNITS);
  11896. const ctx = scratchCanvas.getContext("2d");
  11897. ctx.save();
  11898. ctx.fillStyle = "rgb(255, 255, 255)";
  11899. ctx.fillRect(0, 0, scratchCanvas.width, scratchCanvas.height);
  11900. ctx.restore();
  11901. return pdfDocument.getPage(pageNumber).then(function (pdfPage) {
  11902. const renderContext = {
  11903. canvasContext: ctx,
  11904. transform: [PRINT_UNITS, 0, 0, PRINT_UNITS, 0, 0],
  11905. viewport: pdfPage.getViewport({
  11906. scale: 1,
  11907. rotation: size.rotation
  11908. }),
  11909. intent: "print",
  11910. includeAnnotationStorage: true,
  11911. optionalContentConfigPromise
  11912. };
  11913. return pdfPage.render(renderContext).promise;
  11914. });
  11915. }
  11916. function PDFPrintService(pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise = null, l10n) {
  11917. this.pdfDocument = pdfDocument;
  11918. this.pagesOverview = pagesOverview;
  11919. this.printContainer = printContainer;
  11920. this._printResolution = printResolution || 150;
  11921. this._optionalContentConfigPromise = optionalContentConfigPromise || pdfDocument.getOptionalContentConfig();
  11922. this.l10n = l10n;
  11923. this.currentPage = -1;
  11924. this.scratchCanvas = document.createElement("canvas");
  11925. }
  11926. PDFPrintService.prototype = {
  11927. layout() {
  11928. this.throwIfInactive();
  11929. const body = document.querySelector("body");
  11930. body.setAttribute("data-pdfjsprinting", true);
  11931. const hasEqualPageSizes = this.pagesOverview.every(function (size) {
  11932. return size.width === this.pagesOverview[0].width && size.height === this.pagesOverview[0].height;
  11933. }, this);
  11934. if (!hasEqualPageSizes) {
  11935. console.warn("Not all pages have the same size. The printed " + "result may be incorrect!");
  11936. }
  11937. this.pageStyleSheet = document.createElement("style");
  11938. const pageSize = this.pagesOverview[0];
  11939. this.pageStyleSheet.textContent = "@page { size: " + pageSize.width + "pt " + pageSize.height + "pt;}";
  11940. body.appendChild(this.pageStyleSheet);
  11941. },
  11942. destroy() {
  11943. if (activeService !== this) {
  11944. return;
  11945. }
  11946. this.printContainer.textContent = "";
  11947. const body = document.querySelector("body");
  11948. body.removeAttribute("data-pdfjsprinting");
  11949. if (this.pageStyleSheet) {
  11950. this.pageStyleSheet.remove();
  11951. this.pageStyleSheet = null;
  11952. }
  11953. this.scratchCanvas.width = this.scratchCanvas.height = 0;
  11954. this.scratchCanvas = null;
  11955. activeService = null;
  11956. ensureOverlay().then(function () {
  11957. if (overlayManager.active !== "printServiceOverlay") {
  11958. return;
  11959. }
  11960. overlayManager.close("printServiceOverlay");
  11961. });
  11962. },
  11963. renderPages() {
  11964. if (this.pdfDocument.isPureXfa) {
  11965. (0, _print_utils.getXfaHtmlForPrinting)(this.printContainer, this.pdfDocument);
  11966. return Promise.resolve();
  11967. }
  11968. const pageCount = this.pagesOverview.length;
  11969. const renderNextPage = (resolve, reject) => {
  11970. this.throwIfInactive();
  11971. if (++this.currentPage >= pageCount) {
  11972. renderProgress(pageCount, pageCount, this.l10n);
  11973. resolve();
  11974. return;
  11975. }
  11976. const index = this.currentPage;
  11977. renderProgress(index, pageCount, this.l10n);
  11978. renderPage(this, this.pdfDocument, index + 1, this.pagesOverview[index], this._printResolution, this._optionalContentConfigPromise).then(this.useRenderedPage.bind(this)).then(function () {
  11979. renderNextPage(resolve, reject);
  11980. }, reject);
  11981. };
  11982. return new Promise(renderNextPage);
  11983. },
  11984. useRenderedPage() {
  11985. this.throwIfInactive();
  11986. const img = document.createElement("img");
  11987. const scratchCanvas = this.scratchCanvas;
  11988. if ("toBlob" in scratchCanvas && !_viewer_compatibility.viewerCompatibilityParams.disableCreateObjectURL) {
  11989. scratchCanvas.toBlob(function (blob) {
  11990. img.src = URL.createObjectURL(blob);
  11991. });
  11992. } else {
  11993. img.src = scratchCanvas.toDataURL();
  11994. }
  11995. const wrapper = document.createElement("div");
  11996. wrapper.className = "printedPage";
  11997. wrapper.appendChild(img);
  11998. this.printContainer.appendChild(wrapper);
  11999. return new Promise(function (resolve, reject) {
  12000. img.onload = resolve;
  12001. img.onerror = reject;
  12002. });
  12003. },
  12004. performPrint() {
  12005. this.throwIfInactive();
  12006. return new Promise(resolve => {
  12007. setTimeout(() => {
  12008. if (!this.active) {
  12009. resolve();
  12010. return;
  12011. }
  12012. print.call(window);
  12013. setTimeout(resolve, 20);
  12014. }, 0);
  12015. });
  12016. },
  12017. get active() {
  12018. return this === activeService;
  12019. },
  12020. throwIfInactive() {
  12021. if (!this.active) {
  12022. throw new Error("This print request was cancelled or completed.");
  12023. }
  12024. }
  12025. };
  12026. const print = window.print;
  12027. window.print = function () {
  12028. if (activeService) {
  12029. console.warn("Ignored window.print() because of a pending print job.");
  12030. return;
  12031. }
  12032. ensureOverlay().then(function () {
  12033. if (activeService) {
  12034. overlayManager.open("printServiceOverlay");
  12035. }
  12036. });
  12037. try {
  12038. dispatchEvent("beforeprint");
  12039. } finally {
  12040. if (!activeService) {
  12041. console.error("Expected print service to be initialized.");
  12042. ensureOverlay().then(function () {
  12043. if (overlayManager.active === "printServiceOverlay") {
  12044. overlayManager.close("printServiceOverlay");
  12045. }
  12046. });
  12047. return;
  12048. }
  12049. const activeServiceOnEntry = activeService;
  12050. activeService.renderPages().then(function () {
  12051. return activeServiceOnEntry.performPrint();
  12052. }).catch(function () {}).then(function () {
  12053. if (activeServiceOnEntry.active) {
  12054. abort();
  12055. }
  12056. });
  12057. }
  12058. };
  12059. function dispatchEvent(eventType) {
  12060. const event = document.createEvent("CustomEvent");
  12061. event.initCustomEvent(eventType, false, false, "custom");
  12062. window.dispatchEvent(event);
  12063. }
  12064. function abort() {
  12065. if (activeService) {
  12066. activeService.destroy();
  12067. dispatchEvent("afterprint");
  12068. }
  12069. }
  12070. function renderProgress(index, total, l10n) {
  12071. const progressContainer = document.getElementById("printServiceOverlay");
  12072. const progress = Math.round(100 * index / total);
  12073. const progressBar = progressContainer.querySelector("progress");
  12074. const progressPerc = progressContainer.querySelector(".relative-progress");
  12075. progressBar.value = progress;
  12076. l10n.get("print_progress_percent", {
  12077. progress
  12078. }).then(msg => {
  12079. progressPerc.textContent = msg;
  12080. });
  12081. }
  12082. window.addEventListener("keydown", function (event) {
  12083. if (event.keyCode === 80 && (event.ctrlKey || event.metaKey) && !event.altKey && (!event.shiftKey || window.chrome || window.opera)) {
  12084. window.print();
  12085. event.preventDefault();
  12086. if (event.stopImmediatePropagation) {
  12087. event.stopImmediatePropagation();
  12088. } else {
  12089. event.stopPropagation();
  12090. }
  12091. }
  12092. }, true);
  12093. if ("onbeforeprint" in window) {
  12094. const stopPropagationIfNeeded = function (event) {
  12095. if (event.detail !== "custom" && event.stopImmediatePropagation) {
  12096. event.stopImmediatePropagation();
  12097. }
  12098. };
  12099. window.addEventListener("beforeprint", stopPropagationIfNeeded);
  12100. window.addEventListener("afterprint", stopPropagationIfNeeded);
  12101. }
  12102. let overlayPromise;
  12103. function ensureOverlay() {
  12104. if (!overlayPromise) {
  12105. overlayManager = _app.PDFViewerApplication.overlayManager;
  12106. if (!overlayManager) {
  12107. throw new Error("The overlay manager has not yet been initialized.");
  12108. }
  12109. overlayPromise = overlayManager.register("printServiceOverlay", document.getElementById("printServiceOverlay"), abort, true);
  12110. document.getElementById("printCancel").onclick = abort;
  12111. }
  12112. return overlayPromise;
  12113. }
  12114. _app.PDFPrintServiceFactory.instance = {
  12115. supportsPrinting: true,
  12116. createPrintService(pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise, l10n) {
  12117. if (activeService) {
  12118. throw new Error("The print service is created and active.");
  12119. }
  12120. activeService = new PDFPrintService(pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise, l10n);
  12121. return activeService;
  12122. }
  12123. };
  12124. /***/ }),
  12125. /* 46 */
  12126. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  12127. Object.defineProperty(exports, "__esModule", ({
  12128. value: true
  12129. }));
  12130. exports.getXfaHtmlForPrinting = getXfaHtmlForPrinting;
  12131. var _ui_utils = __webpack_require__(4);
  12132. var _xfa_layer_builder = __webpack_require__(34);
  12133. var _pdfjsLib = __webpack_require__(5);
  12134. function getXfaHtmlForPrinting(printContainer, pdfDocument) {
  12135. const xfaHtml = pdfDocument.allXfaHtml;
  12136. const factory = new _xfa_layer_builder.DefaultXfaLayerFactory();
  12137. const scale = Math.round(_ui_utils.CSS_UNITS * 100) / 100;
  12138. for (const xfaPage of xfaHtml.children) {
  12139. const page = document.createElement("div");
  12140. page.className = "xfaPrintedPage";
  12141. printContainer.appendChild(page);
  12142. const builder = factory.createXfaLayerBuilder(page, null, pdfDocument.annotationStorage, xfaPage);
  12143. const viewport = (0, _pdfjsLib.getXfaPageViewport)(xfaPage, {
  12144. scale
  12145. });
  12146. builder.render(viewport, "print");
  12147. }
  12148. }
  12149. /***/ })
  12150. /******/ ]);
  12151. /************************************************************************/
  12152. /******/ // The module cache
  12153. /******/ var __webpack_module_cache__ = {};
  12154. /******/
  12155. /******/ // The require function
  12156. /******/ function __webpack_require__(moduleId) {
  12157. /******/ // Check if module is in cache
  12158. /******/ var cachedModule = __webpack_module_cache__[moduleId];
  12159. /******/ if (cachedModule !== undefined) {
  12160. /******/ return cachedModule.exports;
  12161. /******/ }
  12162. /******/ // Create a new module (and put it into the cache)
  12163. /******/ var module = __webpack_module_cache__[moduleId] = {
  12164. /******/ // no module.id needed
  12165. /******/ // no module.loaded needed
  12166. /******/ exports: {}
  12167. /******/ };
  12168. /******/
  12169. /******/ // Execute the module function
  12170. /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
  12171. /******/
  12172. /******/ // Return the exports of the module
  12173. /******/ return module.exports;
  12174. /******/ }
  12175. /******/
  12176. /************************************************************************/
  12177. var __webpack_exports__ = {};
  12178. // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
  12179. (() => {
  12180. var exports = __webpack_exports__;
  12181. Object.defineProperty(exports, "__esModule", ({
  12182. value: true
  12183. }));
  12184. Object.defineProperty(exports, "PDFViewerApplicationOptions", ({
  12185. enumerable: true,
  12186. get: function () {
  12187. return _app_options.AppOptions;
  12188. }
  12189. }));
  12190. Object.defineProperty(exports, "PDFViewerApplication", ({
  12191. enumerable: true,
  12192. get: function () {
  12193. return _app.PDFViewerApplication;
  12194. }
  12195. }));
  12196. var _app_options = __webpack_require__(1);
  12197. var _app = __webpack_require__(3);
  12198. const pdfjsVersion = '2.10.377';
  12199. const pdfjsBuild = '156762c48';
  12200. window.PDFViewerApplication = _app.PDFViewerApplication;
  12201. window.PDFViewerApplicationOptions = _app_options.AppOptions;
  12202. ;
  12203. ;
  12204. {
  12205. __webpack_require__(39);
  12206. }
  12207. ;
  12208. {
  12209. __webpack_require__(45);
  12210. }
  12211. function getViewerConfiguration() {
  12212. let errorWrapper = null;
  12213. errorWrapper = {
  12214. container: document.getElementById("errorWrapper"),
  12215. errorMessage: document.getElementById("errorMessage"),
  12216. closeButton: document.getElementById("errorClose"),
  12217. errorMoreInfo: document.getElementById("errorMoreInfo"),
  12218. moreInfoButton: document.getElementById("errorShowMore"),
  12219. lessInfoButton: document.getElementById("errorShowLess")
  12220. };
  12221. return {
  12222. appContainer: document.body,
  12223. mainContainer: document.getElementById("viewerContainer"),
  12224. viewerContainer: document.getElementById("viewer"),
  12225. eventBus: null,
  12226. toolbar: {
  12227. container: document.getElementById("toolbarViewer"),
  12228. numPages: document.getElementById("numPages"),
  12229. pageNumber: document.getElementById("pageNumber"),
  12230. scaleSelectContainer: document.getElementById("scaleSelectContainer"),
  12231. scaleSelect: document.getElementById("scaleSelect"),
  12232. customScaleOption: document.getElementById("customScaleOption"),
  12233. previous: document.getElementById("previous"),
  12234. next: document.getElementById("next"),
  12235. zoomIn: document.getElementById("zoomIn"),
  12236. zoomOut: document.getElementById("zoomOut"),
  12237. viewFind: document.getElementById("viewFind"),
  12238. openFile: document.getElementById("openFile"),
  12239. print: document.getElementById("print"),
  12240. presentationModeButton: document.getElementById("presentationMode"),
  12241. download: document.getElementById("download"),
  12242. viewBookmark: document.getElementById("viewBookmark")
  12243. },
  12244. secondaryToolbar: {
  12245. toolbar: document.getElementById("secondaryToolbar"),
  12246. toggleButton: document.getElementById("secondaryToolbarToggle"),
  12247. toolbarButtonContainer: document.getElementById("secondaryToolbarButtonContainer"),
  12248. presentationModeButton: document.getElementById("secondaryPresentationMode"),
  12249. openFileButton: document.getElementById("secondaryOpenFile"),
  12250. printButton: document.getElementById("secondaryPrint"),
  12251. downloadButton: document.getElementById("secondaryDownload"),
  12252. viewBookmarkButton: document.getElementById("secondaryViewBookmark"),
  12253. firstPageButton: document.getElementById("firstPage"),
  12254. lastPageButton: document.getElementById("lastPage"),
  12255. pageRotateCwButton: document.getElementById("pageRotateCw"),
  12256. pageRotateCcwButton: document.getElementById("pageRotateCcw"),
  12257. cursorSelectToolButton: document.getElementById("cursorSelectTool"),
  12258. cursorHandToolButton: document.getElementById("cursorHandTool"),
  12259. scrollVerticalButton: document.getElementById("scrollVertical"),
  12260. scrollHorizontalButton: document.getElementById("scrollHorizontal"),
  12261. scrollWrappedButton: document.getElementById("scrollWrapped"),
  12262. spreadNoneButton: document.getElementById("spreadNone"),
  12263. spreadOddButton: document.getElementById("spreadOdd"),
  12264. spreadEvenButton: document.getElementById("spreadEven"),
  12265. documentPropertiesButton: document.getElementById("documentProperties")
  12266. },
  12267. sidebar: {
  12268. outerContainer: document.getElementById("outerContainer"),
  12269. viewerContainer: document.getElementById("viewerContainer"),
  12270. toggleButton: document.getElementById("sidebarToggle"),
  12271. thumbnailButton: document.getElementById("viewThumbnail"),
  12272. outlineButton: document.getElementById("viewOutline"),
  12273. attachmentsButton: document.getElementById("viewAttachments"),
  12274. layersButton: document.getElementById("viewLayers"),
  12275. thumbnailView: document.getElementById("thumbnailView"),
  12276. outlineView: document.getElementById("outlineView"),
  12277. attachmentsView: document.getElementById("attachmentsView"),
  12278. layersView: document.getElementById("layersView"),
  12279. outlineOptionsContainer: document.getElementById("outlineOptionsContainer"),
  12280. currentOutlineItemButton: document.getElementById("currentOutlineItem")
  12281. },
  12282. sidebarResizer: {
  12283. outerContainer: document.getElementById("outerContainer"),
  12284. resizer: document.getElementById("sidebarResizer")
  12285. },
  12286. findBar: {
  12287. bar: document.getElementById("findbar"),
  12288. toggleButton: document.getElementById("viewFind"),
  12289. findField: document.getElementById("findInput"),
  12290. highlightAllCheckbox: document.getElementById("findHighlightAll"),
  12291. caseSensitiveCheckbox: document.getElementById("findMatchCase"),
  12292. entireWordCheckbox: document.getElementById("findEntireWord"),
  12293. findMsg: document.getElementById("findMsg"),
  12294. findResultsCount: document.getElementById("findResultsCount"),
  12295. findPreviousButton: document.getElementById("findPrevious"),
  12296. findNextButton: document.getElementById("findNext")
  12297. },
  12298. passwordOverlay: {
  12299. overlayName: "passwordOverlay",
  12300. container: document.getElementById("passwordOverlay"),
  12301. label: document.getElementById("passwordText"),
  12302. input: document.getElementById("password"),
  12303. submitButton: document.getElementById("passwordSubmit"),
  12304. cancelButton: document.getElementById("passwordCancel")
  12305. },
  12306. documentProperties: {
  12307. overlayName: "documentPropertiesOverlay",
  12308. container: document.getElementById("documentPropertiesOverlay"),
  12309. closeButton: document.getElementById("documentPropertiesClose"),
  12310. fields: {
  12311. fileName: document.getElementById("fileNameField"),
  12312. fileSize: document.getElementById("fileSizeField"),
  12313. title: document.getElementById("titleField"),
  12314. author: document.getElementById("authorField"),
  12315. subject: document.getElementById("subjectField"),
  12316. keywords: document.getElementById("keywordsField"),
  12317. creationDate: document.getElementById("creationDateField"),
  12318. modificationDate: document.getElementById("modificationDateField"),
  12319. creator: document.getElementById("creatorField"),
  12320. producer: document.getElementById("producerField"),
  12321. version: document.getElementById("versionField"),
  12322. pageCount: document.getElementById("pageCountField"),
  12323. pageSize: document.getElementById("pageSizeField"),
  12324. linearized: document.getElementById("linearizedField")
  12325. }
  12326. },
  12327. errorWrapper,
  12328. printContainer: document.getElementById("printContainer"),
  12329. openFileInputName: "fileInput",
  12330. debuggerScriptPath: "./debugger.js"
  12331. };
  12332. }
  12333. function webViewerLoad() {
  12334. const config = getViewerConfiguration();
  12335. const event = document.createEvent("CustomEvent");
  12336. event.initCustomEvent("webviewerloaded", true, true, {
  12337. source: window
  12338. });
  12339. try {
  12340. parent.document.dispatchEvent(event);
  12341. } catch (ex) {
  12342. console.error(`webviewerloaded: ${ex}`);
  12343. document.dispatchEvent(event);
  12344. }
  12345. _app.PDFViewerApplication.run(config);
  12346. }
  12347. if (document.blockUnblockOnload) {
  12348. document.blockUnblockOnload(true);
  12349. }
  12350. if (document.readyState === "interactive" || document.readyState === "complete") {
  12351. webViewerLoad();
  12352. } else {
  12353. document.addEventListener("DOMContentLoaded", webViewerLoad, true);
  12354. }
  12355. })();
  12356. /******/ })()
  12357. ;
  12358. //# sourceMappingURL=viewer.js.map