viewer.js 380 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129
  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. enableWebGL: {
  74. value: false,
  75. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  76. },
  77. externalLinkRel: {
  78. value: "noopener noreferrer nofollow",
  79. kind: OptionKind.VIEWER
  80. },
  81. externalLinkTarget: {
  82. value: 0,
  83. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  84. },
  85. historyUpdateUrl: {
  86. value: false,
  87. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  88. },
  89. ignoreDestinationZoom: {
  90. value: false,
  91. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  92. },
  93. imageResourcesPath: {
  94. value: "./images/",
  95. kind: OptionKind.VIEWER
  96. },
  97. maxCanvasPixels: {
  98. value: 16777216,
  99. compatibility: _viewer_compatibility.viewerCompatibilityParams.maxCanvasPixels,
  100. kind: OptionKind.VIEWER
  101. },
  102. pdfBugEnabled: {
  103. value: false,
  104. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  105. },
  106. printResolution: {
  107. value: 150,
  108. kind: OptionKind.VIEWER
  109. },
  110. renderer: {
  111. value: "canvas",
  112. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  113. },
  114. renderInteractiveForms: {
  115. value: true,
  116. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  117. },
  118. sidebarViewOnLoad: {
  119. value: -1,
  120. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  121. },
  122. scrollModeOnLoad: {
  123. value: -1,
  124. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  125. },
  126. spreadModeOnLoad: {
  127. value: -1,
  128. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  129. },
  130. textLayerMode: {
  131. value: 1,
  132. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  133. },
  134. useOnlyCssZoom: {
  135. value: false,
  136. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  137. },
  138. viewerCssTheme: {
  139. value: 0,
  140. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  141. },
  142. viewOnLoad: {
  143. value: 0,
  144. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  145. },
  146. cMapPacked: {
  147. value: true,
  148. kind: OptionKind.API
  149. },
  150. cMapUrl: {
  151. value: "../web/cmaps/",
  152. kind: OptionKind.API
  153. },
  154. disableAutoFetch: {
  155. value: false,
  156. kind: OptionKind.API + OptionKind.PREFERENCE
  157. },
  158. disableFontFace: {
  159. value: false,
  160. kind: OptionKind.API + OptionKind.PREFERENCE
  161. },
  162. disableRange: {
  163. value: false,
  164. kind: OptionKind.API + OptionKind.PREFERENCE
  165. },
  166. disableStream: {
  167. value: false,
  168. kind: OptionKind.API + OptionKind.PREFERENCE
  169. },
  170. docBaseUrl: {
  171. value: "",
  172. kind: OptionKind.API
  173. },
  174. enableXfa: {
  175. value: false,
  176. kind: OptionKind.API
  177. },
  178. fontExtraProperties: {
  179. value: false,
  180. kind: OptionKind.API
  181. },
  182. isEvalSupported: {
  183. value: true,
  184. kind: OptionKind.API
  185. },
  186. maxImageSize: {
  187. value: -1,
  188. kind: OptionKind.API
  189. },
  190. pdfBug: {
  191. value: false,
  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. }
  221. const userOptions = Object.create(null);
  222. class AppOptions {
  223. constructor() {
  224. throw new Error("Cannot initialize AppOptions.");
  225. }
  226. static get(name) {
  227. const userOption = userOptions[name];
  228. if (userOption !== undefined) {
  229. return userOption;
  230. }
  231. const defaultOption = defaultOptions[name];
  232. if (defaultOption !== undefined) {
  233. return defaultOption.compatibility ?? defaultOption.value;
  234. }
  235. return undefined;
  236. }
  237. static getAll(kind = null) {
  238. const options = Object.create(null);
  239. for (const name in defaultOptions) {
  240. const defaultOption = defaultOptions[name];
  241. if (kind) {
  242. if ((kind & defaultOption.kind) === 0) {
  243. continue;
  244. }
  245. if (kind === OptionKind.PREFERENCE) {
  246. const value = defaultOption.value,
  247. valueType = typeof value;
  248. if (valueType === "boolean" || valueType === "string" || valueType === "number" && Number.isInteger(value)) {
  249. options[name] = value;
  250. continue;
  251. }
  252. throw new Error(`Invalid type for preference: ${name}`);
  253. }
  254. }
  255. const userOption = userOptions[name];
  256. options[name] = userOption !== undefined ? userOption : defaultOption.compatibility ?? defaultOption.value;
  257. }
  258. return options;
  259. }
  260. static set(name, value) {
  261. userOptions[name] = value;
  262. }
  263. static setAll(options) {
  264. for (const name in options) {
  265. userOptions[name] = options[name];
  266. }
  267. }
  268. static remove(name) {
  269. delete userOptions[name];
  270. }
  271. }
  272. exports.AppOptions = AppOptions;
  273. /***/ }),
  274. /* 2 */
  275. /***/ ((__unused_webpack_module, exports) => {
  276. Object.defineProperty(exports, "__esModule", ({
  277. value: true
  278. }));
  279. exports.viewerCompatibilityParams = void 0;
  280. const compatibilityParams = Object.create(null);
  281. {
  282. const userAgent = typeof navigator !== "undefined" && navigator.userAgent || "";
  283. const platform = typeof navigator !== "undefined" && navigator.platform || "";
  284. const maxTouchPoints = typeof navigator !== "undefined" && navigator.maxTouchPoints || 1;
  285. const isAndroid = /Android/.test(userAgent);
  286. const isIOS = /\b(iPad|iPhone|iPod)(?=;)/.test(userAgent) || platform === "MacIntel" && maxTouchPoints > 1;
  287. const isIOSChrome = /CriOS/.test(userAgent);
  288. (function checkOnBlobSupport() {
  289. if (isIOSChrome) {
  290. compatibilityParams.disableCreateObjectURL = true;
  291. }
  292. })();
  293. (function checkCanvasSizeLimitation() {
  294. if (isIOS || isAndroid) {
  295. compatibilityParams.maxCanvasPixels = 5242880;
  296. }
  297. })();
  298. }
  299. const viewerCompatibilityParams = Object.freeze(compatibilityParams);
  300. exports.viewerCompatibilityParams = viewerCompatibilityParams;
  301. /***/ }),
  302. /* 3 */
  303. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  304. Object.defineProperty(exports, "__esModule", ({
  305. value: true
  306. }));
  307. exports.PDFViewerApplication = exports.PDFPrintServiceFactory = exports.DefaultExternalServices = void 0;
  308. var _ui_utils = __webpack_require__(4);
  309. var _app_options = __webpack_require__(1);
  310. var _pdfjsLib = __webpack_require__(5);
  311. var _pdf_cursor_tools = __webpack_require__(6);
  312. var _pdf_rendering_queue = __webpack_require__(8);
  313. var _overlay_manager = __webpack_require__(9);
  314. var _password_prompt = __webpack_require__(10);
  315. var _pdf_attachment_viewer = __webpack_require__(11);
  316. var _pdf_document_properties = __webpack_require__(13);
  317. var _pdf_find_bar = __webpack_require__(14);
  318. var _pdf_find_controller = __webpack_require__(15);
  319. var _pdf_history = __webpack_require__(17);
  320. var _pdf_layer_viewer = __webpack_require__(18);
  321. var _pdf_link_service = __webpack_require__(19);
  322. var _pdf_outline_viewer = __webpack_require__(20);
  323. var _pdf_presentation_mode = __webpack_require__(21);
  324. var _pdf_scripting_manager = __webpack_require__(22);
  325. var _pdf_sidebar = __webpack_require__(23);
  326. var _pdf_sidebar_resizer = __webpack_require__(24);
  327. var _pdf_thumbnail_viewer = __webpack_require__(25);
  328. var _pdf_viewer = __webpack_require__(27);
  329. var _secondary_toolbar = __webpack_require__(34);
  330. var _toolbar = __webpack_require__(36);
  331. var _viewer_compatibility = __webpack_require__(2);
  332. var _view_history = __webpack_require__(37);
  333. const DEFAULT_SCALE_DELTA = 1.1;
  334. const DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT = 5000;
  335. const FORCE_PAGES_LOADED_TIMEOUT = 10000;
  336. const WHEEL_ZOOM_DISABLED_TIMEOUT = 1000;
  337. const ENABLE_PERMISSIONS_CLASS = "enablePermissions";
  338. const ViewOnLoad = {
  339. UNKNOWN: -1,
  340. PREVIOUS: 0,
  341. INITIAL: 1
  342. };
  343. const ViewerCssTheme = {
  344. AUTOMATIC: 0,
  345. LIGHT: 1,
  346. DARK: 2
  347. };
  348. 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"];
  349. 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"];
  350. class DefaultExternalServices {
  351. constructor() {
  352. throw new Error("Cannot initialize DefaultExternalServices.");
  353. }
  354. static updateFindControlState(data) {}
  355. static updateFindMatchesCount(data) {}
  356. static initPassiveLoading(callbacks) {}
  357. static async fallback(data) {}
  358. static reportTelemetry(data) {}
  359. static createDownloadManager(options) {
  360. throw new Error("Not implemented: createDownloadManager");
  361. }
  362. static createPreferences() {
  363. throw new Error("Not implemented: createPreferences");
  364. }
  365. static createL10n(options) {
  366. throw new Error("Not implemented: createL10n");
  367. }
  368. static createScripting(options) {
  369. throw new Error("Not implemented: createScripting");
  370. }
  371. static get supportsIntegratedFind() {
  372. return (0, _pdfjsLib.shadow)(this, "supportsIntegratedFind", false);
  373. }
  374. static get supportsDocumentFonts() {
  375. return (0, _pdfjsLib.shadow)(this, "supportsDocumentFonts", true);
  376. }
  377. static get supportedMouseWheelZoomModifierKeys() {
  378. return (0, _pdfjsLib.shadow)(this, "supportedMouseWheelZoomModifierKeys", {
  379. ctrlKey: true,
  380. metaKey: true
  381. });
  382. }
  383. static get isInAutomation() {
  384. return (0, _pdfjsLib.shadow)(this, "isInAutomation", false);
  385. }
  386. }
  387. exports.DefaultExternalServices = DefaultExternalServices;
  388. const PDFViewerApplication = {
  389. initialBookmark: document.location.hash.substring(1),
  390. _initializedCapability: (0, _pdfjsLib.createPromiseCapability)(),
  391. fellback: false,
  392. appConfig: null,
  393. pdfDocument: null,
  394. pdfLoadingTask: null,
  395. printService: null,
  396. pdfViewer: null,
  397. pdfThumbnailViewer: null,
  398. pdfRenderingQueue: null,
  399. pdfPresentationMode: null,
  400. pdfDocumentProperties: null,
  401. pdfLinkService: null,
  402. pdfHistory: null,
  403. pdfSidebar: null,
  404. pdfSidebarResizer: null,
  405. pdfOutlineViewer: null,
  406. pdfAttachmentViewer: null,
  407. pdfLayerViewer: null,
  408. pdfCursorTools: null,
  409. pdfScriptingManager: null,
  410. store: null,
  411. downloadManager: null,
  412. overlayManager: null,
  413. preferences: null,
  414. toolbar: null,
  415. secondaryToolbar: null,
  416. eventBus: null,
  417. l10n: null,
  418. isInitialViewSet: false,
  419. downloadComplete: false,
  420. isViewerEmbedded: window.parent !== window,
  421. url: "",
  422. baseUrl: "",
  423. externalServices: DefaultExternalServices,
  424. _boundEvents: Object.create(null),
  425. documentInfo: null,
  426. metadata: null,
  427. _contentDispositionFilename: null,
  428. _contentLength: null,
  429. triggerDelayedFallback: 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 ("webgl" in hashParams) {
  493. _app_options.AppOptions.set("enableWebGL", hashParams.webgl === "true");
  494. }
  495. if ("verbosity" in hashParams) {
  496. _app_options.AppOptions.set("verbosity", hashParams.verbosity | 0);
  497. }
  498. if ("textlayer" in hashParams) {
  499. switch (hashParams.textlayer) {
  500. case "off":
  501. _app_options.AppOptions.set("textLayerMode", _ui_utils.TextLayerMode.DISABLE);
  502. break;
  503. case "visible":
  504. case "shadow":
  505. case "hover":
  506. const viewer = this.appConfig.viewerContainer;
  507. viewer.classList.add("textLayer-" + hashParams.textlayer);
  508. break;
  509. }
  510. }
  511. if ("pdfbug" in hashParams) {
  512. _app_options.AppOptions.set("pdfBug", true);
  513. _app_options.AppOptions.set("fontExtraProperties", true);
  514. const enabled = hashParams.pdfbug.split(",");
  515. waitOn.push(loadAndEnablePDFBug(enabled));
  516. }
  517. if ("locale" in hashParams) {
  518. _app_options.AppOptions.set("locale", hashParams.locale);
  519. }
  520. if (waitOn.length === 0) {
  521. return undefined;
  522. }
  523. return Promise.all(waitOn).catch(reason => {
  524. console.error(`_parseHashParameters: "${reason.message}".`);
  525. });
  526. },
  527. async _initializeL10n() {
  528. this.l10n = this.externalServices.createL10n({
  529. locale: _app_options.AppOptions.get("locale")
  530. });
  531. const dir = await this.l10n.getDirection();
  532. document.getElementsByTagName("html")[0].dir = dir;
  533. },
  534. _forceCssTheme() {
  535. const cssTheme = _app_options.AppOptions.get("viewerCssTheme");
  536. if (cssTheme === ViewerCssTheme.AUTOMATIC || !Object.values(ViewerCssTheme).includes(cssTheme)) {
  537. return;
  538. }
  539. try {
  540. const styleSheet = document.styleSheets[0];
  541. const cssRules = styleSheet?.cssRules || [];
  542. for (let i = 0, ii = cssRules.length; i < ii; i++) {
  543. const rule = cssRules[i];
  544. if (rule instanceof CSSMediaRule && rule.media?.[0] === "(prefers-color-scheme: dark)") {
  545. if (cssTheme === ViewerCssTheme.LIGHT) {
  546. styleSheet.deleteRule(i);
  547. return;
  548. }
  549. const darkRules = /^@media \(prefers-color-scheme: dark\) {\n\s*([\w\s-.,:;/\\{}()]+)\n}$/.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. enableWebGL: _app_options.AppOptions.get("enableWebGL"),
  605. l10n: this.l10n,
  606. textLayerMode: _app_options.AppOptions.get("textLayerMode"),
  607. imageResourcesPath: _app_options.AppOptions.get("imageResourcesPath"),
  608. renderInteractiveForms: _app_options.AppOptions.get("renderInteractiveForms"),
  609. enablePrintAutoRotate: _app_options.AppOptions.get("enablePrintAutoRotate"),
  610. useOnlyCssZoom: _app_options.AppOptions.get("useOnlyCssZoom"),
  611. maxCanvasPixels: _app_options.AppOptions.get("maxCanvasPixels"),
  612. enableScripting: _app_options.AppOptions.get("enableScripting")
  613. });
  614. pdfRenderingQueue.setViewer(this.pdfViewer);
  615. pdfLinkService.setViewer(this.pdfViewer);
  616. pdfScriptingManager.setViewer(this.pdfViewer);
  617. this.pdfThumbnailViewer = new _pdf_thumbnail_viewer.PDFThumbnailViewer({
  618. container: appConfig.sidebar.thumbnailView,
  619. eventBus,
  620. renderingQueue: pdfRenderingQueue,
  621. linkService: pdfLinkService,
  622. l10n: this.l10n
  623. });
  624. pdfRenderingQueue.setThumbnailViewer(this.pdfThumbnailViewer);
  625. this.pdfHistory = new _pdf_history.PDFHistory({
  626. linkService: pdfLinkService,
  627. eventBus
  628. });
  629. pdfLinkService.setHistory(this.pdfHistory);
  630. if (!this.supportsIntegratedFind) {
  631. this.findBar = new _pdf_find_bar.PDFFindBar(appConfig.findBar, eventBus, this.l10n);
  632. }
  633. this.pdfDocumentProperties = new _pdf_document_properties.PDFDocumentProperties(appConfig.documentProperties, this.overlayManager, eventBus, this.l10n);
  634. this.pdfCursorTools = new _pdf_cursor_tools.PDFCursorTools({
  635. container,
  636. eventBus,
  637. cursorToolOnLoad: _app_options.AppOptions.get("cursorToolOnLoad")
  638. });
  639. this.toolbar = new _toolbar.Toolbar(appConfig.toolbar, eventBus, this.l10n);
  640. this.secondaryToolbar = new _secondary_toolbar.SecondaryToolbar(appConfig.secondaryToolbar, container, eventBus);
  641. if (this.supportsFullscreen) {
  642. this.pdfPresentationMode = new _pdf_presentation_mode.PDFPresentationMode({
  643. container,
  644. pdfViewer: this.pdfViewer,
  645. eventBus
  646. });
  647. }
  648. this.passwordPrompt = new _password_prompt.PasswordPrompt(appConfig.passwordOverlay, this.overlayManager, this.l10n, this.isViewerEmbedded);
  649. this.pdfOutlineViewer = new _pdf_outline_viewer.PDFOutlineViewer({
  650. container: appConfig.sidebar.outlineView,
  651. eventBus,
  652. linkService: pdfLinkService
  653. });
  654. this.pdfAttachmentViewer = new _pdf_attachment_viewer.PDFAttachmentViewer({
  655. container: appConfig.sidebar.attachmentsView,
  656. eventBus,
  657. downloadManager
  658. });
  659. this.pdfLayerViewer = new _pdf_layer_viewer.PDFLayerViewer({
  660. container: appConfig.sidebar.layersView,
  661. eventBus,
  662. l10n: this.l10n
  663. });
  664. this.pdfSidebar = new _pdf_sidebar.PDFSidebar({
  665. elements: appConfig.sidebar,
  666. pdfViewer: this.pdfViewer,
  667. pdfThumbnailViewer: this.pdfThumbnailViewer,
  668. eventBus,
  669. l10n: this.l10n
  670. });
  671. this.pdfSidebar.onToggled = this.forceRendering.bind(this);
  672. this.pdfSidebarResizer = new _pdf_sidebar_resizer.PDFSidebarResizer(appConfig.sidebarResizer, eventBus, this.l10n);
  673. },
  674. run(config) {
  675. this.initialize(config).then(webViewerInitialized);
  676. },
  677. get initialized() {
  678. return this._initializedCapability.settled;
  679. },
  680. get initializedPromise() {
  681. return this._initializedCapability.promise;
  682. },
  683. zoomIn(ticks) {
  684. if (this.pdfViewer.isInPresentationMode) {
  685. return;
  686. }
  687. let newScale = this.pdfViewer.currentScale;
  688. do {
  689. newScale = (newScale * DEFAULT_SCALE_DELTA).toFixed(2);
  690. newScale = Math.ceil(newScale * 10) / 10;
  691. newScale = Math.min(_ui_utils.MAX_SCALE, newScale);
  692. } while (--ticks > 0 && newScale < _ui_utils.MAX_SCALE);
  693. this.pdfViewer.currentScaleValue = newScale;
  694. },
  695. zoomOut(ticks) {
  696. if (this.pdfViewer.isInPresentationMode) {
  697. return;
  698. }
  699. let newScale = this.pdfViewer.currentScale;
  700. do {
  701. newScale = (newScale / DEFAULT_SCALE_DELTA).toFixed(2);
  702. newScale = Math.floor(newScale * 10) / 10;
  703. newScale = Math.max(_ui_utils.MIN_SCALE, newScale);
  704. } while (--ticks > 0 && newScale > _ui_utils.MIN_SCALE);
  705. this.pdfViewer.currentScaleValue = newScale;
  706. },
  707. zoomReset() {
  708. if (this.pdfViewer.isInPresentationMode) {
  709. return;
  710. }
  711. this.pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  712. },
  713. get pagesCount() {
  714. return this.pdfDocument ? this.pdfDocument.numPages : 0;
  715. },
  716. get page() {
  717. return this.pdfViewer.currentPageNumber;
  718. },
  719. set page(val) {
  720. this.pdfViewer.currentPageNumber = val;
  721. },
  722. get supportsPrinting() {
  723. return PDFPrintServiceFactory.instance.supportsPrinting;
  724. },
  725. get supportsFullscreen() {
  726. const doc = document.documentElement;
  727. let support = !!(doc.requestFullscreen || doc.mozRequestFullScreen || doc.webkitRequestFullScreen);
  728. if (document.fullscreenEnabled === false || document.mozFullScreenEnabled === false || document.webkitFullscreenEnabled === false) {
  729. support = false;
  730. }
  731. return (0, _pdfjsLib.shadow)(this, "supportsFullscreen", support);
  732. },
  733. get supportsIntegratedFind() {
  734. return this.externalServices.supportsIntegratedFind;
  735. },
  736. get supportsDocumentFonts() {
  737. return this.externalServices.supportsDocumentFonts;
  738. },
  739. get loadingBar() {
  740. const bar = new _ui_utils.ProgressBar("#loadingBar");
  741. return (0, _pdfjsLib.shadow)(this, "loadingBar", bar);
  742. },
  743. get supportedMouseWheelZoomModifierKeys() {
  744. return this.externalServices.supportedMouseWheelZoomModifierKeys;
  745. },
  746. initPassiveLoading() {
  747. throw new Error("Not implemented: initPassiveLoading");
  748. },
  749. setTitleUsingUrl(url = "") {
  750. this.url = url;
  751. this.baseUrl = url.split("#")[0];
  752. let title = (0, _pdfjsLib.getPdfFilenameFromUrl)(url, "");
  753. if (!title) {
  754. try {
  755. title = decodeURIComponent((0, _pdfjsLib.getFilenameFromUrl)(url)) || url;
  756. } catch (ex) {
  757. title = url;
  758. }
  759. }
  760. this.setTitle(title);
  761. },
  762. setTitle(title) {
  763. if (this.isViewerEmbedded) {
  764. return;
  765. }
  766. document.title = title;
  767. },
  768. get _docFilename() {
  769. return this._contentDispositionFilename || (0, _pdfjsLib.getPdfFilenameFromUrl)(this.url);
  770. },
  771. _cancelIdleCallbacks() {
  772. if (!this._idleCallbacks.size) {
  773. return;
  774. }
  775. for (const callback of this._idleCallbacks) {
  776. window.cancelIdleCallback(callback);
  777. }
  778. this._idleCallbacks.clear();
  779. },
  780. async close() {
  781. this._unblockDocumentLoadEvent();
  782. const {
  783. container
  784. } = this.appConfig.errorWrapper;
  785. container.hidden = true;
  786. if (!this.pdfLoadingTask) {
  787. return;
  788. }
  789. if (this.pdfDocument?.annotationStorage.size > 0 && this._annotationStorageModified) {
  790. try {
  791. await this.save({
  792. sourceEventType: "save"
  793. });
  794. } catch (reason) {}
  795. }
  796. const promises = [];
  797. promises.push(this.pdfLoadingTask.destroy());
  798. this.pdfLoadingTask = null;
  799. if (this.pdfDocument) {
  800. this.pdfDocument = null;
  801. this.pdfThumbnailViewer.setDocument(null);
  802. this.pdfViewer.setDocument(null);
  803. this.pdfLinkService.setDocument(null);
  804. this.pdfDocumentProperties.setDocument(null);
  805. }
  806. webViewerResetPermissions();
  807. this.store = null;
  808. this.isInitialViewSet = false;
  809. this.downloadComplete = false;
  810. this.url = "";
  811. this.baseUrl = "";
  812. this.documentInfo = null;
  813. this.metadata = null;
  814. this._contentDispositionFilename = null;
  815. this._contentLength = null;
  816. this.triggerDelayedFallback = 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(this.pdfDocument.annotationStorage);
  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. _delayedFallback(featureId) {
  958. this.externalServices.reportTelemetry({
  959. type: "unsupportedFeature",
  960. featureId
  961. });
  962. if (!this.triggerDelayedFallback) {
  963. this.triggerDelayedFallback = () => {
  964. this.fallback(featureId);
  965. this.triggerDelayedFallback = null;
  966. };
  967. }
  968. },
  969. fallback(featureId) {
  970. this.externalServices.reportTelemetry({
  971. type: "unsupportedFeature",
  972. featureId
  973. });
  974. switch (featureId) {
  975. case _pdfjsLib.UNSUPPORTED_FEATURES.errorFontLoadNative:
  976. case _pdfjsLib.UNSUPPORTED_FEATURES.errorFontMissing:
  977. return;
  978. }
  979. if (this.fellback) {
  980. return;
  981. }
  982. this.fellback = true;
  983. this.externalServices.fallback({
  984. featureId,
  985. url: this.baseUrl
  986. }).then(download => {
  987. if (!download) {
  988. return;
  989. }
  990. this.download({
  991. sourceEventType: "download"
  992. });
  993. });
  994. },
  995. _documentError(message, moreInfo = null) {
  996. this._unblockDocumentLoadEvent();
  997. this._otherError(message, moreInfo);
  998. },
  999. _otherError(message, moreInfo = null) {
  1000. const moreInfoText = [this.l10n.get("error_version_info", {
  1001. version: _pdfjsLib.version || "?",
  1002. build: _pdfjsLib.build || "?"
  1003. })];
  1004. if (moreInfo) {
  1005. moreInfoText.push(this.l10n.get("error_message", {
  1006. message: moreInfo.message
  1007. }));
  1008. if (moreInfo.stack) {
  1009. moreInfoText.push(this.l10n.get("error_stack", {
  1010. stack: moreInfo.stack
  1011. }));
  1012. } else {
  1013. if (moreInfo.filename) {
  1014. moreInfoText.push(this.l10n.get("error_file", {
  1015. file: moreInfo.filename
  1016. }));
  1017. }
  1018. if (moreInfo.lineNumber) {
  1019. moreInfoText.push(this.l10n.get("error_line", {
  1020. line: moreInfo.lineNumber
  1021. }));
  1022. }
  1023. }
  1024. }
  1025. const errorWrapperConfig = this.appConfig.errorWrapper;
  1026. const errorWrapper = errorWrapperConfig.container;
  1027. errorWrapper.hidden = false;
  1028. const errorMessage = errorWrapperConfig.errorMessage;
  1029. errorMessage.textContent = message;
  1030. const closeButton = errorWrapperConfig.closeButton;
  1031. closeButton.onclick = function () {
  1032. errorWrapper.hidden = true;
  1033. };
  1034. const errorMoreInfo = errorWrapperConfig.errorMoreInfo;
  1035. const moreInfoButton = errorWrapperConfig.moreInfoButton;
  1036. const lessInfoButton = errorWrapperConfig.lessInfoButton;
  1037. moreInfoButton.onclick = function () {
  1038. errorMoreInfo.hidden = false;
  1039. moreInfoButton.hidden = true;
  1040. lessInfoButton.hidden = false;
  1041. errorMoreInfo.style.height = errorMoreInfo.scrollHeight + "px";
  1042. };
  1043. lessInfoButton.onclick = function () {
  1044. errorMoreInfo.hidden = true;
  1045. moreInfoButton.hidden = false;
  1046. lessInfoButton.hidden = true;
  1047. };
  1048. moreInfoButton.oncontextmenu = _ui_utils.noContextMenuHandler;
  1049. lessInfoButton.oncontextmenu = _ui_utils.noContextMenuHandler;
  1050. closeButton.oncontextmenu = _ui_utils.noContextMenuHandler;
  1051. moreInfoButton.hidden = false;
  1052. lessInfoButton.hidden = true;
  1053. Promise.all(moreInfoText).then(parts => {
  1054. errorMoreInfo.value = parts.join("\n");
  1055. });
  1056. },
  1057. progress(level) {
  1058. if (this.downloadComplete) {
  1059. return;
  1060. }
  1061. const percent = Math.round(level * 100);
  1062. if (percent > this.loadingBar.percent || isNaN(percent)) {
  1063. this.loadingBar.percent = percent;
  1064. const disableAutoFetch = this.pdfDocument ? this.pdfDocument.loadingParams.disableAutoFetch : _app_options.AppOptions.get("disableAutoFetch");
  1065. if (disableAutoFetch && percent) {
  1066. if (this.disableAutoFetchLoadingBarTimeout) {
  1067. clearTimeout(this.disableAutoFetchLoadingBarTimeout);
  1068. this.disableAutoFetchLoadingBarTimeout = null;
  1069. }
  1070. this.loadingBar.show();
  1071. this.disableAutoFetchLoadingBarTimeout = setTimeout(() => {
  1072. this.loadingBar.hide();
  1073. this.disableAutoFetchLoadingBarTimeout = null;
  1074. }, DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT);
  1075. }
  1076. }
  1077. },
  1078. load(pdfDocument) {
  1079. this.pdfDocument = pdfDocument;
  1080. pdfDocument.getDownloadInfo().then(({
  1081. length
  1082. }) => {
  1083. this._contentLength = length;
  1084. this.downloadComplete = true;
  1085. this.loadingBar.hide();
  1086. firstPagePromise.then(() => {
  1087. this.eventBus.dispatch("documentloaded", {
  1088. source: this
  1089. });
  1090. });
  1091. });
  1092. const pageLayoutPromise = pdfDocument.getPageLayout().catch(function () {});
  1093. const pageModePromise = pdfDocument.getPageMode().catch(function () {});
  1094. const openActionPromise = pdfDocument.getOpenAction().catch(function () {});
  1095. this.toolbar.setPagesCount(pdfDocument.numPages, false);
  1096. this.secondaryToolbar.setPagesCount(pdfDocument.numPages);
  1097. let baseDocumentUrl;
  1098. baseDocumentUrl = null;
  1099. this.pdfLinkService.setDocument(pdfDocument, baseDocumentUrl);
  1100. this.pdfDocumentProperties.setDocument(pdfDocument, this.url);
  1101. const pdfViewer = this.pdfViewer;
  1102. pdfViewer.setDocument(pdfDocument);
  1103. const {
  1104. firstPagePromise,
  1105. onePageRendered,
  1106. pagesPromise
  1107. } = pdfViewer;
  1108. const pdfThumbnailViewer = this.pdfThumbnailViewer;
  1109. pdfThumbnailViewer.setDocument(pdfDocument);
  1110. const storedPromise = (this.store = new _view_history.ViewHistory(pdfDocument.fingerprint)).getMultiple({
  1111. page: null,
  1112. zoom: _ui_utils.DEFAULT_SCALE_VALUE,
  1113. scrollLeft: "0",
  1114. scrollTop: "0",
  1115. rotation: null,
  1116. sidebarView: _ui_utils.SidebarView.UNKNOWN,
  1117. scrollMode: _ui_utils.ScrollMode.UNKNOWN,
  1118. spreadMode: _ui_utils.SpreadMode.UNKNOWN
  1119. }).catch(() => {
  1120. return Object.create(null);
  1121. });
  1122. firstPagePromise.then(pdfPage => {
  1123. this.loadingBar.setWidth(this.appConfig.viewerContainer);
  1124. this._initializeAnnotationStorageCallbacks(pdfDocument);
  1125. Promise.all([_ui_utils.animationStarted, storedPromise, pageLayoutPromise, pageModePromise, openActionPromise]).then(async ([timeStamp, stored, pageLayout, pageMode, openAction]) => {
  1126. const viewOnLoad = _app_options.AppOptions.get("viewOnLoad");
  1127. this._initializePdfHistory({
  1128. fingerprint: pdfDocument.fingerprint,
  1129. viewOnLoad,
  1130. initialDest: openAction?.dest
  1131. });
  1132. const initialBookmark = this.initialBookmark;
  1133. const zoom = _app_options.AppOptions.get("defaultZoomValue");
  1134. let hash = zoom ? `zoom=${zoom}` : null;
  1135. let rotation = null;
  1136. let sidebarView = _app_options.AppOptions.get("sidebarViewOnLoad");
  1137. let scrollMode = _app_options.AppOptions.get("scrollModeOnLoad");
  1138. let spreadMode = _app_options.AppOptions.get("spreadModeOnLoad");
  1139. if (stored.page && viewOnLoad !== ViewOnLoad.INITIAL) {
  1140. hash = `page=${stored.page}&zoom=${zoom || stored.zoom},` + `${stored.scrollLeft},${stored.scrollTop}`;
  1141. rotation = parseInt(stored.rotation, 10);
  1142. if (sidebarView === _ui_utils.SidebarView.UNKNOWN) {
  1143. sidebarView = stored.sidebarView | 0;
  1144. }
  1145. if (scrollMode === _ui_utils.ScrollMode.UNKNOWN) {
  1146. scrollMode = stored.scrollMode | 0;
  1147. }
  1148. if (spreadMode === _ui_utils.SpreadMode.UNKNOWN) {
  1149. spreadMode = stored.spreadMode | 0;
  1150. }
  1151. }
  1152. if (pageMode && sidebarView === _ui_utils.SidebarView.UNKNOWN) {
  1153. sidebarView = (0, _ui_utils.apiPageModeToSidebarView)(pageMode);
  1154. }
  1155. if (pageLayout && spreadMode === _ui_utils.SpreadMode.UNKNOWN) {
  1156. spreadMode = (0, _ui_utils.apiPageLayoutToSpreadMode)(pageLayout);
  1157. }
  1158. this.setInitialView(hash, {
  1159. rotation,
  1160. sidebarView,
  1161. scrollMode,
  1162. spreadMode
  1163. });
  1164. this.eventBus.dispatch("documentinit", {
  1165. source: this
  1166. });
  1167. if (!this.isViewerEmbedded) {
  1168. pdfViewer.focus();
  1169. }
  1170. this._initializePermissions(pdfDocument);
  1171. await Promise.race([pagesPromise, new Promise(resolve => {
  1172. setTimeout(resolve, FORCE_PAGES_LOADED_TIMEOUT);
  1173. })]);
  1174. if (!initialBookmark && !hash) {
  1175. return;
  1176. }
  1177. if (pdfViewer.hasEqualPageSizes) {
  1178. return;
  1179. }
  1180. this.initialBookmark = initialBookmark;
  1181. pdfViewer.currentScaleValue = pdfViewer.currentScaleValue;
  1182. this.setInitialView(hash);
  1183. }).catch(() => {
  1184. this.setInitialView();
  1185. }).then(function () {
  1186. pdfViewer.update();
  1187. });
  1188. });
  1189. pagesPromise.then(() => {
  1190. this._unblockDocumentLoadEvent();
  1191. this._initializeAutoPrint(pdfDocument, openActionPromise);
  1192. });
  1193. onePageRendered.then(() => {
  1194. pdfDocument.getOutline().then(outline => {
  1195. this.pdfOutlineViewer.render({
  1196. outline,
  1197. pdfDocument
  1198. });
  1199. });
  1200. pdfDocument.getAttachments().then(attachments => {
  1201. this.pdfAttachmentViewer.render({
  1202. attachments
  1203. });
  1204. });
  1205. pdfViewer.optionalContentConfigPromise.then(optionalContentConfig => {
  1206. this.pdfLayerViewer.render({
  1207. optionalContentConfig,
  1208. pdfDocument
  1209. });
  1210. });
  1211. if ("requestIdleCallback" in window) {
  1212. const callback = window.requestIdleCallback(() => {
  1213. this._collectTelemetry(pdfDocument);
  1214. this._idleCallbacks.delete(callback);
  1215. }, {
  1216. timeout: 1000
  1217. });
  1218. this._idleCallbacks.add(callback);
  1219. }
  1220. });
  1221. this._initializePageLabels(pdfDocument);
  1222. this._initializeMetadata(pdfDocument);
  1223. },
  1224. async _scriptingDocProperties(pdfDocument) {
  1225. if (!this.documentInfo) {
  1226. await new Promise(resolve => {
  1227. this.eventBus._on("metadataloaded", resolve, {
  1228. once: true
  1229. });
  1230. });
  1231. if (pdfDocument !== this.pdfDocument) {
  1232. return null;
  1233. }
  1234. }
  1235. if (!this._contentLength) {
  1236. await new Promise(resolve => {
  1237. this.eventBus._on("documentloaded", resolve, {
  1238. once: true
  1239. });
  1240. });
  1241. if (pdfDocument !== this.pdfDocument) {
  1242. return null;
  1243. }
  1244. }
  1245. return { ...this.documentInfo,
  1246. baseURL: this.baseUrl,
  1247. filesize: this._contentLength,
  1248. filename: this._docFilename,
  1249. metadata: this.metadata?.getRaw(),
  1250. authors: this.metadata?.get("dc:creator"),
  1251. numPages: this.pagesCount,
  1252. URL: this.url
  1253. };
  1254. },
  1255. async _collectTelemetry(pdfDocument) {
  1256. const markInfo = await this.pdfDocument.getMarkInfo();
  1257. if (pdfDocument !== this.pdfDocument) {
  1258. return;
  1259. }
  1260. const tagged = markInfo?.Marked || false;
  1261. this.externalServices.reportTelemetry({
  1262. type: "tagged",
  1263. tagged
  1264. });
  1265. },
  1266. async _initializeAutoPrint(pdfDocument, openActionPromise) {
  1267. const [openAction, javaScript] = await Promise.all([openActionPromise, !this.pdfViewer.enableScripting ? pdfDocument.getJavaScript() : null]);
  1268. if (pdfDocument !== this.pdfDocument) {
  1269. return;
  1270. }
  1271. let triggerAutoPrint = false;
  1272. if (openAction?.action === "Print") {
  1273. triggerAutoPrint = true;
  1274. }
  1275. if (javaScript) {
  1276. javaScript.some(js => {
  1277. if (!js) {
  1278. return false;
  1279. }
  1280. console.warn("Warning: JavaScript is not supported");
  1281. this._delayedFallback(_pdfjsLib.UNSUPPORTED_FEATURES.javaScript);
  1282. return true;
  1283. });
  1284. if (!triggerAutoPrint) {
  1285. for (const js of javaScript) {
  1286. if (js && _ui_utils.AutoPrintRegExp.test(js)) {
  1287. triggerAutoPrint = true;
  1288. break;
  1289. }
  1290. }
  1291. }
  1292. }
  1293. if (triggerAutoPrint) {
  1294. this.triggerPrinting();
  1295. }
  1296. },
  1297. async _initializeMetadata(pdfDocument) {
  1298. const {
  1299. info,
  1300. metadata,
  1301. contentDispositionFilename,
  1302. contentLength
  1303. } = await pdfDocument.getMetadata();
  1304. if (pdfDocument !== this.pdfDocument) {
  1305. return;
  1306. }
  1307. this.documentInfo = info;
  1308. this.metadata = metadata;
  1309. this._contentDispositionFilename ?? (this._contentDispositionFilename = contentDispositionFilename);
  1310. this._contentLength ?? (this._contentLength = contentLength);
  1311. console.log(`PDF ${pdfDocument.fingerprint} [${info.PDFFormatVersion} ` + `${(info.Producer || "-").trim()} / ${(info.Creator || "-").trim()}] ` + `(PDF.js: ${_pdfjsLib.version || "-"}` + `${this.pdfViewer.enableWebGL ? " [WebGL]" : ""})`);
  1312. let pdfTitle = info?.Title;
  1313. const metadataTitle = metadata?.get("dc:title");
  1314. if (metadataTitle) {
  1315. if (metadataTitle !== "Untitled" && !/[\uFFF0-\uFFFF]/g.test(metadataTitle)) {
  1316. pdfTitle = metadataTitle;
  1317. }
  1318. }
  1319. if (pdfTitle) {
  1320. this.setTitle(`${pdfTitle} - ${contentDispositionFilename || document.title}`);
  1321. } else if (contentDispositionFilename) {
  1322. this.setTitle(contentDispositionFilename);
  1323. }
  1324. if (info.IsXFAPresent && !info.IsAcroFormPresent && !pdfDocument.isPureXfa) {
  1325. console.warn("Warning: XFA is not supported");
  1326. this._delayedFallback(_pdfjsLib.UNSUPPORTED_FEATURES.forms);
  1327. } else if ((info.IsAcroFormPresent || info.IsXFAPresent) && !this.pdfViewer.renderInteractiveForms) {
  1328. console.warn("Warning: Interactive form support is not enabled");
  1329. this._delayedFallback(_pdfjsLib.UNSUPPORTED_FEATURES.forms);
  1330. }
  1331. let versionId = "other";
  1332. if (KNOWN_VERSIONS.includes(info.PDFFormatVersion)) {
  1333. versionId = `v${info.PDFFormatVersion.replace(".", "_")}`;
  1334. }
  1335. let generatorId = "other";
  1336. if (info.Producer) {
  1337. const producer = info.Producer.toLowerCase();
  1338. KNOWN_GENERATORS.some(function (generator) {
  1339. if (!producer.includes(generator)) {
  1340. return false;
  1341. }
  1342. generatorId = generator.replace(/[ .-]/g, "_");
  1343. return true;
  1344. });
  1345. }
  1346. let formType = null;
  1347. if (info.IsXFAPresent) {
  1348. formType = "xfa";
  1349. } else if (info.IsAcroFormPresent) {
  1350. formType = "acroform";
  1351. }
  1352. this.externalServices.reportTelemetry({
  1353. type: "documentInfo",
  1354. version: versionId,
  1355. generator: generatorId,
  1356. formType
  1357. });
  1358. this.eventBus.dispatch("metadataloaded", {
  1359. source: this
  1360. });
  1361. },
  1362. async _initializePageLabels(pdfDocument) {
  1363. const labels = await pdfDocument.getPageLabels();
  1364. if (pdfDocument !== this.pdfDocument) {
  1365. return;
  1366. }
  1367. if (!labels || _app_options.AppOptions.get("disablePageLabels")) {
  1368. return;
  1369. }
  1370. const numLabels = labels.length;
  1371. if (numLabels !== this.pagesCount) {
  1372. console.error("The number of Page Labels does not match the number of pages in the document.");
  1373. return;
  1374. }
  1375. let i = 0;
  1376. while (i < numLabels && labels[i] === (i + 1).toString()) {
  1377. i++;
  1378. }
  1379. if (i === numLabels) {
  1380. return;
  1381. }
  1382. const {
  1383. pdfViewer,
  1384. pdfThumbnailViewer,
  1385. toolbar
  1386. } = this;
  1387. pdfViewer.setPageLabels(labels);
  1388. pdfThumbnailViewer.setPageLabels(labels);
  1389. toolbar.setPagesCount(numLabels, true);
  1390. toolbar.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
  1391. },
  1392. _initializePdfHistory({
  1393. fingerprint,
  1394. viewOnLoad,
  1395. initialDest = null
  1396. }) {
  1397. if (this.isViewerEmbedded || _app_options.AppOptions.get("disableHistory")) {
  1398. return;
  1399. }
  1400. this.pdfHistory.initialize({
  1401. fingerprint,
  1402. resetHistory: viewOnLoad === ViewOnLoad.INITIAL,
  1403. updateUrl: _app_options.AppOptions.get("historyUpdateUrl")
  1404. });
  1405. if (this.pdfHistory.initialBookmark) {
  1406. this.initialBookmark = this.pdfHistory.initialBookmark;
  1407. this.initialRotation = this.pdfHistory.initialRotation;
  1408. }
  1409. if (initialDest && !this.initialBookmark && viewOnLoad === ViewOnLoad.UNKNOWN) {
  1410. this.initialBookmark = JSON.stringify(initialDest);
  1411. this.pdfHistory.push({
  1412. explicitDest: initialDest,
  1413. pageNumber: null
  1414. });
  1415. }
  1416. },
  1417. async _initializePermissions(pdfDocument) {
  1418. const permissions = await pdfDocument.getPermissions();
  1419. if (pdfDocument !== this.pdfDocument) {
  1420. return;
  1421. }
  1422. if (!permissions || !_app_options.AppOptions.get("enablePermissions")) {
  1423. return;
  1424. }
  1425. if (!permissions.includes(_pdfjsLib.PermissionFlag.COPY)) {
  1426. this.appConfig.viewerContainer.classList.add(ENABLE_PERMISSIONS_CLASS);
  1427. }
  1428. },
  1429. _initializeAnnotationStorageCallbacks(pdfDocument) {
  1430. if (pdfDocument !== this.pdfDocument) {
  1431. return;
  1432. }
  1433. const {
  1434. annotationStorage
  1435. } = pdfDocument;
  1436. annotationStorage.onSetModified = () => {
  1437. window.addEventListener("beforeunload", beforeUnload);
  1438. this._annotationStorageModified = true;
  1439. };
  1440. annotationStorage.onResetModified = () => {
  1441. window.removeEventListener("beforeunload", beforeUnload);
  1442. delete this._annotationStorageModified;
  1443. };
  1444. },
  1445. setInitialView(storedHash, {
  1446. rotation,
  1447. sidebarView,
  1448. scrollMode,
  1449. spreadMode
  1450. } = {}) {
  1451. const setRotation = angle => {
  1452. if ((0, _ui_utils.isValidRotation)(angle)) {
  1453. this.pdfViewer.pagesRotation = angle;
  1454. }
  1455. };
  1456. const setViewerModes = (scroll, spread) => {
  1457. if ((0, _ui_utils.isValidScrollMode)(scroll)) {
  1458. this.pdfViewer.scrollMode = scroll;
  1459. }
  1460. if ((0, _ui_utils.isValidSpreadMode)(spread)) {
  1461. this.pdfViewer.spreadMode = spread;
  1462. }
  1463. };
  1464. this.isInitialViewSet = true;
  1465. this.pdfSidebar.setInitialView(sidebarView);
  1466. setViewerModes(scrollMode, spreadMode);
  1467. if (this.initialBookmark) {
  1468. setRotation(this.initialRotation);
  1469. delete this.initialRotation;
  1470. this.pdfLinkService.setHash(this.initialBookmark);
  1471. this.initialBookmark = null;
  1472. } else if (storedHash) {
  1473. setRotation(rotation);
  1474. this.pdfLinkService.setHash(storedHash);
  1475. }
  1476. this.toolbar.setPageNumber(this.pdfViewer.currentPageNumber, this.pdfViewer.currentPageLabel);
  1477. this.secondaryToolbar.setPageNumber(this.pdfViewer.currentPageNumber);
  1478. if (!this.pdfViewer.currentScaleValue) {
  1479. this.pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  1480. }
  1481. },
  1482. _cleanup() {
  1483. if (!this.pdfDocument) {
  1484. return;
  1485. }
  1486. this.pdfViewer.cleanup();
  1487. this.pdfThumbnailViewer.cleanup();
  1488. this.pdfDocument.cleanup(this.pdfViewer.renderer === _ui_utils.RendererType.SVG);
  1489. },
  1490. forceRendering() {
  1491. this.pdfRenderingQueue.printing = !!this.printService;
  1492. this.pdfRenderingQueue.isThumbnailViewEnabled = this.pdfSidebar.isThumbnailViewVisible;
  1493. this.pdfRenderingQueue.renderHighestPriority();
  1494. },
  1495. beforePrint() {
  1496. this.pdfScriptingManager.dispatchWillPrint();
  1497. if (this.printService) {
  1498. return;
  1499. }
  1500. if (!this.supportsPrinting) {
  1501. this.l10n.get("printing_not_supported").then(msg => {
  1502. this._otherError(msg);
  1503. });
  1504. return;
  1505. }
  1506. if (!this.pdfViewer.pageViewsReady) {
  1507. this.l10n.get("printing_not_ready").then(msg => {
  1508. window.alert(msg);
  1509. });
  1510. return;
  1511. }
  1512. const pagesOverview = this.pdfViewer.getPagesOverview();
  1513. const printContainer = this.appConfig.printContainer;
  1514. const printResolution = _app_options.AppOptions.get("printResolution");
  1515. const optionalContentConfigPromise = this.pdfViewer.optionalContentConfigPromise;
  1516. const printService = PDFPrintServiceFactory.instance.createPrintService(this.pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise, this.l10n);
  1517. this.printService = printService;
  1518. this.forceRendering();
  1519. printService.layout();
  1520. this.externalServices.reportTelemetry({
  1521. type: "print"
  1522. });
  1523. },
  1524. afterPrint() {
  1525. this.pdfScriptingManager.dispatchDidPrint();
  1526. if (this.printService) {
  1527. this.printService.destroy();
  1528. this.printService = null;
  1529. if (this.pdfDocument) {
  1530. this.pdfDocument.annotationStorage.resetModified();
  1531. }
  1532. }
  1533. this.forceRendering();
  1534. },
  1535. rotatePages(delta) {
  1536. this.pdfViewer.pagesRotation += delta;
  1537. },
  1538. requestPresentationMode() {
  1539. if (!this.pdfPresentationMode) {
  1540. return;
  1541. }
  1542. this.pdfPresentationMode.request();
  1543. },
  1544. triggerPrinting() {
  1545. if (!this.supportsPrinting) {
  1546. return;
  1547. }
  1548. window.print();
  1549. },
  1550. bindEvents() {
  1551. const {
  1552. eventBus,
  1553. _boundEvents
  1554. } = this;
  1555. _boundEvents.beforePrint = this.beforePrint.bind(this);
  1556. _boundEvents.afterPrint = this.afterPrint.bind(this);
  1557. eventBus._on("resize", webViewerResize);
  1558. eventBus._on("hashchange", webViewerHashchange);
  1559. eventBus._on("beforeprint", _boundEvents.beforePrint);
  1560. eventBus._on("afterprint", _boundEvents.afterPrint);
  1561. eventBus._on("pagerendered", webViewerPageRendered);
  1562. eventBus._on("updateviewarea", webViewerUpdateViewarea);
  1563. eventBus._on("pagechanging", webViewerPageChanging);
  1564. eventBus._on("scalechanging", webViewerScaleChanging);
  1565. eventBus._on("rotationchanging", webViewerRotationChanging);
  1566. eventBus._on("sidebarviewchanged", webViewerSidebarViewChanged);
  1567. eventBus._on("pagemode", webViewerPageMode);
  1568. eventBus._on("namedaction", webViewerNamedAction);
  1569. eventBus._on("presentationmodechanged", webViewerPresentationModeChanged);
  1570. eventBus._on("presentationmode", webViewerPresentationMode);
  1571. eventBus._on("print", webViewerPrint);
  1572. eventBus._on("download", webViewerDownload);
  1573. eventBus._on("save", webViewerSave);
  1574. eventBus._on("firstpage", webViewerFirstPage);
  1575. eventBus._on("lastpage", webViewerLastPage);
  1576. eventBus._on("nextpage", webViewerNextPage);
  1577. eventBus._on("previouspage", webViewerPreviousPage);
  1578. eventBus._on("zoomin", webViewerZoomIn);
  1579. eventBus._on("zoomout", webViewerZoomOut);
  1580. eventBus._on("zoomreset", webViewerZoomReset);
  1581. eventBus._on("pagenumberchanged", webViewerPageNumberChanged);
  1582. eventBus._on("scalechanged", webViewerScaleChanged);
  1583. eventBus._on("rotatecw", webViewerRotateCw);
  1584. eventBus._on("rotateccw", webViewerRotateCcw);
  1585. eventBus._on("optionalcontentconfig", webViewerOptionalContentConfig);
  1586. eventBus._on("switchscrollmode", webViewerSwitchScrollMode);
  1587. eventBus._on("scrollmodechanged", webViewerScrollModeChanged);
  1588. eventBus._on("switchspreadmode", webViewerSwitchSpreadMode);
  1589. eventBus._on("spreadmodechanged", webViewerSpreadModeChanged);
  1590. eventBus._on("documentproperties", webViewerDocumentProperties);
  1591. eventBus._on("find", webViewerFind);
  1592. eventBus._on("findfromurlhash", webViewerFindFromUrlHash);
  1593. eventBus._on("updatefindmatchescount", webViewerUpdateFindMatchesCount);
  1594. eventBus._on("updatefindcontrolstate", webViewerUpdateFindControlState);
  1595. if (_app_options.AppOptions.get("pdfBug")) {
  1596. _boundEvents.reportPageStatsPDFBug = reportPageStatsPDFBug;
  1597. eventBus._on("pagerendered", _boundEvents.reportPageStatsPDFBug);
  1598. eventBus._on("pagechanging", _boundEvents.reportPageStatsPDFBug);
  1599. }
  1600. eventBus._on("fileinputchange", webViewerFileInputChange);
  1601. eventBus._on("openfile", webViewerOpenFile);
  1602. },
  1603. bindWindowEvents() {
  1604. const {
  1605. eventBus,
  1606. _boundEvents
  1607. } = this;
  1608. _boundEvents.windowResize = () => {
  1609. eventBus.dispatch("resize", {
  1610. source: window
  1611. });
  1612. };
  1613. _boundEvents.windowHashChange = () => {
  1614. eventBus.dispatch("hashchange", {
  1615. source: window,
  1616. hash: document.location.hash.substring(1)
  1617. });
  1618. };
  1619. _boundEvents.windowBeforePrint = () => {
  1620. eventBus.dispatch("beforeprint", {
  1621. source: window
  1622. });
  1623. };
  1624. _boundEvents.windowAfterPrint = () => {
  1625. eventBus.dispatch("afterprint", {
  1626. source: window
  1627. });
  1628. };
  1629. _boundEvents.windowUpdateFromSandbox = event => {
  1630. eventBus.dispatch("updatefromsandbox", {
  1631. source: window,
  1632. detail: event.detail
  1633. });
  1634. };
  1635. window.addEventListener("visibilitychange", webViewerVisibilityChange);
  1636. window.addEventListener("wheel", webViewerWheel, {
  1637. passive: false
  1638. });
  1639. window.addEventListener("touchstart", webViewerTouchStart, {
  1640. passive: false
  1641. });
  1642. window.addEventListener("click", webViewerClick);
  1643. window.addEventListener("keydown", webViewerKeyDown);
  1644. window.addEventListener("keyup", webViewerKeyUp);
  1645. window.addEventListener("resize", _boundEvents.windowResize);
  1646. window.addEventListener("hashchange", _boundEvents.windowHashChange);
  1647. window.addEventListener("beforeprint", _boundEvents.windowBeforePrint);
  1648. window.addEventListener("afterprint", _boundEvents.windowAfterPrint);
  1649. window.addEventListener("updatefromsandbox", _boundEvents.windowUpdateFromSandbox);
  1650. },
  1651. unbindEvents() {
  1652. const {
  1653. eventBus,
  1654. _boundEvents
  1655. } = this;
  1656. eventBus._off("resize", webViewerResize);
  1657. eventBus._off("hashchange", webViewerHashchange);
  1658. eventBus._off("beforeprint", _boundEvents.beforePrint);
  1659. eventBus._off("afterprint", _boundEvents.afterPrint);
  1660. eventBus._off("pagerendered", webViewerPageRendered);
  1661. eventBus._off("updateviewarea", webViewerUpdateViewarea);
  1662. eventBus._off("pagechanging", webViewerPageChanging);
  1663. eventBus._off("scalechanging", webViewerScaleChanging);
  1664. eventBus._off("rotationchanging", webViewerRotationChanging);
  1665. eventBus._off("sidebarviewchanged", webViewerSidebarViewChanged);
  1666. eventBus._off("pagemode", webViewerPageMode);
  1667. eventBus._off("namedaction", webViewerNamedAction);
  1668. eventBus._off("presentationmodechanged", webViewerPresentationModeChanged);
  1669. eventBus._off("presentationmode", webViewerPresentationMode);
  1670. eventBus._off("print", webViewerPrint);
  1671. eventBus._off("download", webViewerDownload);
  1672. eventBus._off("save", webViewerSave);
  1673. eventBus._off("firstpage", webViewerFirstPage);
  1674. eventBus._off("lastpage", webViewerLastPage);
  1675. eventBus._off("nextpage", webViewerNextPage);
  1676. eventBus._off("previouspage", webViewerPreviousPage);
  1677. eventBus._off("zoomin", webViewerZoomIn);
  1678. eventBus._off("zoomout", webViewerZoomOut);
  1679. eventBus._off("zoomreset", webViewerZoomReset);
  1680. eventBus._off("pagenumberchanged", webViewerPageNumberChanged);
  1681. eventBus._off("scalechanged", webViewerScaleChanged);
  1682. eventBus._off("rotatecw", webViewerRotateCw);
  1683. eventBus._off("rotateccw", webViewerRotateCcw);
  1684. eventBus._off("optionalcontentconfig", webViewerOptionalContentConfig);
  1685. eventBus._off("switchscrollmode", webViewerSwitchScrollMode);
  1686. eventBus._off("scrollmodechanged", webViewerScrollModeChanged);
  1687. eventBus._off("switchspreadmode", webViewerSwitchSpreadMode);
  1688. eventBus._off("spreadmodechanged", webViewerSpreadModeChanged);
  1689. eventBus._off("documentproperties", webViewerDocumentProperties);
  1690. eventBus._off("find", webViewerFind);
  1691. eventBus._off("findfromurlhash", webViewerFindFromUrlHash);
  1692. eventBus._off("updatefindmatchescount", webViewerUpdateFindMatchesCount);
  1693. eventBus._off("updatefindcontrolstate", webViewerUpdateFindControlState);
  1694. if (_boundEvents.reportPageStatsPDFBug) {
  1695. eventBus._off("pagerendered", _boundEvents.reportPageStatsPDFBug);
  1696. eventBus._off("pagechanging", _boundEvents.reportPageStatsPDFBug);
  1697. _boundEvents.reportPageStatsPDFBug = null;
  1698. }
  1699. eventBus._off("fileinputchange", webViewerFileInputChange);
  1700. eventBus._off("openfile", webViewerOpenFile);
  1701. _boundEvents.beforePrint = null;
  1702. _boundEvents.afterPrint = null;
  1703. },
  1704. unbindWindowEvents() {
  1705. const {
  1706. _boundEvents
  1707. } = this;
  1708. window.removeEventListener("visibilitychange", webViewerVisibilityChange);
  1709. window.removeEventListener("wheel", webViewerWheel, {
  1710. passive: false
  1711. });
  1712. window.removeEventListener("touchstart", webViewerTouchStart, {
  1713. passive: false
  1714. });
  1715. window.removeEventListener("click", webViewerClick);
  1716. window.removeEventListener("keydown", webViewerKeyDown);
  1717. window.removeEventListener("keyup", webViewerKeyUp);
  1718. window.removeEventListener("resize", _boundEvents.windowResize);
  1719. window.removeEventListener("hashchange", _boundEvents.windowHashChange);
  1720. window.removeEventListener("beforeprint", _boundEvents.windowBeforePrint);
  1721. window.removeEventListener("afterprint", _boundEvents.windowAfterPrint);
  1722. window.removeEventListener("updatefromsandbox", _boundEvents.windowUpdateFromSandbox);
  1723. _boundEvents.windowResize = null;
  1724. _boundEvents.windowHashChange = null;
  1725. _boundEvents.windowBeforePrint = null;
  1726. _boundEvents.windowAfterPrint = null;
  1727. _boundEvents.windowUpdateFromSandbox = null;
  1728. },
  1729. accumulateWheelTicks(ticks) {
  1730. if (this._wheelUnusedTicks > 0 && ticks < 0 || this._wheelUnusedTicks < 0 && ticks > 0) {
  1731. this._wheelUnusedTicks = 0;
  1732. }
  1733. this._wheelUnusedTicks += ticks;
  1734. const wholeTicks = Math.sign(this._wheelUnusedTicks) * Math.floor(Math.abs(this._wheelUnusedTicks));
  1735. this._wheelUnusedTicks -= wholeTicks;
  1736. return wholeTicks;
  1737. },
  1738. _unblockDocumentLoadEvent() {
  1739. if (document.blockUnblockOnload) {
  1740. document.blockUnblockOnload(false);
  1741. }
  1742. this._unblockDocumentLoadEvent = () => {};
  1743. },
  1744. get scriptingReady() {
  1745. return this.pdfScriptingManager.ready;
  1746. }
  1747. };
  1748. exports.PDFViewerApplication = PDFViewerApplication;
  1749. let validateFileURL;
  1750. {
  1751. const HOSTED_VIEWER_ORIGINS = ["null", "http://mozilla.github.io", "https://mozilla.github.io"];
  1752. validateFileURL = function (file) {
  1753. if (file === undefined) {
  1754. return;
  1755. }
  1756. try {
  1757. const viewerOrigin = new URL(window.location.href).origin || "null";
  1758. if (HOSTED_VIEWER_ORIGINS.includes(viewerOrigin)) {
  1759. return;
  1760. }
  1761. const {
  1762. origin,
  1763. protocol
  1764. } = new URL(file, window.location.href);
  1765. // if (origin !== viewerOrigin && protocol !== "blob:") {
  1766. // throw new Error("file origin does not match viewer's");
  1767. // }
  1768. } catch (ex) {
  1769. PDFViewerApplication.l10n.get("loading_error").then(msg => {
  1770. PDFViewerApplication._documentError(msg, {
  1771. message: ex?.message
  1772. });
  1773. });
  1774. throw ex;
  1775. }
  1776. };
  1777. }
  1778. async function loadFakeWorker() {
  1779. if (!_pdfjsLib.GlobalWorkerOptions.workerSrc) {
  1780. _pdfjsLib.GlobalWorkerOptions.workerSrc = _app_options.AppOptions.get("workerSrc");
  1781. }
  1782. return (0, _pdfjsLib.loadScript)(_pdfjsLib.PDFWorker.getWorkerSrc());
  1783. }
  1784. function loadAndEnablePDFBug(enabledTabs) {
  1785. const appConfig = PDFViewerApplication.appConfig;
  1786. return (0, _pdfjsLib.loadScript)(appConfig.debuggerScriptPath).then(function () {
  1787. PDFBug.enable(enabledTabs);
  1788. PDFBug.init({
  1789. OPS: _pdfjsLib.OPS
  1790. }, appConfig.mainContainer);
  1791. });
  1792. }
  1793. function reportPageStatsPDFBug({
  1794. pageNumber
  1795. }) {
  1796. if (typeof Stats === "undefined" || !Stats.enabled) {
  1797. return;
  1798. }
  1799. const pageView = PDFViewerApplication.pdfViewer.getPageView(pageNumber - 1);
  1800. const pageStats = pageView?.pdfPage?.stats;
  1801. if (!pageStats) {
  1802. return;
  1803. }
  1804. Stats.add(pageNumber, pageStats);
  1805. }
  1806. function getUrlParameter(url, name) {
  1807. var regexSearch = "[\\?&#]" + name + "=([^&#]*)";
  1808. var regex = new RegExp(regexSearch);
  1809. var results = regex.exec(url);
  1810. return results
  1811. ? window.decodeURIComponent(results[1])
  1812. : '';
  1813. }
  1814. function webViewerInitialized() {
  1815. const appConfig = PDFViewerApplication.appConfig;
  1816. let file;
  1817. const queryString = document.location.search.substring(1);
  1818. const params = (0, _ui_utils.parseQueryString)(queryString);
  1819. let fileObj = getUrlParameter(location.href, 'file');
  1820. // file = "file" in params ? params.file : _app_options.AppOptions.get("defaultUrl");
  1821. file = fileObj ? fileObj : _app_options.AppOptions.get("defaultUrl");
  1822. validateFileURL(file);
  1823. const fileInput = document.createElement("input");
  1824. fileInput.id = appConfig.openFileInputName;
  1825. fileInput.className = "fileInput";
  1826. fileInput.setAttribute("type", "file");
  1827. fileInput.oncontextmenu = _ui_utils.noContextMenuHandler;
  1828. document.body.appendChild(fileInput);
  1829. if (!window.File || !window.FileReader || !window.FileList || !window.Blob) {
  1830. appConfig.toolbar.openFile.hidden = true;
  1831. appConfig.secondaryToolbar.openFileButton.hidden = true;
  1832. } else {
  1833. fileInput.value = null;
  1834. }
  1835. fileInput.addEventListener("change", function (evt) {
  1836. const files = evt.target.files;
  1837. if (!files || files.length === 0) {
  1838. return;
  1839. }
  1840. PDFViewerApplication.eventBus.dispatch("fileinputchange", {
  1841. source: this,
  1842. fileInput: evt.target
  1843. });
  1844. });
  1845. appConfig.mainContainer.addEventListener("dragover", function (evt) {
  1846. evt.preventDefault();
  1847. evt.dataTransfer.dropEffect = "move";
  1848. });
  1849. appConfig.mainContainer.addEventListener("drop", function (evt) {
  1850. evt.preventDefault();
  1851. const files = evt.dataTransfer.files;
  1852. if (!files || files.length === 0) {
  1853. return;
  1854. }
  1855. PDFViewerApplication.eventBus.dispatch("fileinputchange", {
  1856. source: this,
  1857. fileInput: evt.dataTransfer
  1858. });
  1859. });
  1860. if (!PDFViewerApplication.supportsDocumentFonts) {
  1861. _app_options.AppOptions.set("disableFontFace", true);
  1862. PDFViewerApplication.l10n.get("web_fonts_disabled").then(msg => {
  1863. console.warn(msg);
  1864. });
  1865. }
  1866. if (!PDFViewerApplication.supportsPrinting) {
  1867. appConfig.toolbar.print.classList.add("hidden");
  1868. appConfig.secondaryToolbar.printButton.classList.add("hidden");
  1869. }
  1870. if (!PDFViewerApplication.supportsFullscreen) {
  1871. appConfig.toolbar.presentationModeButton.classList.add("hidden");
  1872. appConfig.secondaryToolbar.presentationModeButton.classList.add("hidden");
  1873. }
  1874. if (PDFViewerApplication.supportsIntegratedFind) {
  1875. appConfig.toolbar.viewFind.classList.add("hidden");
  1876. }
  1877. appConfig.mainContainer.addEventListener("transitionend", function (evt) {
  1878. if (evt.target === this) {
  1879. PDFViewerApplication.eventBus.dispatch("resize", {
  1880. source: this
  1881. });
  1882. }
  1883. }, true);
  1884. try {
  1885. webViewerOpenFileViaURL(file);
  1886. } catch (reason) {
  1887. PDFViewerApplication.l10n.get("loading_error").then(msg => {
  1888. PDFViewerApplication._documentError(msg, reason);
  1889. });
  1890. }
  1891. }
  1892. function webViewerOpenFileViaURL(file) {
  1893. if (file) {
  1894. PDFViewerApplication.open(file);
  1895. }
  1896. }
  1897. function webViewerResetPermissions() {
  1898. const {
  1899. appConfig
  1900. } = PDFViewerApplication;
  1901. if (!appConfig) {
  1902. return;
  1903. }
  1904. appConfig.viewerContainer.classList.remove(ENABLE_PERMISSIONS_CLASS);
  1905. }
  1906. function webViewerPageRendered({
  1907. pageNumber,
  1908. timestamp,
  1909. error
  1910. }) {
  1911. if (pageNumber === PDFViewerApplication.page) {
  1912. PDFViewerApplication.toolbar.updateLoadingIndicatorState(false);
  1913. }
  1914. if (PDFViewerApplication.pdfSidebar.isThumbnailViewVisible) {
  1915. const pageView = PDFViewerApplication.pdfViewer.getPageView(pageNumber - 1);
  1916. const thumbnailView = PDFViewerApplication.pdfThumbnailViewer.getThumbnail(pageNumber - 1);
  1917. if (pageView && thumbnailView) {
  1918. thumbnailView.setImage(pageView);
  1919. }
  1920. }
  1921. if (error) {
  1922. PDFViewerApplication.l10n.get("rendering_error").then(msg => {
  1923. PDFViewerApplication._otherError(msg, error);
  1924. });
  1925. }
  1926. PDFViewerApplication.externalServices.reportTelemetry({
  1927. type: "pageInfo",
  1928. timestamp
  1929. });
  1930. PDFViewerApplication.pdfDocument.getStats().then(function (stats) {
  1931. PDFViewerApplication.externalServices.reportTelemetry({
  1932. type: "documentStats",
  1933. stats
  1934. });
  1935. });
  1936. }
  1937. function webViewerPageMode({
  1938. mode
  1939. }) {
  1940. let view;
  1941. switch (mode) {
  1942. case "thumbs":
  1943. view = _ui_utils.SidebarView.THUMBS;
  1944. break;
  1945. case "bookmarks":
  1946. case "outline":
  1947. view = _ui_utils.SidebarView.OUTLINE;
  1948. break;
  1949. case "attachments":
  1950. view = _ui_utils.SidebarView.ATTACHMENTS;
  1951. break;
  1952. case "layers":
  1953. view = _ui_utils.SidebarView.LAYERS;
  1954. break;
  1955. case "none":
  1956. view = _ui_utils.SidebarView.NONE;
  1957. break;
  1958. default:
  1959. console.error('Invalid "pagemode" hash parameter: ' + mode);
  1960. return;
  1961. }
  1962. PDFViewerApplication.pdfSidebar.switchView(view, true);
  1963. }
  1964. function webViewerNamedAction(evt) {
  1965. switch (evt.action) {
  1966. case "GoToPage":
  1967. PDFViewerApplication.appConfig.toolbar.pageNumber.select();
  1968. break;
  1969. case "Find":
  1970. if (!PDFViewerApplication.supportsIntegratedFind) {
  1971. PDFViewerApplication.findBar.toggle();
  1972. }
  1973. break;
  1974. case "Print":
  1975. PDFViewerApplication.triggerPrinting();
  1976. break;
  1977. case "SaveAs":
  1978. webViewerSave();
  1979. break;
  1980. }
  1981. }
  1982. function webViewerPresentationModeChanged(evt) {
  1983. PDFViewerApplication.pdfViewer.presentationModeState = evt.state;
  1984. }
  1985. function webViewerSidebarViewChanged(evt) {
  1986. PDFViewerApplication.pdfRenderingQueue.isThumbnailViewEnabled = PDFViewerApplication.pdfSidebar.isThumbnailViewVisible;
  1987. const store = PDFViewerApplication.store;
  1988. if (store && PDFViewerApplication.isInitialViewSet) {
  1989. store.set("sidebarView", evt.view).catch(function () {});
  1990. }
  1991. }
  1992. function webViewerUpdateViewarea(evt) {
  1993. const location = evt.location,
  1994. store = PDFViewerApplication.store;
  1995. if (store && PDFViewerApplication.isInitialViewSet) {
  1996. store.setMultiple({
  1997. page: location.pageNumber,
  1998. zoom: location.scale,
  1999. scrollLeft: location.left,
  2000. scrollTop: location.top,
  2001. rotation: location.rotation
  2002. }).catch(function () {});
  2003. }
  2004. const href = PDFViewerApplication.pdfLinkService.getAnchorUrl(location.pdfOpenParams);
  2005. PDFViewerApplication.appConfig.toolbar.viewBookmark.href = href;
  2006. PDFViewerApplication.appConfig.secondaryToolbar.viewBookmarkButton.href = href;
  2007. const currentPage = PDFViewerApplication.pdfViewer.getPageView(PDFViewerApplication.page - 1);
  2008. const loading = currentPage?.renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED;
  2009. PDFViewerApplication.toolbar.updateLoadingIndicatorState(loading);
  2010. }
  2011. function webViewerScrollModeChanged(evt) {
  2012. const store = PDFViewerApplication.store;
  2013. if (store && PDFViewerApplication.isInitialViewSet) {
  2014. store.set("scrollMode", evt.mode).catch(function () {});
  2015. }
  2016. }
  2017. function webViewerSpreadModeChanged(evt) {
  2018. const store = PDFViewerApplication.store;
  2019. if (store && PDFViewerApplication.isInitialViewSet) {
  2020. store.set("spreadMode", evt.mode).catch(function () {});
  2021. }
  2022. }
  2023. function webViewerResize() {
  2024. const {
  2025. pdfDocument,
  2026. pdfViewer
  2027. } = PDFViewerApplication;
  2028. if (!pdfDocument) {
  2029. return;
  2030. }
  2031. const currentScaleValue = pdfViewer.currentScaleValue;
  2032. if (currentScaleValue === "auto" || currentScaleValue === "page-fit" || currentScaleValue === "page-width") {
  2033. pdfViewer.currentScaleValue = currentScaleValue;
  2034. }
  2035. pdfViewer.update();
  2036. }
  2037. function webViewerHashchange(evt) {
  2038. const hash = evt.hash;
  2039. if (!hash) {
  2040. return;
  2041. }
  2042. if (!PDFViewerApplication.isInitialViewSet) {
  2043. PDFViewerApplication.initialBookmark = hash;
  2044. } else if (!PDFViewerApplication.pdfHistory.popStateInProgress) {
  2045. PDFViewerApplication.pdfLinkService.setHash(hash);
  2046. }
  2047. }
  2048. let webViewerFileInputChange, webViewerOpenFile;
  2049. {
  2050. webViewerFileInputChange = function (evt) {
  2051. if (PDFViewerApplication.pdfViewer?.isInPresentationMode) {
  2052. return;
  2053. }
  2054. const file = evt.fileInput.files[0];
  2055. if (!_viewer_compatibility.viewerCompatibilityParams.disableCreateObjectURL) {
  2056. let url = URL.createObjectURL(file);
  2057. if (file.name) {
  2058. url = {
  2059. url,
  2060. originalUrl: file.name
  2061. };
  2062. }
  2063. PDFViewerApplication.open(url);
  2064. } else {
  2065. PDFViewerApplication.setTitleUsingUrl(file.name);
  2066. const fileReader = new FileReader();
  2067. fileReader.onload = function webViewerChangeFileReaderOnload(event) {
  2068. const buffer = event.target.result;
  2069. PDFViewerApplication.open(new Uint8Array(buffer));
  2070. };
  2071. fileReader.readAsArrayBuffer(file);
  2072. }
  2073. const appConfig = PDFViewerApplication.appConfig;
  2074. appConfig.toolbar.viewBookmark.hidden = true;
  2075. appConfig.secondaryToolbar.viewBookmarkButton.hidden = true;
  2076. appConfig.toolbar.download.hidden = true;
  2077. appConfig.secondaryToolbar.downloadButton.hidden = true;
  2078. };
  2079. webViewerOpenFile = function (evt) {
  2080. const openFileInputName = PDFViewerApplication.appConfig.openFileInputName;
  2081. document.getElementById(openFileInputName).click();
  2082. };
  2083. }
  2084. function webViewerPresentationMode() {
  2085. PDFViewerApplication.requestPresentationMode();
  2086. }
  2087. function webViewerPrint() {
  2088. PDFViewerApplication.triggerPrinting();
  2089. }
  2090. function webViewerDownload() {
  2091. PDFViewerApplication.downloadOrSave({
  2092. sourceEventType: "download"
  2093. });
  2094. }
  2095. function webViewerSave() {
  2096. PDFViewerApplication.downloadOrSave({
  2097. sourceEventType: "save"
  2098. });
  2099. }
  2100. function webViewerFirstPage() {
  2101. if (PDFViewerApplication.pdfDocument) {
  2102. PDFViewerApplication.page = 1;
  2103. }
  2104. }
  2105. function webViewerLastPage() {
  2106. if (PDFViewerApplication.pdfDocument) {
  2107. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  2108. }
  2109. }
  2110. function webViewerNextPage() {
  2111. PDFViewerApplication.pdfViewer.nextPage();
  2112. }
  2113. function webViewerPreviousPage() {
  2114. PDFViewerApplication.pdfViewer.previousPage();
  2115. }
  2116. function webViewerZoomIn() {
  2117. PDFViewerApplication.zoomIn();
  2118. }
  2119. function webViewerZoomOut() {
  2120. PDFViewerApplication.zoomOut();
  2121. }
  2122. function webViewerZoomReset() {
  2123. PDFViewerApplication.zoomReset();
  2124. }
  2125. function webViewerPageNumberChanged(evt) {
  2126. const pdfViewer = PDFViewerApplication.pdfViewer;
  2127. if (evt.value !== "") {
  2128. PDFViewerApplication.pdfLinkService.goToPage(evt.value);
  2129. }
  2130. if (evt.value !== pdfViewer.currentPageNumber.toString() && evt.value !== pdfViewer.currentPageLabel) {
  2131. PDFViewerApplication.toolbar.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
  2132. }
  2133. }
  2134. function webViewerScaleChanged(evt) {
  2135. PDFViewerApplication.pdfViewer.currentScaleValue = evt.value;
  2136. }
  2137. function webViewerRotateCw() {
  2138. PDFViewerApplication.rotatePages(90);
  2139. }
  2140. function webViewerRotateCcw() {
  2141. PDFViewerApplication.rotatePages(-90);
  2142. }
  2143. function webViewerOptionalContentConfig(evt) {
  2144. PDFViewerApplication.pdfViewer.optionalContentConfigPromise = evt.promise;
  2145. }
  2146. function webViewerSwitchScrollMode(evt) {
  2147. PDFViewerApplication.pdfViewer.scrollMode = evt.mode;
  2148. }
  2149. function webViewerSwitchSpreadMode(evt) {
  2150. PDFViewerApplication.pdfViewer.spreadMode = evt.mode;
  2151. }
  2152. function webViewerDocumentProperties() {
  2153. PDFViewerApplication.pdfDocumentProperties.open();
  2154. }
  2155. function webViewerFind(evt) {
  2156. PDFViewerApplication.findController.executeCommand("find" + evt.type, {
  2157. query: evt.query,
  2158. phraseSearch: evt.phraseSearch,
  2159. caseSensitive: evt.caseSensitive,
  2160. entireWord: evt.entireWord,
  2161. highlightAll: evt.highlightAll,
  2162. findPrevious: evt.findPrevious
  2163. });
  2164. }
  2165. function webViewerFindFromUrlHash(evt) {
  2166. PDFViewerApplication.findController.executeCommand("find", {
  2167. query: evt.query,
  2168. phraseSearch: evt.phraseSearch,
  2169. caseSensitive: false,
  2170. entireWord: false,
  2171. highlightAll: true,
  2172. findPrevious: false
  2173. });
  2174. }
  2175. function webViewerUpdateFindMatchesCount({
  2176. matchesCount
  2177. }) {
  2178. if (PDFViewerApplication.supportsIntegratedFind) {
  2179. PDFViewerApplication.externalServices.updateFindMatchesCount(matchesCount);
  2180. } else {
  2181. PDFViewerApplication.findBar.updateResultsCount(matchesCount);
  2182. }
  2183. }
  2184. function webViewerUpdateFindControlState({
  2185. state,
  2186. previous,
  2187. matchesCount,
  2188. rawQuery
  2189. }) {
  2190. if (PDFViewerApplication.supportsIntegratedFind) {
  2191. PDFViewerApplication.externalServices.updateFindControlState({
  2192. result: state,
  2193. findPrevious: previous,
  2194. matchesCount,
  2195. rawQuery
  2196. });
  2197. } else {
  2198. PDFViewerApplication.findBar.updateUIState(state, previous, matchesCount);
  2199. }
  2200. }
  2201. function webViewerScaleChanging(evt) {
  2202. PDFViewerApplication.toolbar.setPageScale(evt.presetValue, evt.scale);
  2203. PDFViewerApplication.pdfViewer.update();
  2204. }
  2205. function webViewerRotationChanging(evt) {
  2206. PDFViewerApplication.pdfThumbnailViewer.pagesRotation = evt.pagesRotation;
  2207. PDFViewerApplication.forceRendering();
  2208. PDFViewerApplication.pdfViewer.currentPageNumber = evt.pageNumber;
  2209. }
  2210. function webViewerPageChanging({
  2211. pageNumber,
  2212. pageLabel
  2213. }) {
  2214. PDFViewerApplication.toolbar.setPageNumber(pageNumber, pageLabel);
  2215. PDFViewerApplication.secondaryToolbar.setPageNumber(pageNumber);
  2216. if (PDFViewerApplication.pdfSidebar.isThumbnailViewVisible) {
  2217. PDFViewerApplication.pdfThumbnailViewer.scrollThumbnailIntoView(pageNumber);
  2218. }
  2219. }
  2220. function webViewerVisibilityChange(evt) {
  2221. if (document.visibilityState === "visible") {
  2222. setZoomDisabledTimeout();
  2223. }
  2224. }
  2225. let zoomDisabledTimeout = null;
  2226. function setZoomDisabledTimeout() {
  2227. if (zoomDisabledTimeout) {
  2228. clearTimeout(zoomDisabledTimeout);
  2229. }
  2230. zoomDisabledTimeout = setTimeout(function () {
  2231. zoomDisabledTimeout = null;
  2232. }, WHEEL_ZOOM_DISABLED_TIMEOUT);
  2233. }
  2234. function webViewerWheel(evt) {
  2235. const {
  2236. pdfViewer,
  2237. supportedMouseWheelZoomModifierKeys
  2238. } = PDFViewerApplication;
  2239. if (pdfViewer.isInPresentationMode) {
  2240. return;
  2241. }
  2242. if (evt.ctrlKey && supportedMouseWheelZoomModifierKeys.ctrlKey || evt.metaKey && supportedMouseWheelZoomModifierKeys.metaKey) {
  2243. evt.preventDefault();
  2244. if (zoomDisabledTimeout || document.visibilityState === "hidden") {
  2245. return;
  2246. }
  2247. const previousScale = pdfViewer.currentScale;
  2248. const delta = (0, _ui_utils.normalizeWheelEventDirection)(evt);
  2249. let ticks = 0;
  2250. if (evt.deltaMode === WheelEvent.DOM_DELTA_LINE || evt.deltaMode === WheelEvent.DOM_DELTA_PAGE) {
  2251. if (Math.abs(delta) >= 1) {
  2252. ticks = Math.sign(delta);
  2253. } else {
  2254. ticks = PDFViewerApplication.accumulateWheelTicks(delta);
  2255. }
  2256. } else {
  2257. const PIXELS_PER_LINE_SCALE = 30;
  2258. ticks = PDFViewerApplication.accumulateWheelTicks(delta / PIXELS_PER_LINE_SCALE);
  2259. }
  2260. if (ticks < 0) {
  2261. PDFViewerApplication.zoomOut(-ticks);
  2262. } else if (ticks > 0) {
  2263. PDFViewerApplication.zoomIn(ticks);
  2264. }
  2265. const currentScale = pdfViewer.currentScale;
  2266. if (previousScale !== currentScale) {
  2267. const scaleCorrectionFactor = currentScale / previousScale - 1;
  2268. const rect = pdfViewer.container.getBoundingClientRect();
  2269. const dx = evt.clientX - rect.left;
  2270. const dy = evt.clientY - rect.top;
  2271. pdfViewer.container.scrollLeft += dx * scaleCorrectionFactor;
  2272. pdfViewer.container.scrollTop += dy * scaleCorrectionFactor;
  2273. }
  2274. } else {
  2275. setZoomDisabledTimeout();
  2276. }
  2277. }
  2278. function webViewerTouchStart(evt) {
  2279. if (evt.touches.length > 1) {
  2280. evt.preventDefault();
  2281. }
  2282. }
  2283. function webViewerClick(evt) {
  2284. if (PDFViewerApplication.triggerDelayedFallback && PDFViewerApplication.pdfViewer.containsElement(evt.target)) {
  2285. PDFViewerApplication.triggerDelayedFallback();
  2286. }
  2287. if (!PDFViewerApplication.secondaryToolbar.isOpen) {
  2288. return;
  2289. }
  2290. const appConfig = PDFViewerApplication.appConfig;
  2291. if (PDFViewerApplication.pdfViewer.containsElement(evt.target) || appConfig.toolbar.container.contains(evt.target) && evt.target !== appConfig.secondaryToolbar.toggleButton) {
  2292. PDFViewerApplication.secondaryToolbar.close();
  2293. }
  2294. }
  2295. function webViewerKeyUp(evt) {
  2296. if (evt.keyCode === 9) {
  2297. if (PDFViewerApplication.triggerDelayedFallback) {
  2298. PDFViewerApplication.triggerDelayedFallback();
  2299. }
  2300. }
  2301. }
  2302. function webViewerKeyDown(evt) {
  2303. if (PDFViewerApplication.overlayManager.active) {
  2304. return;
  2305. }
  2306. let handled = false,
  2307. ensureViewerFocused = false;
  2308. const cmd = (evt.ctrlKey ? 1 : 0) | (evt.altKey ? 2 : 0) | (evt.shiftKey ? 4 : 0) | (evt.metaKey ? 8 : 0);
  2309. const pdfViewer = PDFViewerApplication.pdfViewer;
  2310. const isViewerInPresentationMode = pdfViewer?.isInPresentationMode;
  2311. if (cmd === 1 || cmd === 8 || cmd === 5 || cmd === 12) {
  2312. switch (evt.keyCode) {
  2313. case 70:
  2314. if (!PDFViewerApplication.supportsIntegratedFind && !evt.shiftKey) {
  2315. PDFViewerApplication.findBar.open();
  2316. handled = true;
  2317. }
  2318. break;
  2319. case 71:
  2320. if (!PDFViewerApplication.supportsIntegratedFind) {
  2321. const findState = PDFViewerApplication.findController.state;
  2322. if (findState) {
  2323. PDFViewerApplication.findController.executeCommand("findagain", {
  2324. query: findState.query,
  2325. phraseSearch: findState.phraseSearch,
  2326. caseSensitive: findState.caseSensitive,
  2327. entireWord: findState.entireWord,
  2328. highlightAll: findState.highlightAll,
  2329. findPrevious: cmd === 5 || cmd === 12
  2330. });
  2331. }
  2332. handled = true;
  2333. }
  2334. break;
  2335. case 61:
  2336. case 107:
  2337. case 187:
  2338. case 171:
  2339. if (!isViewerInPresentationMode) {
  2340. PDFViewerApplication.zoomIn();
  2341. }
  2342. handled = true;
  2343. break;
  2344. case 173:
  2345. case 109:
  2346. case 189:
  2347. if (!isViewerInPresentationMode) {
  2348. PDFViewerApplication.zoomOut();
  2349. }
  2350. handled = true;
  2351. break;
  2352. case 48:
  2353. case 96:
  2354. if (!isViewerInPresentationMode) {
  2355. setTimeout(function () {
  2356. PDFViewerApplication.zoomReset();
  2357. });
  2358. handled = false;
  2359. }
  2360. break;
  2361. case 38:
  2362. if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
  2363. PDFViewerApplication.page = 1;
  2364. handled = true;
  2365. ensureViewerFocused = true;
  2366. }
  2367. break;
  2368. case 40:
  2369. if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  2370. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  2371. handled = true;
  2372. ensureViewerFocused = true;
  2373. }
  2374. break;
  2375. }
  2376. }
  2377. const {
  2378. eventBus
  2379. } = PDFViewerApplication;
  2380. if (cmd === 1 || cmd === 8) {
  2381. switch (evt.keyCode) {
  2382. case 83:
  2383. eventBus.dispatch("download", {
  2384. source: window
  2385. });
  2386. handled = true;
  2387. break;
  2388. case 79:
  2389. {
  2390. eventBus.dispatch("openfile", {
  2391. source: window
  2392. });
  2393. handled = true;
  2394. }
  2395. break;
  2396. }
  2397. }
  2398. if (cmd === 3 || cmd === 10) {
  2399. switch (evt.keyCode) {
  2400. case 80:
  2401. PDFViewerApplication.requestPresentationMode();
  2402. handled = true;
  2403. break;
  2404. case 71:
  2405. PDFViewerApplication.appConfig.toolbar.pageNumber.select();
  2406. handled = true;
  2407. break;
  2408. }
  2409. }
  2410. if (handled) {
  2411. if (ensureViewerFocused && !isViewerInPresentationMode) {
  2412. pdfViewer.focus();
  2413. }
  2414. evt.preventDefault();
  2415. return;
  2416. }
  2417. const curElement = (0, _ui_utils.getActiveOrFocusedElement)();
  2418. const curElementTagName = curElement?.tagName.toUpperCase();
  2419. if (curElementTagName === "INPUT" || curElementTagName === "TEXTAREA" || curElementTagName === "SELECT" || curElement?.isContentEditable) {
  2420. if (evt.keyCode !== 27) {
  2421. return;
  2422. }
  2423. }
  2424. if (cmd === 0) {
  2425. let turnPage = 0,
  2426. turnOnlyIfPageFit = false;
  2427. switch (evt.keyCode) {
  2428. case 38:
  2429. case 33:
  2430. if (pdfViewer.isVerticalScrollbarEnabled) {
  2431. turnOnlyIfPageFit = true;
  2432. }
  2433. turnPage = -1;
  2434. break;
  2435. case 8:
  2436. if (!isViewerInPresentationMode) {
  2437. turnOnlyIfPageFit = true;
  2438. }
  2439. turnPage = -1;
  2440. break;
  2441. case 37:
  2442. if (pdfViewer.isHorizontalScrollbarEnabled) {
  2443. turnOnlyIfPageFit = true;
  2444. }
  2445. case 75:
  2446. case 80:
  2447. turnPage = -1;
  2448. break;
  2449. case 27:
  2450. if (PDFViewerApplication.secondaryToolbar.isOpen) {
  2451. PDFViewerApplication.secondaryToolbar.close();
  2452. handled = true;
  2453. }
  2454. if (!PDFViewerApplication.supportsIntegratedFind && PDFViewerApplication.findBar.opened) {
  2455. PDFViewerApplication.findBar.close();
  2456. handled = true;
  2457. }
  2458. break;
  2459. case 40:
  2460. case 34:
  2461. if (pdfViewer.isVerticalScrollbarEnabled) {
  2462. turnOnlyIfPageFit = true;
  2463. }
  2464. turnPage = 1;
  2465. break;
  2466. case 13:
  2467. case 32:
  2468. if (!isViewerInPresentationMode) {
  2469. turnOnlyIfPageFit = true;
  2470. }
  2471. turnPage = 1;
  2472. break;
  2473. case 39:
  2474. if (pdfViewer.isHorizontalScrollbarEnabled) {
  2475. turnOnlyIfPageFit = true;
  2476. }
  2477. case 74:
  2478. case 78:
  2479. turnPage = 1;
  2480. break;
  2481. case 36:
  2482. if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
  2483. PDFViewerApplication.page = 1;
  2484. handled = true;
  2485. ensureViewerFocused = true;
  2486. }
  2487. break;
  2488. case 35:
  2489. if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  2490. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  2491. handled = true;
  2492. ensureViewerFocused = true;
  2493. }
  2494. break;
  2495. case 83:
  2496. PDFViewerApplication.pdfCursorTools.switchTool(_pdf_cursor_tools.CursorTool.SELECT);
  2497. break;
  2498. case 72:
  2499. PDFViewerApplication.pdfCursorTools.switchTool(_pdf_cursor_tools.CursorTool.HAND);
  2500. break;
  2501. case 82:
  2502. PDFViewerApplication.rotatePages(90);
  2503. break;
  2504. case 115:
  2505. PDFViewerApplication.pdfSidebar.toggle();
  2506. break;
  2507. }
  2508. if (turnPage !== 0 && (!turnOnlyIfPageFit || pdfViewer.currentScaleValue === "page-fit")) {
  2509. if (turnPage > 0) {
  2510. pdfViewer.nextPage();
  2511. } else {
  2512. pdfViewer.previousPage();
  2513. }
  2514. handled = true;
  2515. }
  2516. }
  2517. if (cmd === 4) {
  2518. switch (evt.keyCode) {
  2519. case 13:
  2520. case 32:
  2521. if (!isViewerInPresentationMode && pdfViewer.currentScaleValue !== "page-fit") {
  2522. break;
  2523. }
  2524. if (PDFViewerApplication.page > 1) {
  2525. PDFViewerApplication.page--;
  2526. }
  2527. handled = true;
  2528. break;
  2529. case 82:
  2530. PDFViewerApplication.rotatePages(-90);
  2531. break;
  2532. }
  2533. }
  2534. if (!handled && !isViewerInPresentationMode) {
  2535. if (evt.keyCode >= 33 && evt.keyCode <= 40 || evt.keyCode === 32 && curElementTagName !== "BUTTON") {
  2536. ensureViewerFocused = true;
  2537. }
  2538. }
  2539. if (ensureViewerFocused && !pdfViewer.containsElement(curElement)) {
  2540. pdfViewer.focus();
  2541. }
  2542. if (handled) {
  2543. evt.preventDefault();
  2544. }
  2545. }
  2546. function beforeUnload(evt) {
  2547. evt.preventDefault();
  2548. evt.returnValue = "";
  2549. return false;
  2550. }
  2551. const PDFPrintServiceFactory = {
  2552. instance: {
  2553. supportsPrinting: false,
  2554. createPrintService() {
  2555. throw new Error("Not implemented: createPrintService");
  2556. }
  2557. }
  2558. };
  2559. exports.PDFPrintServiceFactory = PDFPrintServiceFactory;
  2560. /***/ }),
  2561. /* 4 */
  2562. /***/ ((__unused_webpack_module, exports) => {
  2563. Object.defineProperty(exports, "__esModule", ({
  2564. value: true
  2565. }));
  2566. exports.apiPageLayoutToSpreadMode = apiPageLayoutToSpreadMode;
  2567. exports.apiPageModeToSidebarView = apiPageModeToSidebarView;
  2568. exports.approximateFraction = approximateFraction;
  2569. exports.backtrackBeforeAllVisibleElements = backtrackBeforeAllVisibleElements;
  2570. exports.binarySearchFirstItem = binarySearchFirstItem;
  2571. exports.getActiveOrFocusedElement = getActiveOrFocusedElement;
  2572. exports.getOutputScale = getOutputScale;
  2573. exports.getPageSizeInches = getPageSizeInches;
  2574. exports.getVisibleElements = getVisibleElements;
  2575. exports.isPortraitOrientation = isPortraitOrientation;
  2576. exports.isValidRotation = isValidRotation;
  2577. exports.isValidScrollMode = isValidScrollMode;
  2578. exports.isValidSpreadMode = isValidSpreadMode;
  2579. exports.moveToEndOfArray = moveToEndOfArray;
  2580. exports.noContextMenuHandler = noContextMenuHandler;
  2581. exports.normalizeWheelEventDelta = normalizeWheelEventDelta;
  2582. exports.normalizeWheelEventDirection = normalizeWheelEventDirection;
  2583. exports.parseQueryString = parseQueryString;
  2584. exports.roundToDivide = roundToDivide;
  2585. exports.scrollIntoView = scrollIntoView;
  2586. exports.waitOnEventOrTimeout = waitOnEventOrTimeout;
  2587. exports.watchScroll = watchScroll;
  2588. 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;
  2589. const CSS_UNITS = 96.0 / 72.0;
  2590. exports.CSS_UNITS = CSS_UNITS;
  2591. const DEFAULT_SCALE_VALUE = "auto";
  2592. exports.DEFAULT_SCALE_VALUE = DEFAULT_SCALE_VALUE;
  2593. const DEFAULT_SCALE = 1.0;
  2594. exports.DEFAULT_SCALE = DEFAULT_SCALE;
  2595. const MIN_SCALE = 0.1;
  2596. exports.MIN_SCALE = MIN_SCALE;
  2597. const MAX_SCALE = 10.0;
  2598. exports.MAX_SCALE = MAX_SCALE;
  2599. const UNKNOWN_SCALE = 0;
  2600. exports.UNKNOWN_SCALE = UNKNOWN_SCALE;
  2601. const MAX_AUTO_SCALE = 1.25;
  2602. exports.MAX_AUTO_SCALE = MAX_AUTO_SCALE;
  2603. const SCROLLBAR_PADDING = 40;
  2604. exports.SCROLLBAR_PADDING = SCROLLBAR_PADDING;
  2605. const VERTICAL_PADDING = 5;
  2606. exports.VERTICAL_PADDING = VERTICAL_PADDING;
  2607. const LOADINGBAR_END_OFFSET_VAR = "--loadingBar-end-offset";
  2608. const PresentationModeState = {
  2609. UNKNOWN: 0,
  2610. NORMAL: 1,
  2611. CHANGING: 2,
  2612. FULLSCREEN: 3
  2613. };
  2614. exports.PresentationModeState = PresentationModeState;
  2615. const SidebarView = {
  2616. UNKNOWN: -1,
  2617. NONE: 0,
  2618. THUMBS: 1,
  2619. OUTLINE: 2,
  2620. ATTACHMENTS: 3,
  2621. LAYERS: 4
  2622. };
  2623. exports.SidebarView = SidebarView;
  2624. const RendererType = {
  2625. CANVAS: "canvas",
  2626. SVG: "svg"
  2627. };
  2628. exports.RendererType = RendererType;
  2629. const TextLayerMode = {
  2630. DISABLE: 0,
  2631. ENABLE: 1,
  2632. ENABLE_ENHANCE: 2
  2633. };
  2634. exports.TextLayerMode = TextLayerMode;
  2635. const ScrollMode = {
  2636. UNKNOWN: -1,
  2637. VERTICAL: 0,
  2638. HORIZONTAL: 1,
  2639. WRAPPED: 2
  2640. };
  2641. exports.ScrollMode = ScrollMode;
  2642. const SpreadMode = {
  2643. UNKNOWN: -1,
  2644. NONE: 0,
  2645. ODD: 1,
  2646. EVEN: 2
  2647. };
  2648. exports.SpreadMode = SpreadMode;
  2649. const AutoPrintRegExp = /\bprint\s*\(/;
  2650. exports.AutoPrintRegExp = AutoPrintRegExp;
  2651. function getOutputScale(ctx) {
  2652. const devicePixelRatio = window.devicePixelRatio || 1;
  2653. const backingStoreRatio = ctx.webkitBackingStorePixelRatio || ctx.mozBackingStorePixelRatio || ctx.backingStorePixelRatio || 1;
  2654. const pixelRatio = devicePixelRatio / backingStoreRatio;
  2655. return {
  2656. sx: pixelRatio,
  2657. sy: pixelRatio,
  2658. scaled: pixelRatio !== 1
  2659. };
  2660. }
  2661. function scrollIntoView(element, spot, skipOverflowHiddenElements = false) {
  2662. let parent = element.offsetParent;
  2663. if (!parent) {
  2664. console.error("offsetParent is not set -- cannot scroll");
  2665. return;
  2666. }
  2667. let offsetY = element.offsetTop + element.clientTop;
  2668. let offsetX = element.offsetLeft + element.clientLeft;
  2669. while (parent.clientHeight === parent.scrollHeight && parent.clientWidth === parent.scrollWidth || skipOverflowHiddenElements && getComputedStyle(parent).overflow === "hidden") {
  2670. if (parent.dataset._scaleY) {
  2671. offsetY /= parent.dataset._scaleY;
  2672. offsetX /= parent.dataset._scaleX;
  2673. }
  2674. offsetY += parent.offsetTop;
  2675. offsetX += parent.offsetLeft;
  2676. parent = parent.offsetParent;
  2677. if (!parent) {
  2678. return;
  2679. }
  2680. }
  2681. if (spot) {
  2682. if (spot.top !== undefined) {
  2683. offsetY += spot.top;
  2684. }
  2685. if (spot.left !== undefined) {
  2686. offsetX += spot.left;
  2687. parent.scrollLeft = offsetX;
  2688. }
  2689. }
  2690. parent.scrollTop = offsetY;
  2691. }
  2692. function watchScroll(viewAreaElement, callback) {
  2693. const debounceScroll = function (evt) {
  2694. if (rAF) {
  2695. return;
  2696. }
  2697. rAF = window.requestAnimationFrame(function viewAreaElementScrolled() {
  2698. rAF = null;
  2699. const currentX = viewAreaElement.scrollLeft;
  2700. const lastX = state.lastX;
  2701. if (currentX !== lastX) {
  2702. state.right = currentX > lastX;
  2703. }
  2704. state.lastX = currentX;
  2705. const currentY = viewAreaElement.scrollTop;
  2706. const lastY = state.lastY;
  2707. if (currentY !== lastY) {
  2708. state.down = currentY > lastY;
  2709. }
  2710. state.lastY = currentY;
  2711. callback(state);
  2712. });
  2713. };
  2714. const state = {
  2715. right: true,
  2716. down: true,
  2717. lastX: viewAreaElement.scrollLeft,
  2718. lastY: viewAreaElement.scrollTop,
  2719. _eventHandler: debounceScroll
  2720. };
  2721. let rAF = null;
  2722. viewAreaElement.addEventListener("scroll", debounceScroll, true);
  2723. return state;
  2724. }
  2725. function parseQueryString(query) {
  2726. const parts = query.split("&");
  2727. const params = Object.create(null);
  2728. for (let i = 0, ii = parts.length; i < ii; ++i) {
  2729. const param = parts[i].split("=");
  2730. const key = param[0].toLowerCase();
  2731. const value = param.length > 1 ? param[1] : null;
  2732. params[decodeURIComponent(key)] = decodeURIComponent(value);
  2733. }
  2734. return params;
  2735. }
  2736. function binarySearchFirstItem(items, condition) {
  2737. let minIndex = 0;
  2738. let maxIndex = items.length - 1;
  2739. if (maxIndex < 0 || !condition(items[maxIndex])) {
  2740. return items.length;
  2741. }
  2742. if (condition(items[minIndex])) {
  2743. return minIndex;
  2744. }
  2745. while (minIndex < maxIndex) {
  2746. const currentIndex = minIndex + maxIndex >> 1;
  2747. const currentItem = items[currentIndex];
  2748. if (condition(currentItem)) {
  2749. maxIndex = currentIndex;
  2750. } else {
  2751. minIndex = currentIndex + 1;
  2752. }
  2753. }
  2754. return minIndex;
  2755. }
  2756. function approximateFraction(x) {
  2757. if (Math.floor(x) === x) {
  2758. return [x, 1];
  2759. }
  2760. const xinv = 1 / x;
  2761. const limit = 8;
  2762. if (xinv > limit) {
  2763. return [1, limit];
  2764. } else if (Math.floor(xinv) === xinv) {
  2765. return [1, xinv];
  2766. }
  2767. const x_ = x > 1 ? xinv : x;
  2768. let a = 0,
  2769. b = 1,
  2770. c = 1,
  2771. d = 1;
  2772. while (true) {
  2773. const p = a + c,
  2774. q = b + d;
  2775. if (q > limit) {
  2776. break;
  2777. }
  2778. if (x_ <= p / q) {
  2779. c = p;
  2780. d = q;
  2781. } else {
  2782. a = p;
  2783. b = q;
  2784. }
  2785. }
  2786. let result;
  2787. if (x_ - a / b < c / d - x_) {
  2788. result = x_ === x ? [a, b] : [b, a];
  2789. } else {
  2790. result = x_ === x ? [c, d] : [d, c];
  2791. }
  2792. return result;
  2793. }
  2794. function roundToDivide(x, div) {
  2795. const r = x % div;
  2796. return r === 0 ? x : Math.round(x - r + div);
  2797. }
  2798. function getPageSizeInches({
  2799. view,
  2800. userUnit,
  2801. rotate
  2802. }) {
  2803. const [x1, y1, x2, y2] = view;
  2804. const changeOrientation = rotate % 180 !== 0;
  2805. const width = (x2 - x1) / 72 * userUnit;
  2806. const height = (y2 - y1) / 72 * userUnit;
  2807. return {
  2808. width: changeOrientation ? height : width,
  2809. height: changeOrientation ? width : height
  2810. };
  2811. }
  2812. function backtrackBeforeAllVisibleElements(index, views, top) {
  2813. if (index < 2) {
  2814. return index;
  2815. }
  2816. let elt = views[index].div;
  2817. let pageTop = elt.offsetTop + elt.clientTop;
  2818. if (pageTop >= top) {
  2819. elt = views[index - 1].div;
  2820. pageTop = elt.offsetTop + elt.clientTop;
  2821. }
  2822. for (let i = index - 2; i >= 0; --i) {
  2823. elt = views[i].div;
  2824. if (elt.offsetTop + elt.clientTop + elt.clientHeight <= pageTop) {
  2825. break;
  2826. }
  2827. index = i;
  2828. }
  2829. return index;
  2830. }
  2831. function getVisibleElements({
  2832. scrollEl,
  2833. views,
  2834. sortByVisibility = false,
  2835. horizontal = false,
  2836. rtl = false
  2837. }) {
  2838. const top = scrollEl.scrollTop,
  2839. bottom = top + scrollEl.clientHeight;
  2840. const left = scrollEl.scrollLeft,
  2841. right = left + scrollEl.clientWidth;
  2842. function isElementBottomAfterViewTop(view) {
  2843. const element = view.div;
  2844. const elementBottom = element.offsetTop + element.clientTop + element.clientHeight;
  2845. return elementBottom > top;
  2846. }
  2847. function isElementNextAfterViewHorizontally(view) {
  2848. const element = view.div;
  2849. const elementLeft = element.offsetLeft + element.clientLeft;
  2850. const elementRight = elementLeft + element.clientWidth;
  2851. return rtl ? elementLeft < right : elementRight > left;
  2852. }
  2853. const visible = [],
  2854. numViews = views.length;
  2855. let firstVisibleElementInd = binarySearchFirstItem(views, horizontal ? isElementNextAfterViewHorizontally : isElementBottomAfterViewTop);
  2856. if (firstVisibleElementInd > 0 && firstVisibleElementInd < numViews && !horizontal) {
  2857. firstVisibleElementInd = backtrackBeforeAllVisibleElements(firstVisibleElementInd, views, top);
  2858. }
  2859. let lastEdge = horizontal ? right : -1;
  2860. for (let i = firstVisibleElementInd; i < numViews; i++) {
  2861. const view = views[i],
  2862. element = view.div;
  2863. const currentWidth = element.offsetLeft + element.clientLeft;
  2864. const currentHeight = element.offsetTop + element.clientTop;
  2865. const viewWidth = element.clientWidth,
  2866. viewHeight = element.clientHeight;
  2867. const viewRight = currentWidth + viewWidth;
  2868. const viewBottom = currentHeight + viewHeight;
  2869. if (lastEdge === -1) {
  2870. if (viewBottom >= bottom) {
  2871. lastEdge = viewBottom;
  2872. }
  2873. } else if ((horizontal ? currentWidth : currentHeight) > lastEdge) {
  2874. break;
  2875. }
  2876. if (viewBottom <= top || currentHeight >= bottom || viewRight <= left || currentWidth >= right) {
  2877. continue;
  2878. }
  2879. const hiddenHeight = Math.max(0, top - currentHeight) + Math.max(0, viewBottom - bottom);
  2880. const hiddenWidth = Math.max(0, left - currentWidth) + Math.max(0, viewRight - right);
  2881. const fractionHeight = (viewHeight - hiddenHeight) / viewHeight,
  2882. fractionWidth = (viewWidth - hiddenWidth) / viewWidth;
  2883. const percent = fractionHeight * fractionWidth * 100 | 0;
  2884. visible.push({
  2885. id: view.id,
  2886. x: currentWidth,
  2887. y: currentHeight,
  2888. view,
  2889. percent,
  2890. widthPercent: fractionWidth * 100 | 0
  2891. });
  2892. }
  2893. const first = visible[0],
  2894. last = visible[visible.length - 1];
  2895. if (sortByVisibility) {
  2896. visible.sort(function (a, b) {
  2897. const pc = a.percent - b.percent;
  2898. if (Math.abs(pc) > 0.001) {
  2899. return -pc;
  2900. }
  2901. return a.id - b.id;
  2902. });
  2903. }
  2904. return {
  2905. first,
  2906. last,
  2907. views: visible
  2908. };
  2909. }
  2910. function noContextMenuHandler(evt) {
  2911. evt.preventDefault();
  2912. }
  2913. function normalizeWheelEventDirection(evt) {
  2914. let delta = Math.hypot(evt.deltaX, evt.deltaY);
  2915. const angle = Math.atan2(evt.deltaY, evt.deltaX);
  2916. if (-0.25 * Math.PI < angle && angle < 0.75 * Math.PI) {
  2917. delta = -delta;
  2918. }
  2919. return delta;
  2920. }
  2921. function normalizeWheelEventDelta(evt) {
  2922. let delta = normalizeWheelEventDirection(evt);
  2923. const MOUSE_DOM_DELTA_PIXEL_MODE = 0;
  2924. const MOUSE_DOM_DELTA_LINE_MODE = 1;
  2925. const MOUSE_PIXELS_PER_LINE = 30;
  2926. const MOUSE_LINES_PER_PAGE = 30;
  2927. if (evt.deltaMode === MOUSE_DOM_DELTA_PIXEL_MODE) {
  2928. delta /= MOUSE_PIXELS_PER_LINE * MOUSE_LINES_PER_PAGE;
  2929. } else if (evt.deltaMode === MOUSE_DOM_DELTA_LINE_MODE) {
  2930. delta /= MOUSE_LINES_PER_PAGE;
  2931. }
  2932. return delta;
  2933. }
  2934. function isValidRotation(angle) {
  2935. return Number.isInteger(angle) && angle % 90 === 0;
  2936. }
  2937. function isValidScrollMode(mode) {
  2938. return Number.isInteger(mode) && Object.values(ScrollMode).includes(mode) && mode !== ScrollMode.UNKNOWN;
  2939. }
  2940. function isValidSpreadMode(mode) {
  2941. return Number.isInteger(mode) && Object.values(SpreadMode).includes(mode) && mode !== SpreadMode.UNKNOWN;
  2942. }
  2943. function isPortraitOrientation(size) {
  2944. return size.width <= size.height;
  2945. }
  2946. const WaitOnType = {
  2947. EVENT: "event",
  2948. TIMEOUT: "timeout"
  2949. };
  2950. exports.WaitOnType = WaitOnType;
  2951. function waitOnEventOrTimeout({
  2952. target,
  2953. name,
  2954. delay = 0
  2955. }) {
  2956. return new Promise(function (resolve, reject) {
  2957. if (typeof target !== "object" || !(name && typeof name === "string") || !(Number.isInteger(delay) && delay >= 0)) {
  2958. throw new Error("waitOnEventOrTimeout - invalid parameters.");
  2959. }
  2960. function handler(type) {
  2961. if (target instanceof EventBus) {
  2962. target._off(name, eventHandler);
  2963. } else {
  2964. target.removeEventListener(name, eventHandler);
  2965. }
  2966. if (timeout) {
  2967. clearTimeout(timeout);
  2968. }
  2969. resolve(type);
  2970. }
  2971. const eventHandler = handler.bind(null, WaitOnType.EVENT);
  2972. if (target instanceof EventBus) {
  2973. target._on(name, eventHandler);
  2974. } else {
  2975. target.addEventListener(name, eventHandler);
  2976. }
  2977. const timeoutHandler = handler.bind(null, WaitOnType.TIMEOUT);
  2978. const timeout = setTimeout(timeoutHandler, delay);
  2979. });
  2980. }
  2981. const animationStarted = new Promise(function (resolve) {
  2982. window.requestAnimationFrame(resolve);
  2983. });
  2984. exports.animationStarted = animationStarted;
  2985. function dispatchDOMEvent(eventName, args = null) {
  2986. throw new Error("Not implemented: dispatchDOMEvent");
  2987. }
  2988. class EventBus {
  2989. constructor(options) {
  2990. this._listeners = Object.create(null);
  2991. }
  2992. on(eventName, listener, options = null) {
  2993. this._on(eventName, listener, {
  2994. external: true,
  2995. once: options?.once
  2996. });
  2997. }
  2998. off(eventName, listener, options = null) {
  2999. this._off(eventName, listener, {
  3000. external: true,
  3001. once: options?.once
  3002. });
  3003. }
  3004. dispatch(eventName) {
  3005. const eventListeners = this._listeners[eventName];
  3006. if (!eventListeners || eventListeners.length === 0) {
  3007. return;
  3008. }
  3009. const args = Array.prototype.slice.call(arguments, 1);
  3010. let externalListeners;
  3011. eventListeners.slice(0).forEach(({
  3012. listener,
  3013. external,
  3014. once
  3015. }) => {
  3016. if (once) {
  3017. this._off(eventName, listener);
  3018. }
  3019. if (external) {
  3020. (externalListeners || (externalListeners = [])).push(listener);
  3021. return;
  3022. }
  3023. listener.apply(null, args);
  3024. });
  3025. if (externalListeners) {
  3026. externalListeners.forEach(listener => {
  3027. listener.apply(null, args);
  3028. });
  3029. externalListeners = null;
  3030. }
  3031. }
  3032. _on(eventName, listener, options = null) {
  3033. var _this$_listeners;
  3034. const eventListeners = (_this$_listeners = this._listeners)[eventName] || (_this$_listeners[eventName] = []);
  3035. eventListeners.push({
  3036. listener,
  3037. external: options?.external === true,
  3038. once: options?.once === true
  3039. });
  3040. }
  3041. _off(eventName, listener, options = null) {
  3042. const eventListeners = this._listeners[eventName];
  3043. if (!eventListeners) {
  3044. return;
  3045. }
  3046. for (let i = 0, ii = eventListeners.length; i < ii; i++) {
  3047. if (eventListeners[i].listener === listener) {
  3048. eventListeners.splice(i, 1);
  3049. return;
  3050. }
  3051. }
  3052. }
  3053. }
  3054. exports.EventBus = EventBus;
  3055. function clamp(v, min, max) {
  3056. return Math.min(Math.max(v, min), max);
  3057. }
  3058. class ProgressBar {
  3059. constructor(id, {
  3060. height,
  3061. width,
  3062. units
  3063. } = {}) {
  3064. this.visible = true;
  3065. this.div = document.querySelector(id + " .progress");
  3066. this.bar = this.div.parentNode;
  3067. this.height = height || 100;
  3068. this.width = width || 100;
  3069. this.units = units || "%";
  3070. this.div.style.height = this.height + this.units;
  3071. this.percent = 0;
  3072. }
  3073. _updateBar() {
  3074. if (this._indeterminate) {
  3075. this.div.classList.add("indeterminate");
  3076. this.div.style.width = this.width + this.units;
  3077. return;
  3078. }
  3079. this.div.classList.remove("indeterminate");
  3080. const progressSize = this.width * this._percent / 100;
  3081. this.div.style.width = progressSize + this.units;
  3082. }
  3083. get percent() {
  3084. return this._percent;
  3085. }
  3086. set percent(val) {
  3087. this._indeterminate = isNaN(val);
  3088. this._percent = clamp(val, 0, 100);
  3089. this._updateBar();
  3090. }
  3091. setWidth(viewer) {
  3092. if (!viewer) {
  3093. return;
  3094. }
  3095. const container = viewer.parentNode;
  3096. const scrollbarWidth = container.offsetWidth - viewer.offsetWidth;
  3097. if (scrollbarWidth > 0) {
  3098. const doc = document.documentElement;
  3099. doc.style.setProperty(LOADINGBAR_END_OFFSET_VAR, `${scrollbarWidth}px`);
  3100. }
  3101. }
  3102. hide() {
  3103. if (!this.visible) {
  3104. return;
  3105. }
  3106. this.visible = false;
  3107. this.bar.classList.add("hidden");
  3108. }
  3109. show() {
  3110. if (this.visible) {
  3111. return;
  3112. }
  3113. this.visible = true;
  3114. this.bar.classList.remove("hidden");
  3115. }
  3116. }
  3117. exports.ProgressBar = ProgressBar;
  3118. function moveToEndOfArray(arr, condition) {
  3119. const moved = [],
  3120. len = arr.length;
  3121. let write = 0;
  3122. for (let read = 0; read < len; ++read) {
  3123. if (condition(arr[read])) {
  3124. moved.push(arr[read]);
  3125. } else {
  3126. arr[write] = arr[read];
  3127. ++write;
  3128. }
  3129. }
  3130. for (let read = 0; write < len; ++read, ++write) {
  3131. arr[write] = moved[read];
  3132. }
  3133. }
  3134. function getActiveOrFocusedElement() {
  3135. let curRoot = document;
  3136. let curActiveOrFocused = curRoot.activeElement || curRoot.querySelector(":focus");
  3137. while (curActiveOrFocused?.shadowRoot) {
  3138. curRoot = curActiveOrFocused.shadowRoot;
  3139. curActiveOrFocused = curRoot.activeElement || curRoot.querySelector(":focus");
  3140. }
  3141. return curActiveOrFocused;
  3142. }
  3143. function apiPageLayoutToSpreadMode(layout) {
  3144. switch (layout) {
  3145. case "SinglePage":
  3146. case "OneColumn":
  3147. return SpreadMode.NONE;
  3148. case "TwoColumnLeft":
  3149. case "TwoPageLeft":
  3150. return SpreadMode.ODD;
  3151. case "TwoColumnRight":
  3152. case "TwoPageRight":
  3153. return SpreadMode.EVEN;
  3154. }
  3155. return SpreadMode.NONE;
  3156. }
  3157. function apiPageModeToSidebarView(mode) {
  3158. switch (mode) {
  3159. case "UseNone":
  3160. return SidebarView.NONE;
  3161. case "UseThumbs":
  3162. return SidebarView.THUMBS;
  3163. case "UseOutlines":
  3164. return SidebarView.OUTLINE;
  3165. case "UseAttachments":
  3166. return SidebarView.ATTACHMENTS;
  3167. case "UseOC":
  3168. return SidebarView.LAYERS;
  3169. }
  3170. return SidebarView.NONE;
  3171. }
  3172. /***/ }),
  3173. /* 5 */
  3174. /***/ ((module) => {
  3175. let pdfjsLib;
  3176. if (typeof window !== "undefined" && window["pdfjs-dist/build/pdf"]) {
  3177. pdfjsLib = window["pdfjs-dist/build/pdf"];
  3178. } else {
  3179. pdfjsLib = require("../build/pdf.js");
  3180. }
  3181. module.exports = pdfjsLib;
  3182. /***/ }),
  3183. /* 6 */
  3184. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3185. Object.defineProperty(exports, "__esModule", ({
  3186. value: true
  3187. }));
  3188. exports.PDFCursorTools = exports.CursorTool = void 0;
  3189. var _grab_to_pan = __webpack_require__(7);
  3190. var _ui_utils = __webpack_require__(4);
  3191. const CursorTool = {
  3192. SELECT: 0,
  3193. HAND: 1,
  3194. ZOOM: 2
  3195. };
  3196. exports.CursorTool = CursorTool;
  3197. class PDFCursorTools {
  3198. constructor({
  3199. container,
  3200. eventBus,
  3201. cursorToolOnLoad = CursorTool.SELECT
  3202. }) {
  3203. this.container = container;
  3204. this.eventBus = eventBus;
  3205. this.active = CursorTool.SELECT;
  3206. this.activeBeforePresentationMode = null;
  3207. this.handTool = new _grab_to_pan.GrabToPan({
  3208. element: this.container
  3209. });
  3210. this._addEventListeners();
  3211. Promise.resolve().then(() => {
  3212. this.switchTool(cursorToolOnLoad);
  3213. });
  3214. }
  3215. get activeTool() {
  3216. return this.active;
  3217. }
  3218. switchTool(tool) {
  3219. if (this.activeBeforePresentationMode !== null) {
  3220. return;
  3221. }
  3222. if (tool === this.active) {
  3223. return;
  3224. }
  3225. const disableActiveTool = () => {
  3226. switch (this.active) {
  3227. case CursorTool.SELECT:
  3228. break;
  3229. case CursorTool.HAND:
  3230. this.handTool.deactivate();
  3231. break;
  3232. case CursorTool.ZOOM:
  3233. }
  3234. };
  3235. switch (tool) {
  3236. case CursorTool.SELECT:
  3237. disableActiveTool();
  3238. break;
  3239. case CursorTool.HAND:
  3240. disableActiveTool();
  3241. this.handTool.activate();
  3242. break;
  3243. case CursorTool.ZOOM:
  3244. default:
  3245. console.error(`switchTool: "${tool}" is an unsupported value.`);
  3246. return;
  3247. }
  3248. this.active = tool;
  3249. this._dispatchEvent();
  3250. }
  3251. _dispatchEvent() {
  3252. this.eventBus.dispatch("cursortoolchanged", {
  3253. source: this,
  3254. tool: this.active
  3255. });
  3256. }
  3257. _addEventListeners() {
  3258. this.eventBus._on("switchcursortool", evt => {
  3259. this.switchTool(evt.tool);
  3260. });
  3261. this.eventBus._on("presentationmodechanged", evt => {
  3262. switch (evt.state) {
  3263. case _ui_utils.PresentationModeState.FULLSCREEN:
  3264. {
  3265. const previouslyActive = this.active;
  3266. this.switchTool(CursorTool.SELECT);
  3267. this.activeBeforePresentationMode = previouslyActive;
  3268. break;
  3269. }
  3270. case _ui_utils.PresentationModeState.NORMAL:
  3271. {
  3272. const previouslyActive = this.activeBeforePresentationMode;
  3273. this.activeBeforePresentationMode = null;
  3274. this.switchTool(previouslyActive);
  3275. break;
  3276. }
  3277. }
  3278. });
  3279. }
  3280. }
  3281. exports.PDFCursorTools = PDFCursorTools;
  3282. /***/ }),
  3283. /* 7 */
  3284. /***/ ((__unused_webpack_module, exports) => {
  3285. Object.defineProperty(exports, "__esModule", ({
  3286. value: true
  3287. }));
  3288. exports.GrabToPan = GrabToPan;
  3289. function GrabToPan(options) {
  3290. this.element = options.element;
  3291. this.document = options.element.ownerDocument;
  3292. if (typeof options.ignoreTarget === "function") {
  3293. this.ignoreTarget = options.ignoreTarget;
  3294. }
  3295. this.onActiveChanged = options.onActiveChanged;
  3296. this.activate = this.activate.bind(this);
  3297. this.deactivate = this.deactivate.bind(this);
  3298. this.toggle = this.toggle.bind(this);
  3299. this._onmousedown = this._onmousedown.bind(this);
  3300. this._onmousemove = this._onmousemove.bind(this);
  3301. this._endPan = this._endPan.bind(this);
  3302. const overlay = this.overlay = document.createElement("div");
  3303. overlay.className = "grab-to-pan-grabbing";
  3304. }
  3305. GrabToPan.prototype = {
  3306. CSS_CLASS_GRAB: "grab-to-pan-grab",
  3307. activate: function GrabToPan_activate() {
  3308. if (!this.active) {
  3309. this.active = true;
  3310. this.element.addEventListener("mousedown", this._onmousedown, true);
  3311. this.element.classList.add(this.CSS_CLASS_GRAB);
  3312. if (this.onActiveChanged) {
  3313. this.onActiveChanged(true);
  3314. }
  3315. }
  3316. },
  3317. deactivate: function GrabToPan_deactivate() {
  3318. if (this.active) {
  3319. this.active = false;
  3320. this.element.removeEventListener("mousedown", this._onmousedown, true);
  3321. this._endPan();
  3322. this.element.classList.remove(this.CSS_CLASS_GRAB);
  3323. if (this.onActiveChanged) {
  3324. this.onActiveChanged(false);
  3325. }
  3326. }
  3327. },
  3328. toggle: function GrabToPan_toggle() {
  3329. if (this.active) {
  3330. this.deactivate();
  3331. } else {
  3332. this.activate();
  3333. }
  3334. },
  3335. ignoreTarget: function GrabToPan_ignoreTarget(node) {
  3336. return node.matches("a[href], a[href] *, input, textarea, button, button *, select, option");
  3337. },
  3338. _onmousedown: function GrabToPan__onmousedown(event) {
  3339. if (event.button !== 0 || this.ignoreTarget(event.target)) {
  3340. return;
  3341. }
  3342. if (event.originalTarget) {
  3343. try {
  3344. event.originalTarget.tagName;
  3345. } catch (e) {
  3346. return;
  3347. }
  3348. }
  3349. this.scrollLeftStart = this.element.scrollLeft;
  3350. this.scrollTopStart = this.element.scrollTop;
  3351. this.clientXStart = event.clientX;
  3352. this.clientYStart = event.clientY;
  3353. this.document.addEventListener("mousemove", this._onmousemove, true);
  3354. this.document.addEventListener("mouseup", this._endPan, true);
  3355. this.element.addEventListener("scroll", this._endPan, true);
  3356. event.preventDefault();
  3357. event.stopPropagation();
  3358. const focusedElement = document.activeElement;
  3359. if (focusedElement && !focusedElement.contains(event.target)) {
  3360. focusedElement.blur();
  3361. }
  3362. },
  3363. _onmousemove: function GrabToPan__onmousemove(event) {
  3364. this.element.removeEventListener("scroll", this._endPan, true);
  3365. if (isLeftMouseReleased(event)) {
  3366. this._endPan();
  3367. return;
  3368. }
  3369. const xDiff = event.clientX - this.clientXStart;
  3370. const yDiff = event.clientY - this.clientYStart;
  3371. const scrollTop = this.scrollTopStart - yDiff;
  3372. const scrollLeft = this.scrollLeftStart - xDiff;
  3373. if (this.element.scrollTo) {
  3374. this.element.scrollTo({
  3375. top: scrollTop,
  3376. left: scrollLeft,
  3377. behavior: "instant"
  3378. });
  3379. } else {
  3380. this.element.scrollTop = scrollTop;
  3381. this.element.scrollLeft = scrollLeft;
  3382. }
  3383. if (!this.overlay.parentNode) {
  3384. document.body.appendChild(this.overlay);
  3385. }
  3386. },
  3387. _endPan: function GrabToPan__endPan() {
  3388. this.element.removeEventListener("scroll", this._endPan, true);
  3389. this.document.removeEventListener("mousemove", this._onmousemove, true);
  3390. this.document.removeEventListener("mouseup", this._endPan, true);
  3391. this.overlay.remove();
  3392. }
  3393. };
  3394. function isLeftMouseReleased(event) {
  3395. if ("buttons" in event) {
  3396. return !(event.buttons & 1);
  3397. }
  3398. const chrome = window.chrome;
  3399. const isChrome15OrOpera15plus = chrome && (chrome.webstore || chrome.app);
  3400. const isSafari6plus = /Apple/.test(navigator.vendor) && /Version\/([6-9]\d*|[1-5]\d+)/.test(navigator.userAgent);
  3401. if (isChrome15OrOpera15plus || isSafari6plus) {
  3402. return event.which === 0;
  3403. }
  3404. return false;
  3405. }
  3406. /***/ }),
  3407. /* 8 */
  3408. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3409. Object.defineProperty(exports, "__esModule", ({
  3410. value: true
  3411. }));
  3412. exports.RenderingStates = exports.PDFRenderingQueue = void 0;
  3413. var _pdfjsLib = __webpack_require__(5);
  3414. const CLEANUP_TIMEOUT = 30000;
  3415. const RenderingStates = {
  3416. INITIAL: 0,
  3417. RUNNING: 1,
  3418. PAUSED: 2,
  3419. FINISHED: 3
  3420. };
  3421. exports.RenderingStates = RenderingStates;
  3422. class PDFRenderingQueue {
  3423. constructor() {
  3424. this.pdfViewer = null;
  3425. this.pdfThumbnailViewer = null;
  3426. this.onIdle = null;
  3427. this.highestPriorityPage = null;
  3428. this.idleTimeout = null;
  3429. this.printing = false;
  3430. this.isThumbnailViewEnabled = false;
  3431. }
  3432. setViewer(pdfViewer) {
  3433. this.pdfViewer = pdfViewer;
  3434. }
  3435. setThumbnailViewer(pdfThumbnailViewer) {
  3436. this.pdfThumbnailViewer = pdfThumbnailViewer;
  3437. }
  3438. isHighestPriority(view) {
  3439. return this.highestPriorityPage === view.renderingId;
  3440. }
  3441. renderHighestPriority(currentlyVisiblePages) {
  3442. if (this.idleTimeout) {
  3443. clearTimeout(this.idleTimeout);
  3444. this.idleTimeout = null;
  3445. }
  3446. if (this.pdfViewer.forceRendering(currentlyVisiblePages)) {
  3447. return;
  3448. }
  3449. if (this.pdfThumbnailViewer && this.isThumbnailViewEnabled) {
  3450. if (this.pdfThumbnailViewer.forceRendering()) {
  3451. return;
  3452. }
  3453. }
  3454. if (this.printing) {
  3455. return;
  3456. }
  3457. if (this.onIdle) {
  3458. this.idleTimeout = setTimeout(this.onIdle.bind(this), CLEANUP_TIMEOUT);
  3459. }
  3460. }
  3461. getHighestPriority(visible, views, scrolledDown) {
  3462. const visibleViews = visible.views;
  3463. const numVisible = visibleViews.length;
  3464. if (numVisible === 0) {
  3465. return null;
  3466. }
  3467. for (let i = 0; i < numVisible; ++i) {
  3468. const view = visibleViews[i].view;
  3469. if (!this.isViewFinished(view)) {
  3470. return view;
  3471. }
  3472. }
  3473. if (scrolledDown) {
  3474. const nextPageIndex = visible.last.id;
  3475. if (views[nextPageIndex] && !this.isViewFinished(views[nextPageIndex])) {
  3476. return views[nextPageIndex];
  3477. }
  3478. } else {
  3479. const previousPageIndex = visible.first.id - 2;
  3480. if (views[previousPageIndex] && !this.isViewFinished(views[previousPageIndex])) {
  3481. return views[previousPageIndex];
  3482. }
  3483. }
  3484. return null;
  3485. }
  3486. isViewFinished(view) {
  3487. return view.renderingState === RenderingStates.FINISHED;
  3488. }
  3489. renderView(view) {
  3490. switch (view.renderingState) {
  3491. case RenderingStates.FINISHED:
  3492. return false;
  3493. case RenderingStates.PAUSED:
  3494. this.highestPriorityPage = view.renderingId;
  3495. view.resume();
  3496. break;
  3497. case RenderingStates.RUNNING:
  3498. this.highestPriorityPage = view.renderingId;
  3499. break;
  3500. case RenderingStates.INITIAL:
  3501. this.highestPriorityPage = view.renderingId;
  3502. view.draw().finally(() => {
  3503. this.renderHighestPriority();
  3504. }).catch(reason => {
  3505. if (reason instanceof _pdfjsLib.RenderingCancelledException) {
  3506. return;
  3507. }
  3508. console.error(`renderView: "${reason}"`);
  3509. });
  3510. break;
  3511. }
  3512. return true;
  3513. }
  3514. }
  3515. exports.PDFRenderingQueue = PDFRenderingQueue;
  3516. /***/ }),
  3517. /* 9 */
  3518. /***/ ((__unused_webpack_module, exports) => {
  3519. Object.defineProperty(exports, "__esModule", ({
  3520. value: true
  3521. }));
  3522. exports.OverlayManager = void 0;
  3523. class OverlayManager {
  3524. constructor() {
  3525. this._overlays = {};
  3526. this._active = null;
  3527. this._keyDownBound = this._keyDown.bind(this);
  3528. }
  3529. get active() {
  3530. return this._active;
  3531. }
  3532. async register(name, element, callerCloseMethod = null, canForceClose = false) {
  3533. let container;
  3534. if (!name || !element || !(container = element.parentNode)) {
  3535. throw new Error("Not enough parameters.");
  3536. } else if (this._overlays[name]) {
  3537. throw new Error("The overlay is already registered.");
  3538. }
  3539. this._overlays[name] = {
  3540. element,
  3541. container,
  3542. callerCloseMethod,
  3543. canForceClose
  3544. };
  3545. }
  3546. async unregister(name) {
  3547. if (!this._overlays[name]) {
  3548. throw new Error("The overlay does not exist.");
  3549. } else if (this._active === name) {
  3550. throw new Error("The overlay cannot be removed while it is active.");
  3551. }
  3552. delete this._overlays[name];
  3553. }
  3554. async open(name) {
  3555. if (!this._overlays[name]) {
  3556. throw new Error("The overlay does not exist.");
  3557. } else if (this._active) {
  3558. if (this._overlays[name].canForceClose) {
  3559. this._closeThroughCaller();
  3560. } else if (this._active === name) {
  3561. throw new Error("The overlay is already active.");
  3562. } else {
  3563. throw new Error("Another overlay is currently active.");
  3564. }
  3565. }
  3566. this._active = name;
  3567. this._overlays[this._active].element.classList.remove("hidden");
  3568. this._overlays[this._active].container.classList.remove("hidden");
  3569. window.addEventListener("keydown", this._keyDownBound);
  3570. }
  3571. async close(name) {
  3572. if (!this._overlays[name]) {
  3573. throw new Error("The overlay does not exist.");
  3574. } else if (!this._active) {
  3575. throw new Error("The overlay is currently not active.");
  3576. } else if (this._active !== name) {
  3577. throw new Error("Another overlay is currently active.");
  3578. }
  3579. this._overlays[this._active].container.classList.add("hidden");
  3580. this._overlays[this._active].element.classList.add("hidden");
  3581. this._active = null;
  3582. window.removeEventListener("keydown", this._keyDownBound);
  3583. }
  3584. _keyDown(evt) {
  3585. if (this._active && evt.keyCode === 27) {
  3586. this._closeThroughCaller();
  3587. evt.preventDefault();
  3588. }
  3589. }
  3590. _closeThroughCaller() {
  3591. if (this._overlays[this._active].callerCloseMethod) {
  3592. this._overlays[this._active].callerCloseMethod();
  3593. }
  3594. if (this._active) {
  3595. this.close(this._active);
  3596. }
  3597. }
  3598. }
  3599. exports.OverlayManager = OverlayManager;
  3600. /***/ }),
  3601. /* 10 */
  3602. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3603. Object.defineProperty(exports, "__esModule", ({
  3604. value: true
  3605. }));
  3606. exports.PasswordPrompt = void 0;
  3607. var _pdfjsLib = __webpack_require__(5);
  3608. class PasswordPrompt {
  3609. constructor(options, overlayManager, l10n, isViewerEmbedded = false) {
  3610. this.overlayName = options.overlayName;
  3611. this.container = options.container;
  3612. this.label = options.label;
  3613. this.input = options.input;
  3614. this.submitButton = options.submitButton;
  3615. this.cancelButton = options.cancelButton;
  3616. this.overlayManager = overlayManager;
  3617. this.l10n = l10n;
  3618. this._isViewerEmbedded = isViewerEmbedded;
  3619. this.updateCallback = null;
  3620. this.reason = null;
  3621. this.submitButton.addEventListener("click", this.verify.bind(this));
  3622. this.cancelButton.addEventListener("click", this.close.bind(this));
  3623. this.input.addEventListener("keydown", e => {
  3624. if (e.keyCode === 13) {
  3625. this.verify();
  3626. }
  3627. });
  3628. this.overlayManager.register(this.overlayName, this.container, this.close.bind(this), true);
  3629. }
  3630. async open() {
  3631. await this.overlayManager.open(this.overlayName);
  3632. const passwordIncorrect = this.reason === _pdfjsLib.PasswordResponses.INCORRECT_PASSWORD;
  3633. if (!this._isViewerEmbedded || passwordIncorrect) {
  3634. this.input.focus();
  3635. }
  3636. this.label.textContent = await this.l10n.get(`password_${passwordIncorrect ? "invalid" : "label"}`);
  3637. }
  3638. close() {
  3639. this.overlayManager.close(this.overlayName).then(() => {
  3640. this.input.value = "";
  3641. });
  3642. }
  3643. verify() {
  3644. const password = this.input.value;
  3645. if (password?.length > 0) {
  3646. this.close();
  3647. this.updateCallback(password);
  3648. }
  3649. }
  3650. setUpdateCallback(updateCallback, reason) {
  3651. this.updateCallback = updateCallback;
  3652. this.reason = reason;
  3653. }
  3654. }
  3655. exports.PasswordPrompt = PasswordPrompt;
  3656. /***/ }),
  3657. /* 11 */
  3658. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3659. Object.defineProperty(exports, "__esModule", ({
  3660. value: true
  3661. }));
  3662. exports.PDFAttachmentViewer = void 0;
  3663. var _pdfjsLib = __webpack_require__(5);
  3664. var _base_tree_viewer = __webpack_require__(12);
  3665. class PDFAttachmentViewer extends _base_tree_viewer.BaseTreeViewer {
  3666. constructor(options) {
  3667. super(options);
  3668. this.downloadManager = options.downloadManager;
  3669. this.eventBus._on("fileattachmentannotation", this._appendAttachment.bind(this));
  3670. }
  3671. reset(keepRenderedCapability = false) {
  3672. super.reset();
  3673. this._attachments = null;
  3674. if (!keepRenderedCapability) {
  3675. this._renderedCapability = (0, _pdfjsLib.createPromiseCapability)();
  3676. }
  3677. if (this._pendingDispatchEvent) {
  3678. clearTimeout(this._pendingDispatchEvent);
  3679. }
  3680. this._pendingDispatchEvent = null;
  3681. }
  3682. _dispatchEvent(attachmentsCount) {
  3683. this._renderedCapability.resolve();
  3684. if (this._pendingDispatchEvent) {
  3685. clearTimeout(this._pendingDispatchEvent);
  3686. this._pendingDispatchEvent = null;
  3687. }
  3688. if (attachmentsCount === 0) {
  3689. this._pendingDispatchEvent = setTimeout(() => {
  3690. this.eventBus.dispatch("attachmentsloaded", {
  3691. source: this,
  3692. attachmentsCount: 0
  3693. });
  3694. this._pendingDispatchEvent = null;
  3695. });
  3696. return;
  3697. }
  3698. this.eventBus.dispatch("attachmentsloaded", {
  3699. source: this,
  3700. attachmentsCount
  3701. });
  3702. }
  3703. _bindLink(element, {
  3704. content,
  3705. filename
  3706. }) {
  3707. element.onclick = () => {
  3708. this.downloadManager.openOrDownloadData(element, content, filename);
  3709. return false;
  3710. };
  3711. }
  3712. render({
  3713. attachments,
  3714. keepRenderedCapability = false
  3715. }) {
  3716. if (this._attachments) {
  3717. this.reset(keepRenderedCapability);
  3718. }
  3719. this._attachments = attachments || null;
  3720. if (!attachments) {
  3721. this._dispatchEvent(0);
  3722. return;
  3723. }
  3724. const names = Object.keys(attachments).sort(function (a, b) {
  3725. return a.toLowerCase().localeCompare(b.toLowerCase());
  3726. });
  3727. const fragment = document.createDocumentFragment();
  3728. let attachmentsCount = 0;
  3729. for (const name of names) {
  3730. const item = attachments[name];
  3731. const content = item.content,
  3732. filename = (0, _pdfjsLib.getFilenameFromUrl)(item.filename);
  3733. const div = document.createElement("div");
  3734. div.className = "treeItem";
  3735. const element = document.createElement("a");
  3736. this._bindLink(element, {
  3737. content,
  3738. filename
  3739. });
  3740. element.textContent = this._normalizeTextContent(filename);
  3741. div.appendChild(element);
  3742. fragment.appendChild(div);
  3743. attachmentsCount++;
  3744. }
  3745. this._finishRendering(fragment, attachmentsCount);
  3746. }
  3747. _appendAttachment({
  3748. id,
  3749. filename,
  3750. content
  3751. }) {
  3752. const renderedPromise = this._renderedCapability.promise;
  3753. renderedPromise.then(() => {
  3754. if (renderedPromise !== this._renderedCapability.promise) {
  3755. return;
  3756. }
  3757. let attachments = this._attachments;
  3758. if (!attachments) {
  3759. attachments = Object.create(null);
  3760. } else {
  3761. for (const name in attachments) {
  3762. if (id === name) {
  3763. return;
  3764. }
  3765. }
  3766. }
  3767. attachments[id] = {
  3768. filename,
  3769. content
  3770. };
  3771. this.render({
  3772. attachments,
  3773. keepRenderedCapability: true
  3774. });
  3775. });
  3776. }
  3777. }
  3778. exports.PDFAttachmentViewer = PDFAttachmentViewer;
  3779. /***/ }),
  3780. /* 12 */
  3781. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3782. Object.defineProperty(exports, "__esModule", ({
  3783. value: true
  3784. }));
  3785. exports.BaseTreeViewer = void 0;
  3786. var _pdfjsLib = __webpack_require__(5);
  3787. const TREEITEM_OFFSET_TOP = -100;
  3788. const TREEITEM_SELECTED_CLASS = "selected";
  3789. class BaseTreeViewer {
  3790. constructor(options) {
  3791. if (this.constructor === BaseTreeViewer) {
  3792. throw new Error("Cannot initialize BaseTreeViewer.");
  3793. }
  3794. this.container = options.container;
  3795. this.eventBus = options.eventBus;
  3796. this.reset();
  3797. }
  3798. reset() {
  3799. this._pdfDocument = null;
  3800. this._lastToggleIsShow = true;
  3801. this._currentTreeItem = null;
  3802. this.container.textContent = "";
  3803. this.container.classList.remove("treeWithDeepNesting");
  3804. }
  3805. _dispatchEvent(count) {
  3806. throw new Error("Not implemented: _dispatchEvent");
  3807. }
  3808. _bindLink(element, params) {
  3809. throw new Error("Not implemented: _bindLink");
  3810. }
  3811. _normalizeTextContent(str) {
  3812. return (0, _pdfjsLib.removeNullCharacters)(str) || "\u2013";
  3813. }
  3814. _addToggleButton(div, hidden = false) {
  3815. const toggler = document.createElement("div");
  3816. toggler.className = "treeItemToggler";
  3817. if (hidden) {
  3818. toggler.classList.add("treeItemsHidden");
  3819. }
  3820. toggler.onclick = evt => {
  3821. evt.stopPropagation();
  3822. toggler.classList.toggle("treeItemsHidden");
  3823. if (evt.shiftKey) {
  3824. const shouldShowAll = !toggler.classList.contains("treeItemsHidden");
  3825. this._toggleTreeItem(div, shouldShowAll);
  3826. }
  3827. };
  3828. div.insertBefore(toggler, div.firstChild);
  3829. }
  3830. _toggleTreeItem(root, show = false) {
  3831. this._lastToggleIsShow = show;
  3832. for (const toggler of root.querySelectorAll(".treeItemToggler")) {
  3833. toggler.classList.toggle("treeItemsHidden", !show);
  3834. }
  3835. }
  3836. _toggleAllTreeItems() {
  3837. this._toggleTreeItem(this.container, !this._lastToggleIsShow);
  3838. }
  3839. _finishRendering(fragment, count, hasAnyNesting = false) {
  3840. if (hasAnyNesting) {
  3841. this.container.classList.add("treeWithDeepNesting");
  3842. this._lastToggleIsShow = !fragment.querySelector(".treeItemsHidden");
  3843. }
  3844. this.container.appendChild(fragment);
  3845. this._dispatchEvent(count);
  3846. }
  3847. render(params) {
  3848. throw new Error("Not implemented: render");
  3849. }
  3850. _updateCurrentTreeItem(treeItem = null) {
  3851. if (this._currentTreeItem) {
  3852. this._currentTreeItem.classList.remove(TREEITEM_SELECTED_CLASS);
  3853. this._currentTreeItem = null;
  3854. }
  3855. if (treeItem) {
  3856. treeItem.classList.add(TREEITEM_SELECTED_CLASS);
  3857. this._currentTreeItem = treeItem;
  3858. }
  3859. }
  3860. _scrollToCurrentTreeItem(treeItem) {
  3861. if (!treeItem) {
  3862. return;
  3863. }
  3864. let currentNode = treeItem.parentNode;
  3865. while (currentNode && currentNode !== this.container) {
  3866. if (currentNode.classList.contains("treeItem")) {
  3867. const toggler = currentNode.firstElementChild;
  3868. toggler?.classList.remove("treeItemsHidden");
  3869. }
  3870. currentNode = currentNode.parentNode;
  3871. }
  3872. this._updateCurrentTreeItem(treeItem);
  3873. this.container.scrollTo(treeItem.offsetLeft, treeItem.offsetTop + TREEITEM_OFFSET_TOP);
  3874. }
  3875. }
  3876. exports.BaseTreeViewer = BaseTreeViewer;
  3877. /***/ }),
  3878. /* 13 */
  3879. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3880. Object.defineProperty(exports, "__esModule", ({
  3881. value: true
  3882. }));
  3883. exports.PDFDocumentProperties = void 0;
  3884. var _pdfjsLib = __webpack_require__(5);
  3885. var _ui_utils = __webpack_require__(4);
  3886. const DEFAULT_FIELD_CONTENT = "-";
  3887. const NON_METRIC_LOCALES = ["en-us", "en-lr", "my"];
  3888. const US_PAGE_NAMES = {
  3889. "8.5x11": "Letter",
  3890. "8.5x14": "Legal"
  3891. };
  3892. const METRIC_PAGE_NAMES = {
  3893. "297x420": "A3",
  3894. "210x297": "A4"
  3895. };
  3896. function getPageName(size, isPortrait, pageNames) {
  3897. const width = isPortrait ? size.width : size.height;
  3898. const height = isPortrait ? size.height : size.width;
  3899. return pageNames[`${width}x${height}`];
  3900. }
  3901. class PDFDocumentProperties {
  3902. constructor({
  3903. overlayName,
  3904. fields,
  3905. container,
  3906. closeButton
  3907. }, overlayManager, eventBus, l10n) {
  3908. this.overlayName = overlayName;
  3909. this.fields = fields;
  3910. this.container = container;
  3911. this.overlayManager = overlayManager;
  3912. this.l10n = l10n;
  3913. this._reset();
  3914. closeButton.addEventListener("click", this.close.bind(this));
  3915. this.overlayManager.register(this.overlayName, this.container, this.close.bind(this));
  3916. eventBus._on("pagechanging", evt => {
  3917. this._currentPageNumber = evt.pageNumber;
  3918. });
  3919. eventBus._on("rotationchanging", evt => {
  3920. this._pagesRotation = evt.pagesRotation;
  3921. });
  3922. this._isNonMetricLocale = true;
  3923. l10n.getLanguage().then(locale => {
  3924. this._isNonMetricLocale = NON_METRIC_LOCALES.includes(locale);
  3925. });
  3926. }
  3927. async open() {
  3928. const freezeFieldData = data => {
  3929. Object.defineProperty(this, "fieldData", {
  3930. value: Object.freeze(data),
  3931. writable: false,
  3932. enumerable: true,
  3933. configurable: true
  3934. });
  3935. };
  3936. await Promise.all([this.overlayManager.open(this.overlayName), this._dataAvailableCapability.promise]);
  3937. const currentPageNumber = this._currentPageNumber;
  3938. const pagesRotation = this._pagesRotation;
  3939. if (this.fieldData && currentPageNumber === this.fieldData._currentPageNumber && pagesRotation === this.fieldData._pagesRotation) {
  3940. this._updateUI();
  3941. return;
  3942. }
  3943. const {
  3944. info,
  3945. contentDispositionFilename,
  3946. contentLength
  3947. } = await this.pdfDocument.getMetadata();
  3948. 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 => {
  3949. return this._parsePageSize((0, _ui_utils.getPageSizeInches)(pdfPage), pagesRotation);
  3950. }), this._parseLinearization(info.IsLinearized)]);
  3951. freezeFieldData({
  3952. fileName,
  3953. fileSize,
  3954. title: info.Title,
  3955. author: info.Author,
  3956. subject: info.Subject,
  3957. keywords: info.Keywords,
  3958. creationDate,
  3959. modificationDate,
  3960. creator: info.Creator,
  3961. producer: info.Producer,
  3962. version: info.PDFFormatVersion,
  3963. pageCount: this.pdfDocument.numPages,
  3964. pageSize,
  3965. linearized: isLinearized,
  3966. _currentPageNumber: currentPageNumber,
  3967. _pagesRotation: pagesRotation
  3968. });
  3969. this._updateUI();
  3970. const {
  3971. length
  3972. } = await this.pdfDocument.getDownloadInfo();
  3973. if (contentLength === length) {
  3974. return;
  3975. }
  3976. const data = Object.assign(Object.create(null), this.fieldData);
  3977. data.fileSize = await this._parseFileSize(length);
  3978. freezeFieldData(data);
  3979. this._updateUI();
  3980. }
  3981. close() {
  3982. this.overlayManager.close(this.overlayName);
  3983. }
  3984. setDocument(pdfDocument, url = null) {
  3985. if (this.pdfDocument) {
  3986. this._reset();
  3987. this._updateUI(true);
  3988. }
  3989. if (!pdfDocument) {
  3990. return;
  3991. }
  3992. this.pdfDocument = pdfDocument;
  3993. this.url = url;
  3994. this._dataAvailableCapability.resolve();
  3995. }
  3996. _reset() {
  3997. this.pdfDocument = null;
  3998. this.url = null;
  3999. delete this.fieldData;
  4000. this._dataAvailableCapability = (0, _pdfjsLib.createPromiseCapability)();
  4001. this._currentPageNumber = 1;
  4002. this._pagesRotation = 0;
  4003. }
  4004. _updateUI(reset = false) {
  4005. if (reset || !this.fieldData) {
  4006. for (const id in this.fields) {
  4007. this.fields[id].textContent = DEFAULT_FIELD_CONTENT;
  4008. }
  4009. return;
  4010. }
  4011. if (this.overlayManager.active !== this.overlayName) {
  4012. return;
  4013. }
  4014. for (const id in this.fields) {
  4015. const content = this.fieldData[id];
  4016. this.fields[id].textContent = content || content === 0 ? content : DEFAULT_FIELD_CONTENT;
  4017. }
  4018. }
  4019. async _parseFileSize(fileSize = 0) {
  4020. const kb = fileSize / 1024,
  4021. mb = kb / 1024;
  4022. if (!kb) {
  4023. return undefined;
  4024. }
  4025. return this.l10n.get(`document_properties_${mb >= 1 ? "mb" : "kb"}`, {
  4026. size_mb: mb >= 1 && (+mb.toPrecision(3)).toLocaleString(),
  4027. size_kb: mb < 1 && (+kb.toPrecision(3)).toLocaleString(),
  4028. size_b: fileSize.toLocaleString()
  4029. });
  4030. }
  4031. async _parsePageSize(pageSizeInches, pagesRotation) {
  4032. if (!pageSizeInches) {
  4033. return undefined;
  4034. }
  4035. if (pagesRotation % 180 !== 0) {
  4036. pageSizeInches = {
  4037. width: pageSizeInches.height,
  4038. height: pageSizeInches.width
  4039. };
  4040. }
  4041. const isPortrait = (0, _ui_utils.isPortraitOrientation)(pageSizeInches);
  4042. let sizeInches = {
  4043. width: Math.round(pageSizeInches.width * 100) / 100,
  4044. height: Math.round(pageSizeInches.height * 100) / 100
  4045. };
  4046. let sizeMillimeters = {
  4047. width: Math.round(pageSizeInches.width * 25.4 * 10) / 10,
  4048. height: Math.round(pageSizeInches.height * 25.4 * 10) / 10
  4049. };
  4050. let rawName = getPageName(sizeInches, isPortrait, US_PAGE_NAMES) || getPageName(sizeMillimeters, isPortrait, METRIC_PAGE_NAMES);
  4051. if (!rawName && !(Number.isInteger(sizeMillimeters.width) && Number.isInteger(sizeMillimeters.height))) {
  4052. const exactMillimeters = {
  4053. width: pageSizeInches.width * 25.4,
  4054. height: pageSizeInches.height * 25.4
  4055. };
  4056. const intMillimeters = {
  4057. width: Math.round(sizeMillimeters.width),
  4058. height: Math.round(sizeMillimeters.height)
  4059. };
  4060. if (Math.abs(exactMillimeters.width - intMillimeters.width) < 0.1 && Math.abs(exactMillimeters.height - intMillimeters.height) < 0.1) {
  4061. rawName = getPageName(intMillimeters, isPortrait, METRIC_PAGE_NAMES);
  4062. if (rawName) {
  4063. sizeInches = {
  4064. width: Math.round(intMillimeters.width / 25.4 * 100) / 100,
  4065. height: Math.round(intMillimeters.height / 25.4 * 100) / 100
  4066. };
  4067. sizeMillimeters = intMillimeters;
  4068. }
  4069. }
  4070. }
  4071. const [{
  4072. width,
  4073. height
  4074. }, 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"}`)]);
  4075. return this.l10n.get(`document_properties_page_size_dimension_${name ? "name_" : ""}string`, {
  4076. width: width.toLocaleString(),
  4077. height: height.toLocaleString(),
  4078. unit,
  4079. name,
  4080. orientation
  4081. });
  4082. }
  4083. async _parseDate(inputDate) {
  4084. const dateObject = _pdfjsLib.PDFDateString.toDateObject(inputDate);
  4085. if (!dateObject) {
  4086. return undefined;
  4087. }
  4088. return this.l10n.get("document_properties_date_string", {
  4089. date: dateObject.toLocaleDateString(),
  4090. time: dateObject.toLocaleTimeString()
  4091. });
  4092. }
  4093. _parseLinearization(isLinearized) {
  4094. return this.l10n.get(`document_properties_linearized_${isLinearized ? "yes" : "no"}`);
  4095. }
  4096. }
  4097. exports.PDFDocumentProperties = PDFDocumentProperties;
  4098. /***/ }),
  4099. /* 14 */
  4100. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4101. Object.defineProperty(exports, "__esModule", ({
  4102. value: true
  4103. }));
  4104. exports.PDFFindBar = void 0;
  4105. var _pdf_find_controller = __webpack_require__(15);
  4106. const MATCHES_COUNT_LIMIT = 1000;
  4107. class PDFFindBar {
  4108. constructor(options, eventBus, l10n) {
  4109. this.opened = false;
  4110. this.bar = options.bar;
  4111. this.toggleButton = options.toggleButton;
  4112. this.findField = options.findField;
  4113. this.highlightAll = options.highlightAllCheckbox;
  4114. this.caseSensitive = options.caseSensitiveCheckbox;
  4115. this.entireWord = options.entireWordCheckbox;
  4116. this.findMsg = options.findMsg;
  4117. this.findResultsCount = options.findResultsCount;
  4118. this.findPreviousButton = options.findPreviousButton;
  4119. this.findNextButton = options.findNextButton;
  4120. this.eventBus = eventBus;
  4121. this.l10n = l10n;
  4122. this.toggleButton.addEventListener("click", () => {
  4123. this.toggle();
  4124. });
  4125. this.findField.addEventListener("input", () => {
  4126. this.dispatchEvent("");
  4127. });
  4128. this.bar.addEventListener("keydown", e => {
  4129. switch (e.keyCode) {
  4130. case 13:
  4131. if (e.target === this.findField) {
  4132. this.dispatchEvent("again", e.shiftKey);
  4133. }
  4134. break;
  4135. case 27:
  4136. this.close();
  4137. break;
  4138. }
  4139. });
  4140. this.findPreviousButton.addEventListener("click", () => {
  4141. this.dispatchEvent("again", true);
  4142. });
  4143. this.findNextButton.addEventListener("click", () => {
  4144. this.dispatchEvent("again", false);
  4145. });
  4146. this.highlightAll.addEventListener("click", () => {
  4147. this.dispatchEvent("highlightallchange");
  4148. });
  4149. this.caseSensitive.addEventListener("click", () => {
  4150. this.dispatchEvent("casesensitivitychange");
  4151. });
  4152. this.entireWord.addEventListener("click", () => {
  4153. this.dispatchEvent("entirewordchange");
  4154. });
  4155. this.eventBus._on("resize", this._adjustWidth.bind(this));
  4156. }
  4157. reset() {
  4158. this.updateUIState();
  4159. }
  4160. dispatchEvent(type, findPrev) {
  4161. this.eventBus.dispatch("find", {
  4162. source: this,
  4163. type,
  4164. query: this.findField.value,
  4165. phraseSearch: true,
  4166. caseSensitive: this.caseSensitive.checked,
  4167. entireWord: this.entireWord.checked,
  4168. highlightAll: this.highlightAll.checked,
  4169. findPrevious: findPrev
  4170. });
  4171. }
  4172. updateUIState(state, previous, matchesCount) {
  4173. let findMsg = Promise.resolve("");
  4174. let status = "";
  4175. switch (state) {
  4176. case _pdf_find_controller.FindState.FOUND:
  4177. break;
  4178. case _pdf_find_controller.FindState.PENDING:
  4179. status = "pending";
  4180. break;
  4181. case _pdf_find_controller.FindState.NOT_FOUND:
  4182. findMsg = this.l10n.get("find_not_found");
  4183. status = "notFound";
  4184. break;
  4185. case _pdf_find_controller.FindState.WRAPPED:
  4186. findMsg = this.l10n.get(`find_reached_${previous ? "top" : "bottom"}`);
  4187. break;
  4188. }
  4189. this.findField.setAttribute("data-status", status);
  4190. findMsg.then(msg => {
  4191. this.findMsg.textContent = msg;
  4192. this._adjustWidth();
  4193. });
  4194. this.updateResultsCount(matchesCount);
  4195. }
  4196. updateResultsCount({
  4197. current = 0,
  4198. total = 0
  4199. } = {}) {
  4200. const limit = MATCHES_COUNT_LIMIT;
  4201. let matchCountMsg = Promise.resolve("");
  4202. if (total > 0) {
  4203. if (total > limit) {
  4204. let key = "find_match_count_limit";
  4205. matchCountMsg = this.l10n.get(key, {
  4206. limit
  4207. });
  4208. } else {
  4209. let key = "find_match_count";
  4210. matchCountMsg = this.l10n.get(key, {
  4211. current,
  4212. total
  4213. });
  4214. }
  4215. }
  4216. matchCountMsg.then(msg => {
  4217. this.findResultsCount.textContent = msg;
  4218. this.findResultsCount.classList.toggle("hidden", !total);
  4219. this._adjustWidth();
  4220. });
  4221. }
  4222. open() {
  4223. if (!this.opened) {
  4224. this.opened = true;
  4225. this.toggleButton.classList.add("toggled");
  4226. this.toggleButton.setAttribute("aria-expanded", "true");
  4227. this.bar.classList.remove("hidden");
  4228. }
  4229. this.findField.select();
  4230. this.findField.focus();
  4231. this._adjustWidth();
  4232. }
  4233. close() {
  4234. if (!this.opened) {
  4235. return;
  4236. }
  4237. this.opened = false;
  4238. this.toggleButton.classList.remove("toggled");
  4239. this.toggleButton.setAttribute("aria-expanded", "false");
  4240. this.bar.classList.add("hidden");
  4241. this.eventBus.dispatch("findbarclose", {
  4242. source: this
  4243. });
  4244. }
  4245. toggle() {
  4246. if (this.opened) {
  4247. this.close();
  4248. } else {
  4249. this.open();
  4250. }
  4251. }
  4252. _adjustWidth() {
  4253. if (!this.opened) {
  4254. return;
  4255. }
  4256. this.bar.classList.remove("wrapContainers");
  4257. const findbarHeight = this.bar.clientHeight;
  4258. const inputContainerHeight = this.bar.firstElementChild.clientHeight;
  4259. if (findbarHeight > inputContainerHeight) {
  4260. this.bar.classList.add("wrapContainers");
  4261. }
  4262. }
  4263. }
  4264. exports.PDFFindBar = PDFFindBar;
  4265. /***/ }),
  4266. /* 15 */
  4267. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4268. Object.defineProperty(exports, "__esModule", ({
  4269. value: true
  4270. }));
  4271. exports.PDFFindController = exports.FindState = void 0;
  4272. var _pdfjsLib = __webpack_require__(5);
  4273. var _pdf_find_utils = __webpack_require__(16);
  4274. var _ui_utils = __webpack_require__(4);
  4275. const FindState = {
  4276. FOUND: 0,
  4277. NOT_FOUND: 1,
  4278. WRAPPED: 2,
  4279. PENDING: 3
  4280. };
  4281. exports.FindState = FindState;
  4282. const FIND_TIMEOUT = 250;
  4283. const MATCH_SCROLL_OFFSET_TOP = -50;
  4284. const MATCH_SCROLL_OFFSET_LEFT = -400;
  4285. const CHARACTERS_TO_NORMALIZE = {
  4286. "\u2018": "'",
  4287. "\u2019": "'",
  4288. "\u201A": "'",
  4289. "\u201B": "'",
  4290. "\u201C": '"',
  4291. "\u201D": '"',
  4292. "\u201E": '"',
  4293. "\u201F": '"',
  4294. "\u00BC": "1/4",
  4295. "\u00BD": "1/2",
  4296. "\u00BE": "3/4"
  4297. };
  4298. let normalizationRegex = null;
  4299. function normalize(text) {
  4300. if (!normalizationRegex) {
  4301. const replace = Object.keys(CHARACTERS_TO_NORMALIZE).join("");
  4302. normalizationRegex = new RegExp(`[${replace}]`, "g");
  4303. }
  4304. let diffs = null;
  4305. const normalizedText = text.replace(normalizationRegex, function (ch, index) {
  4306. const normalizedCh = CHARACTERS_TO_NORMALIZE[ch],
  4307. diff = normalizedCh.length - ch.length;
  4308. if (diff !== 0) {
  4309. (diffs || (diffs = [])).push([index, diff]);
  4310. }
  4311. return normalizedCh;
  4312. });
  4313. return [normalizedText, diffs];
  4314. }
  4315. function getOriginalIndex(matchIndex, diffs = null) {
  4316. if (!diffs) {
  4317. return matchIndex;
  4318. }
  4319. let totalDiff = 0;
  4320. for (const [index, diff] of diffs) {
  4321. const currentIndex = index + totalDiff;
  4322. if (currentIndex >= matchIndex) {
  4323. break;
  4324. }
  4325. if (currentIndex + diff > matchIndex) {
  4326. totalDiff += matchIndex - currentIndex;
  4327. break;
  4328. }
  4329. totalDiff += diff;
  4330. }
  4331. return matchIndex - totalDiff;
  4332. }
  4333. class PDFFindController {
  4334. constructor({
  4335. linkService,
  4336. eventBus
  4337. }) {
  4338. this._linkService = linkService;
  4339. this._eventBus = eventBus;
  4340. this._reset();
  4341. eventBus._on("findbarclose", this._onFindBarClose.bind(this));
  4342. }
  4343. get highlightMatches() {
  4344. return this._highlightMatches;
  4345. }
  4346. get pageMatches() {
  4347. return this._pageMatches;
  4348. }
  4349. get pageMatchesLength() {
  4350. return this._pageMatchesLength;
  4351. }
  4352. get selected() {
  4353. return this._selected;
  4354. }
  4355. get state() {
  4356. return this._state;
  4357. }
  4358. setDocument(pdfDocument) {
  4359. if (this._pdfDocument) {
  4360. this._reset();
  4361. }
  4362. if (!pdfDocument) {
  4363. return;
  4364. }
  4365. this._pdfDocument = pdfDocument;
  4366. this._firstPageCapability.resolve();
  4367. }
  4368. executeCommand(cmd, state) {
  4369. if (!state) {
  4370. return;
  4371. }
  4372. const pdfDocument = this._pdfDocument;
  4373. if (this._state === null || this._shouldDirtyMatch(cmd, state)) {
  4374. this._dirtyMatch = true;
  4375. }
  4376. this._state = state;
  4377. if (cmd !== "findhighlightallchange") {
  4378. this._updateUIState(FindState.PENDING);
  4379. }
  4380. this._firstPageCapability.promise.then(() => {
  4381. if (!this._pdfDocument || pdfDocument && this._pdfDocument !== pdfDocument) {
  4382. return;
  4383. }
  4384. this._extractText();
  4385. const findbarClosed = !this._highlightMatches;
  4386. const pendingTimeout = !!this._findTimeout;
  4387. if (this._findTimeout) {
  4388. clearTimeout(this._findTimeout);
  4389. this._findTimeout = null;
  4390. }
  4391. if (cmd === "find") {
  4392. this._findTimeout = setTimeout(() => {
  4393. this._nextMatch();
  4394. this._findTimeout = null;
  4395. }, FIND_TIMEOUT);
  4396. } else if (this._dirtyMatch) {
  4397. this._nextMatch();
  4398. } else if (cmd === "findagain") {
  4399. this._nextMatch();
  4400. if (findbarClosed && this._state.highlightAll) {
  4401. this._updateAllPages();
  4402. }
  4403. } else if (cmd === "findhighlightallchange") {
  4404. if (pendingTimeout) {
  4405. this._nextMatch();
  4406. } else {
  4407. this._highlightMatches = true;
  4408. }
  4409. this._updateAllPages();
  4410. } else {
  4411. this._nextMatch();
  4412. }
  4413. });
  4414. }
  4415. scrollMatchIntoView({
  4416. element = null,
  4417. pageIndex = -1,
  4418. matchIndex = -1
  4419. }) {
  4420. if (!this._scrollMatches || !element) {
  4421. return;
  4422. } else if (matchIndex === -1 || matchIndex !== this._selected.matchIdx) {
  4423. return;
  4424. } else if (pageIndex === -1 || pageIndex !== this._selected.pageIdx) {
  4425. return;
  4426. }
  4427. this._scrollMatches = false;
  4428. const spot = {
  4429. top: MATCH_SCROLL_OFFSET_TOP,
  4430. left: MATCH_SCROLL_OFFSET_LEFT
  4431. };
  4432. (0, _ui_utils.scrollIntoView)(element, spot, true);
  4433. }
  4434. _reset() {
  4435. this._highlightMatches = false;
  4436. this._scrollMatches = false;
  4437. this._pdfDocument = null;
  4438. this._pageMatches = [];
  4439. this._pageMatchesLength = [];
  4440. this._state = null;
  4441. this._selected = {
  4442. pageIdx: -1,
  4443. matchIdx: -1
  4444. };
  4445. this._offset = {
  4446. pageIdx: null,
  4447. matchIdx: null,
  4448. wrapped: false
  4449. };
  4450. this._extractTextPromises = [];
  4451. this._pageContents = [];
  4452. this._pageDiffs = [];
  4453. this._matchesCountTotal = 0;
  4454. this._pagesToSearch = null;
  4455. this._pendingFindMatches = Object.create(null);
  4456. this._resumePageIdx = null;
  4457. this._dirtyMatch = false;
  4458. clearTimeout(this._findTimeout);
  4459. this._findTimeout = null;
  4460. this._firstPageCapability = (0, _pdfjsLib.createPromiseCapability)();
  4461. }
  4462. get _query() {
  4463. if (this._state.query !== this._rawQuery) {
  4464. this._rawQuery = this._state.query;
  4465. [this._normalizedQuery] = normalize(this._state.query);
  4466. }
  4467. return this._normalizedQuery;
  4468. }
  4469. _shouldDirtyMatch(cmd, state) {
  4470. if (state.query !== this._state.query) {
  4471. return true;
  4472. }
  4473. switch (cmd) {
  4474. case "findagain":
  4475. const pageNumber = this._selected.pageIdx + 1;
  4476. const linkService = this._linkService;
  4477. if (pageNumber >= 1 && pageNumber <= linkService.pagesCount && pageNumber !== linkService.page && !linkService.isPageVisible(pageNumber)) {
  4478. return true;
  4479. }
  4480. return false;
  4481. case "findhighlightallchange":
  4482. return false;
  4483. }
  4484. return true;
  4485. }
  4486. _prepareMatches(matchesWithLength, matches, matchesLength) {
  4487. function isSubTerm(currentIndex) {
  4488. const currentElem = matchesWithLength[currentIndex];
  4489. const nextElem = matchesWithLength[currentIndex + 1];
  4490. if (currentIndex < matchesWithLength.length - 1 && currentElem.match === nextElem.match) {
  4491. currentElem.skipped = true;
  4492. return true;
  4493. }
  4494. for (let i = currentIndex - 1; i >= 0; i--) {
  4495. const prevElem = matchesWithLength[i];
  4496. if (prevElem.skipped) {
  4497. continue;
  4498. }
  4499. if (prevElem.match + prevElem.matchLength < currentElem.match) {
  4500. break;
  4501. }
  4502. if (prevElem.match + prevElem.matchLength >= currentElem.match + currentElem.matchLength) {
  4503. currentElem.skipped = true;
  4504. return true;
  4505. }
  4506. }
  4507. return false;
  4508. }
  4509. matchesWithLength.sort(function (a, b) {
  4510. return a.match === b.match ? a.matchLength - b.matchLength : a.match - b.match;
  4511. });
  4512. for (let i = 0, len = matchesWithLength.length; i < len; i++) {
  4513. if (isSubTerm(i)) {
  4514. continue;
  4515. }
  4516. matches.push(matchesWithLength[i].match);
  4517. matchesLength.push(matchesWithLength[i].matchLength);
  4518. }
  4519. }
  4520. _isEntireWord(content, startIdx, length) {
  4521. if (startIdx > 0) {
  4522. const first = content.charCodeAt(startIdx);
  4523. const limit = content.charCodeAt(startIdx - 1);
  4524. if ((0, _pdf_find_utils.getCharacterType)(first) === (0, _pdf_find_utils.getCharacterType)(limit)) {
  4525. return false;
  4526. }
  4527. }
  4528. const endIdx = startIdx + length - 1;
  4529. if (endIdx < content.length - 1) {
  4530. const last = content.charCodeAt(endIdx);
  4531. const limit = content.charCodeAt(endIdx + 1);
  4532. if ((0, _pdf_find_utils.getCharacterType)(last) === (0, _pdf_find_utils.getCharacterType)(limit)) {
  4533. return false;
  4534. }
  4535. }
  4536. return true;
  4537. }
  4538. _calculatePhraseMatch(query, pageIndex, pageContent, pageDiffs, entireWord) {
  4539. const matches = [],
  4540. matchesLength = [];
  4541. const queryLen = query.length;
  4542. let matchIdx = -queryLen;
  4543. while (true) {
  4544. matchIdx = pageContent.indexOf(query, matchIdx + queryLen);
  4545. if (matchIdx === -1) {
  4546. break;
  4547. }
  4548. if (entireWord && !this._isEntireWord(pageContent, matchIdx, queryLen)) {
  4549. continue;
  4550. }
  4551. const originalMatchIdx = getOriginalIndex(matchIdx, pageDiffs),
  4552. matchEnd = matchIdx + queryLen - 1,
  4553. originalQueryLen = getOriginalIndex(matchEnd, pageDiffs) - originalMatchIdx + 1;
  4554. matches.push(originalMatchIdx);
  4555. matchesLength.push(originalQueryLen);
  4556. }
  4557. this._pageMatches[pageIndex] = matches;
  4558. this._pageMatchesLength[pageIndex] = matchesLength;
  4559. }
  4560. _calculateWordMatch(query, pageIndex, pageContent, pageDiffs, entireWord) {
  4561. const matchesWithLength = [];
  4562. const queryArray = query.match(/\S+/g);
  4563. for (let i = 0, len = queryArray.length; i < len; i++) {
  4564. const subquery = queryArray[i];
  4565. const subqueryLen = subquery.length;
  4566. let matchIdx = -subqueryLen;
  4567. while (true) {
  4568. matchIdx = pageContent.indexOf(subquery, matchIdx + subqueryLen);
  4569. if (matchIdx === -1) {
  4570. break;
  4571. }
  4572. if (entireWord && !this._isEntireWord(pageContent, matchIdx, subqueryLen)) {
  4573. continue;
  4574. }
  4575. const originalMatchIdx = getOriginalIndex(matchIdx, pageDiffs),
  4576. matchEnd = matchIdx + subqueryLen - 1,
  4577. originalQueryLen = getOriginalIndex(matchEnd, pageDiffs) - originalMatchIdx + 1;
  4578. matchesWithLength.push({
  4579. match: originalMatchIdx,
  4580. matchLength: originalQueryLen,
  4581. skipped: false
  4582. });
  4583. }
  4584. }
  4585. this._pageMatchesLength[pageIndex] = [];
  4586. this._pageMatches[pageIndex] = [];
  4587. this._prepareMatches(matchesWithLength, this._pageMatches[pageIndex], this._pageMatchesLength[pageIndex]);
  4588. }
  4589. _calculateMatch(pageIndex) {
  4590. let pageContent = this._pageContents[pageIndex];
  4591. const pageDiffs = this._pageDiffs[pageIndex];
  4592. let query = this._query;
  4593. const {
  4594. caseSensitive,
  4595. entireWord,
  4596. phraseSearch
  4597. } = this._state;
  4598. if (query.length === 0) {
  4599. return;
  4600. }
  4601. if (!caseSensitive) {
  4602. pageContent = pageContent.toLowerCase();
  4603. query = query.toLowerCase();
  4604. }
  4605. if (phraseSearch) {
  4606. this._calculatePhraseMatch(query, pageIndex, pageContent, pageDiffs, entireWord);
  4607. } else {
  4608. this._calculateWordMatch(query, pageIndex, pageContent, pageDiffs, entireWord);
  4609. }
  4610. if (this._state.highlightAll) {
  4611. this._updatePage(pageIndex);
  4612. }
  4613. if (this._resumePageIdx === pageIndex) {
  4614. this._resumePageIdx = null;
  4615. this._nextPageMatch();
  4616. }
  4617. const pageMatchesCount = this._pageMatches[pageIndex].length;
  4618. if (pageMatchesCount > 0) {
  4619. this._matchesCountTotal += pageMatchesCount;
  4620. this._updateUIResultsCount();
  4621. }
  4622. }
  4623. _extractText() {
  4624. if (this._extractTextPromises.length > 0) {
  4625. return;
  4626. }
  4627. let promise = Promise.resolve();
  4628. for (let i = 0, ii = this._linkService.pagesCount; i < ii; i++) {
  4629. const extractTextCapability = (0, _pdfjsLib.createPromiseCapability)();
  4630. this._extractTextPromises[i] = extractTextCapability.promise;
  4631. promise = promise.then(() => {
  4632. return this._pdfDocument.getPage(i + 1).then(pdfPage => {
  4633. return pdfPage.getTextContent({
  4634. normalizeWhitespace: true
  4635. });
  4636. }).then(textContent => {
  4637. const textItems = textContent.items;
  4638. const strBuf = [];
  4639. for (let j = 0, jj = textItems.length; j < jj; j++) {
  4640. strBuf.push(textItems[j].str);
  4641. }
  4642. [this._pageContents[i], this._pageDiffs[i]] = normalize(strBuf.join(""));
  4643. extractTextCapability.resolve(i);
  4644. }, reason => {
  4645. console.error(`Unable to get text content for page ${i + 1}`, reason);
  4646. this._pageContents[i] = "";
  4647. this._pageDiffs[i] = null;
  4648. extractTextCapability.resolve(i);
  4649. });
  4650. });
  4651. }
  4652. }
  4653. _updatePage(index) {
  4654. if (this._scrollMatches && this._selected.pageIdx === index) {
  4655. this._linkService.page = index + 1;
  4656. }
  4657. this._eventBus.dispatch("updatetextlayermatches", {
  4658. source: this,
  4659. pageIndex: index
  4660. });
  4661. }
  4662. _updateAllPages() {
  4663. this._eventBus.dispatch("updatetextlayermatches", {
  4664. source: this,
  4665. pageIndex: -1
  4666. });
  4667. }
  4668. _nextMatch() {
  4669. const previous = this._state.findPrevious;
  4670. const currentPageIndex = this._linkService.page - 1;
  4671. const numPages = this._linkService.pagesCount;
  4672. this._highlightMatches = true;
  4673. if (this._dirtyMatch) {
  4674. this._dirtyMatch = false;
  4675. this._selected.pageIdx = this._selected.matchIdx = -1;
  4676. this._offset.pageIdx = currentPageIndex;
  4677. this._offset.matchIdx = null;
  4678. this._offset.wrapped = false;
  4679. this._resumePageIdx = null;
  4680. this._pageMatches.length = 0;
  4681. this._pageMatchesLength.length = 0;
  4682. this._matchesCountTotal = 0;
  4683. this._updateAllPages();
  4684. for (let i = 0; i < numPages; i++) {
  4685. if (this._pendingFindMatches[i] === true) {
  4686. continue;
  4687. }
  4688. this._pendingFindMatches[i] = true;
  4689. this._extractTextPromises[i].then(pageIdx => {
  4690. delete this._pendingFindMatches[pageIdx];
  4691. this._calculateMatch(pageIdx);
  4692. });
  4693. }
  4694. }
  4695. if (this._query === "") {
  4696. this._updateUIState(FindState.FOUND);
  4697. return;
  4698. }
  4699. if (this._resumePageIdx) {
  4700. return;
  4701. }
  4702. const offset = this._offset;
  4703. this._pagesToSearch = numPages;
  4704. if (offset.matchIdx !== null) {
  4705. const numPageMatches = this._pageMatches[offset.pageIdx].length;
  4706. if (!previous && offset.matchIdx + 1 < numPageMatches || previous && offset.matchIdx > 0) {
  4707. offset.matchIdx = previous ? offset.matchIdx - 1 : offset.matchIdx + 1;
  4708. this._updateMatch(true);
  4709. return;
  4710. }
  4711. this._advanceOffsetPage(previous);
  4712. }
  4713. this._nextPageMatch();
  4714. }
  4715. _matchesReady(matches) {
  4716. const offset = this._offset;
  4717. const numMatches = matches.length;
  4718. const previous = this._state.findPrevious;
  4719. if (numMatches) {
  4720. offset.matchIdx = previous ? numMatches - 1 : 0;
  4721. this._updateMatch(true);
  4722. return true;
  4723. }
  4724. this._advanceOffsetPage(previous);
  4725. if (offset.wrapped) {
  4726. offset.matchIdx = null;
  4727. if (this._pagesToSearch < 0) {
  4728. this._updateMatch(false);
  4729. return true;
  4730. }
  4731. }
  4732. return false;
  4733. }
  4734. _nextPageMatch() {
  4735. if (this._resumePageIdx !== null) {
  4736. console.error("There can only be one pending page.");
  4737. }
  4738. let matches = null;
  4739. do {
  4740. const pageIdx = this._offset.pageIdx;
  4741. matches = this._pageMatches[pageIdx];
  4742. if (!matches) {
  4743. this._resumePageIdx = pageIdx;
  4744. break;
  4745. }
  4746. } while (!this._matchesReady(matches));
  4747. }
  4748. _advanceOffsetPage(previous) {
  4749. const offset = this._offset;
  4750. const numPages = this._linkService.pagesCount;
  4751. offset.pageIdx = previous ? offset.pageIdx - 1 : offset.pageIdx + 1;
  4752. offset.matchIdx = null;
  4753. this._pagesToSearch--;
  4754. if (offset.pageIdx >= numPages || offset.pageIdx < 0) {
  4755. offset.pageIdx = previous ? numPages - 1 : 0;
  4756. offset.wrapped = true;
  4757. }
  4758. }
  4759. _updateMatch(found = false) {
  4760. let state = FindState.NOT_FOUND;
  4761. const wrapped = this._offset.wrapped;
  4762. this._offset.wrapped = false;
  4763. if (found) {
  4764. const previousPage = this._selected.pageIdx;
  4765. this._selected.pageIdx = this._offset.pageIdx;
  4766. this._selected.matchIdx = this._offset.matchIdx;
  4767. state = wrapped ? FindState.WRAPPED : FindState.FOUND;
  4768. if (previousPage !== -1 && previousPage !== this._selected.pageIdx) {
  4769. this._updatePage(previousPage);
  4770. }
  4771. }
  4772. this._updateUIState(state, this._state.findPrevious);
  4773. if (this._selected.pageIdx !== -1) {
  4774. this._scrollMatches = true;
  4775. this._updatePage(this._selected.pageIdx);
  4776. }
  4777. }
  4778. _onFindBarClose(evt) {
  4779. const pdfDocument = this._pdfDocument;
  4780. this._firstPageCapability.promise.then(() => {
  4781. if (!this._pdfDocument || pdfDocument && this._pdfDocument !== pdfDocument) {
  4782. return;
  4783. }
  4784. if (this._findTimeout) {
  4785. clearTimeout(this._findTimeout);
  4786. this._findTimeout = null;
  4787. }
  4788. if (this._resumePageIdx) {
  4789. this._resumePageIdx = null;
  4790. this._dirtyMatch = true;
  4791. }
  4792. this._updateUIState(FindState.FOUND);
  4793. this._highlightMatches = false;
  4794. this._updateAllPages();
  4795. });
  4796. }
  4797. _requestMatchesCount() {
  4798. const {
  4799. pageIdx,
  4800. matchIdx
  4801. } = this._selected;
  4802. let current = 0,
  4803. total = this._matchesCountTotal;
  4804. if (matchIdx !== -1) {
  4805. for (let i = 0; i < pageIdx; i++) {
  4806. current += this._pageMatches[i]?.length || 0;
  4807. }
  4808. current += matchIdx + 1;
  4809. }
  4810. if (current < 1 || current > total) {
  4811. current = total = 0;
  4812. }
  4813. return {
  4814. current,
  4815. total
  4816. };
  4817. }
  4818. _updateUIResultsCount() {
  4819. this._eventBus.dispatch("updatefindmatchescount", {
  4820. source: this,
  4821. matchesCount: this._requestMatchesCount()
  4822. });
  4823. }
  4824. _updateUIState(state, previous) {
  4825. this._eventBus.dispatch("updatefindcontrolstate", {
  4826. source: this,
  4827. state,
  4828. previous,
  4829. matchesCount: this._requestMatchesCount(),
  4830. rawQuery: this._state?.query ?? null
  4831. });
  4832. }
  4833. }
  4834. exports.PDFFindController = PDFFindController;
  4835. /***/ }),
  4836. /* 16 */
  4837. /***/ ((__unused_webpack_module, exports) => {
  4838. Object.defineProperty(exports, "__esModule", ({
  4839. value: true
  4840. }));
  4841. exports.getCharacterType = getCharacterType;
  4842. exports.CharacterType = void 0;
  4843. const CharacterType = {
  4844. SPACE: 0,
  4845. ALPHA_LETTER: 1,
  4846. PUNCT: 2,
  4847. HAN_LETTER: 3,
  4848. KATAKANA_LETTER: 4,
  4849. HIRAGANA_LETTER: 5,
  4850. HALFWIDTH_KATAKANA_LETTER: 6,
  4851. THAI_LETTER: 7
  4852. };
  4853. exports.CharacterType = CharacterType;
  4854. function isAlphabeticalScript(charCode) {
  4855. return charCode < 0x2e80;
  4856. }
  4857. function isAscii(charCode) {
  4858. return (charCode & 0xff80) === 0;
  4859. }
  4860. function isAsciiAlpha(charCode) {
  4861. return charCode >= 0x61 && charCode <= 0x7a || charCode >= 0x41 && charCode <= 0x5a;
  4862. }
  4863. function isAsciiDigit(charCode) {
  4864. return charCode >= 0x30 && charCode <= 0x39;
  4865. }
  4866. function isAsciiSpace(charCode) {
  4867. return charCode === 0x20 || charCode === 0x09 || charCode === 0x0d || charCode === 0x0a;
  4868. }
  4869. function isHan(charCode) {
  4870. return charCode >= 0x3400 && charCode <= 0x9fff || charCode >= 0xf900 && charCode <= 0xfaff;
  4871. }
  4872. function isKatakana(charCode) {
  4873. return charCode >= 0x30a0 && charCode <= 0x30ff;
  4874. }
  4875. function isHiragana(charCode) {
  4876. return charCode >= 0x3040 && charCode <= 0x309f;
  4877. }
  4878. function isHalfwidthKatakana(charCode) {
  4879. return charCode >= 0xff60 && charCode <= 0xff9f;
  4880. }
  4881. function isThai(charCode) {
  4882. return (charCode & 0xff80) === 0x0e00;
  4883. }
  4884. function getCharacterType(charCode) {
  4885. if (isAlphabeticalScript(charCode)) {
  4886. if (isAscii(charCode)) {
  4887. if (isAsciiSpace(charCode)) {
  4888. return CharacterType.SPACE;
  4889. } else if (isAsciiAlpha(charCode) || isAsciiDigit(charCode) || charCode === 0x5f) {
  4890. return CharacterType.ALPHA_LETTER;
  4891. }
  4892. return CharacterType.PUNCT;
  4893. } else if (isThai(charCode)) {
  4894. return CharacterType.THAI_LETTER;
  4895. } else if (charCode === 0xa0) {
  4896. return CharacterType.SPACE;
  4897. }
  4898. return CharacterType.ALPHA_LETTER;
  4899. }
  4900. if (isHan(charCode)) {
  4901. return CharacterType.HAN_LETTER;
  4902. } else if (isKatakana(charCode)) {
  4903. return CharacterType.KATAKANA_LETTER;
  4904. } else if (isHiragana(charCode)) {
  4905. return CharacterType.HIRAGANA_LETTER;
  4906. } else if (isHalfwidthKatakana(charCode)) {
  4907. return CharacterType.HALFWIDTH_KATAKANA_LETTER;
  4908. }
  4909. return CharacterType.ALPHA_LETTER;
  4910. }
  4911. /***/ }),
  4912. /* 17 */
  4913. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4914. Object.defineProperty(exports, "__esModule", ({
  4915. value: true
  4916. }));
  4917. exports.isDestArraysEqual = isDestArraysEqual;
  4918. exports.isDestHashesEqual = isDestHashesEqual;
  4919. exports.PDFHistory = void 0;
  4920. var _ui_utils = __webpack_require__(4);
  4921. const HASH_CHANGE_TIMEOUT = 1000;
  4922. const POSITION_UPDATED_THRESHOLD = 50;
  4923. const UPDATE_VIEWAREA_TIMEOUT = 1000;
  4924. function getCurrentHash() {
  4925. return document.location.hash;
  4926. }
  4927. class PDFHistory {
  4928. constructor({
  4929. linkService,
  4930. eventBus
  4931. }) {
  4932. this.linkService = linkService;
  4933. this.eventBus = eventBus;
  4934. this._initialized = false;
  4935. this._fingerprint = "";
  4936. this.reset();
  4937. this._boundEvents = null;
  4938. this._isViewerInPresentationMode = false;
  4939. this.eventBus._on("presentationmodechanged", evt => {
  4940. this._isViewerInPresentationMode = evt.state !== _ui_utils.PresentationModeState.NORMAL;
  4941. });
  4942. this.eventBus._on("pagesinit", () => {
  4943. this._isPagesLoaded = false;
  4944. this.eventBus._on("pagesloaded", evt => {
  4945. this._isPagesLoaded = !!evt.pagesCount;
  4946. }, {
  4947. once: true
  4948. });
  4949. });
  4950. }
  4951. initialize({
  4952. fingerprint,
  4953. resetHistory = false,
  4954. updateUrl = false
  4955. }) {
  4956. if (!fingerprint || typeof fingerprint !== "string") {
  4957. console.error('PDFHistory.initialize: The "fingerprint" must be a non-empty string.');
  4958. return;
  4959. }
  4960. if (this._initialized) {
  4961. this.reset();
  4962. }
  4963. const reInitialized = this._fingerprint !== "" && this._fingerprint !== fingerprint;
  4964. this._fingerprint = fingerprint;
  4965. this._updateUrl = updateUrl === true;
  4966. this._initialized = true;
  4967. this._bindEvents();
  4968. const state = window.history.state;
  4969. this._popStateInProgress = false;
  4970. this._blockHashChange = 0;
  4971. this._currentHash = getCurrentHash();
  4972. this._numPositionUpdates = 0;
  4973. this._uid = this._maxUid = 0;
  4974. this._destination = null;
  4975. this._position = null;
  4976. if (!this._isValidState(state, true) || resetHistory) {
  4977. const {
  4978. hash,
  4979. page,
  4980. rotation
  4981. } = this._parseCurrentHash(true);
  4982. if (!hash || reInitialized || resetHistory) {
  4983. this._pushOrReplaceState(null, true);
  4984. return;
  4985. }
  4986. this._pushOrReplaceState({
  4987. hash,
  4988. page,
  4989. rotation
  4990. }, true);
  4991. return;
  4992. }
  4993. const destination = state.destination;
  4994. this._updateInternalState(destination, state.uid, true);
  4995. if (destination.rotation !== undefined) {
  4996. this._initialRotation = destination.rotation;
  4997. }
  4998. if (destination.dest) {
  4999. this._initialBookmark = JSON.stringify(destination.dest);
  5000. this._destination.page = null;
  5001. } else if (destination.hash) {
  5002. this._initialBookmark = destination.hash;
  5003. } else if (destination.page) {
  5004. this._initialBookmark = `page=${destination.page}`;
  5005. }
  5006. }
  5007. reset() {
  5008. if (this._initialized) {
  5009. this._pageHide();
  5010. this._initialized = false;
  5011. this._unbindEvents();
  5012. }
  5013. if (this._updateViewareaTimeout) {
  5014. clearTimeout(this._updateViewareaTimeout);
  5015. this._updateViewareaTimeout = null;
  5016. }
  5017. this._initialBookmark = null;
  5018. this._initialRotation = null;
  5019. }
  5020. push({
  5021. namedDest = null,
  5022. explicitDest,
  5023. pageNumber
  5024. }) {
  5025. if (!this._initialized) {
  5026. return;
  5027. }
  5028. if (namedDest && typeof namedDest !== "string") {
  5029. console.error("PDFHistory.push: " + `"${namedDest}" is not a valid namedDest parameter.`);
  5030. return;
  5031. } else if (!Array.isArray(explicitDest)) {
  5032. console.error("PDFHistory.push: " + `"${explicitDest}" is not a valid explicitDest parameter.`);
  5033. return;
  5034. } else if (!this._isValidPage(pageNumber)) {
  5035. if (pageNumber !== null || this._destination) {
  5036. console.error("PDFHistory.push: " + `"${pageNumber}" is not a valid pageNumber parameter.`);
  5037. return;
  5038. }
  5039. }
  5040. const hash = namedDest || JSON.stringify(explicitDest);
  5041. if (!hash) {
  5042. return;
  5043. }
  5044. let forceReplace = false;
  5045. if (this._destination && (isDestHashesEqual(this._destination.hash, hash) || isDestArraysEqual(this._destination.dest, explicitDest))) {
  5046. if (this._destination.page) {
  5047. return;
  5048. }
  5049. forceReplace = true;
  5050. }
  5051. if (this._popStateInProgress && !forceReplace) {
  5052. return;
  5053. }
  5054. this._pushOrReplaceState({
  5055. dest: explicitDest,
  5056. hash,
  5057. page: pageNumber,
  5058. rotation: this.linkService.rotation
  5059. }, forceReplace);
  5060. if (!this._popStateInProgress) {
  5061. this._popStateInProgress = true;
  5062. Promise.resolve().then(() => {
  5063. this._popStateInProgress = false;
  5064. });
  5065. }
  5066. }
  5067. pushPage(pageNumber) {
  5068. if (!this._initialized) {
  5069. return;
  5070. }
  5071. if (!this._isValidPage(pageNumber)) {
  5072. console.error(`PDFHistory.pushPage: "${pageNumber}" is not a valid page number.`);
  5073. return;
  5074. }
  5075. if (this._destination?.page === pageNumber) {
  5076. return;
  5077. }
  5078. if (this._popStateInProgress) {
  5079. return;
  5080. }
  5081. this._pushOrReplaceState({
  5082. dest: null,
  5083. hash: `page=${pageNumber}`,
  5084. page: pageNumber,
  5085. rotation: this.linkService.rotation
  5086. });
  5087. if (!this._popStateInProgress) {
  5088. this._popStateInProgress = true;
  5089. Promise.resolve().then(() => {
  5090. this._popStateInProgress = false;
  5091. });
  5092. }
  5093. }
  5094. pushCurrentPosition() {
  5095. if (!this._initialized || this._popStateInProgress) {
  5096. return;
  5097. }
  5098. this._tryPushCurrentPosition();
  5099. }
  5100. back() {
  5101. if (!this._initialized || this._popStateInProgress) {
  5102. return;
  5103. }
  5104. const state = window.history.state;
  5105. if (this._isValidState(state) && state.uid > 0) {
  5106. window.history.back();
  5107. }
  5108. }
  5109. forward() {
  5110. if (!this._initialized || this._popStateInProgress) {
  5111. return;
  5112. }
  5113. const state = window.history.state;
  5114. if (this._isValidState(state) && state.uid < this._maxUid) {
  5115. window.history.forward();
  5116. }
  5117. }
  5118. get popStateInProgress() {
  5119. return this._initialized && (this._popStateInProgress || this._blockHashChange > 0);
  5120. }
  5121. get initialBookmark() {
  5122. return this._initialized ? this._initialBookmark : null;
  5123. }
  5124. get initialRotation() {
  5125. return this._initialized ? this._initialRotation : null;
  5126. }
  5127. _pushOrReplaceState(destination, forceReplace = false) {
  5128. const shouldReplace = forceReplace || !this._destination;
  5129. const newState = {
  5130. fingerprint: this._fingerprint,
  5131. uid: shouldReplace ? this._uid : this._uid + 1,
  5132. destination
  5133. };
  5134. this._updateInternalState(destination, newState.uid);
  5135. let newUrl;
  5136. if (this._updateUrl && destination?.hash) {
  5137. const baseUrl = document.location.href.split("#")[0];
  5138. if (!baseUrl.startsWith("file://")) {
  5139. newUrl = `${baseUrl}#${destination.hash}`;
  5140. }
  5141. }
  5142. if (shouldReplace) {
  5143. window.history.replaceState(newState, "", newUrl);
  5144. } else {
  5145. window.history.pushState(newState, "", newUrl);
  5146. }
  5147. }
  5148. _tryPushCurrentPosition(temporary = false) {
  5149. if (!this._position) {
  5150. return;
  5151. }
  5152. let position = this._position;
  5153. if (temporary) {
  5154. position = Object.assign(Object.create(null), this._position);
  5155. position.temporary = true;
  5156. }
  5157. if (!this._destination) {
  5158. this._pushOrReplaceState(position);
  5159. return;
  5160. }
  5161. if (this._destination.temporary) {
  5162. this._pushOrReplaceState(position, true);
  5163. return;
  5164. }
  5165. if (this._destination.hash === position.hash) {
  5166. return;
  5167. }
  5168. if (!this._destination.page && (POSITION_UPDATED_THRESHOLD <= 0 || this._numPositionUpdates <= POSITION_UPDATED_THRESHOLD)) {
  5169. return;
  5170. }
  5171. let forceReplace = false;
  5172. if (this._destination.page >= position.first && this._destination.page <= position.page) {
  5173. if (this._destination.dest !== undefined || !this._destination.first) {
  5174. return;
  5175. }
  5176. forceReplace = true;
  5177. }
  5178. this._pushOrReplaceState(position, forceReplace);
  5179. }
  5180. _isValidPage(val) {
  5181. return Number.isInteger(val) && val > 0 && val <= this.linkService.pagesCount;
  5182. }
  5183. _isValidState(state, checkReload = false) {
  5184. if (!state) {
  5185. return false;
  5186. }
  5187. if (state.fingerprint !== this._fingerprint) {
  5188. if (checkReload) {
  5189. if (typeof state.fingerprint !== "string" || state.fingerprint.length !== this._fingerprint.length) {
  5190. return false;
  5191. }
  5192. const [perfEntry] = performance.getEntriesByType("navigation");
  5193. if (perfEntry?.type !== "reload") {
  5194. return false;
  5195. }
  5196. } else {
  5197. return false;
  5198. }
  5199. }
  5200. if (!Number.isInteger(state.uid) || state.uid < 0) {
  5201. return false;
  5202. }
  5203. if (state.destination === null || typeof state.destination !== "object") {
  5204. return false;
  5205. }
  5206. return true;
  5207. }
  5208. _updateInternalState(destination, uid, removeTemporary = false) {
  5209. if (this._updateViewareaTimeout) {
  5210. clearTimeout(this._updateViewareaTimeout);
  5211. this._updateViewareaTimeout = null;
  5212. }
  5213. if (removeTemporary && destination?.temporary) {
  5214. delete destination.temporary;
  5215. }
  5216. this._destination = destination;
  5217. this._uid = uid;
  5218. this._maxUid = Math.max(this._maxUid, uid);
  5219. this._numPositionUpdates = 0;
  5220. }
  5221. _parseCurrentHash(checkNameddest = false) {
  5222. const hash = unescape(getCurrentHash()).substring(1);
  5223. const params = (0, _ui_utils.parseQueryString)(hash);
  5224. const nameddest = params.nameddest || "";
  5225. let page = params.page | 0;
  5226. if (!this._isValidPage(page) || checkNameddest && nameddest.length > 0) {
  5227. page = null;
  5228. }
  5229. return {
  5230. hash,
  5231. page,
  5232. rotation: this.linkService.rotation
  5233. };
  5234. }
  5235. _updateViewarea({
  5236. location
  5237. }) {
  5238. if (this._updateViewareaTimeout) {
  5239. clearTimeout(this._updateViewareaTimeout);
  5240. this._updateViewareaTimeout = null;
  5241. }
  5242. this._position = {
  5243. hash: this._isViewerInPresentationMode ? `page=${location.pageNumber}` : location.pdfOpenParams.substring(1),
  5244. page: this.linkService.page,
  5245. first: location.pageNumber,
  5246. rotation: location.rotation
  5247. };
  5248. if (this._popStateInProgress) {
  5249. return;
  5250. }
  5251. if (POSITION_UPDATED_THRESHOLD > 0 && this._isPagesLoaded && this._destination && !this._destination.page) {
  5252. this._numPositionUpdates++;
  5253. }
  5254. if (UPDATE_VIEWAREA_TIMEOUT > 0) {
  5255. this._updateViewareaTimeout = setTimeout(() => {
  5256. if (!this._popStateInProgress) {
  5257. this._tryPushCurrentPosition(true);
  5258. }
  5259. this._updateViewareaTimeout = null;
  5260. }, UPDATE_VIEWAREA_TIMEOUT);
  5261. }
  5262. }
  5263. _popState({
  5264. state
  5265. }) {
  5266. const newHash = getCurrentHash(),
  5267. hashChanged = this._currentHash !== newHash;
  5268. this._currentHash = newHash;
  5269. if (!state) {
  5270. this._uid++;
  5271. const {
  5272. hash,
  5273. page,
  5274. rotation
  5275. } = this._parseCurrentHash();
  5276. this._pushOrReplaceState({
  5277. hash,
  5278. page,
  5279. rotation
  5280. }, true);
  5281. return;
  5282. }
  5283. if (!this._isValidState(state)) {
  5284. return;
  5285. }
  5286. this._popStateInProgress = true;
  5287. if (hashChanged) {
  5288. this._blockHashChange++;
  5289. (0, _ui_utils.waitOnEventOrTimeout)({
  5290. target: window,
  5291. name: "hashchange",
  5292. delay: HASH_CHANGE_TIMEOUT
  5293. }).then(() => {
  5294. this._blockHashChange--;
  5295. });
  5296. }
  5297. const destination = state.destination;
  5298. this._updateInternalState(destination, state.uid, true);
  5299. if ((0, _ui_utils.isValidRotation)(destination.rotation)) {
  5300. this.linkService.rotation = destination.rotation;
  5301. }
  5302. if (destination.dest) {
  5303. this.linkService.goToDestination(destination.dest);
  5304. } else if (destination.hash) {
  5305. this.linkService.setHash(destination.hash);
  5306. } else if (destination.page) {
  5307. this.linkService.page = destination.page;
  5308. }
  5309. Promise.resolve().then(() => {
  5310. this._popStateInProgress = false;
  5311. });
  5312. }
  5313. _pageHide() {
  5314. if (!this._destination || this._destination.temporary) {
  5315. this._tryPushCurrentPosition();
  5316. }
  5317. }
  5318. _bindEvents() {
  5319. if (this._boundEvents) {
  5320. return;
  5321. }
  5322. this._boundEvents = {
  5323. updateViewarea: this._updateViewarea.bind(this),
  5324. popState: this._popState.bind(this),
  5325. pageHide: this._pageHide.bind(this)
  5326. };
  5327. this.eventBus._on("updateviewarea", this._boundEvents.updateViewarea);
  5328. window.addEventListener("popstate", this._boundEvents.popState);
  5329. window.addEventListener("pagehide", this._boundEvents.pageHide);
  5330. }
  5331. _unbindEvents() {
  5332. if (!this._boundEvents) {
  5333. return;
  5334. }
  5335. this.eventBus._off("updateviewarea", this._boundEvents.updateViewarea);
  5336. window.removeEventListener("popstate", this._boundEvents.popState);
  5337. window.removeEventListener("pagehide", this._boundEvents.pageHide);
  5338. this._boundEvents = null;
  5339. }
  5340. }
  5341. exports.PDFHistory = PDFHistory;
  5342. function isDestHashesEqual(destHash, pushHash) {
  5343. if (typeof destHash !== "string" || typeof pushHash !== "string") {
  5344. return false;
  5345. }
  5346. if (destHash === pushHash) {
  5347. return true;
  5348. }
  5349. const {
  5350. nameddest
  5351. } = (0, _ui_utils.parseQueryString)(destHash);
  5352. if (nameddest === pushHash) {
  5353. return true;
  5354. }
  5355. return false;
  5356. }
  5357. function isDestArraysEqual(firstDest, secondDest) {
  5358. function isEntryEqual(first, second) {
  5359. if (typeof first !== typeof second) {
  5360. return false;
  5361. }
  5362. if (Array.isArray(first) || Array.isArray(second)) {
  5363. return false;
  5364. }
  5365. if (first !== null && typeof first === "object" && second !== null) {
  5366. if (Object.keys(first).length !== Object.keys(second).length) {
  5367. return false;
  5368. }
  5369. for (const key in first) {
  5370. if (!isEntryEqual(first[key], second[key])) {
  5371. return false;
  5372. }
  5373. }
  5374. return true;
  5375. }
  5376. return first === second || Number.isNaN(first) && Number.isNaN(second);
  5377. }
  5378. if (!(Array.isArray(firstDest) && Array.isArray(secondDest))) {
  5379. return false;
  5380. }
  5381. if (firstDest.length !== secondDest.length) {
  5382. return false;
  5383. }
  5384. for (let i = 0, ii = firstDest.length; i < ii; i++) {
  5385. if (!isEntryEqual(firstDest[i], secondDest[i])) {
  5386. return false;
  5387. }
  5388. }
  5389. return true;
  5390. }
  5391. /***/ }),
  5392. /* 18 */
  5393. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  5394. Object.defineProperty(exports, "__esModule", ({
  5395. value: true
  5396. }));
  5397. exports.PDFLayerViewer = void 0;
  5398. var _base_tree_viewer = __webpack_require__(12);
  5399. class PDFLayerViewer extends _base_tree_viewer.BaseTreeViewer {
  5400. constructor(options) {
  5401. super(options);
  5402. this.l10n = options.l10n;
  5403. this.eventBus._on("resetlayers", this._resetLayers.bind(this));
  5404. this.eventBus._on("togglelayerstree", this._toggleAllTreeItems.bind(this));
  5405. }
  5406. reset() {
  5407. super.reset();
  5408. this._optionalContentConfig = null;
  5409. }
  5410. _dispatchEvent(layersCount) {
  5411. this.eventBus.dispatch("layersloaded", {
  5412. source: this,
  5413. layersCount
  5414. });
  5415. }
  5416. _bindLink(element, {
  5417. groupId,
  5418. input
  5419. }) {
  5420. const setVisibility = () => {
  5421. this._optionalContentConfig.setVisibility(groupId, input.checked);
  5422. this.eventBus.dispatch("optionalcontentconfig", {
  5423. source: this,
  5424. promise: Promise.resolve(this._optionalContentConfig)
  5425. });
  5426. };
  5427. element.onclick = evt => {
  5428. if (evt.target === input) {
  5429. setVisibility();
  5430. return true;
  5431. } else if (evt.target !== element) {
  5432. return true;
  5433. }
  5434. input.checked = !input.checked;
  5435. setVisibility();
  5436. return false;
  5437. };
  5438. }
  5439. async _setNestedName(element, {
  5440. name = null
  5441. }) {
  5442. if (typeof name === "string") {
  5443. element.textContent = this._normalizeTextContent(name);
  5444. return;
  5445. }
  5446. element.textContent = await this.l10n.get("additional_layers");
  5447. element.style.fontStyle = "italic";
  5448. }
  5449. _addToggleButton(div, {
  5450. name = null
  5451. }) {
  5452. super._addToggleButton(div, name === null);
  5453. }
  5454. _toggleAllTreeItems() {
  5455. if (!this._optionalContentConfig) {
  5456. return;
  5457. }
  5458. super._toggleAllTreeItems();
  5459. }
  5460. render({
  5461. optionalContentConfig,
  5462. pdfDocument
  5463. }) {
  5464. if (this._optionalContentConfig) {
  5465. this.reset();
  5466. }
  5467. this._optionalContentConfig = optionalContentConfig || null;
  5468. this._pdfDocument = pdfDocument || null;
  5469. const groups = optionalContentConfig?.getOrder();
  5470. if (!groups) {
  5471. this._dispatchEvent(0);
  5472. return;
  5473. }
  5474. const fragment = document.createDocumentFragment(),
  5475. queue = [{
  5476. parent: fragment,
  5477. groups
  5478. }];
  5479. let layersCount = 0,
  5480. hasAnyNesting = false;
  5481. while (queue.length > 0) {
  5482. const levelData = queue.shift();
  5483. for (const groupId of levelData.groups) {
  5484. const div = document.createElement("div");
  5485. div.className = "treeItem";
  5486. const element = document.createElement("a");
  5487. div.appendChild(element);
  5488. if (typeof groupId === "object") {
  5489. hasAnyNesting = true;
  5490. this._addToggleButton(div, groupId);
  5491. this._setNestedName(element, groupId);
  5492. const itemsDiv = document.createElement("div");
  5493. itemsDiv.className = "treeItems";
  5494. div.appendChild(itemsDiv);
  5495. queue.push({
  5496. parent: itemsDiv,
  5497. groups: groupId.order
  5498. });
  5499. } else {
  5500. const group = optionalContentConfig.getGroup(groupId);
  5501. const input = document.createElement("input");
  5502. this._bindLink(element, {
  5503. groupId,
  5504. input
  5505. });
  5506. input.type = "checkbox";
  5507. input.id = groupId;
  5508. input.checked = group.visible;
  5509. const label = document.createElement("label");
  5510. label.setAttribute("for", groupId);
  5511. label.textContent = this._normalizeTextContent(group.name);
  5512. element.appendChild(input);
  5513. element.appendChild(label);
  5514. layersCount++;
  5515. }
  5516. levelData.parent.appendChild(div);
  5517. }
  5518. }
  5519. this._finishRendering(fragment, layersCount, hasAnyNesting);
  5520. }
  5521. async _resetLayers() {
  5522. if (!this._optionalContentConfig) {
  5523. return;
  5524. }
  5525. const optionalContentConfig = await this._pdfDocument.getOptionalContentConfig();
  5526. this.eventBus.dispatch("optionalcontentconfig", {
  5527. source: this,
  5528. promise: Promise.resolve(optionalContentConfig)
  5529. });
  5530. this.render({
  5531. optionalContentConfig,
  5532. pdfDocument: this._pdfDocument
  5533. });
  5534. }
  5535. }
  5536. exports.PDFLayerViewer = PDFLayerViewer;
  5537. /***/ }),
  5538. /* 19 */
  5539. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  5540. Object.defineProperty(exports, "__esModule", ({
  5541. value: true
  5542. }));
  5543. exports.SimpleLinkService = exports.PDFLinkService = void 0;
  5544. var _ui_utils = __webpack_require__(4);
  5545. class PDFLinkService {
  5546. constructor({
  5547. eventBus,
  5548. externalLinkTarget = null,
  5549. externalLinkRel = null,
  5550. externalLinkEnabled = true,
  5551. ignoreDestinationZoom = false
  5552. } = {}) {
  5553. this.eventBus = eventBus;
  5554. this.externalLinkTarget = externalLinkTarget;
  5555. this.externalLinkRel = externalLinkRel;
  5556. this.externalLinkEnabled = externalLinkEnabled;
  5557. this._ignoreDestinationZoom = ignoreDestinationZoom;
  5558. this.baseUrl = null;
  5559. this.pdfDocument = null;
  5560. this.pdfViewer = null;
  5561. this.pdfHistory = null;
  5562. this._pagesRefCache = null;
  5563. }
  5564. setDocument(pdfDocument, baseUrl = null) {
  5565. this.baseUrl = baseUrl;
  5566. this.pdfDocument = pdfDocument;
  5567. this._pagesRefCache = Object.create(null);
  5568. }
  5569. setViewer(pdfViewer) {
  5570. this.pdfViewer = pdfViewer;
  5571. }
  5572. setHistory(pdfHistory) {
  5573. this.pdfHistory = pdfHistory;
  5574. }
  5575. get pagesCount() {
  5576. return this.pdfDocument ? this.pdfDocument.numPages : 0;
  5577. }
  5578. get page() {
  5579. return this.pdfViewer.currentPageNumber;
  5580. }
  5581. set page(value) {
  5582. this.pdfViewer.currentPageNumber = value;
  5583. }
  5584. get rotation() {
  5585. return this.pdfViewer.pagesRotation;
  5586. }
  5587. set rotation(value) {
  5588. this.pdfViewer.pagesRotation = value;
  5589. }
  5590. navigateTo(dest) {
  5591. console.error("Deprecated method: `navigateTo`, use `goToDestination` instead.");
  5592. this.goToDestination(dest);
  5593. }
  5594. _goToDestinationHelper(rawDest, namedDest = null, explicitDest) {
  5595. const destRef = explicitDest[0];
  5596. let pageNumber;
  5597. if (destRef instanceof Object) {
  5598. pageNumber = this._cachedPageNumber(destRef);
  5599. if (pageNumber === null) {
  5600. this.pdfDocument.getPageIndex(destRef).then(pageIndex => {
  5601. this.cachePageRef(pageIndex + 1, destRef);
  5602. this._goToDestinationHelper(rawDest, namedDest, explicitDest);
  5603. }).catch(() => {
  5604. console.error(`PDFLinkService._goToDestinationHelper: "${destRef}" is not ` + `a valid page reference, for dest="${rawDest}".`);
  5605. });
  5606. return;
  5607. }
  5608. } else if (Number.isInteger(destRef)) {
  5609. pageNumber = destRef + 1;
  5610. } else {
  5611. console.error(`PDFLinkService._goToDestinationHelper: "${destRef}" is not ` + `a valid destination reference, for dest="${rawDest}".`);
  5612. return;
  5613. }
  5614. if (!pageNumber || pageNumber < 1 || pageNumber > this.pagesCount) {
  5615. console.error(`PDFLinkService._goToDestinationHelper: "${pageNumber}" is not ` + `a valid page number, for dest="${rawDest}".`);
  5616. return;
  5617. }
  5618. if (this.pdfHistory) {
  5619. this.pdfHistory.pushCurrentPosition();
  5620. this.pdfHistory.push({
  5621. namedDest,
  5622. explicitDest,
  5623. pageNumber
  5624. });
  5625. }
  5626. this.pdfViewer.scrollPageIntoView({
  5627. pageNumber,
  5628. destArray: explicitDest,
  5629. ignoreDestinationZoom: this._ignoreDestinationZoom
  5630. });
  5631. }
  5632. async goToDestination(dest) {
  5633. if (!this.pdfDocument) {
  5634. return;
  5635. }
  5636. let namedDest, explicitDest;
  5637. if (typeof dest === "string") {
  5638. namedDest = dest;
  5639. explicitDest = await this.pdfDocument.getDestination(dest);
  5640. } else {
  5641. namedDest = null;
  5642. explicitDest = await dest;
  5643. }
  5644. if (!Array.isArray(explicitDest)) {
  5645. console.error(`PDFLinkService.goToDestination: "${explicitDest}" is not ` + `a valid destination array, for dest="${dest}".`);
  5646. return;
  5647. }
  5648. this._goToDestinationHelper(dest, namedDest, explicitDest);
  5649. }
  5650. goToPage(val) {
  5651. if (!this.pdfDocument) {
  5652. return;
  5653. }
  5654. const pageNumber = typeof val === "string" && this.pdfViewer.pageLabelToPageNumber(val) || val | 0;
  5655. if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) {
  5656. console.error(`PDFLinkService.goToPage: "${val}" is not a valid page.`);
  5657. return;
  5658. }
  5659. if (this.pdfHistory) {
  5660. this.pdfHistory.pushCurrentPosition();
  5661. this.pdfHistory.pushPage(pageNumber);
  5662. }
  5663. this.pdfViewer.scrollPageIntoView({
  5664. pageNumber
  5665. });
  5666. }
  5667. getDestinationHash(dest) {
  5668. if (typeof dest === "string") {
  5669. if (dest.length > 0) {
  5670. return this.getAnchorUrl("#" + escape(dest));
  5671. }
  5672. } else if (Array.isArray(dest)) {
  5673. const str = JSON.stringify(dest);
  5674. if (str.length > 0) {
  5675. return this.getAnchorUrl("#" + escape(str));
  5676. }
  5677. }
  5678. return this.getAnchorUrl("");
  5679. }
  5680. getAnchorUrl(anchor) {
  5681. return (this.baseUrl || "") + anchor;
  5682. }
  5683. setHash(hash) {
  5684. if (!this.pdfDocument) {
  5685. return;
  5686. }
  5687. let pageNumber, dest;
  5688. if (hash.includes("=")) {
  5689. const params = (0, _ui_utils.parseQueryString)(hash);
  5690. if ("search" in params) {
  5691. this.eventBus.dispatch("findfromurlhash", {
  5692. source: this,
  5693. query: params.search.replace(/"/g, ""),
  5694. phraseSearch: params.phrase === "true"
  5695. });
  5696. }
  5697. if ("page" in params) {
  5698. pageNumber = params.page | 0 || 1;
  5699. }
  5700. if ("zoom" in params) {
  5701. const zoomArgs = params.zoom.split(",");
  5702. const zoomArg = zoomArgs[0];
  5703. const zoomArgNumber = parseFloat(zoomArg);
  5704. if (!zoomArg.includes("Fit")) {
  5705. dest = [null, {
  5706. name: "XYZ"
  5707. }, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null, zoomArgs.length > 2 ? zoomArgs[2] | 0 : null, zoomArgNumber ? zoomArgNumber / 100 : zoomArg];
  5708. } else {
  5709. if (zoomArg === "Fit" || zoomArg === "FitB") {
  5710. dest = [null, {
  5711. name: zoomArg
  5712. }];
  5713. } else if (zoomArg === "FitH" || zoomArg === "FitBH" || zoomArg === "FitV" || zoomArg === "FitBV") {
  5714. dest = [null, {
  5715. name: zoomArg
  5716. }, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null];
  5717. } else if (zoomArg === "FitR") {
  5718. if (zoomArgs.length !== 5) {
  5719. console.error('PDFLinkService.setHash: Not enough parameters for "FitR".');
  5720. } else {
  5721. dest = [null, {
  5722. name: zoomArg
  5723. }, zoomArgs[1] | 0, zoomArgs[2] | 0, zoomArgs[3] | 0, zoomArgs[4] | 0];
  5724. }
  5725. } else {
  5726. console.error(`PDFLinkService.setHash: "${zoomArg}" is not ` + "a valid zoom value.");
  5727. }
  5728. }
  5729. }
  5730. if (dest) {
  5731. this.pdfViewer.scrollPageIntoView({
  5732. pageNumber: pageNumber || this.page,
  5733. destArray: dest,
  5734. allowNegativeOffset: true
  5735. });
  5736. } else if (pageNumber) {
  5737. this.page = pageNumber;
  5738. }
  5739. if ("pagemode" in params) {
  5740. this.eventBus.dispatch("pagemode", {
  5741. source: this,
  5742. mode: params.pagemode
  5743. });
  5744. }
  5745. if ("nameddest" in params) {
  5746. this.goToDestination(params.nameddest);
  5747. }
  5748. } else {
  5749. dest = unescape(hash);
  5750. try {
  5751. dest = JSON.parse(dest);
  5752. if (!Array.isArray(dest)) {
  5753. dest = dest.toString();
  5754. }
  5755. } catch (ex) {}
  5756. if (typeof dest === "string" || isValidExplicitDestination(dest)) {
  5757. this.goToDestination(dest);
  5758. return;
  5759. }
  5760. console.error(`PDFLinkService.setHash: "${unescape(hash)}" is not ` + "a valid destination.");
  5761. }
  5762. }
  5763. executeNamedAction(action) {
  5764. switch (action) {
  5765. case "GoBack":
  5766. if (this.pdfHistory) {
  5767. this.pdfHistory.back();
  5768. }
  5769. break;
  5770. case "GoForward":
  5771. if (this.pdfHistory) {
  5772. this.pdfHistory.forward();
  5773. }
  5774. break;
  5775. case "NextPage":
  5776. this.pdfViewer.nextPage();
  5777. break;
  5778. case "PrevPage":
  5779. this.pdfViewer.previousPage();
  5780. break;
  5781. case "LastPage":
  5782. this.page = this.pagesCount;
  5783. break;
  5784. case "FirstPage":
  5785. this.page = 1;
  5786. break;
  5787. default:
  5788. break;
  5789. }
  5790. this.eventBus.dispatch("namedaction", {
  5791. source: this,
  5792. action
  5793. });
  5794. }
  5795. cachePageRef(pageNum, pageRef) {
  5796. if (!pageRef) {
  5797. return;
  5798. }
  5799. const refStr = pageRef.gen === 0 ? `${pageRef.num}R` : `${pageRef.num}R${pageRef.gen}`;
  5800. this._pagesRefCache[refStr] = pageNum;
  5801. }
  5802. _cachedPageNumber(pageRef) {
  5803. const refStr = pageRef.gen === 0 ? `${pageRef.num}R` : `${pageRef.num}R${pageRef.gen}`;
  5804. return this._pagesRefCache?.[refStr] || null;
  5805. }
  5806. isPageVisible(pageNumber) {
  5807. return this.pdfViewer.isPageVisible(pageNumber);
  5808. }
  5809. isPageCached(pageNumber) {
  5810. return this.pdfViewer.isPageCached(pageNumber);
  5811. }
  5812. }
  5813. exports.PDFLinkService = PDFLinkService;
  5814. function isValidExplicitDestination(dest) {
  5815. if (!Array.isArray(dest)) {
  5816. return false;
  5817. }
  5818. const destLength = dest.length;
  5819. if (destLength < 2) {
  5820. return false;
  5821. }
  5822. const page = dest[0];
  5823. if (!(typeof page === "object" && Number.isInteger(page.num) && Number.isInteger(page.gen)) && !(Number.isInteger(page) && page >= 0)) {
  5824. return false;
  5825. }
  5826. const zoom = dest[1];
  5827. if (!(typeof zoom === "object" && typeof zoom.name === "string")) {
  5828. return false;
  5829. }
  5830. let allowNull = true;
  5831. switch (zoom.name) {
  5832. case "XYZ":
  5833. if (destLength !== 5) {
  5834. return false;
  5835. }
  5836. break;
  5837. case "Fit":
  5838. case "FitB":
  5839. return destLength === 2;
  5840. case "FitH":
  5841. case "FitBH":
  5842. case "FitV":
  5843. case "FitBV":
  5844. if (destLength !== 3) {
  5845. return false;
  5846. }
  5847. break;
  5848. case "FitR":
  5849. if (destLength !== 6) {
  5850. return false;
  5851. }
  5852. allowNull = false;
  5853. break;
  5854. default:
  5855. return false;
  5856. }
  5857. for (let i = 2; i < destLength; i++) {
  5858. const param = dest[i];
  5859. if (!(typeof param === "number" || allowNull && param === null)) {
  5860. return false;
  5861. }
  5862. }
  5863. return true;
  5864. }
  5865. class SimpleLinkService {
  5866. constructor() {
  5867. this.externalLinkTarget = null;
  5868. this.externalLinkRel = null;
  5869. this.externalLinkEnabled = true;
  5870. this._ignoreDestinationZoom = false;
  5871. }
  5872. get pagesCount() {
  5873. return 0;
  5874. }
  5875. get page() {
  5876. return 0;
  5877. }
  5878. set page(value) {}
  5879. get rotation() {
  5880. return 0;
  5881. }
  5882. set rotation(value) {}
  5883. async goToDestination(dest) {}
  5884. goToPage(val) {}
  5885. getDestinationHash(dest) {
  5886. return "#";
  5887. }
  5888. getAnchorUrl(hash) {
  5889. return "#";
  5890. }
  5891. setHash(hash) {}
  5892. executeNamedAction(action) {}
  5893. cachePageRef(pageNum, pageRef) {}
  5894. isPageVisible(pageNumber) {
  5895. return true;
  5896. }
  5897. isPageCached(pageNumber) {
  5898. return true;
  5899. }
  5900. }
  5901. exports.SimpleLinkService = SimpleLinkService;
  5902. /***/ }),
  5903. /* 20 */
  5904. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  5905. Object.defineProperty(exports, "__esModule", ({
  5906. value: true
  5907. }));
  5908. exports.PDFOutlineViewer = void 0;
  5909. var _pdfjsLib = __webpack_require__(5);
  5910. var _base_tree_viewer = __webpack_require__(12);
  5911. var _ui_utils = __webpack_require__(4);
  5912. class PDFOutlineViewer extends _base_tree_viewer.BaseTreeViewer {
  5913. constructor(options) {
  5914. super(options);
  5915. this.linkService = options.linkService;
  5916. this.eventBus._on("toggleoutlinetree", this._toggleAllTreeItems.bind(this));
  5917. this.eventBus._on("currentoutlineitem", this._currentOutlineItem.bind(this));
  5918. this.eventBus._on("pagechanging", evt => {
  5919. this._currentPageNumber = evt.pageNumber;
  5920. });
  5921. this.eventBus._on("pagesloaded", evt => {
  5922. this._isPagesLoaded = !!evt.pagesCount;
  5923. });
  5924. this.eventBus._on("sidebarviewchanged", evt => {
  5925. this._sidebarView = evt.view;
  5926. });
  5927. }
  5928. reset() {
  5929. super.reset();
  5930. this._outline = null;
  5931. this._pageNumberToDestHashCapability = null;
  5932. this._currentPageNumber = 1;
  5933. this._isPagesLoaded = false;
  5934. }
  5935. _dispatchEvent(outlineCount) {
  5936. this.eventBus.dispatch("outlineloaded", {
  5937. source: this,
  5938. outlineCount,
  5939. enableCurrentOutlineItemButton: outlineCount > 0 && !this._pdfDocument?.loadingParams.disableAutoFetch
  5940. });
  5941. }
  5942. _bindLink(element, {
  5943. url,
  5944. newWindow,
  5945. dest
  5946. }) {
  5947. const {
  5948. linkService
  5949. } = this;
  5950. if (url) {
  5951. (0, _pdfjsLib.addLinkAttributes)(element, {
  5952. url,
  5953. target: newWindow ? _pdfjsLib.LinkTarget.BLANK : linkService.externalLinkTarget,
  5954. rel: linkService.externalLinkRel,
  5955. enabled: linkService.externalLinkEnabled
  5956. });
  5957. return;
  5958. }
  5959. element.href = linkService.getDestinationHash(dest);
  5960. element.onclick = evt => {
  5961. this._updateCurrentTreeItem(evt.target.parentNode);
  5962. if (dest) {
  5963. linkService.goToDestination(dest);
  5964. }
  5965. return false;
  5966. };
  5967. }
  5968. _setStyles(element, {
  5969. bold,
  5970. italic
  5971. }) {
  5972. if (bold) {
  5973. element.style.fontWeight = "bold";
  5974. }
  5975. if (italic) {
  5976. element.style.fontStyle = "italic";
  5977. }
  5978. }
  5979. _addToggleButton(div, {
  5980. count,
  5981. items
  5982. }) {
  5983. let hidden = false;
  5984. if (count < 0) {
  5985. let totalCount = items.length;
  5986. if (totalCount > 0) {
  5987. const queue = [...items];
  5988. while (queue.length > 0) {
  5989. const {
  5990. count: nestedCount,
  5991. items: nestedItems
  5992. } = queue.shift();
  5993. if (nestedCount > 0 && nestedItems.length > 0) {
  5994. totalCount += nestedItems.length;
  5995. queue.push(...nestedItems);
  5996. }
  5997. }
  5998. }
  5999. if (Math.abs(count) === totalCount) {
  6000. hidden = true;
  6001. }
  6002. }
  6003. super._addToggleButton(div, hidden);
  6004. }
  6005. _toggleAllTreeItems() {
  6006. if (!this._outline) {
  6007. return;
  6008. }
  6009. super._toggleAllTreeItems();
  6010. }
  6011. render({
  6012. outline,
  6013. pdfDocument
  6014. }) {
  6015. if (this._outline) {
  6016. this.reset();
  6017. }
  6018. this._outline = outline || null;
  6019. this._pdfDocument = pdfDocument || null;
  6020. if (!outline) {
  6021. this._dispatchEvent(0);
  6022. return;
  6023. }
  6024. const fragment = document.createDocumentFragment();
  6025. const queue = [{
  6026. parent: fragment,
  6027. items: outline
  6028. }];
  6029. let outlineCount = 0,
  6030. hasAnyNesting = false;
  6031. while (queue.length > 0) {
  6032. const levelData = queue.shift();
  6033. for (const item of levelData.items) {
  6034. const div = document.createElement("div");
  6035. div.className = "treeItem";
  6036. const element = document.createElement("a");
  6037. this._bindLink(element, item);
  6038. this._setStyles(element, item);
  6039. element.textContent = this._normalizeTextContent(item.title);
  6040. div.appendChild(element);
  6041. if (item.items.length > 0) {
  6042. hasAnyNesting = true;
  6043. this._addToggleButton(div, item);
  6044. const itemsDiv = document.createElement("div");
  6045. itemsDiv.className = "treeItems";
  6046. div.appendChild(itemsDiv);
  6047. queue.push({
  6048. parent: itemsDiv,
  6049. items: item.items
  6050. });
  6051. }
  6052. levelData.parent.appendChild(div);
  6053. outlineCount++;
  6054. }
  6055. }
  6056. this._finishRendering(fragment, outlineCount, hasAnyNesting);
  6057. }
  6058. async _currentOutlineItem() {
  6059. if (!this._isPagesLoaded) {
  6060. throw new Error("_currentOutlineItem: All pages have not been loaded.");
  6061. }
  6062. if (!this._outline || !this._pdfDocument) {
  6063. return;
  6064. }
  6065. const pageNumberToDestHash = await this._getPageNumberToDestHash(this._pdfDocument);
  6066. if (!pageNumberToDestHash) {
  6067. return;
  6068. }
  6069. this._updateCurrentTreeItem(null);
  6070. if (this._sidebarView !== _ui_utils.SidebarView.OUTLINE) {
  6071. return;
  6072. }
  6073. for (let i = this._currentPageNumber; i > 0; i--) {
  6074. const destHash = pageNumberToDestHash.get(i);
  6075. if (!destHash) {
  6076. continue;
  6077. }
  6078. const linkElement = this.container.querySelector(`a[href="${destHash}"]`);
  6079. if (!linkElement) {
  6080. continue;
  6081. }
  6082. this._scrollToCurrentTreeItem(linkElement.parentNode);
  6083. break;
  6084. }
  6085. }
  6086. async _getPageNumberToDestHash(pdfDocument) {
  6087. if (this._pageNumberToDestHashCapability) {
  6088. return this._pageNumberToDestHashCapability.promise;
  6089. }
  6090. this._pageNumberToDestHashCapability = (0, _pdfjsLib.createPromiseCapability)();
  6091. const pageNumberToDestHash = new Map(),
  6092. pageNumberNesting = new Map();
  6093. const queue = [{
  6094. nesting: 0,
  6095. items: this._outline
  6096. }];
  6097. while (queue.length > 0) {
  6098. const levelData = queue.shift(),
  6099. currentNesting = levelData.nesting;
  6100. for (const {
  6101. dest,
  6102. items
  6103. } of levelData.items) {
  6104. let explicitDest, pageNumber;
  6105. if (typeof dest === "string") {
  6106. explicitDest = await pdfDocument.getDestination(dest);
  6107. if (pdfDocument !== this._pdfDocument) {
  6108. return null;
  6109. }
  6110. } else {
  6111. explicitDest = dest;
  6112. }
  6113. if (Array.isArray(explicitDest)) {
  6114. const [destRef] = explicitDest;
  6115. if (destRef instanceof Object) {
  6116. pageNumber = this.linkService._cachedPageNumber(destRef);
  6117. if (!pageNumber) {
  6118. try {
  6119. pageNumber = (await pdfDocument.getPageIndex(destRef)) + 1;
  6120. if (pdfDocument !== this._pdfDocument) {
  6121. return null;
  6122. }
  6123. this.linkService.cachePageRef(pageNumber, destRef);
  6124. } catch (ex) {}
  6125. }
  6126. } else if (Number.isInteger(destRef)) {
  6127. pageNumber = destRef + 1;
  6128. }
  6129. if (Number.isInteger(pageNumber) && (!pageNumberToDestHash.has(pageNumber) || currentNesting > pageNumberNesting.get(pageNumber))) {
  6130. const destHash = this.linkService.getDestinationHash(dest);
  6131. pageNumberToDestHash.set(pageNumber, destHash);
  6132. pageNumberNesting.set(pageNumber, currentNesting);
  6133. }
  6134. }
  6135. if (items.length > 0) {
  6136. queue.push({
  6137. nesting: currentNesting + 1,
  6138. items
  6139. });
  6140. }
  6141. }
  6142. }
  6143. this._pageNumberToDestHashCapability.resolve(pageNumberToDestHash.size > 0 ? pageNumberToDestHash : null);
  6144. return this._pageNumberToDestHashCapability.promise;
  6145. }
  6146. }
  6147. exports.PDFOutlineViewer = PDFOutlineViewer;
  6148. /***/ }),
  6149. /* 21 */
  6150. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6151. Object.defineProperty(exports, "__esModule", ({
  6152. value: true
  6153. }));
  6154. exports.PDFPresentationMode = void 0;
  6155. var _ui_utils = __webpack_require__(4);
  6156. const DELAY_BEFORE_RESETTING_SWITCH_IN_PROGRESS = 1500;
  6157. const DELAY_BEFORE_HIDING_CONTROLS = 3000;
  6158. const ACTIVE_SELECTOR = "pdfPresentationMode";
  6159. const CONTROLS_SELECTOR = "pdfPresentationModeControls";
  6160. const MOUSE_SCROLL_COOLDOWN_TIME = 50;
  6161. const PAGE_SWITCH_THRESHOLD = 0.1;
  6162. const SWIPE_MIN_DISTANCE_THRESHOLD = 50;
  6163. const SWIPE_ANGLE_THRESHOLD = Math.PI / 6;
  6164. class PDFPresentationMode {
  6165. constructor({
  6166. container,
  6167. pdfViewer,
  6168. eventBus
  6169. }) {
  6170. this.container = container;
  6171. this.pdfViewer = pdfViewer;
  6172. this.eventBus = eventBus;
  6173. this.active = false;
  6174. this.args = null;
  6175. this.contextMenuOpen = false;
  6176. this.mouseScrollTimeStamp = 0;
  6177. this.mouseScrollDelta = 0;
  6178. this.touchSwipeState = null;
  6179. }
  6180. request() {
  6181. if (this.switchInProgress || this.active || !this.pdfViewer.pagesCount) {
  6182. return false;
  6183. }
  6184. this._addFullscreenChangeListeners();
  6185. this._setSwitchInProgress();
  6186. this._notifyStateChange();
  6187. if (this.container.requestFullscreen) {
  6188. this.container.requestFullscreen();
  6189. } else if (this.container.mozRequestFullScreen) {
  6190. this.container.mozRequestFullScreen();
  6191. } else if (this.container.webkitRequestFullscreen) {
  6192. this.container.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
  6193. } else {
  6194. return false;
  6195. }
  6196. this.args = {
  6197. page: this.pdfViewer.currentPageNumber,
  6198. previousScale: this.pdfViewer.currentScaleValue
  6199. };
  6200. return true;
  6201. }
  6202. _mouseWheel(evt) {
  6203. if (!this.active) {
  6204. return;
  6205. }
  6206. evt.preventDefault();
  6207. const delta = (0, _ui_utils.normalizeWheelEventDelta)(evt);
  6208. const currentTime = Date.now();
  6209. const storedTime = this.mouseScrollTimeStamp;
  6210. if (currentTime > storedTime && currentTime - storedTime < MOUSE_SCROLL_COOLDOWN_TIME) {
  6211. return;
  6212. }
  6213. if (this.mouseScrollDelta > 0 && delta < 0 || this.mouseScrollDelta < 0 && delta > 0) {
  6214. this._resetMouseScrollState();
  6215. }
  6216. this.mouseScrollDelta += delta;
  6217. if (Math.abs(this.mouseScrollDelta) >= PAGE_SWITCH_THRESHOLD) {
  6218. const totalDelta = this.mouseScrollDelta;
  6219. this._resetMouseScrollState();
  6220. const success = totalDelta > 0 ? this.pdfViewer.previousPage() : this.pdfViewer.nextPage();
  6221. if (success) {
  6222. this.mouseScrollTimeStamp = currentTime;
  6223. }
  6224. }
  6225. }
  6226. get isFullscreen() {
  6227. return !!(document.fullscreenElement || document.mozFullScreen || document.webkitIsFullScreen);
  6228. }
  6229. _notifyStateChange() {
  6230. let state = _ui_utils.PresentationModeState.NORMAL;
  6231. if (this.switchInProgress) {
  6232. state = _ui_utils.PresentationModeState.CHANGING;
  6233. } else if (this.active) {
  6234. state = _ui_utils.PresentationModeState.FULLSCREEN;
  6235. }
  6236. this.eventBus.dispatch("presentationmodechanged", {
  6237. source: this,
  6238. state,
  6239. get active() {
  6240. throw new Error("Deprecated parameter: `active`, please use `state` instead.");
  6241. },
  6242. get switchInProgress() {
  6243. throw new Error("Deprecated parameter: `switchInProgress`, please use `state` instead.");
  6244. }
  6245. });
  6246. }
  6247. _setSwitchInProgress() {
  6248. if (this.switchInProgress) {
  6249. clearTimeout(this.switchInProgress);
  6250. }
  6251. this.switchInProgress = setTimeout(() => {
  6252. this._removeFullscreenChangeListeners();
  6253. delete this.switchInProgress;
  6254. this._notifyStateChange();
  6255. }, DELAY_BEFORE_RESETTING_SWITCH_IN_PROGRESS);
  6256. }
  6257. _resetSwitchInProgress() {
  6258. if (this.switchInProgress) {
  6259. clearTimeout(this.switchInProgress);
  6260. delete this.switchInProgress;
  6261. }
  6262. }
  6263. _enter() {
  6264. this.active = true;
  6265. this._resetSwitchInProgress();
  6266. this._notifyStateChange();
  6267. this.container.classList.add(ACTIVE_SELECTOR);
  6268. setTimeout(() => {
  6269. this.pdfViewer.currentPageNumber = this.args.page;
  6270. this.pdfViewer.currentScaleValue = "page-fit";
  6271. }, 0);
  6272. this._addWindowListeners();
  6273. this._showControls();
  6274. this.contextMenuOpen = false;
  6275. window.getSelection().removeAllRanges();
  6276. }
  6277. _exit() {
  6278. const page = this.pdfViewer.currentPageNumber;
  6279. this.container.classList.remove(ACTIVE_SELECTOR);
  6280. setTimeout(() => {
  6281. this.active = false;
  6282. this._removeFullscreenChangeListeners();
  6283. this._notifyStateChange();
  6284. this.pdfViewer.currentScaleValue = this.args.previousScale;
  6285. this.pdfViewer.currentPageNumber = page;
  6286. this.args = null;
  6287. }, 0);
  6288. this._removeWindowListeners();
  6289. this._hideControls();
  6290. this._resetMouseScrollState();
  6291. this.contextMenuOpen = false;
  6292. }
  6293. _mouseDown(evt) {
  6294. if (this.contextMenuOpen) {
  6295. this.contextMenuOpen = false;
  6296. evt.preventDefault();
  6297. return;
  6298. }
  6299. if (evt.button === 0) {
  6300. const isInternalLink = evt.target.href && evt.target.classList.contains("internalLink");
  6301. if (!isInternalLink) {
  6302. evt.preventDefault();
  6303. if (evt.shiftKey) {
  6304. this.pdfViewer.previousPage();
  6305. } else {
  6306. this.pdfViewer.nextPage();
  6307. }
  6308. }
  6309. }
  6310. }
  6311. _contextMenu() {
  6312. this.contextMenuOpen = true;
  6313. }
  6314. _showControls() {
  6315. if (this.controlsTimeout) {
  6316. clearTimeout(this.controlsTimeout);
  6317. } else {
  6318. this.container.classList.add(CONTROLS_SELECTOR);
  6319. }
  6320. this.controlsTimeout = setTimeout(() => {
  6321. this.container.classList.remove(CONTROLS_SELECTOR);
  6322. delete this.controlsTimeout;
  6323. }, DELAY_BEFORE_HIDING_CONTROLS);
  6324. }
  6325. _hideControls() {
  6326. if (!this.controlsTimeout) {
  6327. return;
  6328. }
  6329. clearTimeout(this.controlsTimeout);
  6330. this.container.classList.remove(CONTROLS_SELECTOR);
  6331. delete this.controlsTimeout;
  6332. }
  6333. _resetMouseScrollState() {
  6334. this.mouseScrollTimeStamp = 0;
  6335. this.mouseScrollDelta = 0;
  6336. }
  6337. _touchSwipe(evt) {
  6338. if (!this.active) {
  6339. return;
  6340. }
  6341. if (evt.touches.length > 1) {
  6342. this.touchSwipeState = null;
  6343. return;
  6344. }
  6345. switch (evt.type) {
  6346. case "touchstart":
  6347. this.touchSwipeState = {
  6348. startX: evt.touches[0].pageX,
  6349. startY: evt.touches[0].pageY,
  6350. endX: evt.touches[0].pageX,
  6351. endY: evt.touches[0].pageY
  6352. };
  6353. break;
  6354. case "touchmove":
  6355. if (this.touchSwipeState === null) {
  6356. return;
  6357. }
  6358. this.touchSwipeState.endX = evt.touches[0].pageX;
  6359. this.touchSwipeState.endY = evt.touches[0].pageY;
  6360. evt.preventDefault();
  6361. break;
  6362. case "touchend":
  6363. if (this.touchSwipeState === null) {
  6364. return;
  6365. }
  6366. let delta = 0;
  6367. const dx = this.touchSwipeState.endX - this.touchSwipeState.startX;
  6368. const dy = this.touchSwipeState.endY - this.touchSwipeState.startY;
  6369. const absAngle = Math.abs(Math.atan2(dy, dx));
  6370. if (Math.abs(dx) > SWIPE_MIN_DISTANCE_THRESHOLD && (absAngle <= SWIPE_ANGLE_THRESHOLD || absAngle >= Math.PI - SWIPE_ANGLE_THRESHOLD)) {
  6371. delta = dx;
  6372. } else if (Math.abs(dy) > SWIPE_MIN_DISTANCE_THRESHOLD && Math.abs(absAngle - Math.PI / 2) <= SWIPE_ANGLE_THRESHOLD) {
  6373. delta = dy;
  6374. }
  6375. if (delta > 0) {
  6376. this.pdfViewer.previousPage();
  6377. } else if (delta < 0) {
  6378. this.pdfViewer.nextPage();
  6379. }
  6380. break;
  6381. }
  6382. }
  6383. _addWindowListeners() {
  6384. this.showControlsBind = this._showControls.bind(this);
  6385. this.mouseDownBind = this._mouseDown.bind(this);
  6386. this.mouseWheelBind = this._mouseWheel.bind(this);
  6387. this.resetMouseScrollStateBind = this._resetMouseScrollState.bind(this);
  6388. this.contextMenuBind = this._contextMenu.bind(this);
  6389. this.touchSwipeBind = this._touchSwipe.bind(this);
  6390. window.addEventListener("mousemove", this.showControlsBind);
  6391. window.addEventListener("mousedown", this.mouseDownBind);
  6392. window.addEventListener("wheel", this.mouseWheelBind, {
  6393. passive: false
  6394. });
  6395. window.addEventListener("keydown", this.resetMouseScrollStateBind);
  6396. window.addEventListener("contextmenu", this.contextMenuBind);
  6397. window.addEventListener("touchstart", this.touchSwipeBind);
  6398. window.addEventListener("touchmove", this.touchSwipeBind);
  6399. window.addEventListener("touchend", this.touchSwipeBind);
  6400. }
  6401. _removeWindowListeners() {
  6402. window.removeEventListener("mousemove", this.showControlsBind);
  6403. window.removeEventListener("mousedown", this.mouseDownBind);
  6404. window.removeEventListener("wheel", this.mouseWheelBind, {
  6405. passive: false
  6406. });
  6407. window.removeEventListener("keydown", this.resetMouseScrollStateBind);
  6408. window.removeEventListener("contextmenu", this.contextMenuBind);
  6409. window.removeEventListener("touchstart", this.touchSwipeBind);
  6410. window.removeEventListener("touchmove", this.touchSwipeBind);
  6411. window.removeEventListener("touchend", this.touchSwipeBind);
  6412. delete this.showControlsBind;
  6413. delete this.mouseDownBind;
  6414. delete this.mouseWheelBind;
  6415. delete this.resetMouseScrollStateBind;
  6416. delete this.contextMenuBind;
  6417. delete this.touchSwipeBind;
  6418. }
  6419. _fullscreenChange() {
  6420. if (this.isFullscreen) {
  6421. this._enter();
  6422. } else {
  6423. this._exit();
  6424. }
  6425. }
  6426. _addFullscreenChangeListeners() {
  6427. this.fullscreenChangeBind = this._fullscreenChange.bind(this);
  6428. window.addEventListener("fullscreenchange", this.fullscreenChangeBind);
  6429. window.addEventListener("mozfullscreenchange", this.fullscreenChangeBind);
  6430. window.addEventListener("webkitfullscreenchange", this.fullscreenChangeBind);
  6431. }
  6432. _removeFullscreenChangeListeners() {
  6433. window.removeEventListener("fullscreenchange", this.fullscreenChangeBind);
  6434. window.removeEventListener("mozfullscreenchange", this.fullscreenChangeBind);
  6435. window.removeEventListener("webkitfullscreenchange", this.fullscreenChangeBind);
  6436. delete this.fullscreenChangeBind;
  6437. }
  6438. }
  6439. exports.PDFPresentationMode = PDFPresentationMode;
  6440. /***/ }),
  6441. /* 22 */
  6442. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6443. Object.defineProperty(exports, "__esModule", ({
  6444. value: true
  6445. }));
  6446. exports.PDFScriptingManager = void 0;
  6447. var _pdfjsLib = __webpack_require__(5);
  6448. var _ui_utils = __webpack_require__(4);
  6449. var _pdf_rendering_queue = __webpack_require__(8);
  6450. class PDFScriptingManager {
  6451. constructor({
  6452. eventBus,
  6453. sandboxBundleSrc = null,
  6454. scriptingFactory = null,
  6455. docPropertiesLookup = null
  6456. }) {
  6457. this._pdfDocument = null;
  6458. this._pdfViewer = null;
  6459. this._closeCapability = null;
  6460. this._destroyCapability = null;
  6461. this._scripting = null;
  6462. this._mouseState = Object.create(null);
  6463. this._pageEventsReady = false;
  6464. this._ready = false;
  6465. this._eventBus = eventBus;
  6466. this._sandboxBundleSrc = sandboxBundleSrc;
  6467. this._scriptingFactory = scriptingFactory;
  6468. this._docPropertiesLookup = docPropertiesLookup;
  6469. }
  6470. setViewer(pdfViewer) {
  6471. this._pdfViewer = pdfViewer;
  6472. }
  6473. async setDocument(pdfDocument) {
  6474. if (this._pdfDocument) {
  6475. await this._destroyScripting();
  6476. }
  6477. this._pdfDocument = pdfDocument;
  6478. if (!pdfDocument) {
  6479. return;
  6480. }
  6481. const [objects, calculationOrder, docActions] = await Promise.all([pdfDocument.getFieldObjects(), pdfDocument.getCalculationOrderIds(), pdfDocument.getJSActions()]);
  6482. if (!objects && !docActions) {
  6483. await this._destroyScripting();
  6484. return;
  6485. }
  6486. if (pdfDocument !== this._pdfDocument) {
  6487. return;
  6488. }
  6489. this._scripting = this._createScripting();
  6490. this._internalEvents.set("updatefromsandbox", event => {
  6491. if (event?.source !== window) {
  6492. return;
  6493. }
  6494. this._updateFromSandbox(event.detail);
  6495. });
  6496. this._internalEvents.set("dispatcheventinsandbox", event => {
  6497. this._scripting?.dispatchEventInSandbox(event.detail);
  6498. });
  6499. this._internalEvents.set("pagechanging", ({
  6500. pageNumber,
  6501. previous
  6502. }) => {
  6503. if (pageNumber === previous) {
  6504. return;
  6505. }
  6506. this._dispatchPageClose(previous);
  6507. this._dispatchPageOpen(pageNumber);
  6508. });
  6509. this._internalEvents.set("pagerendered", ({
  6510. pageNumber
  6511. }) => {
  6512. if (!this._pageOpenPending.has(pageNumber)) {
  6513. return;
  6514. }
  6515. if (pageNumber !== this._pdfViewer.currentPageNumber) {
  6516. return;
  6517. }
  6518. this._dispatchPageOpen(pageNumber);
  6519. });
  6520. this._internalEvents.set("pagesdestroy", async event => {
  6521. await this._dispatchPageClose(this._pdfViewer.currentPageNumber);
  6522. await this._scripting?.dispatchEventInSandbox({
  6523. id: "doc",
  6524. name: "WillClose"
  6525. });
  6526. this._closeCapability?.resolve();
  6527. });
  6528. this._domEvents.set("mousedown", event => {
  6529. this._mouseState.isDown = true;
  6530. });
  6531. this._domEvents.set("mouseup", event => {
  6532. this._mouseState.isDown = false;
  6533. });
  6534. for (const [name, listener] of this._internalEvents) {
  6535. this._eventBus._on(name, listener);
  6536. }
  6537. for (const [name, listener] of this._domEvents) {
  6538. window.addEventListener(name, listener);
  6539. }
  6540. try {
  6541. const docProperties = await this._getDocProperties();
  6542. if (pdfDocument !== this._pdfDocument) {
  6543. return;
  6544. }
  6545. await this._scripting.createSandbox({
  6546. objects,
  6547. calculationOrder,
  6548. appInfo: {
  6549. platform: navigator.platform,
  6550. language: navigator.language
  6551. },
  6552. docInfo: { ...docProperties,
  6553. actions: docActions
  6554. }
  6555. });
  6556. this._eventBus.dispatch("sandboxcreated", {
  6557. source: this
  6558. });
  6559. } catch (error) {
  6560. console.error(`PDFScriptingManager.setDocument: "${error?.message}".`);
  6561. await this._destroyScripting();
  6562. return;
  6563. }
  6564. await this._scripting?.dispatchEventInSandbox({
  6565. id: "doc",
  6566. name: "Open"
  6567. });
  6568. await this._dispatchPageOpen(this._pdfViewer.currentPageNumber, true);
  6569. Promise.resolve().then(() => {
  6570. if (pdfDocument === this._pdfDocument) {
  6571. this._ready = true;
  6572. }
  6573. });
  6574. }
  6575. async dispatchWillSave(detail) {
  6576. return this._scripting?.dispatchEventInSandbox({
  6577. id: "doc",
  6578. name: "WillSave"
  6579. });
  6580. }
  6581. async dispatchDidSave(detail) {
  6582. return this._scripting?.dispatchEventInSandbox({
  6583. id: "doc",
  6584. name: "DidSave"
  6585. });
  6586. }
  6587. async dispatchWillPrint(detail) {
  6588. return this._scripting?.dispatchEventInSandbox({
  6589. id: "doc",
  6590. name: "WillPrint"
  6591. });
  6592. }
  6593. async dispatchDidPrint(detail) {
  6594. return this._scripting?.dispatchEventInSandbox({
  6595. id: "doc",
  6596. name: "DidPrint"
  6597. });
  6598. }
  6599. get mouseState() {
  6600. return this._mouseState;
  6601. }
  6602. get destroyPromise() {
  6603. return this._destroyCapability?.promise || null;
  6604. }
  6605. get ready() {
  6606. return this._ready;
  6607. }
  6608. get _internalEvents() {
  6609. return (0, _pdfjsLib.shadow)(this, "_internalEvents", new Map());
  6610. }
  6611. get _domEvents() {
  6612. return (0, _pdfjsLib.shadow)(this, "_domEvents", new Map());
  6613. }
  6614. get _pageOpenPending() {
  6615. return (0, _pdfjsLib.shadow)(this, "_pageOpenPending", new Set());
  6616. }
  6617. get _visitedPages() {
  6618. return (0, _pdfjsLib.shadow)(this, "_visitedPages", new Map());
  6619. }
  6620. async _updateFromSandbox(detail) {
  6621. const isInPresentationMode = this._pdfViewer.isInPresentationMode || this._pdfViewer.isChangingPresentationMode;
  6622. const {
  6623. id,
  6624. command,
  6625. value
  6626. } = detail;
  6627. if (!id) {
  6628. switch (command) {
  6629. case "clear":
  6630. console.clear();
  6631. break;
  6632. case "error":
  6633. console.error(value);
  6634. break;
  6635. case "layout":
  6636. this._pdfViewer.spreadMode = (0, _ui_utils.apiPageLayoutToSpreadMode)(value);
  6637. break;
  6638. case "page-num":
  6639. this._pdfViewer.currentPageNumber = value + 1;
  6640. break;
  6641. case "print":
  6642. await this._pdfViewer.pagesPromise;
  6643. this._eventBus.dispatch("print", {
  6644. source: this
  6645. });
  6646. break;
  6647. case "println":
  6648. console.log(value);
  6649. break;
  6650. case "zoom":
  6651. if (isInPresentationMode) {
  6652. return;
  6653. }
  6654. this._pdfViewer.currentScaleValue = value;
  6655. break;
  6656. }
  6657. return;
  6658. }
  6659. if (isInPresentationMode) {
  6660. if (detail.focus) {
  6661. return;
  6662. }
  6663. }
  6664. const element = document.getElementById(id);
  6665. if (element) {
  6666. element.dispatchEvent(new CustomEvent("updatefromsandbox", {
  6667. detail
  6668. }));
  6669. } else {
  6670. delete detail.id;
  6671. this._pdfDocument?.annotationStorage.setValue(id, detail);
  6672. }
  6673. }
  6674. async _dispatchPageOpen(pageNumber, initialize = false) {
  6675. const pdfDocument = this._pdfDocument,
  6676. visitedPages = this._visitedPages;
  6677. if (initialize) {
  6678. this._closeCapability = (0, _pdfjsLib.createPromiseCapability)();
  6679. this._pageEventsReady = true;
  6680. }
  6681. if (!this._pageEventsReady) {
  6682. return;
  6683. }
  6684. const pageView = this._pdfViewer.getPageView(pageNumber - 1);
  6685. if (pageView?.renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED) {
  6686. this._pageOpenPending.add(pageNumber);
  6687. return;
  6688. }
  6689. this._pageOpenPending.delete(pageNumber);
  6690. const actionsPromise = (async () => {
  6691. const actions = await (!visitedPages.has(pageNumber) ? pageView.pdfPage?.getJSActions() : null);
  6692. if (pdfDocument !== this._pdfDocument) {
  6693. return;
  6694. }
  6695. await this._scripting?.dispatchEventInSandbox({
  6696. id: "page",
  6697. name: "PageOpen",
  6698. pageNumber,
  6699. actions
  6700. });
  6701. })();
  6702. visitedPages.set(pageNumber, actionsPromise);
  6703. }
  6704. async _dispatchPageClose(pageNumber) {
  6705. const pdfDocument = this._pdfDocument,
  6706. visitedPages = this._visitedPages;
  6707. if (!this._pageEventsReady) {
  6708. return;
  6709. }
  6710. if (this._pageOpenPending.has(pageNumber)) {
  6711. return;
  6712. }
  6713. const actionsPromise = visitedPages.get(pageNumber);
  6714. if (!actionsPromise) {
  6715. return;
  6716. }
  6717. visitedPages.set(pageNumber, null);
  6718. await actionsPromise;
  6719. if (pdfDocument !== this._pdfDocument) {
  6720. return;
  6721. }
  6722. await this._scripting?.dispatchEventInSandbox({
  6723. id: "page",
  6724. name: "PageClose",
  6725. pageNumber
  6726. });
  6727. }
  6728. async _getDocProperties() {
  6729. if (this._docPropertiesLookup) {
  6730. return this._docPropertiesLookup(this._pdfDocument);
  6731. }
  6732. throw new Error("_getDocProperties: Unable to lookup properties.");
  6733. }
  6734. _createScripting() {
  6735. this._destroyCapability = (0, _pdfjsLib.createPromiseCapability)();
  6736. if (this._scripting) {
  6737. throw new Error("_createScripting: Scripting already exists.");
  6738. }
  6739. if (this._scriptingFactory) {
  6740. return this._scriptingFactory.createScripting({
  6741. sandboxBundleSrc: this._sandboxBundleSrc
  6742. });
  6743. }
  6744. throw new Error("_createScripting: Cannot create scripting.");
  6745. }
  6746. async _destroyScripting() {
  6747. if (!this._scripting) {
  6748. this._pdfDocument = null;
  6749. this._destroyCapability?.resolve();
  6750. return;
  6751. }
  6752. if (this._closeCapability) {
  6753. await Promise.race([this._closeCapability.promise, new Promise(resolve => {
  6754. setTimeout(resolve, 1000);
  6755. })]).catch(reason => {});
  6756. this._closeCapability = null;
  6757. }
  6758. this._pdfDocument = null;
  6759. try {
  6760. await this._scripting.destroySandbox();
  6761. } catch (ex) {}
  6762. for (const [name, listener] of this._internalEvents) {
  6763. this._eventBus._off(name, listener);
  6764. }
  6765. this._internalEvents.clear();
  6766. for (const [name, listener] of this._domEvents) {
  6767. window.removeEventListener(name, listener);
  6768. }
  6769. this._domEvents.clear();
  6770. this._pageOpenPending.clear();
  6771. this._visitedPages.clear();
  6772. this._scripting = null;
  6773. delete this._mouseState.isDown;
  6774. this._pageEventsReady = false;
  6775. this._ready = false;
  6776. this._destroyCapability?.resolve();
  6777. }
  6778. }
  6779. exports.PDFScriptingManager = PDFScriptingManager;
  6780. /***/ }),
  6781. /* 23 */
  6782. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6783. Object.defineProperty(exports, "__esModule", ({
  6784. value: true
  6785. }));
  6786. exports.PDFSidebar = void 0;
  6787. var _ui_utils = __webpack_require__(4);
  6788. var _pdf_rendering_queue = __webpack_require__(8);
  6789. const UI_NOTIFICATION_CLASS = "pdfSidebarNotification";
  6790. class PDFSidebar {
  6791. constructor({
  6792. elements,
  6793. pdfViewer,
  6794. pdfThumbnailViewer,
  6795. eventBus,
  6796. l10n
  6797. }) {
  6798. this.isOpen = false;
  6799. this.active = _ui_utils.SidebarView.THUMBS;
  6800. this.isInitialViewSet = false;
  6801. this.onToggled = null;
  6802. this.pdfViewer = pdfViewer;
  6803. this.pdfThumbnailViewer = pdfThumbnailViewer;
  6804. this.outerContainer = elements.outerContainer;
  6805. this.viewerContainer = elements.viewerContainer;
  6806. this.toggleButton = elements.toggleButton;
  6807. this.thumbnailButton = elements.thumbnailButton;
  6808. this.outlineButton = elements.outlineButton;
  6809. this.attachmentsButton = elements.attachmentsButton;
  6810. this.layersButton = elements.layersButton;
  6811. this.thumbnailView = elements.thumbnailView;
  6812. this.outlineView = elements.outlineView;
  6813. this.attachmentsView = elements.attachmentsView;
  6814. this.layersView = elements.layersView;
  6815. this._outlineOptionsContainer = elements.outlineOptionsContainer;
  6816. this._currentOutlineItemButton = elements.currentOutlineItemButton;
  6817. this.eventBus = eventBus;
  6818. this.l10n = l10n;
  6819. this._addEventListeners();
  6820. }
  6821. reset() {
  6822. this.isInitialViewSet = false;
  6823. this._hideUINotification(true);
  6824. this.switchView(_ui_utils.SidebarView.THUMBS);
  6825. this.outlineButton.disabled = false;
  6826. this.attachmentsButton.disabled = false;
  6827. this.layersButton.disabled = false;
  6828. this._currentOutlineItemButton.disabled = true;
  6829. }
  6830. get visibleView() {
  6831. return this.isOpen ? this.active : _ui_utils.SidebarView.NONE;
  6832. }
  6833. get isThumbnailViewVisible() {
  6834. return this.isOpen && this.active === _ui_utils.SidebarView.THUMBS;
  6835. }
  6836. get isOutlineViewVisible() {
  6837. return this.isOpen && this.active === _ui_utils.SidebarView.OUTLINE;
  6838. }
  6839. get isAttachmentsViewVisible() {
  6840. return this.isOpen && this.active === _ui_utils.SidebarView.ATTACHMENTS;
  6841. }
  6842. get isLayersViewVisible() {
  6843. return this.isOpen && this.active === _ui_utils.SidebarView.LAYERS;
  6844. }
  6845. setInitialView(view = _ui_utils.SidebarView.NONE) {
  6846. if (this.isInitialViewSet) {
  6847. return;
  6848. }
  6849. this.isInitialViewSet = true;
  6850. if (view === _ui_utils.SidebarView.NONE || view === _ui_utils.SidebarView.UNKNOWN) {
  6851. this._dispatchEvent();
  6852. return;
  6853. }
  6854. if (!this._switchView(view, true)) {
  6855. this._dispatchEvent();
  6856. }
  6857. }
  6858. switchView(view, forceOpen = false) {
  6859. this._switchView(view, forceOpen);
  6860. }
  6861. _switchView(view, forceOpen = false) {
  6862. const isViewChanged = view !== this.active;
  6863. let shouldForceRendering = false;
  6864. switch (view) {
  6865. case _ui_utils.SidebarView.NONE:
  6866. if (this.isOpen) {
  6867. this.close();
  6868. return true;
  6869. }
  6870. return false;
  6871. case _ui_utils.SidebarView.THUMBS:
  6872. if (this.isOpen && isViewChanged) {
  6873. shouldForceRendering = true;
  6874. }
  6875. break;
  6876. case _ui_utils.SidebarView.OUTLINE:
  6877. if (this.outlineButton.disabled) {
  6878. return false;
  6879. }
  6880. break;
  6881. case _ui_utils.SidebarView.ATTACHMENTS:
  6882. if (this.attachmentsButton.disabled) {
  6883. return false;
  6884. }
  6885. break;
  6886. case _ui_utils.SidebarView.LAYERS:
  6887. if (this.layersButton.disabled) {
  6888. return false;
  6889. }
  6890. break;
  6891. default:
  6892. console.error(`PDFSidebar._switchView: "${view}" is not a valid view.`);
  6893. return false;
  6894. }
  6895. this.active = view;
  6896. this.thumbnailButton.classList.toggle("toggled", view === _ui_utils.SidebarView.THUMBS);
  6897. this.outlineButton.classList.toggle("toggled", view === _ui_utils.SidebarView.OUTLINE);
  6898. this.attachmentsButton.classList.toggle("toggled", view === _ui_utils.SidebarView.ATTACHMENTS);
  6899. this.layersButton.classList.toggle("toggled", view === _ui_utils.SidebarView.LAYERS);
  6900. this.thumbnailView.classList.toggle("hidden", view !== _ui_utils.SidebarView.THUMBS);
  6901. this.outlineView.classList.toggle("hidden", view !== _ui_utils.SidebarView.OUTLINE);
  6902. this.attachmentsView.classList.toggle("hidden", view !== _ui_utils.SidebarView.ATTACHMENTS);
  6903. this.layersView.classList.toggle("hidden", view !== _ui_utils.SidebarView.LAYERS);
  6904. this._outlineOptionsContainer.classList.toggle("hidden", view !== _ui_utils.SidebarView.OUTLINE);
  6905. if (forceOpen && !this.isOpen) {
  6906. this.open();
  6907. return true;
  6908. }
  6909. if (shouldForceRendering) {
  6910. this._updateThumbnailViewer();
  6911. this._forceRendering();
  6912. }
  6913. if (isViewChanged) {
  6914. this._dispatchEvent();
  6915. }
  6916. return isViewChanged;
  6917. }
  6918. open() {
  6919. if (this.isOpen) {
  6920. return;
  6921. }
  6922. this.isOpen = true;
  6923. this.toggleButton.classList.add("toggled");
  6924. this.toggleButton.setAttribute("aria-expanded", "true");
  6925. this.outerContainer.classList.add("sidebarMoving", "sidebarOpen");
  6926. if (this.active === _ui_utils.SidebarView.THUMBS) {
  6927. this._updateThumbnailViewer();
  6928. }
  6929. this._forceRendering();
  6930. this._dispatchEvent();
  6931. this._hideUINotification();
  6932. }
  6933. close() {
  6934. if (!this.isOpen) {
  6935. return;
  6936. }
  6937. this.isOpen = false;
  6938. this.toggleButton.classList.remove("toggled");
  6939. this.toggleButton.setAttribute("aria-expanded", "false");
  6940. this.outerContainer.classList.add("sidebarMoving");
  6941. this.outerContainer.classList.remove("sidebarOpen");
  6942. this._forceRendering();
  6943. this._dispatchEvent();
  6944. }
  6945. toggle() {
  6946. if (this.isOpen) {
  6947. this.close();
  6948. } else {
  6949. this.open();
  6950. }
  6951. }
  6952. _dispatchEvent() {
  6953. this.eventBus.dispatch("sidebarviewchanged", {
  6954. source: this,
  6955. view: this.visibleView
  6956. });
  6957. }
  6958. _forceRendering() {
  6959. if (this.onToggled) {
  6960. this.onToggled();
  6961. } else {
  6962. this.pdfViewer.forceRendering();
  6963. this.pdfThumbnailViewer.forceRendering();
  6964. }
  6965. }
  6966. _updateThumbnailViewer() {
  6967. const {
  6968. pdfViewer,
  6969. pdfThumbnailViewer
  6970. } = this;
  6971. const pagesCount = pdfViewer.pagesCount;
  6972. for (let pageIndex = 0; pageIndex < pagesCount; pageIndex++) {
  6973. const pageView = pdfViewer.getPageView(pageIndex);
  6974. if (pageView?.renderingState === _pdf_rendering_queue.RenderingStates.FINISHED) {
  6975. const thumbnailView = pdfThumbnailViewer.getThumbnail(pageIndex);
  6976. thumbnailView.setImage(pageView);
  6977. }
  6978. }
  6979. pdfThumbnailViewer.scrollThumbnailIntoView(pdfViewer.currentPageNumber);
  6980. }
  6981. _showUINotification() {
  6982. this.l10n.get("toggle_sidebar_notification2.title").then(msg => {
  6983. this.toggleButton.title = msg;
  6984. });
  6985. if (!this.isOpen) {
  6986. this.toggleButton.classList.add(UI_NOTIFICATION_CLASS);
  6987. }
  6988. }
  6989. _hideUINotification(reset = false) {
  6990. if (this.isOpen || reset) {
  6991. this.toggleButton.classList.remove(UI_NOTIFICATION_CLASS);
  6992. }
  6993. if (reset) {
  6994. this.l10n.get("toggle_sidebar.title").then(msg => {
  6995. this.toggleButton.title = msg;
  6996. });
  6997. }
  6998. }
  6999. _addEventListeners() {
  7000. this.viewerContainer.addEventListener("transitionend", evt => {
  7001. if (evt.target === this.viewerContainer) {
  7002. this.outerContainer.classList.remove("sidebarMoving");
  7003. }
  7004. });
  7005. this.toggleButton.addEventListener("click", () => {
  7006. this.toggle();
  7007. });
  7008. this.thumbnailButton.addEventListener("click", () => {
  7009. this.switchView(_ui_utils.SidebarView.THUMBS);
  7010. });
  7011. this.outlineButton.addEventListener("click", () => {
  7012. this.switchView(_ui_utils.SidebarView.OUTLINE);
  7013. });
  7014. this.outlineButton.addEventListener("dblclick", () => {
  7015. this.eventBus.dispatch("toggleoutlinetree", {
  7016. source: this
  7017. });
  7018. });
  7019. this.attachmentsButton.addEventListener("click", () => {
  7020. this.switchView(_ui_utils.SidebarView.ATTACHMENTS);
  7021. });
  7022. this.layersButton.addEventListener("click", () => {
  7023. this.switchView(_ui_utils.SidebarView.LAYERS);
  7024. });
  7025. this.layersButton.addEventListener("dblclick", () => {
  7026. this.eventBus.dispatch("resetlayers", {
  7027. source: this
  7028. });
  7029. });
  7030. this._currentOutlineItemButton.addEventListener("click", () => {
  7031. this.eventBus.dispatch("currentoutlineitem", {
  7032. source: this
  7033. });
  7034. });
  7035. const onTreeLoaded = (count, button, view) => {
  7036. button.disabled = !count;
  7037. if (count) {
  7038. this._showUINotification();
  7039. } else if (this.active === view) {
  7040. this.switchView(_ui_utils.SidebarView.THUMBS);
  7041. }
  7042. };
  7043. this.eventBus._on("outlineloaded", evt => {
  7044. onTreeLoaded(evt.outlineCount, this.outlineButton, _ui_utils.SidebarView.OUTLINE);
  7045. if (evt.enableCurrentOutlineItemButton) {
  7046. this.pdfViewer.pagesPromise.then(() => {
  7047. this._currentOutlineItemButton.disabled = !this.isInitialViewSet;
  7048. });
  7049. }
  7050. });
  7051. this.eventBus._on("attachmentsloaded", evt => {
  7052. onTreeLoaded(evt.attachmentsCount, this.attachmentsButton, _ui_utils.SidebarView.ATTACHMENTS);
  7053. });
  7054. this.eventBus._on("layersloaded", evt => {
  7055. onTreeLoaded(evt.layersCount, this.layersButton, _ui_utils.SidebarView.LAYERS);
  7056. });
  7057. this.eventBus._on("presentationmodechanged", evt => {
  7058. if (evt.state === _ui_utils.PresentationModeState.NORMAL && this.isThumbnailViewVisible) {
  7059. this._updateThumbnailViewer();
  7060. }
  7061. });
  7062. }
  7063. }
  7064. exports.PDFSidebar = PDFSidebar;
  7065. /***/ }),
  7066. /* 24 */
  7067. /***/ ((__unused_webpack_module, exports) => {
  7068. Object.defineProperty(exports, "__esModule", ({
  7069. value: true
  7070. }));
  7071. exports.PDFSidebarResizer = void 0;
  7072. const SIDEBAR_WIDTH_VAR = "--sidebar-width";
  7073. const SIDEBAR_MIN_WIDTH = 200;
  7074. const SIDEBAR_RESIZING_CLASS = "sidebarResizing";
  7075. class PDFSidebarResizer {
  7076. constructor(options, eventBus, l10n) {
  7077. this.isRTL = false;
  7078. this.sidebarOpen = false;
  7079. this.doc = document.documentElement;
  7080. this._width = null;
  7081. this._outerContainerWidth = null;
  7082. this._boundEvents = Object.create(null);
  7083. this.outerContainer = options.outerContainer;
  7084. this.resizer = options.resizer;
  7085. this.eventBus = eventBus;
  7086. l10n.getDirection().then(dir => {
  7087. this.isRTL = dir === "rtl";
  7088. });
  7089. this._addEventListeners();
  7090. }
  7091. get outerContainerWidth() {
  7092. return this._outerContainerWidth || (this._outerContainerWidth = this.outerContainer.clientWidth);
  7093. }
  7094. _updateWidth(width = 0) {
  7095. const maxWidth = Math.floor(this.outerContainerWidth / 2);
  7096. if (width > maxWidth) {
  7097. width = maxWidth;
  7098. }
  7099. if (width < SIDEBAR_MIN_WIDTH) {
  7100. width = SIDEBAR_MIN_WIDTH;
  7101. }
  7102. if (width === this._width) {
  7103. return false;
  7104. }
  7105. this._width = width;
  7106. this.doc.style.setProperty(SIDEBAR_WIDTH_VAR, `${width}px`);
  7107. return true;
  7108. }
  7109. _mouseMove(evt) {
  7110. let width = evt.clientX;
  7111. if (this.isRTL) {
  7112. width = this.outerContainerWidth - width;
  7113. }
  7114. this._updateWidth(width);
  7115. }
  7116. _mouseUp(evt) {
  7117. this.outerContainer.classList.remove(SIDEBAR_RESIZING_CLASS);
  7118. this.eventBus.dispatch("resize", {
  7119. source: this
  7120. });
  7121. const _boundEvents = this._boundEvents;
  7122. window.removeEventListener("mousemove", _boundEvents.mouseMove);
  7123. window.removeEventListener("mouseup", _boundEvents.mouseUp);
  7124. }
  7125. _addEventListeners() {
  7126. const _boundEvents = this._boundEvents;
  7127. _boundEvents.mouseMove = this._mouseMove.bind(this);
  7128. _boundEvents.mouseUp = this._mouseUp.bind(this);
  7129. this.resizer.addEventListener("mousedown", evt => {
  7130. if (evt.button !== 0) {
  7131. return;
  7132. }
  7133. this.outerContainer.classList.add(SIDEBAR_RESIZING_CLASS);
  7134. window.addEventListener("mousemove", _boundEvents.mouseMove);
  7135. window.addEventListener("mouseup", _boundEvents.mouseUp);
  7136. });
  7137. this.eventBus._on("sidebarviewchanged", evt => {
  7138. this.sidebarOpen = !!evt?.view;
  7139. });
  7140. this.eventBus._on("resize", evt => {
  7141. if (evt?.source !== window) {
  7142. return;
  7143. }
  7144. this._outerContainerWidth = null;
  7145. if (!this._width) {
  7146. return;
  7147. }
  7148. if (!this.sidebarOpen) {
  7149. this._updateWidth(this._width);
  7150. return;
  7151. }
  7152. this.outerContainer.classList.add(SIDEBAR_RESIZING_CLASS);
  7153. const updated = this._updateWidth(this._width);
  7154. Promise.resolve().then(() => {
  7155. this.outerContainer.classList.remove(SIDEBAR_RESIZING_CLASS);
  7156. if (updated) {
  7157. this.eventBus.dispatch("resize", {
  7158. source: this
  7159. });
  7160. }
  7161. });
  7162. });
  7163. }
  7164. }
  7165. exports.PDFSidebarResizer = PDFSidebarResizer;
  7166. /***/ }),
  7167. /* 25 */
  7168. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7169. Object.defineProperty(exports, "__esModule", ({
  7170. value: true
  7171. }));
  7172. exports.PDFThumbnailViewer = void 0;
  7173. var _ui_utils = __webpack_require__(4);
  7174. var _pdf_thumbnail_view = __webpack_require__(26);
  7175. var _pdf_rendering_queue = __webpack_require__(8);
  7176. const THUMBNAIL_SCROLL_MARGIN = -19;
  7177. const THUMBNAIL_SELECTED_CLASS = "selected";
  7178. class PDFThumbnailViewer {
  7179. constructor({
  7180. container,
  7181. eventBus,
  7182. linkService,
  7183. renderingQueue,
  7184. l10n
  7185. }) {
  7186. this.container = container;
  7187. this.linkService = linkService;
  7188. this.renderingQueue = renderingQueue;
  7189. this.l10n = l10n;
  7190. this.scroll = (0, _ui_utils.watchScroll)(this.container, this._scrollUpdated.bind(this));
  7191. this._resetView();
  7192. eventBus._on("optionalcontentconfigchanged", () => {
  7193. this._setImageDisabled = true;
  7194. });
  7195. }
  7196. _scrollUpdated() {
  7197. this.renderingQueue.renderHighestPriority();
  7198. }
  7199. getThumbnail(index) {
  7200. return this._thumbnails[index];
  7201. }
  7202. _getVisibleThumbs() {
  7203. return (0, _ui_utils.getVisibleElements)({
  7204. scrollEl: this.container,
  7205. views: this._thumbnails
  7206. });
  7207. }
  7208. scrollThumbnailIntoView(pageNumber) {
  7209. if (!this.pdfDocument) {
  7210. return;
  7211. }
  7212. const thumbnailView = this._thumbnails[pageNumber - 1];
  7213. if (!thumbnailView) {
  7214. console.error('scrollThumbnailIntoView: Invalid "pageNumber" parameter.');
  7215. return;
  7216. }
  7217. if (pageNumber !== this._currentPageNumber) {
  7218. const prevThumbnailView = this._thumbnails[this._currentPageNumber - 1];
  7219. prevThumbnailView.div.classList.remove(THUMBNAIL_SELECTED_CLASS);
  7220. thumbnailView.div.classList.add(THUMBNAIL_SELECTED_CLASS);
  7221. }
  7222. const visibleThumbs = this._getVisibleThumbs();
  7223. const numVisibleThumbs = visibleThumbs.views.length;
  7224. if (numVisibleThumbs > 0) {
  7225. const first = visibleThumbs.first.id;
  7226. const last = numVisibleThumbs > 1 ? visibleThumbs.last.id : first;
  7227. let shouldScroll = false;
  7228. if (pageNumber <= first || pageNumber >= last) {
  7229. shouldScroll = true;
  7230. } else {
  7231. visibleThumbs.views.some(function (view) {
  7232. if (view.id !== pageNumber) {
  7233. return false;
  7234. }
  7235. shouldScroll = view.percent < 100;
  7236. return true;
  7237. });
  7238. }
  7239. if (shouldScroll) {
  7240. (0, _ui_utils.scrollIntoView)(thumbnailView.div, {
  7241. top: THUMBNAIL_SCROLL_MARGIN
  7242. });
  7243. }
  7244. }
  7245. this._currentPageNumber = pageNumber;
  7246. }
  7247. get pagesRotation() {
  7248. return this._pagesRotation;
  7249. }
  7250. set pagesRotation(rotation) {
  7251. if (!(0, _ui_utils.isValidRotation)(rotation)) {
  7252. throw new Error("Invalid thumbnails rotation angle.");
  7253. }
  7254. if (!this.pdfDocument) {
  7255. return;
  7256. }
  7257. if (this._pagesRotation === rotation) {
  7258. return;
  7259. }
  7260. this._pagesRotation = rotation;
  7261. for (let i = 0, ii = this._thumbnails.length; i < ii; i++) {
  7262. this._thumbnails[i].update(rotation);
  7263. }
  7264. }
  7265. cleanup() {
  7266. for (let i = 0, ii = this._thumbnails.length; i < ii; i++) {
  7267. if (this._thumbnails[i] && this._thumbnails[i].renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED) {
  7268. this._thumbnails[i].reset();
  7269. }
  7270. }
  7271. _pdf_thumbnail_view.TempImageFactory.destroyCanvas();
  7272. }
  7273. _resetView() {
  7274. this._thumbnails = [];
  7275. this._currentPageNumber = 1;
  7276. this._pageLabels = null;
  7277. this._pagesRotation = 0;
  7278. this._optionalContentConfigPromise = null;
  7279. this._pagesRequests = new WeakMap();
  7280. this._setImageDisabled = false;
  7281. this.container.textContent = "";
  7282. }
  7283. setDocument(pdfDocument) {
  7284. if (this.pdfDocument) {
  7285. this._cancelRendering();
  7286. this._resetView();
  7287. }
  7288. this.pdfDocument = pdfDocument;
  7289. if (!pdfDocument) {
  7290. return;
  7291. }
  7292. const firstPagePromise = pdfDocument.getPage(1);
  7293. const optionalContentConfigPromise = pdfDocument.getOptionalContentConfig();
  7294. firstPagePromise.then(firstPdfPage => {
  7295. this._optionalContentConfigPromise = optionalContentConfigPromise;
  7296. const pagesCount = pdfDocument.numPages;
  7297. const viewport = firstPdfPage.getViewport({
  7298. scale: 1
  7299. });
  7300. const checkSetImageDisabled = () => {
  7301. return this._setImageDisabled;
  7302. };
  7303. for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) {
  7304. const thumbnail = new _pdf_thumbnail_view.PDFThumbnailView({
  7305. container: this.container,
  7306. id: pageNum,
  7307. defaultViewport: viewport.clone(),
  7308. optionalContentConfigPromise,
  7309. linkService: this.linkService,
  7310. renderingQueue: this.renderingQueue,
  7311. checkSetImageDisabled,
  7312. disableCanvasToImageConversion: false,
  7313. l10n: this.l10n
  7314. });
  7315. this._thumbnails.push(thumbnail);
  7316. }
  7317. const firstThumbnailView = this._thumbnails[0];
  7318. if (firstThumbnailView) {
  7319. firstThumbnailView.setPdfPage(firstPdfPage);
  7320. }
  7321. const thumbnailView = this._thumbnails[this._currentPageNumber - 1];
  7322. thumbnailView.div.classList.add(THUMBNAIL_SELECTED_CLASS);
  7323. }).catch(reason => {
  7324. console.error("Unable to initialize thumbnail viewer", reason);
  7325. });
  7326. }
  7327. _cancelRendering() {
  7328. for (let i = 0, ii = this._thumbnails.length; i < ii; i++) {
  7329. if (this._thumbnails[i]) {
  7330. this._thumbnails[i].cancelRendering();
  7331. }
  7332. }
  7333. }
  7334. setPageLabels(labels) {
  7335. if (!this.pdfDocument) {
  7336. return;
  7337. }
  7338. if (!labels) {
  7339. this._pageLabels = null;
  7340. } else if (!(Array.isArray(labels) && this.pdfDocument.numPages === labels.length)) {
  7341. this._pageLabels = null;
  7342. console.error("PDFThumbnailViewer_setPageLabels: Invalid page labels.");
  7343. } else {
  7344. this._pageLabels = labels;
  7345. }
  7346. for (let i = 0, ii = this._thumbnails.length; i < ii; i++) {
  7347. this._thumbnails[i].setPageLabel(this._pageLabels?.[i] ?? null);
  7348. }
  7349. }
  7350. _ensurePdfPageLoaded(thumbView) {
  7351. if (thumbView.pdfPage) {
  7352. return Promise.resolve(thumbView.pdfPage);
  7353. }
  7354. if (this._pagesRequests.has(thumbView)) {
  7355. return this._pagesRequests.get(thumbView);
  7356. }
  7357. const promise = this.pdfDocument.getPage(thumbView.id).then(pdfPage => {
  7358. if (!thumbView.pdfPage) {
  7359. thumbView.setPdfPage(pdfPage);
  7360. }
  7361. this._pagesRequests.delete(thumbView);
  7362. return pdfPage;
  7363. }).catch(reason => {
  7364. console.error("Unable to get page for thumb view", reason);
  7365. this._pagesRequests.delete(thumbView);
  7366. });
  7367. this._pagesRequests.set(thumbView, promise);
  7368. return promise;
  7369. }
  7370. forceRendering() {
  7371. const visibleThumbs = this._getVisibleThumbs();
  7372. const thumbView = this.renderingQueue.getHighestPriority(visibleThumbs, this._thumbnails, this.scroll.down);
  7373. if (thumbView) {
  7374. this._ensurePdfPageLoaded(thumbView).then(() => {
  7375. this.renderingQueue.renderView(thumbView);
  7376. });
  7377. return true;
  7378. }
  7379. return false;
  7380. }
  7381. }
  7382. exports.PDFThumbnailViewer = PDFThumbnailViewer;
  7383. /***/ }),
  7384. /* 26 */
  7385. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7386. Object.defineProperty(exports, "__esModule", ({
  7387. value: true
  7388. }));
  7389. exports.TempImageFactory = exports.PDFThumbnailView = void 0;
  7390. var _ui_utils = __webpack_require__(4);
  7391. var _pdfjsLib = __webpack_require__(5);
  7392. var _pdf_rendering_queue = __webpack_require__(8);
  7393. const MAX_NUM_SCALING_STEPS = 3;
  7394. const THUMBNAIL_CANVAS_BORDER_WIDTH = 1;
  7395. const THUMBNAIL_WIDTH = 98;
  7396. const TempImageFactory = function TempImageFactoryClosure() {
  7397. let tempCanvasCache = null;
  7398. return {
  7399. getCanvas(width, height) {
  7400. let tempCanvas = tempCanvasCache;
  7401. if (!tempCanvas) {
  7402. tempCanvas = document.createElement("canvas");
  7403. tempCanvasCache = tempCanvas;
  7404. }
  7405. tempCanvas.width = width;
  7406. tempCanvas.height = height;
  7407. tempCanvas.mozOpaque = true;
  7408. const ctx = tempCanvas.getContext("2d", {
  7409. alpha: false
  7410. });
  7411. ctx.save();
  7412. ctx.fillStyle = "rgb(255, 255, 255)";
  7413. ctx.fillRect(0, 0, width, height);
  7414. ctx.restore();
  7415. return tempCanvas;
  7416. },
  7417. destroyCanvas() {
  7418. const tempCanvas = tempCanvasCache;
  7419. if (tempCanvas) {
  7420. tempCanvas.width = 0;
  7421. tempCanvas.height = 0;
  7422. }
  7423. tempCanvasCache = null;
  7424. }
  7425. };
  7426. }();
  7427. exports.TempImageFactory = TempImageFactory;
  7428. class PDFThumbnailView {
  7429. constructor({
  7430. container,
  7431. id,
  7432. defaultViewport,
  7433. optionalContentConfigPromise,
  7434. linkService,
  7435. renderingQueue,
  7436. checkSetImageDisabled,
  7437. disableCanvasToImageConversion = false,
  7438. l10n
  7439. }) {
  7440. this.id = id;
  7441. this.renderingId = "thumbnail" + id;
  7442. this.pageLabel = null;
  7443. this.pdfPage = null;
  7444. this.rotation = 0;
  7445. this.viewport = defaultViewport;
  7446. this.pdfPageRotate = defaultViewport.rotation;
  7447. this._optionalContentConfigPromise = optionalContentConfigPromise || null;
  7448. this.linkService = linkService;
  7449. this.renderingQueue = renderingQueue;
  7450. this.renderTask = null;
  7451. this.renderingState = _pdf_rendering_queue.RenderingStates.INITIAL;
  7452. this.resume = null;
  7453. this._checkSetImageDisabled = checkSetImageDisabled || function () {
  7454. return false;
  7455. };
  7456. this.disableCanvasToImageConversion = disableCanvasToImageConversion;
  7457. this.pageWidth = this.viewport.width;
  7458. this.pageHeight = this.viewport.height;
  7459. this.pageRatio = this.pageWidth / this.pageHeight;
  7460. this.canvasWidth = THUMBNAIL_WIDTH;
  7461. this.canvasHeight = this.canvasWidth / this.pageRatio | 0;
  7462. this.scale = this.canvasWidth / this.pageWidth;
  7463. this.l10n = l10n;
  7464. const anchor = document.createElement("a");
  7465. anchor.href = linkService.getAnchorUrl("#page=" + id);
  7466. this._thumbPageTitle.then(msg => {
  7467. anchor.title = msg;
  7468. });
  7469. anchor.onclick = function () {
  7470. linkService.goToPage(id);
  7471. return false;
  7472. };
  7473. this.anchor = anchor;
  7474. const div = document.createElement("div");
  7475. div.className = "thumbnail";
  7476. div.setAttribute("data-page-number", this.id);
  7477. this.div = div;
  7478. const ring = document.createElement("div");
  7479. ring.className = "thumbnailSelectionRing";
  7480. const borderAdjustment = 2 * THUMBNAIL_CANVAS_BORDER_WIDTH;
  7481. ring.style.width = this.canvasWidth + borderAdjustment + "px";
  7482. ring.style.height = this.canvasHeight + borderAdjustment + "px";
  7483. this.ring = ring;
  7484. div.appendChild(ring);
  7485. anchor.appendChild(div);
  7486. container.appendChild(anchor);
  7487. }
  7488. setPdfPage(pdfPage) {
  7489. this.pdfPage = pdfPage;
  7490. this.pdfPageRotate = pdfPage.rotate;
  7491. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  7492. this.viewport = pdfPage.getViewport({
  7493. scale: 1,
  7494. rotation: totalRotation
  7495. });
  7496. this.reset();
  7497. }
  7498. reset() {
  7499. this.cancelRendering();
  7500. this.renderingState = _pdf_rendering_queue.RenderingStates.INITIAL;
  7501. this.pageWidth = this.viewport.width;
  7502. this.pageHeight = this.viewport.height;
  7503. this.pageRatio = this.pageWidth / this.pageHeight;
  7504. this.canvasHeight = this.canvasWidth / this.pageRatio | 0;
  7505. this.scale = this.canvasWidth / this.pageWidth;
  7506. this.div.removeAttribute("data-loaded");
  7507. const ring = this.ring;
  7508. const childNodes = ring.childNodes;
  7509. for (let i = childNodes.length - 1; i >= 0; i--) {
  7510. ring.removeChild(childNodes[i]);
  7511. }
  7512. const borderAdjustment = 2 * THUMBNAIL_CANVAS_BORDER_WIDTH;
  7513. ring.style.width = this.canvasWidth + borderAdjustment + "px";
  7514. ring.style.height = this.canvasHeight + borderAdjustment + "px";
  7515. if (this.canvas) {
  7516. this.canvas.width = 0;
  7517. this.canvas.height = 0;
  7518. delete this.canvas;
  7519. }
  7520. if (this.image) {
  7521. this.image.removeAttribute("src");
  7522. delete this.image;
  7523. }
  7524. }
  7525. update(rotation) {
  7526. if (typeof rotation !== "undefined") {
  7527. this.rotation = rotation;
  7528. }
  7529. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  7530. this.viewport = this.viewport.clone({
  7531. scale: 1,
  7532. rotation: totalRotation
  7533. });
  7534. this.reset();
  7535. }
  7536. cancelRendering() {
  7537. if (this.renderTask) {
  7538. this.renderTask.cancel();
  7539. this.renderTask = null;
  7540. }
  7541. this.resume = null;
  7542. }
  7543. _getPageDrawContext() {
  7544. const canvas = document.createElement("canvas");
  7545. this.canvas = canvas;
  7546. canvas.mozOpaque = true;
  7547. const ctx = canvas.getContext("2d", {
  7548. alpha: false
  7549. });
  7550. const outputScale = (0, _ui_utils.getOutputScale)(ctx);
  7551. canvas.width = this.canvasWidth * outputScale.sx | 0;
  7552. canvas.height = this.canvasHeight * outputScale.sy | 0;
  7553. canvas.style.width = this.canvasWidth + "px";
  7554. canvas.style.height = this.canvasHeight + "px";
  7555. const transform = outputScale.scaled ? [outputScale.sx, 0, 0, outputScale.sy, 0, 0] : null;
  7556. return [ctx, transform];
  7557. }
  7558. _convertCanvasToImage() {
  7559. if (!this.canvas) {
  7560. return;
  7561. }
  7562. if (this.renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED) {
  7563. return;
  7564. }
  7565. const className = "thumbnailImage";
  7566. if (this.disableCanvasToImageConversion) {
  7567. this.canvas.className = className;
  7568. this._thumbPageCanvas.then(msg => {
  7569. this.canvas.setAttribute("aria-label", msg);
  7570. });
  7571. this.div.setAttribute("data-loaded", true);
  7572. this.ring.appendChild(this.canvas);
  7573. return;
  7574. }
  7575. const image = document.createElement("img");
  7576. image.className = className;
  7577. this._thumbPageCanvas.then(msg => {
  7578. image.setAttribute("aria-label", msg);
  7579. });
  7580. image.style.width = this.canvasWidth + "px";
  7581. image.style.height = this.canvasHeight + "px";
  7582. image.src = this.canvas.toDataURL();
  7583. this.image = image;
  7584. this.div.setAttribute("data-loaded", true);
  7585. this.ring.appendChild(image);
  7586. this.canvas.width = 0;
  7587. this.canvas.height = 0;
  7588. delete this.canvas;
  7589. }
  7590. draw() {
  7591. if (this.renderingState !== _pdf_rendering_queue.RenderingStates.INITIAL) {
  7592. console.error("Must be in new state before drawing");
  7593. return Promise.resolve(undefined);
  7594. }
  7595. const {
  7596. pdfPage
  7597. } = this;
  7598. if (!pdfPage) {
  7599. this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
  7600. return Promise.reject(new Error("pdfPage is not loaded"));
  7601. }
  7602. this.renderingState = _pdf_rendering_queue.RenderingStates.RUNNING;
  7603. const finishRenderTask = async (error = null) => {
  7604. if (renderTask === this.renderTask) {
  7605. this.renderTask = null;
  7606. }
  7607. if (error instanceof _pdfjsLib.RenderingCancelledException) {
  7608. return;
  7609. }
  7610. this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
  7611. this._convertCanvasToImage();
  7612. if (error) {
  7613. throw error;
  7614. }
  7615. };
  7616. const [ctx, transform] = this._getPageDrawContext();
  7617. const drawViewport = this.viewport.clone({
  7618. scale: this.scale
  7619. });
  7620. const renderContinueCallback = cont => {
  7621. if (!this.renderingQueue.isHighestPriority(this)) {
  7622. this.renderingState = _pdf_rendering_queue.RenderingStates.PAUSED;
  7623. this.resume = () => {
  7624. this.renderingState = _pdf_rendering_queue.RenderingStates.RUNNING;
  7625. cont();
  7626. };
  7627. return;
  7628. }
  7629. cont();
  7630. };
  7631. const renderContext = {
  7632. canvasContext: ctx,
  7633. transform,
  7634. viewport: drawViewport,
  7635. optionalContentConfigPromise: this._optionalContentConfigPromise
  7636. };
  7637. const renderTask = this.renderTask = pdfPage.render(renderContext);
  7638. renderTask.onContinue = renderContinueCallback;
  7639. const resultPromise = renderTask.promise.then(function () {
  7640. finishRenderTask(null);
  7641. }, function (error) {
  7642. finishRenderTask(error);
  7643. });
  7644. resultPromise.finally(() => {
  7645. const pageCached = this.linkService.isPageCached(this.id);
  7646. if (pageCached) {
  7647. return;
  7648. }
  7649. this.pdfPage?.cleanup();
  7650. });
  7651. return resultPromise;
  7652. }
  7653. setImage(pageView) {
  7654. if (this._checkSetImageDisabled()) {
  7655. return;
  7656. }
  7657. if (this.renderingState !== _pdf_rendering_queue.RenderingStates.INITIAL) {
  7658. return;
  7659. }
  7660. const img = pageView.canvas;
  7661. if (!img) {
  7662. return;
  7663. }
  7664. if (!this.pdfPage) {
  7665. this.setPdfPage(pageView.pdfPage);
  7666. }
  7667. this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
  7668. const [ctx] = this._getPageDrawContext();
  7669. const canvas = ctx.canvas;
  7670. if (img.width <= 2 * canvas.width) {
  7671. ctx.drawImage(img, 0, 0, img.width, img.height, 0, 0, canvas.width, canvas.height);
  7672. this._convertCanvasToImage();
  7673. return;
  7674. }
  7675. let reducedWidth = canvas.width << MAX_NUM_SCALING_STEPS;
  7676. let reducedHeight = canvas.height << MAX_NUM_SCALING_STEPS;
  7677. const reducedImage = TempImageFactory.getCanvas(reducedWidth, reducedHeight);
  7678. const reducedImageCtx = reducedImage.getContext("2d");
  7679. while (reducedWidth > img.width || reducedHeight > img.height) {
  7680. reducedWidth >>= 1;
  7681. reducedHeight >>= 1;
  7682. }
  7683. reducedImageCtx.drawImage(img, 0, 0, img.width, img.height, 0, 0, reducedWidth, reducedHeight);
  7684. while (reducedWidth > 2 * canvas.width) {
  7685. reducedImageCtx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, reducedWidth >> 1, reducedHeight >> 1);
  7686. reducedWidth >>= 1;
  7687. reducedHeight >>= 1;
  7688. }
  7689. ctx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, canvas.width, canvas.height);
  7690. this._convertCanvasToImage();
  7691. }
  7692. get _thumbPageTitle() {
  7693. return this.l10n.get("thumb_page_title", {
  7694. page: this.pageLabel ?? this.id
  7695. });
  7696. }
  7697. get _thumbPageCanvas() {
  7698. return this.l10n.get("thumb_page_canvas", {
  7699. page: this.pageLabel ?? this.id
  7700. });
  7701. }
  7702. setPageLabel(label) {
  7703. this.pageLabel = typeof label === "string" ? label : null;
  7704. this._thumbPageTitle.then(msg => {
  7705. this.anchor.title = msg;
  7706. });
  7707. if (this.renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED) {
  7708. return;
  7709. }
  7710. this._thumbPageCanvas.then(msg => {
  7711. if (this.image) {
  7712. this.image.setAttribute("aria-label", msg);
  7713. } else if (this.disableCanvasToImageConversion && this.canvas) {
  7714. this.canvas.setAttribute("aria-label", msg);
  7715. }
  7716. });
  7717. }
  7718. }
  7719. exports.PDFThumbnailView = PDFThumbnailView;
  7720. /***/ }),
  7721. /* 27 */
  7722. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7723. Object.defineProperty(exports, "__esModule", ({
  7724. value: true
  7725. }));
  7726. exports.PDFViewer = void 0;
  7727. var _ui_utils = __webpack_require__(4);
  7728. var _base_viewer = __webpack_require__(28);
  7729. var _pdfjsLib = __webpack_require__(5);
  7730. class PDFViewer extends _base_viewer.BaseViewer {
  7731. get _viewerElement() {
  7732. return (0, _pdfjsLib.shadow)(this, "_viewerElement", this.viewer);
  7733. }
  7734. _scrollIntoView({
  7735. pageDiv,
  7736. pageSpot = null,
  7737. pageNumber = null
  7738. }) {
  7739. if (!pageSpot && !this.isInPresentationMode) {
  7740. const left = pageDiv.offsetLeft + pageDiv.clientLeft;
  7741. const right = left + pageDiv.clientWidth;
  7742. const {
  7743. scrollLeft,
  7744. clientWidth
  7745. } = this.container;
  7746. if (this._isScrollModeHorizontal || left < scrollLeft || right > scrollLeft + clientWidth) {
  7747. pageSpot = {
  7748. left: 0,
  7749. top: 0
  7750. };
  7751. }
  7752. }
  7753. super._scrollIntoView({
  7754. pageDiv,
  7755. pageSpot,
  7756. pageNumber
  7757. });
  7758. }
  7759. _getVisiblePages() {
  7760. if (this.isInPresentationMode) {
  7761. return this._getCurrentVisiblePage();
  7762. }
  7763. return super._getVisiblePages();
  7764. }
  7765. _updateHelper(visiblePages) {
  7766. if (this.isInPresentationMode) {
  7767. return;
  7768. }
  7769. let currentId = this._currentPageNumber;
  7770. let stillFullyVisible = false;
  7771. for (const page of visiblePages) {
  7772. if (page.percent < 100) {
  7773. break;
  7774. }
  7775. if (page.id === currentId && this._scrollMode === _ui_utils.ScrollMode.VERTICAL && this._spreadMode === _ui_utils.SpreadMode.NONE) {
  7776. stillFullyVisible = true;
  7777. break;
  7778. }
  7779. }
  7780. if (!stillFullyVisible) {
  7781. currentId = visiblePages[0].id;
  7782. }
  7783. this._setCurrentPageNumber(currentId);
  7784. }
  7785. }
  7786. exports.PDFViewer = PDFViewer;
  7787. /***/ }),
  7788. /* 28 */
  7789. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7790. Object.defineProperty(exports, "__esModule", ({
  7791. value: true
  7792. }));
  7793. exports.BaseViewer = void 0;
  7794. var _pdfjsLib = __webpack_require__(5);
  7795. var _ui_utils = __webpack_require__(4);
  7796. var _pdf_rendering_queue = __webpack_require__(8);
  7797. var _annotation_layer_builder = __webpack_require__(29);
  7798. var _l10n_utils = __webpack_require__(30);
  7799. var _pdf_page_view = __webpack_require__(31);
  7800. var _pdf_link_service = __webpack_require__(19);
  7801. var _text_layer_builder = __webpack_require__(32);
  7802. var _xfa_layer_builder = __webpack_require__(33);
  7803. const DEFAULT_CACHE_SIZE = 10;
  7804. function PDFPageViewBuffer(size) {
  7805. const data = [];
  7806. this.push = function (view) {
  7807. const i = data.indexOf(view);
  7808. if (i >= 0) {
  7809. data.splice(i, 1);
  7810. }
  7811. data.push(view);
  7812. if (data.length > size) {
  7813. data.shift().destroy();
  7814. }
  7815. };
  7816. this.resize = function (newSize, pagesToKeep) {
  7817. size = newSize;
  7818. if (pagesToKeep) {
  7819. const pageIdsToKeep = new Set();
  7820. for (let i = 0, iMax = pagesToKeep.length; i < iMax; ++i) {
  7821. pageIdsToKeep.add(pagesToKeep[i].id);
  7822. }
  7823. (0, _ui_utils.moveToEndOfArray)(data, function (page) {
  7824. return pageIdsToKeep.has(page.id);
  7825. });
  7826. }
  7827. while (data.length > size) {
  7828. data.shift().destroy();
  7829. }
  7830. };
  7831. this.has = function (view) {
  7832. return data.includes(view);
  7833. };
  7834. }
  7835. function isSameScale(oldScale, newScale) {
  7836. if (newScale === oldScale) {
  7837. return true;
  7838. }
  7839. if (Math.abs(newScale - oldScale) < 1e-15) {
  7840. return true;
  7841. }
  7842. return false;
  7843. }
  7844. class BaseViewer {
  7845. constructor(options) {
  7846. if (this.constructor === BaseViewer) {
  7847. throw new Error("Cannot initialize BaseViewer.");
  7848. }
  7849. const viewerVersion = '2.8.335';
  7850. if (_pdfjsLib.version !== viewerVersion) {
  7851. throw new Error(`The API version "${_pdfjsLib.version}" does not match the Viewer version "${viewerVersion}".`);
  7852. }
  7853. this._name = this.constructor.name;
  7854. this.container = options.container;
  7855. this.viewer = options.viewer || options.container.firstElementChild;
  7856. if (!(this.container?.tagName.toUpperCase() === "DIV" && this.viewer?.tagName.toUpperCase() === "DIV")) {
  7857. throw new Error("Invalid `container` and/or `viewer` option.");
  7858. }
  7859. if (this.container.offsetParent && getComputedStyle(this.container).position !== "absolute") {
  7860. throw new Error("The `container` must be absolutely positioned.");
  7861. }
  7862. this.eventBus = options.eventBus;
  7863. this.linkService = options.linkService || new _pdf_link_service.SimpleLinkService();
  7864. this.downloadManager = options.downloadManager || null;
  7865. this.findController = options.findController || null;
  7866. this._scriptingManager = options.scriptingManager || null;
  7867. this.removePageBorders = options.removePageBorders || false;
  7868. this.textLayerMode = Number.isInteger(options.textLayerMode) ? options.textLayerMode : _ui_utils.TextLayerMode.ENABLE;
  7869. this.imageResourcesPath = options.imageResourcesPath || "";
  7870. this.renderInteractiveForms = options.renderInteractiveForms !== false;
  7871. this.enablePrintAutoRotate = options.enablePrintAutoRotate || false;
  7872. this.renderer = options.renderer || _ui_utils.RendererType.CANVAS;
  7873. this.enableWebGL = options.enableWebGL || false;
  7874. this.useOnlyCssZoom = options.useOnlyCssZoom || false;
  7875. this.maxCanvasPixels = options.maxCanvasPixels;
  7876. this.l10n = options.l10n || _l10n_utils.NullL10n;
  7877. this.enableScripting = options.enableScripting === true && !!this._scriptingManager;
  7878. this.defaultRenderingQueue = !options.renderingQueue;
  7879. if (this.defaultRenderingQueue) {
  7880. this.renderingQueue = new _pdf_rendering_queue.PDFRenderingQueue();
  7881. this.renderingQueue.setViewer(this);
  7882. } else {
  7883. this.renderingQueue = options.renderingQueue;
  7884. }
  7885. this.scroll = (0, _ui_utils.watchScroll)(this.container, this._scrollUpdate.bind(this));
  7886. this.presentationModeState = _ui_utils.PresentationModeState.UNKNOWN;
  7887. this._onBeforeDraw = this._onAfterDraw = null;
  7888. this._resetView();
  7889. if (this.removePageBorders) {
  7890. this.viewer.classList.add("removePageBorders");
  7891. }
  7892. Promise.resolve().then(() => {
  7893. this.eventBus.dispatch("baseviewerinit", {
  7894. source: this
  7895. });
  7896. });
  7897. }
  7898. get pagesCount() {
  7899. return this._pages.length;
  7900. }
  7901. getPageView(index) {
  7902. return this._pages[index];
  7903. }
  7904. get pageViewsReady() {
  7905. if (!this._pagesCapability.settled) {
  7906. return false;
  7907. }
  7908. return this._pages.every(function (pageView) {
  7909. return pageView?.pdfPage;
  7910. });
  7911. }
  7912. get currentPageNumber() {
  7913. return this._currentPageNumber;
  7914. }
  7915. set currentPageNumber(val) {
  7916. if (!Number.isInteger(val)) {
  7917. throw new Error("Invalid page number.");
  7918. }
  7919. if (!this.pdfDocument) {
  7920. return;
  7921. }
  7922. if (!this._setCurrentPageNumber(val, true)) {
  7923. console.error(`${this._name}.currentPageNumber: "${val}" is not a valid page.`);
  7924. }
  7925. }
  7926. _setCurrentPageNumber(val, resetCurrentPageView = false) {
  7927. if (this._currentPageNumber === val) {
  7928. if (resetCurrentPageView) {
  7929. this._resetCurrentPageView();
  7930. }
  7931. return true;
  7932. }
  7933. if (!(0 < val && val <= this.pagesCount)) {
  7934. return false;
  7935. }
  7936. const previous = this._currentPageNumber;
  7937. this._currentPageNumber = val;
  7938. this.eventBus.dispatch("pagechanging", {
  7939. source: this,
  7940. pageNumber: val,
  7941. pageLabel: this._pageLabels?.[val - 1] ?? null,
  7942. previous
  7943. });
  7944. if (resetCurrentPageView) {
  7945. this._resetCurrentPageView();
  7946. }
  7947. return true;
  7948. }
  7949. get currentPageLabel() {
  7950. return this._pageLabels?.[this._currentPageNumber - 1] ?? null;
  7951. }
  7952. set currentPageLabel(val) {
  7953. if (!this.pdfDocument) {
  7954. return;
  7955. }
  7956. let page = val | 0;
  7957. if (this._pageLabels) {
  7958. const i = this._pageLabels.indexOf(val);
  7959. if (i >= 0) {
  7960. page = i + 1;
  7961. }
  7962. }
  7963. if (!this._setCurrentPageNumber(page, true)) {
  7964. console.error(`${this._name}.currentPageLabel: "${val}" is not a valid page.`);
  7965. }
  7966. }
  7967. get currentScale() {
  7968. return this._currentScale !== _ui_utils.UNKNOWN_SCALE ? this._currentScale : _ui_utils.DEFAULT_SCALE;
  7969. }
  7970. set currentScale(val) {
  7971. if (isNaN(val)) {
  7972. throw new Error("Invalid numeric scale.");
  7973. }
  7974. if (!this.pdfDocument) {
  7975. return;
  7976. }
  7977. this._setScale(val, false);
  7978. }
  7979. get currentScaleValue() {
  7980. return this._currentScaleValue;
  7981. }
  7982. set currentScaleValue(val) {
  7983. if (!this.pdfDocument) {
  7984. return;
  7985. }
  7986. this._setScale(val, false);
  7987. }
  7988. get pagesRotation() {
  7989. return this._pagesRotation;
  7990. }
  7991. set pagesRotation(rotation) {
  7992. if (!(0, _ui_utils.isValidRotation)(rotation)) {
  7993. throw new Error("Invalid pages rotation angle.");
  7994. }
  7995. if (!this.pdfDocument) {
  7996. return;
  7997. }
  7998. rotation %= 360;
  7999. if (rotation < 0) {
  8000. rotation += 360;
  8001. }
  8002. if (this._pagesRotation === rotation) {
  8003. return;
  8004. }
  8005. this._pagesRotation = rotation;
  8006. const pageNumber = this._currentPageNumber;
  8007. for (let i = 0, ii = this._pages.length; i < ii; i++) {
  8008. const pageView = this._pages[i];
  8009. pageView.update(pageView.scale, rotation);
  8010. }
  8011. if (this._currentScaleValue) {
  8012. this._setScale(this._currentScaleValue, true);
  8013. }
  8014. this.eventBus.dispatch("rotationchanging", {
  8015. source: this,
  8016. pagesRotation: rotation,
  8017. pageNumber
  8018. });
  8019. if (this.defaultRenderingQueue) {
  8020. this.update();
  8021. }
  8022. }
  8023. get firstPagePromise() {
  8024. return this.pdfDocument ? this._firstPageCapability.promise : null;
  8025. }
  8026. get onePageRendered() {
  8027. return this.pdfDocument ? this._onePageRenderedCapability.promise : null;
  8028. }
  8029. get pagesPromise() {
  8030. return this.pdfDocument ? this._pagesCapability.promise : null;
  8031. }
  8032. get _viewerElement() {
  8033. throw new Error("Not implemented: _viewerElement");
  8034. }
  8035. _onePageRenderedOrForceFetch() {
  8036. if (!this.container.offsetParent || this._getVisiblePages().views.length === 0) {
  8037. return Promise.resolve();
  8038. }
  8039. return this._onePageRenderedCapability.promise;
  8040. }
  8041. setDocument(pdfDocument) {
  8042. if (this.pdfDocument) {
  8043. this.eventBus.dispatch("pagesdestroy", {
  8044. source: this
  8045. });
  8046. this._cancelRendering();
  8047. this._resetView();
  8048. if (this.findController) {
  8049. this.findController.setDocument(null);
  8050. }
  8051. if (this._scriptingManager) {
  8052. this._scriptingManager.setDocument(null);
  8053. }
  8054. }
  8055. this.pdfDocument = pdfDocument;
  8056. if (!pdfDocument) {
  8057. return;
  8058. }
  8059. const isPureXfa = pdfDocument.isPureXfa;
  8060. const pagesCount = pdfDocument.numPages;
  8061. const firstPagePromise = pdfDocument.getPage(1);
  8062. const optionalContentConfigPromise = pdfDocument.getOptionalContentConfig();
  8063. this._pagesCapability.promise.then(() => {
  8064. this.eventBus.dispatch("pagesloaded", {
  8065. source: this,
  8066. pagesCount
  8067. });
  8068. });
  8069. this._onBeforeDraw = evt => {
  8070. const pageView = this._pages[evt.pageNumber - 1];
  8071. if (!pageView) {
  8072. return;
  8073. }
  8074. this._buffer.push(pageView);
  8075. };
  8076. this.eventBus._on("pagerender", this._onBeforeDraw);
  8077. this._onAfterDraw = evt => {
  8078. if (evt.cssTransform || this._onePageRenderedCapability.settled) {
  8079. return;
  8080. }
  8081. this._onePageRenderedCapability.resolve();
  8082. this.eventBus._off("pagerendered", this._onAfterDraw);
  8083. this._onAfterDraw = null;
  8084. };
  8085. this.eventBus._on("pagerendered", this._onAfterDraw);
  8086. firstPagePromise.then(firstPdfPage => {
  8087. this._firstPageCapability.resolve(firstPdfPage);
  8088. this._optionalContentConfigPromise = optionalContentConfigPromise;
  8089. const scale = this.currentScale;
  8090. const viewport = firstPdfPage.getViewport({
  8091. scale: scale * _ui_utils.CSS_UNITS
  8092. });
  8093. const textLayerFactory = this.textLayerMode !== _ui_utils.TextLayerMode.DISABLE ? this : null;
  8094. const xfaLayerFactory = isPureXfa ? this : null;
  8095. for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) {
  8096. const pageView = new _pdf_page_view.PDFPageView({
  8097. container: this._viewerElement,
  8098. eventBus: this.eventBus,
  8099. id: pageNum,
  8100. scale,
  8101. defaultViewport: viewport.clone(),
  8102. optionalContentConfigPromise,
  8103. renderingQueue: this.renderingQueue,
  8104. textLayerFactory,
  8105. textLayerMode: this.textLayerMode,
  8106. annotationLayerFactory: this,
  8107. xfaLayerFactory,
  8108. imageResourcesPath: this.imageResourcesPath,
  8109. renderInteractiveForms: this.renderInteractiveForms,
  8110. renderer: this.renderer,
  8111. enableWebGL: this.enableWebGL,
  8112. useOnlyCssZoom: this.useOnlyCssZoom,
  8113. maxCanvasPixels: this.maxCanvasPixels,
  8114. l10n: this.l10n,
  8115. enableScripting: this.enableScripting
  8116. });
  8117. this._pages.push(pageView);
  8118. }
  8119. const firstPageView = this._pages[0];
  8120. if (firstPageView) {
  8121. firstPageView.setPdfPage(firstPdfPage);
  8122. this.linkService.cachePageRef(1, firstPdfPage.ref);
  8123. }
  8124. if (this._spreadMode !== _ui_utils.SpreadMode.NONE) {
  8125. this._updateSpreadMode();
  8126. }
  8127. this._onePageRenderedOrForceFetch().then(() => {
  8128. if (this.findController) {
  8129. this.findController.setDocument(pdfDocument);
  8130. }
  8131. if (this.enableScripting) {
  8132. this._scriptingManager.setDocument(pdfDocument);
  8133. }
  8134. if (pdfDocument.loadingParams.disableAutoFetch || pagesCount > 7500) {
  8135. this._pagesCapability.resolve();
  8136. return;
  8137. }
  8138. let getPagesLeft = pagesCount - 1;
  8139. if (getPagesLeft <= 0) {
  8140. this._pagesCapability.resolve();
  8141. return;
  8142. }
  8143. for (let pageNum = 2; pageNum <= pagesCount; ++pageNum) {
  8144. pdfDocument.getPage(pageNum).then(pdfPage => {
  8145. const pageView = this._pages[pageNum - 1];
  8146. if (!pageView.pdfPage) {
  8147. pageView.setPdfPage(pdfPage);
  8148. }
  8149. this.linkService.cachePageRef(pageNum, pdfPage.ref);
  8150. if (--getPagesLeft === 0) {
  8151. this._pagesCapability.resolve();
  8152. }
  8153. }, reason => {
  8154. console.error(`Unable to get page ${pageNum} to initialize viewer`, reason);
  8155. if (--getPagesLeft === 0) {
  8156. this._pagesCapability.resolve();
  8157. }
  8158. });
  8159. }
  8160. });
  8161. this.eventBus.dispatch("pagesinit", {
  8162. source: this
  8163. });
  8164. if (this.defaultRenderingQueue) {
  8165. this.update();
  8166. }
  8167. }).catch(reason => {
  8168. console.error("Unable to initialize viewer", reason);
  8169. });
  8170. }
  8171. setPageLabels(labels) {
  8172. if (!this.pdfDocument) {
  8173. return;
  8174. }
  8175. if (!labels) {
  8176. this._pageLabels = null;
  8177. } else if (!(Array.isArray(labels) && this.pdfDocument.numPages === labels.length)) {
  8178. this._pageLabels = null;
  8179. console.error(`${this._name}.setPageLabels: Invalid page labels.`);
  8180. } else {
  8181. this._pageLabels = labels;
  8182. }
  8183. for (let i = 0, ii = this._pages.length; i < ii; i++) {
  8184. this._pages[i].setPageLabel(this._pageLabels?.[i] ?? null);
  8185. }
  8186. }
  8187. _resetView() {
  8188. this._pages = [];
  8189. this._currentPageNumber = 1;
  8190. this._currentScale = _ui_utils.UNKNOWN_SCALE;
  8191. this._currentScaleValue = null;
  8192. this._pageLabels = null;
  8193. this._buffer = new PDFPageViewBuffer(DEFAULT_CACHE_SIZE);
  8194. this._location = null;
  8195. this._pagesRotation = 0;
  8196. this._optionalContentConfigPromise = null;
  8197. this._pagesRequests = new WeakMap();
  8198. this._firstPageCapability = (0, _pdfjsLib.createPromiseCapability)();
  8199. this._onePageRenderedCapability = (0, _pdfjsLib.createPromiseCapability)();
  8200. this._pagesCapability = (0, _pdfjsLib.createPromiseCapability)();
  8201. this._scrollMode = _ui_utils.ScrollMode.VERTICAL;
  8202. this._spreadMode = _ui_utils.SpreadMode.NONE;
  8203. if (this._onBeforeDraw) {
  8204. this.eventBus._off("pagerender", this._onBeforeDraw);
  8205. this._onBeforeDraw = null;
  8206. }
  8207. if (this._onAfterDraw) {
  8208. this.eventBus._off("pagerendered", this._onAfterDraw);
  8209. this._onAfterDraw = null;
  8210. }
  8211. this.viewer.textContent = "";
  8212. this._updateScrollMode();
  8213. }
  8214. _scrollUpdate() {
  8215. if (this.pagesCount === 0) {
  8216. return;
  8217. }
  8218. this.update();
  8219. }
  8220. _scrollIntoView({
  8221. pageDiv,
  8222. pageSpot = null,
  8223. pageNumber = null
  8224. }) {
  8225. (0, _ui_utils.scrollIntoView)(pageDiv, pageSpot);
  8226. }
  8227. _setScaleUpdatePages(newScale, newValue, noScroll = false, preset = false) {
  8228. this._currentScaleValue = newValue.toString();
  8229. if (isSameScale(this._currentScale, newScale)) {
  8230. if (preset) {
  8231. this.eventBus.dispatch("scalechanging", {
  8232. source: this,
  8233. scale: newScale,
  8234. presetValue: newValue
  8235. });
  8236. }
  8237. return;
  8238. }
  8239. for (let i = 0, ii = this._pages.length; i < ii; i++) {
  8240. this._pages[i].update(newScale);
  8241. }
  8242. this._currentScale = newScale;
  8243. if (!noScroll) {
  8244. let page = this._currentPageNumber,
  8245. dest;
  8246. if (this._location && !(this.isInPresentationMode || this.isChangingPresentationMode)) {
  8247. page = this._location.pageNumber;
  8248. dest = [null, {
  8249. name: "XYZ"
  8250. }, this._location.left, this._location.top, null];
  8251. }
  8252. this.scrollPageIntoView({
  8253. pageNumber: page,
  8254. destArray: dest,
  8255. allowNegativeOffset: true
  8256. });
  8257. }
  8258. this.eventBus.dispatch("scalechanging", {
  8259. source: this,
  8260. scale: newScale,
  8261. presetValue: preset ? newValue : undefined
  8262. });
  8263. if (this.defaultRenderingQueue) {
  8264. this.update();
  8265. }
  8266. }
  8267. get _pageWidthScaleFactor() {
  8268. if (this._spreadMode !== _ui_utils.SpreadMode.NONE && this._scrollMode !== _ui_utils.ScrollMode.HORIZONTAL && !this.isInPresentationMode) {
  8269. return 2;
  8270. }
  8271. return 1;
  8272. }
  8273. _setScale(value, noScroll = false) {
  8274. let scale = parseFloat(value);
  8275. if (scale > 0) {
  8276. this._setScaleUpdatePages(scale, value, noScroll, false);
  8277. } else {
  8278. const currentPage = this._pages[this._currentPageNumber - 1];
  8279. if (!currentPage) {
  8280. return;
  8281. }
  8282. const noPadding = this.isInPresentationMode || this.removePageBorders;
  8283. let hPadding = noPadding ? 0 : _ui_utils.SCROLLBAR_PADDING;
  8284. let vPadding = noPadding ? 0 : _ui_utils.VERTICAL_PADDING;
  8285. if (!noPadding && this._isScrollModeHorizontal) {
  8286. [hPadding, vPadding] = [vPadding, hPadding];
  8287. }
  8288. const pageWidthScale = (this.container.clientWidth - hPadding) / currentPage.width * currentPage.scale / this._pageWidthScaleFactor;
  8289. const pageHeightScale = (this.container.clientHeight - vPadding) / currentPage.height * currentPage.scale;
  8290. switch (value) {
  8291. case "page-actual":
  8292. scale = 1;
  8293. break;
  8294. case "page-width":
  8295. scale = pageWidthScale;
  8296. break;
  8297. case "page-height":
  8298. scale = pageHeightScale;
  8299. break;
  8300. case "page-fit":
  8301. scale = Math.min(pageWidthScale, pageHeightScale);
  8302. break;
  8303. case "auto":
  8304. const horizontalScale = (0, _ui_utils.isPortraitOrientation)(currentPage) ? pageWidthScale : Math.min(pageHeightScale, pageWidthScale);
  8305. scale = Math.min(_ui_utils.MAX_AUTO_SCALE, horizontalScale);
  8306. break;
  8307. default:
  8308. console.error(`${this._name}._setScale: "${value}" is an unknown zoom value.`);
  8309. return;
  8310. }
  8311. this._setScaleUpdatePages(scale, value, noScroll, true);
  8312. }
  8313. }
  8314. _resetCurrentPageView() {
  8315. if (this.isInPresentationMode) {
  8316. this._setScale(this._currentScaleValue, true);
  8317. }
  8318. const pageView = this._pages[this._currentPageNumber - 1];
  8319. this._scrollIntoView({
  8320. pageDiv: pageView.div
  8321. });
  8322. }
  8323. pageLabelToPageNumber(label) {
  8324. if (!this._pageLabels) {
  8325. return null;
  8326. }
  8327. const i = this._pageLabels.indexOf(label);
  8328. if (i < 0) {
  8329. return null;
  8330. }
  8331. return i + 1;
  8332. }
  8333. scrollPageIntoView({
  8334. pageNumber,
  8335. destArray = null,
  8336. allowNegativeOffset = false,
  8337. ignoreDestinationZoom = false
  8338. }) {
  8339. if (!this.pdfDocument) {
  8340. return;
  8341. }
  8342. const pageView = Number.isInteger(pageNumber) && this._pages[pageNumber - 1];
  8343. if (!pageView) {
  8344. console.error(`${this._name}.scrollPageIntoView: ` + `"${pageNumber}" is not a valid pageNumber parameter.`);
  8345. return;
  8346. }
  8347. if (this.isInPresentationMode || !destArray) {
  8348. this._setCurrentPageNumber(pageNumber, true);
  8349. return;
  8350. }
  8351. let x = 0,
  8352. y = 0;
  8353. let width = 0,
  8354. height = 0,
  8355. widthScale,
  8356. heightScale;
  8357. const changeOrientation = pageView.rotation % 180 !== 0;
  8358. const pageWidth = (changeOrientation ? pageView.height : pageView.width) / pageView.scale / _ui_utils.CSS_UNITS;
  8359. const pageHeight = (changeOrientation ? pageView.width : pageView.height) / pageView.scale / _ui_utils.CSS_UNITS;
  8360. let scale = 0;
  8361. switch (destArray[1].name) {
  8362. case "XYZ":
  8363. x = destArray[2];
  8364. y = destArray[3];
  8365. scale = destArray[4];
  8366. x = x !== null ? x : 0;
  8367. y = y !== null ? y : pageHeight;
  8368. break;
  8369. case "Fit":
  8370. case "FitB":
  8371. scale = "page-fit";
  8372. break;
  8373. case "FitH":
  8374. case "FitBH":
  8375. y = destArray[2];
  8376. scale = "page-width";
  8377. if (y === null && this._location) {
  8378. x = this._location.left;
  8379. y = this._location.top;
  8380. } else if (typeof y !== "number") {
  8381. y = pageHeight;
  8382. }
  8383. break;
  8384. case "FitV":
  8385. case "FitBV":
  8386. x = destArray[2];
  8387. width = pageWidth;
  8388. height = pageHeight;
  8389. scale = "page-height";
  8390. break;
  8391. case "FitR":
  8392. x = destArray[2];
  8393. y = destArray[3];
  8394. width = destArray[4] - x;
  8395. height = destArray[5] - y;
  8396. const hPadding = this.removePageBorders ? 0 : _ui_utils.SCROLLBAR_PADDING;
  8397. const vPadding = this.removePageBorders ? 0 : _ui_utils.VERTICAL_PADDING;
  8398. widthScale = (this.container.clientWidth - hPadding) / width / _ui_utils.CSS_UNITS;
  8399. heightScale = (this.container.clientHeight - vPadding) / height / _ui_utils.CSS_UNITS;
  8400. scale = Math.min(Math.abs(widthScale), Math.abs(heightScale));
  8401. break;
  8402. default:
  8403. console.error(`${this._name}.scrollPageIntoView: ` + `"${destArray[1].name}" is not a valid destination type.`);
  8404. return;
  8405. }
  8406. if (!ignoreDestinationZoom) {
  8407. if (scale && scale !== this._currentScale) {
  8408. this.currentScaleValue = scale;
  8409. } else if (this._currentScale === _ui_utils.UNKNOWN_SCALE) {
  8410. this.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  8411. }
  8412. }
  8413. if (scale === "page-fit" && !destArray[4]) {
  8414. this._scrollIntoView({
  8415. pageDiv: pageView.div,
  8416. pageNumber
  8417. });
  8418. return;
  8419. }
  8420. const boundingRect = [pageView.viewport.convertToViewportPoint(x, y), pageView.viewport.convertToViewportPoint(x + width, y + height)];
  8421. let left = Math.min(boundingRect[0][0], boundingRect[1][0]);
  8422. let top = Math.min(boundingRect[0][1], boundingRect[1][1]);
  8423. if (!allowNegativeOffset) {
  8424. left = Math.max(left, 0);
  8425. top = Math.max(top, 0);
  8426. }
  8427. this._scrollIntoView({
  8428. pageDiv: pageView.div,
  8429. pageSpot: {
  8430. left,
  8431. top
  8432. },
  8433. pageNumber
  8434. });
  8435. }
  8436. _updateLocation(firstPage) {
  8437. const currentScale = this._currentScale;
  8438. const currentScaleValue = this._currentScaleValue;
  8439. const normalizedScaleValue = parseFloat(currentScaleValue) === currentScale ? Math.round(currentScale * 10000) / 100 : currentScaleValue;
  8440. const pageNumber = firstPage.id;
  8441. let pdfOpenParams = "#page=" + pageNumber;
  8442. pdfOpenParams += "&zoom=" + normalizedScaleValue;
  8443. const currentPageView = this._pages[pageNumber - 1];
  8444. const container = this.container;
  8445. const topLeft = currentPageView.getPagePoint(container.scrollLeft - firstPage.x, container.scrollTop - firstPage.y);
  8446. const intLeft = Math.round(topLeft[0]);
  8447. const intTop = Math.round(topLeft[1]);
  8448. pdfOpenParams += "," + intLeft + "," + intTop;
  8449. this._location = {
  8450. pageNumber,
  8451. scale: normalizedScaleValue,
  8452. top: intTop,
  8453. left: intLeft,
  8454. rotation: this._pagesRotation,
  8455. pdfOpenParams
  8456. };
  8457. }
  8458. _updateHelper(visiblePages) {
  8459. throw new Error("Not implemented: _updateHelper");
  8460. }
  8461. update() {
  8462. const visible = this._getVisiblePages();
  8463. const visiblePages = visible.views,
  8464. numVisiblePages = visiblePages.length;
  8465. if (numVisiblePages === 0) {
  8466. return;
  8467. }
  8468. const newCacheSize = Math.max(DEFAULT_CACHE_SIZE, 2 * numVisiblePages + 1);
  8469. this._buffer.resize(newCacheSize, visiblePages);
  8470. this.renderingQueue.renderHighestPriority(visible);
  8471. this._updateHelper(visiblePages);
  8472. this._updateLocation(visible.first);
  8473. this.eventBus.dispatch("updateviewarea", {
  8474. source: this,
  8475. location: this._location
  8476. });
  8477. }
  8478. containsElement(element) {
  8479. return this.container.contains(element);
  8480. }
  8481. focus() {
  8482. this.container.focus();
  8483. }
  8484. get _isScrollModeHorizontal() {
  8485. return this.isInPresentationMode ? false : this._scrollMode === _ui_utils.ScrollMode.HORIZONTAL;
  8486. }
  8487. get _isContainerRtl() {
  8488. return getComputedStyle(this.container).direction === "rtl";
  8489. }
  8490. get isInPresentationMode() {
  8491. return this.presentationModeState === _ui_utils.PresentationModeState.FULLSCREEN;
  8492. }
  8493. get isChangingPresentationMode() {
  8494. return this.presentationModeState === _ui_utils.PresentationModeState.CHANGING;
  8495. }
  8496. get isHorizontalScrollbarEnabled() {
  8497. return this.isInPresentationMode ? false : this.container.scrollWidth > this.container.clientWidth;
  8498. }
  8499. get isVerticalScrollbarEnabled() {
  8500. return this.isInPresentationMode ? false : this.container.scrollHeight > this.container.clientHeight;
  8501. }
  8502. _getCurrentVisiblePage() {
  8503. if (!this.pagesCount) {
  8504. return {
  8505. views: []
  8506. };
  8507. }
  8508. const pageView = this._pages[this._currentPageNumber - 1];
  8509. const element = pageView.div;
  8510. const view = {
  8511. id: pageView.id,
  8512. x: element.offsetLeft + element.clientLeft,
  8513. y: element.offsetTop + element.clientTop,
  8514. view: pageView
  8515. };
  8516. return {
  8517. first: view,
  8518. last: view,
  8519. views: [view]
  8520. };
  8521. }
  8522. _getVisiblePages() {
  8523. return (0, _ui_utils.getVisibleElements)({
  8524. scrollEl: this.container,
  8525. views: this._pages,
  8526. sortByVisibility: true,
  8527. horizontal: this._isScrollModeHorizontal,
  8528. rtl: this._isScrollModeHorizontal && this._isContainerRtl
  8529. });
  8530. }
  8531. isPageVisible(pageNumber) {
  8532. if (!this.pdfDocument) {
  8533. return false;
  8534. }
  8535. if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) {
  8536. console.error(`${this._name}.isPageVisible: "${pageNumber}" is not a valid page.`);
  8537. return false;
  8538. }
  8539. return this._getVisiblePages().views.some(function (view) {
  8540. return view.id === pageNumber;
  8541. });
  8542. }
  8543. isPageCached(pageNumber) {
  8544. if (!this.pdfDocument || !this._buffer) {
  8545. return false;
  8546. }
  8547. if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) {
  8548. console.error(`${this._name}.isPageCached: "${pageNumber}" is not a valid page.`);
  8549. return false;
  8550. }
  8551. const pageView = this._pages[pageNumber - 1];
  8552. if (!pageView) {
  8553. return false;
  8554. }
  8555. return this._buffer.has(pageView);
  8556. }
  8557. cleanup() {
  8558. for (let i = 0, ii = this._pages.length; i < ii; i++) {
  8559. if (this._pages[i] && this._pages[i].renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED) {
  8560. this._pages[i].reset();
  8561. }
  8562. }
  8563. }
  8564. _cancelRendering() {
  8565. for (let i = 0, ii = this._pages.length; i < ii; i++) {
  8566. if (this._pages[i]) {
  8567. this._pages[i].cancelRendering();
  8568. }
  8569. }
  8570. }
  8571. _ensurePdfPageLoaded(pageView) {
  8572. if (pageView.pdfPage) {
  8573. return Promise.resolve(pageView.pdfPage);
  8574. }
  8575. if (this._pagesRequests.has(pageView)) {
  8576. return this._pagesRequests.get(pageView);
  8577. }
  8578. const promise = this.pdfDocument.getPage(pageView.id).then(pdfPage => {
  8579. if (!pageView.pdfPage) {
  8580. pageView.setPdfPage(pdfPage);
  8581. }
  8582. this._pagesRequests.delete(pageView);
  8583. return pdfPage;
  8584. }).catch(reason => {
  8585. console.error("Unable to get page for page view", reason);
  8586. this._pagesRequests.delete(pageView);
  8587. });
  8588. this._pagesRequests.set(pageView, promise);
  8589. return promise;
  8590. }
  8591. forceRendering(currentlyVisiblePages) {
  8592. const visiblePages = currentlyVisiblePages || this._getVisiblePages();
  8593. const scrollAhead = this._isScrollModeHorizontal ? this.scroll.right : this.scroll.down;
  8594. const pageView = this.renderingQueue.getHighestPriority(visiblePages, this._pages, scrollAhead);
  8595. if (pageView) {
  8596. this._ensurePdfPageLoaded(pageView).then(() => {
  8597. this.renderingQueue.renderView(pageView);
  8598. });
  8599. return true;
  8600. }
  8601. return false;
  8602. }
  8603. createTextLayerBuilder(textLayerDiv, pageIndex, viewport, enhanceTextSelection = false, eventBus) {
  8604. return new _text_layer_builder.TextLayerBuilder({
  8605. textLayerDiv,
  8606. eventBus,
  8607. pageIndex,
  8608. viewport,
  8609. findController: this.isInPresentationMode ? null : this.findController,
  8610. enhanceTextSelection: this.isInPresentationMode ? false : enhanceTextSelection
  8611. });
  8612. }
  8613. createAnnotationLayerBuilder(pageDiv, pdfPage, annotationStorage = null, imageResourcesPath = "", renderInteractiveForms = false, l10n = _l10n_utils.NullL10n, enableScripting = false, hasJSActionsPromise = null, mouseState = null) {
  8614. return new _annotation_layer_builder.AnnotationLayerBuilder({
  8615. pageDiv,
  8616. pdfPage,
  8617. annotationStorage: annotationStorage || this.pdfDocument?.annotationStorage,
  8618. imageResourcesPath,
  8619. renderInteractiveForms,
  8620. linkService: this.linkService,
  8621. downloadManager: this.downloadManager,
  8622. l10n,
  8623. enableScripting,
  8624. hasJSActionsPromise: hasJSActionsPromise || this.pdfDocument?.hasJSActions(),
  8625. mouseState: mouseState || this._scriptingManager?.mouseState
  8626. });
  8627. }
  8628. createXfaLayerBuilder(pageDiv, pdfPage) {
  8629. return new _xfa_layer_builder.XfaLayerBuilder({
  8630. pageDiv,
  8631. pdfPage
  8632. });
  8633. }
  8634. get hasEqualPageSizes() {
  8635. const firstPageView = this._pages[0];
  8636. for (let i = 1, ii = this._pages.length; i < ii; ++i) {
  8637. const pageView = this._pages[i];
  8638. if (pageView.width !== firstPageView.width || pageView.height !== firstPageView.height) {
  8639. return false;
  8640. }
  8641. }
  8642. return true;
  8643. }
  8644. getPagesOverview() {
  8645. return this._pages.map(pageView => {
  8646. const viewport = pageView.pdfPage.getViewport({
  8647. scale: 1
  8648. });
  8649. if (!this.enablePrintAutoRotate || (0, _ui_utils.isPortraitOrientation)(viewport)) {
  8650. return {
  8651. width: viewport.width,
  8652. height: viewport.height,
  8653. rotation: viewport.rotation
  8654. };
  8655. }
  8656. return {
  8657. width: viewport.height,
  8658. height: viewport.width,
  8659. rotation: (viewport.rotation - 90) % 360
  8660. };
  8661. });
  8662. }
  8663. get optionalContentConfigPromise() {
  8664. if (!this.pdfDocument) {
  8665. return Promise.resolve(null);
  8666. }
  8667. if (!this._optionalContentConfigPromise) {
  8668. return this.pdfDocument.getOptionalContentConfig();
  8669. }
  8670. return this._optionalContentConfigPromise;
  8671. }
  8672. set optionalContentConfigPromise(promise) {
  8673. if (!(promise instanceof Promise)) {
  8674. throw new Error(`Invalid optionalContentConfigPromise: ${promise}`);
  8675. }
  8676. if (!this.pdfDocument) {
  8677. return;
  8678. }
  8679. if (!this._optionalContentConfigPromise) {
  8680. return;
  8681. }
  8682. this._optionalContentConfigPromise = promise;
  8683. for (const pageView of this._pages) {
  8684. pageView.update(pageView.scale, pageView.rotation, promise);
  8685. }
  8686. this.update();
  8687. this.eventBus.dispatch("optionalcontentconfigchanged", {
  8688. source: this,
  8689. promise
  8690. });
  8691. }
  8692. get scrollMode() {
  8693. return this._scrollMode;
  8694. }
  8695. set scrollMode(mode) {
  8696. if (this._scrollMode === mode) {
  8697. return;
  8698. }
  8699. if (!(0, _ui_utils.isValidScrollMode)(mode)) {
  8700. throw new Error(`Invalid scroll mode: ${mode}`);
  8701. }
  8702. this._scrollMode = mode;
  8703. this.eventBus.dispatch("scrollmodechanged", {
  8704. source: this,
  8705. mode
  8706. });
  8707. this._updateScrollMode(this._currentPageNumber);
  8708. }
  8709. _updateScrollMode(pageNumber = null) {
  8710. const scrollMode = this._scrollMode,
  8711. viewer = this.viewer;
  8712. viewer.classList.toggle("scrollHorizontal", scrollMode === _ui_utils.ScrollMode.HORIZONTAL);
  8713. viewer.classList.toggle("scrollWrapped", scrollMode === _ui_utils.ScrollMode.WRAPPED);
  8714. if (!this.pdfDocument || !pageNumber) {
  8715. return;
  8716. }
  8717. if (this._currentScaleValue && isNaN(this._currentScaleValue)) {
  8718. this._setScale(this._currentScaleValue, true);
  8719. }
  8720. this._setCurrentPageNumber(pageNumber, true);
  8721. this.update();
  8722. }
  8723. get spreadMode() {
  8724. return this._spreadMode;
  8725. }
  8726. set spreadMode(mode) {
  8727. if (this._spreadMode === mode) {
  8728. return;
  8729. }
  8730. if (!(0, _ui_utils.isValidSpreadMode)(mode)) {
  8731. throw new Error(`Invalid spread mode: ${mode}`);
  8732. }
  8733. this._spreadMode = mode;
  8734. this.eventBus.dispatch("spreadmodechanged", {
  8735. source: this,
  8736. mode
  8737. });
  8738. this._updateSpreadMode(this._currentPageNumber);
  8739. }
  8740. _updateSpreadMode(pageNumber = null) {
  8741. if (!this.pdfDocument) {
  8742. return;
  8743. }
  8744. const viewer = this.viewer,
  8745. pages = this._pages;
  8746. viewer.textContent = "";
  8747. if (this._spreadMode === _ui_utils.SpreadMode.NONE) {
  8748. for (let i = 0, iMax = pages.length; i < iMax; ++i) {
  8749. viewer.appendChild(pages[i].div);
  8750. }
  8751. } else {
  8752. const parity = this._spreadMode - 1;
  8753. let spread = null;
  8754. for (let i = 0, iMax = pages.length; i < iMax; ++i) {
  8755. if (spread === null) {
  8756. spread = document.createElement("div");
  8757. spread.className = "spread";
  8758. viewer.appendChild(spread);
  8759. } else if (i % 2 === parity) {
  8760. spread = spread.cloneNode(false);
  8761. viewer.appendChild(spread);
  8762. }
  8763. spread.appendChild(pages[i].div);
  8764. }
  8765. }
  8766. if (!pageNumber) {
  8767. return;
  8768. }
  8769. if (this._currentScaleValue && isNaN(this._currentScaleValue)) {
  8770. this._setScale(this._currentScaleValue, true);
  8771. }
  8772. this._setCurrentPageNumber(pageNumber, true);
  8773. this.update();
  8774. }
  8775. _getPageAdvance(currentPageNumber, previous = false) {
  8776. if (this.isInPresentationMode) {
  8777. return 1;
  8778. }
  8779. switch (this._scrollMode) {
  8780. case _ui_utils.ScrollMode.WRAPPED:
  8781. {
  8782. const {
  8783. views
  8784. } = this._getVisiblePages(),
  8785. pageLayout = new Map();
  8786. for (const {
  8787. id,
  8788. y,
  8789. percent,
  8790. widthPercent
  8791. } of views) {
  8792. if (percent === 0 || widthPercent < 100) {
  8793. continue;
  8794. }
  8795. let yArray = pageLayout.get(y);
  8796. if (!yArray) {
  8797. pageLayout.set(y, yArray || (yArray = []));
  8798. }
  8799. yArray.push(id);
  8800. }
  8801. for (const yArray of pageLayout.values()) {
  8802. const currentIndex = yArray.indexOf(currentPageNumber);
  8803. if (currentIndex === -1) {
  8804. continue;
  8805. }
  8806. const numPages = yArray.length;
  8807. if (numPages === 1) {
  8808. break;
  8809. }
  8810. if (previous) {
  8811. for (let i = currentIndex - 1, ii = 0; i >= ii; i--) {
  8812. const currentId = yArray[i],
  8813. expectedId = yArray[i + 1] - 1;
  8814. if (currentId < expectedId) {
  8815. return currentPageNumber - expectedId;
  8816. }
  8817. }
  8818. } else {
  8819. for (let i = currentIndex + 1, ii = numPages; i < ii; i++) {
  8820. const currentId = yArray[i],
  8821. expectedId = yArray[i - 1] + 1;
  8822. if (currentId > expectedId) {
  8823. return expectedId - currentPageNumber;
  8824. }
  8825. }
  8826. }
  8827. if (previous) {
  8828. const firstId = yArray[0];
  8829. if (firstId < currentPageNumber) {
  8830. return currentPageNumber - firstId + 1;
  8831. }
  8832. } else {
  8833. const lastId = yArray[numPages - 1];
  8834. if (lastId > currentPageNumber) {
  8835. return lastId - currentPageNumber + 1;
  8836. }
  8837. }
  8838. break;
  8839. }
  8840. break;
  8841. }
  8842. case _ui_utils.ScrollMode.HORIZONTAL:
  8843. {
  8844. break;
  8845. }
  8846. case _ui_utils.ScrollMode.VERTICAL:
  8847. {
  8848. if (this._spreadMode === _ui_utils.SpreadMode.NONE) {
  8849. break;
  8850. }
  8851. const parity = this._spreadMode - 1;
  8852. if (previous && currentPageNumber % 2 !== parity) {
  8853. break;
  8854. } else if (!previous && currentPageNumber % 2 === parity) {
  8855. break;
  8856. }
  8857. const {
  8858. views
  8859. } = this._getVisiblePages(),
  8860. expectedId = previous ? currentPageNumber - 1 : currentPageNumber + 1;
  8861. for (const {
  8862. id,
  8863. percent,
  8864. widthPercent
  8865. } of views) {
  8866. if (id !== expectedId) {
  8867. continue;
  8868. }
  8869. if (percent > 0 && widthPercent === 100) {
  8870. return 2;
  8871. }
  8872. break;
  8873. }
  8874. break;
  8875. }
  8876. }
  8877. return 1;
  8878. }
  8879. nextPage() {
  8880. const currentPageNumber = this._currentPageNumber,
  8881. pagesCount = this.pagesCount;
  8882. if (currentPageNumber >= pagesCount) {
  8883. return false;
  8884. }
  8885. const advance = this._getPageAdvance(currentPageNumber, false) || 1;
  8886. this.currentPageNumber = Math.min(currentPageNumber + advance, pagesCount);
  8887. return true;
  8888. }
  8889. previousPage() {
  8890. const currentPageNumber = this._currentPageNumber;
  8891. if (currentPageNumber <= 1) {
  8892. return false;
  8893. }
  8894. const advance = this._getPageAdvance(currentPageNumber, true) || 1;
  8895. this.currentPageNumber = Math.max(currentPageNumber - advance, 1);
  8896. return true;
  8897. }
  8898. }
  8899. exports.BaseViewer = BaseViewer;
  8900. /***/ }),
  8901. /* 29 */
  8902. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  8903. Object.defineProperty(exports, "__esModule", ({
  8904. value: true
  8905. }));
  8906. exports.DefaultAnnotationLayerFactory = exports.AnnotationLayerBuilder = void 0;
  8907. var _pdfjsLib = __webpack_require__(5);
  8908. var _l10n_utils = __webpack_require__(30);
  8909. var _pdf_link_service = __webpack_require__(19);
  8910. class AnnotationLayerBuilder {
  8911. constructor({
  8912. pageDiv,
  8913. pdfPage,
  8914. linkService,
  8915. downloadManager,
  8916. annotationStorage = null,
  8917. imageResourcesPath = "",
  8918. renderInteractiveForms = true,
  8919. l10n = _l10n_utils.NullL10n,
  8920. enableScripting = false,
  8921. hasJSActionsPromise = null,
  8922. mouseState = null
  8923. }) {
  8924. this.pageDiv = pageDiv;
  8925. this.pdfPage = pdfPage;
  8926. this.linkService = linkService;
  8927. this.downloadManager = downloadManager;
  8928. this.imageResourcesPath = imageResourcesPath;
  8929. this.renderInteractiveForms = renderInteractiveForms;
  8930. this.l10n = l10n;
  8931. this.annotationStorage = annotationStorage;
  8932. this.enableScripting = enableScripting;
  8933. this._hasJSActionsPromise = hasJSActionsPromise;
  8934. this._mouseState = mouseState;
  8935. this.div = null;
  8936. this._cancelled = false;
  8937. }
  8938. render(viewport, intent = "display") {
  8939. return Promise.all([this.pdfPage.getAnnotations({
  8940. intent
  8941. }), this._hasJSActionsPromise]).then(([annotations, hasJSActions = false]) => {
  8942. if (this._cancelled) {
  8943. return;
  8944. }
  8945. if (annotations.length === 0) {
  8946. return;
  8947. }
  8948. const parameters = {
  8949. viewport: viewport.clone({
  8950. dontFlip: true
  8951. }),
  8952. div: this.div,
  8953. annotations,
  8954. page: this.pdfPage,
  8955. imageResourcesPath: this.imageResourcesPath,
  8956. renderInteractiveForms: this.renderInteractiveForms,
  8957. linkService: this.linkService,
  8958. downloadManager: this.downloadManager,
  8959. annotationStorage: this.annotationStorage,
  8960. enableScripting: this.enableScripting,
  8961. hasJSActions,
  8962. mouseState: this._mouseState
  8963. };
  8964. if (this.div) {
  8965. _pdfjsLib.AnnotationLayer.update(parameters);
  8966. } else {
  8967. this.div = document.createElement("div");
  8968. this.div.className = "annotationLayer";
  8969. this.pageDiv.appendChild(this.div);
  8970. parameters.div = this.div;
  8971. _pdfjsLib.AnnotationLayer.render(parameters);
  8972. this.l10n.translate(this.div);
  8973. }
  8974. });
  8975. }
  8976. cancel() {
  8977. this._cancelled = true;
  8978. }
  8979. hide() {
  8980. if (!this.div) {
  8981. return;
  8982. }
  8983. this.div.hidden = true;
  8984. }
  8985. }
  8986. exports.AnnotationLayerBuilder = AnnotationLayerBuilder;
  8987. class DefaultAnnotationLayerFactory {
  8988. createAnnotationLayerBuilder(pageDiv, pdfPage, annotationStorage = null, imageResourcesPath = "", renderInteractiveForms = true, l10n = _l10n_utils.NullL10n, enableScripting = false, hasJSActionsPromise = null, mouseState = null) {
  8989. return new AnnotationLayerBuilder({
  8990. pageDiv,
  8991. pdfPage,
  8992. imageResourcesPath,
  8993. renderInteractiveForms,
  8994. linkService: new _pdf_link_service.SimpleLinkService(),
  8995. l10n,
  8996. annotationStorage,
  8997. enableScripting,
  8998. hasJSActionsPromise,
  8999. mouseState
  9000. });
  9001. }
  9002. }
  9003. exports.DefaultAnnotationLayerFactory = DefaultAnnotationLayerFactory;
  9004. /***/ }),
  9005. /* 30 */
  9006. /***/ ((__unused_webpack_module, exports) => {
  9007. Object.defineProperty(exports, "__esModule", ({
  9008. value: true
  9009. }));
  9010. exports.getL10nFallback = getL10nFallback;
  9011. exports.NullL10n = void 0;
  9012. const DEFAULT_L10N_STRINGS = {
  9013. of_pages: "of {{pagesCount}}",
  9014. page_of_pages: "({{pageNumber}} of {{pagesCount}})",
  9015. document_properties_kb: "{{size_kb}} KB ({{size_b}} bytes)",
  9016. document_properties_mb: "{{size_mb}} MB ({{size_b}} bytes)",
  9017. document_properties_date_string: "{{date}}, {{time}}",
  9018. document_properties_page_size_unit_inches: "in",
  9019. document_properties_page_size_unit_millimeters: "mm",
  9020. document_properties_page_size_orientation_portrait: "portrait",
  9021. document_properties_page_size_orientation_landscape: "landscape",
  9022. document_properties_page_size_name_a3: "A3",
  9023. document_properties_page_size_name_a4: "A4",
  9024. document_properties_page_size_name_letter: "Letter",
  9025. document_properties_page_size_name_legal: "Legal",
  9026. document_properties_page_size_dimension_string: "{{width}} × {{height}} {{unit}} ({{orientation}})",
  9027. document_properties_page_size_dimension_name_string: "{{width}} × {{height}} {{unit}} ({{name}}, {{orientation}})",
  9028. document_properties_linearized_yes: "Yes",
  9029. document_properties_linearized_no: "No",
  9030. print_progress_percent: "{{progress}}%",
  9031. "toggle_sidebar.title": "Toggle Sidebar",
  9032. "toggle_sidebar_notification2.title": "Toggle Sidebar (document contains outline/attachments/layers)",
  9033. additional_layers: "Additional Layers",
  9034. page_landmark: "Page {{page}}",
  9035. thumb_page_title: "Page {{page}}",
  9036. thumb_page_canvas: "Thumbnail of Page {{page}}",
  9037. find_reached_top: "Reached top of document, continued from bottom",
  9038. find_reached_bottom: "Reached end of document, continued from top",
  9039. "find_match_count[one]": "{{current}} of {{total}} match",
  9040. "find_match_count[other]": "{{current}} of {{total}} matches",
  9041. "find_match_count_limit[one]": "More than {{limit}} match",
  9042. "find_match_count_limit[other]": "More than {{limit}} matches",
  9043. find_not_found: "Phrase not found",
  9044. error_version_info: "PDF.js v{{version}} (build: {{build}})",
  9045. error_message: "Message: {{message}}",
  9046. error_stack: "Stack: {{stack}}",
  9047. error_file: "File: {{file}}",
  9048. error_line: "Line: {{line}}",
  9049. rendering_error: "An error occurred while rendering the page.",
  9050. page_scale_width: "Page Width",
  9051. page_scale_fit: "Page Fit",
  9052. page_scale_auto: "Automatic Zoom",
  9053. page_scale_actual: "Actual Size",
  9054. page_scale_percent: "{{scale}}%",
  9055. loading: "Loading…",
  9056. loading_error: "An error occurred while loading the PDF.",
  9057. invalid_file_error: "Invalid or corrupted PDF file.",
  9058. missing_file_error: "Missing PDF file.",
  9059. unexpected_response_error: "Unexpected server response.",
  9060. printing_not_supported: "Warning: Printing is not fully supported by this browser.",
  9061. printing_not_ready: "Warning: The PDF is not fully loaded for printing.",
  9062. web_fonts_disabled: "Web fonts are disabled: unable to use embedded PDF fonts."
  9063. };
  9064. function getL10nFallback(key, args) {
  9065. switch (key) {
  9066. case "find_match_count":
  9067. key = `find_match_count[${args.total === 1 ? "one" : "other"}]`;
  9068. break;
  9069. case "find_match_count_limit":
  9070. key = `find_match_count_limit[${args.limit === 1 ? "one" : "other"}]`;
  9071. break;
  9072. }
  9073. return DEFAULT_L10N_STRINGS[key] || "";
  9074. }
  9075. function formatL10nValue(text, args) {
  9076. if (!args) {
  9077. return text;
  9078. }
  9079. return text.replace(/\{\{\s*(\w+)\s*\}\}/g, (all, name) => {
  9080. return name in args ? args[name] : "{{" + name + "}}";
  9081. });
  9082. }
  9083. const NullL10n = {
  9084. async getLanguage() {
  9085. return "en-us";
  9086. },
  9087. async getDirection() {
  9088. return "ltr";
  9089. },
  9090. async get(key, args = null, fallback = getL10nFallback(key, args)) {
  9091. return formatL10nValue(fallback, args);
  9092. },
  9093. async translate(element) {}
  9094. };
  9095. exports.NullL10n = NullL10n;
  9096. /***/ }),
  9097. /* 31 */
  9098. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  9099. Object.defineProperty(exports, "__esModule", ({
  9100. value: true
  9101. }));
  9102. exports.PDFPageView = void 0;
  9103. var _ui_utils = __webpack_require__(4);
  9104. var _pdfjsLib = __webpack_require__(5);
  9105. var _l10n_utils = __webpack_require__(30);
  9106. var _pdf_rendering_queue = __webpack_require__(8);
  9107. var _viewer_compatibility = __webpack_require__(2);
  9108. const MAX_CANVAS_PIXELS = _viewer_compatibility.viewerCompatibilityParams.maxCanvasPixels || 16777216;
  9109. class PDFPageView {
  9110. constructor(options) {
  9111. const container = options.container;
  9112. const defaultViewport = options.defaultViewport;
  9113. this.id = options.id;
  9114. this.renderingId = "page" + this.id;
  9115. this.pdfPage = null;
  9116. this.pageLabel = null;
  9117. this.rotation = 0;
  9118. this.scale = options.scale || _ui_utils.DEFAULT_SCALE;
  9119. this.viewport = defaultViewport;
  9120. this.pdfPageRotate = defaultViewport.rotation;
  9121. this._optionalContentConfigPromise = options.optionalContentConfigPromise || null;
  9122. this.hasRestrictedScaling = false;
  9123. this.textLayerMode = Number.isInteger(options.textLayerMode) ? options.textLayerMode : _ui_utils.TextLayerMode.ENABLE;
  9124. this.imageResourcesPath = options.imageResourcesPath || "";
  9125. this.renderInteractiveForms = options.renderInteractiveForms !== false;
  9126. this.useOnlyCssZoom = options.useOnlyCssZoom || false;
  9127. this.maxCanvasPixels = options.maxCanvasPixels || MAX_CANVAS_PIXELS;
  9128. this.eventBus = options.eventBus;
  9129. this.renderingQueue = options.renderingQueue;
  9130. this.textLayerFactory = options.textLayerFactory;
  9131. this.annotationLayerFactory = options.annotationLayerFactory;
  9132. this.xfaLayerFactory = options.xfaLayerFactory;
  9133. this.renderer = options.renderer || _ui_utils.RendererType.CANVAS;
  9134. this.enableWebGL = options.enableWebGL || false;
  9135. this.l10n = options.l10n || _l10n_utils.NullL10n;
  9136. this.enableScripting = options.enableScripting === true;
  9137. this.paintTask = null;
  9138. this.paintedViewportMap = new WeakMap();
  9139. this.renderingState = _pdf_rendering_queue.RenderingStates.INITIAL;
  9140. this.resume = null;
  9141. this._renderError = null;
  9142. this.annotationLayer = null;
  9143. this.textLayer = null;
  9144. this.zoomLayer = null;
  9145. this.xfaLayer = null;
  9146. const div = document.createElement("div");
  9147. div.className = "page";
  9148. div.style.width = Math.floor(this.viewport.width) + "px";
  9149. div.style.height = Math.floor(this.viewport.height) + "px";
  9150. div.setAttribute("data-page-number", this.id);
  9151. div.setAttribute("role", "region");
  9152. this.l10n.get("page_landmark", {
  9153. page: this.id
  9154. }).then(msg => {
  9155. div.setAttribute("aria-label", msg);
  9156. });
  9157. this.div = div;
  9158. container.appendChild(div);
  9159. }
  9160. setPdfPage(pdfPage) {
  9161. this.pdfPage = pdfPage;
  9162. this.pdfPageRotate = pdfPage.rotate;
  9163. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  9164. this.viewport = pdfPage.getViewport({
  9165. scale: this.scale * _ui_utils.CSS_UNITS,
  9166. rotation: totalRotation
  9167. });
  9168. this.reset();
  9169. }
  9170. destroy() {
  9171. this.reset();
  9172. if (this.pdfPage) {
  9173. this.pdfPage.cleanup();
  9174. }
  9175. }
  9176. async _renderAnnotationLayer() {
  9177. let error = null;
  9178. try {
  9179. await this.annotationLayer.render(this.viewport, "display");
  9180. } catch (ex) {
  9181. error = ex;
  9182. } finally {
  9183. this.eventBus.dispatch("annotationlayerrendered", {
  9184. source: this,
  9185. pageNumber: this.id,
  9186. error
  9187. });
  9188. }
  9189. }
  9190. async _renderXfaLayer() {
  9191. let error = null;
  9192. try {
  9193. await this.xfaLayer.render(this.viewport, "display");
  9194. } catch (ex) {
  9195. error = ex;
  9196. } finally {
  9197. this.eventBus.dispatch("xfalayerrendered", {
  9198. source: this,
  9199. pageNumber: this.id,
  9200. error
  9201. });
  9202. }
  9203. }
  9204. _resetZoomLayer(removeFromDOM = false) {
  9205. if (!this.zoomLayer) {
  9206. return;
  9207. }
  9208. const zoomLayerCanvas = this.zoomLayer.firstChild;
  9209. this.paintedViewportMap.delete(zoomLayerCanvas);
  9210. zoomLayerCanvas.width = 0;
  9211. zoomLayerCanvas.height = 0;
  9212. if (removeFromDOM) {
  9213. this.zoomLayer.remove();
  9214. }
  9215. this.zoomLayer = null;
  9216. }
  9217. reset(keepZoomLayer = false, keepAnnotations = false) {
  9218. this.cancelRendering(keepAnnotations);
  9219. this.renderingState = _pdf_rendering_queue.RenderingStates.INITIAL;
  9220. const div = this.div;
  9221. div.style.width = Math.floor(this.viewport.width) + "px";
  9222. div.style.height = Math.floor(this.viewport.height) + "px";
  9223. const childNodes = div.childNodes;
  9224. const currentZoomLayerNode = keepZoomLayer && this.zoomLayer || null;
  9225. const currentAnnotationNode = keepAnnotations && this.annotationLayer?.div || null;
  9226. const currentXfaLayerNode = this.xfaLayer?.div || null;
  9227. for (let i = childNodes.length - 1; i >= 0; i--) {
  9228. const node = childNodes[i];
  9229. if (currentZoomLayerNode === node || currentAnnotationNode === node || currentXfaLayerNode === node) {
  9230. continue;
  9231. }
  9232. div.removeChild(node);
  9233. }
  9234. div.removeAttribute("data-loaded");
  9235. if (currentAnnotationNode) {
  9236. this.annotationLayer.hide();
  9237. } else if (this.annotationLayer) {
  9238. this.annotationLayer.cancel();
  9239. this.annotationLayer = null;
  9240. }
  9241. if (!currentZoomLayerNode) {
  9242. if (this.canvas) {
  9243. this.paintedViewportMap.delete(this.canvas);
  9244. this.canvas.width = 0;
  9245. this.canvas.height = 0;
  9246. delete this.canvas;
  9247. }
  9248. this._resetZoomLayer();
  9249. }
  9250. if (this.svg) {
  9251. this.paintedViewportMap.delete(this.svg);
  9252. delete this.svg;
  9253. }
  9254. this.loadingIconDiv = document.createElement("div");
  9255. this.loadingIconDiv.className = "loadingIcon";
  9256. this.loadingIconDiv.setAttribute("role", "img");
  9257. this.l10n.get("loading").then(msg => {
  9258. this.loadingIconDiv?.setAttribute("aria-label", msg);
  9259. });
  9260. div.appendChild(this.loadingIconDiv);
  9261. }
  9262. update(scale, rotation, optionalContentConfigPromise = null) {
  9263. this.scale = scale || this.scale;
  9264. if (typeof rotation !== "undefined") {
  9265. this.rotation = rotation;
  9266. }
  9267. if (optionalContentConfigPromise instanceof Promise) {
  9268. this._optionalContentConfigPromise = optionalContentConfigPromise;
  9269. }
  9270. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  9271. this.viewport = this.viewport.clone({
  9272. scale: this.scale * _ui_utils.CSS_UNITS,
  9273. rotation: totalRotation
  9274. });
  9275. if (this.svg) {
  9276. this.cssTransform(this.svg, true);
  9277. this.eventBus.dispatch("pagerendered", {
  9278. source: this,
  9279. pageNumber: this.id,
  9280. cssTransform: true,
  9281. timestamp: performance.now(),
  9282. error: this._renderError
  9283. });
  9284. return;
  9285. }
  9286. let isScalingRestricted = false;
  9287. if (this.canvas && this.maxCanvasPixels > 0) {
  9288. const outputScale = this.outputScale;
  9289. if ((Math.floor(this.viewport.width) * outputScale.sx | 0) * (Math.floor(this.viewport.height) * outputScale.sy | 0) > this.maxCanvasPixels) {
  9290. isScalingRestricted = true;
  9291. }
  9292. }
  9293. if (this.canvas) {
  9294. if (this.useOnlyCssZoom || this.hasRestrictedScaling && isScalingRestricted) {
  9295. this.cssTransform(this.canvas, true);
  9296. this.eventBus.dispatch("pagerendered", {
  9297. source: this,
  9298. pageNumber: this.id,
  9299. cssTransform: true,
  9300. timestamp: performance.now(),
  9301. error: this._renderError
  9302. });
  9303. return;
  9304. }
  9305. if (!this.zoomLayer && !this.canvas.hidden) {
  9306. this.zoomLayer = this.canvas.parentNode;
  9307. this.zoomLayer.style.position = "absolute";
  9308. }
  9309. }
  9310. if (this.zoomLayer) {
  9311. this.cssTransform(this.zoomLayer.firstChild);
  9312. }
  9313. this.reset(true, true);
  9314. }
  9315. cancelRendering(keepAnnotations = false) {
  9316. if (this.paintTask) {
  9317. this.paintTask.cancel();
  9318. this.paintTask = null;
  9319. }
  9320. this.resume = null;
  9321. if (this.textLayer) {
  9322. this.textLayer.cancel();
  9323. this.textLayer = null;
  9324. }
  9325. if (!keepAnnotations && this.annotationLayer) {
  9326. this.annotationLayer.cancel();
  9327. this.annotationLayer = null;
  9328. }
  9329. }
  9330. cssTransform(target, redrawAnnotations = false) {
  9331. const width = this.viewport.width;
  9332. const height = this.viewport.height;
  9333. const div = this.div;
  9334. target.style.width = target.parentNode.style.width = div.style.width = Math.floor(width) + "px";
  9335. target.style.height = target.parentNode.style.height = div.style.height = Math.floor(height) + "px";
  9336. const relativeRotation = this.viewport.rotation - this.paintedViewportMap.get(target).rotation;
  9337. const absRotation = Math.abs(relativeRotation);
  9338. let scaleX = 1,
  9339. scaleY = 1;
  9340. if (absRotation === 90 || absRotation === 270) {
  9341. scaleX = height / width;
  9342. scaleY = width / height;
  9343. }
  9344. target.style.transform = `rotate(${relativeRotation}deg) scale(${scaleX}, ${scaleY})`;
  9345. if (this.textLayer) {
  9346. const textLayerViewport = this.textLayer.viewport;
  9347. const textRelativeRotation = this.viewport.rotation - textLayerViewport.rotation;
  9348. const textAbsRotation = Math.abs(textRelativeRotation);
  9349. let scale = width / textLayerViewport.width;
  9350. if (textAbsRotation === 90 || textAbsRotation === 270) {
  9351. scale = width / textLayerViewport.height;
  9352. }
  9353. const textLayerDiv = this.textLayer.textLayerDiv;
  9354. let transX, transY;
  9355. switch (textAbsRotation) {
  9356. case 0:
  9357. transX = transY = 0;
  9358. break;
  9359. case 90:
  9360. transX = 0;
  9361. transY = "-" + textLayerDiv.style.height;
  9362. break;
  9363. case 180:
  9364. transX = "-" + textLayerDiv.style.width;
  9365. transY = "-" + textLayerDiv.style.height;
  9366. break;
  9367. case 270:
  9368. transX = "-" + textLayerDiv.style.width;
  9369. transY = 0;
  9370. break;
  9371. default:
  9372. console.error("Bad rotation value.");
  9373. break;
  9374. }
  9375. textLayerDiv.style.transform = `rotate(${textAbsRotation}deg) ` + `scale(${scale}) ` + `translate(${transX}, ${transY})`;
  9376. textLayerDiv.style.transformOrigin = "0% 0%";
  9377. }
  9378. if (redrawAnnotations && this.annotationLayer) {
  9379. this._renderAnnotationLayer();
  9380. }
  9381. if (this.xfaLayer) {
  9382. this._renderXfaLayer();
  9383. }
  9384. }
  9385. get width() {
  9386. return this.viewport.width;
  9387. }
  9388. get height() {
  9389. return this.viewport.height;
  9390. }
  9391. getPagePoint(x, y) {
  9392. return this.viewport.convertToPdfPoint(x, y);
  9393. }
  9394. draw() {
  9395. if (this.renderingState !== _pdf_rendering_queue.RenderingStates.INITIAL) {
  9396. console.error("Must be in new state before drawing");
  9397. this.reset();
  9398. }
  9399. const {
  9400. div,
  9401. pdfPage
  9402. } = this;
  9403. if (!pdfPage) {
  9404. this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
  9405. if (this.loadingIconDiv) {
  9406. div.removeChild(this.loadingIconDiv);
  9407. delete this.loadingIconDiv;
  9408. }
  9409. return Promise.reject(new Error("pdfPage is not loaded"));
  9410. }
  9411. this.renderingState = _pdf_rendering_queue.RenderingStates.RUNNING;
  9412. const canvasWrapper = document.createElement("div");
  9413. canvasWrapper.style.width = div.style.width;
  9414. canvasWrapper.style.height = div.style.height;
  9415. canvasWrapper.classList.add("canvasWrapper");
  9416. if (this.annotationLayer?.div) {
  9417. div.insertBefore(canvasWrapper, this.annotationLayer.div);
  9418. } else {
  9419. div.appendChild(canvasWrapper);
  9420. }
  9421. let textLayer = null;
  9422. if (this.textLayerMode !== _ui_utils.TextLayerMode.DISABLE && this.textLayerFactory) {
  9423. const textLayerDiv = document.createElement("div");
  9424. textLayerDiv.className = "textLayer";
  9425. textLayerDiv.style.width = canvasWrapper.style.width;
  9426. textLayerDiv.style.height = canvasWrapper.style.height;
  9427. if (this.annotationLayer?.div) {
  9428. div.insertBefore(textLayerDiv, this.annotationLayer.div);
  9429. } else {
  9430. div.appendChild(textLayerDiv);
  9431. }
  9432. textLayer = this.textLayerFactory.createTextLayerBuilder(textLayerDiv, this.id - 1, this.viewport, this.textLayerMode === _ui_utils.TextLayerMode.ENABLE_ENHANCE, this.eventBus);
  9433. }
  9434. this.textLayer = textLayer;
  9435. let renderContinueCallback = null;
  9436. if (this.renderingQueue) {
  9437. renderContinueCallback = cont => {
  9438. if (!this.renderingQueue.isHighestPriority(this)) {
  9439. this.renderingState = _pdf_rendering_queue.RenderingStates.PAUSED;
  9440. this.resume = () => {
  9441. this.renderingState = _pdf_rendering_queue.RenderingStates.RUNNING;
  9442. cont();
  9443. };
  9444. return;
  9445. }
  9446. cont();
  9447. };
  9448. }
  9449. const finishPaintTask = async (error = null) => {
  9450. if (paintTask === this.paintTask) {
  9451. this.paintTask = null;
  9452. }
  9453. if (error instanceof _pdfjsLib.RenderingCancelledException) {
  9454. this._renderError = null;
  9455. return;
  9456. }
  9457. this._renderError = error;
  9458. this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
  9459. if (this.loadingIconDiv) {
  9460. div.removeChild(this.loadingIconDiv);
  9461. delete this.loadingIconDiv;
  9462. }
  9463. this._resetZoomLayer(true);
  9464. this.eventBus.dispatch("pagerendered", {
  9465. source: this,
  9466. pageNumber: this.id,
  9467. cssTransform: false,
  9468. timestamp: performance.now(),
  9469. error: this._renderError
  9470. });
  9471. if (error) {
  9472. throw error;
  9473. }
  9474. };
  9475. const paintTask = this.renderer === _ui_utils.RendererType.SVG ? this.paintOnSvg(canvasWrapper) : this.paintOnCanvas(canvasWrapper);
  9476. paintTask.onRenderContinue = renderContinueCallback;
  9477. this.paintTask = paintTask;
  9478. const resultPromise = paintTask.promise.then(function () {
  9479. return finishPaintTask(null).then(function () {
  9480. if (textLayer) {
  9481. const readableStream = pdfPage.streamTextContent({
  9482. normalizeWhitespace: true
  9483. });
  9484. textLayer.setTextContentStream(readableStream);
  9485. textLayer.render();
  9486. }
  9487. });
  9488. }, function (reason) {
  9489. return finishPaintTask(reason);
  9490. });
  9491. if (this.annotationLayerFactory) {
  9492. if (!this.annotationLayer) {
  9493. this.annotationLayer = this.annotationLayerFactory.createAnnotationLayerBuilder(div, pdfPage, null, this.imageResourcesPath, this.renderInteractiveForms, this.l10n, this.enableScripting, null, null);
  9494. }
  9495. this._renderAnnotationLayer();
  9496. }
  9497. if (this.xfaLayerFactory) {
  9498. if (!this.xfaLayer) {
  9499. this.xfaLayer = this.xfaLayerFactory.createXfaLayerBuilder(div, pdfPage);
  9500. }
  9501. this._renderXfaLayer();
  9502. }
  9503. div.setAttribute("data-loaded", true);
  9504. this.eventBus.dispatch("pagerender", {
  9505. source: this,
  9506. pageNumber: this.id
  9507. });
  9508. return resultPromise;
  9509. }
  9510. paintOnCanvas(canvasWrapper) {
  9511. const renderCapability = (0, _pdfjsLib.createPromiseCapability)();
  9512. const result = {
  9513. promise: renderCapability.promise,
  9514. onRenderContinue(cont) {
  9515. cont();
  9516. },
  9517. cancel() {
  9518. renderTask.cancel();
  9519. }
  9520. };
  9521. const viewport = this.viewport;
  9522. const canvas = document.createElement("canvas");
  9523. canvas.hidden = true;
  9524. let isCanvasHidden = true;
  9525. const showCanvas = function () {
  9526. if (isCanvasHidden) {
  9527. canvas.hidden = false;
  9528. isCanvasHidden = false;
  9529. }
  9530. };
  9531. canvasWrapper.appendChild(canvas);
  9532. this.canvas = canvas;
  9533. canvas.mozOpaque = true;
  9534. const ctx = canvas.getContext("2d", {
  9535. alpha: false
  9536. });
  9537. const outputScale = (0, _ui_utils.getOutputScale)(ctx);
  9538. this.outputScale = outputScale;
  9539. if (this.useOnlyCssZoom) {
  9540. const actualSizeViewport = viewport.clone({
  9541. scale: _ui_utils.CSS_UNITS
  9542. });
  9543. outputScale.sx *= actualSizeViewport.width / viewport.width;
  9544. outputScale.sy *= actualSizeViewport.height / viewport.height;
  9545. outputScale.scaled = true;
  9546. }
  9547. if (this.maxCanvasPixels > 0) {
  9548. const pixelsInViewport = viewport.width * viewport.height;
  9549. const maxScale = Math.sqrt(this.maxCanvasPixels / pixelsInViewport);
  9550. if (outputScale.sx > maxScale || outputScale.sy > maxScale) {
  9551. outputScale.sx = maxScale;
  9552. outputScale.sy = maxScale;
  9553. outputScale.scaled = true;
  9554. this.hasRestrictedScaling = true;
  9555. } else {
  9556. this.hasRestrictedScaling = false;
  9557. }
  9558. }
  9559. const sfx = (0, _ui_utils.approximateFraction)(outputScale.sx);
  9560. const sfy = (0, _ui_utils.approximateFraction)(outputScale.sy);
  9561. canvas.width = (0, _ui_utils.roundToDivide)(viewport.width * outputScale.sx, sfx[0]);
  9562. canvas.height = (0, _ui_utils.roundToDivide)(viewport.height * outputScale.sy, sfy[0]);
  9563. canvas.style.width = (0, _ui_utils.roundToDivide)(viewport.width, sfx[1]) + "px";
  9564. canvas.style.height = (0, _ui_utils.roundToDivide)(viewport.height, sfy[1]) + "px";
  9565. this.paintedViewportMap.set(canvas, viewport);
  9566. const transform = !outputScale.scaled ? null : [outputScale.sx, 0, 0, outputScale.sy, 0, 0];
  9567. const renderContext = {
  9568. canvasContext: ctx,
  9569. transform,
  9570. viewport: this.viewport,
  9571. enableWebGL: this.enableWebGL,
  9572. renderInteractiveForms: this.renderInteractiveForms,
  9573. optionalContentConfigPromise: this._optionalContentConfigPromise
  9574. };
  9575. const renderTask = this.pdfPage.render(renderContext);
  9576. renderTask.onContinue = function (cont) {
  9577. showCanvas();
  9578. if (result.onRenderContinue) {
  9579. result.onRenderContinue(cont);
  9580. } else {
  9581. cont();
  9582. }
  9583. };
  9584. renderTask.promise.then(function () {
  9585. showCanvas();
  9586. renderCapability.resolve(undefined);
  9587. }, function (error) {
  9588. showCanvas();
  9589. renderCapability.reject(error);
  9590. });
  9591. return result;
  9592. }
  9593. paintOnSvg(wrapper) {
  9594. let cancelled = false;
  9595. const ensureNotCancelled = () => {
  9596. if (cancelled) {
  9597. throw new _pdfjsLib.RenderingCancelledException(`Rendering cancelled, page ${this.id}`, "svg");
  9598. }
  9599. };
  9600. const pdfPage = this.pdfPage;
  9601. const actualSizeViewport = this.viewport.clone({
  9602. scale: _ui_utils.CSS_UNITS
  9603. });
  9604. const promise = pdfPage.getOperatorList().then(opList => {
  9605. ensureNotCancelled();
  9606. const svgGfx = new _pdfjsLib.SVGGraphics(pdfPage.commonObjs, pdfPage.objs, _viewer_compatibility.viewerCompatibilityParams.disableCreateObjectURL);
  9607. return svgGfx.getSVG(opList, actualSizeViewport).then(svg => {
  9608. ensureNotCancelled();
  9609. this.svg = svg;
  9610. this.paintedViewportMap.set(svg, actualSizeViewport);
  9611. svg.style.width = wrapper.style.width;
  9612. svg.style.height = wrapper.style.height;
  9613. this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
  9614. wrapper.appendChild(svg);
  9615. });
  9616. });
  9617. return {
  9618. promise,
  9619. onRenderContinue(cont) {
  9620. cont();
  9621. },
  9622. cancel() {
  9623. cancelled = true;
  9624. }
  9625. };
  9626. }
  9627. setPageLabel(label) {
  9628. this.pageLabel = typeof label === "string" ? label : null;
  9629. if (this.pageLabel !== null) {
  9630. this.div.setAttribute("data-page-label", this.pageLabel);
  9631. } else {
  9632. this.div.removeAttribute("data-page-label");
  9633. }
  9634. }
  9635. }
  9636. exports.PDFPageView = PDFPageView;
  9637. /***/ }),
  9638. /* 32 */
  9639. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  9640. Object.defineProperty(exports, "__esModule", ({
  9641. value: true
  9642. }));
  9643. exports.TextLayerBuilder = exports.DefaultTextLayerFactory = void 0;
  9644. var _pdfjsLib = __webpack_require__(5);
  9645. const EXPAND_DIVS_TIMEOUT = 300;
  9646. class TextLayerBuilder {
  9647. constructor({
  9648. textLayerDiv,
  9649. eventBus,
  9650. pageIndex,
  9651. viewport,
  9652. findController = null,
  9653. enhanceTextSelection = false
  9654. }) {
  9655. this.textLayerDiv = textLayerDiv;
  9656. this.eventBus = eventBus;
  9657. this.textContent = null;
  9658. this.textContentItemsStr = [];
  9659. this.textContentStream = null;
  9660. this.renderingDone = false;
  9661. this.pageIdx = pageIndex;
  9662. this.pageNumber = this.pageIdx + 1;
  9663. this.matches = [];
  9664. this.viewport = viewport;
  9665. this.textDivs = [];
  9666. this.findController = findController;
  9667. this.textLayerRenderTask = null;
  9668. this.enhanceTextSelection = enhanceTextSelection;
  9669. this._onUpdateTextLayerMatches = null;
  9670. this._bindMouse();
  9671. }
  9672. _finishRendering() {
  9673. this.renderingDone = true;
  9674. if (!this.enhanceTextSelection) {
  9675. const endOfContent = document.createElement("div");
  9676. endOfContent.className = "endOfContent";
  9677. this.textLayerDiv.appendChild(endOfContent);
  9678. }
  9679. this.eventBus.dispatch("textlayerrendered", {
  9680. source: this,
  9681. pageNumber: this.pageNumber,
  9682. numTextDivs: this.textDivs.length
  9683. });
  9684. }
  9685. render(timeout = 0) {
  9686. if (!(this.textContent || this.textContentStream) || this.renderingDone) {
  9687. return;
  9688. }
  9689. this.cancel();
  9690. this.textDivs = [];
  9691. const textLayerFrag = document.createDocumentFragment();
  9692. this.textLayerRenderTask = (0, _pdfjsLib.renderTextLayer)({
  9693. textContent: this.textContent,
  9694. textContentStream: this.textContentStream,
  9695. container: textLayerFrag,
  9696. viewport: this.viewport,
  9697. textDivs: this.textDivs,
  9698. textContentItemsStr: this.textContentItemsStr,
  9699. timeout,
  9700. enhanceTextSelection: this.enhanceTextSelection
  9701. });
  9702. this.textLayerRenderTask.promise.then(() => {
  9703. this.textLayerDiv.appendChild(textLayerFrag);
  9704. this._finishRendering();
  9705. this._updateMatches();
  9706. }, function (reason) {});
  9707. if (!this._onUpdateTextLayerMatches) {
  9708. this._onUpdateTextLayerMatches = evt => {
  9709. if (evt.pageIndex === this.pageIdx || evt.pageIndex === -1) {
  9710. this._updateMatches();
  9711. }
  9712. };
  9713. this.eventBus._on("updatetextlayermatches", this._onUpdateTextLayerMatches);
  9714. }
  9715. }
  9716. cancel() {
  9717. if (this.textLayerRenderTask) {
  9718. this.textLayerRenderTask.cancel();
  9719. this.textLayerRenderTask = null;
  9720. }
  9721. if (this._onUpdateTextLayerMatches) {
  9722. this.eventBus._off("updatetextlayermatches", this._onUpdateTextLayerMatches);
  9723. this._onUpdateTextLayerMatches = null;
  9724. }
  9725. }
  9726. setTextContentStream(readableStream) {
  9727. this.cancel();
  9728. this.textContentStream = readableStream;
  9729. }
  9730. setTextContent(textContent) {
  9731. this.cancel();
  9732. this.textContent = textContent;
  9733. }
  9734. _convertMatches(matches, matchesLength) {
  9735. if (!matches) {
  9736. return [];
  9737. }
  9738. const {
  9739. textContentItemsStr
  9740. } = this;
  9741. let i = 0,
  9742. iIndex = 0;
  9743. const end = textContentItemsStr.length - 1;
  9744. const result = [];
  9745. for (let m = 0, mm = matches.length; m < mm; m++) {
  9746. let matchIdx = matches[m];
  9747. while (i !== end && matchIdx >= iIndex + textContentItemsStr[i].length) {
  9748. iIndex += textContentItemsStr[i].length;
  9749. i++;
  9750. }
  9751. if (i === textContentItemsStr.length) {
  9752. console.error("Could not find a matching mapping");
  9753. }
  9754. const match = {
  9755. begin: {
  9756. divIdx: i,
  9757. offset: matchIdx - iIndex
  9758. }
  9759. };
  9760. matchIdx += matchesLength[m];
  9761. while (i !== end && matchIdx > iIndex + textContentItemsStr[i].length) {
  9762. iIndex += textContentItemsStr[i].length;
  9763. i++;
  9764. }
  9765. match.end = {
  9766. divIdx: i,
  9767. offset: matchIdx - iIndex
  9768. };
  9769. result.push(match);
  9770. }
  9771. return result;
  9772. }
  9773. _renderMatches(matches) {
  9774. if (matches.length === 0) {
  9775. return;
  9776. }
  9777. const {
  9778. findController,
  9779. pageIdx,
  9780. textContentItemsStr,
  9781. textDivs
  9782. } = this;
  9783. const isSelectedPage = pageIdx === findController.selected.pageIdx;
  9784. const selectedMatchIdx = findController.selected.matchIdx;
  9785. const highlightAll = findController.state.highlightAll;
  9786. let prevEnd = null;
  9787. const infinity = {
  9788. divIdx: -1,
  9789. offset: undefined
  9790. };
  9791. function beginText(begin, className) {
  9792. const divIdx = begin.divIdx;
  9793. textDivs[divIdx].textContent = "";
  9794. appendTextToDiv(divIdx, 0, begin.offset, className);
  9795. }
  9796. function appendTextToDiv(divIdx, fromOffset, toOffset, className) {
  9797. const div = textDivs[divIdx];
  9798. const content = textContentItemsStr[divIdx].substring(fromOffset, toOffset);
  9799. const node = document.createTextNode(content);
  9800. if (className) {
  9801. const span = document.createElement("span");
  9802. span.className = className;
  9803. span.appendChild(node);
  9804. div.appendChild(span);
  9805. return;
  9806. }
  9807. div.appendChild(node);
  9808. }
  9809. let i0 = selectedMatchIdx,
  9810. i1 = i0 + 1;
  9811. if (highlightAll) {
  9812. i0 = 0;
  9813. i1 = matches.length;
  9814. } else if (!isSelectedPage) {
  9815. return;
  9816. }
  9817. for (let i = i0; i < i1; i++) {
  9818. const match = matches[i];
  9819. const begin = match.begin;
  9820. const end = match.end;
  9821. const isSelected = isSelectedPage && i === selectedMatchIdx;
  9822. const highlightSuffix = isSelected ? " selected" : "";
  9823. if (isSelected) {
  9824. findController.scrollMatchIntoView({
  9825. element: textDivs[begin.divIdx],
  9826. pageIndex: pageIdx,
  9827. matchIndex: selectedMatchIdx
  9828. });
  9829. }
  9830. if (!prevEnd || begin.divIdx !== prevEnd.divIdx) {
  9831. if (prevEnd !== null) {
  9832. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset);
  9833. }
  9834. beginText(begin);
  9835. } else {
  9836. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, begin.offset);
  9837. }
  9838. if (begin.divIdx === end.divIdx) {
  9839. appendTextToDiv(begin.divIdx, begin.offset, end.offset, "highlight" + highlightSuffix);
  9840. } else {
  9841. appendTextToDiv(begin.divIdx, begin.offset, infinity.offset, "highlight begin" + highlightSuffix);
  9842. for (let n0 = begin.divIdx + 1, n1 = end.divIdx; n0 < n1; n0++) {
  9843. textDivs[n0].className = "highlight middle" + highlightSuffix;
  9844. }
  9845. beginText(end, "highlight end" + highlightSuffix);
  9846. }
  9847. prevEnd = end;
  9848. }
  9849. if (prevEnd) {
  9850. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset);
  9851. }
  9852. }
  9853. _updateMatches() {
  9854. if (!this.renderingDone) {
  9855. return;
  9856. }
  9857. const {
  9858. findController,
  9859. matches,
  9860. pageIdx,
  9861. textContentItemsStr,
  9862. textDivs
  9863. } = this;
  9864. let clearedUntilDivIdx = -1;
  9865. for (let i = 0, ii = matches.length; i < ii; i++) {
  9866. const match = matches[i];
  9867. const begin = Math.max(clearedUntilDivIdx, match.begin.divIdx);
  9868. for (let n = begin, end = match.end.divIdx; n <= end; n++) {
  9869. const div = textDivs[n];
  9870. div.textContent = textContentItemsStr[n];
  9871. div.className = "";
  9872. }
  9873. clearedUntilDivIdx = match.end.divIdx + 1;
  9874. }
  9875. if (!findController?.highlightMatches) {
  9876. return;
  9877. }
  9878. const pageMatches = findController.pageMatches[pageIdx] || null;
  9879. const pageMatchesLength = findController.pageMatchesLength[pageIdx] || null;
  9880. this.matches = this._convertMatches(pageMatches, pageMatchesLength);
  9881. this._renderMatches(this.matches);
  9882. }
  9883. _bindMouse() {
  9884. const div = this.textLayerDiv;
  9885. let expandDivsTimer = null;
  9886. div.addEventListener("mousedown", evt => {
  9887. if (this.enhanceTextSelection && this.textLayerRenderTask) {
  9888. this.textLayerRenderTask.expandTextDivs(true);
  9889. if (expandDivsTimer) {
  9890. clearTimeout(expandDivsTimer);
  9891. expandDivsTimer = null;
  9892. }
  9893. return;
  9894. }
  9895. const end = div.querySelector(".endOfContent");
  9896. if (!end) {
  9897. return;
  9898. }
  9899. let adjustTop = evt.target !== div;
  9900. adjustTop = adjustTop && window.getComputedStyle(end).getPropertyValue("-moz-user-select") !== "none";
  9901. if (adjustTop) {
  9902. const divBounds = div.getBoundingClientRect();
  9903. const r = Math.max(0, (evt.pageY - divBounds.top) / divBounds.height);
  9904. end.style.top = (r * 100).toFixed(2) + "%";
  9905. }
  9906. end.classList.add("active");
  9907. });
  9908. div.addEventListener("mouseup", () => {
  9909. if (this.enhanceTextSelection && this.textLayerRenderTask) {
  9910. expandDivsTimer = setTimeout(() => {
  9911. if (this.textLayerRenderTask) {
  9912. this.textLayerRenderTask.expandTextDivs(false);
  9913. }
  9914. expandDivsTimer = null;
  9915. }, EXPAND_DIVS_TIMEOUT);
  9916. return;
  9917. }
  9918. const end = div.querySelector(".endOfContent");
  9919. if (!end) {
  9920. return;
  9921. }
  9922. end.style.top = "";
  9923. end.classList.remove("active");
  9924. });
  9925. }
  9926. }
  9927. exports.TextLayerBuilder = TextLayerBuilder;
  9928. class DefaultTextLayerFactory {
  9929. createTextLayerBuilder(textLayerDiv, pageIndex, viewport, enhanceTextSelection = false, eventBus) {
  9930. return new TextLayerBuilder({
  9931. textLayerDiv,
  9932. pageIndex,
  9933. viewport,
  9934. enhanceTextSelection,
  9935. eventBus
  9936. });
  9937. }
  9938. }
  9939. exports.DefaultTextLayerFactory = DefaultTextLayerFactory;
  9940. /***/ }),
  9941. /* 33 */
  9942. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  9943. Object.defineProperty(exports, "__esModule", ({
  9944. value: true
  9945. }));
  9946. exports.XfaLayerBuilder = exports.DefaultXfaLayerFactory = void 0;
  9947. var _pdfjsLib = __webpack_require__(5);
  9948. class XfaLayerBuilder {
  9949. constructor({
  9950. pageDiv,
  9951. pdfPage
  9952. }) {
  9953. this.pageDiv = pageDiv;
  9954. this.pdfPage = pdfPage;
  9955. this.div = null;
  9956. this._cancelled = false;
  9957. }
  9958. render(viewport, intent = "display") {
  9959. return this.pdfPage.getXfa().then(xfa => {
  9960. if (this._cancelled) {
  9961. return;
  9962. }
  9963. const parameters = {
  9964. viewport: viewport.clone({
  9965. dontFlip: true
  9966. }),
  9967. div: this.div,
  9968. xfa,
  9969. page: this.pdfPage
  9970. };
  9971. if (this.div) {
  9972. _pdfjsLib.XfaLayer.update(parameters);
  9973. } else {
  9974. this.div = document.createElement("div");
  9975. this.pageDiv.appendChild(this.div);
  9976. parameters.div = this.div;
  9977. _pdfjsLib.XfaLayer.render(parameters);
  9978. }
  9979. });
  9980. }
  9981. cancel() {
  9982. this._cancelled = true;
  9983. }
  9984. hide() {
  9985. if (!this.div) {
  9986. return;
  9987. }
  9988. this.div.hidden = true;
  9989. }
  9990. }
  9991. exports.XfaLayerBuilder = XfaLayerBuilder;
  9992. class DefaultXfaLayerFactory {
  9993. createXfaLayerBuilder(pageDiv, pdfPage) {
  9994. return new XfaLayerBuilder({
  9995. pageDiv,
  9996. pdfPage
  9997. });
  9998. }
  9999. }
  10000. exports.DefaultXfaLayerFactory = DefaultXfaLayerFactory;
  10001. /***/ }),
  10002. /* 34 */
  10003. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10004. Object.defineProperty(exports, "__esModule", ({
  10005. value: true
  10006. }));
  10007. exports.SecondaryToolbar = void 0;
  10008. var _ui_utils = __webpack_require__(4);
  10009. var _pdf_cursor_tools = __webpack_require__(6);
  10010. var _pdf_single_page_viewer = __webpack_require__(35);
  10011. class SecondaryToolbar {
  10012. constructor(options, mainContainer, eventBus) {
  10013. this.toolbar = options.toolbar;
  10014. this.toggleButton = options.toggleButton;
  10015. this.toolbarButtonContainer = options.toolbarButtonContainer;
  10016. this.buttons = [{
  10017. element: options.presentationModeButton,
  10018. eventName: "presentationmode",
  10019. close: true
  10020. }, {
  10021. element: options.openFileButton,
  10022. eventName: "openfile",
  10023. close: true
  10024. }, {
  10025. element: options.printButton,
  10026. eventName: "print",
  10027. close: true
  10028. }, {
  10029. element: options.downloadButton,
  10030. eventName: "download",
  10031. close: true
  10032. }, {
  10033. element: options.viewBookmarkButton,
  10034. eventName: null,
  10035. close: true
  10036. }, {
  10037. element: options.firstPageButton,
  10038. eventName: "firstpage",
  10039. close: true
  10040. }, {
  10041. element: options.lastPageButton,
  10042. eventName: "lastpage",
  10043. close: true
  10044. }, {
  10045. element: options.pageRotateCwButton,
  10046. eventName: "rotatecw",
  10047. close: false
  10048. }, {
  10049. element: options.pageRotateCcwButton,
  10050. eventName: "rotateccw",
  10051. close: false
  10052. }, {
  10053. element: options.cursorSelectToolButton,
  10054. eventName: "switchcursortool",
  10055. eventDetails: {
  10056. tool: _pdf_cursor_tools.CursorTool.SELECT
  10057. },
  10058. close: true
  10059. }, {
  10060. element: options.cursorHandToolButton,
  10061. eventName: "switchcursortool",
  10062. eventDetails: {
  10063. tool: _pdf_cursor_tools.CursorTool.HAND
  10064. },
  10065. close: true
  10066. }, {
  10067. element: options.scrollVerticalButton,
  10068. eventName: "switchscrollmode",
  10069. eventDetails: {
  10070. mode: _ui_utils.ScrollMode.VERTICAL
  10071. },
  10072. close: true
  10073. }, {
  10074. element: options.scrollHorizontalButton,
  10075. eventName: "switchscrollmode",
  10076. eventDetails: {
  10077. mode: _ui_utils.ScrollMode.HORIZONTAL
  10078. },
  10079. close: true
  10080. }, {
  10081. element: options.scrollWrappedButton,
  10082. eventName: "switchscrollmode",
  10083. eventDetails: {
  10084. mode: _ui_utils.ScrollMode.WRAPPED
  10085. },
  10086. close: true
  10087. }, {
  10088. element: options.spreadNoneButton,
  10089. eventName: "switchspreadmode",
  10090. eventDetails: {
  10091. mode: _ui_utils.SpreadMode.NONE
  10092. },
  10093. close: true
  10094. }, {
  10095. element: options.spreadOddButton,
  10096. eventName: "switchspreadmode",
  10097. eventDetails: {
  10098. mode: _ui_utils.SpreadMode.ODD
  10099. },
  10100. close: true
  10101. }, {
  10102. element: options.spreadEvenButton,
  10103. eventName: "switchspreadmode",
  10104. eventDetails: {
  10105. mode: _ui_utils.SpreadMode.EVEN
  10106. },
  10107. close: true
  10108. }, {
  10109. element: options.documentPropertiesButton,
  10110. eventName: "documentproperties",
  10111. close: true
  10112. }];
  10113. this.items = {
  10114. firstPage: options.firstPageButton,
  10115. lastPage: options.lastPageButton,
  10116. pageRotateCw: options.pageRotateCwButton,
  10117. pageRotateCcw: options.pageRotateCcwButton
  10118. };
  10119. this.mainContainer = mainContainer;
  10120. this.eventBus = eventBus;
  10121. this.opened = false;
  10122. this.containerHeight = null;
  10123. this.previousContainerHeight = null;
  10124. this.reset();
  10125. this._bindClickListeners();
  10126. this._bindCursorToolsListener(options);
  10127. this._bindScrollModeListener(options);
  10128. this._bindSpreadModeListener(options);
  10129. this.eventBus._on("resize", this._setMaxHeight.bind(this));
  10130. this.eventBus._on("baseviewerinit", evt => {
  10131. if (evt.source instanceof _pdf_single_page_viewer.PDFSinglePageViewer) {
  10132. this.toolbarButtonContainer.classList.add("hiddenScrollModeButtons", "hiddenSpreadModeButtons");
  10133. } else {
  10134. this.toolbarButtonContainer.classList.remove("hiddenScrollModeButtons", "hiddenSpreadModeButtons");
  10135. }
  10136. });
  10137. }
  10138. get isOpen() {
  10139. return this.opened;
  10140. }
  10141. setPageNumber(pageNumber) {
  10142. this.pageNumber = pageNumber;
  10143. this._updateUIState();
  10144. }
  10145. setPagesCount(pagesCount) {
  10146. this.pagesCount = pagesCount;
  10147. this._updateUIState();
  10148. }
  10149. reset() {
  10150. this.pageNumber = 0;
  10151. this.pagesCount = 0;
  10152. this._updateUIState();
  10153. this.eventBus.dispatch("secondarytoolbarreset", {
  10154. source: this
  10155. });
  10156. }
  10157. _updateUIState() {
  10158. this.items.firstPage.disabled = this.pageNumber <= 1;
  10159. this.items.lastPage.disabled = this.pageNumber >= this.pagesCount;
  10160. this.items.pageRotateCw.disabled = this.pagesCount === 0;
  10161. this.items.pageRotateCcw.disabled = this.pagesCount === 0;
  10162. }
  10163. _bindClickListeners() {
  10164. this.toggleButton.addEventListener("click", this.toggle.bind(this));
  10165. for (const {
  10166. element,
  10167. eventName,
  10168. close,
  10169. eventDetails
  10170. } of this.buttons) {
  10171. element.addEventListener("click", evt => {
  10172. if (eventName !== null) {
  10173. const details = {
  10174. source: this
  10175. };
  10176. for (const property in eventDetails) {
  10177. details[property] = eventDetails[property];
  10178. }
  10179. this.eventBus.dispatch(eventName, details);
  10180. }
  10181. if (close) {
  10182. this.close();
  10183. }
  10184. });
  10185. }
  10186. }
  10187. _bindCursorToolsListener(buttons) {
  10188. this.eventBus._on("cursortoolchanged", function ({
  10189. tool
  10190. }) {
  10191. buttons.cursorSelectToolButton.classList.toggle("toggled", tool === _pdf_cursor_tools.CursorTool.SELECT);
  10192. buttons.cursorHandToolButton.classList.toggle("toggled", tool === _pdf_cursor_tools.CursorTool.HAND);
  10193. });
  10194. }
  10195. _bindScrollModeListener(buttons) {
  10196. function scrollModeChanged({
  10197. mode
  10198. }) {
  10199. buttons.scrollVerticalButton.classList.toggle("toggled", mode === _ui_utils.ScrollMode.VERTICAL);
  10200. buttons.scrollHorizontalButton.classList.toggle("toggled", mode === _ui_utils.ScrollMode.HORIZONTAL);
  10201. buttons.scrollWrappedButton.classList.toggle("toggled", mode === _ui_utils.ScrollMode.WRAPPED);
  10202. const isScrollModeHorizontal = mode === _ui_utils.ScrollMode.HORIZONTAL;
  10203. buttons.spreadNoneButton.disabled = isScrollModeHorizontal;
  10204. buttons.spreadOddButton.disabled = isScrollModeHorizontal;
  10205. buttons.spreadEvenButton.disabled = isScrollModeHorizontal;
  10206. }
  10207. this.eventBus._on("scrollmodechanged", scrollModeChanged);
  10208. this.eventBus._on("secondarytoolbarreset", evt => {
  10209. if (evt.source === this) {
  10210. scrollModeChanged({
  10211. mode: _ui_utils.ScrollMode.VERTICAL
  10212. });
  10213. }
  10214. });
  10215. }
  10216. _bindSpreadModeListener(buttons) {
  10217. function spreadModeChanged({
  10218. mode
  10219. }) {
  10220. buttons.spreadNoneButton.classList.toggle("toggled", mode === _ui_utils.SpreadMode.NONE);
  10221. buttons.spreadOddButton.classList.toggle("toggled", mode === _ui_utils.SpreadMode.ODD);
  10222. buttons.spreadEvenButton.classList.toggle("toggled", mode === _ui_utils.SpreadMode.EVEN);
  10223. }
  10224. this.eventBus._on("spreadmodechanged", spreadModeChanged);
  10225. this.eventBus._on("secondarytoolbarreset", evt => {
  10226. if (evt.source === this) {
  10227. spreadModeChanged({
  10228. mode: _ui_utils.SpreadMode.NONE
  10229. });
  10230. }
  10231. });
  10232. }
  10233. open() {
  10234. if (this.opened) {
  10235. return;
  10236. }
  10237. this.opened = true;
  10238. this._setMaxHeight();
  10239. this.toggleButton.classList.add("toggled");
  10240. this.toggleButton.setAttribute("aria-expanded", "true");
  10241. this.toolbar.classList.remove("hidden");
  10242. }
  10243. close() {
  10244. if (!this.opened) {
  10245. return;
  10246. }
  10247. this.opened = false;
  10248. this.toolbar.classList.add("hidden");
  10249. this.toggleButton.classList.remove("toggled");
  10250. this.toggleButton.setAttribute("aria-expanded", "false");
  10251. }
  10252. toggle() {
  10253. if (this.opened) {
  10254. this.close();
  10255. } else {
  10256. this.open();
  10257. }
  10258. }
  10259. _setMaxHeight() {
  10260. if (!this.opened) {
  10261. return;
  10262. }
  10263. this.containerHeight = this.mainContainer.clientHeight;
  10264. if (this.containerHeight === this.previousContainerHeight) {
  10265. return;
  10266. }
  10267. this.toolbarButtonContainer.style.maxHeight = `${this.containerHeight - _ui_utils.SCROLLBAR_PADDING}px`;
  10268. this.previousContainerHeight = this.containerHeight;
  10269. }
  10270. }
  10271. exports.SecondaryToolbar = SecondaryToolbar;
  10272. /***/ }),
  10273. /* 35 */
  10274. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10275. Object.defineProperty(exports, "__esModule", ({
  10276. value: true
  10277. }));
  10278. exports.PDFSinglePageViewer = void 0;
  10279. var _base_viewer = __webpack_require__(28);
  10280. var _pdfjsLib = __webpack_require__(5);
  10281. class PDFSinglePageViewer extends _base_viewer.BaseViewer {
  10282. constructor(options) {
  10283. super(options);
  10284. this.eventBus._on("pagesinit", evt => {
  10285. this._ensurePageViewVisible();
  10286. });
  10287. }
  10288. get _viewerElement() {
  10289. return (0, _pdfjsLib.shadow)(this, "_viewerElement", this._shadowViewer);
  10290. }
  10291. get _pageWidthScaleFactor() {
  10292. return 1;
  10293. }
  10294. _resetView() {
  10295. super._resetView();
  10296. this._previousPageNumber = 1;
  10297. this._shadowViewer = document.createDocumentFragment();
  10298. this._updateScrollDown = null;
  10299. }
  10300. _ensurePageViewVisible() {
  10301. const pageView = this._pages[this._currentPageNumber - 1];
  10302. const previousPageView = this._pages[this._previousPageNumber - 1];
  10303. const viewerNodes = this.viewer.childNodes;
  10304. switch (viewerNodes.length) {
  10305. case 0:
  10306. this.viewer.appendChild(pageView.div);
  10307. break;
  10308. case 1:
  10309. if (viewerNodes[0] !== previousPageView.div) {
  10310. throw new Error("_ensurePageViewVisible: Unexpected previously visible page.");
  10311. }
  10312. if (pageView === previousPageView) {
  10313. break;
  10314. }
  10315. this._shadowViewer.appendChild(previousPageView.div);
  10316. this.viewer.appendChild(pageView.div);
  10317. this.container.scrollTop = 0;
  10318. break;
  10319. default:
  10320. throw new Error("_ensurePageViewVisible: Only one page should be visible at a time.");
  10321. }
  10322. this._previousPageNumber = this._currentPageNumber;
  10323. }
  10324. _scrollUpdate() {
  10325. if (this._updateScrollDown) {
  10326. this._updateScrollDown();
  10327. }
  10328. super._scrollUpdate();
  10329. }
  10330. _scrollIntoView({
  10331. pageDiv,
  10332. pageSpot = null,
  10333. pageNumber = null
  10334. }) {
  10335. if (pageNumber) {
  10336. this._setCurrentPageNumber(pageNumber);
  10337. }
  10338. const scrolledDown = this._currentPageNumber >= this._previousPageNumber;
  10339. this._ensurePageViewVisible();
  10340. this.update();
  10341. super._scrollIntoView({
  10342. pageDiv,
  10343. pageSpot,
  10344. pageNumber
  10345. });
  10346. this._updateScrollDown = () => {
  10347. this.scroll.down = scrolledDown;
  10348. this._updateScrollDown = null;
  10349. };
  10350. }
  10351. _getVisiblePages() {
  10352. return this._getCurrentVisiblePage();
  10353. }
  10354. _updateHelper(visiblePages) {}
  10355. get _isScrollModeHorizontal() {
  10356. return (0, _pdfjsLib.shadow)(this, "_isScrollModeHorizontal", false);
  10357. }
  10358. _updateScrollMode() {}
  10359. _updateSpreadMode() {}
  10360. _getPageAdvance() {
  10361. return 1;
  10362. }
  10363. }
  10364. exports.PDFSinglePageViewer = PDFSinglePageViewer;
  10365. /***/ }),
  10366. /* 36 */
  10367. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10368. Object.defineProperty(exports, "__esModule", ({
  10369. value: true
  10370. }));
  10371. exports.Toolbar = void 0;
  10372. var _ui_utils = __webpack_require__(4);
  10373. const PAGE_NUMBER_LOADING_INDICATOR = "visiblePageIsLoading";
  10374. const SCALE_SELECT_CONTAINER_WIDTH = 140;
  10375. const SCALE_SELECT_WIDTH = 162;
  10376. class Toolbar {
  10377. constructor(options, eventBus, l10n) {
  10378. this.toolbar = options.container;
  10379. this.eventBus = eventBus;
  10380. this.l10n = l10n;
  10381. this.buttons = [{
  10382. element: options.previous,
  10383. eventName: "previouspage"
  10384. }, {
  10385. element: options.next,
  10386. eventName: "nextpage"
  10387. }, {
  10388. element: options.zoomIn,
  10389. eventName: "zoomin"
  10390. }, {
  10391. element: options.zoomOut,
  10392. eventName: "zoomout"
  10393. }, {
  10394. element: options.openFile,
  10395. eventName: "openfile"
  10396. }, {
  10397. element: options.print,
  10398. eventName: "print"
  10399. }, {
  10400. element: options.presentationModeButton,
  10401. eventName: "presentationmode"
  10402. }, {
  10403. element: options.download,
  10404. eventName: "download"
  10405. }, {
  10406. element: options.viewBookmark,
  10407. eventName: null
  10408. }];
  10409. this.items = {
  10410. numPages: options.numPages,
  10411. pageNumber: options.pageNumber,
  10412. scaleSelectContainer: options.scaleSelectContainer,
  10413. scaleSelect: options.scaleSelect,
  10414. customScaleOption: options.customScaleOption,
  10415. previous: options.previous,
  10416. next: options.next,
  10417. zoomIn: options.zoomIn,
  10418. zoomOut: options.zoomOut
  10419. };
  10420. this._wasLocalized = false;
  10421. this.reset();
  10422. this._bindListeners();
  10423. }
  10424. setPageNumber(pageNumber, pageLabel) {
  10425. this.pageNumber = pageNumber;
  10426. this.pageLabel = pageLabel;
  10427. this._updateUIState(false);
  10428. }
  10429. setPagesCount(pagesCount, hasPageLabels) {
  10430. this.pagesCount = pagesCount;
  10431. this.hasPageLabels = hasPageLabels;
  10432. this._updateUIState(true);
  10433. }
  10434. setPageScale(pageScaleValue, pageScale) {
  10435. this.pageScaleValue = (pageScaleValue || pageScale).toString();
  10436. this.pageScale = pageScale;
  10437. this._updateUIState(false);
  10438. }
  10439. reset() {
  10440. this.pageNumber = 0;
  10441. this.pageLabel = null;
  10442. this.hasPageLabels = false;
  10443. this.pagesCount = 0;
  10444. this.pageScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  10445. this.pageScale = _ui_utils.DEFAULT_SCALE;
  10446. this._updateUIState(true);
  10447. this.updateLoadingIndicatorState();
  10448. }
  10449. _bindListeners() {
  10450. const {
  10451. pageNumber,
  10452. scaleSelect
  10453. } = this.items;
  10454. const self = this;
  10455. for (const {
  10456. element,
  10457. eventName
  10458. } of this.buttons) {
  10459. element.addEventListener("click", evt => {
  10460. if (eventName !== null) {
  10461. this.eventBus.dispatch(eventName, {
  10462. source: this
  10463. });
  10464. }
  10465. });
  10466. }
  10467. pageNumber.addEventListener("click", function () {
  10468. this.select();
  10469. });
  10470. pageNumber.addEventListener("change", function () {
  10471. self.eventBus.dispatch("pagenumberchanged", {
  10472. source: self,
  10473. value: this.value
  10474. });
  10475. });
  10476. scaleSelect.addEventListener("change", function () {
  10477. if (this.value === "custom") {
  10478. return;
  10479. }
  10480. self.eventBus.dispatch("scalechanged", {
  10481. source: self,
  10482. value: this.value
  10483. });
  10484. });
  10485. scaleSelect.oncontextmenu = _ui_utils.noContextMenuHandler;
  10486. this.eventBus._on("localized", () => {
  10487. this._wasLocalized = true;
  10488. this._adjustScaleWidth();
  10489. this._updateUIState(true);
  10490. });
  10491. }
  10492. _updateUIState(resetNumPages = false) {
  10493. if (!this._wasLocalized) {
  10494. return;
  10495. }
  10496. const {
  10497. pageNumber,
  10498. pagesCount,
  10499. pageScaleValue,
  10500. pageScale,
  10501. items
  10502. } = this;
  10503. if (resetNumPages) {
  10504. if (this.hasPageLabels) {
  10505. items.pageNumber.type = "text";
  10506. } else {
  10507. items.pageNumber.type = "number";
  10508. this.l10n.get("of_pages", {
  10509. pagesCount
  10510. }).then(msg => {
  10511. items.numPages.textContent = msg;
  10512. });
  10513. }
  10514. items.pageNumber.max = pagesCount;
  10515. }
  10516. if (this.hasPageLabels) {
  10517. items.pageNumber.value = this.pageLabel;
  10518. this.l10n.get("page_of_pages", {
  10519. pageNumber,
  10520. pagesCount
  10521. }).then(msg => {
  10522. items.numPages.textContent = msg;
  10523. });
  10524. } else {
  10525. items.pageNumber.value = pageNumber;
  10526. }
  10527. items.previous.disabled = pageNumber <= 1;
  10528. items.next.disabled = pageNumber >= pagesCount;
  10529. items.zoomOut.disabled = pageScale <= _ui_utils.MIN_SCALE;
  10530. items.zoomIn.disabled = pageScale >= _ui_utils.MAX_SCALE;
  10531. this.l10n.get("page_scale_percent", {
  10532. scale: Math.round(pageScale * 10000) / 100
  10533. }).then(msg => {
  10534. let predefinedValueFound = false;
  10535. for (const option of items.scaleSelect.options) {
  10536. if (option.value !== pageScaleValue) {
  10537. option.selected = false;
  10538. continue;
  10539. }
  10540. option.selected = true;
  10541. predefinedValueFound = true;
  10542. }
  10543. if (!predefinedValueFound) {
  10544. items.customScaleOption.textContent = msg;
  10545. items.customScaleOption.selected = true;
  10546. }
  10547. });
  10548. }
  10549. updateLoadingIndicatorState(loading = false) {
  10550. const pageNumberInput = this.items.pageNumber;
  10551. pageNumberInput.classList.toggle(PAGE_NUMBER_LOADING_INDICATOR, loading);
  10552. }
  10553. async _adjustScaleWidth() {
  10554. const {
  10555. items,
  10556. l10n
  10557. } = this;
  10558. const predefinedValuesPromise = Promise.all([l10n.get("page_scale_auto"), l10n.get("page_scale_actual"), l10n.get("page_scale_fit"), l10n.get("page_scale_width")]);
  10559. let canvas = document.createElement("canvas");
  10560. canvas.mozOpaque = true;
  10561. let ctx = canvas.getContext("2d", {
  10562. alpha: false
  10563. });
  10564. await _ui_utils.animationStarted;
  10565. const {
  10566. fontSize,
  10567. fontFamily
  10568. } = getComputedStyle(items.scaleSelect);
  10569. ctx.font = `${fontSize} ${fontFamily}`;
  10570. let maxWidth = 0;
  10571. for (const predefinedValue of await predefinedValuesPromise) {
  10572. const {
  10573. width
  10574. } = ctx.measureText(predefinedValue);
  10575. if (width > maxWidth) {
  10576. maxWidth = width;
  10577. }
  10578. }
  10579. const overflow = SCALE_SELECT_WIDTH - SCALE_SELECT_CONTAINER_WIDTH;
  10580. maxWidth += 2 * overflow;
  10581. if (maxWidth > SCALE_SELECT_CONTAINER_WIDTH) {
  10582. items.scaleSelect.style.width = `${maxWidth + overflow}px`;
  10583. items.scaleSelectContainer.style.width = `${maxWidth}px`;
  10584. }
  10585. canvas.width = 0;
  10586. canvas.height = 0;
  10587. canvas = ctx = null;
  10588. }
  10589. }
  10590. exports.Toolbar = Toolbar;
  10591. /***/ }),
  10592. /* 37 */
  10593. /***/ ((__unused_webpack_module, exports) => {
  10594. Object.defineProperty(exports, "__esModule", ({
  10595. value: true
  10596. }));
  10597. exports.ViewHistory = void 0;
  10598. const DEFAULT_VIEW_HISTORY_CACHE_SIZE = 20;
  10599. class ViewHistory {
  10600. constructor(fingerprint, cacheSize = DEFAULT_VIEW_HISTORY_CACHE_SIZE) {
  10601. this.fingerprint = fingerprint;
  10602. this.cacheSize = cacheSize;
  10603. this._initializedPromise = this._readFromStorage().then(databaseStr => {
  10604. const database = JSON.parse(databaseStr || "{}");
  10605. let index = -1;
  10606. if (!Array.isArray(database.files)) {
  10607. database.files = [];
  10608. } else {
  10609. while (database.files.length >= this.cacheSize) {
  10610. database.files.shift();
  10611. }
  10612. for (let i = 0, ii = database.files.length; i < ii; i++) {
  10613. const branch = database.files[i];
  10614. if (branch.fingerprint === this.fingerprint) {
  10615. index = i;
  10616. break;
  10617. }
  10618. }
  10619. }
  10620. if (index === -1) {
  10621. index = database.files.push({
  10622. fingerprint: this.fingerprint
  10623. }) - 1;
  10624. }
  10625. this.file = database.files[index];
  10626. this.database = database;
  10627. });
  10628. }
  10629. async _writeToStorage() {
  10630. const databaseStr = JSON.stringify(this.database);
  10631. localStorage.setItem("pdfjs.history", databaseStr);
  10632. }
  10633. async _readFromStorage() {
  10634. return localStorage.getItem("pdfjs.history");
  10635. }
  10636. async set(name, val) {
  10637. await this._initializedPromise;
  10638. this.file[name] = val;
  10639. return this._writeToStorage();
  10640. }
  10641. async setMultiple(properties) {
  10642. await this._initializedPromise;
  10643. for (const name in properties) {
  10644. this.file[name] = properties[name];
  10645. }
  10646. return this._writeToStorage();
  10647. }
  10648. async get(name, defaultValue) {
  10649. await this._initializedPromise;
  10650. const val = this.file[name];
  10651. return val !== undefined ? val : defaultValue;
  10652. }
  10653. async getMultiple(properties) {
  10654. await this._initializedPromise;
  10655. const values = Object.create(null);
  10656. for (const name in properties) {
  10657. const val = this.file[name];
  10658. values[name] = val !== undefined ? val : properties[name];
  10659. }
  10660. return values;
  10661. }
  10662. }
  10663. exports.ViewHistory = ViewHistory;
  10664. /***/ }),
  10665. /* 38 */
  10666. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10667. Object.defineProperty(exports, "__esModule", ({
  10668. value: true
  10669. }));
  10670. exports.GenericCom = void 0;
  10671. var _app = __webpack_require__(3);
  10672. var _preferences = __webpack_require__(39);
  10673. var _download_manager = __webpack_require__(40);
  10674. var _genericl10n = __webpack_require__(41);
  10675. var _generic_scripting = __webpack_require__(43);
  10676. ;
  10677. const GenericCom = {};
  10678. exports.GenericCom = GenericCom;
  10679. class GenericPreferences extends _preferences.BasePreferences {
  10680. async _writeToStorage(prefObj) {
  10681. localStorage.setItem("pdfjs.preferences", JSON.stringify(prefObj));
  10682. }
  10683. async _readFromStorage(prefObj) {
  10684. return JSON.parse(localStorage.getItem("pdfjs.preferences"));
  10685. }
  10686. }
  10687. class GenericExternalServices extends _app.DefaultExternalServices {
  10688. static createDownloadManager(options) {
  10689. return new _download_manager.DownloadManager();
  10690. }
  10691. static createPreferences() {
  10692. return new GenericPreferences();
  10693. }
  10694. static createL10n({
  10695. locale = "en-US"
  10696. }) {
  10697. return new _genericl10n.GenericL10n(locale);
  10698. }
  10699. static createScripting({
  10700. sandboxBundleSrc
  10701. }) {
  10702. return new _generic_scripting.GenericScripting(sandboxBundleSrc);
  10703. }
  10704. }
  10705. _app.PDFViewerApplication.externalServices = GenericExternalServices;
  10706. /***/ }),
  10707. /* 39 */
  10708. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10709. Object.defineProperty(exports, "__esModule", ({
  10710. value: true
  10711. }));
  10712. exports.BasePreferences = void 0;
  10713. var _app_options = __webpack_require__(1);
  10714. class BasePreferences {
  10715. constructor() {
  10716. if (this.constructor === BasePreferences) {
  10717. throw new Error("Cannot initialize BasePreferences.");
  10718. }
  10719. Object.defineProperty(this, "defaults", {
  10720. value: Object.freeze({
  10721. "cursorToolOnLoad": 0,
  10722. "defaultZoomValue": "",
  10723. "disablePageLabels": false,
  10724. "enablePermissions": false,
  10725. "enablePrintAutoRotate": true,
  10726. "enableScripting": true,
  10727. "enableWebGL": false,
  10728. "externalLinkTarget": 0,
  10729. "historyUpdateUrl": false,
  10730. "ignoreDestinationZoom": false,
  10731. "pdfBugEnabled": false,
  10732. "renderer": "canvas",
  10733. "renderInteractiveForms": true,
  10734. "sidebarViewOnLoad": -1,
  10735. "scrollModeOnLoad": -1,
  10736. "spreadModeOnLoad": -1,
  10737. "textLayerMode": 1,
  10738. "useOnlyCssZoom": false,
  10739. "viewerCssTheme": 0,
  10740. "viewOnLoad": 0,
  10741. "disableAutoFetch": false,
  10742. "disableFontFace": false,
  10743. "disableRange": false,
  10744. "disableStream": false
  10745. }),
  10746. writable: false,
  10747. enumerable: true,
  10748. configurable: false
  10749. });
  10750. this.prefs = Object.create(null);
  10751. this._initializedPromise = this._readFromStorage(this.defaults).then(prefs => {
  10752. for (const name in this.defaults) {
  10753. const prefValue = prefs?.[name];
  10754. if (typeof prefValue === typeof this.defaults[name]) {
  10755. this.prefs[name] = prefValue;
  10756. }
  10757. }
  10758. });
  10759. }
  10760. async _writeToStorage(prefObj) {
  10761. throw new Error("Not implemented: _writeToStorage");
  10762. }
  10763. async _readFromStorage(prefObj) {
  10764. throw new Error("Not implemented: _readFromStorage");
  10765. }
  10766. async reset() {
  10767. await this._initializedPromise;
  10768. this.prefs = Object.create(null);
  10769. return this._writeToStorage(this.defaults);
  10770. }
  10771. async set(name, value) {
  10772. await this._initializedPromise;
  10773. const defaultValue = this.defaults[name];
  10774. if (defaultValue === undefined) {
  10775. throw new Error(`Set preference: "${name}" is undefined.`);
  10776. } else if (value === undefined) {
  10777. throw new Error("Set preference: no value is specified.");
  10778. }
  10779. const valueType = typeof value;
  10780. const defaultType = typeof defaultValue;
  10781. if (valueType !== defaultType) {
  10782. if (valueType === "number" && defaultType === "string") {
  10783. value = value.toString();
  10784. } else {
  10785. throw new Error(`Set preference: "${value}" is a ${valueType}, expected a ${defaultType}.`);
  10786. }
  10787. } else {
  10788. if (valueType === "number" && !Number.isInteger(value)) {
  10789. throw new Error(`Set preference: "${value}" must be an integer.`);
  10790. }
  10791. }
  10792. this.prefs[name] = value;
  10793. return this._writeToStorage(this.prefs);
  10794. }
  10795. async get(name) {
  10796. await this._initializedPromise;
  10797. const defaultValue = this.defaults[name],
  10798. prefValue = this.prefs[name];
  10799. if (defaultValue === undefined) {
  10800. throw new Error(`Get preference: "${name}" is undefined.`);
  10801. }
  10802. return prefValue !== undefined ? prefValue : defaultValue;
  10803. }
  10804. async getAll() {
  10805. await this._initializedPromise;
  10806. const obj = Object.create(null);
  10807. for (const name in this.defaults) {
  10808. const prefValue = this.prefs[name];
  10809. obj[name] = prefValue !== undefined ? prefValue : this.defaults[name];
  10810. }
  10811. return obj;
  10812. }
  10813. }
  10814. exports.BasePreferences = BasePreferences;
  10815. /***/ }),
  10816. /* 40 */
  10817. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10818. Object.defineProperty(exports, "__esModule", ({
  10819. value: true
  10820. }));
  10821. exports.DownloadManager = void 0;
  10822. var _pdfjsLib = __webpack_require__(5);
  10823. var _viewer_compatibility = __webpack_require__(2);
  10824. ;
  10825. function download(blobUrl, filename) {
  10826. const a = document.createElement("a");
  10827. if (!a.click) {
  10828. throw new Error('DownloadManager: "a.click()" is not supported.');
  10829. }
  10830. a.href = blobUrl;
  10831. a.target = "_parent";
  10832. if ("download" in a) {
  10833. a.download = filename;
  10834. }
  10835. (document.body || document.documentElement).appendChild(a);
  10836. a.click();
  10837. a.remove();
  10838. }
  10839. class DownloadManager {
  10840. constructor() {
  10841. this._openBlobUrls = new WeakMap();
  10842. }
  10843. downloadUrl(url, filename) {
  10844. if (!(0, _pdfjsLib.createValidAbsoluteUrl)(url, "http://example.com")) {
  10845. return;
  10846. }
  10847. download(url + "#pdfjs.action=download", filename);
  10848. }
  10849. downloadData(data, filename, contentType) {
  10850. const blobUrl = (0, _pdfjsLib.createObjectURL)(data, contentType, _viewer_compatibility.viewerCompatibilityParams.disableCreateObjectURL);
  10851. download(blobUrl, filename);
  10852. }
  10853. openOrDownloadData(element, data, filename) {
  10854. const isPdfData = (0, _pdfjsLib.isPdfFile)(filename);
  10855. const contentType = isPdfData ? "application/pdf" : "";
  10856. if (isPdfData && !_viewer_compatibility.viewerCompatibilityParams.disableCreateObjectURL) {
  10857. let blobUrl = this._openBlobUrls.get(element);
  10858. if (!blobUrl) {
  10859. blobUrl = URL.createObjectURL(new Blob([data], {
  10860. type: contentType
  10861. }));
  10862. this._openBlobUrls.set(element, blobUrl);
  10863. }
  10864. let viewerUrl;
  10865. viewerUrl = "?file=" + encodeURIComponent(blobUrl + "#" + filename);
  10866. try {
  10867. window.open(viewerUrl);
  10868. return true;
  10869. } catch (ex) {
  10870. console.error(`openOrDownloadData: ${ex}`);
  10871. URL.revokeObjectURL(blobUrl);
  10872. this._openBlobUrls.delete(element);
  10873. }
  10874. }
  10875. this.downloadData(data, filename, contentType);
  10876. return false;
  10877. }
  10878. download(blob, url, filename, sourceEventType = "download") {
  10879. if (_viewer_compatibility.viewerCompatibilityParams.disableCreateObjectURL) {
  10880. this.downloadUrl(url, filename);
  10881. return;
  10882. }
  10883. const blobUrl = URL.createObjectURL(blob);
  10884. download(blobUrl, filename);
  10885. }
  10886. }
  10887. exports.DownloadManager = DownloadManager;
  10888. /***/ }),
  10889. /* 41 */
  10890. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10891. Object.defineProperty(exports, "__esModule", ({
  10892. value: true
  10893. }));
  10894. exports.GenericL10n = void 0;
  10895. __webpack_require__(42);
  10896. var _l10n_utils = __webpack_require__(30);
  10897. const webL10n = document.webL10n;
  10898. class GenericL10n {
  10899. constructor(lang) {
  10900. this._lang = lang;
  10901. this._ready = new Promise((resolve, reject) => {
  10902. webL10n.setLanguage(lang, () => {
  10903. resolve(webL10n);
  10904. });
  10905. });
  10906. }
  10907. async getLanguage() {
  10908. const l10n = await this._ready;
  10909. return l10n.getLanguage();
  10910. }
  10911. async getDirection() {
  10912. const l10n = await this._ready;
  10913. return l10n.getDirection();
  10914. }
  10915. async get(key, args = null, fallback = (0, _l10n_utils.getL10nFallback)(key, args)) {
  10916. const l10n = await this._ready;
  10917. return l10n.get(key, args, fallback);
  10918. }
  10919. async translate(element) {
  10920. const l10n = await this._ready;
  10921. return l10n.translate(element);
  10922. }
  10923. }
  10924. exports.GenericL10n = GenericL10n;
  10925. /***/ }),
  10926. /* 42 */
  10927. /***/ (() => {
  10928. document.webL10n = function (window, document, undefined) {
  10929. var gL10nData = {};
  10930. var gTextData = '';
  10931. var gTextProp = 'textContent';
  10932. var gLanguage = '';
  10933. var gMacros = {};
  10934. var gReadyState = 'loading';
  10935. var gAsyncResourceLoading = true;
  10936. function getL10nResourceLinks() {
  10937. return document.querySelectorAll('link[type="application/l10n"]');
  10938. }
  10939. function getL10nDictionary() {
  10940. var script = document.querySelector('script[type="application/l10n"]');
  10941. return script ? JSON.parse(script.innerHTML) : null;
  10942. }
  10943. function getTranslatableChildren(element) {
  10944. return element ? element.querySelectorAll('*[data-l10n-id]') : [];
  10945. }
  10946. function getL10nAttributes(element) {
  10947. if (!element) return {};
  10948. var l10nId = element.getAttribute('data-l10n-id');
  10949. var l10nArgs = element.getAttribute('data-l10n-args');
  10950. var args = {};
  10951. if (l10nArgs) {
  10952. try {
  10953. args = JSON.parse(l10nArgs);
  10954. } catch (e) {
  10955. console.warn('could not parse arguments for #' + l10nId);
  10956. }
  10957. }
  10958. return {
  10959. id: l10nId,
  10960. args: args
  10961. };
  10962. }
  10963. function xhrLoadText(url, onSuccess, onFailure) {
  10964. onSuccess = onSuccess || function _onSuccess(data) {};
  10965. onFailure = onFailure || function _onFailure() {};
  10966. var xhr = new XMLHttpRequest();
  10967. xhr.open('GET', url, gAsyncResourceLoading);
  10968. if (xhr.overrideMimeType) {
  10969. xhr.overrideMimeType('text/plain; charset=utf-8');
  10970. }
  10971. xhr.onreadystatechange = function () {
  10972. if (xhr.readyState == 4) {
  10973. if (xhr.status == 200 || xhr.status === 0) {
  10974. onSuccess(xhr.responseText);
  10975. } else {
  10976. onFailure();
  10977. }
  10978. }
  10979. };
  10980. xhr.onerror = onFailure;
  10981. xhr.ontimeout = onFailure;
  10982. try {
  10983. xhr.send(null);
  10984. } catch (e) {
  10985. onFailure();
  10986. }
  10987. }
  10988. function parseResource(href, lang, successCallback, failureCallback) {
  10989. var baseURL = href.replace(/[^\/]*$/, '') || './';
  10990. function evalString(text) {
  10991. if (text.lastIndexOf('\\') < 0) return text;
  10992. 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, "'");
  10993. }
  10994. function parseProperties(text, parsedPropertiesCallback) {
  10995. var dictionary = {};
  10996. var reBlank = /^\s*|\s*$/;
  10997. var reComment = /^\s*#|^\s*$/;
  10998. var reSection = /^\s*\[(.*)\]\s*$/;
  10999. var reImport = /^\s*@import\s+url\((.*)\)\s*$/i;
  11000. var reSplit = /^([^=\s]*)\s*=\s*(.+)$/;
  11001. function parseRawLines(rawText, extendedSyntax, parsedRawLinesCallback) {
  11002. var entries = rawText.replace(reBlank, '').split(/[\r\n]+/);
  11003. var currentLang = '*';
  11004. var genericLang = lang.split('-', 1)[0];
  11005. var skipLang = false;
  11006. var match = '';
  11007. function nextEntry() {
  11008. while (true) {
  11009. if (!entries.length) {
  11010. parsedRawLinesCallback();
  11011. return;
  11012. }
  11013. var line = entries.shift();
  11014. if (reComment.test(line)) continue;
  11015. if (extendedSyntax) {
  11016. match = reSection.exec(line);
  11017. if (match) {
  11018. currentLang = match[1].toLowerCase();
  11019. skipLang = currentLang !== '*' && currentLang !== lang && currentLang !== genericLang;
  11020. continue;
  11021. } else if (skipLang) {
  11022. continue;
  11023. }
  11024. match = reImport.exec(line);
  11025. if (match) {
  11026. loadImport(baseURL + match[1], nextEntry);
  11027. return;
  11028. }
  11029. }
  11030. var tmp = line.match(reSplit);
  11031. if (tmp && tmp.length == 3) {
  11032. dictionary[tmp[1]] = evalString(tmp[2]);
  11033. }
  11034. }
  11035. }
  11036. nextEntry();
  11037. }
  11038. function loadImport(url, callback) {
  11039. xhrLoadText(url, function (content) {
  11040. parseRawLines(content, false, callback);
  11041. }, function () {
  11042. console.warn(url + ' not found.');
  11043. callback();
  11044. });
  11045. }
  11046. parseRawLines(text, true, function () {
  11047. parsedPropertiesCallback(dictionary);
  11048. });
  11049. }
  11050. xhrLoadText(href, function (response) {
  11051. gTextData += response;
  11052. parseProperties(response, function (data) {
  11053. for (var key in data) {
  11054. var id,
  11055. prop,
  11056. index = key.lastIndexOf('.');
  11057. if (index > 0) {
  11058. id = key.substring(0, index);
  11059. prop = key.substring(index + 1);
  11060. } else {
  11061. id = key;
  11062. prop = gTextProp;
  11063. }
  11064. if (!gL10nData[id]) {
  11065. gL10nData[id] = {};
  11066. }
  11067. gL10nData[id][prop] = data[key];
  11068. }
  11069. if (successCallback) {
  11070. successCallback();
  11071. }
  11072. });
  11073. }, failureCallback);
  11074. }
  11075. function loadLocale(lang, callback) {
  11076. if (lang) {
  11077. lang = lang.toLowerCase();
  11078. }
  11079. callback = callback || function _callback() {};
  11080. clear();
  11081. gLanguage = lang;
  11082. var langLinks = getL10nResourceLinks();
  11083. var langCount = langLinks.length;
  11084. if (langCount === 0) {
  11085. var dict = getL10nDictionary();
  11086. if (dict && dict.locales && dict.default_locale) {
  11087. console.log('using the embedded JSON directory, early way out');
  11088. gL10nData = dict.locales[lang];
  11089. if (!gL10nData) {
  11090. var defaultLocale = dict.default_locale.toLowerCase();
  11091. for (var anyCaseLang in dict.locales) {
  11092. anyCaseLang = anyCaseLang.toLowerCase();
  11093. if (anyCaseLang === lang) {
  11094. gL10nData = dict.locales[lang];
  11095. break;
  11096. } else if (anyCaseLang === defaultLocale) {
  11097. gL10nData = dict.locales[defaultLocale];
  11098. }
  11099. }
  11100. }
  11101. callback();
  11102. } else {
  11103. console.log('no resource to load, early way out');
  11104. }
  11105. gReadyState = 'complete';
  11106. return;
  11107. }
  11108. var onResourceLoaded = null;
  11109. var gResourceCount = 0;
  11110. onResourceLoaded = function () {
  11111. gResourceCount++;
  11112. if (gResourceCount >= langCount) {
  11113. callback();
  11114. gReadyState = 'complete';
  11115. }
  11116. };
  11117. function L10nResourceLink(link) {
  11118. var href = link.href;
  11119. this.load = function (lang, callback) {
  11120. parseResource(href, lang, callback, function () {
  11121. console.warn(href + ' not found.');
  11122. console.warn('"' + lang + '" resource not found');
  11123. gLanguage = '';
  11124. callback();
  11125. });
  11126. };
  11127. }
  11128. for (var i = 0; i < langCount; i++) {
  11129. var resource = new L10nResourceLink(langLinks[i]);
  11130. resource.load(lang, onResourceLoaded);
  11131. }
  11132. }
  11133. function clear() {
  11134. gL10nData = {};
  11135. gTextData = '';
  11136. gLanguage = '';
  11137. }
  11138. function getPluralRules(lang) {
  11139. var locales2rules = {
  11140. 'af': 3,
  11141. 'ak': 4,
  11142. 'am': 4,
  11143. 'ar': 1,
  11144. 'asa': 3,
  11145. 'az': 0,
  11146. 'be': 11,
  11147. 'bem': 3,
  11148. 'bez': 3,
  11149. 'bg': 3,
  11150. 'bh': 4,
  11151. 'bm': 0,
  11152. 'bn': 3,
  11153. 'bo': 0,
  11154. 'br': 20,
  11155. 'brx': 3,
  11156. 'bs': 11,
  11157. 'ca': 3,
  11158. 'cgg': 3,
  11159. 'chr': 3,
  11160. 'cs': 12,
  11161. 'cy': 17,
  11162. 'da': 3,
  11163. 'de': 3,
  11164. 'dv': 3,
  11165. 'dz': 0,
  11166. 'ee': 3,
  11167. 'el': 3,
  11168. 'en': 3,
  11169. 'eo': 3,
  11170. 'es': 3,
  11171. 'et': 3,
  11172. 'eu': 3,
  11173. 'fa': 0,
  11174. 'ff': 5,
  11175. 'fi': 3,
  11176. 'fil': 4,
  11177. 'fo': 3,
  11178. 'fr': 5,
  11179. 'fur': 3,
  11180. 'fy': 3,
  11181. 'ga': 8,
  11182. 'gd': 24,
  11183. 'gl': 3,
  11184. 'gsw': 3,
  11185. 'gu': 3,
  11186. 'guw': 4,
  11187. 'gv': 23,
  11188. 'ha': 3,
  11189. 'haw': 3,
  11190. 'he': 2,
  11191. 'hi': 4,
  11192. 'hr': 11,
  11193. 'hu': 0,
  11194. 'id': 0,
  11195. 'ig': 0,
  11196. 'ii': 0,
  11197. 'is': 3,
  11198. 'it': 3,
  11199. 'iu': 7,
  11200. 'ja': 0,
  11201. 'jmc': 3,
  11202. 'jv': 0,
  11203. 'ka': 0,
  11204. 'kab': 5,
  11205. 'kaj': 3,
  11206. 'kcg': 3,
  11207. 'kde': 0,
  11208. 'kea': 0,
  11209. 'kk': 3,
  11210. 'kl': 3,
  11211. 'km': 0,
  11212. 'kn': 0,
  11213. 'ko': 0,
  11214. 'ksb': 3,
  11215. 'ksh': 21,
  11216. 'ku': 3,
  11217. 'kw': 7,
  11218. 'lag': 18,
  11219. 'lb': 3,
  11220. 'lg': 3,
  11221. 'ln': 4,
  11222. 'lo': 0,
  11223. 'lt': 10,
  11224. 'lv': 6,
  11225. 'mas': 3,
  11226. 'mg': 4,
  11227. 'mk': 16,
  11228. 'ml': 3,
  11229. 'mn': 3,
  11230. 'mo': 9,
  11231. 'mr': 3,
  11232. 'ms': 0,
  11233. 'mt': 15,
  11234. 'my': 0,
  11235. 'nah': 3,
  11236. 'naq': 7,
  11237. 'nb': 3,
  11238. 'nd': 3,
  11239. 'ne': 3,
  11240. 'nl': 3,
  11241. 'nn': 3,
  11242. 'no': 3,
  11243. 'nr': 3,
  11244. 'nso': 4,
  11245. 'ny': 3,
  11246. 'nyn': 3,
  11247. 'om': 3,
  11248. 'or': 3,
  11249. 'pa': 3,
  11250. 'pap': 3,
  11251. 'pl': 13,
  11252. 'ps': 3,
  11253. 'pt': 3,
  11254. 'rm': 3,
  11255. 'ro': 9,
  11256. 'rof': 3,
  11257. 'ru': 11,
  11258. 'rwk': 3,
  11259. 'sah': 0,
  11260. 'saq': 3,
  11261. 'se': 7,
  11262. 'seh': 3,
  11263. 'ses': 0,
  11264. 'sg': 0,
  11265. 'sh': 11,
  11266. 'shi': 19,
  11267. 'sk': 12,
  11268. 'sl': 14,
  11269. 'sma': 7,
  11270. 'smi': 7,
  11271. 'smj': 7,
  11272. 'smn': 7,
  11273. 'sms': 7,
  11274. 'sn': 3,
  11275. 'so': 3,
  11276. 'sq': 3,
  11277. 'sr': 11,
  11278. 'ss': 3,
  11279. 'ssy': 3,
  11280. 'st': 3,
  11281. 'sv': 3,
  11282. 'sw': 3,
  11283. 'syr': 3,
  11284. 'ta': 3,
  11285. 'te': 3,
  11286. 'teo': 3,
  11287. 'th': 0,
  11288. 'ti': 4,
  11289. 'tig': 3,
  11290. 'tk': 3,
  11291. 'tl': 4,
  11292. 'tn': 3,
  11293. 'to': 0,
  11294. 'tr': 0,
  11295. 'ts': 3,
  11296. 'tzm': 22,
  11297. 'uk': 11,
  11298. 'ur': 3,
  11299. 've': 3,
  11300. 'vi': 0,
  11301. 'vun': 3,
  11302. 'wa': 4,
  11303. 'wae': 3,
  11304. 'wo': 0,
  11305. 'xh': 3,
  11306. 'xog': 3,
  11307. 'yo': 0,
  11308. 'zh': 0,
  11309. 'zu': 3
  11310. };
  11311. function isIn(n, list) {
  11312. return list.indexOf(n) !== -1;
  11313. }
  11314. function isBetween(n, start, end) {
  11315. return start <= n && n <= end;
  11316. }
  11317. var pluralRules = {
  11318. '0': function (n) {
  11319. return 'other';
  11320. },
  11321. '1': function (n) {
  11322. if (isBetween(n % 100, 3, 10)) return 'few';
  11323. if (n === 0) return 'zero';
  11324. if (isBetween(n % 100, 11, 99)) return 'many';
  11325. if (n == 2) return 'two';
  11326. if (n == 1) return 'one';
  11327. return 'other';
  11328. },
  11329. '2': function (n) {
  11330. if (n !== 0 && n % 10 === 0) return 'many';
  11331. if (n == 2) return 'two';
  11332. if (n == 1) return 'one';
  11333. return 'other';
  11334. },
  11335. '3': function (n) {
  11336. if (n == 1) return 'one';
  11337. return 'other';
  11338. },
  11339. '4': function (n) {
  11340. if (isBetween(n, 0, 1)) return 'one';
  11341. return 'other';
  11342. },
  11343. '5': function (n) {
  11344. if (isBetween(n, 0, 2) && n != 2) return 'one';
  11345. return 'other';
  11346. },
  11347. '6': function (n) {
  11348. if (n === 0) return 'zero';
  11349. if (n % 10 == 1 && n % 100 != 11) return 'one';
  11350. return 'other';
  11351. },
  11352. '7': function (n) {
  11353. if (n == 2) return 'two';
  11354. if (n == 1) return 'one';
  11355. return 'other';
  11356. },
  11357. '8': function (n) {
  11358. if (isBetween(n, 3, 6)) return 'few';
  11359. if (isBetween(n, 7, 10)) return 'many';
  11360. if (n == 2) return 'two';
  11361. if (n == 1) return 'one';
  11362. return 'other';
  11363. },
  11364. '9': function (n) {
  11365. if (n === 0 || n != 1 && isBetween(n % 100, 1, 19)) return 'few';
  11366. if (n == 1) return 'one';
  11367. return 'other';
  11368. },
  11369. '10': function (n) {
  11370. if (isBetween(n % 10, 2, 9) && !isBetween(n % 100, 11, 19)) return 'few';
  11371. if (n % 10 == 1 && !isBetween(n % 100, 11, 19)) return 'one';
  11372. return 'other';
  11373. },
  11374. '11': function (n) {
  11375. if (isBetween(n % 10, 2, 4) && !isBetween(n % 100, 12, 14)) return 'few';
  11376. if (n % 10 === 0 || isBetween(n % 10, 5, 9) || isBetween(n % 100, 11, 14)) return 'many';
  11377. if (n % 10 == 1 && n % 100 != 11) return 'one';
  11378. return 'other';
  11379. },
  11380. '12': function (n) {
  11381. if (isBetween(n, 2, 4)) return 'few';
  11382. if (n == 1) return 'one';
  11383. return 'other';
  11384. },
  11385. '13': function (n) {
  11386. if (isBetween(n % 10, 2, 4) && !isBetween(n % 100, 12, 14)) return 'few';
  11387. if (n != 1 && isBetween(n % 10, 0, 1) || isBetween(n % 10, 5, 9) || isBetween(n % 100, 12, 14)) return 'many';
  11388. if (n == 1) return 'one';
  11389. return 'other';
  11390. },
  11391. '14': function (n) {
  11392. if (isBetween(n % 100, 3, 4)) return 'few';
  11393. if (n % 100 == 2) return 'two';
  11394. if (n % 100 == 1) return 'one';
  11395. return 'other';
  11396. },
  11397. '15': function (n) {
  11398. if (n === 0 || isBetween(n % 100, 2, 10)) return 'few';
  11399. if (isBetween(n % 100, 11, 19)) return 'many';
  11400. if (n == 1) return 'one';
  11401. return 'other';
  11402. },
  11403. '16': function (n) {
  11404. if (n % 10 == 1 && n != 11) return 'one';
  11405. return 'other';
  11406. },
  11407. '17': function (n) {
  11408. if (n == 3) return 'few';
  11409. if (n === 0) return 'zero';
  11410. if (n == 6) return 'many';
  11411. if (n == 2) return 'two';
  11412. if (n == 1) return 'one';
  11413. return 'other';
  11414. },
  11415. '18': function (n) {
  11416. if (n === 0) return 'zero';
  11417. if (isBetween(n, 0, 2) && n !== 0 && n != 2) return 'one';
  11418. return 'other';
  11419. },
  11420. '19': function (n) {
  11421. if (isBetween(n, 2, 10)) return 'few';
  11422. if (isBetween(n, 0, 1)) return 'one';
  11423. return 'other';
  11424. },
  11425. '20': function (n) {
  11426. 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';
  11427. if (n % 1000000 === 0 && n !== 0) return 'many';
  11428. if (n % 10 == 2 && !isIn(n % 100, [12, 72, 92])) return 'two';
  11429. if (n % 10 == 1 && !isIn(n % 100, [11, 71, 91])) return 'one';
  11430. return 'other';
  11431. },
  11432. '21': function (n) {
  11433. if (n === 0) return 'zero';
  11434. if (n == 1) return 'one';
  11435. return 'other';
  11436. },
  11437. '22': function (n) {
  11438. if (isBetween(n, 0, 1) || isBetween(n, 11, 99)) return 'one';
  11439. return 'other';
  11440. },
  11441. '23': function (n) {
  11442. if (isBetween(n % 10, 1, 2) || n % 20 === 0) return 'one';
  11443. return 'other';
  11444. },
  11445. '24': function (n) {
  11446. if (isBetween(n, 3, 10) || isBetween(n, 13, 19)) return 'few';
  11447. if (isIn(n, [2, 12])) return 'two';
  11448. if (isIn(n, [1, 11])) return 'one';
  11449. return 'other';
  11450. }
  11451. };
  11452. var index = locales2rules[lang.replace(/-.*$/, '')];
  11453. if (!(index in pluralRules)) {
  11454. console.warn('plural form unknown for [' + lang + ']');
  11455. return function () {
  11456. return 'other';
  11457. };
  11458. }
  11459. return pluralRules[index];
  11460. }
  11461. gMacros.plural = function (str, param, key, prop) {
  11462. var n = parseFloat(param);
  11463. if (isNaN(n)) return str;
  11464. if (prop != gTextProp) return str;
  11465. if (!gMacros._pluralRules) {
  11466. gMacros._pluralRules = getPluralRules(gLanguage);
  11467. }
  11468. var index = '[' + gMacros._pluralRules(n) + ']';
  11469. if (n === 0 && key + '[zero]' in gL10nData) {
  11470. str = gL10nData[key + '[zero]'][prop];
  11471. } else if (n == 1 && key + '[one]' in gL10nData) {
  11472. str = gL10nData[key + '[one]'][prop];
  11473. } else if (n == 2 && key + '[two]' in gL10nData) {
  11474. str = gL10nData[key + '[two]'][prop];
  11475. } else if (key + index in gL10nData) {
  11476. str = gL10nData[key + index][prop];
  11477. } else if (key + '[other]' in gL10nData) {
  11478. str = gL10nData[key + '[other]'][prop];
  11479. }
  11480. return str;
  11481. };
  11482. function getL10nData(key, args, fallback) {
  11483. var data = gL10nData[key];
  11484. if (!data) {
  11485. console.warn('#' + key + ' is undefined.');
  11486. if (!fallback) {
  11487. return null;
  11488. }
  11489. data = fallback;
  11490. }
  11491. var rv = {};
  11492. for (var prop in data) {
  11493. var str = data[prop];
  11494. str = substIndexes(str, args, key, prop);
  11495. str = substArguments(str, args, key);
  11496. rv[prop] = str;
  11497. }
  11498. return rv;
  11499. }
  11500. function substIndexes(str, args, key, prop) {
  11501. var reIndex = /\{\[\s*([a-zA-Z]+)\(([a-zA-Z]+)\)\s*\]\}/;
  11502. var reMatch = reIndex.exec(str);
  11503. if (!reMatch || !reMatch.length) return str;
  11504. var macroName = reMatch[1];
  11505. var paramName = reMatch[2];
  11506. var param;
  11507. if (args && paramName in args) {
  11508. param = args[paramName];
  11509. } else if (paramName in gL10nData) {
  11510. param = gL10nData[paramName];
  11511. }
  11512. if (macroName in gMacros) {
  11513. var macro = gMacros[macroName];
  11514. str = macro(str, param, key, prop);
  11515. }
  11516. return str;
  11517. }
  11518. function substArguments(str, args, key) {
  11519. var reArgs = /\{\{\s*(.+?)\s*\}\}/g;
  11520. return str.replace(reArgs, function (matched_text, arg) {
  11521. if (args && arg in args) {
  11522. return args[arg];
  11523. }
  11524. if (arg in gL10nData) {
  11525. return gL10nData[arg];
  11526. }
  11527. console.log('argument {{' + arg + '}} for #' + key + ' is undefined.');
  11528. return matched_text;
  11529. });
  11530. }
  11531. function translateElement(element) {
  11532. var l10n = getL10nAttributes(element);
  11533. if (!l10n.id) return;
  11534. var data = getL10nData(l10n.id, l10n.args);
  11535. if (!data) {
  11536. console.warn('#' + l10n.id + ' is undefined.');
  11537. return;
  11538. }
  11539. if (data[gTextProp]) {
  11540. if (getChildElementCount(element) === 0) {
  11541. element[gTextProp] = data[gTextProp];
  11542. } else {
  11543. var children = element.childNodes;
  11544. var found = false;
  11545. for (var i = 0, l = children.length; i < l; i++) {
  11546. if (children[i].nodeType === 3 && /\S/.test(children[i].nodeValue)) {
  11547. if (found) {
  11548. children[i].nodeValue = '';
  11549. } else {
  11550. children[i].nodeValue = data[gTextProp];
  11551. found = true;
  11552. }
  11553. }
  11554. }
  11555. if (!found) {
  11556. var textNode = document.createTextNode(data[gTextProp]);
  11557. element.insertBefore(textNode, element.firstChild);
  11558. }
  11559. }
  11560. delete data[gTextProp];
  11561. }
  11562. for (var k in data) {
  11563. element[k] = data[k];
  11564. }
  11565. }
  11566. function getChildElementCount(element) {
  11567. if (element.children) {
  11568. return element.children.length;
  11569. }
  11570. if (typeof element.childElementCount !== 'undefined') {
  11571. return element.childElementCount;
  11572. }
  11573. var count = 0;
  11574. for (var i = 0; i < element.childNodes.length; i++) {
  11575. count += element.nodeType === 1 ? 1 : 0;
  11576. }
  11577. return count;
  11578. }
  11579. function translateFragment(element) {
  11580. element = element || document.documentElement;
  11581. var children = getTranslatableChildren(element);
  11582. var elementCount = children.length;
  11583. for (var i = 0; i < elementCount; i++) {
  11584. translateElement(children[i]);
  11585. }
  11586. translateElement(element);
  11587. }
  11588. return {
  11589. get: function (key, args, fallbackString) {
  11590. var index = key.lastIndexOf('.');
  11591. var prop = gTextProp;
  11592. if (index > 0) {
  11593. prop = key.substring(index + 1);
  11594. key = key.substring(0, index);
  11595. }
  11596. var fallback;
  11597. if (fallbackString) {
  11598. fallback = {};
  11599. fallback[prop] = fallbackString;
  11600. }
  11601. var data = getL10nData(key, args, fallback);
  11602. if (data && prop in data) {
  11603. return data[prop];
  11604. }
  11605. return '{{' + key + '}}';
  11606. },
  11607. getData: function () {
  11608. return gL10nData;
  11609. },
  11610. getText: function () {
  11611. return gTextData;
  11612. },
  11613. getLanguage: function () {
  11614. return gLanguage;
  11615. },
  11616. setLanguage: function (lang, callback) {
  11617. loadLocale(lang, function () {
  11618. if (callback) callback();
  11619. });
  11620. },
  11621. getDirection: function () {
  11622. var rtlList = ['ar', 'he', 'fa', 'ps', 'ur'];
  11623. var shortCode = gLanguage.split('-', 1)[0];
  11624. return rtlList.indexOf(shortCode) >= 0 ? 'rtl' : 'ltr';
  11625. },
  11626. translate: translateFragment,
  11627. getReadyState: function () {
  11628. return gReadyState;
  11629. },
  11630. ready: function (callback) {
  11631. if (!callback) {
  11632. return;
  11633. } else if (gReadyState == 'complete' || gReadyState == 'interactive') {
  11634. window.setTimeout(function () {
  11635. callback();
  11636. });
  11637. } else if (document.addEventListener) {
  11638. document.addEventListener('localized', function once() {
  11639. document.removeEventListener('localized', once);
  11640. callback();
  11641. });
  11642. }
  11643. }
  11644. };
  11645. }(window, document);
  11646. /***/ }),
  11647. /* 43 */
  11648. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11649. Object.defineProperty(exports, "__esModule", ({
  11650. value: true
  11651. }));
  11652. exports.docPropertiesLookup = docPropertiesLookup;
  11653. exports.GenericScripting = void 0;
  11654. var _pdfjsLib = __webpack_require__(5);
  11655. async function docPropertiesLookup(pdfDocument) {
  11656. const url = "",
  11657. baseUrl = url.split("#")[0];
  11658. let {
  11659. info,
  11660. metadata,
  11661. contentDispositionFilename,
  11662. contentLength
  11663. } = await pdfDocument.getMetadata();
  11664. if (!contentLength) {
  11665. const {
  11666. length
  11667. } = await pdfDocument.getDownloadInfo();
  11668. contentLength = length;
  11669. }
  11670. return { ...info,
  11671. baseURL: baseUrl,
  11672. filesize: contentLength,
  11673. filename: contentDispositionFilename || (0, _pdfjsLib.getPdfFilenameFromUrl)(url),
  11674. metadata: metadata?.getRaw(),
  11675. authors: metadata?.get("dc:creator"),
  11676. numPages: pdfDocument.numPages,
  11677. URL: url
  11678. };
  11679. }
  11680. class GenericScripting {
  11681. constructor(sandboxBundleSrc) {
  11682. this._ready = (0, _pdfjsLib.loadScript)(sandboxBundleSrc, true).then(() => {
  11683. return window.pdfjsSandbox.QuickJSSandbox();
  11684. });
  11685. }
  11686. async createSandbox(data) {
  11687. const sandbox = await this._ready;
  11688. sandbox.create(data);
  11689. }
  11690. async dispatchEventInSandbox(event) {
  11691. const sandbox = await this._ready;
  11692. sandbox.dispatchEvent(event);
  11693. }
  11694. async destroySandbox() {
  11695. const sandbox = await this._ready;
  11696. sandbox.nukeSandbox();
  11697. }
  11698. }
  11699. exports.GenericScripting = GenericScripting;
  11700. /***/ }),
  11701. /* 44 */
  11702. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11703. Object.defineProperty(exports, "__esModule", ({
  11704. value: true
  11705. }));
  11706. exports.PDFPrintService = PDFPrintService;
  11707. var _app = __webpack_require__(3);
  11708. var _viewer_compatibility = __webpack_require__(2);
  11709. let activeService = null;
  11710. let overlayManager = null;
  11711. function renderPage(activeServiceOnEntry, pdfDocument, pageNumber, size, printResolution, optionalContentConfigPromise) {
  11712. const scratchCanvas = activeService.scratchCanvas;
  11713. const PRINT_UNITS = printResolution / 72.0;
  11714. scratchCanvas.width = Math.floor(size.width * PRINT_UNITS);
  11715. scratchCanvas.height = Math.floor(size.height * PRINT_UNITS);
  11716. const ctx = scratchCanvas.getContext("2d");
  11717. ctx.save();
  11718. ctx.fillStyle = "rgb(255, 255, 255)";
  11719. ctx.fillRect(0, 0, scratchCanvas.width, scratchCanvas.height);
  11720. ctx.restore();
  11721. return pdfDocument.getPage(pageNumber).then(function (pdfPage) {
  11722. const renderContext = {
  11723. canvasContext: ctx,
  11724. transform: [PRINT_UNITS, 0, 0, PRINT_UNITS, 0, 0],
  11725. viewport: pdfPage.getViewport({
  11726. scale: 1,
  11727. rotation: size.rotation
  11728. }),
  11729. intent: "print",
  11730. annotationStorage: pdfDocument.annotationStorage,
  11731. optionalContentConfigPromise
  11732. };
  11733. return pdfPage.render(renderContext).promise;
  11734. });
  11735. }
  11736. function PDFPrintService(pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise = null, l10n) {
  11737. this.pdfDocument = pdfDocument;
  11738. this.pagesOverview = pagesOverview;
  11739. this.printContainer = printContainer;
  11740. this._printResolution = printResolution || 150;
  11741. this._optionalContentConfigPromise = optionalContentConfigPromise || pdfDocument.getOptionalContentConfig();
  11742. this.l10n = l10n;
  11743. this.currentPage = -1;
  11744. this.scratchCanvas = document.createElement("canvas");
  11745. }
  11746. PDFPrintService.prototype = {
  11747. layout() {
  11748. this.throwIfInactive();
  11749. const body = document.querySelector("body");
  11750. body.setAttribute("data-pdfjsprinting", true);
  11751. const hasEqualPageSizes = this.pagesOverview.every(function (size) {
  11752. return size.width === this.pagesOverview[0].width && size.height === this.pagesOverview[0].height;
  11753. }, this);
  11754. if (!hasEqualPageSizes) {
  11755. console.warn("Not all pages have the same size. The printed " + "result may be incorrect!");
  11756. }
  11757. this.pageStyleSheet = document.createElement("style");
  11758. const pageSize = this.pagesOverview[0];
  11759. this.pageStyleSheet.textContent = "@page { size: " + pageSize.width + "pt " + pageSize.height + "pt;}";
  11760. body.appendChild(this.pageStyleSheet);
  11761. },
  11762. destroy() {
  11763. if (activeService !== this) {
  11764. return;
  11765. }
  11766. this.printContainer.textContent = "";
  11767. const body = document.querySelector("body");
  11768. body.removeAttribute("data-pdfjsprinting");
  11769. if (this.pageStyleSheet) {
  11770. this.pageStyleSheet.remove();
  11771. this.pageStyleSheet = null;
  11772. }
  11773. this.scratchCanvas.width = this.scratchCanvas.height = 0;
  11774. this.scratchCanvas = null;
  11775. activeService = null;
  11776. ensureOverlay().then(function () {
  11777. if (overlayManager.active !== "printServiceOverlay") {
  11778. return;
  11779. }
  11780. overlayManager.close("printServiceOverlay");
  11781. });
  11782. },
  11783. renderPages() {
  11784. const pageCount = this.pagesOverview.length;
  11785. const renderNextPage = (resolve, reject) => {
  11786. this.throwIfInactive();
  11787. if (++this.currentPage >= pageCount) {
  11788. renderProgress(pageCount, pageCount, this.l10n);
  11789. resolve();
  11790. return;
  11791. }
  11792. const index = this.currentPage;
  11793. renderProgress(index, pageCount, this.l10n);
  11794. renderPage(this, this.pdfDocument, index + 1, this.pagesOverview[index], this._printResolution, this._optionalContentConfigPromise).then(this.useRenderedPage.bind(this)).then(function () {
  11795. renderNextPage(resolve, reject);
  11796. }, reject);
  11797. };
  11798. return new Promise(renderNextPage);
  11799. },
  11800. useRenderedPage() {
  11801. this.throwIfInactive();
  11802. const img = document.createElement("img");
  11803. const scratchCanvas = this.scratchCanvas;
  11804. if ("toBlob" in scratchCanvas && !_viewer_compatibility.viewerCompatibilityParams.disableCreateObjectURL) {
  11805. scratchCanvas.toBlob(function (blob) {
  11806. img.src = URL.createObjectURL(blob);
  11807. });
  11808. } else {
  11809. img.src = scratchCanvas.toDataURL();
  11810. }
  11811. const wrapper = document.createElement("div");
  11812. wrapper.appendChild(img);
  11813. this.printContainer.appendChild(wrapper);
  11814. return new Promise(function (resolve, reject) {
  11815. img.onload = resolve;
  11816. img.onerror = reject;
  11817. });
  11818. },
  11819. performPrint() {
  11820. this.throwIfInactive();
  11821. return new Promise(resolve => {
  11822. setTimeout(() => {
  11823. if (!this.active) {
  11824. resolve();
  11825. return;
  11826. }
  11827. print.call(window);
  11828. setTimeout(resolve, 20);
  11829. }, 0);
  11830. });
  11831. },
  11832. get active() {
  11833. return this === activeService;
  11834. },
  11835. throwIfInactive() {
  11836. if (!this.active) {
  11837. throw new Error("This print request was cancelled or completed.");
  11838. }
  11839. }
  11840. };
  11841. const print = window.print;
  11842. window.print = function () {
  11843. if (activeService) {
  11844. console.warn("Ignored window.print() because of a pending print job.");
  11845. return;
  11846. }
  11847. ensureOverlay().then(function () {
  11848. if (activeService) {
  11849. overlayManager.open("printServiceOverlay");
  11850. }
  11851. });
  11852. try {
  11853. dispatchEvent("beforeprint");
  11854. } finally {
  11855. if (!activeService) {
  11856. console.error("Expected print service to be initialized.");
  11857. ensureOverlay().then(function () {
  11858. if (overlayManager.active === "printServiceOverlay") {
  11859. overlayManager.close("printServiceOverlay");
  11860. }
  11861. });
  11862. return;
  11863. }
  11864. const activeServiceOnEntry = activeService;
  11865. activeService.renderPages().then(function () {
  11866. return activeServiceOnEntry.performPrint();
  11867. }).catch(function () {}).then(function () {
  11868. if (activeServiceOnEntry.active) {
  11869. abort();
  11870. }
  11871. });
  11872. }
  11873. };
  11874. function dispatchEvent(eventType) {
  11875. const event = document.createEvent("CustomEvent");
  11876. event.initCustomEvent(eventType, false, false, "custom");
  11877. window.dispatchEvent(event);
  11878. }
  11879. function abort() {
  11880. if (activeService) {
  11881. activeService.destroy();
  11882. dispatchEvent("afterprint");
  11883. }
  11884. }
  11885. function renderProgress(index, total, l10n) {
  11886. const progressContainer = document.getElementById("printServiceOverlay");
  11887. const progress = Math.round(100 * index / total);
  11888. const progressBar = progressContainer.querySelector("progress");
  11889. const progressPerc = progressContainer.querySelector(".relative-progress");
  11890. progressBar.value = progress;
  11891. l10n.get("print_progress_percent", {
  11892. progress
  11893. }).then(msg => {
  11894. progressPerc.textContent = msg;
  11895. });
  11896. }
  11897. window.addEventListener("keydown", function (event) {
  11898. if (event.keyCode === 80 && (event.ctrlKey || event.metaKey) && !event.altKey && (!event.shiftKey || window.chrome || window.opera)) {
  11899. window.print();
  11900. event.preventDefault();
  11901. if (event.stopImmediatePropagation) {
  11902. event.stopImmediatePropagation();
  11903. } else {
  11904. event.stopPropagation();
  11905. }
  11906. }
  11907. }, true);
  11908. if ("onbeforeprint" in window) {
  11909. const stopPropagationIfNeeded = function (event) {
  11910. if (event.detail !== "custom" && event.stopImmediatePropagation) {
  11911. event.stopImmediatePropagation();
  11912. }
  11913. };
  11914. window.addEventListener("beforeprint", stopPropagationIfNeeded);
  11915. window.addEventListener("afterprint", stopPropagationIfNeeded);
  11916. }
  11917. let overlayPromise;
  11918. function ensureOverlay() {
  11919. if (!overlayPromise) {
  11920. overlayManager = _app.PDFViewerApplication.overlayManager;
  11921. if (!overlayManager) {
  11922. throw new Error("The overlay manager has not yet been initialized.");
  11923. }
  11924. overlayPromise = overlayManager.register("printServiceOverlay", document.getElementById("printServiceOverlay"), abort, true);
  11925. document.getElementById("printCancel").onclick = abort;
  11926. }
  11927. return overlayPromise;
  11928. }
  11929. _app.PDFPrintServiceFactory.instance = {
  11930. supportsPrinting: true,
  11931. createPrintService(pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise, l10n) {
  11932. if (activeService) {
  11933. throw new Error("The print service is created and active.");
  11934. }
  11935. activeService = new PDFPrintService(pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise, l10n);
  11936. return activeService;
  11937. }
  11938. };
  11939. /***/ })
  11940. /******/ ]);
  11941. /************************************************************************/
  11942. /******/ // The module cache
  11943. /******/ var __webpack_module_cache__ = {};
  11944. /******/
  11945. /******/ // The require function
  11946. /******/ function __webpack_require__(moduleId) {
  11947. /******/ // Check if module is in cache
  11948. /******/ var cachedModule = __webpack_module_cache__[moduleId];
  11949. /******/ if (cachedModule !== undefined) {
  11950. /******/ return cachedModule.exports;
  11951. /******/ }
  11952. /******/ // Create a new module (and put it into the cache)
  11953. /******/ var module = __webpack_module_cache__[moduleId] = {
  11954. /******/ // no module.id needed
  11955. /******/ // no module.loaded needed
  11956. /******/ exports: {}
  11957. /******/ };
  11958. /******/
  11959. /******/ // Execute the module function
  11960. /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
  11961. /******/
  11962. /******/ // Return the exports of the module
  11963. /******/ return module.exports;
  11964. /******/ }
  11965. /******/
  11966. /************************************************************************/
  11967. var __webpack_exports__ = {};
  11968. // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
  11969. (() => {
  11970. var exports = __webpack_exports__;
  11971. Object.defineProperty(exports, "__esModule", ({
  11972. value: true
  11973. }));
  11974. Object.defineProperty(exports, "PDFViewerApplicationOptions", ({
  11975. enumerable: true,
  11976. get: function () {
  11977. return _app_options.AppOptions;
  11978. }
  11979. }));
  11980. Object.defineProperty(exports, "PDFViewerApplication", ({
  11981. enumerable: true,
  11982. get: function () {
  11983. return _app.PDFViewerApplication;
  11984. }
  11985. }));
  11986. var _app_options = __webpack_require__(1);
  11987. var _app = __webpack_require__(3);
  11988. const pdfjsVersion = '2.8.335';
  11989. const pdfjsBuild = '228adbf67';
  11990. window.PDFViewerApplication = _app.PDFViewerApplication;
  11991. window.PDFViewerApplicationOptions = _app_options.AppOptions;
  11992. ;
  11993. ;
  11994. {
  11995. __webpack_require__(38);
  11996. }
  11997. ;
  11998. {
  11999. __webpack_require__(44);
  12000. }
  12001. function getViewerConfiguration() {
  12002. let errorWrapper = null;
  12003. errorWrapper = {
  12004. container: document.getElementById("errorWrapper"),
  12005. errorMessage: document.getElementById("errorMessage"),
  12006. closeButton: document.getElementById("errorClose"),
  12007. errorMoreInfo: document.getElementById("errorMoreInfo"),
  12008. moreInfoButton: document.getElementById("errorShowMore"),
  12009. lessInfoButton: document.getElementById("errorShowLess")
  12010. };
  12011. return {
  12012. appContainer: document.body,
  12013. mainContainer: document.getElementById("viewerContainer"),
  12014. viewerContainer: document.getElementById("viewer"),
  12015. eventBus: null,
  12016. toolbar: {
  12017. container: document.getElementById("toolbarViewer"),
  12018. numPages: document.getElementById("numPages"),
  12019. pageNumber: document.getElementById("pageNumber"),
  12020. scaleSelectContainer: document.getElementById("scaleSelectContainer"),
  12021. scaleSelect: document.getElementById("scaleSelect"),
  12022. customScaleOption: document.getElementById("customScaleOption"),
  12023. previous: document.getElementById("previous"),
  12024. next: document.getElementById("next"),
  12025. zoomIn: document.getElementById("zoomIn"),
  12026. zoomOut: document.getElementById("zoomOut"),
  12027. viewFind: document.getElementById("viewFind"),
  12028. openFile: document.getElementById("openFile"),
  12029. print: document.getElementById("print"),
  12030. presentationModeButton: document.getElementById("presentationMode"),
  12031. download: document.getElementById("download"),
  12032. viewBookmark: document.getElementById("viewBookmark")
  12033. },
  12034. secondaryToolbar: {
  12035. toolbar: document.getElementById("secondaryToolbar"),
  12036. toggleButton: document.getElementById("secondaryToolbarToggle"),
  12037. toolbarButtonContainer: document.getElementById("secondaryToolbarButtonContainer"),
  12038. presentationModeButton: document.getElementById("secondaryPresentationMode"),
  12039. openFileButton: document.getElementById("secondaryOpenFile"),
  12040. printButton: document.getElementById("secondaryPrint"),
  12041. downloadButton: document.getElementById("secondaryDownload"),
  12042. viewBookmarkButton: document.getElementById("secondaryViewBookmark"),
  12043. firstPageButton: document.getElementById("firstPage"),
  12044. lastPageButton: document.getElementById("lastPage"),
  12045. pageRotateCwButton: document.getElementById("pageRotateCw"),
  12046. pageRotateCcwButton: document.getElementById("pageRotateCcw"),
  12047. cursorSelectToolButton: document.getElementById("cursorSelectTool"),
  12048. cursorHandToolButton: document.getElementById("cursorHandTool"),
  12049. scrollVerticalButton: document.getElementById("scrollVertical"),
  12050. scrollHorizontalButton: document.getElementById("scrollHorizontal"),
  12051. scrollWrappedButton: document.getElementById("scrollWrapped"),
  12052. spreadNoneButton: document.getElementById("spreadNone"),
  12053. spreadOddButton: document.getElementById("spreadOdd"),
  12054. spreadEvenButton: document.getElementById("spreadEven"),
  12055. documentPropertiesButton: document.getElementById("documentProperties")
  12056. },
  12057. sidebar: {
  12058. outerContainer: document.getElementById("outerContainer"),
  12059. viewerContainer: document.getElementById("viewerContainer"),
  12060. toggleButton: document.getElementById("sidebarToggle"),
  12061. thumbnailButton: document.getElementById("viewThumbnail"),
  12062. outlineButton: document.getElementById("viewOutline"),
  12063. attachmentsButton: document.getElementById("viewAttachments"),
  12064. layersButton: document.getElementById("viewLayers"),
  12065. thumbnailView: document.getElementById("thumbnailView"),
  12066. outlineView: document.getElementById("outlineView"),
  12067. attachmentsView: document.getElementById("attachmentsView"),
  12068. layersView: document.getElementById("layersView"),
  12069. outlineOptionsContainer: document.getElementById("outlineOptionsContainer"),
  12070. currentOutlineItemButton: document.getElementById("currentOutlineItem")
  12071. },
  12072. sidebarResizer: {
  12073. outerContainer: document.getElementById("outerContainer"),
  12074. resizer: document.getElementById("sidebarResizer")
  12075. },
  12076. findBar: {
  12077. bar: document.getElementById("findbar"),
  12078. toggleButton: document.getElementById("viewFind"),
  12079. findField: document.getElementById("findInput"),
  12080. highlightAllCheckbox: document.getElementById("findHighlightAll"),
  12081. caseSensitiveCheckbox: document.getElementById("findMatchCase"),
  12082. entireWordCheckbox: document.getElementById("findEntireWord"),
  12083. findMsg: document.getElementById("findMsg"),
  12084. findResultsCount: document.getElementById("findResultsCount"),
  12085. findPreviousButton: document.getElementById("findPrevious"),
  12086. findNextButton: document.getElementById("findNext")
  12087. },
  12088. passwordOverlay: {
  12089. overlayName: "passwordOverlay",
  12090. container: document.getElementById("passwordOverlay"),
  12091. label: document.getElementById("passwordText"),
  12092. input: document.getElementById("password"),
  12093. submitButton: document.getElementById("passwordSubmit"),
  12094. cancelButton: document.getElementById("passwordCancel")
  12095. },
  12096. documentProperties: {
  12097. overlayName: "documentPropertiesOverlay",
  12098. container: document.getElementById("documentPropertiesOverlay"),
  12099. closeButton: document.getElementById("documentPropertiesClose"),
  12100. fields: {
  12101. fileName: document.getElementById("fileNameField"),
  12102. fileSize: document.getElementById("fileSizeField"),
  12103. title: document.getElementById("titleField"),
  12104. author: document.getElementById("authorField"),
  12105. subject: document.getElementById("subjectField"),
  12106. keywords: document.getElementById("keywordsField"),
  12107. creationDate: document.getElementById("creationDateField"),
  12108. modificationDate: document.getElementById("modificationDateField"),
  12109. creator: document.getElementById("creatorField"),
  12110. producer: document.getElementById("producerField"),
  12111. version: document.getElementById("versionField"),
  12112. pageCount: document.getElementById("pageCountField"),
  12113. pageSize: document.getElementById("pageSizeField"),
  12114. linearized: document.getElementById("linearizedField")
  12115. }
  12116. },
  12117. errorWrapper,
  12118. printContainer: document.getElementById("printContainer"),
  12119. openFileInputName: "fileInput",
  12120. debuggerScriptPath: "./debugger.js"
  12121. };
  12122. }
  12123. function webViewerLoad() {
  12124. const config = getViewerConfiguration();
  12125. const event = document.createEvent("CustomEvent");
  12126. event.initCustomEvent("webviewerloaded", true, true, {
  12127. source: window
  12128. });
  12129. try {
  12130. parent.document.dispatchEvent(event);
  12131. } catch (ex) {
  12132. console.error(`webviewerloaded: ${ex}`);
  12133. document.dispatchEvent(event);
  12134. }
  12135. _app.PDFViewerApplication.run(config);
  12136. }
  12137. if (document.blockUnblockOnload) {
  12138. document.blockUnblockOnload(true);
  12139. }
  12140. if (document.readyState === "interactive" || document.readyState === "complete") {
  12141. webViewerLoad();
  12142. } else {
  12143. document.addEventListener("DOMContentLoaded", webViewerLoad, true);
  12144. }
  12145. })();
  12146. /******/ })()
  12147. ;
  12148. //# sourceMappingURL=viewer.js.map