viewer.js 335 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * Javascript code in this page
  4. *
  5. * Copyright 2020 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. /******/ (function(modules) { // webpackBootstrap
  23. /******/ // The module cache
  24. /******/ var installedModules = {};
  25. /******/
  26. /******/ // The require function
  27. /******/ function __webpack_require__(moduleId) {
  28. /******/
  29. /******/ // Check if module is in cache
  30. /******/ if(installedModules[moduleId]) {
  31. /******/ return installedModules[moduleId].exports;
  32. /******/ }
  33. /******/ // Create a new module (and put it into the cache)
  34. /******/ var module = installedModules[moduleId] = {
  35. /******/ i: moduleId,
  36. /******/ l: false,
  37. /******/ exports: {}
  38. /******/ };
  39. /******/
  40. /******/ // Execute the module function
  41. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  42. /******/
  43. /******/ // Flag the module as loaded
  44. /******/ module.l = true;
  45. /******/
  46. /******/ // Return the exports of the module
  47. /******/ return module.exports;
  48. /******/ }
  49. /******/
  50. /******/
  51. /******/ // expose the modules object (__webpack_modules__)
  52. /******/ __webpack_require__.m = modules;
  53. /******/
  54. /******/ // expose the module cache
  55. /******/ __webpack_require__.c = installedModules;
  56. /******/
  57. /******/ // define getter function for harmony exports
  58. /******/ __webpack_require__.d = function(exports, name, getter) {
  59. /******/ if(!__webpack_require__.o(exports, name)) {
  60. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  61. /******/ }
  62. /******/ };
  63. /******/
  64. /******/ // define __esModule on exports
  65. /******/ __webpack_require__.r = function(exports) {
  66. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  67. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  68. /******/ }
  69. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  70. /******/ };
  71. /******/
  72. /******/ // create a fake namespace object
  73. /******/ // mode & 1: value is a module id, require it
  74. /******/ // mode & 2: merge all properties of value into the ns
  75. /******/ // mode & 4: return value when already ns object
  76. /******/ // mode & 8|1: behave like require
  77. /******/ __webpack_require__.t = function(value, mode) {
  78. /******/ if(mode & 1) value = __webpack_require__(value);
  79. /******/ if(mode & 8) return value;
  80. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  81. /******/ var ns = Object.create(null);
  82. /******/ __webpack_require__.r(ns);
  83. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  84. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  85. /******/ return ns;
  86. /******/ };
  87. /******/
  88. /******/ // getDefaultExport function for compatibility with non-harmony modules
  89. /******/ __webpack_require__.n = function(module) {
  90. /******/ var getter = module && module.__esModule ?
  91. /******/ function getDefault() { return module['default']; } :
  92. /******/ function getModuleExports() { return module; };
  93. /******/ __webpack_require__.d(getter, 'a', getter);
  94. /******/ return getter;
  95. /******/ };
  96. /******/
  97. /******/ // Object.prototype.hasOwnProperty.call
  98. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  99. /******/
  100. /******/ // __webpack_public_path__
  101. /******/ __webpack_require__.p = "";
  102. /******/
  103. /******/
  104. /******/ // Load entry module and return exports
  105. /******/ return __webpack_require__(__webpack_require__.s = 0);
  106. /******/ })
  107. /************************************************************************/
  108. /******/ ([
  109. /* 0 */
  110. /***/ (function(module, exports, __webpack_require__) {
  111. "use strict";
  112. ;
  113. let pdfjsWebApp, pdfjsWebAppOptions;
  114. {
  115. pdfjsWebApp = __webpack_require__(1);
  116. pdfjsWebAppOptions = __webpack_require__(3);
  117. }
  118. ;
  119. {
  120. __webpack_require__(33);
  121. }
  122. ;
  123. {
  124. __webpack_require__(38);
  125. }
  126. function getViewerConfiguration() {
  127. return {
  128. appContainer: document.body,
  129. mainContainer: document.getElementById("viewerContainer"),
  130. viewerContainer: document.getElementById("viewer"),
  131. eventBus: null,
  132. toolbar: {
  133. container: document.getElementById("toolbarViewer"),
  134. numPages: document.getElementById("numPages"),
  135. pageNumber: document.getElementById("pageNumber"),
  136. scaleSelectContainer: document.getElementById("scaleSelectContainer"),
  137. scaleSelect: document.getElementById("scaleSelect"),
  138. customScaleOption: document.getElementById("customScaleOption"),
  139. previous: document.getElementById("previous"),
  140. next: document.getElementById("next"),
  141. zoomIn: document.getElementById("zoomIn"),
  142. zoomOut: document.getElementById("zoomOut"),
  143. viewFind: document.getElementById("viewFind"),
  144. openFile: document.getElementById("openFile"),
  145. print: document.getElementById("print"),
  146. presentationModeButton: document.getElementById("presentationMode"),
  147. download: document.getElementById("download"),
  148. viewBookmark: document.getElementById("viewBookmark")
  149. },
  150. secondaryToolbar: {
  151. toolbar: document.getElementById("secondaryToolbar"),
  152. toggleButton: document.getElementById("secondaryToolbarToggle"),
  153. toolbarButtonContainer: document.getElementById("secondaryToolbarButtonContainer"),
  154. presentationModeButton: document.getElementById("secondaryPresentationMode"),
  155. openFileButton: document.getElementById("secondaryOpenFile"),
  156. printButton: document.getElementById("secondaryPrint"),
  157. downloadButton: document.getElementById("secondaryDownload"),
  158. viewBookmarkButton: document.getElementById("secondaryViewBookmark"),
  159. firstPageButton: document.getElementById("firstPage"),
  160. lastPageButton: document.getElementById("lastPage"),
  161. pageRotateCwButton: document.getElementById("pageRotateCw"),
  162. pageRotateCcwButton: document.getElementById("pageRotateCcw"),
  163. cursorSelectToolButton: document.getElementById("cursorSelectTool"),
  164. cursorHandToolButton: document.getElementById("cursorHandTool"),
  165. scrollVerticalButton: document.getElementById("scrollVertical"),
  166. scrollHorizontalButton: document.getElementById("scrollHorizontal"),
  167. scrollWrappedButton: document.getElementById("scrollWrapped"),
  168. spreadNoneButton: document.getElementById("spreadNone"),
  169. spreadOddButton: document.getElementById("spreadOdd"),
  170. spreadEvenButton: document.getElementById("spreadEven"),
  171. documentPropertiesButton: document.getElementById("documentProperties")
  172. },
  173. fullscreen: {
  174. contextFirstPage: document.getElementById("contextFirstPage"),
  175. contextLastPage: document.getElementById("contextLastPage"),
  176. contextPageRotateCw: document.getElementById("contextPageRotateCw"),
  177. contextPageRotateCcw: document.getElementById("contextPageRotateCcw")
  178. },
  179. sidebar: {
  180. outerContainer: document.getElementById("outerContainer"),
  181. viewerContainer: document.getElementById("viewerContainer"),
  182. toggleButton: document.getElementById("sidebarToggle"),
  183. thumbnailButton: document.getElementById("viewThumbnail"),
  184. outlineButton: document.getElementById("viewOutline"),
  185. attachmentsButton: document.getElementById("viewAttachments"),
  186. thumbnailView: document.getElementById("thumbnailView"),
  187. outlineView: document.getElementById("outlineView"),
  188. attachmentsView: document.getElementById("attachmentsView")
  189. },
  190. sidebarResizer: {
  191. outerContainer: document.getElementById("outerContainer"),
  192. resizer: document.getElementById("sidebarResizer")
  193. },
  194. findBar: {
  195. bar: document.getElementById("findbar"),
  196. toggleButton: document.getElementById("viewFind"),
  197. findField: document.getElementById("findInput"),
  198. highlightAllCheckbox: document.getElementById("findHighlightAll"),
  199. caseSensitiveCheckbox: document.getElementById("findMatchCase"),
  200. entireWordCheckbox: document.getElementById("findEntireWord"),
  201. findMsg: document.getElementById("findMsg"),
  202. findResultsCount: document.getElementById("findResultsCount"),
  203. findPreviousButton: document.getElementById("findPrevious"),
  204. findNextButton: document.getElementById("findNext")
  205. },
  206. passwordOverlay: {
  207. overlayName: "passwordOverlay",
  208. container: document.getElementById("passwordOverlay"),
  209. label: document.getElementById("passwordText"),
  210. input: document.getElementById("password"),
  211. submitButton: document.getElementById("passwordSubmit"),
  212. cancelButton: document.getElementById("passwordCancel")
  213. },
  214. documentProperties: {
  215. overlayName: "documentPropertiesOverlay",
  216. container: document.getElementById("documentPropertiesOverlay"),
  217. closeButton: document.getElementById("documentPropertiesClose"),
  218. fields: {
  219. fileName: document.getElementById("fileNameField"),
  220. fileSize: document.getElementById("fileSizeField"),
  221. title: document.getElementById("titleField"),
  222. author: document.getElementById("authorField"),
  223. subject: document.getElementById("subjectField"),
  224. keywords: document.getElementById("keywordsField"),
  225. creationDate: document.getElementById("creationDateField"),
  226. modificationDate: document.getElementById("modificationDateField"),
  227. creator: document.getElementById("creatorField"),
  228. producer: document.getElementById("producerField"),
  229. version: document.getElementById("versionField"),
  230. pageCount: document.getElementById("pageCountField"),
  231. pageSize: document.getElementById("pageSizeField"),
  232. linearized: document.getElementById("linearizedField")
  233. }
  234. },
  235. errorWrapper: {
  236. container: document.getElementById("errorWrapper"),
  237. errorMessage: document.getElementById("errorMessage"),
  238. closeButton: document.getElementById("errorClose"),
  239. errorMoreInfo: document.getElementById("errorMoreInfo"),
  240. moreInfoButton: document.getElementById("errorShowMore"),
  241. lessInfoButton: document.getElementById("errorShowLess")
  242. },
  243. printContainer: document.getElementById("printContainer"),
  244. openFileInputName: "fileInput",
  245. debuggerScriptPath: "./debugger.js"
  246. };
  247. }
  248. function webViewerLoad() {
  249. const config = getViewerConfiguration();
  250. window.PDFViewerApplication = pdfjsWebApp.PDFViewerApplication;
  251. window.PDFViewerApplicationOptions = pdfjsWebAppOptions.AppOptions;
  252. const event = document.createEvent("CustomEvent");
  253. event.initCustomEvent("webviewerloaded", true, true, {});
  254. document.dispatchEvent(event);
  255. pdfjsWebApp.PDFViewerApplication.run(config);
  256. }
  257. if (document.readyState === "interactive" || document.readyState === "complete") {
  258. webViewerLoad();
  259. } else {
  260. document.addEventListener("DOMContentLoaded", webViewerLoad, true);
  261. }
  262. /***/ }),
  263. /* 1 */
  264. /***/ (function(module, exports, __webpack_require__) {
  265. "use strict";
  266. Object.defineProperty(exports, "__esModule", {
  267. value: true
  268. });
  269. exports.PDFPrintServiceFactory = exports.DefaultExternalServices = exports.PDFViewerApplication = void 0;
  270. var _ui_utils = __webpack_require__(2);
  271. var _app_options = __webpack_require__(3);
  272. var _pdfjsLib = __webpack_require__(4);
  273. var _pdf_cursor_tools = __webpack_require__(6);
  274. var _pdf_rendering_queue = __webpack_require__(8);
  275. var _pdf_sidebar = __webpack_require__(9);
  276. var _overlay_manager = __webpack_require__(10);
  277. var _password_prompt = __webpack_require__(11);
  278. var _pdf_attachment_viewer = __webpack_require__(12);
  279. var _pdf_document_properties = __webpack_require__(13);
  280. var _pdf_find_bar = __webpack_require__(14);
  281. var _pdf_find_controller = __webpack_require__(15);
  282. var _pdf_history = __webpack_require__(17);
  283. var _pdf_link_service = __webpack_require__(18);
  284. var _pdf_outline_viewer = __webpack_require__(19);
  285. var _pdf_presentation_mode = __webpack_require__(20);
  286. var _pdf_sidebar_resizer = __webpack_require__(21);
  287. var _pdf_thumbnail_viewer = __webpack_require__(22);
  288. var _pdf_viewer = __webpack_require__(24);
  289. var _secondary_toolbar = __webpack_require__(29);
  290. var _toolbar = __webpack_require__(31);
  291. var _view_history = __webpack_require__(32);
  292. const DEFAULT_SCALE_DELTA = 1.1;
  293. const DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT = 5000;
  294. const FORCE_PAGES_LOADED_TIMEOUT = 10000;
  295. const WHEEL_ZOOM_DISABLED_TIMEOUT = 1000;
  296. const ViewOnLoad = {
  297. UNKNOWN: -1,
  298. PREVIOUS: 0,
  299. INITIAL: 1
  300. };
  301. class DefaultExternalServices {
  302. constructor() {
  303. throw new Error("Cannot initialize DefaultExternalServices.");
  304. }
  305. static updateFindControlState(data) {}
  306. static updateFindMatchesCount(data) {}
  307. static initPassiveLoading(callbacks) {}
  308. static fallback(data, callback) {}
  309. static reportTelemetry(data) {}
  310. static createDownloadManager(options) {
  311. throw new Error("Not implemented: createDownloadManager");
  312. }
  313. static createPreferences() {
  314. throw new Error("Not implemented: createPreferences");
  315. }
  316. static createL10n(options) {
  317. throw new Error("Not implemented: createL10n");
  318. }
  319. static get supportsIntegratedFind() {
  320. return (0, _pdfjsLib.shadow)(this, "supportsIntegratedFind", false);
  321. }
  322. static get supportsDocumentFonts() {
  323. return (0, _pdfjsLib.shadow)(this, "supportsDocumentFonts", true);
  324. }
  325. static get supportedMouseWheelZoomModifierKeys() {
  326. return (0, _pdfjsLib.shadow)(this, "supportedMouseWheelZoomModifierKeys", {
  327. ctrlKey: true,
  328. metaKey: true
  329. });
  330. }
  331. }
  332. exports.DefaultExternalServices = DefaultExternalServices;
  333. const PDFViewerApplication = {
  334. initialBookmark: document.location.hash.substring(1),
  335. _initializedCapability: (0, _pdfjsLib.createPromiseCapability)(),
  336. fellback: false,
  337. appConfig: null,
  338. pdfDocument: null,
  339. pdfLoadingTask: null,
  340. printService: null,
  341. pdfViewer: null,
  342. pdfThumbnailViewer: null,
  343. pdfRenderingQueue: null,
  344. pdfPresentationMode: null,
  345. pdfDocumentProperties: null,
  346. pdfLinkService: null,
  347. pdfHistory: null,
  348. pdfSidebar: null,
  349. pdfSidebarResizer: null,
  350. pdfOutlineViewer: null,
  351. pdfAttachmentViewer: null,
  352. pdfCursorTools: null,
  353. store: null,
  354. downloadManager: null,
  355. overlayManager: null,
  356. preferences: null,
  357. toolbar: null,
  358. secondaryToolbar: null,
  359. eventBus: null,
  360. l10n: null,
  361. isInitialViewSet: false,
  362. downloadComplete: false,
  363. isViewerEmbedded: window.parent !== window,
  364. url: "",
  365. baseUrl: "",
  366. externalServices: DefaultExternalServices,
  367. _boundEvents: {},
  368. contentDispositionFilename: null,
  369. async initialize(appConfig) {
  370. this.preferences = this.externalServices.createPreferences();
  371. this.appConfig = appConfig;
  372. await this._readPreferences();
  373. await this._parseHashParameters();
  374. await this._initializeL10n();
  375. if (this.isViewerEmbedded && _app_options.AppOptions.get("externalLinkTarget") === _pdfjsLib.LinkTarget.NONE) {
  376. _app_options.AppOptions.set("externalLinkTarget", _pdfjsLib.LinkTarget.TOP);
  377. }
  378. await this._initializeViewerComponents();
  379. this.bindEvents();
  380. this.bindWindowEvents();
  381. const appContainer = appConfig.appContainer || document.documentElement;
  382. this.l10n.translate(appContainer).then(() => {
  383. this.eventBus.dispatch("localized", {
  384. source: this
  385. });
  386. });
  387. this._initializedCapability.resolve();
  388. },
  389. async _readPreferences() {
  390. if (_app_options.AppOptions.get("disablePreferences") === true) {
  391. return;
  392. }
  393. try {
  394. const prefs = await this.preferences.getAll();
  395. for (const name in prefs) {
  396. _app_options.AppOptions.set(name, prefs[name]);
  397. }
  398. } catch (reason) {
  399. console.error(`_readPreferences: "${reason.message}".`);
  400. }
  401. },
  402. async _parseHashParameters() {
  403. if (!_app_options.AppOptions.get("pdfBugEnabled")) {
  404. return undefined;
  405. }
  406. const hash = document.location.hash.substring(1);
  407. if (!hash) {
  408. return undefined;
  409. }
  410. const hashParams = (0, _ui_utils.parseQueryString)(hash),
  411. waitOn = [];
  412. if ("disableworker" in hashParams && hashParams["disableworker"] === "true") {
  413. waitOn.push(loadFakeWorker());
  414. }
  415. if ("disablerange" in hashParams) {
  416. _app_options.AppOptions.set("disableRange", hashParams["disablerange"] === "true");
  417. }
  418. if ("disablestream" in hashParams) {
  419. _app_options.AppOptions.set("disableStream", hashParams["disablestream"] === "true");
  420. }
  421. if ("disableautofetch" in hashParams) {
  422. _app_options.AppOptions.set("disableAutoFetch", hashParams["disableautofetch"] === "true");
  423. }
  424. if ("disablefontface" in hashParams) {
  425. _app_options.AppOptions.set("disableFontFace", hashParams["disablefontface"] === "true");
  426. }
  427. if ("disablehistory" in hashParams) {
  428. _app_options.AppOptions.set("disableHistory", hashParams["disablehistory"] === "true");
  429. }
  430. if ("webgl" in hashParams) {
  431. _app_options.AppOptions.set("enableWebGL", hashParams["webgl"] === "true");
  432. }
  433. if ("verbosity" in hashParams) {
  434. _app_options.AppOptions.set("verbosity", hashParams["verbosity"] | 0);
  435. }
  436. if ("textlayer" in hashParams) {
  437. switch (hashParams["textlayer"]) {
  438. case "off":
  439. _app_options.AppOptions.set("textLayerMode", _ui_utils.TextLayerMode.DISABLE);
  440. break;
  441. case "visible":
  442. case "shadow":
  443. case "hover":
  444. const viewer = this.appConfig.viewerContainer;
  445. viewer.classList.add("textLayer-" + hashParams["textlayer"]);
  446. break;
  447. }
  448. }
  449. if ("pdfbug" in hashParams) {
  450. _app_options.AppOptions.set("pdfBug", true);
  451. const enabled = hashParams["pdfbug"].split(",");
  452. waitOn.push(loadAndEnablePDFBug(enabled));
  453. }
  454. if ("locale" in hashParams) {
  455. _app_options.AppOptions.set("locale", hashParams["locale"]);
  456. }
  457. return Promise.all(waitOn).catch(reason => {
  458. console.error(`_parseHashParameters: "${reason.message}".`);
  459. });
  460. },
  461. async _initializeL10n() {
  462. this.l10n = this.externalServices.createL10n({
  463. locale: _app_options.AppOptions.get("locale")
  464. });
  465. const dir = await this.l10n.getDirection();
  466. document.getElementsByTagName("html")[0].dir = dir;
  467. },
  468. async _initializeViewerComponents() {
  469. const appConfig = this.appConfig;
  470. this.overlayManager = new _overlay_manager.OverlayManager();
  471. const eventBus = appConfig.eventBus || new _ui_utils.EventBus({
  472. dispatchToDOM: _app_options.AppOptions.get("eventBusDispatchToDOM")
  473. });
  474. this.eventBus = eventBus;
  475. const pdfRenderingQueue = new _pdf_rendering_queue.PDFRenderingQueue();
  476. pdfRenderingQueue.onIdle = this.cleanup.bind(this);
  477. this.pdfRenderingQueue = pdfRenderingQueue;
  478. const pdfLinkService = new _pdf_link_service.PDFLinkService({
  479. eventBus,
  480. externalLinkTarget: _app_options.AppOptions.get("externalLinkTarget"),
  481. externalLinkRel: _app_options.AppOptions.get("externalLinkRel"),
  482. ignoreDestinationZoom: _app_options.AppOptions.get("ignoreDestinationZoom")
  483. });
  484. this.pdfLinkService = pdfLinkService;
  485. const downloadManager = this.externalServices.createDownloadManager({
  486. disableCreateObjectURL: _app_options.AppOptions.get("disableCreateObjectURL")
  487. });
  488. this.downloadManager = downloadManager;
  489. const findController = new _pdf_find_controller.PDFFindController({
  490. linkService: pdfLinkService,
  491. eventBus
  492. });
  493. this.findController = findController;
  494. const container = appConfig.mainContainer;
  495. const viewer = appConfig.viewerContainer;
  496. this.pdfViewer = new _pdf_viewer.PDFViewer({
  497. container,
  498. viewer,
  499. eventBus,
  500. renderingQueue: pdfRenderingQueue,
  501. linkService: pdfLinkService,
  502. downloadManager,
  503. findController,
  504. renderer: _app_options.AppOptions.get("renderer"),
  505. enableWebGL: _app_options.AppOptions.get("enableWebGL"),
  506. l10n: this.l10n,
  507. textLayerMode: _app_options.AppOptions.get("textLayerMode"),
  508. imageResourcesPath: _app_options.AppOptions.get("imageResourcesPath"),
  509. renderInteractiveForms: _app_options.AppOptions.get("renderInteractiveForms"),
  510. enablePrintAutoRotate: _app_options.AppOptions.get("enablePrintAutoRotate"),
  511. useOnlyCssZoom: _app_options.AppOptions.get("useOnlyCssZoom"),
  512. maxCanvasPixels: _app_options.AppOptions.get("maxCanvasPixels")
  513. });
  514. pdfRenderingQueue.setViewer(this.pdfViewer);
  515. pdfLinkService.setViewer(this.pdfViewer);
  516. this.pdfThumbnailViewer = new _pdf_thumbnail_viewer.PDFThumbnailViewer({
  517. container: appConfig.sidebar.thumbnailView,
  518. renderingQueue: pdfRenderingQueue,
  519. linkService: pdfLinkService,
  520. l10n: this.l10n
  521. });
  522. pdfRenderingQueue.setThumbnailViewer(this.pdfThumbnailViewer);
  523. this.pdfHistory = new _pdf_history.PDFHistory({
  524. linkService: pdfLinkService,
  525. eventBus
  526. });
  527. pdfLinkService.setHistory(this.pdfHistory);
  528. if (!this.supportsIntegratedFind) {
  529. this.findBar = new _pdf_find_bar.PDFFindBar(appConfig.findBar, eventBus, this.l10n);
  530. }
  531. this.pdfDocumentProperties = new _pdf_document_properties.PDFDocumentProperties(appConfig.documentProperties, this.overlayManager, eventBus, this.l10n);
  532. this.pdfCursorTools = new _pdf_cursor_tools.PDFCursorTools({
  533. container,
  534. eventBus,
  535. cursorToolOnLoad: _app_options.AppOptions.get("cursorToolOnLoad")
  536. });
  537. this.toolbar = new _toolbar.Toolbar(appConfig.toolbar, eventBus, this.l10n);
  538. this.secondaryToolbar = new _secondary_toolbar.SecondaryToolbar(appConfig.secondaryToolbar, container, eventBus);
  539. if (this.supportsFullscreen) {
  540. this.pdfPresentationMode = new _pdf_presentation_mode.PDFPresentationMode({
  541. container,
  542. pdfViewer: this.pdfViewer,
  543. eventBus,
  544. contextMenuItems: appConfig.fullscreen
  545. });
  546. }
  547. this.passwordPrompt = new _password_prompt.PasswordPrompt(appConfig.passwordOverlay, this.overlayManager, this.l10n);
  548. this.pdfOutlineViewer = new _pdf_outline_viewer.PDFOutlineViewer({
  549. container: appConfig.sidebar.outlineView,
  550. eventBus,
  551. linkService: pdfLinkService
  552. });
  553. this.pdfAttachmentViewer = new _pdf_attachment_viewer.PDFAttachmentViewer({
  554. container: appConfig.sidebar.attachmentsView,
  555. eventBus,
  556. downloadManager
  557. });
  558. this.pdfSidebar = new _pdf_sidebar.PDFSidebar({
  559. elements: appConfig.sidebar,
  560. pdfViewer: this.pdfViewer,
  561. pdfThumbnailViewer: this.pdfThumbnailViewer,
  562. eventBus,
  563. l10n: this.l10n
  564. });
  565. this.pdfSidebar.onToggled = this.forceRendering.bind(this);
  566. this.pdfSidebarResizer = new _pdf_sidebar_resizer.PDFSidebarResizer(appConfig.sidebarResizer, eventBus, this.l10n);
  567. },
  568. run(config) {
  569. this.initialize(config).then(webViewerInitialized);
  570. },
  571. get initialized() {
  572. return this._initializedCapability.settled;
  573. },
  574. get initializedPromise() {
  575. return this._initializedCapability.promise;
  576. },
  577. zoomIn(ticks) {
  578. if (this.pdfViewer.isInPresentationMode) {
  579. return;
  580. }
  581. let newScale = this.pdfViewer.currentScale;
  582. do {
  583. newScale = (newScale * DEFAULT_SCALE_DELTA).toFixed(2);
  584. newScale = Math.ceil(newScale * 10) / 10;
  585. newScale = Math.min(_ui_utils.MAX_SCALE, newScale);
  586. } while (--ticks > 0 && newScale < _ui_utils.MAX_SCALE);
  587. this.pdfViewer.currentScaleValue = newScale;
  588. },
  589. zoomOut(ticks) {
  590. if (this.pdfViewer.isInPresentationMode) {
  591. return;
  592. }
  593. let newScale = this.pdfViewer.currentScale;
  594. do {
  595. newScale = (newScale / DEFAULT_SCALE_DELTA).toFixed(2);
  596. newScale = Math.floor(newScale * 10) / 10;
  597. newScale = Math.max(_ui_utils.MIN_SCALE, newScale);
  598. } while (--ticks > 0 && newScale > _ui_utils.MIN_SCALE);
  599. this.pdfViewer.currentScaleValue = newScale;
  600. },
  601. zoomReset() {
  602. if (this.pdfViewer.isInPresentationMode) {
  603. return;
  604. }
  605. this.pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  606. },
  607. get pagesCount() {
  608. return this.pdfDocument ? this.pdfDocument.numPages : 0;
  609. },
  610. set page(val) {
  611. this.pdfViewer.currentPageNumber = val;
  612. },
  613. get page() {
  614. return this.pdfViewer.currentPageNumber;
  615. },
  616. get printing() {
  617. return !!this.printService;
  618. },
  619. get supportsPrinting() {
  620. return PDFPrintServiceFactory.instance.supportsPrinting;
  621. },
  622. get supportsFullscreen() {
  623. let support;
  624. const doc = document.documentElement;
  625. support = !!(doc.requestFullscreen || doc.mozRequestFullScreen || doc.webkitRequestFullScreen || doc.msRequestFullscreen);
  626. if (document.fullscreenEnabled === false || document.mozFullScreenEnabled === false || document.webkitFullscreenEnabled === false || document.msFullscreenEnabled === false) {
  627. support = false;
  628. }
  629. return (0, _pdfjsLib.shadow)(this, "supportsFullscreen", support);
  630. },
  631. get supportsIntegratedFind() {
  632. return this.externalServices.supportsIntegratedFind;
  633. },
  634. get supportsDocumentFonts() {
  635. return this.externalServices.supportsDocumentFonts;
  636. },
  637. get loadingBar() {
  638. const bar = new _ui_utils.ProgressBar("#loadingBar");
  639. return (0, _pdfjsLib.shadow)(this, "loadingBar", bar);
  640. },
  641. get supportedMouseWheelZoomModifierKeys() {
  642. return this.externalServices.supportedMouseWheelZoomModifierKeys;
  643. },
  644. initPassiveLoading() {
  645. throw new Error("Not implemented: initPassiveLoading");
  646. },
  647. setTitleUsingUrl(url = "") {
  648. this.url = url;
  649. this.baseUrl = url.split("#")[0];
  650. let title = (0, _ui_utils.getPDFFileNameFromURL)(url, "");
  651. if (!title) {
  652. try {
  653. title = decodeURIComponent((0, _pdfjsLib.getFilenameFromUrl)(url)) || url;
  654. } catch (ex) {
  655. title = url;
  656. }
  657. }
  658. this.setTitle(title);
  659. },
  660. setTitle(title) {
  661. if (this.isViewerEmbedded) {
  662. return;
  663. }
  664. document.title = title;
  665. },
  666. async close() {
  667. const errorWrapper = this.appConfig.errorWrapper.container;
  668. errorWrapper.setAttribute("hidden", "true");
  669. if (!this.pdfLoadingTask) {
  670. return undefined;
  671. }
  672. const promise = this.pdfLoadingTask.destroy();
  673. this.pdfLoadingTask = null;
  674. if (this.pdfDocument) {
  675. this.pdfDocument = null;
  676. this.pdfThumbnailViewer.setDocument(null);
  677. this.pdfViewer.setDocument(null);
  678. this.pdfLinkService.setDocument(null);
  679. this.pdfDocumentProperties.setDocument(null);
  680. }
  681. this.store = null;
  682. this.isInitialViewSet = false;
  683. this.downloadComplete = false;
  684. this.url = "";
  685. this.baseUrl = "";
  686. this.contentDispositionFilename = null;
  687. this.pdfSidebar.reset();
  688. this.pdfOutlineViewer.reset();
  689. this.pdfAttachmentViewer.reset();
  690. if (this.pdfHistory) {
  691. this.pdfHistory.reset();
  692. }
  693. if (this.findBar) {
  694. this.findBar.reset();
  695. }
  696. this.toolbar.reset();
  697. this.secondaryToolbar.reset();
  698. if (typeof PDFBug !== "undefined") {
  699. PDFBug.cleanup();
  700. }
  701. return promise;
  702. },
  703. async open(file, args) {
  704. if (this.pdfLoadingTask) {
  705. await this.close();
  706. }
  707. const workerParameters = _app_options.AppOptions.getAll(_app_options.OptionKind.WORKER);
  708. for (const key in workerParameters) {
  709. _pdfjsLib.GlobalWorkerOptions[key] = workerParameters[key];
  710. }
  711. const parameters = Object.create(null);
  712. if (typeof file === "string") {
  713. this.setTitleUsingUrl(file);
  714. parameters.url = file;
  715. } else if (file && "byteLength" in file) {
  716. parameters.data = file;
  717. } else if (file.url && file.originalUrl) {
  718. this.setTitleUsingUrl(file.originalUrl);
  719. parameters.url = file.url;
  720. }
  721. const apiParameters = _app_options.AppOptions.getAll(_app_options.OptionKind.API);
  722. for (const key in apiParameters) {
  723. let value = apiParameters[key];
  724. if (key === "docBaseUrl" && !value) {}
  725. parameters[key] = value;
  726. }
  727. if (args) {
  728. for (const key in args) {
  729. const value = args[key];
  730. if (key === "length") {
  731. this.pdfDocumentProperties.setFileSize(value);
  732. }
  733. parameters[key] = value;
  734. }
  735. }
  736. const loadingTask = (0, _pdfjsLib.getDocument)(parameters);
  737. this.pdfLoadingTask = loadingTask;
  738. loadingTask.onPassword = (updateCallback, reason) => {
  739. this.pdfLinkService.externalLinkEnabled = false;
  740. this.passwordPrompt.setUpdateCallback(updateCallback, reason);
  741. this.passwordPrompt.open();
  742. };
  743. loadingTask.onProgress = ({
  744. loaded,
  745. total
  746. }) => {
  747. this.progress(loaded / total);
  748. };
  749. loadingTask.onUnsupportedFeature = this.fallback.bind(this);
  750. return loadingTask.promise.then(pdfDocument => {
  751. this.load(pdfDocument);
  752. }, exception => {
  753. if (loadingTask !== this.pdfLoadingTask) {
  754. return undefined;
  755. }
  756. const message = exception && exception.message;
  757. let loadingErrorMessage;
  758. if (exception instanceof _pdfjsLib.InvalidPDFException) {
  759. loadingErrorMessage = this.l10n.get("invalid_file_error", null, "Invalid or corrupted PDF file.");
  760. } else if (exception instanceof _pdfjsLib.MissingPDFException) {
  761. loadingErrorMessage = this.l10n.get("missing_file_error", null, "Missing PDF file.");
  762. } else if (exception instanceof _pdfjsLib.UnexpectedResponseException) {
  763. loadingErrorMessage = this.l10n.get("unexpected_response_error", null, "Unexpected server response.");
  764. } else {
  765. loadingErrorMessage = this.l10n.get("loading_error", null, "An error occurred while loading the PDF.");
  766. }
  767. return loadingErrorMessage.then(msg => {
  768. this.error(msg, {
  769. message
  770. });
  771. throw new Error(msg);
  772. });
  773. });
  774. },
  775. download() {
  776. function downloadByUrl() {
  777. downloadManager.downloadUrl(url, filename);
  778. }
  779. const url = this.baseUrl;
  780. const filename = this.contentDispositionFilename || (0, _ui_utils.getPDFFileNameFromURL)(this.url);
  781. const downloadManager = this.downloadManager;
  782. downloadManager.onerror = err => {
  783. this.error(`PDF failed to download: ${err}`);
  784. };
  785. if (!this.pdfDocument || !this.downloadComplete) {
  786. downloadByUrl();
  787. return;
  788. }
  789. this.pdfDocument.getData().then(function (data) {
  790. const blob = new Blob([data], {
  791. type: "application/pdf"
  792. });
  793. downloadManager.download(blob, url, filename);
  794. }).catch(downloadByUrl);
  795. },
  796. fallback(featureId) {
  797. if (this.fellback) {
  798. return;
  799. }
  800. this.fellback = true;
  801. this.externalServices.fallback({
  802. featureId,
  803. url: this.baseUrl
  804. }, function response(download) {
  805. if (!download) {
  806. return;
  807. }
  808. PDFViewerApplication.download();
  809. });
  810. },
  811. error(message, moreInfo) {
  812. const moreInfoText = [this.l10n.get("error_version_info", {
  813. version: _pdfjsLib.version || "?",
  814. build: _pdfjsLib.build || "?"
  815. }, "PDF.js v{{version}} (build: {{build}})")];
  816. if (moreInfo) {
  817. moreInfoText.push(this.l10n.get("error_message", {
  818. message: moreInfo.message
  819. }, "Message: {{message}}"));
  820. if (moreInfo.stack) {
  821. moreInfoText.push(this.l10n.get("error_stack", {
  822. stack: moreInfo.stack
  823. }, "Stack: {{stack}}"));
  824. } else {
  825. if (moreInfo.filename) {
  826. moreInfoText.push(this.l10n.get("error_file", {
  827. file: moreInfo.filename
  828. }, "File: {{file}}"));
  829. }
  830. if (moreInfo.lineNumber) {
  831. moreInfoText.push(this.l10n.get("error_line", {
  832. line: moreInfo.lineNumber
  833. }, "Line: {{line}}"));
  834. }
  835. }
  836. }
  837. const errorWrapperConfig = this.appConfig.errorWrapper;
  838. const errorWrapper = errorWrapperConfig.container;
  839. errorWrapper.removeAttribute("hidden");
  840. const errorMessage = errorWrapperConfig.errorMessage;
  841. errorMessage.textContent = message;
  842. const closeButton = errorWrapperConfig.closeButton;
  843. closeButton.onclick = function () {
  844. errorWrapper.setAttribute("hidden", "true");
  845. };
  846. const errorMoreInfo = errorWrapperConfig.errorMoreInfo;
  847. const moreInfoButton = errorWrapperConfig.moreInfoButton;
  848. const lessInfoButton = errorWrapperConfig.lessInfoButton;
  849. moreInfoButton.onclick = function () {
  850. errorMoreInfo.removeAttribute("hidden");
  851. moreInfoButton.setAttribute("hidden", "true");
  852. lessInfoButton.removeAttribute("hidden");
  853. errorMoreInfo.style.height = errorMoreInfo.scrollHeight + "px";
  854. };
  855. lessInfoButton.onclick = function () {
  856. errorMoreInfo.setAttribute("hidden", "true");
  857. moreInfoButton.removeAttribute("hidden");
  858. lessInfoButton.setAttribute("hidden", "true");
  859. };
  860. moreInfoButton.oncontextmenu = _ui_utils.noContextMenuHandler;
  861. lessInfoButton.oncontextmenu = _ui_utils.noContextMenuHandler;
  862. closeButton.oncontextmenu = _ui_utils.noContextMenuHandler;
  863. moreInfoButton.removeAttribute("hidden");
  864. lessInfoButton.setAttribute("hidden", "true");
  865. Promise.all(moreInfoText).then(parts => {
  866. errorMoreInfo.value = parts.join("\n");
  867. });
  868. },
  869. progress(level) {
  870. if (this.downloadComplete) {
  871. return;
  872. }
  873. const percent = Math.round(level * 100);
  874. if (percent > this.loadingBar.percent || isNaN(percent)) {
  875. this.loadingBar.percent = percent;
  876. const disableAutoFetch = this.pdfDocument ? this.pdfDocument.loadingParams["disableAutoFetch"] : _app_options.AppOptions.get("disableAutoFetch");
  877. if (disableAutoFetch && percent) {
  878. if (this.disableAutoFetchLoadingBarTimeout) {
  879. clearTimeout(this.disableAutoFetchLoadingBarTimeout);
  880. this.disableAutoFetchLoadingBarTimeout = null;
  881. }
  882. this.loadingBar.show();
  883. this.disableAutoFetchLoadingBarTimeout = setTimeout(() => {
  884. this.loadingBar.hide();
  885. this.disableAutoFetchLoadingBarTimeout = null;
  886. }, DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT);
  887. }
  888. }
  889. },
  890. load(pdfDocument) {
  891. this.pdfDocument = pdfDocument;
  892. pdfDocument.getDownloadInfo().then(() => {
  893. this.downloadComplete = true;
  894. this.loadingBar.hide();
  895. firstPagePromise.then(() => {
  896. this.eventBus.dispatch("documentloaded", {
  897. source: this
  898. });
  899. });
  900. });
  901. const pageLayoutPromise = pdfDocument.getPageLayout().catch(function () {});
  902. const pageModePromise = pdfDocument.getPageMode().catch(function () {});
  903. const openActionPromise = pdfDocument.getOpenAction().catch(function () {});
  904. this.toolbar.setPagesCount(pdfDocument.numPages, false);
  905. this.secondaryToolbar.setPagesCount(pdfDocument.numPages);
  906. const store = this.store = new _view_history.ViewHistory(pdfDocument.fingerprint);
  907. let baseDocumentUrl;
  908. baseDocumentUrl = null;
  909. this.pdfLinkService.setDocument(pdfDocument, baseDocumentUrl);
  910. this.pdfDocumentProperties.setDocument(pdfDocument, this.url);
  911. const pdfViewer = this.pdfViewer;
  912. pdfViewer.setDocument(pdfDocument);
  913. const {
  914. firstPagePromise,
  915. onePageRendered,
  916. pagesPromise
  917. } = pdfViewer;
  918. const pdfThumbnailViewer = this.pdfThumbnailViewer;
  919. pdfThumbnailViewer.setDocument(pdfDocument);
  920. firstPagePromise.then(pdfPage => {
  921. this.loadingBar.setWidth(this.appConfig.viewerContainer);
  922. const storePromise = store.getMultiple({
  923. page: null,
  924. zoom: _ui_utils.DEFAULT_SCALE_VALUE,
  925. scrollLeft: "0",
  926. scrollTop: "0",
  927. rotation: null,
  928. sidebarView: _pdf_sidebar.SidebarView.UNKNOWN,
  929. scrollMode: _ui_utils.ScrollMode.UNKNOWN,
  930. spreadMode: _ui_utils.SpreadMode.UNKNOWN
  931. }).catch(() => {});
  932. Promise.all([_ui_utils.animationStarted, storePromise, pageLayoutPromise, pageModePromise, openActionPromise]).then(async ([timeStamp, values = {}, pageLayout, pageMode, openAction]) => {
  933. const viewOnLoad = _app_options.AppOptions.get("viewOnLoad");
  934. this._initializePdfHistory({
  935. fingerprint: pdfDocument.fingerprint,
  936. viewOnLoad,
  937. initialDest: openAction && openAction.dest
  938. });
  939. const initialBookmark = this.initialBookmark;
  940. const zoom = _app_options.AppOptions.get("defaultZoomValue");
  941. let hash = zoom ? `zoom=${zoom}` : null;
  942. let rotation = null;
  943. let sidebarView = _app_options.AppOptions.get("sidebarViewOnLoad");
  944. let scrollMode = _app_options.AppOptions.get("scrollModeOnLoad");
  945. let spreadMode = _app_options.AppOptions.get("spreadModeOnLoad");
  946. if (values.page && viewOnLoad !== ViewOnLoad.INITIAL) {
  947. hash = `page=${values.page}&zoom=${zoom || values.zoom},` + `${values.scrollLeft},${values.scrollTop}`;
  948. rotation = parseInt(values.rotation, 10);
  949. if (sidebarView === _pdf_sidebar.SidebarView.UNKNOWN) {
  950. sidebarView = values.sidebarView | 0;
  951. }
  952. if (scrollMode === _ui_utils.ScrollMode.UNKNOWN) {
  953. scrollMode = values.scrollMode | 0;
  954. }
  955. if (spreadMode === _ui_utils.SpreadMode.UNKNOWN) {
  956. spreadMode = values.spreadMode | 0;
  957. }
  958. }
  959. if (pageMode && sidebarView === _pdf_sidebar.SidebarView.UNKNOWN) {
  960. sidebarView = apiPageModeToSidebarView(pageMode);
  961. }
  962. if (pageLayout && spreadMode === _ui_utils.SpreadMode.UNKNOWN) {
  963. spreadMode = apiPageLayoutToSpreadMode(pageLayout);
  964. }
  965. this.setInitialView(hash, {
  966. rotation,
  967. sidebarView,
  968. scrollMode,
  969. spreadMode
  970. });
  971. this.eventBus.dispatch("documentinit", {
  972. source: this
  973. });
  974. if (!this.isViewerEmbedded) {
  975. pdfViewer.focus();
  976. }
  977. await Promise.race([pagesPromise, new Promise(resolve => {
  978. setTimeout(resolve, FORCE_PAGES_LOADED_TIMEOUT);
  979. })]);
  980. if (!initialBookmark && !hash) {
  981. return;
  982. }
  983. if (pdfViewer.hasEqualPageSizes) {
  984. return;
  985. }
  986. this.initialBookmark = initialBookmark;
  987. pdfViewer.currentScaleValue = pdfViewer.currentScaleValue;
  988. this.setInitialView(hash);
  989. }).catch(() => {
  990. this.setInitialView();
  991. }).then(function () {
  992. pdfViewer.update();
  993. });
  994. });
  995. pdfDocument.getPageLabels().then(labels => {
  996. if (!labels || _app_options.AppOptions.get("disablePageLabels")) {
  997. return;
  998. }
  999. const numLabels = labels.length;
  1000. if (numLabels !== this.pagesCount) {
  1001. console.error("The number of Page Labels does not match " + "the number of pages in the document.");
  1002. return;
  1003. }
  1004. let i = 0;
  1005. while (i < numLabels && labels[i] === (i + 1).toString()) {
  1006. i++;
  1007. }
  1008. if (i === numLabels) {
  1009. return;
  1010. }
  1011. pdfViewer.setPageLabels(labels);
  1012. pdfThumbnailViewer.setPageLabels(labels);
  1013. this.toolbar.setPagesCount(pdfDocument.numPages, true);
  1014. this.toolbar.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
  1015. });
  1016. pagesPromise.then(async () => {
  1017. const [openAction, javaScript] = await Promise.all([openActionPromise, pdfDocument.getJavaScript()]);
  1018. let triggerAutoPrint = false;
  1019. if (openAction && openAction.action === "Print") {
  1020. triggerAutoPrint = true;
  1021. }
  1022. if (javaScript) {
  1023. javaScript.some(js => {
  1024. if (!js) {
  1025. return false;
  1026. }
  1027. console.warn("Warning: JavaScript is not supported");
  1028. this.fallback(_pdfjsLib.UNSUPPORTED_FEATURES.javaScript);
  1029. return true;
  1030. });
  1031. if (!triggerAutoPrint) {
  1032. for (const js of javaScript) {
  1033. if (js && _ui_utils.AutoPrintRegExp.test(js)) {
  1034. triggerAutoPrint = true;
  1035. break;
  1036. }
  1037. }
  1038. }
  1039. }
  1040. if (!this.supportsPrinting) {
  1041. return;
  1042. }
  1043. if (triggerAutoPrint) {
  1044. setTimeout(function () {
  1045. window.print();
  1046. });
  1047. }
  1048. });
  1049. onePageRendered.then(() => {
  1050. pdfDocument.getOutline().then(outline => {
  1051. this.pdfOutlineViewer.render({
  1052. outline
  1053. });
  1054. });
  1055. pdfDocument.getAttachments().then(attachments => {
  1056. this.pdfAttachmentViewer.render({
  1057. attachments
  1058. });
  1059. });
  1060. });
  1061. pdfDocument.getMetadata().then(({
  1062. info,
  1063. metadata,
  1064. contentDispositionFilename
  1065. }) => {
  1066. this.documentInfo = info;
  1067. this.metadata = metadata;
  1068. this.contentDispositionFilename = contentDispositionFilename;
  1069. console.log("PDF " + pdfDocument.fingerprint + " [" + info.PDFFormatVersion + " " + (info.Producer || "-").trim() + " / " + (info.Creator || "-").trim() + "]" + " (PDF.js: " + (_pdfjsLib.version || "-") + (_app_options.AppOptions.get("enableWebGL") ? " [WebGL]" : "") + ")");
  1070. let pdfTitle;
  1071. const infoTitle = info && info["Title"];
  1072. if (infoTitle) {
  1073. pdfTitle = infoTitle;
  1074. }
  1075. const metadataTitle = metadata && metadata.get("dc:title");
  1076. if (metadataTitle) {
  1077. if (metadataTitle !== "Untitled" && !/[\uFFF0-\uFFFF]/g.test(metadataTitle)) {
  1078. pdfTitle = metadataTitle;
  1079. }
  1080. }
  1081. if (pdfTitle) {
  1082. this.setTitle(`${pdfTitle} - ${contentDispositionFilename || document.title}`);
  1083. } else if (contentDispositionFilename) {
  1084. this.setTitle(contentDispositionFilename);
  1085. }
  1086. if (info.IsAcroFormPresent) {
  1087. console.warn("Warning: AcroForm/XFA is not supported");
  1088. this.fallback(_pdfjsLib.UNSUPPORTED_FEATURES.forms);
  1089. }
  1090. let versionId = "other";
  1091. 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"];
  1092. if (KNOWN_VERSIONS.includes(info.PDFFormatVersion)) {
  1093. versionId = `v${info.PDFFormatVersion.replace(".", "_")}`;
  1094. }
  1095. let generatorId = "other";
  1096. 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"];
  1097. if (info.Producer) {
  1098. const producer = info.Producer.toLowerCase();
  1099. KNOWN_GENERATORS.some(function (generator) {
  1100. if (!producer.includes(generator)) {
  1101. return false;
  1102. }
  1103. generatorId = generator.replace(/[ .\-]/g, "_");
  1104. return true;
  1105. });
  1106. }
  1107. let formType = null;
  1108. if (info.IsAcroFormPresent) {
  1109. formType = info.IsXFAPresent ? "xfa" : "acroform";
  1110. }
  1111. this.externalServices.reportTelemetry({
  1112. type: "documentInfo",
  1113. version: versionId,
  1114. generator: generatorId,
  1115. formType
  1116. });
  1117. });
  1118. },
  1119. _initializePdfHistory({
  1120. fingerprint,
  1121. viewOnLoad,
  1122. initialDest = null
  1123. }) {
  1124. if (_app_options.AppOptions.get("disableHistory") || this.isViewerEmbedded) {
  1125. return;
  1126. }
  1127. this.pdfHistory.initialize({
  1128. fingerprint,
  1129. resetHistory: viewOnLoad === ViewOnLoad.INITIAL,
  1130. updateUrl: _app_options.AppOptions.get("historyUpdateUrl")
  1131. });
  1132. if (this.pdfHistory.initialBookmark) {
  1133. this.initialBookmark = this.pdfHistory.initialBookmark;
  1134. this.initialRotation = this.pdfHistory.initialRotation;
  1135. }
  1136. if (initialDest && !this.initialBookmark && viewOnLoad === ViewOnLoad.UNKNOWN) {
  1137. this.initialBookmark = JSON.stringify(initialDest);
  1138. this.pdfHistory.push({
  1139. explicitDest: initialDest,
  1140. pageNumber: null
  1141. });
  1142. }
  1143. },
  1144. setInitialView(storedHash, {
  1145. rotation,
  1146. sidebarView,
  1147. scrollMode,
  1148. spreadMode
  1149. } = {}) {
  1150. const setRotation = angle => {
  1151. if ((0, _ui_utils.isValidRotation)(angle)) {
  1152. this.pdfViewer.pagesRotation = angle;
  1153. }
  1154. };
  1155. const setViewerModes = (scroll, spread) => {
  1156. if ((0, _ui_utils.isValidScrollMode)(scroll)) {
  1157. this.pdfViewer.scrollMode = scroll;
  1158. }
  1159. if ((0, _ui_utils.isValidSpreadMode)(spread)) {
  1160. this.pdfViewer.spreadMode = spread;
  1161. }
  1162. };
  1163. this.isInitialViewSet = true;
  1164. this.pdfSidebar.setInitialView(sidebarView);
  1165. setViewerModes(scrollMode, spreadMode);
  1166. if (this.initialBookmark) {
  1167. setRotation(this.initialRotation);
  1168. delete this.initialRotation;
  1169. this.pdfLinkService.setHash(this.initialBookmark);
  1170. this.initialBookmark = null;
  1171. } else if (storedHash) {
  1172. setRotation(rotation);
  1173. this.pdfLinkService.setHash(storedHash);
  1174. }
  1175. this.toolbar.setPageNumber(this.pdfViewer.currentPageNumber, this.pdfViewer.currentPageLabel);
  1176. this.secondaryToolbar.setPageNumber(this.pdfViewer.currentPageNumber);
  1177. if (!this.pdfViewer.currentScaleValue) {
  1178. this.pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  1179. }
  1180. },
  1181. cleanup() {
  1182. if (!this.pdfDocument) {
  1183. return;
  1184. }
  1185. this.pdfViewer.cleanup();
  1186. this.pdfThumbnailViewer.cleanup();
  1187. if (this.pdfViewer.renderer !== _ui_utils.RendererType.SVG) {
  1188. this.pdfDocument.cleanup();
  1189. }
  1190. },
  1191. forceRendering() {
  1192. this.pdfRenderingQueue.printing = this.printing;
  1193. this.pdfRenderingQueue.isThumbnailViewEnabled = this.pdfSidebar.isThumbnailViewVisible;
  1194. this.pdfRenderingQueue.renderHighestPriority();
  1195. },
  1196. beforePrint() {
  1197. if (this.printService) {
  1198. return;
  1199. }
  1200. if (!this.supportsPrinting) {
  1201. this.l10n.get("printing_not_supported", null, "Warning: Printing is not fully supported by this browser.").then(printMessage => {
  1202. this.error(printMessage);
  1203. });
  1204. return;
  1205. }
  1206. if (!this.pdfViewer.pageViewsReady) {
  1207. this.l10n.get("printing_not_ready", null, "Warning: The PDF is not fully loaded for printing.").then(notReadyMessage => {
  1208. window.alert(notReadyMessage);
  1209. });
  1210. return;
  1211. }
  1212. const pagesOverview = this.pdfViewer.getPagesOverview();
  1213. const printContainer = this.appConfig.printContainer;
  1214. const printService = PDFPrintServiceFactory.instance.createPrintService(this.pdfDocument, pagesOverview, printContainer, this.l10n);
  1215. this.printService = printService;
  1216. this.forceRendering();
  1217. printService.layout();
  1218. this.externalServices.reportTelemetry({
  1219. type: "print"
  1220. });
  1221. },
  1222. afterPrint() {
  1223. if (this.printService) {
  1224. this.printService.destroy();
  1225. this.printService = null;
  1226. }
  1227. this.forceRendering();
  1228. },
  1229. rotatePages(delta) {
  1230. if (!this.pdfDocument) {
  1231. return;
  1232. }
  1233. const newRotation = (this.pdfViewer.pagesRotation + 360 + delta) % 360;
  1234. this.pdfViewer.pagesRotation = newRotation;
  1235. },
  1236. requestPresentationMode() {
  1237. if (!this.pdfPresentationMode) {
  1238. return;
  1239. }
  1240. this.pdfPresentationMode.request();
  1241. },
  1242. bindEvents() {
  1243. const {
  1244. eventBus,
  1245. _boundEvents
  1246. } = this;
  1247. _boundEvents.beforePrint = this.beforePrint.bind(this);
  1248. _boundEvents.afterPrint = this.afterPrint.bind(this);
  1249. eventBus._on("resize", webViewerResize);
  1250. eventBus._on("hashchange", webViewerHashchange);
  1251. eventBus._on("beforeprint", _boundEvents.beforePrint);
  1252. eventBus._on("afterprint", _boundEvents.afterPrint);
  1253. eventBus._on("pagerendered", webViewerPageRendered);
  1254. eventBus._on("updateviewarea", webViewerUpdateViewarea);
  1255. eventBus._on("pagechanging", webViewerPageChanging);
  1256. eventBus._on("scalechanging", webViewerScaleChanging);
  1257. eventBus._on("rotationchanging", webViewerRotationChanging);
  1258. eventBus._on("sidebarviewchanged", webViewerSidebarViewChanged);
  1259. eventBus._on("pagemode", webViewerPageMode);
  1260. eventBus._on("namedaction", webViewerNamedAction);
  1261. eventBus._on("presentationmodechanged", webViewerPresentationModeChanged);
  1262. eventBus._on("presentationmode", webViewerPresentationMode);
  1263. eventBus._on("print", webViewerPrint);
  1264. eventBus._on("download", webViewerDownload);
  1265. eventBus._on("firstpage", webViewerFirstPage);
  1266. eventBus._on("lastpage", webViewerLastPage);
  1267. eventBus._on("nextpage", webViewerNextPage);
  1268. eventBus._on("previouspage", webViewerPreviousPage);
  1269. eventBus._on("zoomin", webViewerZoomIn);
  1270. eventBus._on("zoomout", webViewerZoomOut);
  1271. eventBus._on("zoomreset", webViewerZoomReset);
  1272. eventBus._on("pagenumberchanged", webViewerPageNumberChanged);
  1273. eventBus._on("scalechanged", webViewerScaleChanged);
  1274. eventBus._on("rotatecw", webViewerRotateCw);
  1275. eventBus._on("rotateccw", webViewerRotateCcw);
  1276. eventBus._on("switchscrollmode", webViewerSwitchScrollMode);
  1277. eventBus._on("scrollmodechanged", webViewerScrollModeChanged);
  1278. eventBus._on("switchspreadmode", webViewerSwitchSpreadMode);
  1279. eventBus._on("spreadmodechanged", webViewerSpreadModeChanged);
  1280. eventBus._on("documentproperties", webViewerDocumentProperties);
  1281. eventBus._on("find", webViewerFind);
  1282. eventBus._on("findfromurlhash", webViewerFindFromUrlHash);
  1283. eventBus._on("updatefindmatchescount", webViewerUpdateFindMatchesCount);
  1284. eventBus._on("updatefindcontrolstate", webViewerUpdateFindControlState);
  1285. eventBus._on("fileinputchange", webViewerFileInputChange);
  1286. eventBus._on("openfile", webViewerOpenFile);
  1287. },
  1288. bindWindowEvents() {
  1289. const {
  1290. eventBus,
  1291. _boundEvents
  1292. } = this;
  1293. _boundEvents.windowResize = () => {
  1294. eventBus.dispatch("resize", {
  1295. source: window
  1296. });
  1297. };
  1298. _boundEvents.windowHashChange = () => {
  1299. eventBus.dispatch("hashchange", {
  1300. source: window,
  1301. hash: document.location.hash.substring(1)
  1302. });
  1303. };
  1304. _boundEvents.windowBeforePrint = () => {
  1305. eventBus.dispatch("beforeprint", {
  1306. source: window
  1307. });
  1308. };
  1309. _boundEvents.windowAfterPrint = () => {
  1310. eventBus.dispatch("afterprint", {
  1311. source: window
  1312. });
  1313. };
  1314. window.addEventListener("visibilitychange", webViewerVisibilityChange);
  1315. window.addEventListener("wheel", webViewerWheel, {
  1316. passive: false
  1317. });
  1318. window.addEventListener("click", webViewerClick);
  1319. window.addEventListener("keydown", webViewerKeyDown);
  1320. window.addEventListener("resize", _boundEvents.windowResize);
  1321. window.addEventListener("hashchange", _boundEvents.windowHashChange);
  1322. window.addEventListener("beforeprint", _boundEvents.windowBeforePrint);
  1323. window.addEventListener("afterprint", _boundEvents.windowAfterPrint);
  1324. },
  1325. unbindEvents() {
  1326. const {
  1327. eventBus,
  1328. _boundEvents
  1329. } = this;
  1330. eventBus._off("resize", webViewerResize);
  1331. eventBus._off("hashchange", webViewerHashchange);
  1332. eventBus._off("beforeprint", _boundEvents.beforePrint);
  1333. eventBus._off("afterprint", _boundEvents.afterPrint);
  1334. eventBus._off("pagerendered", webViewerPageRendered);
  1335. eventBus._off("updateviewarea", webViewerUpdateViewarea);
  1336. eventBus._off("pagechanging", webViewerPageChanging);
  1337. eventBus._off("scalechanging", webViewerScaleChanging);
  1338. eventBus._off("rotationchanging", webViewerRotationChanging);
  1339. eventBus._off("sidebarviewchanged", webViewerSidebarViewChanged);
  1340. eventBus._off("pagemode", webViewerPageMode);
  1341. eventBus._off("namedaction", webViewerNamedAction);
  1342. eventBus._off("presentationmodechanged", webViewerPresentationModeChanged);
  1343. eventBus._off("presentationmode", webViewerPresentationMode);
  1344. eventBus._off("print", webViewerPrint);
  1345. eventBus._off("download", webViewerDownload);
  1346. eventBus._off("firstpage", webViewerFirstPage);
  1347. eventBus._off("lastpage", webViewerLastPage);
  1348. eventBus._off("nextpage", webViewerNextPage);
  1349. eventBus._off("previouspage", webViewerPreviousPage);
  1350. eventBus._off("zoomin", webViewerZoomIn);
  1351. eventBus._off("zoomout", webViewerZoomOut);
  1352. eventBus._off("zoomreset", webViewerZoomReset);
  1353. eventBus._off("pagenumberchanged", webViewerPageNumberChanged);
  1354. eventBus._off("scalechanged", webViewerScaleChanged);
  1355. eventBus._off("rotatecw", webViewerRotateCw);
  1356. eventBus._off("rotateccw", webViewerRotateCcw);
  1357. eventBus._off("switchscrollmode", webViewerSwitchScrollMode);
  1358. eventBus._off("scrollmodechanged", webViewerScrollModeChanged);
  1359. eventBus._off("switchspreadmode", webViewerSwitchSpreadMode);
  1360. eventBus._off("spreadmodechanged", webViewerSpreadModeChanged);
  1361. eventBus._off("documentproperties", webViewerDocumentProperties);
  1362. eventBus._off("find", webViewerFind);
  1363. eventBus._off("findfromurlhash", webViewerFindFromUrlHash);
  1364. eventBus._off("updatefindmatchescount", webViewerUpdateFindMatchesCount);
  1365. eventBus._off("updatefindcontrolstate", webViewerUpdateFindControlState);
  1366. eventBus._off("fileinputchange", webViewerFileInputChange);
  1367. eventBus._off("openfile", webViewerOpenFile);
  1368. _boundEvents.beforePrint = null;
  1369. _boundEvents.afterPrint = null;
  1370. },
  1371. unbindWindowEvents() {
  1372. const {
  1373. _boundEvents
  1374. } = this;
  1375. window.removeEventListener("visibilitychange", webViewerVisibilityChange);
  1376. window.removeEventListener("wheel", webViewerWheel);
  1377. window.removeEventListener("click", webViewerClick);
  1378. window.removeEventListener("keydown", webViewerKeyDown);
  1379. window.removeEventListener("resize", _boundEvents.windowResize);
  1380. window.removeEventListener("hashchange", _boundEvents.windowHashChange);
  1381. window.removeEventListener("beforeprint", _boundEvents.windowBeforePrint);
  1382. window.removeEventListener("afterprint", _boundEvents.windowAfterPrint);
  1383. _boundEvents.windowResize = null;
  1384. _boundEvents.windowHashChange = null;
  1385. _boundEvents.windowBeforePrint = null;
  1386. _boundEvents.windowAfterPrint = null;
  1387. }
  1388. };
  1389. exports.PDFViewerApplication = PDFViewerApplication;
  1390. let validateFileURL;
  1391. {
  1392. const HOSTED_VIEWER_ORIGINS = ["null", "http://mozilla.github.io", "https://mozilla.github.io"];
  1393. validateFileURL = function (file) {
  1394. if (file === undefined) {
  1395. return;
  1396. }
  1397. try {
  1398. const viewerOrigin = new URL(window.location.href).origin || "null";
  1399. if (HOSTED_VIEWER_ORIGINS.includes(viewerOrigin)) {
  1400. return;
  1401. }
  1402. const {
  1403. origin,
  1404. protocol
  1405. } = new URL(file, window.location.href);
  1406. // if (origin !== viewerOrigin && protocol !== "blob:") {
  1407. // throw new Error("file origin does not match viewer's");
  1408. // }
  1409. } catch (ex) {
  1410. const message = ex && ex.message;
  1411. PDFViewerApplication.l10n.get("loading_error", null, "An error occurred while loading the PDF.").then(loadingErrorMessage => {
  1412. PDFViewerApplication.error(loadingErrorMessage, {
  1413. message
  1414. });
  1415. });
  1416. throw ex;
  1417. }
  1418. };
  1419. }
  1420. async function loadFakeWorker() {
  1421. if (!_pdfjsLib.GlobalWorkerOptions.workerSrc) {
  1422. _pdfjsLib.GlobalWorkerOptions.workerSrc = _app_options.AppOptions.get("workerSrc");
  1423. }
  1424. return (0, _pdfjsLib.loadScript)(_pdfjsLib.PDFWorker.getWorkerSrc());
  1425. }
  1426. function loadAndEnablePDFBug(enabledTabs) {
  1427. const appConfig = PDFViewerApplication.appConfig;
  1428. return (0, _pdfjsLib.loadScript)(appConfig.debuggerScriptPath).then(function () {
  1429. PDFBug.enable(enabledTabs);
  1430. PDFBug.init({
  1431. OPS: _pdfjsLib.OPS
  1432. }, appConfig.mainContainer);
  1433. });
  1434. }
  1435. function webViewerInitialized() {
  1436. const appConfig = PDFViewerApplication.appConfig;
  1437. let file;
  1438. const queryString = document.location.search.substring(1);
  1439. const params = (0, _ui_utils.parseQueryString)(queryString);
  1440. file = "file" in params ? params.file : _app_options.AppOptions.get("defaultUrl");
  1441. validateFileURL(file);
  1442. const fileInput = document.createElement("input");
  1443. fileInput.id = appConfig.openFileInputName;
  1444. fileInput.className = "fileInput";
  1445. fileInput.setAttribute("type", "file");
  1446. fileInput.oncontextmenu = _ui_utils.noContextMenuHandler;
  1447. document.body.appendChild(fileInput);
  1448. if (!window.File || !window.FileReader || !window.FileList || !window.Blob) {
  1449. appConfig.toolbar.openFile.setAttribute("hidden", "true");
  1450. appConfig.secondaryToolbar.openFileButton.setAttribute("hidden", "true");
  1451. } else {
  1452. fileInput.value = null;
  1453. }
  1454. fileInput.addEventListener("change", function (evt) {
  1455. const files = evt.target.files;
  1456. if (!files || files.length === 0) {
  1457. return;
  1458. }
  1459. PDFViewerApplication.eventBus.dispatch("fileinputchange", {
  1460. source: this,
  1461. fileInput: evt.target
  1462. });
  1463. });
  1464. appConfig.mainContainer.addEventListener("dragover", function (evt) {
  1465. evt.preventDefault();
  1466. evt.dataTransfer.dropEffect = "move";
  1467. });
  1468. appConfig.mainContainer.addEventListener("drop", function (evt) {
  1469. evt.preventDefault();
  1470. const files = evt.dataTransfer.files;
  1471. if (!files || files.length === 0) {
  1472. return;
  1473. }
  1474. PDFViewerApplication.eventBus.dispatch("fileinputchange", {
  1475. source: this,
  1476. fileInput: evt.dataTransfer
  1477. });
  1478. });
  1479. if (!PDFViewerApplication.supportsDocumentFonts) {
  1480. _app_options.AppOptions.set("disableFontFace", true);
  1481. PDFViewerApplication.l10n.get("web_fonts_disabled", null, "Web fonts are disabled: unable to use embedded PDF fonts.").then(msg => {
  1482. console.warn(msg);
  1483. });
  1484. }
  1485. if (!PDFViewerApplication.supportsPrinting) {
  1486. appConfig.toolbar.print.classList.add("hidden");
  1487. appConfig.secondaryToolbar.printButton.classList.add("hidden");
  1488. }
  1489. if (!PDFViewerApplication.supportsFullscreen) {
  1490. appConfig.toolbar.presentationModeButton.classList.add("hidden");
  1491. appConfig.secondaryToolbar.presentationModeButton.classList.add("hidden");
  1492. }
  1493. if (PDFViewerApplication.supportsIntegratedFind) {
  1494. appConfig.toolbar.viewFind.classList.add("hidden");
  1495. }
  1496. appConfig.mainContainer.addEventListener("transitionend", function (evt) {
  1497. if (evt.target === this) {
  1498. PDFViewerApplication.eventBus.dispatch("resize", {
  1499. source: this
  1500. });
  1501. }
  1502. }, true);
  1503. try {
  1504. webViewerOpenFileViaURL(file);
  1505. } catch (reason) {
  1506. PDFViewerApplication.l10n.get("loading_error", null, "An error occurred while loading the PDF.").then(msg => {
  1507. PDFViewerApplication.error(msg, reason);
  1508. });
  1509. }
  1510. }
  1511. let webViewerOpenFileViaURL;
  1512. {
  1513. webViewerOpenFileViaURL = function (file) {
  1514. if (file && file.lastIndexOf("file:", 0) === 0) {
  1515. PDFViewerApplication.setTitleUsingUrl(file);
  1516. const xhr = new XMLHttpRequest();
  1517. xhr.onload = function () {
  1518. PDFViewerApplication.open(new Uint8Array(xhr.response));
  1519. };
  1520. xhr.open("GET", file);
  1521. xhr.responseType = "arraybuffer";
  1522. xhr.send();
  1523. return;
  1524. }
  1525. if (file) {
  1526. PDFViewerApplication.open(file);
  1527. }
  1528. };
  1529. }
  1530. function webViewerPageRendered(evt) {
  1531. const pageNumber = evt.pageNumber;
  1532. const pageIndex = pageNumber - 1;
  1533. const pageView = PDFViewerApplication.pdfViewer.getPageView(pageIndex);
  1534. if (pageNumber === PDFViewerApplication.page) {
  1535. PDFViewerApplication.toolbar.updateLoadingIndicatorState(false);
  1536. }
  1537. if (!pageView) {
  1538. return;
  1539. }
  1540. if (PDFViewerApplication.pdfSidebar.isThumbnailViewVisible) {
  1541. const thumbnailView = PDFViewerApplication.pdfThumbnailViewer.getThumbnail(pageIndex);
  1542. thumbnailView.setImage(pageView);
  1543. }
  1544. if (typeof Stats !== "undefined" && Stats.enabled && pageView.stats) {
  1545. Stats.add(pageNumber, pageView.stats);
  1546. }
  1547. if (pageView.error) {
  1548. PDFViewerApplication.l10n.get("rendering_error", null, "An error occurred while rendering the page.").then(msg => {
  1549. PDFViewerApplication.error(msg, pageView.error);
  1550. });
  1551. }
  1552. PDFViewerApplication.externalServices.reportTelemetry({
  1553. type: "pageInfo",
  1554. timestamp: evt.timestamp
  1555. });
  1556. PDFViewerApplication.pdfDocument.getStats().then(function (stats) {
  1557. PDFViewerApplication.externalServices.reportTelemetry({
  1558. type: "documentStats",
  1559. stats
  1560. });
  1561. });
  1562. }
  1563. function webViewerPageMode({
  1564. mode
  1565. }) {
  1566. let view;
  1567. switch (mode) {
  1568. case "thumbs":
  1569. view = _pdf_sidebar.SidebarView.THUMBS;
  1570. break;
  1571. case "bookmarks":
  1572. case "outline":
  1573. view = _pdf_sidebar.SidebarView.OUTLINE;
  1574. break;
  1575. case "attachments":
  1576. view = _pdf_sidebar.SidebarView.ATTACHMENTS;
  1577. break;
  1578. case "none":
  1579. view = _pdf_sidebar.SidebarView.NONE;
  1580. break;
  1581. default:
  1582. console.error('Invalid "pagemode" hash parameter: ' + mode);
  1583. return;
  1584. }
  1585. PDFViewerApplication.pdfSidebar.switchView(view, true);
  1586. }
  1587. function webViewerNamedAction(evt) {
  1588. const action = evt.action;
  1589. switch (action) {
  1590. case "GoToPage":
  1591. PDFViewerApplication.appConfig.toolbar.pageNumber.select();
  1592. break;
  1593. case "Find":
  1594. if (!PDFViewerApplication.supportsIntegratedFind) {
  1595. PDFViewerApplication.findBar.toggle();
  1596. }
  1597. break;
  1598. }
  1599. }
  1600. function webViewerPresentationModeChanged({
  1601. active,
  1602. switchInProgress
  1603. }) {
  1604. let state = _ui_utils.PresentationModeState.NORMAL;
  1605. if (switchInProgress) {
  1606. state = _ui_utils.PresentationModeState.CHANGING;
  1607. } else if (active) {
  1608. state = _ui_utils.PresentationModeState.FULLSCREEN;
  1609. }
  1610. PDFViewerApplication.pdfViewer.presentationModeState = state;
  1611. }
  1612. function webViewerSidebarViewChanged(evt) {
  1613. PDFViewerApplication.pdfRenderingQueue.isThumbnailViewEnabled = PDFViewerApplication.pdfSidebar.isThumbnailViewVisible;
  1614. const store = PDFViewerApplication.store;
  1615. if (store && PDFViewerApplication.isInitialViewSet) {
  1616. store.set("sidebarView", evt.view).catch(function () {});
  1617. }
  1618. }
  1619. function webViewerUpdateViewarea(evt) {
  1620. const location = evt.location,
  1621. store = PDFViewerApplication.store;
  1622. if (store && PDFViewerApplication.isInitialViewSet) {
  1623. store.setMultiple({
  1624. page: location.pageNumber,
  1625. zoom: location.scale,
  1626. scrollLeft: location.left,
  1627. scrollTop: location.top,
  1628. rotation: location.rotation
  1629. }).catch(function () {});
  1630. }
  1631. const href = PDFViewerApplication.pdfLinkService.getAnchorUrl(location.pdfOpenParams);
  1632. PDFViewerApplication.appConfig.toolbar.viewBookmark.href = href;
  1633. PDFViewerApplication.appConfig.secondaryToolbar.viewBookmarkButton.href = href;
  1634. const currentPage = PDFViewerApplication.pdfViewer.getPageView(PDFViewerApplication.page - 1);
  1635. const loading = currentPage.renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED;
  1636. PDFViewerApplication.toolbar.updateLoadingIndicatorState(loading);
  1637. }
  1638. function webViewerScrollModeChanged(evt) {
  1639. const store = PDFViewerApplication.store;
  1640. if (store && PDFViewerApplication.isInitialViewSet) {
  1641. store.set("scrollMode", evt.mode).catch(function () {});
  1642. }
  1643. }
  1644. function webViewerSpreadModeChanged(evt) {
  1645. const store = PDFViewerApplication.store;
  1646. if (store && PDFViewerApplication.isInitialViewSet) {
  1647. store.set("spreadMode", evt.mode).catch(function () {});
  1648. }
  1649. }
  1650. function webViewerResize() {
  1651. const {
  1652. pdfDocument,
  1653. pdfViewer
  1654. } = PDFViewerApplication;
  1655. if (!pdfDocument) {
  1656. return;
  1657. }
  1658. const currentScaleValue = pdfViewer.currentScaleValue;
  1659. if (currentScaleValue === "auto" || currentScaleValue === "page-fit" || currentScaleValue === "page-width") {
  1660. pdfViewer.currentScaleValue = currentScaleValue;
  1661. }
  1662. pdfViewer.update();
  1663. }
  1664. function webViewerHashchange(evt) {
  1665. const hash = evt.hash;
  1666. if (!hash) {
  1667. return;
  1668. }
  1669. if (!PDFViewerApplication.isInitialViewSet) {
  1670. PDFViewerApplication.initialBookmark = hash;
  1671. } else if (!PDFViewerApplication.pdfHistory.popStateInProgress) {
  1672. PDFViewerApplication.pdfLinkService.setHash(hash);
  1673. }
  1674. }
  1675. let webViewerFileInputChange, webViewerOpenFile;
  1676. {
  1677. webViewerFileInputChange = function (evt) {
  1678. if (PDFViewerApplication.pdfViewer && PDFViewerApplication.pdfViewer.isInPresentationMode) {
  1679. return;
  1680. }
  1681. const file = evt.fileInput.files[0];
  1682. if (URL.createObjectURL && !_app_options.AppOptions.get("disableCreateObjectURL")) {
  1683. let url = URL.createObjectURL(file);
  1684. if (file.name) {
  1685. url = {
  1686. url,
  1687. originalUrl: file.name
  1688. };
  1689. }
  1690. PDFViewerApplication.open(url);
  1691. } else {
  1692. PDFViewerApplication.setTitleUsingUrl(file.name);
  1693. const fileReader = new FileReader();
  1694. fileReader.onload = function webViewerChangeFileReaderOnload(event) {
  1695. const buffer = event.target.result;
  1696. PDFViewerApplication.open(new Uint8Array(buffer));
  1697. };
  1698. fileReader.readAsArrayBuffer(file);
  1699. }
  1700. const appConfig = PDFViewerApplication.appConfig;
  1701. appConfig.toolbar.viewBookmark.setAttribute("hidden", "true");
  1702. appConfig.secondaryToolbar.viewBookmarkButton.setAttribute("hidden", "true");
  1703. appConfig.toolbar.download.setAttribute("hidden", "true");
  1704. appConfig.secondaryToolbar.downloadButton.setAttribute("hidden", "true");
  1705. };
  1706. webViewerOpenFile = function (evt) {
  1707. const openFileInputName = PDFViewerApplication.appConfig.openFileInputName;
  1708. document.getElementById(openFileInputName).click();
  1709. };
  1710. }
  1711. function webViewerPresentationMode() {
  1712. PDFViewerApplication.requestPresentationMode();
  1713. }
  1714. function webViewerPrint() {
  1715. window.print();
  1716. }
  1717. function webViewerDownload() {
  1718. PDFViewerApplication.download();
  1719. }
  1720. function webViewerFirstPage() {
  1721. if (PDFViewerApplication.pdfDocument) {
  1722. PDFViewerApplication.page = 1;
  1723. }
  1724. }
  1725. function webViewerLastPage() {
  1726. if (PDFViewerApplication.pdfDocument) {
  1727. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  1728. }
  1729. }
  1730. function webViewerNextPage() {
  1731. PDFViewerApplication.page++;
  1732. }
  1733. function webViewerPreviousPage() {
  1734. PDFViewerApplication.page--;
  1735. }
  1736. function webViewerZoomIn() {
  1737. PDFViewerApplication.zoomIn();
  1738. }
  1739. function webViewerZoomOut() {
  1740. PDFViewerApplication.zoomOut();
  1741. }
  1742. function webViewerZoomReset() {
  1743. PDFViewerApplication.zoomReset();
  1744. }
  1745. function webViewerPageNumberChanged(evt) {
  1746. const pdfViewer = PDFViewerApplication.pdfViewer;
  1747. if (evt.value !== "") {
  1748. pdfViewer.currentPageLabel = evt.value;
  1749. }
  1750. if (evt.value !== pdfViewer.currentPageNumber.toString() && evt.value !== pdfViewer.currentPageLabel) {
  1751. PDFViewerApplication.toolbar.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
  1752. }
  1753. }
  1754. function webViewerScaleChanged(evt) {
  1755. PDFViewerApplication.pdfViewer.currentScaleValue = evt.value;
  1756. }
  1757. function webViewerRotateCw() {
  1758. PDFViewerApplication.rotatePages(90);
  1759. }
  1760. function webViewerRotateCcw() {
  1761. PDFViewerApplication.rotatePages(-90);
  1762. }
  1763. function webViewerSwitchScrollMode(evt) {
  1764. PDFViewerApplication.pdfViewer.scrollMode = evt.mode;
  1765. }
  1766. function webViewerSwitchSpreadMode(evt) {
  1767. PDFViewerApplication.pdfViewer.spreadMode = evt.mode;
  1768. }
  1769. function webViewerDocumentProperties() {
  1770. PDFViewerApplication.pdfDocumentProperties.open();
  1771. }
  1772. function webViewerFind(evt) {
  1773. PDFViewerApplication.findController.executeCommand("find" + evt.type, {
  1774. query: evt.query,
  1775. phraseSearch: evt.phraseSearch,
  1776. caseSensitive: evt.caseSensitive,
  1777. entireWord: evt.entireWord,
  1778. highlightAll: evt.highlightAll,
  1779. findPrevious: evt.findPrevious
  1780. });
  1781. }
  1782. function webViewerFindFromUrlHash(evt) {
  1783. PDFViewerApplication.findController.executeCommand("find", {
  1784. query: evt.query,
  1785. phraseSearch: evt.phraseSearch,
  1786. caseSensitive: false,
  1787. entireWord: false,
  1788. highlightAll: true,
  1789. findPrevious: false
  1790. });
  1791. }
  1792. function webViewerUpdateFindMatchesCount({
  1793. matchesCount
  1794. }) {
  1795. if (PDFViewerApplication.supportsIntegratedFind) {
  1796. PDFViewerApplication.externalServices.updateFindMatchesCount(matchesCount);
  1797. } else {
  1798. PDFViewerApplication.findBar.updateResultsCount(matchesCount);
  1799. }
  1800. }
  1801. function webViewerUpdateFindControlState({
  1802. state,
  1803. previous,
  1804. matchesCount
  1805. }) {
  1806. if (PDFViewerApplication.supportsIntegratedFind) {
  1807. PDFViewerApplication.externalServices.updateFindControlState({
  1808. result: state,
  1809. findPrevious: previous,
  1810. matchesCount
  1811. });
  1812. } else {
  1813. PDFViewerApplication.findBar.updateUIState(state, previous, matchesCount);
  1814. }
  1815. }
  1816. function webViewerScaleChanging(evt) {
  1817. PDFViewerApplication.toolbar.setPageScale(evt.presetValue, evt.scale);
  1818. PDFViewerApplication.pdfViewer.update();
  1819. }
  1820. function webViewerRotationChanging(evt) {
  1821. PDFViewerApplication.pdfThumbnailViewer.pagesRotation = evt.pagesRotation;
  1822. PDFViewerApplication.forceRendering();
  1823. PDFViewerApplication.pdfViewer.currentPageNumber = evt.pageNumber;
  1824. }
  1825. function webViewerPageChanging(evt) {
  1826. const page = evt.pageNumber;
  1827. PDFViewerApplication.toolbar.setPageNumber(page, evt.pageLabel || null);
  1828. PDFViewerApplication.secondaryToolbar.setPageNumber(page);
  1829. if (PDFViewerApplication.pdfSidebar.isThumbnailViewVisible) {
  1830. PDFViewerApplication.pdfThumbnailViewer.scrollThumbnailIntoView(page);
  1831. }
  1832. if (typeof Stats !== "undefined" && Stats.enabled) {
  1833. const pageView = PDFViewerApplication.pdfViewer.getPageView(page - 1);
  1834. if (pageView && pageView.stats) {
  1835. Stats.add(page, pageView.stats);
  1836. }
  1837. }
  1838. }
  1839. function webViewerVisibilityChange(evt) {
  1840. if (document.visibilityState === "visible") {
  1841. setZoomDisabledTimeout();
  1842. }
  1843. }
  1844. let zoomDisabledTimeout = null;
  1845. function setZoomDisabledTimeout() {
  1846. if (zoomDisabledTimeout) {
  1847. clearTimeout(zoomDisabledTimeout);
  1848. }
  1849. zoomDisabledTimeout = setTimeout(function () {
  1850. zoomDisabledTimeout = null;
  1851. }, WHEEL_ZOOM_DISABLED_TIMEOUT);
  1852. }
  1853. function webViewerWheel(evt) {
  1854. const {
  1855. pdfViewer,
  1856. supportedMouseWheelZoomModifierKeys
  1857. } = PDFViewerApplication;
  1858. if (pdfViewer.isInPresentationMode) {
  1859. return;
  1860. }
  1861. if (evt.ctrlKey && supportedMouseWheelZoomModifierKeys.ctrlKey || evt.metaKey && supportedMouseWheelZoomModifierKeys.metaKey) {
  1862. evt.preventDefault();
  1863. if (zoomDisabledTimeout || document.visibilityState === "hidden") {
  1864. return;
  1865. }
  1866. const previousScale = pdfViewer.currentScale;
  1867. const delta = (0, _ui_utils.normalizeWheelEventDelta)(evt);
  1868. const MOUSE_WHEEL_DELTA_PER_PAGE_SCALE = 3.0;
  1869. const ticks = delta * MOUSE_WHEEL_DELTA_PER_PAGE_SCALE;
  1870. if (ticks < 0) {
  1871. PDFViewerApplication.zoomOut(-ticks);
  1872. } else {
  1873. PDFViewerApplication.zoomIn(ticks);
  1874. }
  1875. const currentScale = pdfViewer.currentScale;
  1876. if (previousScale !== currentScale) {
  1877. const scaleCorrectionFactor = currentScale / previousScale - 1;
  1878. const rect = pdfViewer.container.getBoundingClientRect();
  1879. const dx = evt.clientX - rect.left;
  1880. const dy = evt.clientY - rect.top;
  1881. pdfViewer.container.scrollLeft += dx * scaleCorrectionFactor;
  1882. pdfViewer.container.scrollTop += dy * scaleCorrectionFactor;
  1883. }
  1884. } else {
  1885. setZoomDisabledTimeout();
  1886. }
  1887. }
  1888. function webViewerClick(evt) {
  1889. if (!PDFViewerApplication.secondaryToolbar.isOpen) {
  1890. return;
  1891. }
  1892. const appConfig = PDFViewerApplication.appConfig;
  1893. if (PDFViewerApplication.pdfViewer.containsElement(evt.target) || appConfig.toolbar.container.contains(evt.target) && evt.target !== appConfig.secondaryToolbar.toggleButton) {
  1894. PDFViewerApplication.secondaryToolbar.close();
  1895. }
  1896. }
  1897. function webViewerKeyDown(evt) {
  1898. if (PDFViewerApplication.overlayManager.active) {
  1899. return;
  1900. }
  1901. let handled = false,
  1902. ensureViewerFocused = false;
  1903. const cmd = (evt.ctrlKey ? 1 : 0) | (evt.altKey ? 2 : 0) | (evt.shiftKey ? 4 : 0) | (evt.metaKey ? 8 : 0);
  1904. const pdfViewer = PDFViewerApplication.pdfViewer;
  1905. const isViewerInPresentationMode = pdfViewer && pdfViewer.isInPresentationMode;
  1906. if (cmd === 1 || cmd === 8 || cmd === 5 || cmd === 12) {
  1907. switch (evt.keyCode) {
  1908. case 70:
  1909. if (!PDFViewerApplication.supportsIntegratedFind) {
  1910. PDFViewerApplication.findBar.open();
  1911. handled = true;
  1912. }
  1913. break;
  1914. case 71:
  1915. if (!PDFViewerApplication.supportsIntegratedFind) {
  1916. const findState = PDFViewerApplication.findController.state;
  1917. if (findState) {
  1918. PDFViewerApplication.findController.executeCommand("findagain", {
  1919. query: findState.query,
  1920. phraseSearch: findState.phraseSearch,
  1921. caseSensitive: findState.caseSensitive,
  1922. entireWord: findState.entireWord,
  1923. highlightAll: findState.highlightAll,
  1924. findPrevious: cmd === 5 || cmd === 12
  1925. });
  1926. }
  1927. handled = true;
  1928. }
  1929. break;
  1930. case 61:
  1931. case 107:
  1932. case 187:
  1933. case 171:
  1934. if (!isViewerInPresentationMode) {
  1935. PDFViewerApplication.zoomIn();
  1936. }
  1937. handled = true;
  1938. break;
  1939. case 173:
  1940. case 109:
  1941. case 189:
  1942. if (!isViewerInPresentationMode) {
  1943. PDFViewerApplication.zoomOut();
  1944. }
  1945. handled = true;
  1946. break;
  1947. case 48:
  1948. case 96:
  1949. if (!isViewerInPresentationMode) {
  1950. setTimeout(function () {
  1951. PDFViewerApplication.zoomReset();
  1952. });
  1953. handled = false;
  1954. }
  1955. break;
  1956. case 38:
  1957. if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
  1958. PDFViewerApplication.page = 1;
  1959. handled = true;
  1960. ensureViewerFocused = true;
  1961. }
  1962. break;
  1963. case 40:
  1964. if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  1965. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  1966. handled = true;
  1967. ensureViewerFocused = true;
  1968. }
  1969. break;
  1970. }
  1971. }
  1972. if (cmd === 1 || cmd === 8) {
  1973. switch (evt.keyCode) {
  1974. case 83:
  1975. PDFViewerApplication.download();
  1976. handled = true;
  1977. break;
  1978. }
  1979. }
  1980. if (cmd === 3 || cmd === 10) {
  1981. switch (evt.keyCode) {
  1982. case 80:
  1983. PDFViewerApplication.requestPresentationMode();
  1984. handled = true;
  1985. break;
  1986. case 71:
  1987. PDFViewerApplication.appConfig.toolbar.pageNumber.select();
  1988. handled = true;
  1989. break;
  1990. }
  1991. }
  1992. if (handled) {
  1993. if (ensureViewerFocused && !isViewerInPresentationMode) {
  1994. pdfViewer.focus();
  1995. }
  1996. evt.preventDefault();
  1997. return;
  1998. }
  1999. const curElement = document.activeElement || document.querySelector(":focus");
  2000. const curElementTagName = curElement && curElement.tagName.toUpperCase();
  2001. if (curElementTagName === "INPUT" || curElementTagName === "TEXTAREA" || curElementTagName === "SELECT" || curElement && curElement.isContentEditable) {
  2002. if (evt.keyCode !== 27) {
  2003. return;
  2004. }
  2005. }
  2006. if (cmd === 0) {
  2007. let turnPage = 0,
  2008. turnOnlyIfPageFit = false;
  2009. switch (evt.keyCode) {
  2010. case 38:
  2011. case 33:
  2012. if (pdfViewer.isVerticalScrollbarEnabled) {
  2013. turnOnlyIfPageFit = true;
  2014. }
  2015. turnPage = -1;
  2016. break;
  2017. case 8:
  2018. if (!isViewerInPresentationMode) {
  2019. turnOnlyIfPageFit = true;
  2020. }
  2021. turnPage = -1;
  2022. break;
  2023. case 37:
  2024. if (pdfViewer.isHorizontalScrollbarEnabled) {
  2025. turnOnlyIfPageFit = true;
  2026. }
  2027. case 75:
  2028. case 80:
  2029. turnPage = -1;
  2030. break;
  2031. case 27:
  2032. if (PDFViewerApplication.secondaryToolbar.isOpen) {
  2033. PDFViewerApplication.secondaryToolbar.close();
  2034. handled = true;
  2035. }
  2036. if (!PDFViewerApplication.supportsIntegratedFind && PDFViewerApplication.findBar.opened) {
  2037. PDFViewerApplication.findBar.close();
  2038. handled = true;
  2039. }
  2040. break;
  2041. case 40:
  2042. case 34:
  2043. if (pdfViewer.isVerticalScrollbarEnabled) {
  2044. turnOnlyIfPageFit = true;
  2045. }
  2046. turnPage = 1;
  2047. break;
  2048. case 13:
  2049. case 32:
  2050. if (!isViewerInPresentationMode) {
  2051. turnOnlyIfPageFit = true;
  2052. }
  2053. turnPage = 1;
  2054. break;
  2055. case 39:
  2056. if (pdfViewer.isHorizontalScrollbarEnabled) {
  2057. turnOnlyIfPageFit = true;
  2058. }
  2059. case 74:
  2060. case 78:
  2061. turnPage = 1;
  2062. break;
  2063. case 36:
  2064. if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
  2065. PDFViewerApplication.page = 1;
  2066. handled = true;
  2067. ensureViewerFocused = true;
  2068. }
  2069. break;
  2070. case 35:
  2071. if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  2072. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  2073. handled = true;
  2074. ensureViewerFocused = true;
  2075. }
  2076. break;
  2077. case 83:
  2078. PDFViewerApplication.pdfCursorTools.switchTool(_pdf_cursor_tools.CursorTool.SELECT);
  2079. break;
  2080. case 72:
  2081. PDFViewerApplication.pdfCursorTools.switchTool(_pdf_cursor_tools.CursorTool.HAND);
  2082. break;
  2083. case 82:
  2084. PDFViewerApplication.rotatePages(90);
  2085. break;
  2086. case 115:
  2087. PDFViewerApplication.pdfSidebar.toggle();
  2088. break;
  2089. }
  2090. if (turnPage !== 0 && (!turnOnlyIfPageFit || pdfViewer.currentScaleValue === "page-fit")) {
  2091. if (turnPage > 0) {
  2092. if (PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  2093. PDFViewerApplication.page++;
  2094. }
  2095. } else {
  2096. if (PDFViewerApplication.page > 1) {
  2097. PDFViewerApplication.page--;
  2098. }
  2099. }
  2100. handled = true;
  2101. }
  2102. }
  2103. if (cmd === 4) {
  2104. switch (evt.keyCode) {
  2105. case 13:
  2106. case 32:
  2107. if (!isViewerInPresentationMode && pdfViewer.currentScaleValue !== "page-fit") {
  2108. break;
  2109. }
  2110. if (PDFViewerApplication.page > 1) {
  2111. PDFViewerApplication.page--;
  2112. }
  2113. handled = true;
  2114. break;
  2115. case 82:
  2116. PDFViewerApplication.rotatePages(-90);
  2117. break;
  2118. }
  2119. }
  2120. if (!handled && !isViewerInPresentationMode) {
  2121. if (evt.keyCode >= 33 && evt.keyCode <= 40 || evt.keyCode === 32 && curElementTagName !== "BUTTON") {
  2122. ensureViewerFocused = true;
  2123. }
  2124. }
  2125. if (ensureViewerFocused && !pdfViewer.containsElement(curElement)) {
  2126. pdfViewer.focus();
  2127. }
  2128. if (handled) {
  2129. evt.preventDefault();
  2130. }
  2131. }
  2132. function apiPageLayoutToSpreadMode(layout) {
  2133. switch (layout) {
  2134. case "SinglePage":
  2135. case "OneColumn":
  2136. return _ui_utils.SpreadMode.NONE;
  2137. case "TwoColumnLeft":
  2138. case "TwoPageLeft":
  2139. return _ui_utils.SpreadMode.ODD;
  2140. case "TwoColumnRight":
  2141. case "TwoPageRight":
  2142. return _ui_utils.SpreadMode.EVEN;
  2143. }
  2144. return _ui_utils.SpreadMode.NONE;
  2145. }
  2146. function apiPageModeToSidebarView(mode) {
  2147. switch (mode) {
  2148. case "UseNone":
  2149. return _pdf_sidebar.SidebarView.NONE;
  2150. case "UseThumbs":
  2151. return _pdf_sidebar.SidebarView.THUMBS;
  2152. case "UseOutlines":
  2153. return _pdf_sidebar.SidebarView.OUTLINE;
  2154. case "UseAttachments":
  2155. return _pdf_sidebar.SidebarView.ATTACHMENTS;
  2156. case "UseOC":
  2157. }
  2158. return _pdf_sidebar.SidebarView.NONE;
  2159. }
  2160. const PDFPrintServiceFactory = {
  2161. instance: {
  2162. supportsPrinting: false,
  2163. createPrintService() {
  2164. throw new Error("Not implemented: createPrintService");
  2165. }
  2166. }
  2167. };
  2168. exports.PDFPrintServiceFactory = PDFPrintServiceFactory;
  2169. /***/ }),
  2170. /* 2 */
  2171. /***/ (function(module, exports, __webpack_require__) {
  2172. "use strict";
  2173. Object.defineProperty(exports, "__esModule", {
  2174. value: true
  2175. });
  2176. exports.isValidRotation = isValidRotation;
  2177. exports.isValidScrollMode = isValidScrollMode;
  2178. exports.isValidSpreadMode = isValidSpreadMode;
  2179. exports.isPortraitOrientation = isPortraitOrientation;
  2180. exports.getGlobalEventBus = getGlobalEventBus;
  2181. exports.clamp = clamp;
  2182. exports.getPDFFileNameFromURL = getPDFFileNameFromURL;
  2183. exports.noContextMenuHandler = noContextMenuHandler;
  2184. exports.parseQueryString = parseQueryString;
  2185. exports.backtrackBeforeAllVisibleElements = backtrackBeforeAllVisibleElements;
  2186. exports.getVisibleElements = getVisibleElements;
  2187. exports.roundToDivide = roundToDivide;
  2188. exports.getPageSizeInches = getPageSizeInches;
  2189. exports.approximateFraction = approximateFraction;
  2190. exports.getOutputScale = getOutputScale;
  2191. exports.scrollIntoView = scrollIntoView;
  2192. exports.watchScroll = watchScroll;
  2193. exports.binarySearchFirstItem = binarySearchFirstItem;
  2194. exports.normalizeWheelEventDelta = normalizeWheelEventDelta;
  2195. exports.waitOnEventOrTimeout = waitOnEventOrTimeout;
  2196. exports.moveToEndOfArray = moveToEndOfArray;
  2197. exports.WaitOnType = exports.animationStarted = exports.ProgressBar = exports.EventBus = exports.NullL10n = exports.SpreadMode = exports.ScrollMode = exports.TextLayerMode = exports.RendererType = exports.PresentationModeState = exports.VERTICAL_PADDING = exports.SCROLLBAR_PADDING = exports.MAX_AUTO_SCALE = exports.UNKNOWN_SCALE = exports.MAX_SCALE = exports.MIN_SCALE = exports.DEFAULT_SCALE = exports.DEFAULT_SCALE_VALUE = exports.CSS_UNITS = exports.AutoPrintRegExp = void 0;
  2198. const CSS_UNITS = 96.0 / 72.0;
  2199. exports.CSS_UNITS = CSS_UNITS;
  2200. const DEFAULT_SCALE_VALUE = "auto";
  2201. exports.DEFAULT_SCALE_VALUE = DEFAULT_SCALE_VALUE;
  2202. const DEFAULT_SCALE = 1.0;
  2203. exports.DEFAULT_SCALE = DEFAULT_SCALE;
  2204. const MIN_SCALE = 0.1;
  2205. exports.MIN_SCALE = MIN_SCALE;
  2206. const MAX_SCALE = 10.0;
  2207. exports.MAX_SCALE = MAX_SCALE;
  2208. const UNKNOWN_SCALE = 0;
  2209. exports.UNKNOWN_SCALE = UNKNOWN_SCALE;
  2210. const MAX_AUTO_SCALE = 1.25;
  2211. exports.MAX_AUTO_SCALE = MAX_AUTO_SCALE;
  2212. const SCROLLBAR_PADDING = 40;
  2213. exports.SCROLLBAR_PADDING = SCROLLBAR_PADDING;
  2214. const VERTICAL_PADDING = 5;
  2215. exports.VERTICAL_PADDING = VERTICAL_PADDING;
  2216. const PresentationModeState = {
  2217. UNKNOWN: 0,
  2218. NORMAL: 1,
  2219. CHANGING: 2,
  2220. FULLSCREEN: 3
  2221. };
  2222. exports.PresentationModeState = PresentationModeState;
  2223. const RendererType = {
  2224. CANVAS: "canvas",
  2225. SVG: "svg"
  2226. };
  2227. exports.RendererType = RendererType;
  2228. const TextLayerMode = {
  2229. DISABLE: 0,
  2230. ENABLE: 1,
  2231. ENABLE_ENHANCE: 2
  2232. };
  2233. exports.TextLayerMode = TextLayerMode;
  2234. const ScrollMode = {
  2235. UNKNOWN: -1,
  2236. VERTICAL: 0,
  2237. HORIZONTAL: 1,
  2238. WRAPPED: 2
  2239. };
  2240. exports.ScrollMode = ScrollMode;
  2241. const SpreadMode = {
  2242. UNKNOWN: -1,
  2243. NONE: 0,
  2244. ODD: 1,
  2245. EVEN: 2
  2246. };
  2247. exports.SpreadMode = SpreadMode;
  2248. const AutoPrintRegExp = /\bprint\s*\(/;
  2249. exports.AutoPrintRegExp = AutoPrintRegExp;
  2250. function formatL10nValue(text, args) {
  2251. if (!args) {
  2252. return text;
  2253. }
  2254. return text.replace(/\{\{\s*(\w+)\s*\}\}/g, (all, name) => {
  2255. return name in args ? args[name] : "{{" + name + "}}";
  2256. });
  2257. }
  2258. const NullL10n = {
  2259. async getLanguage() {
  2260. return "en-us";
  2261. },
  2262. async getDirection() {
  2263. return "ltr";
  2264. },
  2265. async get(property, args, fallback) {
  2266. return formatL10nValue(fallback, args);
  2267. },
  2268. async translate(element) {}
  2269. };
  2270. exports.NullL10n = NullL10n;
  2271. function getOutputScale(ctx) {
  2272. const devicePixelRatio = window.devicePixelRatio || 1;
  2273. const backingStoreRatio = ctx.webkitBackingStorePixelRatio || ctx.mozBackingStorePixelRatio || ctx.msBackingStorePixelRatio || ctx.oBackingStorePixelRatio || ctx.backingStorePixelRatio || 1;
  2274. const pixelRatio = devicePixelRatio / backingStoreRatio;
  2275. return {
  2276. sx: pixelRatio,
  2277. sy: pixelRatio,
  2278. scaled: pixelRatio !== 1
  2279. };
  2280. }
  2281. function scrollIntoView(element, spot, skipOverflowHiddenElements = false) {
  2282. let parent = element.offsetParent;
  2283. if (!parent) {
  2284. console.error("offsetParent is not set -- cannot scroll");
  2285. return;
  2286. }
  2287. let offsetY = element.offsetTop + element.clientTop;
  2288. let offsetX = element.offsetLeft + element.clientLeft;
  2289. while (parent.clientHeight === parent.scrollHeight && parent.clientWidth === parent.scrollWidth || skipOverflowHiddenElements && getComputedStyle(parent).overflow === "hidden") {
  2290. if (parent.dataset._scaleY) {
  2291. offsetY /= parent.dataset._scaleY;
  2292. offsetX /= parent.dataset._scaleX;
  2293. }
  2294. offsetY += parent.offsetTop;
  2295. offsetX += parent.offsetLeft;
  2296. parent = parent.offsetParent;
  2297. if (!parent) {
  2298. return;
  2299. }
  2300. }
  2301. if (spot) {
  2302. if (spot.top !== undefined) {
  2303. offsetY += spot.top;
  2304. }
  2305. if (spot.left !== undefined) {
  2306. offsetX += spot.left;
  2307. parent.scrollLeft = offsetX;
  2308. }
  2309. }
  2310. parent.scrollTop = offsetY;
  2311. }
  2312. function watchScroll(viewAreaElement, callback) {
  2313. const debounceScroll = function (evt) {
  2314. if (rAF) {
  2315. return;
  2316. }
  2317. rAF = window.requestAnimationFrame(function viewAreaElementScrolled() {
  2318. rAF = null;
  2319. const currentX = viewAreaElement.scrollLeft;
  2320. const lastX = state.lastX;
  2321. if (currentX !== lastX) {
  2322. state.right = currentX > lastX;
  2323. }
  2324. state.lastX = currentX;
  2325. const currentY = viewAreaElement.scrollTop;
  2326. const lastY = state.lastY;
  2327. if (currentY !== lastY) {
  2328. state.down = currentY > lastY;
  2329. }
  2330. state.lastY = currentY;
  2331. callback(state);
  2332. });
  2333. };
  2334. const state = {
  2335. right: true,
  2336. down: true,
  2337. lastX: viewAreaElement.scrollLeft,
  2338. lastY: viewAreaElement.scrollTop,
  2339. _eventHandler: debounceScroll
  2340. };
  2341. let rAF = null;
  2342. viewAreaElement.addEventListener("scroll", debounceScroll, true);
  2343. return state;
  2344. }
  2345. function parseQueryString(query) {
  2346. const parts = query.split("&");
  2347. const params = Object.create(null);
  2348. for (let i = 0, ii = parts.length; i < ii; ++i) {
  2349. const param = parts[i].split("=");
  2350. const key = param[0].toLowerCase();
  2351. const value = param.length > 1 ? param[1] : null;
  2352. params[decodeURIComponent(key)] = decodeURIComponent(value);
  2353. }
  2354. return params;
  2355. }
  2356. function binarySearchFirstItem(items, condition) {
  2357. let minIndex = 0;
  2358. let maxIndex = items.length - 1;
  2359. if (items.length === 0 || !condition(items[maxIndex])) {
  2360. return items.length;
  2361. }
  2362. if (condition(items[minIndex])) {
  2363. return minIndex;
  2364. }
  2365. while (minIndex < maxIndex) {
  2366. const currentIndex = minIndex + maxIndex >> 1;
  2367. const currentItem = items[currentIndex];
  2368. if (condition(currentItem)) {
  2369. maxIndex = currentIndex;
  2370. } else {
  2371. minIndex = currentIndex + 1;
  2372. }
  2373. }
  2374. return minIndex;
  2375. }
  2376. function approximateFraction(x) {
  2377. if (Math.floor(x) === x) {
  2378. return [x, 1];
  2379. }
  2380. const xinv = 1 / x;
  2381. const limit = 8;
  2382. if (xinv > limit) {
  2383. return [1, limit];
  2384. } else if (Math.floor(xinv) === xinv) {
  2385. return [1, xinv];
  2386. }
  2387. const x_ = x > 1 ? xinv : x;
  2388. let a = 0,
  2389. b = 1,
  2390. c = 1,
  2391. d = 1;
  2392. while (true) {
  2393. const p = a + c,
  2394. q = b + d;
  2395. if (q > limit) {
  2396. break;
  2397. }
  2398. if (x_ <= p / q) {
  2399. c = p;
  2400. d = q;
  2401. } else {
  2402. a = p;
  2403. b = q;
  2404. }
  2405. }
  2406. let result;
  2407. if (x_ - a / b < c / d - x_) {
  2408. result = x_ === x ? [a, b] : [b, a];
  2409. } else {
  2410. result = x_ === x ? [c, d] : [d, c];
  2411. }
  2412. return result;
  2413. }
  2414. function roundToDivide(x, div) {
  2415. const r = x % div;
  2416. return r === 0 ? x : Math.round(x - r + div);
  2417. }
  2418. function getPageSizeInches({
  2419. view,
  2420. userUnit,
  2421. rotate
  2422. }) {
  2423. const [x1, y1, x2, y2] = view;
  2424. const changeOrientation = rotate % 180 !== 0;
  2425. const width = (x2 - x1) / 72 * userUnit;
  2426. const height = (y2 - y1) / 72 * userUnit;
  2427. return {
  2428. width: changeOrientation ? height : width,
  2429. height: changeOrientation ? width : height
  2430. };
  2431. }
  2432. function backtrackBeforeAllVisibleElements(index, views, top) {
  2433. if (index < 2) {
  2434. return index;
  2435. }
  2436. let elt = views[index].div;
  2437. let pageTop = elt.offsetTop + elt.clientTop;
  2438. if (pageTop >= top) {
  2439. elt = views[index - 1].div;
  2440. pageTop = elt.offsetTop + elt.clientTop;
  2441. }
  2442. for (let i = index - 2; i >= 0; --i) {
  2443. elt = views[i].div;
  2444. if (elt.offsetTop + elt.clientTop + elt.clientHeight <= pageTop) {
  2445. break;
  2446. }
  2447. index = i;
  2448. }
  2449. return index;
  2450. }
  2451. function getVisibleElements(scrollEl, views, sortByVisibility = false, horizontal = false) {
  2452. const top = scrollEl.scrollTop,
  2453. bottom = top + scrollEl.clientHeight;
  2454. const left = scrollEl.scrollLeft,
  2455. right = left + scrollEl.clientWidth;
  2456. function isElementBottomAfterViewTop(view) {
  2457. const element = view.div;
  2458. const elementBottom = element.offsetTop + element.clientTop + element.clientHeight;
  2459. return elementBottom > top;
  2460. }
  2461. function isElementRightAfterViewLeft(view) {
  2462. const element = view.div;
  2463. const elementRight = element.offsetLeft + element.clientLeft + element.clientWidth;
  2464. return elementRight > left;
  2465. }
  2466. const visible = [],
  2467. numViews = views.length;
  2468. let firstVisibleElementInd = numViews === 0 ? 0 : binarySearchFirstItem(views, horizontal ? isElementRightAfterViewLeft : isElementBottomAfterViewTop);
  2469. if (firstVisibleElementInd > 0 && firstVisibleElementInd < numViews && !horizontal) {
  2470. firstVisibleElementInd = backtrackBeforeAllVisibleElements(firstVisibleElementInd, views, top);
  2471. }
  2472. let lastEdge = horizontal ? right : -1;
  2473. for (let i = firstVisibleElementInd; i < numViews; i++) {
  2474. const view = views[i],
  2475. element = view.div;
  2476. const currentWidth = element.offsetLeft + element.clientLeft;
  2477. const currentHeight = element.offsetTop + element.clientTop;
  2478. const viewWidth = element.clientWidth,
  2479. viewHeight = element.clientHeight;
  2480. const viewRight = currentWidth + viewWidth;
  2481. const viewBottom = currentHeight + viewHeight;
  2482. if (lastEdge === -1) {
  2483. if (viewBottom >= bottom) {
  2484. lastEdge = viewBottom;
  2485. }
  2486. } else if ((horizontal ? currentWidth : currentHeight) > lastEdge) {
  2487. break;
  2488. }
  2489. if (viewBottom <= top || currentHeight >= bottom || viewRight <= left || currentWidth >= right) {
  2490. continue;
  2491. }
  2492. const hiddenHeight = Math.max(0, top - currentHeight) + Math.max(0, viewBottom - bottom);
  2493. const hiddenWidth = Math.max(0, left - currentWidth) + Math.max(0, viewRight - right);
  2494. const percent = (viewHeight - hiddenHeight) * (viewWidth - hiddenWidth) * 100 / viewHeight / viewWidth | 0;
  2495. visible.push({
  2496. id: view.id,
  2497. x: currentWidth,
  2498. y: currentHeight,
  2499. view,
  2500. percent
  2501. });
  2502. }
  2503. const first = visible[0],
  2504. last = visible[visible.length - 1];
  2505. if (sortByVisibility) {
  2506. visible.sort(function (a, b) {
  2507. const pc = a.percent - b.percent;
  2508. if (Math.abs(pc) > 0.001) {
  2509. return -pc;
  2510. }
  2511. return a.id - b.id;
  2512. });
  2513. }
  2514. return {
  2515. first,
  2516. last,
  2517. views: visible
  2518. };
  2519. }
  2520. function noContextMenuHandler(evt) {
  2521. evt.preventDefault();
  2522. }
  2523. function isDataSchema(url) {
  2524. let i = 0;
  2525. const ii = url.length;
  2526. while (i < ii && url[i].trim() === "") {
  2527. i++;
  2528. }
  2529. return url.substring(i, i + 5).toLowerCase() === "data:";
  2530. }
  2531. function getPDFFileNameFromURL(url, defaultFilename = "document.pdf") {
  2532. if (typeof url !== "string") {
  2533. return defaultFilename;
  2534. }
  2535. if (isDataSchema(url)) {
  2536. console.warn("getPDFFileNameFromURL: " + 'ignoring "data:" URL for performance reasons.');
  2537. return defaultFilename;
  2538. }
  2539. const reURI = /^(?:(?:[^:]+:)?\/\/[^\/]+)?([^?#]*)(\?[^#]*)?(#.*)?$/;
  2540. const reFilename = /[^\/?#=]+\.pdf\b(?!.*\.pdf\b)/i;
  2541. const splitURI = reURI.exec(url);
  2542. let suggestedFilename = reFilename.exec(splitURI[1]) || reFilename.exec(splitURI[2]) || reFilename.exec(splitURI[3]);
  2543. if (suggestedFilename) {
  2544. suggestedFilename = suggestedFilename[0];
  2545. if (suggestedFilename.includes("%")) {
  2546. try {
  2547. suggestedFilename = reFilename.exec(decodeURIComponent(suggestedFilename))[0];
  2548. } catch (ex) {}
  2549. }
  2550. }
  2551. return suggestedFilename || defaultFilename;
  2552. }
  2553. function normalizeWheelEventDelta(evt) {
  2554. let delta = Math.sqrt(evt.deltaX * evt.deltaX + evt.deltaY * evt.deltaY);
  2555. const angle = Math.atan2(evt.deltaY, evt.deltaX);
  2556. if (-0.25 * Math.PI < angle && angle < 0.75 * Math.PI) {
  2557. delta = -delta;
  2558. }
  2559. const MOUSE_DOM_DELTA_PIXEL_MODE = 0;
  2560. const MOUSE_DOM_DELTA_LINE_MODE = 1;
  2561. const MOUSE_PIXELS_PER_LINE = 30;
  2562. const MOUSE_LINES_PER_PAGE = 30;
  2563. if (evt.deltaMode === MOUSE_DOM_DELTA_PIXEL_MODE) {
  2564. delta /= MOUSE_PIXELS_PER_LINE * MOUSE_LINES_PER_PAGE;
  2565. } else if (evt.deltaMode === MOUSE_DOM_DELTA_LINE_MODE) {
  2566. delta /= MOUSE_LINES_PER_PAGE;
  2567. }
  2568. return delta;
  2569. }
  2570. function isValidRotation(angle) {
  2571. return Number.isInteger(angle) && angle % 90 === 0;
  2572. }
  2573. function isValidScrollMode(mode) {
  2574. return Number.isInteger(mode) && Object.values(ScrollMode).includes(mode) && mode !== ScrollMode.UNKNOWN;
  2575. }
  2576. function isValidSpreadMode(mode) {
  2577. return Number.isInteger(mode) && Object.values(SpreadMode).includes(mode) && mode !== SpreadMode.UNKNOWN;
  2578. }
  2579. function isPortraitOrientation(size) {
  2580. return size.width <= size.height;
  2581. }
  2582. const WaitOnType = {
  2583. EVENT: "event",
  2584. TIMEOUT: "timeout"
  2585. };
  2586. exports.WaitOnType = WaitOnType;
  2587. function waitOnEventOrTimeout({
  2588. target,
  2589. name,
  2590. delay = 0
  2591. }) {
  2592. return new Promise(function (resolve, reject) {
  2593. if (typeof target !== "object" || !(name && typeof name === "string") || !(Number.isInteger(delay) && delay >= 0)) {
  2594. throw new Error("waitOnEventOrTimeout - invalid parameters.");
  2595. }
  2596. function handler(type) {
  2597. if (target instanceof EventBus) {
  2598. target._off(name, eventHandler);
  2599. } else {
  2600. target.removeEventListener(name, eventHandler);
  2601. }
  2602. if (timeout) {
  2603. clearTimeout(timeout);
  2604. }
  2605. resolve(type);
  2606. }
  2607. const eventHandler = handler.bind(null, WaitOnType.EVENT);
  2608. if (target instanceof EventBus) {
  2609. target._on(name, eventHandler);
  2610. } else {
  2611. target.addEventListener(name, eventHandler);
  2612. }
  2613. const timeoutHandler = handler.bind(null, WaitOnType.TIMEOUT);
  2614. const timeout = setTimeout(timeoutHandler, delay);
  2615. });
  2616. }
  2617. const animationStarted = new Promise(function (resolve) {
  2618. window.requestAnimationFrame(resolve);
  2619. });
  2620. exports.animationStarted = animationStarted;
  2621. function dispatchDOMEvent(eventName, args = null) {
  2622. const details = Object.create(null);
  2623. if (args && args.length > 0) {
  2624. const obj = args[0];
  2625. for (const key in obj) {
  2626. const value = obj[key];
  2627. if (key === "source") {
  2628. if (value === window || value === document) {
  2629. return;
  2630. }
  2631. continue;
  2632. }
  2633. details[key] = value;
  2634. }
  2635. }
  2636. const event = document.createEvent("CustomEvent");
  2637. event.initCustomEvent(eventName, true, true, details);
  2638. document.dispatchEvent(event);
  2639. }
  2640. class EventBus {
  2641. constructor({
  2642. dispatchToDOM = false
  2643. } = {}) {
  2644. this._listeners = Object.create(null);
  2645. this._dispatchToDOM = dispatchToDOM === true;
  2646. if (dispatchToDOM) {
  2647. console.error("The `eventBusDispatchToDOM` option/preference is deprecated, " + "add event listeners to the EventBus instance rather than the DOM.");
  2648. }
  2649. }
  2650. on(eventName, listener) {
  2651. this._on(eventName, listener, {
  2652. external: true
  2653. });
  2654. }
  2655. off(eventName, listener) {
  2656. this._off(eventName, listener, {
  2657. external: true
  2658. });
  2659. }
  2660. dispatch(eventName) {
  2661. const eventListeners = this._listeners[eventName];
  2662. if (!eventListeners || eventListeners.length === 0) {
  2663. if (this._dispatchToDOM) {
  2664. const args = Array.prototype.slice.call(arguments, 1);
  2665. dispatchDOMEvent(eventName, args);
  2666. }
  2667. return;
  2668. }
  2669. const args = Array.prototype.slice.call(arguments, 1);
  2670. let externalListeners;
  2671. eventListeners.slice(0).forEach(function ({
  2672. listener,
  2673. external
  2674. }) {
  2675. if (external) {
  2676. if (!externalListeners) {
  2677. externalListeners = [];
  2678. }
  2679. externalListeners.push(listener);
  2680. return;
  2681. }
  2682. listener.apply(null, args);
  2683. });
  2684. if (externalListeners) {
  2685. externalListeners.forEach(function (listener) {
  2686. listener.apply(null, args);
  2687. });
  2688. externalListeners = null;
  2689. }
  2690. if (this._dispatchToDOM) {
  2691. dispatchDOMEvent(eventName, args);
  2692. }
  2693. }
  2694. _on(eventName, listener, options = null) {
  2695. let eventListeners = this._listeners[eventName];
  2696. if (!eventListeners) {
  2697. this._listeners[eventName] = eventListeners = [];
  2698. }
  2699. eventListeners.push({
  2700. listener,
  2701. external: (options && options.external) === true
  2702. });
  2703. }
  2704. _off(eventName, listener, options = null) {
  2705. const eventListeners = this._listeners[eventName];
  2706. if (!eventListeners) {
  2707. return;
  2708. }
  2709. for (let i = 0, ii = eventListeners.length; i < ii; i++) {
  2710. if (eventListeners[i].listener === listener) {
  2711. eventListeners.splice(i, 1);
  2712. return;
  2713. }
  2714. }
  2715. }
  2716. }
  2717. exports.EventBus = EventBus;
  2718. let globalEventBus = null;
  2719. function getGlobalEventBus(dispatchToDOM = false) {
  2720. console.error("getGlobalEventBus is deprecated, use a manually created EventBus instance instead.");
  2721. if (!globalEventBus) {
  2722. globalEventBus = new EventBus({
  2723. dispatchToDOM
  2724. });
  2725. }
  2726. return globalEventBus;
  2727. }
  2728. function clamp(v, min, max) {
  2729. return Math.min(Math.max(v, min), max);
  2730. }
  2731. class ProgressBar {
  2732. constructor(id, {
  2733. height,
  2734. width,
  2735. units
  2736. } = {}) {
  2737. this.visible = true;
  2738. this.div = document.querySelector(id + " .progress");
  2739. this.bar = this.div.parentNode;
  2740. this.height = height || 100;
  2741. this.width = width || 100;
  2742. this.units = units || "%";
  2743. this.div.style.height = this.height + this.units;
  2744. this.percent = 0;
  2745. }
  2746. _updateBar() {
  2747. if (this._indeterminate) {
  2748. this.div.classList.add("indeterminate");
  2749. this.div.style.width = this.width + this.units;
  2750. return;
  2751. }
  2752. this.div.classList.remove("indeterminate");
  2753. const progressSize = this.width * this._percent / 100;
  2754. this.div.style.width = progressSize + this.units;
  2755. }
  2756. get percent() {
  2757. return this._percent;
  2758. }
  2759. set percent(val) {
  2760. this._indeterminate = isNaN(val);
  2761. this._percent = clamp(val, 0, 100);
  2762. this._updateBar();
  2763. }
  2764. setWidth(viewer) {
  2765. if (!viewer) {
  2766. return;
  2767. }
  2768. const container = viewer.parentNode;
  2769. const scrollbarWidth = container.offsetWidth - viewer.offsetWidth;
  2770. if (scrollbarWidth > 0) {
  2771. this.bar.style.width = `calc(100% - ${scrollbarWidth}px)`;
  2772. }
  2773. }
  2774. hide() {
  2775. if (!this.visible) {
  2776. return;
  2777. }
  2778. this.visible = false;
  2779. this.bar.classList.add("hidden");
  2780. document.body.classList.remove("loadingInProgress");
  2781. }
  2782. show() {
  2783. if (this.visible) {
  2784. return;
  2785. }
  2786. this.visible = true;
  2787. document.body.classList.add("loadingInProgress");
  2788. this.bar.classList.remove("hidden");
  2789. }
  2790. }
  2791. exports.ProgressBar = ProgressBar;
  2792. function moveToEndOfArray(arr, condition) {
  2793. const moved = [],
  2794. len = arr.length;
  2795. let write = 0;
  2796. for (let read = 0; read < len; ++read) {
  2797. if (condition(arr[read])) {
  2798. moved.push(arr[read]);
  2799. } else {
  2800. arr[write] = arr[read];
  2801. ++write;
  2802. }
  2803. }
  2804. for (let read = 0; write < len; ++read, ++write) {
  2805. arr[write] = moved[read];
  2806. }
  2807. }
  2808. /***/ }),
  2809. /* 3 */
  2810. /***/ (function(module, exports, __webpack_require__) {
  2811. "use strict";
  2812. Object.defineProperty(exports, "__esModule", {
  2813. value: true
  2814. });
  2815. exports.OptionKind = exports.AppOptions = void 0;
  2816. var _pdfjsLib = __webpack_require__(4);
  2817. var _viewer_compatibility = __webpack_require__(5);
  2818. const OptionKind = {
  2819. VIEWER: 0x02,
  2820. API: 0x04,
  2821. WORKER: 0x08,
  2822. PREFERENCE: 0x80
  2823. };
  2824. exports.OptionKind = OptionKind;
  2825. const defaultOptions = {
  2826. cursorToolOnLoad: {
  2827. value: 0,
  2828. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  2829. },
  2830. defaultUrl: {
  2831. value: "compressed.tracemonkey-pldi-09.pdf",
  2832. kind: OptionKind.VIEWER
  2833. },
  2834. defaultZoomValue: {
  2835. value: "",
  2836. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  2837. },
  2838. disableHistory: {
  2839. value: false,
  2840. kind: OptionKind.VIEWER
  2841. },
  2842. disablePageLabels: {
  2843. value: false,
  2844. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  2845. },
  2846. enablePrintAutoRotate: {
  2847. value: false,
  2848. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  2849. },
  2850. enableWebGL: {
  2851. value: false,
  2852. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  2853. },
  2854. eventBusDispatchToDOM: {
  2855. value: false,
  2856. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  2857. },
  2858. externalLinkRel: {
  2859. value: "noopener noreferrer nofollow",
  2860. kind: OptionKind.VIEWER
  2861. },
  2862. externalLinkTarget: {
  2863. value: 0,
  2864. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  2865. },
  2866. historyUpdateUrl: {
  2867. value: false,
  2868. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  2869. },
  2870. ignoreDestinationZoom: {
  2871. value: false,
  2872. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  2873. },
  2874. imageResourcesPath: {
  2875. value: "./images/",
  2876. kind: OptionKind.VIEWER
  2877. },
  2878. maxCanvasPixels: {
  2879. value: 16777216,
  2880. compatibility: _viewer_compatibility.viewerCompatibilityParams.maxCanvasPixels,
  2881. kind: OptionKind.VIEWER
  2882. },
  2883. pdfBugEnabled: {
  2884. value: false,
  2885. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  2886. },
  2887. renderer: {
  2888. value: "canvas",
  2889. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  2890. },
  2891. renderInteractiveForms: {
  2892. value: false,
  2893. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  2894. },
  2895. sidebarViewOnLoad: {
  2896. value: -1,
  2897. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  2898. },
  2899. scrollModeOnLoad: {
  2900. value: -1,
  2901. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  2902. },
  2903. spreadModeOnLoad: {
  2904. value: -1,
  2905. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  2906. },
  2907. textLayerMode: {
  2908. value: 1,
  2909. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  2910. },
  2911. useOnlyCssZoom: {
  2912. value: false,
  2913. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  2914. },
  2915. viewOnLoad: {
  2916. value: 0,
  2917. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  2918. },
  2919. cMapPacked: {
  2920. value: true,
  2921. kind: OptionKind.API
  2922. },
  2923. cMapUrl: {
  2924. value: "../web/cmaps/",
  2925. kind: OptionKind.API
  2926. },
  2927. disableAutoFetch: {
  2928. value: false,
  2929. kind: OptionKind.API + OptionKind.PREFERENCE
  2930. },
  2931. disableCreateObjectURL: {
  2932. value: false,
  2933. compatibility: _pdfjsLib.apiCompatibilityParams.disableCreateObjectURL,
  2934. kind: OptionKind.API
  2935. },
  2936. disableFontFace: {
  2937. value: false,
  2938. kind: OptionKind.API + OptionKind.PREFERENCE
  2939. },
  2940. disableRange: {
  2941. value: false,
  2942. kind: OptionKind.API + OptionKind.PREFERENCE
  2943. },
  2944. disableStream: {
  2945. value: false,
  2946. kind: OptionKind.API + OptionKind.PREFERENCE
  2947. },
  2948. docBaseUrl: {
  2949. value: "",
  2950. kind: OptionKind.API
  2951. },
  2952. isEvalSupported: {
  2953. value: true,
  2954. kind: OptionKind.API
  2955. },
  2956. maxImageSize: {
  2957. value: -1,
  2958. kind: OptionKind.API
  2959. },
  2960. pdfBug: {
  2961. value: false,
  2962. kind: OptionKind.API
  2963. },
  2964. verbosity: {
  2965. value: 1,
  2966. kind: OptionKind.API
  2967. },
  2968. workerPort: {
  2969. value: null,
  2970. kind: OptionKind.WORKER
  2971. },
  2972. workerSrc: {
  2973. value: "../build/pdf.worker.js",
  2974. kind: OptionKind.WORKER
  2975. }
  2976. };
  2977. {
  2978. defaultOptions.disablePreferences = {
  2979. value: false,
  2980. kind: OptionKind.VIEWER
  2981. };
  2982. defaultOptions.locale = {
  2983. value: typeof navigator !== "undefined" ? navigator.language : "en-US",
  2984. kind: OptionKind.VIEWER
  2985. };
  2986. defaultOptions.printResolution = {
  2987. value: 150,
  2988. kind: OptionKind.VIEWER
  2989. };
  2990. }
  2991. const userOptions = Object.create(null);
  2992. class AppOptions {
  2993. constructor() {
  2994. throw new Error("Cannot initialize AppOptions.");
  2995. }
  2996. static get(name) {
  2997. const userOption = userOptions[name];
  2998. if (userOption !== undefined) {
  2999. return userOption;
  3000. }
  3001. const defaultOption = defaultOptions[name];
  3002. if (defaultOption !== undefined) {
  3003. return defaultOption.compatibility || defaultOption.value;
  3004. }
  3005. return undefined;
  3006. }
  3007. static getAll(kind = null) {
  3008. const options = Object.create(null);
  3009. for (const name in defaultOptions) {
  3010. const defaultOption = defaultOptions[name];
  3011. if (kind) {
  3012. if ((kind & defaultOption.kind) === 0) {
  3013. continue;
  3014. }
  3015. if (kind === OptionKind.PREFERENCE) {
  3016. const value = defaultOption.value,
  3017. valueType = typeof value;
  3018. if (valueType === "boolean" || valueType === "string" || valueType === "number" && Number.isInteger(value)) {
  3019. options[name] = value;
  3020. continue;
  3021. }
  3022. throw new Error(`Invalid type for preference: ${name}`);
  3023. }
  3024. }
  3025. const userOption = userOptions[name];
  3026. options[name] = userOption !== undefined ? userOption : defaultOption.compatibility || defaultOption.value;
  3027. }
  3028. return options;
  3029. }
  3030. static set(name, value) {
  3031. userOptions[name] = value;
  3032. }
  3033. static remove(name) {
  3034. delete userOptions[name];
  3035. }
  3036. }
  3037. exports.AppOptions = AppOptions;
  3038. /***/ }),
  3039. /* 4 */
  3040. /***/ (function(module, exports, __webpack_require__) {
  3041. "use strict";
  3042. let pdfjsLib;
  3043. if (typeof window !== "undefined" && window["pdfjs-dist/build/pdf"]) {
  3044. pdfjsLib = window["pdfjs-dist/build/pdf"];
  3045. } else {
  3046. pdfjsLib = require("../build/pdf.js");
  3047. }
  3048. module.exports = pdfjsLib;
  3049. /***/ }),
  3050. /* 5 */
  3051. /***/ (function(module, exports, __webpack_require__) {
  3052. "use strict";
  3053. const compatibilityParams = Object.create(null);
  3054. {
  3055. const userAgent = typeof navigator !== "undefined" && navigator.userAgent || "";
  3056. const platform = typeof navigator !== "undefined" && navigator.platform || "";
  3057. const maxTouchPoints = typeof navigator !== "undefined" && navigator.maxTouchPoints || 1;
  3058. const isAndroid = /Android/.test(userAgent);
  3059. const isIOS = /\b(iPad|iPhone|iPod)(?=;)/.test(userAgent) || platform === "MacIntel" && maxTouchPoints > 1;
  3060. (function checkCanvasSizeLimitation() {
  3061. if (isIOS || isAndroid) {
  3062. compatibilityParams.maxCanvasPixels = 5242880;
  3063. }
  3064. })();
  3065. }
  3066. exports.viewerCompatibilityParams = Object.freeze(compatibilityParams);
  3067. /***/ }),
  3068. /* 6 */
  3069. /***/ (function(module, exports, __webpack_require__) {
  3070. "use strict";
  3071. Object.defineProperty(exports, "__esModule", {
  3072. value: true
  3073. });
  3074. exports.PDFCursorTools = exports.CursorTool = void 0;
  3075. var _grab_to_pan = __webpack_require__(7);
  3076. const CursorTool = {
  3077. SELECT: 0,
  3078. HAND: 1,
  3079. ZOOM: 2
  3080. };
  3081. exports.CursorTool = CursorTool;
  3082. class PDFCursorTools {
  3083. constructor({
  3084. container,
  3085. eventBus,
  3086. cursorToolOnLoad = CursorTool.SELECT
  3087. }) {
  3088. this.container = container;
  3089. this.eventBus = eventBus;
  3090. this.active = CursorTool.SELECT;
  3091. this.activeBeforePresentationMode = null;
  3092. this.handTool = new _grab_to_pan.GrabToPan({
  3093. element: this.container
  3094. });
  3095. this._addEventListeners();
  3096. Promise.resolve().then(() => {
  3097. this.switchTool(cursorToolOnLoad);
  3098. });
  3099. }
  3100. get activeTool() {
  3101. return this.active;
  3102. }
  3103. switchTool(tool) {
  3104. if (this.activeBeforePresentationMode !== null) {
  3105. return;
  3106. }
  3107. if (tool === this.active) {
  3108. return;
  3109. }
  3110. const disableActiveTool = () => {
  3111. switch (this.active) {
  3112. case CursorTool.SELECT:
  3113. break;
  3114. case CursorTool.HAND:
  3115. this.handTool.deactivate();
  3116. break;
  3117. case CursorTool.ZOOM:
  3118. }
  3119. };
  3120. switch (tool) {
  3121. case CursorTool.SELECT:
  3122. disableActiveTool();
  3123. break;
  3124. case CursorTool.HAND:
  3125. disableActiveTool();
  3126. this.handTool.activate();
  3127. break;
  3128. case CursorTool.ZOOM:
  3129. default:
  3130. console.error(`switchTool: "${tool}" is an unsupported value.`);
  3131. return;
  3132. }
  3133. this.active = tool;
  3134. this._dispatchEvent();
  3135. }
  3136. _dispatchEvent() {
  3137. this.eventBus.dispatch("cursortoolchanged", {
  3138. source: this,
  3139. tool: this.active
  3140. });
  3141. }
  3142. _addEventListeners() {
  3143. this.eventBus._on("switchcursortool", evt => {
  3144. this.switchTool(evt.tool);
  3145. });
  3146. this.eventBus._on("presentationmodechanged", evt => {
  3147. if (evt.switchInProgress) {
  3148. return;
  3149. }
  3150. let previouslyActive;
  3151. if (evt.active) {
  3152. previouslyActive = this.active;
  3153. this.switchTool(CursorTool.SELECT);
  3154. this.activeBeforePresentationMode = previouslyActive;
  3155. } else {
  3156. previouslyActive = this.activeBeforePresentationMode;
  3157. this.activeBeforePresentationMode = null;
  3158. this.switchTool(previouslyActive);
  3159. }
  3160. });
  3161. }
  3162. }
  3163. exports.PDFCursorTools = PDFCursorTools;
  3164. /***/ }),
  3165. /* 7 */
  3166. /***/ (function(module, exports, __webpack_require__) {
  3167. "use strict";
  3168. Object.defineProperty(exports, "__esModule", {
  3169. value: true
  3170. });
  3171. exports.GrabToPan = GrabToPan;
  3172. function GrabToPan(options) {
  3173. this.element = options.element;
  3174. this.document = options.element.ownerDocument;
  3175. if (typeof options.ignoreTarget === "function") {
  3176. this.ignoreTarget = options.ignoreTarget;
  3177. }
  3178. this.onActiveChanged = options.onActiveChanged;
  3179. this.activate = this.activate.bind(this);
  3180. this.deactivate = this.deactivate.bind(this);
  3181. this.toggle = this.toggle.bind(this);
  3182. this._onmousedown = this._onmousedown.bind(this);
  3183. this._onmousemove = this._onmousemove.bind(this);
  3184. this._endPan = this._endPan.bind(this);
  3185. const overlay = this.overlay = document.createElement("div");
  3186. overlay.className = "grab-to-pan-grabbing";
  3187. }
  3188. GrabToPan.prototype = {
  3189. CSS_CLASS_GRAB: "grab-to-pan-grab",
  3190. activate: function GrabToPan_activate() {
  3191. if (!this.active) {
  3192. this.active = true;
  3193. this.element.addEventListener("mousedown", this._onmousedown, true);
  3194. this.element.classList.add(this.CSS_CLASS_GRAB);
  3195. if (this.onActiveChanged) {
  3196. this.onActiveChanged(true);
  3197. }
  3198. }
  3199. },
  3200. deactivate: function GrabToPan_deactivate() {
  3201. if (this.active) {
  3202. this.active = false;
  3203. this.element.removeEventListener("mousedown", this._onmousedown, true);
  3204. this._endPan();
  3205. this.element.classList.remove(this.CSS_CLASS_GRAB);
  3206. if (this.onActiveChanged) {
  3207. this.onActiveChanged(false);
  3208. }
  3209. }
  3210. },
  3211. toggle: function GrabToPan_toggle() {
  3212. if (this.active) {
  3213. this.deactivate();
  3214. } else {
  3215. this.activate();
  3216. }
  3217. },
  3218. ignoreTarget: function GrabToPan_ignoreTarget(node) {
  3219. return node[matchesSelector]("a[href], a[href] *, input, textarea, button, button *, select, option");
  3220. },
  3221. _onmousedown: function GrabToPan__onmousedown(event) {
  3222. if (event.button !== 0 || this.ignoreTarget(event.target)) {
  3223. return;
  3224. }
  3225. if (event.originalTarget) {
  3226. try {
  3227. event.originalTarget.tagName;
  3228. } catch (e) {
  3229. return;
  3230. }
  3231. }
  3232. this.scrollLeftStart = this.element.scrollLeft;
  3233. this.scrollTopStart = this.element.scrollTop;
  3234. this.clientXStart = event.clientX;
  3235. this.clientYStart = event.clientY;
  3236. this.document.addEventListener("mousemove", this._onmousemove, true);
  3237. this.document.addEventListener("mouseup", this._endPan, true);
  3238. this.element.addEventListener("scroll", this._endPan, true);
  3239. event.preventDefault();
  3240. event.stopPropagation();
  3241. const focusedElement = document.activeElement;
  3242. if (focusedElement && !focusedElement.contains(event.target)) {
  3243. focusedElement.blur();
  3244. }
  3245. },
  3246. _onmousemove: function GrabToPan__onmousemove(event) {
  3247. this.element.removeEventListener("scroll", this._endPan, true);
  3248. if (isLeftMouseReleased(event)) {
  3249. this._endPan();
  3250. return;
  3251. }
  3252. const xDiff = event.clientX - this.clientXStart;
  3253. const yDiff = event.clientY - this.clientYStart;
  3254. const scrollTop = this.scrollTopStart - yDiff;
  3255. const scrollLeft = this.scrollLeftStart - xDiff;
  3256. if (this.element.scrollTo) {
  3257. this.element.scrollTo({
  3258. top: scrollTop,
  3259. left: scrollLeft,
  3260. behavior: "instant"
  3261. });
  3262. } else {
  3263. this.element.scrollTop = scrollTop;
  3264. this.element.scrollLeft = scrollLeft;
  3265. }
  3266. if (!this.overlay.parentNode) {
  3267. document.body.appendChild(this.overlay);
  3268. }
  3269. },
  3270. _endPan: function GrabToPan__endPan() {
  3271. this.element.removeEventListener("scroll", this._endPan, true);
  3272. this.document.removeEventListener("mousemove", this._onmousemove, true);
  3273. this.document.removeEventListener("mouseup", this._endPan, true);
  3274. this.overlay.remove();
  3275. }
  3276. };
  3277. let matchesSelector;
  3278. ["webkitM", "mozM", "msM", "oM", "m"].some(function (prefix) {
  3279. let name = prefix + "atches";
  3280. if (name in document.documentElement) {
  3281. matchesSelector = name;
  3282. }
  3283. name += "Selector";
  3284. if (name in document.documentElement) {
  3285. matchesSelector = name;
  3286. }
  3287. return matchesSelector;
  3288. });
  3289. const isNotIEorIsIE10plus = !document.documentMode || document.documentMode > 9;
  3290. const chrome = window.chrome;
  3291. const isChrome15OrOpera15plus = chrome && (chrome.webstore || chrome.app);
  3292. const isSafari6plus = /Apple/.test(navigator.vendor) && /Version\/([6-9]\d*|[1-5]\d+)/.test(navigator.userAgent);
  3293. function isLeftMouseReleased(event) {
  3294. if ("buttons" in event && isNotIEorIsIE10plus) {
  3295. return !(event.buttons & 1);
  3296. }
  3297. if (isChrome15OrOpera15plus || isSafari6plus) {
  3298. return event.which === 0;
  3299. }
  3300. return false;
  3301. }
  3302. /***/ }),
  3303. /* 8 */
  3304. /***/ (function(module, exports, __webpack_require__) {
  3305. "use strict";
  3306. Object.defineProperty(exports, "__esModule", {
  3307. value: true
  3308. });
  3309. exports.PDFRenderingQueue = exports.RenderingStates = void 0;
  3310. const CLEANUP_TIMEOUT = 30000;
  3311. const RenderingStates = {
  3312. INITIAL: 0,
  3313. RUNNING: 1,
  3314. PAUSED: 2,
  3315. FINISHED: 3
  3316. };
  3317. exports.RenderingStates = RenderingStates;
  3318. class PDFRenderingQueue {
  3319. constructor() {
  3320. this.pdfViewer = null;
  3321. this.pdfThumbnailViewer = null;
  3322. this.onIdle = null;
  3323. this.highestPriorityPage = null;
  3324. this.idleTimeout = null;
  3325. this.printing = false;
  3326. this.isThumbnailViewEnabled = false;
  3327. }
  3328. setViewer(pdfViewer) {
  3329. this.pdfViewer = pdfViewer;
  3330. }
  3331. setThumbnailViewer(pdfThumbnailViewer) {
  3332. this.pdfThumbnailViewer = pdfThumbnailViewer;
  3333. }
  3334. isHighestPriority(view) {
  3335. return this.highestPriorityPage === view.renderingId;
  3336. }
  3337. renderHighestPriority(currentlyVisiblePages) {
  3338. if (this.idleTimeout) {
  3339. clearTimeout(this.idleTimeout);
  3340. this.idleTimeout = null;
  3341. }
  3342. if (this.pdfViewer.forceRendering(currentlyVisiblePages)) {
  3343. return;
  3344. }
  3345. if (this.pdfThumbnailViewer && this.isThumbnailViewEnabled) {
  3346. if (this.pdfThumbnailViewer.forceRendering()) {
  3347. return;
  3348. }
  3349. }
  3350. if (this.printing) {
  3351. return;
  3352. }
  3353. if (this.onIdle) {
  3354. this.idleTimeout = setTimeout(this.onIdle.bind(this), CLEANUP_TIMEOUT);
  3355. }
  3356. }
  3357. getHighestPriority(visible, views, scrolledDown) {
  3358. const visibleViews = visible.views;
  3359. const numVisible = visibleViews.length;
  3360. if (numVisible === 0) {
  3361. return null;
  3362. }
  3363. for (let i = 0; i < numVisible; ++i) {
  3364. const view = visibleViews[i].view;
  3365. if (!this.isViewFinished(view)) {
  3366. return view;
  3367. }
  3368. }
  3369. if (scrolledDown) {
  3370. const nextPageIndex = visible.last.id;
  3371. if (views[nextPageIndex] && !this.isViewFinished(views[nextPageIndex])) {
  3372. return views[nextPageIndex];
  3373. }
  3374. } else {
  3375. const previousPageIndex = visible.first.id - 2;
  3376. if (views[previousPageIndex] && !this.isViewFinished(views[previousPageIndex])) {
  3377. return views[previousPageIndex];
  3378. }
  3379. }
  3380. return null;
  3381. }
  3382. isViewFinished(view) {
  3383. return view.renderingState === RenderingStates.FINISHED;
  3384. }
  3385. renderView(view) {
  3386. switch (view.renderingState) {
  3387. case RenderingStates.FINISHED:
  3388. return false;
  3389. case RenderingStates.PAUSED:
  3390. this.highestPriorityPage = view.renderingId;
  3391. view.resume();
  3392. break;
  3393. case RenderingStates.RUNNING:
  3394. this.highestPriorityPage = view.renderingId;
  3395. break;
  3396. case RenderingStates.INITIAL:
  3397. this.highestPriorityPage = view.renderingId;
  3398. view.draw().finally(() => {
  3399. this.renderHighestPriority();
  3400. }).catch(reason => {
  3401. console.error(`renderView: "${reason}"`);
  3402. });
  3403. break;
  3404. }
  3405. return true;
  3406. }
  3407. }
  3408. exports.PDFRenderingQueue = PDFRenderingQueue;
  3409. /***/ }),
  3410. /* 9 */
  3411. /***/ (function(module, exports, __webpack_require__) {
  3412. "use strict";
  3413. Object.defineProperty(exports, "__esModule", {
  3414. value: true
  3415. });
  3416. exports.PDFSidebar = exports.SidebarView = void 0;
  3417. var _ui_utils = __webpack_require__(2);
  3418. var _pdf_rendering_queue = __webpack_require__(8);
  3419. const UI_NOTIFICATION_CLASS = "pdfSidebarNotification";
  3420. const SidebarView = {
  3421. UNKNOWN: -1,
  3422. NONE: 0,
  3423. THUMBS: 1,
  3424. OUTLINE: 2,
  3425. ATTACHMENTS: 3,
  3426. LAYERS: 4
  3427. };
  3428. exports.SidebarView = SidebarView;
  3429. class PDFSidebar {
  3430. constructor({
  3431. elements,
  3432. pdfViewer,
  3433. pdfThumbnailViewer,
  3434. eventBus,
  3435. l10n = _ui_utils.NullL10n,
  3436. disableNotification = false
  3437. }) {
  3438. this.isOpen = false;
  3439. this.active = SidebarView.THUMBS;
  3440. this.isInitialViewSet = false;
  3441. this.onToggled = null;
  3442. this.pdfViewer = pdfViewer;
  3443. this.pdfThumbnailViewer = pdfThumbnailViewer;
  3444. this.outerContainer = elements.outerContainer;
  3445. this.viewerContainer = elements.viewerContainer;
  3446. this.toggleButton = elements.toggleButton;
  3447. this.thumbnailButton = elements.thumbnailButton;
  3448. this.outlineButton = elements.outlineButton;
  3449. this.attachmentsButton = elements.attachmentsButton;
  3450. this.thumbnailView = elements.thumbnailView;
  3451. this.outlineView = elements.outlineView;
  3452. this.attachmentsView = elements.attachmentsView;
  3453. this.eventBus = eventBus;
  3454. this.l10n = l10n;
  3455. this._disableNotification = disableNotification;
  3456. this._addEventListeners();
  3457. }
  3458. reset() {
  3459. this.isInitialViewSet = false;
  3460. this._hideUINotification(null);
  3461. this.switchView(SidebarView.THUMBS);
  3462. this.outlineButton.disabled = false;
  3463. this.attachmentsButton.disabled = false;
  3464. }
  3465. get visibleView() {
  3466. return this.isOpen ? this.active : SidebarView.NONE;
  3467. }
  3468. get isThumbnailViewVisible() {
  3469. return this.isOpen && this.active === SidebarView.THUMBS;
  3470. }
  3471. get isOutlineViewVisible() {
  3472. return this.isOpen && this.active === SidebarView.OUTLINE;
  3473. }
  3474. get isAttachmentsViewVisible() {
  3475. return this.isOpen && this.active === SidebarView.ATTACHMENTS;
  3476. }
  3477. setInitialView(view = SidebarView.NONE) {
  3478. if (this.isInitialViewSet) {
  3479. return;
  3480. }
  3481. this.isInitialViewSet = true;
  3482. if (view === SidebarView.NONE || view === SidebarView.UNKNOWN) {
  3483. this._dispatchEvent();
  3484. return;
  3485. }
  3486. if (!this._switchView(view, true)) {
  3487. this._dispatchEvent();
  3488. }
  3489. }
  3490. switchView(view, forceOpen = false) {
  3491. this._switchView(view, forceOpen);
  3492. }
  3493. _switchView(view, forceOpen = false) {
  3494. const isViewChanged = view !== this.active;
  3495. let shouldForceRendering = false;
  3496. switch (view) {
  3497. case SidebarView.NONE:
  3498. if (this.isOpen) {
  3499. this.close();
  3500. return true;
  3501. }
  3502. return false;
  3503. case SidebarView.THUMBS:
  3504. if (this.isOpen && isViewChanged) {
  3505. shouldForceRendering = true;
  3506. }
  3507. break;
  3508. case SidebarView.OUTLINE:
  3509. if (this.outlineButton.disabled) {
  3510. return false;
  3511. }
  3512. break;
  3513. case SidebarView.ATTACHMENTS:
  3514. if (this.attachmentsButton.disabled) {
  3515. return false;
  3516. }
  3517. break;
  3518. default:
  3519. console.error(`PDFSidebar._switchView: "${view}" is not a valid view.`);
  3520. return false;
  3521. }
  3522. this.active = view;
  3523. this.thumbnailButton.classList.toggle("toggled", view === SidebarView.THUMBS);
  3524. this.outlineButton.classList.toggle("toggled", view === SidebarView.OUTLINE);
  3525. this.attachmentsButton.classList.toggle("toggled", view === SidebarView.ATTACHMENTS);
  3526. this.thumbnailView.classList.toggle("hidden", view !== SidebarView.THUMBS);
  3527. this.outlineView.classList.toggle("hidden", view !== SidebarView.OUTLINE);
  3528. this.attachmentsView.classList.toggle("hidden", view !== SidebarView.ATTACHMENTS);
  3529. if (forceOpen && !this.isOpen) {
  3530. this.open();
  3531. return true;
  3532. }
  3533. if (shouldForceRendering) {
  3534. this._updateThumbnailViewer();
  3535. this._forceRendering();
  3536. }
  3537. if (isViewChanged) {
  3538. this._dispatchEvent();
  3539. }
  3540. this._hideUINotification(this.active);
  3541. return isViewChanged;
  3542. }
  3543. open() {
  3544. if (this.isOpen) {
  3545. return;
  3546. }
  3547. this.isOpen = true;
  3548. this.toggleButton.classList.add("toggled");
  3549. this.outerContainer.classList.add("sidebarMoving", "sidebarOpen");
  3550. if (this.active === SidebarView.THUMBS) {
  3551. this._updateThumbnailViewer();
  3552. }
  3553. this._forceRendering();
  3554. this._dispatchEvent();
  3555. this._hideUINotification(this.active);
  3556. }
  3557. close() {
  3558. if (!this.isOpen) {
  3559. return;
  3560. }
  3561. this.isOpen = false;
  3562. this.toggleButton.classList.remove("toggled");
  3563. this.outerContainer.classList.add("sidebarMoving");
  3564. this.outerContainer.classList.remove("sidebarOpen");
  3565. this._forceRendering();
  3566. this._dispatchEvent();
  3567. }
  3568. toggle() {
  3569. if (this.isOpen) {
  3570. this.close();
  3571. } else {
  3572. this.open();
  3573. }
  3574. }
  3575. _dispatchEvent() {
  3576. this.eventBus.dispatch("sidebarviewchanged", {
  3577. source: this,
  3578. view: this.visibleView
  3579. });
  3580. }
  3581. _forceRendering() {
  3582. if (this.onToggled) {
  3583. this.onToggled();
  3584. } else {
  3585. this.pdfViewer.forceRendering();
  3586. this.pdfThumbnailViewer.forceRendering();
  3587. }
  3588. }
  3589. _updateThumbnailViewer() {
  3590. const {
  3591. pdfViewer,
  3592. pdfThumbnailViewer
  3593. } = this;
  3594. const pagesCount = pdfViewer.pagesCount;
  3595. for (let pageIndex = 0; pageIndex < pagesCount; pageIndex++) {
  3596. const pageView = pdfViewer.getPageView(pageIndex);
  3597. if (pageView && pageView.renderingState === _pdf_rendering_queue.RenderingStates.FINISHED) {
  3598. const thumbnailView = pdfThumbnailViewer.getThumbnail(pageIndex);
  3599. thumbnailView.setImage(pageView);
  3600. }
  3601. }
  3602. pdfThumbnailViewer.scrollThumbnailIntoView(pdfViewer.currentPageNumber);
  3603. }
  3604. _showUINotification(view) {
  3605. if (this._disableNotification) {
  3606. return;
  3607. }
  3608. this.l10n.get("toggle_sidebar_notification.title", null, "Toggle Sidebar (document contains outline/attachments)").then(msg => {
  3609. this.toggleButton.title = msg;
  3610. });
  3611. if (!this.isOpen) {
  3612. this.toggleButton.classList.add(UI_NOTIFICATION_CLASS);
  3613. } else if (view === this.active) {
  3614. return;
  3615. }
  3616. switch (view) {
  3617. case SidebarView.OUTLINE:
  3618. this.outlineButton.classList.add(UI_NOTIFICATION_CLASS);
  3619. break;
  3620. case SidebarView.ATTACHMENTS:
  3621. this.attachmentsButton.classList.add(UI_NOTIFICATION_CLASS);
  3622. break;
  3623. }
  3624. }
  3625. _hideUINotification(view) {
  3626. if (this._disableNotification) {
  3627. return;
  3628. }
  3629. const removeNotification = sidebarView => {
  3630. switch (sidebarView) {
  3631. case SidebarView.OUTLINE:
  3632. this.outlineButton.classList.remove(UI_NOTIFICATION_CLASS);
  3633. break;
  3634. case SidebarView.ATTACHMENTS:
  3635. this.attachmentsButton.classList.remove(UI_NOTIFICATION_CLASS);
  3636. break;
  3637. }
  3638. };
  3639. if (!this.isOpen && view !== null) {
  3640. return;
  3641. }
  3642. this.toggleButton.classList.remove(UI_NOTIFICATION_CLASS);
  3643. if (view !== null) {
  3644. removeNotification(view);
  3645. return;
  3646. }
  3647. for (view in SidebarView) {
  3648. removeNotification(SidebarView[view]);
  3649. }
  3650. this.l10n.get("toggle_sidebar.title", null, "Toggle Sidebar").then(msg => {
  3651. this.toggleButton.title = msg;
  3652. });
  3653. }
  3654. _addEventListeners() {
  3655. this.viewerContainer.addEventListener("transitionend", evt => {
  3656. if (evt.target === this.viewerContainer) {
  3657. this.outerContainer.classList.remove("sidebarMoving");
  3658. }
  3659. });
  3660. this.toggleButton.addEventListener("click", () => {
  3661. this.toggle();
  3662. });
  3663. this.thumbnailButton.addEventListener("click", () => {
  3664. this.switchView(SidebarView.THUMBS);
  3665. });
  3666. this.outlineButton.addEventListener("click", () => {
  3667. this.switchView(SidebarView.OUTLINE);
  3668. });
  3669. this.outlineButton.addEventListener("dblclick", () => {
  3670. this.eventBus.dispatch("toggleoutlinetree", {
  3671. source: this
  3672. });
  3673. });
  3674. this.attachmentsButton.addEventListener("click", () => {
  3675. this.switchView(SidebarView.ATTACHMENTS);
  3676. });
  3677. this.eventBus._on("outlineloaded", evt => {
  3678. const outlineCount = evt.outlineCount;
  3679. this.outlineButton.disabled = !outlineCount;
  3680. if (outlineCount) {
  3681. this._showUINotification(SidebarView.OUTLINE);
  3682. } else if (this.active === SidebarView.OUTLINE) {
  3683. this.switchView(SidebarView.THUMBS);
  3684. }
  3685. });
  3686. this.eventBus._on("attachmentsloaded", evt => {
  3687. if (evt.attachmentsCount) {
  3688. this.attachmentsButton.disabled = false;
  3689. this._showUINotification(SidebarView.ATTACHMENTS);
  3690. return;
  3691. }
  3692. Promise.resolve().then(() => {
  3693. if (this.attachmentsView.hasChildNodes()) {
  3694. return;
  3695. }
  3696. this.attachmentsButton.disabled = true;
  3697. if (this.active === SidebarView.ATTACHMENTS) {
  3698. this.switchView(SidebarView.THUMBS);
  3699. }
  3700. });
  3701. });
  3702. this.eventBus._on("presentationmodechanged", evt => {
  3703. if (!evt.active && !evt.switchInProgress && this.isThumbnailViewVisible) {
  3704. this._updateThumbnailViewer();
  3705. }
  3706. });
  3707. }
  3708. }
  3709. exports.PDFSidebar = PDFSidebar;
  3710. /***/ }),
  3711. /* 10 */
  3712. /***/ (function(module, exports, __webpack_require__) {
  3713. "use strict";
  3714. Object.defineProperty(exports, "__esModule", {
  3715. value: true
  3716. });
  3717. exports.OverlayManager = void 0;
  3718. class OverlayManager {
  3719. constructor() {
  3720. this._overlays = {};
  3721. this._active = null;
  3722. this._keyDownBound = this._keyDown.bind(this);
  3723. }
  3724. get active() {
  3725. return this._active;
  3726. }
  3727. async register(name, element, callerCloseMethod = null, canForceClose = false) {
  3728. let container;
  3729. if (!name || !element || !(container = element.parentNode)) {
  3730. throw new Error("Not enough parameters.");
  3731. } else if (this._overlays[name]) {
  3732. throw new Error("The overlay is already registered.");
  3733. }
  3734. this._overlays[name] = {
  3735. element,
  3736. container,
  3737. callerCloseMethod,
  3738. canForceClose
  3739. };
  3740. }
  3741. async unregister(name) {
  3742. if (!this._overlays[name]) {
  3743. throw new Error("The overlay does not exist.");
  3744. } else if (this._active === name) {
  3745. throw new Error("The overlay cannot be removed while it is active.");
  3746. }
  3747. delete this._overlays[name];
  3748. }
  3749. async open(name) {
  3750. if (!this._overlays[name]) {
  3751. throw new Error("The overlay does not exist.");
  3752. } else if (this._active) {
  3753. if (this._overlays[name].canForceClose) {
  3754. this._closeThroughCaller();
  3755. } else if (this._active === name) {
  3756. throw new Error("The overlay is already active.");
  3757. } else {
  3758. throw new Error("Another overlay is currently active.");
  3759. }
  3760. }
  3761. this._active = name;
  3762. this._overlays[this._active].element.classList.remove("hidden");
  3763. this._overlays[this._active].container.classList.remove("hidden");
  3764. window.addEventListener("keydown", this._keyDownBound);
  3765. }
  3766. async close(name) {
  3767. if (!this._overlays[name]) {
  3768. throw new Error("The overlay does not exist.");
  3769. } else if (!this._active) {
  3770. throw new Error("The overlay is currently not active.");
  3771. } else if (this._active !== name) {
  3772. throw new Error("Another overlay is currently active.");
  3773. }
  3774. this._overlays[this._active].container.classList.add("hidden");
  3775. this._overlays[this._active].element.classList.add("hidden");
  3776. this._active = null;
  3777. window.removeEventListener("keydown", this._keyDownBound);
  3778. }
  3779. _keyDown(evt) {
  3780. if (this._active && evt.keyCode === 27) {
  3781. this._closeThroughCaller();
  3782. evt.preventDefault();
  3783. }
  3784. }
  3785. _closeThroughCaller() {
  3786. if (this._overlays[this._active].callerCloseMethod) {
  3787. this._overlays[this._active].callerCloseMethod();
  3788. }
  3789. if (this._active) {
  3790. this.close(this._active);
  3791. }
  3792. }
  3793. }
  3794. exports.OverlayManager = OverlayManager;
  3795. /***/ }),
  3796. /* 11 */
  3797. /***/ (function(module, exports, __webpack_require__) {
  3798. "use strict";
  3799. Object.defineProperty(exports, "__esModule", {
  3800. value: true
  3801. });
  3802. exports.PasswordPrompt = void 0;
  3803. var _ui_utils = __webpack_require__(2);
  3804. var _pdfjsLib = __webpack_require__(4);
  3805. class PasswordPrompt {
  3806. constructor(options, overlayManager, l10n = _ui_utils.NullL10n) {
  3807. this.overlayName = options.overlayName;
  3808. this.container = options.container;
  3809. this.label = options.label;
  3810. this.input = options.input;
  3811. this.submitButton = options.submitButton;
  3812. this.cancelButton = options.cancelButton;
  3813. this.overlayManager = overlayManager;
  3814. this.l10n = l10n;
  3815. this.updateCallback = null;
  3816. this.reason = null;
  3817. this.submitButton.addEventListener("click", this.verify.bind(this));
  3818. this.cancelButton.addEventListener("click", this.close.bind(this));
  3819. this.input.addEventListener("keydown", e => {
  3820. if (e.keyCode === 13) {
  3821. this.verify();
  3822. }
  3823. });
  3824. this.overlayManager.register(this.overlayName, this.container, this.close.bind(this), true);
  3825. }
  3826. open() {
  3827. this.overlayManager.open(this.overlayName).then(() => {
  3828. this.input.focus();
  3829. let promptString;
  3830. if (this.reason === _pdfjsLib.PasswordResponses.INCORRECT_PASSWORD) {
  3831. promptString = this.l10n.get("password_invalid", null, "Invalid password. Please try again.");
  3832. } else {
  3833. promptString = this.l10n.get("password_label", null, "Enter the password to open this PDF file.");
  3834. }
  3835. promptString.then(msg => {
  3836. this.label.textContent = msg;
  3837. });
  3838. });
  3839. }
  3840. close() {
  3841. this.overlayManager.close(this.overlayName).then(() => {
  3842. this.input.value = "";
  3843. });
  3844. }
  3845. verify() {
  3846. const password = this.input.value;
  3847. if (password && password.length > 0) {
  3848. this.close();
  3849. this.updateCallback(password);
  3850. }
  3851. }
  3852. setUpdateCallback(updateCallback, reason) {
  3853. this.updateCallback = updateCallback;
  3854. this.reason = reason;
  3855. }
  3856. }
  3857. exports.PasswordPrompt = PasswordPrompt;
  3858. /***/ }),
  3859. /* 12 */
  3860. /***/ (function(module, exports, __webpack_require__) {
  3861. "use strict";
  3862. Object.defineProperty(exports, "__esModule", {
  3863. value: true
  3864. });
  3865. exports.PDFAttachmentViewer = void 0;
  3866. var _pdfjsLib = __webpack_require__(4);
  3867. class PDFAttachmentViewer {
  3868. constructor({
  3869. container,
  3870. eventBus,
  3871. downloadManager
  3872. }) {
  3873. this.container = container;
  3874. this.eventBus = eventBus;
  3875. this.downloadManager = downloadManager;
  3876. this.reset();
  3877. this.eventBus._on("fileattachmentannotation", this._appendAttachment.bind(this));
  3878. }
  3879. reset(keepRenderedCapability = false) {
  3880. this.attachments = null;
  3881. this.container.textContent = "";
  3882. if (!keepRenderedCapability) {
  3883. this._renderedCapability = (0, _pdfjsLib.createPromiseCapability)();
  3884. }
  3885. }
  3886. _dispatchEvent(attachmentsCount) {
  3887. this._renderedCapability.resolve();
  3888. this.eventBus.dispatch("attachmentsloaded", {
  3889. source: this,
  3890. attachmentsCount
  3891. });
  3892. }
  3893. _bindPdfLink(button, content, filename) {
  3894. if (this.downloadManager.disableCreateObjectURL) {
  3895. throw new Error('bindPdfLink: Unsupported "disableCreateObjectURL" value.');
  3896. }
  3897. let blobUrl;
  3898. button.onclick = function () {
  3899. if (!blobUrl) {
  3900. blobUrl = (0, _pdfjsLib.createObjectURL)(content, "application/pdf");
  3901. }
  3902. let viewerUrl;
  3903. viewerUrl = "?file=" + encodeURIComponent(blobUrl + "#" + filename);
  3904. window.open(viewerUrl);
  3905. return false;
  3906. };
  3907. }
  3908. _bindLink(button, content, filename) {
  3909. button.onclick = () => {
  3910. this.downloadManager.downloadData(content, filename, "");
  3911. return false;
  3912. };
  3913. }
  3914. render({
  3915. attachments,
  3916. keepRenderedCapability = false
  3917. }) {
  3918. let attachmentsCount = 0;
  3919. if (this.attachments) {
  3920. this.reset(keepRenderedCapability === true);
  3921. }
  3922. this.attachments = attachments || null;
  3923. if (!attachments) {
  3924. this._dispatchEvent(attachmentsCount);
  3925. return;
  3926. }
  3927. const names = Object.keys(attachments).sort(function (a, b) {
  3928. return a.toLowerCase().localeCompare(b.toLowerCase());
  3929. });
  3930. attachmentsCount = names.length;
  3931. for (let i = 0; i < attachmentsCount; i++) {
  3932. const item = attachments[names[i]];
  3933. const filename = (0, _pdfjsLib.removeNullCharacters)((0, _pdfjsLib.getFilenameFromUrl)(item.filename));
  3934. const div = document.createElement("div");
  3935. div.className = "attachmentsItem";
  3936. const button = document.createElement("button");
  3937. button.textContent = filename;
  3938. if (/\.pdf$/i.test(filename) && !this.downloadManager.disableCreateObjectURL) {
  3939. this._bindPdfLink(button, item.content, filename);
  3940. } else {
  3941. this._bindLink(button, item.content, filename);
  3942. }
  3943. div.appendChild(button);
  3944. this.container.appendChild(div);
  3945. }
  3946. this._dispatchEvent(attachmentsCount);
  3947. }
  3948. _appendAttachment({
  3949. id,
  3950. filename,
  3951. content
  3952. }) {
  3953. this._renderedCapability.promise.then(() => {
  3954. let attachments = this.attachments;
  3955. if (!attachments) {
  3956. attachments = Object.create(null);
  3957. } else {
  3958. for (const name in attachments) {
  3959. if (id === name) {
  3960. return;
  3961. }
  3962. }
  3963. }
  3964. attachments[id] = {
  3965. filename,
  3966. content
  3967. };
  3968. this.render({
  3969. attachments,
  3970. keepRenderedCapability: true
  3971. });
  3972. });
  3973. }
  3974. }
  3975. exports.PDFAttachmentViewer = PDFAttachmentViewer;
  3976. /***/ }),
  3977. /* 13 */
  3978. /***/ (function(module, exports, __webpack_require__) {
  3979. "use strict";
  3980. Object.defineProperty(exports, "__esModule", {
  3981. value: true
  3982. });
  3983. exports.PDFDocumentProperties = void 0;
  3984. var _pdfjsLib = __webpack_require__(4);
  3985. var _ui_utils = __webpack_require__(2);
  3986. const DEFAULT_FIELD_CONTENT = "-";
  3987. const NON_METRIC_LOCALES = ["en-us", "en-lr", "my"];
  3988. const US_PAGE_NAMES = {
  3989. "8.5x11": "Letter",
  3990. "8.5x14": "Legal"
  3991. };
  3992. const METRIC_PAGE_NAMES = {
  3993. "297x420": "A3",
  3994. "210x297": "A4"
  3995. };
  3996. function getPageName(size, isPortrait, pageNames) {
  3997. const width = isPortrait ? size.width : size.height;
  3998. const height = isPortrait ? size.height : size.width;
  3999. return pageNames[`${width}x${height}`];
  4000. }
  4001. class PDFDocumentProperties {
  4002. constructor({
  4003. overlayName,
  4004. fields,
  4005. container,
  4006. closeButton
  4007. }, overlayManager, eventBus, l10n = _ui_utils.NullL10n) {
  4008. this.overlayName = overlayName;
  4009. this.fields = fields;
  4010. this.container = container;
  4011. this.overlayManager = overlayManager;
  4012. this.l10n = l10n;
  4013. this._reset();
  4014. if (closeButton) {
  4015. closeButton.addEventListener("click", this.close.bind(this));
  4016. }
  4017. this.overlayManager.register(this.overlayName, this.container, this.close.bind(this));
  4018. if (eventBus) {
  4019. eventBus._on("pagechanging", evt => {
  4020. this._currentPageNumber = evt.pageNumber;
  4021. });
  4022. eventBus._on("rotationchanging", evt => {
  4023. this._pagesRotation = evt.pagesRotation;
  4024. });
  4025. }
  4026. this._isNonMetricLocale = true;
  4027. l10n.getLanguage().then(locale => {
  4028. this._isNonMetricLocale = NON_METRIC_LOCALES.includes(locale);
  4029. });
  4030. }
  4031. open() {
  4032. const freezeFieldData = data => {
  4033. Object.defineProperty(this, "fieldData", {
  4034. value: Object.freeze(data),
  4035. writable: false,
  4036. enumerable: true,
  4037. configurable: true
  4038. });
  4039. };
  4040. Promise.all([this.overlayManager.open(this.overlayName), this._dataAvailableCapability.promise]).then(() => {
  4041. const currentPageNumber = this._currentPageNumber;
  4042. const pagesRotation = this._pagesRotation;
  4043. if (this.fieldData && currentPageNumber === this.fieldData["_currentPageNumber"] && pagesRotation === this.fieldData["_pagesRotation"]) {
  4044. this._updateUI();
  4045. return;
  4046. }
  4047. this.pdfDocument.getMetadata().then(({
  4048. info,
  4049. metadata,
  4050. contentDispositionFilename
  4051. }) => {
  4052. return Promise.all([info, metadata, contentDispositionFilename || (0, _ui_utils.getPDFFileNameFromURL)(this.url || ""), this._parseFileSize(this.maybeFileSize), this._parseDate(info.CreationDate), this._parseDate(info.ModDate), this.pdfDocument.getPage(currentPageNumber).then(pdfPage => {
  4053. return this._parsePageSize((0, _ui_utils.getPageSizeInches)(pdfPage), pagesRotation);
  4054. }), this._parseLinearization(info.IsLinearized)]);
  4055. }).then(([info, metadata, fileName, fileSize, creationDate, modDate, pageSize, isLinearized]) => {
  4056. freezeFieldData({
  4057. fileName,
  4058. fileSize,
  4059. title: info.Title,
  4060. author: info.Author,
  4061. subject: info.Subject,
  4062. keywords: info.Keywords,
  4063. creationDate,
  4064. modificationDate: modDate,
  4065. creator: info.Creator,
  4066. producer: info.Producer,
  4067. version: info.PDFFormatVersion,
  4068. pageCount: this.pdfDocument.numPages,
  4069. pageSize,
  4070. linearized: isLinearized,
  4071. _currentPageNumber: currentPageNumber,
  4072. _pagesRotation: pagesRotation
  4073. });
  4074. this._updateUI();
  4075. return this.pdfDocument.getDownloadInfo();
  4076. }).then(({
  4077. length
  4078. }) => {
  4079. this.maybeFileSize = length;
  4080. return this._parseFileSize(length);
  4081. }).then(fileSize => {
  4082. if (fileSize === this.fieldData["fileSize"]) {
  4083. return;
  4084. }
  4085. const data = Object.assign(Object.create(null), this.fieldData);
  4086. data["fileSize"] = fileSize;
  4087. freezeFieldData(data);
  4088. this._updateUI();
  4089. });
  4090. });
  4091. }
  4092. close() {
  4093. this.overlayManager.close(this.overlayName);
  4094. }
  4095. setDocument(pdfDocument, url = null) {
  4096. if (this.pdfDocument) {
  4097. this._reset();
  4098. this._updateUI(true);
  4099. }
  4100. if (!pdfDocument) {
  4101. return;
  4102. }
  4103. this.pdfDocument = pdfDocument;
  4104. this.url = url;
  4105. this._dataAvailableCapability.resolve();
  4106. }
  4107. setFileSize(fileSize) {
  4108. if (Number.isInteger(fileSize) && fileSize > 0) {
  4109. this.maybeFileSize = fileSize;
  4110. }
  4111. }
  4112. _reset() {
  4113. this.pdfDocument = null;
  4114. this.url = null;
  4115. this.maybeFileSize = 0;
  4116. delete this.fieldData;
  4117. this._dataAvailableCapability = (0, _pdfjsLib.createPromiseCapability)();
  4118. this._currentPageNumber = 1;
  4119. this._pagesRotation = 0;
  4120. }
  4121. _updateUI(reset = false) {
  4122. if (reset || !this.fieldData) {
  4123. for (const id in this.fields) {
  4124. this.fields[id].textContent = DEFAULT_FIELD_CONTENT;
  4125. }
  4126. return;
  4127. }
  4128. if (this.overlayManager.active !== this.overlayName) {
  4129. return;
  4130. }
  4131. for (const id in this.fields) {
  4132. const content = this.fieldData[id];
  4133. this.fields[id].textContent = content || content === 0 ? content : DEFAULT_FIELD_CONTENT;
  4134. }
  4135. }
  4136. async _parseFileSize(fileSize = 0) {
  4137. const kb = fileSize / 1024;
  4138. if (!kb) {
  4139. return undefined;
  4140. } else if (kb < 1024) {
  4141. return this.l10n.get("document_properties_kb", {
  4142. size_kb: (+kb.toPrecision(3)).toLocaleString(),
  4143. size_b: fileSize.toLocaleString()
  4144. }, "{{size_kb}} KB ({{size_b}} bytes)");
  4145. }
  4146. return this.l10n.get("document_properties_mb", {
  4147. size_mb: (+(kb / 1024).toPrecision(3)).toLocaleString(),
  4148. size_b: fileSize.toLocaleString()
  4149. }, "{{size_mb}} MB ({{size_b}} bytes)");
  4150. }
  4151. async _parsePageSize(pageSizeInches, pagesRotation) {
  4152. if (!pageSizeInches) {
  4153. return undefined;
  4154. }
  4155. if (pagesRotation % 180 !== 0) {
  4156. pageSizeInches = {
  4157. width: pageSizeInches.height,
  4158. height: pageSizeInches.width
  4159. };
  4160. }
  4161. const isPortrait = (0, _ui_utils.isPortraitOrientation)(pageSizeInches);
  4162. let sizeInches = {
  4163. width: Math.round(pageSizeInches.width * 100) / 100,
  4164. height: Math.round(pageSizeInches.height * 100) / 100
  4165. };
  4166. let sizeMillimeters = {
  4167. width: Math.round(pageSizeInches.width * 25.4 * 10) / 10,
  4168. height: Math.round(pageSizeInches.height * 25.4 * 10) / 10
  4169. };
  4170. let pageName = null;
  4171. let rawName = getPageName(sizeInches, isPortrait, US_PAGE_NAMES) || getPageName(sizeMillimeters, isPortrait, METRIC_PAGE_NAMES);
  4172. if (!rawName && !(Number.isInteger(sizeMillimeters.width) && Number.isInteger(sizeMillimeters.height))) {
  4173. const exactMillimeters = {
  4174. width: pageSizeInches.width * 25.4,
  4175. height: pageSizeInches.height * 25.4
  4176. };
  4177. const intMillimeters = {
  4178. width: Math.round(sizeMillimeters.width),
  4179. height: Math.round(sizeMillimeters.height)
  4180. };
  4181. if (Math.abs(exactMillimeters.width - intMillimeters.width) < 0.1 && Math.abs(exactMillimeters.height - intMillimeters.height) < 0.1) {
  4182. rawName = getPageName(intMillimeters, isPortrait, METRIC_PAGE_NAMES);
  4183. if (rawName) {
  4184. sizeInches = {
  4185. width: Math.round(intMillimeters.width / 25.4 * 100) / 100,
  4186. height: Math.round(intMillimeters.height / 25.4 * 100) / 100
  4187. };
  4188. sizeMillimeters = intMillimeters;
  4189. }
  4190. }
  4191. }
  4192. if (rawName) {
  4193. pageName = this.l10n.get("document_properties_page_size_name_" + rawName.toLowerCase(), null, rawName);
  4194. }
  4195. return Promise.all([this._isNonMetricLocale ? sizeInches : sizeMillimeters, this.l10n.get("document_properties_page_size_unit_" + (this._isNonMetricLocale ? "inches" : "millimeters"), null, this._isNonMetricLocale ? "in" : "mm"), pageName, this.l10n.get("document_properties_page_size_orientation_" + (isPortrait ? "portrait" : "landscape"), null, isPortrait ? "portrait" : "landscape")]).then(([{
  4196. width,
  4197. height
  4198. }, unit, name, orientation]) => {
  4199. return this.l10n.get("document_properties_page_size_dimension_" + (name ? "name_" : "") + "string", {
  4200. width: width.toLocaleString(),
  4201. height: height.toLocaleString(),
  4202. unit,
  4203. name,
  4204. orientation
  4205. }, "{{width}} × {{height}} {{unit}} (" + (name ? "{{name}}, " : "") + "{{orientation}})");
  4206. });
  4207. }
  4208. async _parseDate(inputDate) {
  4209. const dateObject = _pdfjsLib.PDFDateString.toDateObject(inputDate);
  4210. if (!dateObject) {
  4211. return undefined;
  4212. }
  4213. return this.l10n.get("document_properties_date_string", {
  4214. date: dateObject.toLocaleDateString(),
  4215. time: dateObject.toLocaleTimeString()
  4216. }, "{{date}}, {{time}}");
  4217. }
  4218. _parseLinearization(isLinearized) {
  4219. return this.l10n.get("document_properties_linearized_" + (isLinearized ? "yes" : "no"), null, isLinearized ? "Yes" : "No");
  4220. }
  4221. }
  4222. exports.PDFDocumentProperties = PDFDocumentProperties;
  4223. /***/ }),
  4224. /* 14 */
  4225. /***/ (function(module, exports, __webpack_require__) {
  4226. "use strict";
  4227. Object.defineProperty(exports, "__esModule", {
  4228. value: true
  4229. });
  4230. exports.PDFFindBar = void 0;
  4231. var _ui_utils = __webpack_require__(2);
  4232. var _pdf_find_controller = __webpack_require__(15);
  4233. const MATCHES_COUNT_LIMIT = 1000;
  4234. class PDFFindBar {
  4235. constructor(options, eventBus, l10n = _ui_utils.NullL10n) {
  4236. this.opened = false;
  4237. this.bar = options.bar || null;
  4238. this.toggleButton = options.toggleButton || null;
  4239. this.findField = options.findField || null;
  4240. this.highlightAll = options.highlightAllCheckbox || null;
  4241. this.caseSensitive = options.caseSensitiveCheckbox || null;
  4242. this.entireWord = options.entireWordCheckbox || null;
  4243. this.findMsg = options.findMsg || null;
  4244. this.findResultsCount = options.findResultsCount || null;
  4245. this.findPreviousButton = options.findPreviousButton || null;
  4246. this.findNextButton = options.findNextButton || null;
  4247. this.eventBus = eventBus || (0, _ui_utils.getGlobalEventBus)();
  4248. this.l10n = l10n;
  4249. this.toggleButton.addEventListener("click", () => {
  4250. this.toggle();
  4251. });
  4252. this.findField.addEventListener("input", () => {
  4253. this.dispatchEvent("");
  4254. });
  4255. this.bar.addEventListener("keydown", e => {
  4256. switch (e.keyCode) {
  4257. case 13:
  4258. if (e.target === this.findField) {
  4259. this.dispatchEvent("again", e.shiftKey);
  4260. }
  4261. break;
  4262. case 27:
  4263. this.close();
  4264. break;
  4265. }
  4266. });
  4267. this.findPreviousButton.addEventListener("click", () => {
  4268. this.dispatchEvent("again", true);
  4269. });
  4270. this.findNextButton.addEventListener("click", () => {
  4271. this.dispatchEvent("again", false);
  4272. });
  4273. this.highlightAll.addEventListener("click", () => {
  4274. this.dispatchEvent("highlightallchange");
  4275. });
  4276. this.caseSensitive.addEventListener("click", () => {
  4277. this.dispatchEvent("casesensitivitychange");
  4278. });
  4279. this.entireWord.addEventListener("click", () => {
  4280. this.dispatchEvent("entirewordchange");
  4281. });
  4282. this.eventBus._on("resize", this._adjustWidth.bind(this));
  4283. }
  4284. reset() {
  4285. this.updateUIState();
  4286. }
  4287. dispatchEvent(type, findPrev) {
  4288. this.eventBus.dispatch("find", {
  4289. source: this,
  4290. type,
  4291. query: this.findField.value,
  4292. phraseSearch: true,
  4293. caseSensitive: this.caseSensitive.checked,
  4294. entireWord: this.entireWord.checked,
  4295. highlightAll: this.highlightAll.checked,
  4296. findPrevious: findPrev
  4297. });
  4298. }
  4299. updateUIState(state, previous, matchesCount) {
  4300. let notFound = false;
  4301. let findMsg = "";
  4302. let status = "";
  4303. switch (state) {
  4304. case _pdf_find_controller.FindState.FOUND:
  4305. break;
  4306. case _pdf_find_controller.FindState.PENDING:
  4307. status = "pending";
  4308. break;
  4309. case _pdf_find_controller.FindState.NOT_FOUND:
  4310. findMsg = this.l10n.get("find_not_found", null, "Phrase not found");
  4311. notFound = true;
  4312. break;
  4313. case _pdf_find_controller.FindState.WRAPPED:
  4314. if (previous) {
  4315. findMsg = this.l10n.get("find_reached_top", null, "Reached top of document, continued from bottom");
  4316. } else {
  4317. findMsg = this.l10n.get("find_reached_bottom", null, "Reached end of document, continued from top");
  4318. }
  4319. break;
  4320. }
  4321. this.findField.classList.toggle("notFound", notFound);
  4322. this.findField.setAttribute("data-status", status);
  4323. Promise.resolve(findMsg).then(msg => {
  4324. this.findMsg.textContent = msg;
  4325. this._adjustWidth();
  4326. });
  4327. this.updateResultsCount(matchesCount);
  4328. }
  4329. updateResultsCount({
  4330. current = 0,
  4331. total = 0
  4332. } = {}) {
  4333. if (!this.findResultsCount) {
  4334. return;
  4335. }
  4336. const limit = MATCHES_COUNT_LIMIT;
  4337. let matchesCountMsg = "";
  4338. if (total > 0) {
  4339. if (total > limit) {
  4340. matchesCountMsg = this.l10n.get("find_match_count_limit", {
  4341. limit
  4342. }, "More than {{limit}} match" + (limit !== 1 ? "es" : ""));
  4343. } else {
  4344. matchesCountMsg = this.l10n.get("find_match_count", {
  4345. current,
  4346. total
  4347. }, "{{current}} of {{total}} match" + (total !== 1 ? "es" : ""));
  4348. }
  4349. }
  4350. Promise.resolve(matchesCountMsg).then(msg => {
  4351. this.findResultsCount.textContent = msg;
  4352. this.findResultsCount.classList.toggle("hidden", !total);
  4353. this._adjustWidth();
  4354. });
  4355. }
  4356. open() {
  4357. if (!this.opened) {
  4358. this.opened = true;
  4359. this.toggleButton.classList.add("toggled");
  4360. this.bar.classList.remove("hidden");
  4361. }
  4362. this.findField.select();
  4363. this.findField.focus();
  4364. this._adjustWidth();
  4365. }
  4366. close() {
  4367. if (!this.opened) {
  4368. return;
  4369. }
  4370. this.opened = false;
  4371. this.toggleButton.classList.remove("toggled");
  4372. this.bar.classList.add("hidden");
  4373. this.eventBus.dispatch("findbarclose", {
  4374. source: this
  4375. });
  4376. }
  4377. toggle() {
  4378. if (this.opened) {
  4379. this.close();
  4380. } else {
  4381. this.open();
  4382. }
  4383. }
  4384. _adjustWidth() {
  4385. if (!this.opened) {
  4386. return;
  4387. }
  4388. this.bar.classList.remove("wrapContainers");
  4389. const findbarHeight = this.bar.clientHeight;
  4390. const inputContainerHeight = this.bar.firstElementChild.clientHeight;
  4391. if (findbarHeight > inputContainerHeight) {
  4392. this.bar.classList.add("wrapContainers");
  4393. }
  4394. }
  4395. }
  4396. exports.PDFFindBar = PDFFindBar;
  4397. /***/ }),
  4398. /* 15 */
  4399. /***/ (function(module, exports, __webpack_require__) {
  4400. "use strict";
  4401. Object.defineProperty(exports, "__esModule", {
  4402. value: true
  4403. });
  4404. exports.PDFFindController = exports.FindState = void 0;
  4405. var _ui_utils = __webpack_require__(2);
  4406. var _pdfjsLib = __webpack_require__(4);
  4407. var _pdf_find_utils = __webpack_require__(16);
  4408. const FindState = {
  4409. FOUND: 0,
  4410. NOT_FOUND: 1,
  4411. WRAPPED: 2,
  4412. PENDING: 3
  4413. };
  4414. exports.FindState = FindState;
  4415. const FIND_TIMEOUT = 250;
  4416. const MATCH_SCROLL_OFFSET_TOP = -50;
  4417. const MATCH_SCROLL_OFFSET_LEFT = -400;
  4418. const CHARACTERS_TO_NORMALIZE = {
  4419. "\u2018": "'",
  4420. "\u2019": "'",
  4421. "\u201A": "'",
  4422. "\u201B": "'",
  4423. "\u201C": '"',
  4424. "\u201D": '"',
  4425. "\u201E": '"',
  4426. "\u201F": '"',
  4427. "\u00BC": "1/4",
  4428. "\u00BD": "1/2",
  4429. "\u00BE": "3/4"
  4430. };
  4431. let normalizationRegex = null;
  4432. function normalize(text) {
  4433. if (!normalizationRegex) {
  4434. const replace = Object.keys(CHARACTERS_TO_NORMALIZE).join("");
  4435. normalizationRegex = new RegExp(`[${replace}]`, "g");
  4436. }
  4437. return text.replace(normalizationRegex, function (ch) {
  4438. return CHARACTERS_TO_NORMALIZE[ch];
  4439. });
  4440. }
  4441. class PDFFindController {
  4442. constructor({
  4443. linkService,
  4444. eventBus
  4445. }) {
  4446. this._linkService = linkService;
  4447. this._eventBus = eventBus || (0, _ui_utils.getGlobalEventBus)();
  4448. this._reset();
  4449. eventBus._on("findbarclose", this._onFindBarClose.bind(this));
  4450. }
  4451. get highlightMatches() {
  4452. return this._highlightMatches;
  4453. }
  4454. get pageMatches() {
  4455. return this._pageMatches;
  4456. }
  4457. get pageMatchesLength() {
  4458. return this._pageMatchesLength;
  4459. }
  4460. get selected() {
  4461. return this._selected;
  4462. }
  4463. get state() {
  4464. return this._state;
  4465. }
  4466. setDocument(pdfDocument) {
  4467. if (this._pdfDocument) {
  4468. this._reset();
  4469. }
  4470. if (!pdfDocument) {
  4471. return;
  4472. }
  4473. this._pdfDocument = pdfDocument;
  4474. this._firstPageCapability.resolve();
  4475. }
  4476. executeCommand(cmd, state) {
  4477. if (!state) {
  4478. return;
  4479. }
  4480. const pdfDocument = this._pdfDocument;
  4481. if (this._state === null || this._shouldDirtyMatch(cmd, state)) {
  4482. this._dirtyMatch = true;
  4483. }
  4484. this._state = state;
  4485. if (cmd !== "findhighlightallchange") {
  4486. this._updateUIState(FindState.PENDING);
  4487. }
  4488. this._firstPageCapability.promise.then(() => {
  4489. if (!this._pdfDocument || pdfDocument && this._pdfDocument !== pdfDocument) {
  4490. return;
  4491. }
  4492. this._extractText();
  4493. const findbarClosed = !this._highlightMatches;
  4494. const pendingTimeout = !!this._findTimeout;
  4495. if (this._findTimeout) {
  4496. clearTimeout(this._findTimeout);
  4497. this._findTimeout = null;
  4498. }
  4499. if (cmd === "find") {
  4500. this._findTimeout = setTimeout(() => {
  4501. this._nextMatch();
  4502. this._findTimeout = null;
  4503. }, FIND_TIMEOUT);
  4504. } else if (this._dirtyMatch) {
  4505. this._nextMatch();
  4506. } else if (cmd === "findagain") {
  4507. this._nextMatch();
  4508. if (findbarClosed && this._state.highlightAll) {
  4509. this._updateAllPages();
  4510. }
  4511. } else if (cmd === "findhighlightallchange") {
  4512. if (pendingTimeout) {
  4513. this._nextMatch();
  4514. } else {
  4515. this._highlightMatches = true;
  4516. }
  4517. this._updateAllPages();
  4518. } else {
  4519. this._nextMatch();
  4520. }
  4521. });
  4522. }
  4523. scrollMatchIntoView({
  4524. element = null,
  4525. pageIndex = -1,
  4526. matchIndex = -1
  4527. }) {
  4528. if (!this._scrollMatches || !element) {
  4529. return;
  4530. } else if (matchIndex === -1 || matchIndex !== this._selected.matchIdx) {
  4531. return;
  4532. } else if (pageIndex === -1 || pageIndex !== this._selected.pageIdx) {
  4533. return;
  4534. }
  4535. this._scrollMatches = false;
  4536. const spot = {
  4537. top: MATCH_SCROLL_OFFSET_TOP,
  4538. left: MATCH_SCROLL_OFFSET_LEFT
  4539. };
  4540. (0, _ui_utils.scrollIntoView)(element, spot, true);
  4541. }
  4542. _reset() {
  4543. this._highlightMatches = false;
  4544. this._scrollMatches = false;
  4545. this._pdfDocument = null;
  4546. this._pageMatches = [];
  4547. this._pageMatchesLength = [];
  4548. this._state = null;
  4549. this._selected = {
  4550. pageIdx: -1,
  4551. matchIdx: -1
  4552. };
  4553. this._offset = {
  4554. pageIdx: null,
  4555. matchIdx: null,
  4556. wrapped: false
  4557. };
  4558. this._extractTextPromises = [];
  4559. this._pageContents = [];
  4560. this._matchesCountTotal = 0;
  4561. this._pagesToSearch = null;
  4562. this._pendingFindMatches = Object.create(null);
  4563. this._resumePageIdx = null;
  4564. this._dirtyMatch = false;
  4565. clearTimeout(this._findTimeout);
  4566. this._findTimeout = null;
  4567. this._firstPageCapability = (0, _pdfjsLib.createPromiseCapability)();
  4568. }
  4569. get _query() {
  4570. if (this._state.query !== this._rawQuery) {
  4571. this._rawQuery = this._state.query;
  4572. this._normalizedQuery = normalize(this._state.query);
  4573. }
  4574. return this._normalizedQuery;
  4575. }
  4576. _shouldDirtyMatch(cmd, state) {
  4577. if (state.query !== this._state.query) {
  4578. return true;
  4579. }
  4580. switch (cmd) {
  4581. case "findagain":
  4582. const pageNumber = this._selected.pageIdx + 1;
  4583. const linkService = this._linkService;
  4584. if (pageNumber >= 1 && pageNumber <= linkService.pagesCount && pageNumber !== linkService.page && !linkService.isPageVisible(pageNumber)) {
  4585. return true;
  4586. }
  4587. return false;
  4588. case "findhighlightallchange":
  4589. return false;
  4590. }
  4591. return true;
  4592. }
  4593. _prepareMatches(matchesWithLength, matches, matchesLength) {
  4594. function isSubTerm(currentIndex) {
  4595. const currentElem = matchesWithLength[currentIndex];
  4596. const nextElem = matchesWithLength[currentIndex + 1];
  4597. if (currentIndex < matchesWithLength.length - 1 && currentElem.match === nextElem.match) {
  4598. currentElem.skipped = true;
  4599. return true;
  4600. }
  4601. for (let i = currentIndex - 1; i >= 0; i--) {
  4602. const prevElem = matchesWithLength[i];
  4603. if (prevElem.skipped) {
  4604. continue;
  4605. }
  4606. if (prevElem.match + prevElem.matchLength < currentElem.match) {
  4607. break;
  4608. }
  4609. if (prevElem.match + prevElem.matchLength >= currentElem.match + currentElem.matchLength) {
  4610. currentElem.skipped = true;
  4611. return true;
  4612. }
  4613. }
  4614. return false;
  4615. }
  4616. matchesWithLength.sort(function (a, b) {
  4617. return a.match === b.match ? a.matchLength - b.matchLength : a.match - b.match;
  4618. });
  4619. for (let i = 0, len = matchesWithLength.length; i < len; i++) {
  4620. if (isSubTerm(i)) {
  4621. continue;
  4622. }
  4623. matches.push(matchesWithLength[i].match);
  4624. matchesLength.push(matchesWithLength[i].matchLength);
  4625. }
  4626. }
  4627. _isEntireWord(content, startIdx, length) {
  4628. if (startIdx > 0) {
  4629. const first = content.charCodeAt(startIdx);
  4630. const limit = content.charCodeAt(startIdx - 1);
  4631. if ((0, _pdf_find_utils.getCharacterType)(first) === (0, _pdf_find_utils.getCharacterType)(limit)) {
  4632. return false;
  4633. }
  4634. }
  4635. const endIdx = startIdx + length - 1;
  4636. if (endIdx < content.length - 1) {
  4637. const last = content.charCodeAt(endIdx);
  4638. const limit = content.charCodeAt(endIdx + 1);
  4639. if ((0, _pdf_find_utils.getCharacterType)(last) === (0, _pdf_find_utils.getCharacterType)(limit)) {
  4640. return false;
  4641. }
  4642. }
  4643. return true;
  4644. }
  4645. _calculatePhraseMatch(query, pageIndex, pageContent, entireWord) {
  4646. const matches = [];
  4647. const queryLen = query.length;
  4648. let matchIdx = -queryLen;
  4649. while (true) {
  4650. matchIdx = pageContent.indexOf(query, matchIdx + queryLen);
  4651. if (matchIdx === -1) {
  4652. break;
  4653. }
  4654. if (entireWord && !this._isEntireWord(pageContent, matchIdx, queryLen)) {
  4655. continue;
  4656. }
  4657. matches.push(matchIdx);
  4658. }
  4659. this._pageMatches[pageIndex] = matches;
  4660. }
  4661. _calculateWordMatch(query, pageIndex, pageContent, entireWord) {
  4662. const matchesWithLength = [];
  4663. const queryArray = query.match(/\S+/g);
  4664. for (let i = 0, len = queryArray.length; i < len; i++) {
  4665. const subquery = queryArray[i];
  4666. const subqueryLen = subquery.length;
  4667. let matchIdx = -subqueryLen;
  4668. while (true) {
  4669. matchIdx = pageContent.indexOf(subquery, matchIdx + subqueryLen);
  4670. if (matchIdx === -1) {
  4671. break;
  4672. }
  4673. if (entireWord && !this._isEntireWord(pageContent, matchIdx, subqueryLen)) {
  4674. continue;
  4675. }
  4676. matchesWithLength.push({
  4677. match: matchIdx,
  4678. matchLength: subqueryLen,
  4679. skipped: false
  4680. });
  4681. }
  4682. }
  4683. this._pageMatchesLength[pageIndex] = [];
  4684. this._pageMatches[pageIndex] = [];
  4685. this._prepareMatches(matchesWithLength, this._pageMatches[pageIndex], this._pageMatchesLength[pageIndex]);
  4686. }
  4687. _calculateMatch(pageIndex) {
  4688. let pageContent = this._pageContents[pageIndex];
  4689. let query = this._query;
  4690. const {
  4691. caseSensitive,
  4692. entireWord,
  4693. phraseSearch
  4694. } = this._state;
  4695. if (query.length === 0) {
  4696. return;
  4697. }
  4698. if (!caseSensitive) {
  4699. pageContent = pageContent.toLowerCase();
  4700. query = query.toLowerCase();
  4701. }
  4702. if (phraseSearch) {
  4703. this._calculatePhraseMatch(query, pageIndex, pageContent, entireWord);
  4704. } else {
  4705. this._calculateWordMatch(query, pageIndex, pageContent, entireWord);
  4706. }
  4707. if (this._state.highlightAll) {
  4708. this._updatePage(pageIndex);
  4709. }
  4710. if (this._resumePageIdx === pageIndex) {
  4711. this._resumePageIdx = null;
  4712. this._nextPageMatch();
  4713. }
  4714. const pageMatchesCount = this._pageMatches[pageIndex].length;
  4715. if (pageMatchesCount > 0) {
  4716. this._matchesCountTotal += pageMatchesCount;
  4717. this._updateUIResultsCount();
  4718. }
  4719. }
  4720. _extractText() {
  4721. if (this._extractTextPromises.length > 0) {
  4722. return;
  4723. }
  4724. let promise = Promise.resolve();
  4725. for (let i = 0, ii = this._linkService.pagesCount; i < ii; i++) {
  4726. const extractTextCapability = (0, _pdfjsLib.createPromiseCapability)();
  4727. this._extractTextPromises[i] = extractTextCapability.promise;
  4728. promise = promise.then(() => {
  4729. return this._pdfDocument.getPage(i + 1).then(pdfPage => {
  4730. return pdfPage.getTextContent({
  4731. normalizeWhitespace: true
  4732. });
  4733. }).then(textContent => {
  4734. const textItems = textContent.items;
  4735. const strBuf = [];
  4736. for (let j = 0, jj = textItems.length; j < jj; j++) {
  4737. strBuf.push(textItems[j].str);
  4738. }
  4739. this._pageContents[i] = normalize(strBuf.join(""));
  4740. extractTextCapability.resolve(i);
  4741. }, reason => {
  4742. console.error(`Unable to get text content for page ${i + 1}`, reason);
  4743. this._pageContents[i] = "";
  4744. extractTextCapability.resolve(i);
  4745. });
  4746. });
  4747. }
  4748. }
  4749. _updatePage(index) {
  4750. if (this._scrollMatches && this._selected.pageIdx === index) {
  4751. this._linkService.page = index + 1;
  4752. }
  4753. this._eventBus.dispatch("updatetextlayermatches", {
  4754. source: this,
  4755. pageIndex: index
  4756. });
  4757. }
  4758. _updateAllPages() {
  4759. this._eventBus.dispatch("updatetextlayermatches", {
  4760. source: this,
  4761. pageIndex: -1
  4762. });
  4763. }
  4764. _nextMatch() {
  4765. const previous = this._state.findPrevious;
  4766. const currentPageIndex = this._linkService.page - 1;
  4767. const numPages = this._linkService.pagesCount;
  4768. this._highlightMatches = true;
  4769. if (this._dirtyMatch) {
  4770. this._dirtyMatch = false;
  4771. this._selected.pageIdx = this._selected.matchIdx = -1;
  4772. this._offset.pageIdx = currentPageIndex;
  4773. this._offset.matchIdx = null;
  4774. this._offset.wrapped = false;
  4775. this._resumePageIdx = null;
  4776. this._pageMatches.length = 0;
  4777. this._pageMatchesLength.length = 0;
  4778. this._matchesCountTotal = 0;
  4779. this._updateAllPages();
  4780. for (let i = 0; i < numPages; i++) {
  4781. if (this._pendingFindMatches[i] === true) {
  4782. continue;
  4783. }
  4784. this._pendingFindMatches[i] = true;
  4785. this._extractTextPromises[i].then(pageIdx => {
  4786. delete this._pendingFindMatches[pageIdx];
  4787. this._calculateMatch(pageIdx);
  4788. });
  4789. }
  4790. }
  4791. if (this._query === "") {
  4792. this._updateUIState(FindState.FOUND);
  4793. return;
  4794. }
  4795. if (this._resumePageIdx) {
  4796. return;
  4797. }
  4798. const offset = this._offset;
  4799. this._pagesToSearch = numPages;
  4800. if (offset.matchIdx !== null) {
  4801. const numPageMatches = this._pageMatches[offset.pageIdx].length;
  4802. if (!previous && offset.matchIdx + 1 < numPageMatches || previous && offset.matchIdx > 0) {
  4803. offset.matchIdx = previous ? offset.matchIdx - 1 : offset.matchIdx + 1;
  4804. this._updateMatch(true);
  4805. return;
  4806. }
  4807. this._advanceOffsetPage(previous);
  4808. }
  4809. this._nextPageMatch();
  4810. }
  4811. _matchesReady(matches) {
  4812. const offset = this._offset;
  4813. const numMatches = matches.length;
  4814. const previous = this._state.findPrevious;
  4815. if (numMatches) {
  4816. offset.matchIdx = previous ? numMatches - 1 : 0;
  4817. this._updateMatch(true);
  4818. return true;
  4819. }
  4820. this._advanceOffsetPage(previous);
  4821. if (offset.wrapped) {
  4822. offset.matchIdx = null;
  4823. if (this._pagesToSearch < 0) {
  4824. this._updateMatch(false);
  4825. return true;
  4826. }
  4827. }
  4828. return false;
  4829. }
  4830. _nextPageMatch() {
  4831. if (this._resumePageIdx !== null) {
  4832. console.error("There can only be one pending page.");
  4833. }
  4834. let matches = null;
  4835. do {
  4836. const pageIdx = this._offset.pageIdx;
  4837. matches = this._pageMatches[pageIdx];
  4838. if (!matches) {
  4839. this._resumePageIdx = pageIdx;
  4840. break;
  4841. }
  4842. } while (!this._matchesReady(matches));
  4843. }
  4844. _advanceOffsetPage(previous) {
  4845. const offset = this._offset;
  4846. const numPages = this._linkService.pagesCount;
  4847. offset.pageIdx = previous ? offset.pageIdx - 1 : offset.pageIdx + 1;
  4848. offset.matchIdx = null;
  4849. this._pagesToSearch--;
  4850. if (offset.pageIdx >= numPages || offset.pageIdx < 0) {
  4851. offset.pageIdx = previous ? numPages - 1 : 0;
  4852. offset.wrapped = true;
  4853. }
  4854. }
  4855. _updateMatch(found = false) {
  4856. let state = FindState.NOT_FOUND;
  4857. const wrapped = this._offset.wrapped;
  4858. this._offset.wrapped = false;
  4859. if (found) {
  4860. const previousPage = this._selected.pageIdx;
  4861. this._selected.pageIdx = this._offset.pageIdx;
  4862. this._selected.matchIdx = this._offset.matchIdx;
  4863. state = wrapped ? FindState.WRAPPED : FindState.FOUND;
  4864. if (previousPage !== -1 && previousPage !== this._selected.pageIdx) {
  4865. this._updatePage(previousPage);
  4866. }
  4867. }
  4868. this._updateUIState(state, this._state.findPrevious);
  4869. if (this._selected.pageIdx !== -1) {
  4870. this._scrollMatches = true;
  4871. this._updatePage(this._selected.pageIdx);
  4872. }
  4873. }
  4874. _onFindBarClose(evt) {
  4875. const pdfDocument = this._pdfDocument;
  4876. this._firstPageCapability.promise.then(() => {
  4877. if (!this._pdfDocument || pdfDocument && this._pdfDocument !== pdfDocument) {
  4878. return;
  4879. }
  4880. if (this._findTimeout) {
  4881. clearTimeout(this._findTimeout);
  4882. this._findTimeout = null;
  4883. }
  4884. if (this._resumePageIdx) {
  4885. this._resumePageIdx = null;
  4886. this._dirtyMatch = true;
  4887. }
  4888. this._updateUIState(FindState.FOUND);
  4889. this._highlightMatches = false;
  4890. this._updateAllPages();
  4891. });
  4892. }
  4893. _requestMatchesCount() {
  4894. const {
  4895. pageIdx,
  4896. matchIdx
  4897. } = this._selected;
  4898. let current = 0,
  4899. total = this._matchesCountTotal;
  4900. if (matchIdx !== -1) {
  4901. for (let i = 0; i < pageIdx; i++) {
  4902. current += this._pageMatches[i] && this._pageMatches[i].length || 0;
  4903. }
  4904. current += matchIdx + 1;
  4905. }
  4906. if (current < 1 || current > total) {
  4907. current = total = 0;
  4908. }
  4909. return {
  4910. current,
  4911. total
  4912. };
  4913. }
  4914. _updateUIResultsCount() {
  4915. this._eventBus.dispatch("updatefindmatchescount", {
  4916. source: this,
  4917. matchesCount: this._requestMatchesCount()
  4918. });
  4919. }
  4920. _updateUIState(state, previous) {
  4921. this._eventBus.dispatch("updatefindcontrolstate", {
  4922. source: this,
  4923. state,
  4924. previous,
  4925. matchesCount: this._requestMatchesCount()
  4926. });
  4927. }
  4928. }
  4929. exports.PDFFindController = PDFFindController;
  4930. /***/ }),
  4931. /* 16 */
  4932. /***/ (function(module, exports, __webpack_require__) {
  4933. "use strict";
  4934. Object.defineProperty(exports, "__esModule", {
  4935. value: true
  4936. });
  4937. exports.getCharacterType = getCharacterType;
  4938. exports.CharacterType = void 0;
  4939. const CharacterType = {
  4940. SPACE: 0,
  4941. ALPHA_LETTER: 1,
  4942. PUNCT: 2,
  4943. HAN_LETTER: 3,
  4944. KATAKANA_LETTER: 4,
  4945. HIRAGANA_LETTER: 5,
  4946. HALFWIDTH_KATAKANA_LETTER: 6,
  4947. THAI_LETTER: 7
  4948. };
  4949. exports.CharacterType = CharacterType;
  4950. function isAlphabeticalScript(charCode) {
  4951. return charCode < 0x2e80;
  4952. }
  4953. function isAscii(charCode) {
  4954. return (charCode & 0xff80) === 0;
  4955. }
  4956. function isAsciiAlpha(charCode) {
  4957. return charCode >= 0x61 && charCode <= 0x7a || charCode >= 0x41 && charCode <= 0x5a;
  4958. }
  4959. function isAsciiDigit(charCode) {
  4960. return charCode >= 0x30 && charCode <= 0x39;
  4961. }
  4962. function isAsciiSpace(charCode) {
  4963. return charCode === 0x20 || charCode === 0x09 || charCode === 0x0d || charCode === 0x0a;
  4964. }
  4965. function isHan(charCode) {
  4966. return charCode >= 0x3400 && charCode <= 0x9fff || charCode >= 0xf900 && charCode <= 0xfaff;
  4967. }
  4968. function isKatakana(charCode) {
  4969. return charCode >= 0x30a0 && charCode <= 0x30ff;
  4970. }
  4971. function isHiragana(charCode) {
  4972. return charCode >= 0x3040 && charCode <= 0x309f;
  4973. }
  4974. function isHalfwidthKatakana(charCode) {
  4975. return charCode >= 0xff60 && charCode <= 0xff9f;
  4976. }
  4977. function isThai(charCode) {
  4978. return (charCode & 0xff80) === 0x0e00;
  4979. }
  4980. function getCharacterType(charCode) {
  4981. if (isAlphabeticalScript(charCode)) {
  4982. if (isAscii(charCode)) {
  4983. if (isAsciiSpace(charCode)) {
  4984. return CharacterType.SPACE;
  4985. } else if (isAsciiAlpha(charCode) || isAsciiDigit(charCode) || charCode === 0x5f) {
  4986. return CharacterType.ALPHA_LETTER;
  4987. }
  4988. return CharacterType.PUNCT;
  4989. } else if (isThai(charCode)) {
  4990. return CharacterType.THAI_LETTER;
  4991. } else if (charCode === 0xa0) {
  4992. return CharacterType.SPACE;
  4993. }
  4994. return CharacterType.ALPHA_LETTER;
  4995. }
  4996. if (isHan(charCode)) {
  4997. return CharacterType.HAN_LETTER;
  4998. } else if (isKatakana(charCode)) {
  4999. return CharacterType.KATAKANA_LETTER;
  5000. } else if (isHiragana(charCode)) {
  5001. return CharacterType.HIRAGANA_LETTER;
  5002. } else if (isHalfwidthKatakana(charCode)) {
  5003. return CharacterType.HALFWIDTH_KATAKANA_LETTER;
  5004. }
  5005. return CharacterType.ALPHA_LETTER;
  5006. }
  5007. /***/ }),
  5008. /* 17 */
  5009. /***/ (function(module, exports, __webpack_require__) {
  5010. "use strict";
  5011. Object.defineProperty(exports, "__esModule", {
  5012. value: true
  5013. });
  5014. exports.isDestHashesEqual = isDestHashesEqual;
  5015. exports.isDestArraysEqual = isDestArraysEqual;
  5016. exports.PDFHistory = void 0;
  5017. var _ui_utils = __webpack_require__(2);
  5018. const HASH_CHANGE_TIMEOUT = 1000;
  5019. const POSITION_UPDATED_THRESHOLD = 50;
  5020. const UPDATE_VIEWAREA_TIMEOUT = 1000;
  5021. function getCurrentHash() {
  5022. return document.location.hash;
  5023. }
  5024. class PDFHistory {
  5025. constructor({
  5026. linkService,
  5027. eventBus
  5028. }) {
  5029. this.linkService = linkService;
  5030. this.eventBus = eventBus || (0, _ui_utils.getGlobalEventBus)();
  5031. this._initialized = false;
  5032. this._fingerprint = "";
  5033. this.reset();
  5034. this._boundEvents = null;
  5035. this._isViewerInPresentationMode = false;
  5036. this.eventBus._on("presentationmodechanged", evt => {
  5037. this._isViewerInPresentationMode = evt.active || evt.switchInProgress;
  5038. });
  5039. this.eventBus._on("pagesinit", () => {
  5040. this._isPagesLoaded = false;
  5041. const onPagesLoaded = evt => {
  5042. this.eventBus._off("pagesloaded", onPagesLoaded);
  5043. this._isPagesLoaded = !!evt.pagesCount;
  5044. };
  5045. this.eventBus._on("pagesloaded", onPagesLoaded);
  5046. });
  5047. }
  5048. initialize({
  5049. fingerprint,
  5050. resetHistory = false,
  5051. updateUrl = false
  5052. }) {
  5053. if (!fingerprint || typeof fingerprint !== "string") {
  5054. console.error('PDFHistory.initialize: The "fingerprint" must be a non-empty string.');
  5055. return;
  5056. }
  5057. if (this._initialized) {
  5058. this.reset();
  5059. }
  5060. const reInitialized = this._fingerprint !== "" && this._fingerprint !== fingerprint;
  5061. this._fingerprint = fingerprint;
  5062. this._updateUrl = updateUrl === true;
  5063. this._initialized = true;
  5064. this._bindEvents();
  5065. const state = window.history.state;
  5066. this._popStateInProgress = false;
  5067. this._blockHashChange = 0;
  5068. this._currentHash = getCurrentHash();
  5069. this._numPositionUpdates = 0;
  5070. this._uid = this._maxUid = 0;
  5071. this._destination = null;
  5072. this._position = null;
  5073. if (!this._isValidState(state, true) || resetHistory) {
  5074. const {
  5075. hash,
  5076. page,
  5077. rotation
  5078. } = this._parseCurrentHash();
  5079. if (!hash || reInitialized || resetHistory) {
  5080. this._pushOrReplaceState(null, true);
  5081. return;
  5082. }
  5083. this._pushOrReplaceState({
  5084. hash,
  5085. page,
  5086. rotation
  5087. }, true);
  5088. return;
  5089. }
  5090. const destination = state.destination;
  5091. this._updateInternalState(destination, state.uid, true);
  5092. if (this._uid > this._maxUid) {
  5093. this._maxUid = this._uid;
  5094. }
  5095. if (destination.rotation !== undefined) {
  5096. this._initialRotation = destination.rotation;
  5097. }
  5098. if (destination.dest) {
  5099. this._initialBookmark = JSON.stringify(destination.dest);
  5100. this._destination.page = null;
  5101. } else if (destination.hash) {
  5102. this._initialBookmark = destination.hash;
  5103. } else if (destination.page) {
  5104. this._initialBookmark = `page=${destination.page}`;
  5105. }
  5106. }
  5107. reset() {
  5108. if (this._initialized) {
  5109. this._pageHide();
  5110. this._initialized = false;
  5111. this._unbindEvents();
  5112. }
  5113. if (this._updateViewareaTimeout) {
  5114. clearTimeout(this._updateViewareaTimeout);
  5115. this._updateViewareaTimeout = null;
  5116. }
  5117. this._initialBookmark = null;
  5118. this._initialRotation = null;
  5119. }
  5120. push({
  5121. namedDest = null,
  5122. explicitDest,
  5123. pageNumber
  5124. }) {
  5125. if (!this._initialized) {
  5126. return;
  5127. }
  5128. if (namedDest && typeof namedDest !== "string") {
  5129. console.error("PDFHistory.push: " + `"${namedDest}" is not a valid namedDest parameter.`);
  5130. return;
  5131. } else if (!Array.isArray(explicitDest)) {
  5132. console.error("PDFHistory.push: " + `"${explicitDest}" is not a valid explicitDest parameter.`);
  5133. return;
  5134. } else if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.linkService.pagesCount)) {
  5135. if (pageNumber !== null || this._destination) {
  5136. console.error("PDFHistory.push: " + `"${pageNumber}" is not a valid pageNumber parameter.`);
  5137. return;
  5138. }
  5139. }
  5140. const hash = namedDest || JSON.stringify(explicitDest);
  5141. if (!hash) {
  5142. return;
  5143. }
  5144. let forceReplace = false;
  5145. if (this._destination && (isDestHashesEqual(this._destination.hash, hash) || isDestArraysEqual(this._destination.dest, explicitDest))) {
  5146. if (this._destination.page) {
  5147. return;
  5148. }
  5149. forceReplace = true;
  5150. }
  5151. if (this._popStateInProgress && !forceReplace) {
  5152. return;
  5153. }
  5154. this._pushOrReplaceState({
  5155. dest: explicitDest,
  5156. hash,
  5157. page: pageNumber,
  5158. rotation: this.linkService.rotation
  5159. }, forceReplace);
  5160. if (!this._popStateInProgress) {
  5161. this._popStateInProgress = true;
  5162. Promise.resolve().then(() => {
  5163. this._popStateInProgress = false;
  5164. });
  5165. }
  5166. }
  5167. pushCurrentPosition() {
  5168. if (!this._initialized || this._popStateInProgress) {
  5169. return;
  5170. }
  5171. this._tryPushCurrentPosition();
  5172. }
  5173. back() {
  5174. if (!this._initialized || this._popStateInProgress) {
  5175. return;
  5176. }
  5177. const state = window.history.state;
  5178. if (this._isValidState(state) && state.uid > 0) {
  5179. window.history.back();
  5180. }
  5181. }
  5182. forward() {
  5183. if (!this._initialized || this._popStateInProgress) {
  5184. return;
  5185. }
  5186. const state = window.history.state;
  5187. if (this._isValidState(state) && state.uid < this._maxUid) {
  5188. window.history.forward();
  5189. }
  5190. }
  5191. get popStateInProgress() {
  5192. return this._initialized && (this._popStateInProgress || this._blockHashChange > 0);
  5193. }
  5194. get initialBookmark() {
  5195. return this._initialized ? this._initialBookmark : null;
  5196. }
  5197. get initialRotation() {
  5198. return this._initialized ? this._initialRotation : null;
  5199. }
  5200. _pushOrReplaceState(destination, forceReplace = false) {
  5201. const shouldReplace = forceReplace || !this._destination;
  5202. const newState = {
  5203. fingerprint: this._fingerprint,
  5204. uid: shouldReplace ? this._uid : this._uid + 1,
  5205. destination
  5206. };
  5207. this._updateInternalState(destination, newState.uid);
  5208. let newUrl;
  5209. if (this._updateUrl && destination && destination.hash) {
  5210. const baseUrl = document.location.href.split("#")[0];
  5211. if (!baseUrl.startsWith("file://")) {
  5212. newUrl = `${baseUrl}#${destination.hash}`;
  5213. }
  5214. }
  5215. if (shouldReplace) {
  5216. window.history.replaceState(newState, "", newUrl);
  5217. } else {
  5218. this._maxUid = this._uid;
  5219. window.history.pushState(newState, "", newUrl);
  5220. }
  5221. }
  5222. _tryPushCurrentPosition(temporary = false) {
  5223. if (!this._position) {
  5224. return;
  5225. }
  5226. let position = this._position;
  5227. if (temporary) {
  5228. position = Object.assign(Object.create(null), this._position);
  5229. position.temporary = true;
  5230. }
  5231. if (!this._destination) {
  5232. this._pushOrReplaceState(position);
  5233. return;
  5234. }
  5235. if (this._destination.temporary) {
  5236. this._pushOrReplaceState(position, true);
  5237. return;
  5238. }
  5239. if (this._destination.hash === position.hash) {
  5240. return;
  5241. }
  5242. if (!this._destination.page && (POSITION_UPDATED_THRESHOLD <= 0 || this._numPositionUpdates <= POSITION_UPDATED_THRESHOLD)) {
  5243. return;
  5244. }
  5245. let forceReplace = false;
  5246. if (this._destination.page >= position.first && this._destination.page <= position.page) {
  5247. if (this._destination.dest || !this._destination.first) {
  5248. return;
  5249. }
  5250. forceReplace = true;
  5251. }
  5252. this._pushOrReplaceState(position, forceReplace);
  5253. }
  5254. _isValidState(state, checkReload = false) {
  5255. if (!state) {
  5256. return false;
  5257. }
  5258. if (state.fingerprint !== this._fingerprint) {
  5259. if (checkReload) {
  5260. if (typeof state.fingerprint !== "string" || state.fingerprint.length !== this._fingerprint.length) {
  5261. return false;
  5262. }
  5263. const [perfEntry] = performance.getEntriesByType("navigation");
  5264. if (!perfEntry || perfEntry.type !== "reload") {
  5265. return false;
  5266. }
  5267. } else {
  5268. return false;
  5269. }
  5270. }
  5271. if (!Number.isInteger(state.uid) || state.uid < 0) {
  5272. return false;
  5273. }
  5274. if (state.destination === null || typeof state.destination !== "object") {
  5275. return false;
  5276. }
  5277. return true;
  5278. }
  5279. _updateInternalState(destination, uid, removeTemporary = false) {
  5280. if (this._updateViewareaTimeout) {
  5281. clearTimeout(this._updateViewareaTimeout);
  5282. this._updateViewareaTimeout = null;
  5283. }
  5284. if (removeTemporary && destination && destination.temporary) {
  5285. delete destination.temporary;
  5286. }
  5287. this._destination = destination;
  5288. this._uid = uid;
  5289. this._numPositionUpdates = 0;
  5290. }
  5291. _parseCurrentHash() {
  5292. const hash = unescape(getCurrentHash()).substring(1);
  5293. let page = (0, _ui_utils.parseQueryString)(hash).page | 0;
  5294. if (!(Number.isInteger(page) && page > 0 && page <= this.linkService.pagesCount)) {
  5295. page = null;
  5296. }
  5297. return {
  5298. hash,
  5299. page,
  5300. rotation: this.linkService.rotation
  5301. };
  5302. }
  5303. _updateViewarea({
  5304. location
  5305. }) {
  5306. if (this._updateViewareaTimeout) {
  5307. clearTimeout(this._updateViewareaTimeout);
  5308. this._updateViewareaTimeout = null;
  5309. }
  5310. this._position = {
  5311. hash: this._isViewerInPresentationMode ? `page=${location.pageNumber}` : location.pdfOpenParams.substring(1),
  5312. page: this.linkService.page,
  5313. first: location.pageNumber,
  5314. rotation: location.rotation
  5315. };
  5316. if (this._popStateInProgress) {
  5317. return;
  5318. }
  5319. if (POSITION_UPDATED_THRESHOLD > 0 && this._isPagesLoaded && this._destination && !this._destination.page) {
  5320. this._numPositionUpdates++;
  5321. }
  5322. if (UPDATE_VIEWAREA_TIMEOUT > 0) {
  5323. this._updateViewareaTimeout = setTimeout(() => {
  5324. if (!this._popStateInProgress) {
  5325. this._tryPushCurrentPosition(true);
  5326. }
  5327. this._updateViewareaTimeout = null;
  5328. }, UPDATE_VIEWAREA_TIMEOUT);
  5329. }
  5330. }
  5331. _popState({
  5332. state
  5333. }) {
  5334. const newHash = getCurrentHash(),
  5335. hashChanged = this._currentHash !== newHash;
  5336. this._currentHash = newHash;
  5337. if (!state) {
  5338. this._uid++;
  5339. const {
  5340. hash,
  5341. page,
  5342. rotation
  5343. } = this._parseCurrentHash();
  5344. this._pushOrReplaceState({
  5345. hash,
  5346. page,
  5347. rotation
  5348. }, true);
  5349. return;
  5350. }
  5351. if (!this._isValidState(state)) {
  5352. return;
  5353. }
  5354. this._popStateInProgress = true;
  5355. if (hashChanged) {
  5356. this._blockHashChange++;
  5357. (0, _ui_utils.waitOnEventOrTimeout)({
  5358. target: window,
  5359. name: "hashchange",
  5360. delay: HASH_CHANGE_TIMEOUT
  5361. }).then(() => {
  5362. this._blockHashChange--;
  5363. });
  5364. }
  5365. const destination = state.destination;
  5366. this._updateInternalState(destination, state.uid, true);
  5367. if (this._uid > this._maxUid) {
  5368. this._maxUid = this._uid;
  5369. }
  5370. if ((0, _ui_utils.isValidRotation)(destination.rotation)) {
  5371. this.linkService.rotation = destination.rotation;
  5372. }
  5373. if (destination.dest) {
  5374. this.linkService.navigateTo(destination.dest);
  5375. } else if (destination.hash) {
  5376. this.linkService.setHash(destination.hash);
  5377. } else if (destination.page) {
  5378. this.linkService.page = destination.page;
  5379. }
  5380. Promise.resolve().then(() => {
  5381. this._popStateInProgress = false;
  5382. });
  5383. }
  5384. _pageHide() {
  5385. if (!this._destination || this._destination.temporary) {
  5386. this._tryPushCurrentPosition();
  5387. }
  5388. }
  5389. _bindEvents() {
  5390. if (this._boundEvents) {
  5391. return;
  5392. }
  5393. this._boundEvents = {
  5394. updateViewarea: this._updateViewarea.bind(this),
  5395. popState: this._popState.bind(this),
  5396. pageHide: this._pageHide.bind(this)
  5397. };
  5398. this.eventBus._on("updateviewarea", this._boundEvents.updateViewarea);
  5399. window.addEventListener("popstate", this._boundEvents.popState);
  5400. window.addEventListener("pagehide", this._boundEvents.pageHide);
  5401. }
  5402. _unbindEvents() {
  5403. if (!this._boundEvents) {
  5404. return;
  5405. }
  5406. this.eventBus._off("updateviewarea", this._boundEvents.updateViewarea);
  5407. window.removeEventListener("popstate", this._boundEvents.popState);
  5408. window.removeEventListener("pagehide", this._boundEvents.pageHide);
  5409. this._boundEvents = null;
  5410. }
  5411. }
  5412. exports.PDFHistory = PDFHistory;
  5413. function isDestHashesEqual(destHash, pushHash) {
  5414. if (typeof destHash !== "string" || typeof pushHash !== "string") {
  5415. return false;
  5416. }
  5417. if (destHash === pushHash) {
  5418. return true;
  5419. }
  5420. const {
  5421. nameddest
  5422. } = (0, _ui_utils.parseQueryString)(destHash);
  5423. if (nameddest === pushHash) {
  5424. return true;
  5425. }
  5426. return false;
  5427. }
  5428. function isDestArraysEqual(firstDest, secondDest) {
  5429. function isEntryEqual(first, second) {
  5430. if (typeof first !== typeof second) {
  5431. return false;
  5432. }
  5433. if (Array.isArray(first) || Array.isArray(second)) {
  5434. return false;
  5435. }
  5436. if (first !== null && typeof first === "object" && second !== null) {
  5437. if (Object.keys(first).length !== Object.keys(second).length) {
  5438. return false;
  5439. }
  5440. for (const key in first) {
  5441. if (!isEntryEqual(first[key], second[key])) {
  5442. return false;
  5443. }
  5444. }
  5445. return true;
  5446. }
  5447. return first === second || Number.isNaN(first) && Number.isNaN(second);
  5448. }
  5449. if (!(Array.isArray(firstDest) && Array.isArray(secondDest))) {
  5450. return false;
  5451. }
  5452. if (firstDest.length !== secondDest.length) {
  5453. return false;
  5454. }
  5455. for (let i = 0, ii = firstDest.length; i < ii; i++) {
  5456. if (!isEntryEqual(firstDest[i], secondDest[i])) {
  5457. return false;
  5458. }
  5459. }
  5460. return true;
  5461. }
  5462. /***/ }),
  5463. /* 18 */
  5464. /***/ (function(module, exports, __webpack_require__) {
  5465. "use strict";
  5466. Object.defineProperty(exports, "__esModule", {
  5467. value: true
  5468. });
  5469. exports.SimpleLinkService = exports.PDFLinkService = void 0;
  5470. var _ui_utils = __webpack_require__(2);
  5471. class PDFLinkService {
  5472. constructor({
  5473. eventBus,
  5474. externalLinkTarget = null,
  5475. externalLinkRel = null,
  5476. externalLinkEnabled = true,
  5477. ignoreDestinationZoom = false
  5478. } = {}) {
  5479. this.eventBus = eventBus || (0, _ui_utils.getGlobalEventBus)();
  5480. this.externalLinkTarget = externalLinkTarget;
  5481. this.externalLinkRel = externalLinkRel;
  5482. this.externalLinkEnabled = externalLinkEnabled;
  5483. this._ignoreDestinationZoom = ignoreDestinationZoom;
  5484. this.baseUrl = null;
  5485. this.pdfDocument = null;
  5486. this.pdfViewer = null;
  5487. this.pdfHistory = null;
  5488. this._pagesRefCache = null;
  5489. }
  5490. setDocument(pdfDocument, baseUrl = null) {
  5491. this.baseUrl = baseUrl;
  5492. this.pdfDocument = pdfDocument;
  5493. this._pagesRefCache = Object.create(null);
  5494. }
  5495. setViewer(pdfViewer) {
  5496. this.pdfViewer = pdfViewer;
  5497. }
  5498. setHistory(pdfHistory) {
  5499. this.pdfHistory = pdfHistory;
  5500. }
  5501. get pagesCount() {
  5502. return this.pdfDocument ? this.pdfDocument.numPages : 0;
  5503. }
  5504. get page() {
  5505. return this.pdfViewer.currentPageNumber;
  5506. }
  5507. set page(value) {
  5508. this.pdfViewer.currentPageNumber = value;
  5509. }
  5510. get rotation() {
  5511. return this.pdfViewer.pagesRotation;
  5512. }
  5513. set rotation(value) {
  5514. this.pdfViewer.pagesRotation = value;
  5515. }
  5516. navigateTo(dest) {
  5517. const goToDestination = ({
  5518. namedDest,
  5519. explicitDest
  5520. }) => {
  5521. const destRef = explicitDest[0];
  5522. let pageNumber;
  5523. if (destRef instanceof Object) {
  5524. pageNumber = this._cachedPageNumber(destRef);
  5525. if (pageNumber === null) {
  5526. this.pdfDocument.getPageIndex(destRef).then(pageIndex => {
  5527. this.cachePageRef(pageIndex + 1, destRef);
  5528. goToDestination({
  5529. namedDest,
  5530. explicitDest
  5531. });
  5532. }).catch(() => {
  5533. console.error(`PDFLinkService.navigateTo: "${destRef}" is not ` + `a valid page reference, for dest="${dest}".`);
  5534. });
  5535. return;
  5536. }
  5537. } else if (Number.isInteger(destRef)) {
  5538. pageNumber = destRef + 1;
  5539. } else {
  5540. console.error(`PDFLinkService.navigateTo: "${destRef}" is not ` + `a valid destination reference, for dest="${dest}".`);
  5541. return;
  5542. }
  5543. if (!pageNumber || pageNumber < 1 || pageNumber > this.pagesCount) {
  5544. console.error(`PDFLinkService.navigateTo: "${pageNumber}" is not ` + `a valid page number, for dest="${dest}".`);
  5545. return;
  5546. }
  5547. if (this.pdfHistory) {
  5548. this.pdfHistory.pushCurrentPosition();
  5549. this.pdfHistory.push({
  5550. namedDest,
  5551. explicitDest,
  5552. pageNumber
  5553. });
  5554. }
  5555. this.pdfViewer.scrollPageIntoView({
  5556. pageNumber,
  5557. destArray: explicitDest,
  5558. ignoreDestinationZoom: this._ignoreDestinationZoom
  5559. });
  5560. };
  5561. new Promise((resolve, reject) => {
  5562. if (typeof dest === "string") {
  5563. this.pdfDocument.getDestination(dest).then(destArray => {
  5564. resolve({
  5565. namedDest: dest,
  5566. explicitDest: destArray
  5567. });
  5568. });
  5569. return;
  5570. }
  5571. resolve({
  5572. namedDest: "",
  5573. explicitDest: dest
  5574. });
  5575. }).then(data => {
  5576. if (!Array.isArray(data.explicitDest)) {
  5577. console.error(`PDFLinkService.navigateTo: "${data.explicitDest}" is` + ` not a valid destination array, for dest="${dest}".`);
  5578. return;
  5579. }
  5580. goToDestination(data);
  5581. });
  5582. }
  5583. getDestinationHash(dest) {
  5584. if (typeof dest === "string") {
  5585. return this.getAnchorUrl("#" + escape(dest));
  5586. }
  5587. if (Array.isArray(dest)) {
  5588. const str = JSON.stringify(dest);
  5589. return this.getAnchorUrl("#" + escape(str));
  5590. }
  5591. return this.getAnchorUrl("");
  5592. }
  5593. getAnchorUrl(anchor) {
  5594. return (this.baseUrl || "") + anchor;
  5595. }
  5596. setHash(hash) {
  5597. let pageNumber, dest;
  5598. if (hash.includes("=")) {
  5599. const params = (0, _ui_utils.parseQueryString)(hash);
  5600. if ("search" in params) {
  5601. this.eventBus.dispatch("findfromurlhash", {
  5602. source: this,
  5603. query: params["search"].replace(/"/g, ""),
  5604. phraseSearch: params["phrase"] === "true"
  5605. });
  5606. }
  5607. if ("nameddest" in params) {
  5608. this.navigateTo(params.nameddest);
  5609. return;
  5610. }
  5611. if ("page" in params) {
  5612. pageNumber = params.page | 0 || 1;
  5613. }
  5614. if ("zoom" in params) {
  5615. const zoomArgs = params.zoom.split(",");
  5616. const zoomArg = zoomArgs[0];
  5617. const zoomArgNumber = parseFloat(zoomArg);
  5618. if (!zoomArg.includes("Fit")) {
  5619. dest = [null, {
  5620. name: "XYZ"
  5621. }, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null, zoomArgs.length > 2 ? zoomArgs[2] | 0 : null, zoomArgNumber ? zoomArgNumber / 100 : zoomArg];
  5622. } else {
  5623. if (zoomArg === "Fit" || zoomArg === "FitB") {
  5624. dest = [null, {
  5625. name: zoomArg
  5626. }];
  5627. } else if (zoomArg === "FitH" || zoomArg === "FitBH" || zoomArg === "FitV" || zoomArg === "FitBV") {
  5628. dest = [null, {
  5629. name: zoomArg
  5630. }, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null];
  5631. } else if (zoomArg === "FitR") {
  5632. if (zoomArgs.length !== 5) {
  5633. console.error('PDFLinkService.setHash: Not enough parameters for "FitR".');
  5634. } else {
  5635. dest = [null, {
  5636. name: zoomArg
  5637. }, zoomArgs[1] | 0, zoomArgs[2] | 0, zoomArgs[3] | 0, zoomArgs[4] | 0];
  5638. }
  5639. } else {
  5640. console.error(`PDFLinkService.setHash: "${zoomArg}" is not ` + "a valid zoom value.");
  5641. }
  5642. }
  5643. }
  5644. if (dest) {
  5645. this.pdfViewer.scrollPageIntoView({
  5646. pageNumber: pageNumber || this.page,
  5647. destArray: dest,
  5648. allowNegativeOffset: true
  5649. });
  5650. } else if (pageNumber) {
  5651. this.page = pageNumber;
  5652. }
  5653. if ("pagemode" in params) {
  5654. this.eventBus.dispatch("pagemode", {
  5655. source: this,
  5656. mode: params.pagemode
  5657. });
  5658. }
  5659. } else {
  5660. dest = unescape(hash);
  5661. try {
  5662. dest = JSON.parse(dest);
  5663. if (!Array.isArray(dest)) {
  5664. dest = dest.toString();
  5665. }
  5666. } catch (ex) {}
  5667. if (typeof dest === "string" || isValidExplicitDestination(dest)) {
  5668. this.navigateTo(dest);
  5669. return;
  5670. }
  5671. console.error(`PDFLinkService.setHash: "${unescape(hash)}" is not ` + "a valid destination.");
  5672. }
  5673. }
  5674. executeNamedAction(action) {
  5675. switch (action) {
  5676. case "GoBack":
  5677. if (this.pdfHistory) {
  5678. this.pdfHistory.back();
  5679. }
  5680. break;
  5681. case "GoForward":
  5682. if (this.pdfHistory) {
  5683. this.pdfHistory.forward();
  5684. }
  5685. break;
  5686. case "NextPage":
  5687. if (this.page < this.pagesCount) {
  5688. this.page++;
  5689. }
  5690. break;
  5691. case "PrevPage":
  5692. if (this.page > 1) {
  5693. this.page--;
  5694. }
  5695. break;
  5696. case "LastPage":
  5697. this.page = this.pagesCount;
  5698. break;
  5699. case "FirstPage":
  5700. this.page = 1;
  5701. break;
  5702. default:
  5703. break;
  5704. }
  5705. this.eventBus.dispatch("namedaction", {
  5706. source: this,
  5707. action
  5708. });
  5709. }
  5710. cachePageRef(pageNum, pageRef) {
  5711. if (!pageRef) {
  5712. return;
  5713. }
  5714. const refStr = pageRef.gen === 0 ? `${pageRef.num}R` : `${pageRef.num}R${pageRef.gen}`;
  5715. this._pagesRefCache[refStr] = pageNum;
  5716. }
  5717. _cachedPageNumber(pageRef) {
  5718. const refStr = pageRef.gen === 0 ? `${pageRef.num}R` : `${pageRef.num}R${pageRef.gen}`;
  5719. return this._pagesRefCache && this._pagesRefCache[refStr] || null;
  5720. }
  5721. isPageVisible(pageNumber) {
  5722. return this.pdfViewer.isPageVisible(pageNumber);
  5723. }
  5724. }
  5725. exports.PDFLinkService = PDFLinkService;
  5726. function isValidExplicitDestination(dest) {
  5727. if (!Array.isArray(dest)) {
  5728. return false;
  5729. }
  5730. const destLength = dest.length;
  5731. if (destLength < 2) {
  5732. return false;
  5733. }
  5734. const page = dest[0];
  5735. if (!(typeof page === "object" && Number.isInteger(page.num) && Number.isInteger(page.gen)) && !(Number.isInteger(page) && page >= 0)) {
  5736. return false;
  5737. }
  5738. const zoom = dest[1];
  5739. if (!(typeof zoom === "object" && typeof zoom.name === "string")) {
  5740. return false;
  5741. }
  5742. let allowNull = true;
  5743. switch (zoom.name) {
  5744. case "XYZ":
  5745. if (destLength !== 5) {
  5746. return false;
  5747. }
  5748. break;
  5749. case "Fit":
  5750. case "FitB":
  5751. return destLength === 2;
  5752. case "FitH":
  5753. case "FitBH":
  5754. case "FitV":
  5755. case "FitBV":
  5756. if (destLength !== 3) {
  5757. return false;
  5758. }
  5759. break;
  5760. case "FitR":
  5761. if (destLength !== 6) {
  5762. return false;
  5763. }
  5764. allowNull = false;
  5765. break;
  5766. default:
  5767. return false;
  5768. }
  5769. for (let i = 2; i < destLength; i++) {
  5770. const param = dest[i];
  5771. if (!(typeof param === "number" || allowNull && param === null)) {
  5772. return false;
  5773. }
  5774. }
  5775. return true;
  5776. }
  5777. class SimpleLinkService {
  5778. constructor() {
  5779. this.externalLinkTarget = null;
  5780. this.externalLinkRel = null;
  5781. this.externalLinkEnabled = true;
  5782. this._ignoreDestinationZoom = false;
  5783. }
  5784. get pagesCount() {
  5785. return 0;
  5786. }
  5787. get page() {
  5788. return 0;
  5789. }
  5790. set page(value) {}
  5791. get rotation() {
  5792. return 0;
  5793. }
  5794. set rotation(value) {}
  5795. navigateTo(dest) {}
  5796. getDestinationHash(dest) {
  5797. return "#";
  5798. }
  5799. getAnchorUrl(hash) {
  5800. return "#";
  5801. }
  5802. setHash(hash) {}
  5803. executeNamedAction(action) {}
  5804. cachePageRef(pageNum, pageRef) {}
  5805. isPageVisible(pageNumber) {
  5806. return true;
  5807. }
  5808. }
  5809. exports.SimpleLinkService = SimpleLinkService;
  5810. /***/ }),
  5811. /* 19 */
  5812. /***/ (function(module, exports, __webpack_require__) {
  5813. "use strict";
  5814. Object.defineProperty(exports, "__esModule", {
  5815. value: true
  5816. });
  5817. exports.PDFOutlineViewer = void 0;
  5818. var _pdfjsLib = __webpack_require__(4);
  5819. const DEFAULT_TITLE = "\u2013";
  5820. class PDFOutlineViewer {
  5821. constructor({
  5822. container,
  5823. linkService,
  5824. eventBus
  5825. }) {
  5826. this.container = container;
  5827. this.linkService = linkService;
  5828. this.eventBus = eventBus;
  5829. this.reset();
  5830. eventBus._on("toggleoutlinetree", this.toggleOutlineTree.bind(this));
  5831. }
  5832. reset() {
  5833. this.outline = null;
  5834. this.lastToggleIsShow = true;
  5835. this.container.textContent = "";
  5836. this.container.classList.remove("outlineWithDeepNesting");
  5837. }
  5838. _dispatchEvent(outlineCount) {
  5839. this.eventBus.dispatch("outlineloaded", {
  5840. source: this,
  5841. outlineCount
  5842. });
  5843. }
  5844. _bindLink(element, {
  5845. url,
  5846. newWindow,
  5847. dest
  5848. }) {
  5849. const {
  5850. linkService
  5851. } = this;
  5852. if (url) {
  5853. (0, _pdfjsLib.addLinkAttributes)(element, {
  5854. url,
  5855. target: newWindow ? _pdfjsLib.LinkTarget.BLANK : linkService.externalLinkTarget,
  5856. rel: linkService.externalLinkRel,
  5857. enabled: linkService.externalLinkEnabled
  5858. });
  5859. return;
  5860. }
  5861. element.href = linkService.getDestinationHash(dest);
  5862. element.onclick = () => {
  5863. if (dest) {
  5864. linkService.navigateTo(dest);
  5865. }
  5866. return false;
  5867. };
  5868. }
  5869. _setStyles(element, {
  5870. bold,
  5871. italic
  5872. }) {
  5873. if (bold) {
  5874. element.style.fontWeight = "bold";
  5875. }
  5876. if (italic) {
  5877. element.style.fontStyle = "italic";
  5878. }
  5879. }
  5880. _addToggleButton(div, {
  5881. count,
  5882. items
  5883. }) {
  5884. const toggler = document.createElement("div");
  5885. toggler.className = "outlineItemToggler";
  5886. if (count < 0 && Math.abs(count) === items.length) {
  5887. toggler.classList.add("outlineItemsHidden");
  5888. }
  5889. toggler.onclick = evt => {
  5890. evt.stopPropagation();
  5891. toggler.classList.toggle("outlineItemsHidden");
  5892. if (evt.shiftKey) {
  5893. const shouldShowAll = !toggler.classList.contains("outlineItemsHidden");
  5894. this._toggleOutlineItem(div, shouldShowAll);
  5895. }
  5896. };
  5897. div.insertBefore(toggler, div.firstChild);
  5898. }
  5899. _toggleOutlineItem(root, show = false) {
  5900. this.lastToggleIsShow = show;
  5901. for (const toggler of root.querySelectorAll(".outlineItemToggler")) {
  5902. toggler.classList.toggle("outlineItemsHidden", !show);
  5903. }
  5904. }
  5905. toggleOutlineTree() {
  5906. if (!this.outline) {
  5907. return;
  5908. }
  5909. this._toggleOutlineItem(this.container, !this.lastToggleIsShow);
  5910. }
  5911. render({
  5912. outline
  5913. }) {
  5914. let outlineCount = 0;
  5915. if (this.outline) {
  5916. this.reset();
  5917. }
  5918. this.outline = outline || null;
  5919. if (!outline) {
  5920. this._dispatchEvent(outlineCount);
  5921. return;
  5922. }
  5923. const fragment = document.createDocumentFragment();
  5924. const queue = [{
  5925. parent: fragment,
  5926. items: this.outline
  5927. }];
  5928. let hasAnyNesting = false;
  5929. while (queue.length > 0) {
  5930. const levelData = queue.shift();
  5931. for (const item of levelData.items) {
  5932. const div = document.createElement("div");
  5933. div.className = "outlineItem";
  5934. const element = document.createElement("a");
  5935. this._bindLink(element, item);
  5936. this._setStyles(element, item);
  5937. element.textContent = (0, _pdfjsLib.removeNullCharacters)(item.title) || DEFAULT_TITLE;
  5938. div.appendChild(element);
  5939. if (item.items.length > 0) {
  5940. hasAnyNesting = true;
  5941. this._addToggleButton(div, item);
  5942. const itemsDiv = document.createElement("div");
  5943. itemsDiv.className = "outlineItems";
  5944. div.appendChild(itemsDiv);
  5945. queue.push({
  5946. parent: itemsDiv,
  5947. items: item.items
  5948. });
  5949. }
  5950. levelData.parent.appendChild(div);
  5951. outlineCount++;
  5952. }
  5953. }
  5954. if (hasAnyNesting) {
  5955. this.container.classList.add("outlineWithDeepNesting");
  5956. this.lastToggleIsShow = fragment.querySelectorAll(".outlineItemsHidden").length === 0;
  5957. }
  5958. this.container.appendChild(fragment);
  5959. this._dispatchEvent(outlineCount);
  5960. }
  5961. }
  5962. exports.PDFOutlineViewer = PDFOutlineViewer;
  5963. /***/ }),
  5964. /* 20 */
  5965. /***/ (function(module, exports, __webpack_require__) {
  5966. "use strict";
  5967. Object.defineProperty(exports, "__esModule", {
  5968. value: true
  5969. });
  5970. exports.PDFPresentationMode = void 0;
  5971. var _ui_utils = __webpack_require__(2);
  5972. const DELAY_BEFORE_RESETTING_SWITCH_IN_PROGRESS = 1500;
  5973. const DELAY_BEFORE_HIDING_CONTROLS = 3000;
  5974. const ACTIVE_SELECTOR = "pdfPresentationMode";
  5975. const CONTROLS_SELECTOR = "pdfPresentationModeControls";
  5976. const MOUSE_SCROLL_COOLDOWN_TIME = 50;
  5977. const PAGE_SWITCH_THRESHOLD = 0.1;
  5978. const SWIPE_MIN_DISTANCE_THRESHOLD = 50;
  5979. const SWIPE_ANGLE_THRESHOLD = Math.PI / 6;
  5980. class PDFPresentationMode {
  5981. constructor({
  5982. container,
  5983. pdfViewer,
  5984. eventBus,
  5985. contextMenuItems = null
  5986. }) {
  5987. this.container = container;
  5988. this.pdfViewer = pdfViewer;
  5989. this.eventBus = eventBus;
  5990. this.active = false;
  5991. this.args = null;
  5992. this.contextMenuOpen = false;
  5993. this.mouseScrollTimeStamp = 0;
  5994. this.mouseScrollDelta = 0;
  5995. this.touchSwipeState = null;
  5996. if (contextMenuItems) {
  5997. contextMenuItems.contextFirstPage.addEventListener("click", () => {
  5998. this.contextMenuOpen = false;
  5999. this.eventBus.dispatch("firstpage", {
  6000. source: this
  6001. });
  6002. });
  6003. contextMenuItems.contextLastPage.addEventListener("click", () => {
  6004. this.contextMenuOpen = false;
  6005. this.eventBus.dispatch("lastpage", {
  6006. source: this
  6007. });
  6008. });
  6009. contextMenuItems.contextPageRotateCw.addEventListener("click", () => {
  6010. this.contextMenuOpen = false;
  6011. this.eventBus.dispatch("rotatecw", {
  6012. source: this
  6013. });
  6014. });
  6015. contextMenuItems.contextPageRotateCcw.addEventListener("click", () => {
  6016. this.contextMenuOpen = false;
  6017. this.eventBus.dispatch("rotateccw", {
  6018. source: this
  6019. });
  6020. });
  6021. }
  6022. }
  6023. request() {
  6024. if (this.switchInProgress || this.active || !this.pdfViewer.pagesCount) {
  6025. return false;
  6026. }
  6027. this._addFullscreenChangeListeners();
  6028. this._setSwitchInProgress();
  6029. this._notifyStateChange();
  6030. if (this.container.requestFullscreen) {
  6031. this.container.requestFullscreen();
  6032. } else if (this.container.mozRequestFullScreen) {
  6033. this.container.mozRequestFullScreen();
  6034. } else if (this.container.webkitRequestFullscreen) {
  6035. this.container.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
  6036. } else if (this.container.msRequestFullscreen) {
  6037. this.container.msRequestFullscreen();
  6038. } else {
  6039. return false;
  6040. }
  6041. this.args = {
  6042. page: this.pdfViewer.currentPageNumber,
  6043. previousScale: this.pdfViewer.currentScaleValue
  6044. };
  6045. return true;
  6046. }
  6047. _mouseWheel(evt) {
  6048. if (!this.active) {
  6049. return;
  6050. }
  6051. evt.preventDefault();
  6052. const delta = (0, _ui_utils.normalizeWheelEventDelta)(evt);
  6053. const currentTime = new Date().getTime();
  6054. const storedTime = this.mouseScrollTimeStamp;
  6055. if (currentTime > storedTime && currentTime - storedTime < MOUSE_SCROLL_COOLDOWN_TIME) {
  6056. return;
  6057. }
  6058. if (this.mouseScrollDelta > 0 && delta < 0 || this.mouseScrollDelta < 0 && delta > 0) {
  6059. this._resetMouseScrollState();
  6060. }
  6061. this.mouseScrollDelta += delta;
  6062. if (Math.abs(this.mouseScrollDelta) >= PAGE_SWITCH_THRESHOLD) {
  6063. const totalDelta = this.mouseScrollDelta;
  6064. this._resetMouseScrollState();
  6065. const success = totalDelta > 0 ? this._goToPreviousPage() : this._goToNextPage();
  6066. if (success) {
  6067. this.mouseScrollTimeStamp = currentTime;
  6068. }
  6069. }
  6070. }
  6071. get isFullscreen() {
  6072. return !!(document.fullscreenElement || document.mozFullScreen || document.webkitIsFullScreen || document.msFullscreenElement);
  6073. }
  6074. _goToPreviousPage() {
  6075. const page = this.pdfViewer.currentPageNumber;
  6076. if (page <= 1) {
  6077. return false;
  6078. }
  6079. this.pdfViewer.currentPageNumber = page - 1;
  6080. return true;
  6081. }
  6082. _goToNextPage() {
  6083. const page = this.pdfViewer.currentPageNumber;
  6084. if (page >= this.pdfViewer.pagesCount) {
  6085. return false;
  6086. }
  6087. this.pdfViewer.currentPageNumber = page + 1;
  6088. return true;
  6089. }
  6090. _notifyStateChange() {
  6091. this.eventBus.dispatch("presentationmodechanged", {
  6092. source: this,
  6093. active: this.active,
  6094. switchInProgress: !!this.switchInProgress
  6095. });
  6096. }
  6097. _setSwitchInProgress() {
  6098. if (this.switchInProgress) {
  6099. clearTimeout(this.switchInProgress);
  6100. }
  6101. this.switchInProgress = setTimeout(() => {
  6102. this._removeFullscreenChangeListeners();
  6103. delete this.switchInProgress;
  6104. this._notifyStateChange();
  6105. }, DELAY_BEFORE_RESETTING_SWITCH_IN_PROGRESS);
  6106. }
  6107. _resetSwitchInProgress() {
  6108. if (this.switchInProgress) {
  6109. clearTimeout(this.switchInProgress);
  6110. delete this.switchInProgress;
  6111. }
  6112. }
  6113. _enter() {
  6114. this.active = true;
  6115. this._resetSwitchInProgress();
  6116. this._notifyStateChange();
  6117. this.container.classList.add(ACTIVE_SELECTOR);
  6118. setTimeout(() => {
  6119. this.pdfViewer.currentPageNumber = this.args.page;
  6120. this.pdfViewer.currentScaleValue = "page-fit";
  6121. }, 0);
  6122. this._addWindowListeners();
  6123. this._showControls();
  6124. this.contextMenuOpen = false;
  6125. this.container.setAttribute("contextmenu", "viewerContextMenu");
  6126. window.getSelection().removeAllRanges();
  6127. }
  6128. _exit() {
  6129. const page = this.pdfViewer.currentPageNumber;
  6130. this.container.classList.remove(ACTIVE_SELECTOR);
  6131. setTimeout(() => {
  6132. this.active = false;
  6133. this._removeFullscreenChangeListeners();
  6134. this._notifyStateChange();
  6135. this.pdfViewer.currentScaleValue = this.args.previousScale;
  6136. this.pdfViewer.currentPageNumber = page;
  6137. this.args = null;
  6138. }, 0);
  6139. this._removeWindowListeners();
  6140. this._hideControls();
  6141. this._resetMouseScrollState();
  6142. this.container.removeAttribute("contextmenu");
  6143. this.contextMenuOpen = false;
  6144. }
  6145. _mouseDown(evt) {
  6146. if (this.contextMenuOpen) {
  6147. this.contextMenuOpen = false;
  6148. evt.preventDefault();
  6149. return;
  6150. }
  6151. if (evt.button === 0) {
  6152. const isInternalLink = evt.target.href && evt.target.classList.contains("internalLink");
  6153. if (!isInternalLink) {
  6154. evt.preventDefault();
  6155. if (evt.shiftKey) {
  6156. this._goToPreviousPage();
  6157. } else {
  6158. this._goToNextPage();
  6159. }
  6160. }
  6161. }
  6162. }
  6163. _contextMenu() {
  6164. this.contextMenuOpen = true;
  6165. }
  6166. _showControls() {
  6167. if (this.controlsTimeout) {
  6168. clearTimeout(this.controlsTimeout);
  6169. } else {
  6170. this.container.classList.add(CONTROLS_SELECTOR);
  6171. }
  6172. this.controlsTimeout = setTimeout(() => {
  6173. this.container.classList.remove(CONTROLS_SELECTOR);
  6174. delete this.controlsTimeout;
  6175. }, DELAY_BEFORE_HIDING_CONTROLS);
  6176. }
  6177. _hideControls() {
  6178. if (!this.controlsTimeout) {
  6179. return;
  6180. }
  6181. clearTimeout(this.controlsTimeout);
  6182. this.container.classList.remove(CONTROLS_SELECTOR);
  6183. delete this.controlsTimeout;
  6184. }
  6185. _resetMouseScrollState() {
  6186. this.mouseScrollTimeStamp = 0;
  6187. this.mouseScrollDelta = 0;
  6188. }
  6189. _touchSwipe(evt) {
  6190. if (!this.active) {
  6191. return;
  6192. }
  6193. if (evt.touches.length > 1) {
  6194. this.touchSwipeState = null;
  6195. return;
  6196. }
  6197. switch (evt.type) {
  6198. case "touchstart":
  6199. this.touchSwipeState = {
  6200. startX: evt.touches[0].pageX,
  6201. startY: evt.touches[0].pageY,
  6202. endX: evt.touches[0].pageX,
  6203. endY: evt.touches[0].pageY
  6204. };
  6205. break;
  6206. case "touchmove":
  6207. if (this.touchSwipeState === null) {
  6208. return;
  6209. }
  6210. this.touchSwipeState.endX = evt.touches[0].pageX;
  6211. this.touchSwipeState.endY = evt.touches[0].pageY;
  6212. evt.preventDefault();
  6213. break;
  6214. case "touchend":
  6215. if (this.touchSwipeState === null) {
  6216. return;
  6217. }
  6218. let delta = 0;
  6219. const dx = this.touchSwipeState.endX - this.touchSwipeState.startX;
  6220. const dy = this.touchSwipeState.endY - this.touchSwipeState.startY;
  6221. const absAngle = Math.abs(Math.atan2(dy, dx));
  6222. if (Math.abs(dx) > SWIPE_MIN_DISTANCE_THRESHOLD && (absAngle <= SWIPE_ANGLE_THRESHOLD || absAngle >= Math.PI - SWIPE_ANGLE_THRESHOLD)) {
  6223. delta = dx;
  6224. } else if (Math.abs(dy) > SWIPE_MIN_DISTANCE_THRESHOLD && Math.abs(absAngle - Math.PI / 2) <= SWIPE_ANGLE_THRESHOLD) {
  6225. delta = dy;
  6226. }
  6227. if (delta > 0) {
  6228. this._goToPreviousPage();
  6229. } else if (delta < 0) {
  6230. this._goToNextPage();
  6231. }
  6232. break;
  6233. }
  6234. }
  6235. _addWindowListeners() {
  6236. this.showControlsBind = this._showControls.bind(this);
  6237. this.mouseDownBind = this._mouseDown.bind(this);
  6238. this.mouseWheelBind = this._mouseWheel.bind(this);
  6239. this.resetMouseScrollStateBind = this._resetMouseScrollState.bind(this);
  6240. this.contextMenuBind = this._contextMenu.bind(this);
  6241. this.touchSwipeBind = this._touchSwipe.bind(this);
  6242. window.addEventListener("mousemove", this.showControlsBind);
  6243. window.addEventListener("mousedown", this.mouseDownBind);
  6244. window.addEventListener("wheel", this.mouseWheelBind);
  6245. window.addEventListener("keydown", this.resetMouseScrollStateBind);
  6246. window.addEventListener("contextmenu", this.contextMenuBind);
  6247. window.addEventListener("touchstart", this.touchSwipeBind);
  6248. window.addEventListener("touchmove", this.touchSwipeBind);
  6249. window.addEventListener("touchend", this.touchSwipeBind);
  6250. }
  6251. _removeWindowListeners() {
  6252. window.removeEventListener("mousemove", this.showControlsBind);
  6253. window.removeEventListener("mousedown", this.mouseDownBind);
  6254. window.removeEventListener("wheel", this.mouseWheelBind);
  6255. window.removeEventListener("keydown", this.resetMouseScrollStateBind);
  6256. window.removeEventListener("contextmenu", this.contextMenuBind);
  6257. window.removeEventListener("touchstart", this.touchSwipeBind);
  6258. window.removeEventListener("touchmove", this.touchSwipeBind);
  6259. window.removeEventListener("touchend", this.touchSwipeBind);
  6260. delete this.showControlsBind;
  6261. delete this.mouseDownBind;
  6262. delete this.mouseWheelBind;
  6263. delete this.resetMouseScrollStateBind;
  6264. delete this.contextMenuBind;
  6265. delete this.touchSwipeBind;
  6266. }
  6267. _fullscreenChange() {
  6268. if (this.isFullscreen) {
  6269. this._enter();
  6270. } else {
  6271. this._exit();
  6272. }
  6273. }
  6274. _addFullscreenChangeListeners() {
  6275. this.fullscreenChangeBind = this._fullscreenChange.bind(this);
  6276. window.addEventListener("fullscreenchange", this.fullscreenChangeBind);
  6277. window.addEventListener("mozfullscreenchange", this.fullscreenChangeBind);
  6278. window.addEventListener("webkitfullscreenchange", this.fullscreenChangeBind);
  6279. window.addEventListener("MSFullscreenChange", this.fullscreenChangeBind);
  6280. }
  6281. _removeFullscreenChangeListeners() {
  6282. window.removeEventListener("fullscreenchange", this.fullscreenChangeBind);
  6283. window.removeEventListener("mozfullscreenchange", this.fullscreenChangeBind);
  6284. window.removeEventListener("webkitfullscreenchange", this.fullscreenChangeBind);
  6285. window.removeEventListener("MSFullscreenChange", this.fullscreenChangeBind);
  6286. delete this.fullscreenChangeBind;
  6287. }
  6288. }
  6289. exports.PDFPresentationMode = PDFPresentationMode;
  6290. /***/ }),
  6291. /* 21 */
  6292. /***/ (function(module, exports, __webpack_require__) {
  6293. "use strict";
  6294. Object.defineProperty(exports, "__esModule", {
  6295. value: true
  6296. });
  6297. exports.PDFSidebarResizer = void 0;
  6298. var _ui_utils = __webpack_require__(2);
  6299. const SIDEBAR_WIDTH_VAR = "--sidebar-width";
  6300. const SIDEBAR_MIN_WIDTH = 200;
  6301. const SIDEBAR_RESIZING_CLASS = "sidebarResizing";
  6302. class PDFSidebarResizer {
  6303. constructor(options, eventBus, l10n = _ui_utils.NullL10n) {
  6304. this.enabled = false;
  6305. this.isRTL = false;
  6306. this.sidebarOpen = false;
  6307. this.doc = document.documentElement;
  6308. this._width = null;
  6309. this._outerContainerWidth = null;
  6310. this._boundEvents = Object.create(null);
  6311. this.outerContainer = options.outerContainer;
  6312. this.resizer = options.resizer;
  6313. this.eventBus = eventBus;
  6314. this.l10n = l10n;
  6315. if (typeof CSS === "undefined" || typeof CSS.supports !== "function" || !CSS.supports(SIDEBAR_WIDTH_VAR, `calc(-1 * ${SIDEBAR_MIN_WIDTH}px)`)) {
  6316. console.warn("PDFSidebarResizer: " + "The browser does not support resizing of the sidebar.");
  6317. return;
  6318. }
  6319. this.enabled = true;
  6320. this.resizer.classList.remove("hidden");
  6321. this.l10n.getDirection().then(dir => {
  6322. this.isRTL = dir === "rtl";
  6323. });
  6324. this._addEventListeners();
  6325. }
  6326. get outerContainerWidth() {
  6327. if (!this._outerContainerWidth) {
  6328. this._outerContainerWidth = this.outerContainer.clientWidth;
  6329. }
  6330. return this._outerContainerWidth;
  6331. }
  6332. _updateWidth(width = 0) {
  6333. if (!this.enabled) {
  6334. return false;
  6335. }
  6336. const newWidth = (0, _ui_utils.clamp)(width, SIDEBAR_MIN_WIDTH, Math.floor(this.outerContainerWidth / 2));
  6337. if (newWidth === this._width) {
  6338. return false;
  6339. }
  6340. this._width = newWidth;
  6341. this.doc.style.setProperty(SIDEBAR_WIDTH_VAR, `${newWidth}px`);
  6342. return true;
  6343. }
  6344. _mouseMove(evt) {
  6345. let width = evt.clientX;
  6346. if (this.isRTL) {
  6347. width = this.outerContainerWidth - width;
  6348. }
  6349. this._updateWidth(width);
  6350. }
  6351. _mouseUp(evt) {
  6352. this.outerContainer.classList.remove(SIDEBAR_RESIZING_CLASS);
  6353. this.eventBus.dispatch("resize", {
  6354. source: this
  6355. });
  6356. const _boundEvents = this._boundEvents;
  6357. window.removeEventListener("mousemove", _boundEvents.mouseMove);
  6358. window.removeEventListener("mouseup", _boundEvents.mouseUp);
  6359. }
  6360. _addEventListeners() {
  6361. if (!this.enabled) {
  6362. return;
  6363. }
  6364. const _boundEvents = this._boundEvents;
  6365. _boundEvents.mouseMove = this._mouseMove.bind(this);
  6366. _boundEvents.mouseUp = this._mouseUp.bind(this);
  6367. this.resizer.addEventListener("mousedown", evt => {
  6368. if (evt.button !== 0) {
  6369. return;
  6370. }
  6371. this.outerContainer.classList.add(SIDEBAR_RESIZING_CLASS);
  6372. window.addEventListener("mousemove", _boundEvents.mouseMove);
  6373. window.addEventListener("mouseup", _boundEvents.mouseUp);
  6374. });
  6375. this.eventBus._on("sidebarviewchanged", evt => {
  6376. this.sidebarOpen = !!(evt && evt.view);
  6377. });
  6378. this.eventBus._on("resize", evt => {
  6379. if (!evt || evt.source !== window) {
  6380. return;
  6381. }
  6382. this._outerContainerWidth = null;
  6383. if (!this._width) {
  6384. return;
  6385. }
  6386. if (!this.sidebarOpen) {
  6387. this._updateWidth(this._width);
  6388. return;
  6389. }
  6390. this.outerContainer.classList.add(SIDEBAR_RESIZING_CLASS);
  6391. const updated = this._updateWidth(this._width);
  6392. Promise.resolve().then(() => {
  6393. this.outerContainer.classList.remove(SIDEBAR_RESIZING_CLASS);
  6394. if (updated) {
  6395. this.eventBus.dispatch("resize", {
  6396. source: this
  6397. });
  6398. }
  6399. });
  6400. });
  6401. }
  6402. }
  6403. exports.PDFSidebarResizer = PDFSidebarResizer;
  6404. /***/ }),
  6405. /* 22 */
  6406. /***/ (function(module, exports, __webpack_require__) {
  6407. "use strict";
  6408. Object.defineProperty(exports, "__esModule", {
  6409. value: true
  6410. });
  6411. exports.PDFThumbnailViewer = void 0;
  6412. var _ui_utils = __webpack_require__(2);
  6413. var _pdf_thumbnail_view = __webpack_require__(23);
  6414. const THUMBNAIL_SCROLL_MARGIN = -19;
  6415. const THUMBNAIL_SELECTED_CLASS = "selected";
  6416. class PDFThumbnailViewer {
  6417. constructor({
  6418. container,
  6419. linkService,
  6420. renderingQueue,
  6421. l10n = _ui_utils.NullL10n
  6422. }) {
  6423. this.container = container;
  6424. this.linkService = linkService;
  6425. this.renderingQueue = renderingQueue;
  6426. this.l10n = l10n;
  6427. this.scroll = (0, _ui_utils.watchScroll)(this.container, this._scrollUpdated.bind(this));
  6428. this._resetView();
  6429. }
  6430. _scrollUpdated() {
  6431. this.renderingQueue.renderHighestPriority();
  6432. }
  6433. getThumbnail(index) {
  6434. return this._thumbnails[index];
  6435. }
  6436. _getVisibleThumbs() {
  6437. return (0, _ui_utils.getVisibleElements)(this.container, this._thumbnails);
  6438. }
  6439. scrollThumbnailIntoView(pageNumber) {
  6440. if (!this.pdfDocument) {
  6441. return;
  6442. }
  6443. const thumbnailView = this._thumbnails[pageNumber - 1];
  6444. if (!thumbnailView) {
  6445. console.error('scrollThumbnailIntoView: Invalid "pageNumber" parameter.');
  6446. return;
  6447. }
  6448. if (pageNumber !== this._currentPageNumber) {
  6449. const prevThumbnailView = this._thumbnails[this._currentPageNumber - 1];
  6450. prevThumbnailView.div.classList.remove(THUMBNAIL_SELECTED_CLASS);
  6451. thumbnailView.div.classList.add(THUMBNAIL_SELECTED_CLASS);
  6452. }
  6453. const visibleThumbs = this._getVisibleThumbs();
  6454. const numVisibleThumbs = visibleThumbs.views.length;
  6455. if (numVisibleThumbs > 0) {
  6456. const first = visibleThumbs.first.id;
  6457. const last = numVisibleThumbs > 1 ? visibleThumbs.last.id : first;
  6458. let shouldScroll = false;
  6459. if (pageNumber <= first || pageNumber >= last) {
  6460. shouldScroll = true;
  6461. } else {
  6462. visibleThumbs.views.some(function (view) {
  6463. if (view.id !== pageNumber) {
  6464. return false;
  6465. }
  6466. shouldScroll = view.percent < 100;
  6467. return true;
  6468. });
  6469. }
  6470. if (shouldScroll) {
  6471. (0, _ui_utils.scrollIntoView)(thumbnailView.div, {
  6472. top: THUMBNAIL_SCROLL_MARGIN
  6473. });
  6474. }
  6475. }
  6476. this._currentPageNumber = pageNumber;
  6477. }
  6478. get pagesRotation() {
  6479. return this._pagesRotation;
  6480. }
  6481. set pagesRotation(rotation) {
  6482. if (!(0, _ui_utils.isValidRotation)(rotation)) {
  6483. throw new Error("Invalid thumbnails rotation angle.");
  6484. }
  6485. if (!this.pdfDocument) {
  6486. return;
  6487. }
  6488. if (this._pagesRotation === rotation) {
  6489. return;
  6490. }
  6491. this._pagesRotation = rotation;
  6492. for (let i = 0, ii = this._thumbnails.length; i < ii; i++) {
  6493. this._thumbnails[i].update(rotation);
  6494. }
  6495. }
  6496. cleanup() {
  6497. _pdf_thumbnail_view.PDFThumbnailView.cleanup();
  6498. }
  6499. _resetView() {
  6500. this._thumbnails = [];
  6501. this._currentPageNumber = 1;
  6502. this._pageLabels = null;
  6503. this._pagesRotation = 0;
  6504. this._pagesRequests = new WeakMap();
  6505. this.container.textContent = "";
  6506. }
  6507. setDocument(pdfDocument) {
  6508. if (this.pdfDocument) {
  6509. this._cancelRendering();
  6510. this._resetView();
  6511. }
  6512. this.pdfDocument = pdfDocument;
  6513. if (!pdfDocument) {
  6514. return;
  6515. }
  6516. pdfDocument.getPage(1).then(firstPdfPage => {
  6517. const pagesCount = pdfDocument.numPages;
  6518. const viewport = firstPdfPage.getViewport({
  6519. scale: 1
  6520. });
  6521. for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) {
  6522. const thumbnail = new _pdf_thumbnail_view.PDFThumbnailView({
  6523. container: this.container,
  6524. id: pageNum,
  6525. defaultViewport: viewport.clone(),
  6526. linkService: this.linkService,
  6527. renderingQueue: this.renderingQueue,
  6528. disableCanvasToImageConversion: false,
  6529. l10n: this.l10n
  6530. });
  6531. this._thumbnails.push(thumbnail);
  6532. }
  6533. const firstThumbnailView = this._thumbnails[0];
  6534. if (firstThumbnailView) {
  6535. firstThumbnailView.setPdfPage(firstPdfPage);
  6536. }
  6537. const thumbnailView = this._thumbnails[this._currentPageNumber - 1];
  6538. thumbnailView.div.classList.add(THUMBNAIL_SELECTED_CLASS);
  6539. }).catch(reason => {
  6540. console.error("Unable to initialize thumbnail viewer", reason);
  6541. });
  6542. }
  6543. _cancelRendering() {
  6544. for (let i = 0, ii = this._thumbnails.length; i < ii; i++) {
  6545. if (this._thumbnails[i]) {
  6546. this._thumbnails[i].cancelRendering();
  6547. }
  6548. }
  6549. }
  6550. setPageLabels(labels) {
  6551. if (!this.pdfDocument) {
  6552. return;
  6553. }
  6554. if (!labels) {
  6555. this._pageLabels = null;
  6556. } else if (!(Array.isArray(labels) && this.pdfDocument.numPages === labels.length)) {
  6557. this._pageLabels = null;
  6558. console.error("PDFThumbnailViewer_setPageLabels: Invalid page labels.");
  6559. } else {
  6560. this._pageLabels = labels;
  6561. }
  6562. for (let i = 0, ii = this._thumbnails.length; i < ii; i++) {
  6563. const label = this._pageLabels && this._pageLabels[i];
  6564. this._thumbnails[i].setPageLabel(label);
  6565. }
  6566. }
  6567. _ensurePdfPageLoaded(thumbView) {
  6568. if (thumbView.pdfPage) {
  6569. return Promise.resolve(thumbView.pdfPage);
  6570. }
  6571. if (this._pagesRequests.has(thumbView)) {
  6572. return this._pagesRequests.get(thumbView);
  6573. }
  6574. const promise = this.pdfDocument.getPage(thumbView.id).then(pdfPage => {
  6575. if (!thumbView.pdfPage) {
  6576. thumbView.setPdfPage(pdfPage);
  6577. }
  6578. this._pagesRequests.delete(thumbView);
  6579. return pdfPage;
  6580. }).catch(reason => {
  6581. console.error("Unable to get page for thumb view", reason);
  6582. this._pagesRequests.delete(thumbView);
  6583. });
  6584. this._pagesRequests.set(thumbView, promise);
  6585. return promise;
  6586. }
  6587. forceRendering() {
  6588. const visibleThumbs = this._getVisibleThumbs();
  6589. const thumbView = this.renderingQueue.getHighestPriority(visibleThumbs, this._thumbnails, this.scroll.down);
  6590. if (thumbView) {
  6591. this._ensurePdfPageLoaded(thumbView).then(() => {
  6592. this.renderingQueue.renderView(thumbView);
  6593. });
  6594. return true;
  6595. }
  6596. return false;
  6597. }
  6598. }
  6599. exports.PDFThumbnailViewer = PDFThumbnailViewer;
  6600. /***/ }),
  6601. /* 23 */
  6602. /***/ (function(module, exports, __webpack_require__) {
  6603. "use strict";
  6604. Object.defineProperty(exports, "__esModule", {
  6605. value: true
  6606. });
  6607. exports.PDFThumbnailView = void 0;
  6608. var _pdfjsLib = __webpack_require__(4);
  6609. var _ui_utils = __webpack_require__(2);
  6610. var _pdf_rendering_queue = __webpack_require__(8);
  6611. const MAX_NUM_SCALING_STEPS = 3;
  6612. const THUMBNAIL_CANVAS_BORDER_WIDTH = 1;
  6613. const THUMBNAIL_WIDTH = 98;
  6614. const TempImageFactory = function TempImageFactoryClosure() {
  6615. let tempCanvasCache = null;
  6616. return {
  6617. getCanvas(width, height) {
  6618. let tempCanvas = tempCanvasCache;
  6619. if (!tempCanvas) {
  6620. tempCanvas = document.createElement("canvas");
  6621. tempCanvasCache = tempCanvas;
  6622. }
  6623. tempCanvas.width = width;
  6624. tempCanvas.height = height;
  6625. tempCanvas.mozOpaque = true;
  6626. const ctx = tempCanvas.getContext("2d", {
  6627. alpha: false
  6628. });
  6629. ctx.save();
  6630. ctx.fillStyle = "rgb(255, 255, 255)";
  6631. ctx.fillRect(0, 0, width, height);
  6632. ctx.restore();
  6633. return tempCanvas;
  6634. },
  6635. destroyCanvas() {
  6636. const tempCanvas = tempCanvasCache;
  6637. if (tempCanvas) {
  6638. tempCanvas.width = 0;
  6639. tempCanvas.height = 0;
  6640. }
  6641. tempCanvasCache = null;
  6642. }
  6643. };
  6644. }();
  6645. class PDFThumbnailView {
  6646. constructor({
  6647. container,
  6648. id,
  6649. defaultViewport,
  6650. linkService,
  6651. renderingQueue,
  6652. disableCanvasToImageConversion = false,
  6653. l10n = _ui_utils.NullL10n
  6654. }) {
  6655. this.id = id;
  6656. this.renderingId = "thumbnail" + id;
  6657. this.pageLabel = null;
  6658. this.pdfPage = null;
  6659. this.rotation = 0;
  6660. this.viewport = defaultViewport;
  6661. this.pdfPageRotate = defaultViewport.rotation;
  6662. this.linkService = linkService;
  6663. this.renderingQueue = renderingQueue;
  6664. this.renderTask = null;
  6665. this.renderingState = _pdf_rendering_queue.RenderingStates.INITIAL;
  6666. this.resume = null;
  6667. this.disableCanvasToImageConversion = disableCanvasToImageConversion;
  6668. this.pageWidth = this.viewport.width;
  6669. this.pageHeight = this.viewport.height;
  6670. this.pageRatio = this.pageWidth / this.pageHeight;
  6671. this.canvasWidth = THUMBNAIL_WIDTH;
  6672. this.canvasHeight = this.canvasWidth / this.pageRatio | 0;
  6673. this.scale = this.canvasWidth / this.pageWidth;
  6674. this.l10n = l10n;
  6675. const anchor = document.createElement("a");
  6676. anchor.href = linkService.getAnchorUrl("#page=" + id);
  6677. this._thumbPageTitle.then(msg => {
  6678. anchor.title = msg;
  6679. });
  6680. anchor.onclick = function () {
  6681. linkService.page = id;
  6682. return false;
  6683. };
  6684. this.anchor = anchor;
  6685. const div = document.createElement("div");
  6686. div.className = "thumbnail";
  6687. div.setAttribute("data-page-number", this.id);
  6688. this.div = div;
  6689. const ring = document.createElement("div");
  6690. ring.className = "thumbnailSelectionRing";
  6691. const borderAdjustment = 2 * THUMBNAIL_CANVAS_BORDER_WIDTH;
  6692. ring.style.width = this.canvasWidth + borderAdjustment + "px";
  6693. ring.style.height = this.canvasHeight + borderAdjustment + "px";
  6694. this.ring = ring;
  6695. div.appendChild(ring);
  6696. anchor.appendChild(div);
  6697. container.appendChild(anchor);
  6698. }
  6699. setPdfPage(pdfPage) {
  6700. this.pdfPage = pdfPage;
  6701. this.pdfPageRotate = pdfPage.rotate;
  6702. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  6703. this.viewport = pdfPage.getViewport({
  6704. scale: 1,
  6705. rotation: totalRotation
  6706. });
  6707. this.reset();
  6708. }
  6709. reset() {
  6710. this.cancelRendering();
  6711. this.renderingState = _pdf_rendering_queue.RenderingStates.INITIAL;
  6712. this.pageWidth = this.viewport.width;
  6713. this.pageHeight = this.viewport.height;
  6714. this.pageRatio = this.pageWidth / this.pageHeight;
  6715. this.canvasHeight = this.canvasWidth / this.pageRatio | 0;
  6716. this.scale = this.canvasWidth / this.pageWidth;
  6717. this.div.removeAttribute("data-loaded");
  6718. const ring = this.ring;
  6719. const childNodes = ring.childNodes;
  6720. for (let i = childNodes.length - 1; i >= 0; i--) {
  6721. ring.removeChild(childNodes[i]);
  6722. }
  6723. const borderAdjustment = 2 * THUMBNAIL_CANVAS_BORDER_WIDTH;
  6724. ring.style.width = this.canvasWidth + borderAdjustment + "px";
  6725. ring.style.height = this.canvasHeight + borderAdjustment + "px";
  6726. if (this.canvas) {
  6727. this.canvas.width = 0;
  6728. this.canvas.height = 0;
  6729. delete this.canvas;
  6730. }
  6731. if (this.image) {
  6732. this.image.removeAttribute("src");
  6733. delete this.image;
  6734. }
  6735. }
  6736. update(rotation) {
  6737. if (typeof rotation !== "undefined") {
  6738. this.rotation = rotation;
  6739. }
  6740. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  6741. this.viewport = this.viewport.clone({
  6742. scale: 1,
  6743. rotation: totalRotation
  6744. });
  6745. this.reset();
  6746. }
  6747. cancelRendering() {
  6748. if (this.renderTask) {
  6749. this.renderTask.cancel();
  6750. this.renderTask = null;
  6751. }
  6752. this.resume = null;
  6753. }
  6754. _getPageDrawContext(noCtxScale = false) {
  6755. const canvas = document.createElement("canvas");
  6756. this.canvas = canvas;
  6757. canvas.mozOpaque = true;
  6758. const ctx = canvas.getContext("2d", {
  6759. alpha: false
  6760. });
  6761. const outputScale = (0, _ui_utils.getOutputScale)(ctx);
  6762. canvas.width = this.canvasWidth * outputScale.sx | 0;
  6763. canvas.height = this.canvasHeight * outputScale.sy | 0;
  6764. canvas.style.width = this.canvasWidth + "px";
  6765. canvas.style.height = this.canvasHeight + "px";
  6766. if (!noCtxScale && outputScale.scaled) {
  6767. ctx.scale(outputScale.sx, outputScale.sy);
  6768. }
  6769. return ctx;
  6770. }
  6771. _convertCanvasToImage() {
  6772. if (!this.canvas) {
  6773. return;
  6774. }
  6775. if (this.renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED) {
  6776. return;
  6777. }
  6778. const className = "thumbnailImage";
  6779. if (this.disableCanvasToImageConversion) {
  6780. this.canvas.className = className;
  6781. this._thumbPageCanvas.then(msg => {
  6782. this.canvas.setAttribute("aria-label", msg);
  6783. });
  6784. this.div.setAttribute("data-loaded", true);
  6785. this.ring.appendChild(this.canvas);
  6786. return;
  6787. }
  6788. const image = document.createElement("img");
  6789. image.className = className;
  6790. this._thumbPageCanvas.then(msg => {
  6791. image.setAttribute("aria-label", msg);
  6792. });
  6793. image.style.width = this.canvasWidth + "px";
  6794. image.style.height = this.canvasHeight + "px";
  6795. image.src = this.canvas.toDataURL();
  6796. this.image = image;
  6797. this.div.setAttribute("data-loaded", true);
  6798. this.ring.appendChild(image);
  6799. this.canvas.width = 0;
  6800. this.canvas.height = 0;
  6801. delete this.canvas;
  6802. }
  6803. draw() {
  6804. if (this.renderingState !== _pdf_rendering_queue.RenderingStates.INITIAL) {
  6805. console.error("Must be in new state before drawing");
  6806. return Promise.resolve(undefined);
  6807. }
  6808. const {
  6809. pdfPage
  6810. } = this;
  6811. if (!pdfPage) {
  6812. this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
  6813. return Promise.reject(new Error("pdfPage is not loaded"));
  6814. }
  6815. this.renderingState = _pdf_rendering_queue.RenderingStates.RUNNING;
  6816. const renderCapability = (0, _pdfjsLib.createPromiseCapability)();
  6817. const finishRenderTask = error => {
  6818. if (renderTask === this.renderTask) {
  6819. this.renderTask = null;
  6820. }
  6821. if (error instanceof _pdfjsLib.RenderingCancelledException) {
  6822. renderCapability.resolve(undefined);
  6823. return;
  6824. }
  6825. this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
  6826. this._convertCanvasToImage();
  6827. if (!error) {
  6828. renderCapability.resolve(undefined);
  6829. } else {
  6830. renderCapability.reject(error);
  6831. }
  6832. };
  6833. const ctx = this._getPageDrawContext();
  6834. const drawViewport = this.viewport.clone({
  6835. scale: this.scale
  6836. });
  6837. const renderContinueCallback = cont => {
  6838. if (!this.renderingQueue.isHighestPriority(this)) {
  6839. this.renderingState = _pdf_rendering_queue.RenderingStates.PAUSED;
  6840. this.resume = () => {
  6841. this.renderingState = _pdf_rendering_queue.RenderingStates.RUNNING;
  6842. cont();
  6843. };
  6844. return;
  6845. }
  6846. cont();
  6847. };
  6848. const renderContext = {
  6849. canvasContext: ctx,
  6850. viewport: drawViewport
  6851. };
  6852. const renderTask = this.renderTask = pdfPage.render(renderContext);
  6853. renderTask.onContinue = renderContinueCallback;
  6854. renderTask.promise.then(function () {
  6855. finishRenderTask(null);
  6856. }, function (error) {
  6857. finishRenderTask(error);
  6858. });
  6859. return renderCapability.promise;
  6860. }
  6861. setImage(pageView) {
  6862. if (this.renderingState !== _pdf_rendering_queue.RenderingStates.INITIAL) {
  6863. return;
  6864. }
  6865. const img = pageView.canvas;
  6866. if (!img) {
  6867. return;
  6868. }
  6869. if (!this.pdfPage) {
  6870. this.setPdfPage(pageView.pdfPage);
  6871. }
  6872. this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
  6873. const ctx = this._getPageDrawContext(true);
  6874. const canvas = ctx.canvas;
  6875. if (img.width <= 2 * canvas.width) {
  6876. ctx.drawImage(img, 0, 0, img.width, img.height, 0, 0, canvas.width, canvas.height);
  6877. this._convertCanvasToImage();
  6878. return;
  6879. }
  6880. let reducedWidth = canvas.width << MAX_NUM_SCALING_STEPS;
  6881. let reducedHeight = canvas.height << MAX_NUM_SCALING_STEPS;
  6882. const reducedImage = TempImageFactory.getCanvas(reducedWidth, reducedHeight);
  6883. const reducedImageCtx = reducedImage.getContext("2d");
  6884. while (reducedWidth > img.width || reducedHeight > img.height) {
  6885. reducedWidth >>= 1;
  6886. reducedHeight >>= 1;
  6887. }
  6888. reducedImageCtx.drawImage(img, 0, 0, img.width, img.height, 0, 0, reducedWidth, reducedHeight);
  6889. while (reducedWidth > 2 * canvas.width) {
  6890. reducedImageCtx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, reducedWidth >> 1, reducedHeight >> 1);
  6891. reducedWidth >>= 1;
  6892. reducedHeight >>= 1;
  6893. }
  6894. ctx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, canvas.width, canvas.height);
  6895. this._convertCanvasToImage();
  6896. }
  6897. get _thumbPageTitle() {
  6898. return this.l10n.get("thumb_page_title", {
  6899. page: this.pageLabel !== null ? this.pageLabel : this.id
  6900. }, "Page {{page}}");
  6901. }
  6902. get _thumbPageCanvas() {
  6903. return this.l10n.get("thumb_page_canvas", {
  6904. page: this.pageLabel !== null ? this.pageLabel : this.id
  6905. }, "Thumbnail of Page {{page}}");
  6906. }
  6907. setPageLabel(label) {
  6908. this.pageLabel = typeof label === "string" ? label : null;
  6909. this._thumbPageTitle.then(msg => {
  6910. this.anchor.title = msg;
  6911. });
  6912. if (this.renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED) {
  6913. return;
  6914. }
  6915. this._thumbPageCanvas.then(msg => {
  6916. if (this.image) {
  6917. this.image.setAttribute("aria-label", msg);
  6918. } else if (this.disableCanvasToImageConversion && this.canvas) {
  6919. this.canvas.setAttribute("aria-label", msg);
  6920. }
  6921. });
  6922. }
  6923. static cleanup() {
  6924. TempImageFactory.destroyCanvas();
  6925. }
  6926. }
  6927. exports.PDFThumbnailView = PDFThumbnailView;
  6928. /***/ }),
  6929. /* 24 */
  6930. /***/ (function(module, exports, __webpack_require__) {
  6931. "use strict";
  6932. Object.defineProperty(exports, "__esModule", {
  6933. value: true
  6934. });
  6935. exports.PDFViewer = void 0;
  6936. var _base_viewer = __webpack_require__(25);
  6937. var _pdfjsLib = __webpack_require__(4);
  6938. class PDFViewer extends _base_viewer.BaseViewer {
  6939. get _setDocumentViewerElement() {
  6940. return (0, _pdfjsLib.shadow)(this, "_setDocumentViewerElement", this.viewer);
  6941. }
  6942. _scrollIntoView({
  6943. pageDiv,
  6944. pageSpot = null,
  6945. pageNumber = null
  6946. }) {
  6947. if (!pageSpot && !this.isInPresentationMode) {
  6948. const left = pageDiv.offsetLeft + pageDiv.clientLeft;
  6949. const right = left + pageDiv.clientWidth;
  6950. const {
  6951. scrollLeft,
  6952. clientWidth
  6953. } = this.container;
  6954. if (this._isScrollModeHorizontal || left < scrollLeft || right > scrollLeft + clientWidth) {
  6955. pageSpot = {
  6956. left: 0,
  6957. top: 0
  6958. };
  6959. }
  6960. }
  6961. super._scrollIntoView({
  6962. pageDiv,
  6963. pageSpot,
  6964. pageNumber
  6965. });
  6966. }
  6967. _getVisiblePages() {
  6968. if (this.isInPresentationMode) {
  6969. return this._getCurrentVisiblePage();
  6970. }
  6971. return super._getVisiblePages();
  6972. }
  6973. _updateHelper(visiblePages) {
  6974. if (this.isInPresentationMode) {
  6975. return;
  6976. }
  6977. let currentId = this._currentPageNumber;
  6978. let stillFullyVisible = false;
  6979. for (const page of visiblePages) {
  6980. if (page.percent < 100) {
  6981. break;
  6982. }
  6983. if (page.id === currentId) {
  6984. stillFullyVisible = true;
  6985. break;
  6986. }
  6987. }
  6988. if (!stillFullyVisible) {
  6989. currentId = visiblePages[0].id;
  6990. }
  6991. this._setCurrentPageNumber(currentId);
  6992. }
  6993. }
  6994. exports.PDFViewer = PDFViewer;
  6995. /***/ }),
  6996. /* 25 */
  6997. /***/ (function(module, exports, __webpack_require__) {
  6998. "use strict";
  6999. Object.defineProperty(exports, "__esModule", {
  7000. value: true
  7001. });
  7002. exports.BaseViewer = void 0;
  7003. var _ui_utils = __webpack_require__(2);
  7004. var _pdf_rendering_queue = __webpack_require__(8);
  7005. var _annotation_layer_builder = __webpack_require__(26);
  7006. var _pdfjsLib = __webpack_require__(4);
  7007. var _pdf_page_view = __webpack_require__(27);
  7008. var _pdf_link_service = __webpack_require__(18);
  7009. var _text_layer_builder = __webpack_require__(28);
  7010. const DEFAULT_CACHE_SIZE = 10;
  7011. function PDFPageViewBuffer(size) {
  7012. const data = [];
  7013. this.push = function (view) {
  7014. const i = data.indexOf(view);
  7015. if (i >= 0) {
  7016. data.splice(i, 1);
  7017. }
  7018. data.push(view);
  7019. if (data.length > size) {
  7020. data.shift().destroy();
  7021. }
  7022. };
  7023. this.resize = function (newSize, pagesToKeep) {
  7024. size = newSize;
  7025. if (pagesToKeep) {
  7026. const pageIdsToKeep = new Set();
  7027. for (let i = 0, iMax = pagesToKeep.length; i < iMax; ++i) {
  7028. pageIdsToKeep.add(pagesToKeep[i].id);
  7029. }
  7030. (0, _ui_utils.moveToEndOfArray)(data, function (page) {
  7031. return pageIdsToKeep.has(page.id);
  7032. });
  7033. }
  7034. while (data.length > size) {
  7035. data.shift().destroy();
  7036. }
  7037. };
  7038. }
  7039. function isSameScale(oldScale, newScale) {
  7040. if (newScale === oldScale) {
  7041. return true;
  7042. }
  7043. if (Math.abs(newScale - oldScale) < 1e-15) {
  7044. return true;
  7045. }
  7046. return false;
  7047. }
  7048. class BaseViewer {
  7049. constructor(options) {
  7050. if (this.constructor === BaseViewer) {
  7051. throw new Error("Cannot initialize BaseViewer.");
  7052. }
  7053. this._name = this.constructor.name;
  7054. this.container = options.container;
  7055. this.viewer = options.viewer || options.container.firstElementChild;
  7056. this.eventBus = options.eventBus || (0, _ui_utils.getGlobalEventBus)();
  7057. this.linkService = options.linkService || new _pdf_link_service.SimpleLinkService();
  7058. this.downloadManager = options.downloadManager || null;
  7059. this.findController = options.findController || null;
  7060. this.removePageBorders = options.removePageBorders || false;
  7061. this.textLayerMode = Number.isInteger(options.textLayerMode) ? options.textLayerMode : _ui_utils.TextLayerMode.ENABLE;
  7062. this.imageResourcesPath = options.imageResourcesPath || "";
  7063. this.renderInteractiveForms = options.renderInteractiveForms || false;
  7064. this.enablePrintAutoRotate = options.enablePrintAutoRotate || false;
  7065. this.renderer = options.renderer || _ui_utils.RendererType.CANVAS;
  7066. this.enableWebGL = options.enableWebGL || false;
  7067. this.useOnlyCssZoom = options.useOnlyCssZoom || false;
  7068. this.maxCanvasPixels = options.maxCanvasPixels;
  7069. this.l10n = options.l10n || _ui_utils.NullL10n;
  7070. this.defaultRenderingQueue = !options.renderingQueue;
  7071. if (this.defaultRenderingQueue) {
  7072. this.renderingQueue = new _pdf_rendering_queue.PDFRenderingQueue();
  7073. this.renderingQueue.setViewer(this);
  7074. } else {
  7075. this.renderingQueue = options.renderingQueue;
  7076. }
  7077. this.scroll = (0, _ui_utils.watchScroll)(this.container, this._scrollUpdate.bind(this));
  7078. this.presentationModeState = _ui_utils.PresentationModeState.UNKNOWN;
  7079. this._onBeforeDraw = this._onAfterDraw = null;
  7080. this._resetView();
  7081. if (this.removePageBorders) {
  7082. this.viewer.classList.add("removePageBorders");
  7083. }
  7084. Promise.resolve().then(() => {
  7085. this.eventBus.dispatch("baseviewerinit", {
  7086. source: this
  7087. });
  7088. });
  7089. }
  7090. get pagesCount() {
  7091. return this._pages.length;
  7092. }
  7093. getPageView(index) {
  7094. return this._pages[index];
  7095. }
  7096. get pageViewsReady() {
  7097. if (!this._pagesCapability.settled) {
  7098. return false;
  7099. }
  7100. return this._pages.every(function (pageView) {
  7101. return pageView && pageView.pdfPage;
  7102. });
  7103. }
  7104. get currentPageNumber() {
  7105. return this._currentPageNumber;
  7106. }
  7107. set currentPageNumber(val) {
  7108. if (!Number.isInteger(val)) {
  7109. throw new Error("Invalid page number.");
  7110. }
  7111. if (!this.pdfDocument) {
  7112. return;
  7113. }
  7114. if (!this._setCurrentPageNumber(val, true)) {
  7115. console.error(`${this._name}.currentPageNumber: "${val}" is not a valid page.`);
  7116. }
  7117. }
  7118. _setCurrentPageNumber(val, resetCurrentPageView = false) {
  7119. if (this._currentPageNumber === val) {
  7120. if (resetCurrentPageView) {
  7121. this._resetCurrentPageView();
  7122. }
  7123. return true;
  7124. }
  7125. if (!(0 < val && val <= this.pagesCount)) {
  7126. return false;
  7127. }
  7128. this._currentPageNumber = val;
  7129. this.eventBus.dispatch("pagechanging", {
  7130. source: this,
  7131. pageNumber: val,
  7132. pageLabel: this._pageLabels && this._pageLabels[val - 1]
  7133. });
  7134. if (resetCurrentPageView) {
  7135. this._resetCurrentPageView();
  7136. }
  7137. return true;
  7138. }
  7139. get currentPageLabel() {
  7140. return this._pageLabels && this._pageLabels[this._currentPageNumber - 1];
  7141. }
  7142. set currentPageLabel(val) {
  7143. if (!this.pdfDocument) {
  7144. return;
  7145. }
  7146. let page = val | 0;
  7147. if (this._pageLabels) {
  7148. const i = this._pageLabels.indexOf(val);
  7149. if (i >= 0) {
  7150. page = i + 1;
  7151. }
  7152. }
  7153. if (!this._setCurrentPageNumber(page, true)) {
  7154. console.error(`${this._name}.currentPageLabel: "${val}" is not a valid page.`);
  7155. }
  7156. }
  7157. get currentScale() {
  7158. return this._currentScale !== _ui_utils.UNKNOWN_SCALE ? this._currentScale : _ui_utils.DEFAULT_SCALE;
  7159. }
  7160. set currentScale(val) {
  7161. if (isNaN(val)) {
  7162. throw new Error("Invalid numeric scale.");
  7163. }
  7164. if (!this.pdfDocument) {
  7165. return;
  7166. }
  7167. this._setScale(val, false);
  7168. }
  7169. get currentScaleValue() {
  7170. return this._currentScaleValue;
  7171. }
  7172. set currentScaleValue(val) {
  7173. if (!this.pdfDocument) {
  7174. return;
  7175. }
  7176. this._setScale(val, false);
  7177. }
  7178. get pagesRotation() {
  7179. return this._pagesRotation;
  7180. }
  7181. set pagesRotation(rotation) {
  7182. if (!(0, _ui_utils.isValidRotation)(rotation)) {
  7183. throw new Error("Invalid pages rotation angle.");
  7184. }
  7185. if (!this.pdfDocument) {
  7186. return;
  7187. }
  7188. if (this._pagesRotation === rotation) {
  7189. return;
  7190. }
  7191. this._pagesRotation = rotation;
  7192. const pageNumber = this._currentPageNumber;
  7193. for (let i = 0, ii = this._pages.length; i < ii; i++) {
  7194. const pageView = this._pages[i];
  7195. pageView.update(pageView.scale, rotation);
  7196. }
  7197. if (this._currentScaleValue) {
  7198. this._setScale(this._currentScaleValue, true);
  7199. }
  7200. this.eventBus.dispatch("rotationchanging", {
  7201. source: this,
  7202. pagesRotation: rotation,
  7203. pageNumber
  7204. });
  7205. if (this.defaultRenderingQueue) {
  7206. this.update();
  7207. }
  7208. }
  7209. get firstPagePromise() {
  7210. return this.pdfDocument ? this._firstPageCapability.promise : null;
  7211. }
  7212. get onePageRendered() {
  7213. return this.pdfDocument ? this._onePageRenderedCapability.promise : null;
  7214. }
  7215. get pagesPromise() {
  7216. return this.pdfDocument ? this._pagesCapability.promise : null;
  7217. }
  7218. get _setDocumentViewerElement() {
  7219. throw new Error("Not implemented: _setDocumentViewerElement");
  7220. }
  7221. setDocument(pdfDocument) {
  7222. if (this.pdfDocument) {
  7223. this._cancelRendering();
  7224. this._resetView();
  7225. if (this.findController) {
  7226. this.findController.setDocument(null);
  7227. }
  7228. }
  7229. this.pdfDocument = pdfDocument;
  7230. if (!pdfDocument) {
  7231. return;
  7232. }
  7233. const pagesCount = pdfDocument.numPages;
  7234. const firstPagePromise = pdfDocument.getPage(1);
  7235. this._pagesCapability.promise.then(() => {
  7236. this.eventBus.dispatch("pagesloaded", {
  7237. source: this,
  7238. pagesCount
  7239. });
  7240. });
  7241. this._onBeforeDraw = evt => {
  7242. const pageView = this._pages[evt.pageNumber - 1];
  7243. if (!pageView) {
  7244. return;
  7245. }
  7246. this._buffer.push(pageView);
  7247. };
  7248. this.eventBus._on("pagerender", this._onBeforeDraw);
  7249. this._onAfterDraw = evt => {
  7250. if (evt.cssTransform || this._onePageRenderedCapability.settled) {
  7251. return;
  7252. }
  7253. this._onePageRenderedCapability.resolve();
  7254. this.eventBus._off("pagerendered", this._onAfterDraw);
  7255. this._onAfterDraw = null;
  7256. };
  7257. this.eventBus._on("pagerendered", this._onAfterDraw);
  7258. firstPagePromise.then(firstPdfPage => {
  7259. this._firstPageCapability.resolve(firstPdfPage);
  7260. const scale = this.currentScale;
  7261. const viewport = firstPdfPage.getViewport({
  7262. scale: scale * _ui_utils.CSS_UNITS
  7263. });
  7264. const textLayerFactory = this.textLayerMode !== _ui_utils.TextLayerMode.DISABLE ? this : null;
  7265. for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) {
  7266. const pageView = new _pdf_page_view.PDFPageView({
  7267. container: this._setDocumentViewerElement,
  7268. eventBus: this.eventBus,
  7269. id: pageNum,
  7270. scale,
  7271. defaultViewport: viewport.clone(),
  7272. renderingQueue: this.renderingQueue,
  7273. textLayerFactory,
  7274. textLayerMode: this.textLayerMode,
  7275. annotationLayerFactory: this,
  7276. imageResourcesPath: this.imageResourcesPath,
  7277. renderInteractiveForms: this.renderInteractiveForms,
  7278. renderer: this.renderer,
  7279. enableWebGL: this.enableWebGL,
  7280. useOnlyCssZoom: this.useOnlyCssZoom,
  7281. maxCanvasPixels: this.maxCanvasPixels,
  7282. l10n: this.l10n
  7283. });
  7284. this._pages.push(pageView);
  7285. }
  7286. const firstPageView = this._pages[0];
  7287. if (firstPageView) {
  7288. firstPageView.setPdfPage(firstPdfPage);
  7289. this.linkService.cachePageRef(1, firstPdfPage.ref);
  7290. }
  7291. if (this._spreadMode !== _ui_utils.SpreadMode.NONE) {
  7292. this._updateSpreadMode();
  7293. }
  7294. this._onePageRenderedCapability.promise.then(() => {
  7295. if (this.findController) {
  7296. this.findController.setDocument(pdfDocument);
  7297. }
  7298. if (pdfDocument.loadingParams["disableAutoFetch"] || pagesCount > 7500) {
  7299. this._pagesCapability.resolve();
  7300. return;
  7301. }
  7302. let getPagesLeft = pagesCount - 1;
  7303. if (getPagesLeft <= 0) {
  7304. this._pagesCapability.resolve();
  7305. return;
  7306. }
  7307. for (let pageNum = 2; pageNum <= pagesCount; ++pageNum) {
  7308. pdfDocument.getPage(pageNum).then(pdfPage => {
  7309. const pageView = this._pages[pageNum - 1];
  7310. if (!pageView.pdfPage) {
  7311. pageView.setPdfPage(pdfPage);
  7312. }
  7313. this.linkService.cachePageRef(pageNum, pdfPage.ref);
  7314. if (--getPagesLeft === 0) {
  7315. this._pagesCapability.resolve();
  7316. }
  7317. }, reason => {
  7318. console.error(`Unable to get page ${pageNum} to initialize viewer`, reason);
  7319. if (--getPagesLeft === 0) {
  7320. this._pagesCapability.resolve();
  7321. }
  7322. });
  7323. }
  7324. });
  7325. this.eventBus.dispatch("pagesinit", {
  7326. source: this
  7327. });
  7328. if (this.defaultRenderingQueue) {
  7329. this.update();
  7330. }
  7331. }).catch(reason => {
  7332. console.error("Unable to initialize viewer", reason);
  7333. });
  7334. }
  7335. setPageLabels(labels) {
  7336. if (!this.pdfDocument) {
  7337. return;
  7338. }
  7339. if (!labels) {
  7340. this._pageLabels = null;
  7341. } else if (!(Array.isArray(labels) && this.pdfDocument.numPages === labels.length)) {
  7342. this._pageLabels = null;
  7343. console.error(`${this._name}.setPageLabels: Invalid page labels.`);
  7344. } else {
  7345. this._pageLabels = labels;
  7346. }
  7347. for (let i = 0, ii = this._pages.length; i < ii; i++) {
  7348. const pageView = this._pages[i];
  7349. const label = this._pageLabels && this._pageLabels[i];
  7350. pageView.setPageLabel(label);
  7351. }
  7352. }
  7353. _resetView() {
  7354. this._pages = [];
  7355. this._currentPageNumber = 1;
  7356. this._currentScale = _ui_utils.UNKNOWN_SCALE;
  7357. this._currentScaleValue = null;
  7358. this._pageLabels = null;
  7359. this._buffer = new PDFPageViewBuffer(DEFAULT_CACHE_SIZE);
  7360. this._location = null;
  7361. this._pagesRotation = 0;
  7362. this._pagesRequests = new WeakMap();
  7363. this._firstPageCapability = (0, _pdfjsLib.createPromiseCapability)();
  7364. this._onePageRenderedCapability = (0, _pdfjsLib.createPromiseCapability)();
  7365. this._pagesCapability = (0, _pdfjsLib.createPromiseCapability)();
  7366. this._scrollMode = _ui_utils.ScrollMode.VERTICAL;
  7367. this._spreadMode = _ui_utils.SpreadMode.NONE;
  7368. if (this._onBeforeDraw) {
  7369. this.eventBus._off("pagerender", this._onBeforeDraw);
  7370. this._onBeforeDraw = null;
  7371. }
  7372. if (this._onAfterDraw) {
  7373. this.eventBus._off("pagerendered", this._onAfterDraw);
  7374. this._onAfterDraw = null;
  7375. }
  7376. this.viewer.textContent = "";
  7377. this._updateScrollMode();
  7378. }
  7379. _scrollUpdate() {
  7380. if (this.pagesCount === 0) {
  7381. return;
  7382. }
  7383. this.update();
  7384. }
  7385. _scrollIntoView({
  7386. pageDiv,
  7387. pageSpot = null,
  7388. pageNumber = null
  7389. }) {
  7390. (0, _ui_utils.scrollIntoView)(pageDiv, pageSpot);
  7391. }
  7392. _setScaleUpdatePages(newScale, newValue, noScroll = false, preset = false) {
  7393. this._currentScaleValue = newValue.toString();
  7394. if (isSameScale(this._currentScale, newScale)) {
  7395. if (preset) {
  7396. this.eventBus.dispatch("scalechanging", {
  7397. source: this,
  7398. scale: newScale,
  7399. presetValue: newValue
  7400. });
  7401. }
  7402. return;
  7403. }
  7404. for (let i = 0, ii = this._pages.length; i < ii; i++) {
  7405. this._pages[i].update(newScale);
  7406. }
  7407. this._currentScale = newScale;
  7408. if (!noScroll) {
  7409. let page = this._currentPageNumber,
  7410. dest;
  7411. if (this._location && !(this.isInPresentationMode || this.isChangingPresentationMode)) {
  7412. page = this._location.pageNumber;
  7413. dest = [null, {
  7414. name: "XYZ"
  7415. }, this._location.left, this._location.top, null];
  7416. }
  7417. this.scrollPageIntoView({
  7418. pageNumber: page,
  7419. destArray: dest,
  7420. allowNegativeOffset: true
  7421. });
  7422. }
  7423. this.eventBus.dispatch("scalechanging", {
  7424. source: this,
  7425. scale: newScale,
  7426. presetValue: preset ? newValue : undefined
  7427. });
  7428. if (this.defaultRenderingQueue) {
  7429. this.update();
  7430. }
  7431. }
  7432. _setScale(value, noScroll = false) {
  7433. let scale = parseFloat(value);
  7434. if (scale > 0) {
  7435. this._setScaleUpdatePages(scale, value, noScroll, false);
  7436. } else {
  7437. const currentPage = this._pages[this._currentPageNumber - 1];
  7438. if (!currentPage) {
  7439. return;
  7440. }
  7441. const noPadding = this.isInPresentationMode || this.removePageBorders;
  7442. let hPadding = noPadding ? 0 : _ui_utils.SCROLLBAR_PADDING;
  7443. let vPadding = noPadding ? 0 : _ui_utils.VERTICAL_PADDING;
  7444. if (!noPadding && this._isScrollModeHorizontal) {
  7445. [hPadding, vPadding] = [vPadding, hPadding];
  7446. }
  7447. const pageWidthScale = (this.container.clientWidth - hPadding) / currentPage.width * currentPage.scale;
  7448. const pageHeightScale = (this.container.clientHeight - vPadding) / currentPage.height * currentPage.scale;
  7449. switch (value) {
  7450. case "page-actual":
  7451. scale = 1;
  7452. break;
  7453. case "page-width":
  7454. scale = pageWidthScale;
  7455. break;
  7456. case "page-height":
  7457. scale = pageHeightScale;
  7458. break;
  7459. case "page-fit":
  7460. scale = Math.min(pageWidthScale, pageHeightScale);
  7461. break;
  7462. case "auto":
  7463. const horizontalScale = (0, _ui_utils.isPortraitOrientation)(currentPage) ? pageWidthScale : Math.min(pageHeightScale, pageWidthScale);
  7464. scale = Math.min(_ui_utils.MAX_AUTO_SCALE, horizontalScale);
  7465. break;
  7466. default:
  7467. console.error(`${this._name}._setScale: "${value}" is an unknown zoom value.`);
  7468. return;
  7469. }
  7470. this._setScaleUpdatePages(scale, value, noScroll, true);
  7471. }
  7472. }
  7473. _resetCurrentPageView() {
  7474. if (this.isInPresentationMode) {
  7475. this._setScale(this._currentScaleValue, true);
  7476. }
  7477. const pageView = this._pages[this._currentPageNumber - 1];
  7478. this._scrollIntoView({
  7479. pageDiv: pageView.div
  7480. });
  7481. }
  7482. scrollPageIntoView({
  7483. pageNumber,
  7484. destArray = null,
  7485. allowNegativeOffset = false,
  7486. ignoreDestinationZoom = false
  7487. }) {
  7488. if (!this.pdfDocument) {
  7489. return;
  7490. }
  7491. const pageView = Number.isInteger(pageNumber) && this._pages[pageNumber - 1];
  7492. if (!pageView) {
  7493. console.error(`${this._name}.scrollPageIntoView: ` + `"${pageNumber}" is not a valid pageNumber parameter.`);
  7494. return;
  7495. }
  7496. if (this.isInPresentationMode || !destArray) {
  7497. this._setCurrentPageNumber(pageNumber, true);
  7498. return;
  7499. }
  7500. let x = 0,
  7501. y = 0;
  7502. let width = 0,
  7503. height = 0,
  7504. widthScale,
  7505. heightScale;
  7506. const changeOrientation = pageView.rotation % 180 !== 0;
  7507. const pageWidth = (changeOrientation ? pageView.height : pageView.width) / pageView.scale / _ui_utils.CSS_UNITS;
  7508. const pageHeight = (changeOrientation ? pageView.width : pageView.height) / pageView.scale / _ui_utils.CSS_UNITS;
  7509. let scale = 0;
  7510. switch (destArray[1].name) {
  7511. case "XYZ":
  7512. x = destArray[2];
  7513. y = destArray[3];
  7514. scale = destArray[4];
  7515. x = x !== null ? x : 0;
  7516. y = y !== null ? y : pageHeight;
  7517. break;
  7518. case "Fit":
  7519. case "FitB":
  7520. scale = "page-fit";
  7521. break;
  7522. case "FitH":
  7523. case "FitBH":
  7524. y = destArray[2];
  7525. scale = "page-width";
  7526. if (y === null && this._location) {
  7527. x = this._location.left;
  7528. y = this._location.top;
  7529. }
  7530. break;
  7531. case "FitV":
  7532. case "FitBV":
  7533. x = destArray[2];
  7534. width = pageWidth;
  7535. height = pageHeight;
  7536. scale = "page-height";
  7537. break;
  7538. case "FitR":
  7539. x = destArray[2];
  7540. y = destArray[3];
  7541. width = destArray[4] - x;
  7542. height = destArray[5] - y;
  7543. const hPadding = this.removePageBorders ? 0 : _ui_utils.SCROLLBAR_PADDING;
  7544. const vPadding = this.removePageBorders ? 0 : _ui_utils.VERTICAL_PADDING;
  7545. widthScale = (this.container.clientWidth - hPadding) / width / _ui_utils.CSS_UNITS;
  7546. heightScale = (this.container.clientHeight - vPadding) / height / _ui_utils.CSS_UNITS;
  7547. scale = Math.min(Math.abs(widthScale), Math.abs(heightScale));
  7548. break;
  7549. default:
  7550. console.error(`${this._name}.scrollPageIntoView: ` + `"${destArray[1].name}" is not a valid destination type.`);
  7551. return;
  7552. }
  7553. if (!ignoreDestinationZoom) {
  7554. if (scale && scale !== this._currentScale) {
  7555. this.currentScaleValue = scale;
  7556. } else if (this._currentScale === _ui_utils.UNKNOWN_SCALE) {
  7557. this.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  7558. }
  7559. }
  7560. if (scale === "page-fit" && !destArray[4]) {
  7561. this._scrollIntoView({
  7562. pageDiv: pageView.div,
  7563. pageNumber
  7564. });
  7565. return;
  7566. }
  7567. const boundingRect = [pageView.viewport.convertToViewportPoint(x, y), pageView.viewport.convertToViewportPoint(x + width, y + height)];
  7568. let left = Math.min(boundingRect[0][0], boundingRect[1][0]);
  7569. let top = Math.min(boundingRect[0][1], boundingRect[1][1]);
  7570. if (!allowNegativeOffset) {
  7571. left = Math.max(left, 0);
  7572. top = Math.max(top, 0);
  7573. }
  7574. this._scrollIntoView({
  7575. pageDiv: pageView.div,
  7576. pageSpot: {
  7577. left,
  7578. top
  7579. },
  7580. pageNumber
  7581. });
  7582. }
  7583. _updateLocation(firstPage) {
  7584. const currentScale = this._currentScale;
  7585. const currentScaleValue = this._currentScaleValue;
  7586. const normalizedScaleValue = parseFloat(currentScaleValue) === currentScale ? Math.round(currentScale * 10000) / 100 : currentScaleValue;
  7587. const pageNumber = firstPage.id;
  7588. let pdfOpenParams = "#page=" + pageNumber;
  7589. pdfOpenParams += "&zoom=" + normalizedScaleValue;
  7590. const currentPageView = this._pages[pageNumber - 1];
  7591. const container = this.container;
  7592. const topLeft = currentPageView.getPagePoint(container.scrollLeft - firstPage.x, container.scrollTop - firstPage.y);
  7593. const intLeft = Math.round(topLeft[0]);
  7594. const intTop = Math.round(topLeft[1]);
  7595. pdfOpenParams += "," + intLeft + "," + intTop;
  7596. this._location = {
  7597. pageNumber,
  7598. scale: normalizedScaleValue,
  7599. top: intTop,
  7600. left: intLeft,
  7601. rotation: this._pagesRotation,
  7602. pdfOpenParams
  7603. };
  7604. }
  7605. _updateHelper(visiblePages) {
  7606. throw new Error("Not implemented: _updateHelper");
  7607. }
  7608. update() {
  7609. const visible = this._getVisiblePages();
  7610. const visiblePages = visible.views,
  7611. numVisiblePages = visiblePages.length;
  7612. if (numVisiblePages === 0) {
  7613. return;
  7614. }
  7615. const newCacheSize = Math.max(DEFAULT_CACHE_SIZE, 2 * numVisiblePages + 1);
  7616. this._buffer.resize(newCacheSize, visiblePages);
  7617. this.renderingQueue.renderHighestPriority(visible);
  7618. this._updateHelper(visiblePages);
  7619. this._updateLocation(visible.first);
  7620. this.eventBus.dispatch("updateviewarea", {
  7621. source: this,
  7622. location: this._location
  7623. });
  7624. }
  7625. containsElement(element) {
  7626. return this.container.contains(element);
  7627. }
  7628. focus() {
  7629. this.container.focus();
  7630. }
  7631. get _isScrollModeHorizontal() {
  7632. return this.isInPresentationMode ? false : this._scrollMode === _ui_utils.ScrollMode.HORIZONTAL;
  7633. }
  7634. get isInPresentationMode() {
  7635. return this.presentationModeState === _ui_utils.PresentationModeState.FULLSCREEN;
  7636. }
  7637. get isChangingPresentationMode() {
  7638. return this.presentationModeState === _ui_utils.PresentationModeState.CHANGING;
  7639. }
  7640. get isHorizontalScrollbarEnabled() {
  7641. return this.isInPresentationMode ? false : this.container.scrollWidth > this.container.clientWidth;
  7642. }
  7643. get isVerticalScrollbarEnabled() {
  7644. return this.isInPresentationMode ? false : this.container.scrollHeight > this.container.clientHeight;
  7645. }
  7646. _getCurrentVisiblePage() {
  7647. if (!this.pagesCount) {
  7648. return {
  7649. views: []
  7650. };
  7651. }
  7652. const pageView = this._pages[this._currentPageNumber - 1];
  7653. const element = pageView.div;
  7654. const view = {
  7655. id: pageView.id,
  7656. x: element.offsetLeft + element.clientLeft,
  7657. y: element.offsetTop + element.clientTop,
  7658. view: pageView
  7659. };
  7660. return {
  7661. first: view,
  7662. last: view,
  7663. views: [view]
  7664. };
  7665. }
  7666. _getVisiblePages() {
  7667. return (0, _ui_utils.getVisibleElements)(this.container, this._pages, true, this._isScrollModeHorizontal);
  7668. }
  7669. isPageVisible(pageNumber) {
  7670. if (!this.pdfDocument) {
  7671. return false;
  7672. }
  7673. if (pageNumber < 1 || pageNumber > this.pagesCount) {
  7674. console.error(`${this._name}.isPageVisible: "${pageNumber}" is out of bounds.`);
  7675. return false;
  7676. }
  7677. return this._getVisiblePages().views.some(function (view) {
  7678. return view.id === pageNumber;
  7679. });
  7680. }
  7681. cleanup() {
  7682. for (let i = 0, ii = this._pages.length; i < ii; i++) {
  7683. if (this._pages[i] && this._pages[i].renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED) {
  7684. this._pages[i].reset();
  7685. }
  7686. }
  7687. }
  7688. _cancelRendering() {
  7689. for (let i = 0, ii = this._pages.length; i < ii; i++) {
  7690. if (this._pages[i]) {
  7691. this._pages[i].cancelRendering();
  7692. }
  7693. }
  7694. }
  7695. _ensurePdfPageLoaded(pageView) {
  7696. if (pageView.pdfPage) {
  7697. return Promise.resolve(pageView.pdfPage);
  7698. }
  7699. if (this._pagesRequests.has(pageView)) {
  7700. return this._pagesRequests.get(pageView);
  7701. }
  7702. const promise = this.pdfDocument.getPage(pageView.id).then(pdfPage => {
  7703. if (!pageView.pdfPage) {
  7704. pageView.setPdfPage(pdfPage);
  7705. }
  7706. this._pagesRequests.delete(pageView);
  7707. return pdfPage;
  7708. }).catch(reason => {
  7709. console.error("Unable to get page for page view", reason);
  7710. this._pagesRequests.delete(pageView);
  7711. });
  7712. this._pagesRequests.set(pageView, promise);
  7713. return promise;
  7714. }
  7715. forceRendering(currentlyVisiblePages) {
  7716. const visiblePages = currentlyVisiblePages || this._getVisiblePages();
  7717. const scrollAhead = this._isScrollModeHorizontal ? this.scroll.right : this.scroll.down;
  7718. const pageView = this.renderingQueue.getHighestPriority(visiblePages, this._pages, scrollAhead);
  7719. if (pageView) {
  7720. this._ensurePdfPageLoaded(pageView).then(() => {
  7721. this.renderingQueue.renderView(pageView);
  7722. });
  7723. return true;
  7724. }
  7725. return false;
  7726. }
  7727. createTextLayerBuilder(textLayerDiv, pageIndex, viewport, enhanceTextSelection = false, eventBus) {
  7728. return new _text_layer_builder.TextLayerBuilder({
  7729. textLayerDiv,
  7730. eventBus,
  7731. pageIndex,
  7732. viewport,
  7733. findController: this.isInPresentationMode ? null : this.findController,
  7734. enhanceTextSelection: this.isInPresentationMode ? false : enhanceTextSelection
  7735. });
  7736. }
  7737. createAnnotationLayerBuilder(pageDiv, pdfPage, imageResourcesPath = "", renderInteractiveForms = false, l10n = _ui_utils.NullL10n) {
  7738. return new _annotation_layer_builder.AnnotationLayerBuilder({
  7739. pageDiv,
  7740. pdfPage,
  7741. imageResourcesPath,
  7742. renderInteractiveForms,
  7743. linkService: this.linkService,
  7744. downloadManager: this.downloadManager,
  7745. l10n
  7746. });
  7747. }
  7748. get hasEqualPageSizes() {
  7749. const firstPageView = this._pages[0];
  7750. for (let i = 1, ii = this._pages.length; i < ii; ++i) {
  7751. const pageView = this._pages[i];
  7752. if (pageView.width !== firstPageView.width || pageView.height !== firstPageView.height) {
  7753. return false;
  7754. }
  7755. }
  7756. return true;
  7757. }
  7758. getPagesOverview() {
  7759. const pagesOverview = this._pages.map(function (pageView) {
  7760. const viewport = pageView.pdfPage.getViewport({
  7761. scale: 1
  7762. });
  7763. return {
  7764. width: viewport.width,
  7765. height: viewport.height,
  7766. rotation: viewport.rotation
  7767. };
  7768. });
  7769. if (!this.enablePrintAutoRotate) {
  7770. return pagesOverview;
  7771. }
  7772. const isFirstPagePortrait = (0, _ui_utils.isPortraitOrientation)(pagesOverview[0]);
  7773. return pagesOverview.map(function (size) {
  7774. if (isFirstPagePortrait === (0, _ui_utils.isPortraitOrientation)(size)) {
  7775. return size;
  7776. }
  7777. return {
  7778. width: size.height,
  7779. height: size.width,
  7780. rotation: (size.rotation + 90) % 360
  7781. };
  7782. });
  7783. }
  7784. get scrollMode() {
  7785. return this._scrollMode;
  7786. }
  7787. set scrollMode(mode) {
  7788. if (this._scrollMode === mode) {
  7789. return;
  7790. }
  7791. if (!(0, _ui_utils.isValidScrollMode)(mode)) {
  7792. throw new Error(`Invalid scroll mode: ${mode}`);
  7793. }
  7794. this._scrollMode = mode;
  7795. this.eventBus.dispatch("scrollmodechanged", {
  7796. source: this,
  7797. mode
  7798. });
  7799. this._updateScrollMode(this._currentPageNumber);
  7800. }
  7801. _updateScrollMode(pageNumber = null) {
  7802. const scrollMode = this._scrollMode,
  7803. viewer = this.viewer;
  7804. viewer.classList.toggle("scrollHorizontal", scrollMode === _ui_utils.ScrollMode.HORIZONTAL);
  7805. viewer.classList.toggle("scrollWrapped", scrollMode === _ui_utils.ScrollMode.WRAPPED);
  7806. if (!this.pdfDocument || !pageNumber) {
  7807. return;
  7808. }
  7809. if (this._currentScaleValue && isNaN(this._currentScaleValue)) {
  7810. this._setScale(this._currentScaleValue, true);
  7811. }
  7812. this._setCurrentPageNumber(pageNumber, true);
  7813. this.update();
  7814. }
  7815. get spreadMode() {
  7816. return this._spreadMode;
  7817. }
  7818. set spreadMode(mode) {
  7819. if (this._spreadMode === mode) {
  7820. return;
  7821. }
  7822. if (!(0, _ui_utils.isValidSpreadMode)(mode)) {
  7823. throw new Error(`Invalid spread mode: ${mode}`);
  7824. }
  7825. this._spreadMode = mode;
  7826. this.eventBus.dispatch("spreadmodechanged", {
  7827. source: this,
  7828. mode
  7829. });
  7830. this._updateSpreadMode(this._currentPageNumber);
  7831. }
  7832. _updateSpreadMode(pageNumber = null) {
  7833. if (!this.pdfDocument) {
  7834. return;
  7835. }
  7836. const viewer = this.viewer,
  7837. pages = this._pages;
  7838. viewer.textContent = "";
  7839. if (this._spreadMode === _ui_utils.SpreadMode.NONE) {
  7840. for (let i = 0, iMax = pages.length; i < iMax; ++i) {
  7841. viewer.appendChild(pages[i].div);
  7842. }
  7843. } else {
  7844. const parity = this._spreadMode - 1;
  7845. let spread = null;
  7846. for (let i = 0, iMax = pages.length; i < iMax; ++i) {
  7847. if (spread === null) {
  7848. spread = document.createElement("div");
  7849. spread.className = "spread";
  7850. viewer.appendChild(spread);
  7851. } else if (i % 2 === parity) {
  7852. spread = spread.cloneNode(false);
  7853. viewer.appendChild(spread);
  7854. }
  7855. spread.appendChild(pages[i].div);
  7856. }
  7857. }
  7858. if (!pageNumber) {
  7859. return;
  7860. }
  7861. this._setCurrentPageNumber(pageNumber, true);
  7862. this.update();
  7863. }
  7864. }
  7865. exports.BaseViewer = BaseViewer;
  7866. /***/ }),
  7867. /* 26 */
  7868. /***/ (function(module, exports, __webpack_require__) {
  7869. "use strict";
  7870. Object.defineProperty(exports, "__esModule", {
  7871. value: true
  7872. });
  7873. exports.DefaultAnnotationLayerFactory = exports.AnnotationLayerBuilder = void 0;
  7874. var _pdfjsLib = __webpack_require__(4);
  7875. var _ui_utils = __webpack_require__(2);
  7876. var _pdf_link_service = __webpack_require__(18);
  7877. class AnnotationLayerBuilder {
  7878. constructor({
  7879. pageDiv,
  7880. pdfPage,
  7881. linkService,
  7882. downloadManager,
  7883. imageResourcesPath = "",
  7884. renderInteractiveForms = false,
  7885. l10n = _ui_utils.NullL10n
  7886. }) {
  7887. this.pageDiv = pageDiv;
  7888. this.pdfPage = pdfPage;
  7889. this.linkService = linkService;
  7890. this.downloadManager = downloadManager;
  7891. this.imageResourcesPath = imageResourcesPath;
  7892. this.renderInteractiveForms = renderInteractiveForms;
  7893. this.l10n = l10n;
  7894. this.div = null;
  7895. this._cancelled = false;
  7896. }
  7897. render(viewport, intent = "display") {
  7898. this.pdfPage.getAnnotations({
  7899. intent
  7900. }).then(annotations => {
  7901. if (this._cancelled) {
  7902. return;
  7903. }
  7904. const parameters = {
  7905. viewport: viewport.clone({
  7906. dontFlip: true
  7907. }),
  7908. div: this.div,
  7909. annotations,
  7910. page: this.pdfPage,
  7911. imageResourcesPath: this.imageResourcesPath,
  7912. renderInteractiveForms: this.renderInteractiveForms,
  7913. linkService: this.linkService,
  7914. downloadManager: this.downloadManager
  7915. };
  7916. if (this.div) {
  7917. _pdfjsLib.AnnotationLayer.update(parameters);
  7918. } else {
  7919. if (annotations.length === 0) {
  7920. return;
  7921. }
  7922. this.div = document.createElement("div");
  7923. this.div.className = "annotationLayer";
  7924. this.pageDiv.appendChild(this.div);
  7925. parameters.div = this.div;
  7926. _pdfjsLib.AnnotationLayer.render(parameters);
  7927. this.l10n.translate(this.div);
  7928. }
  7929. });
  7930. }
  7931. cancel() {
  7932. this._cancelled = true;
  7933. }
  7934. hide() {
  7935. if (!this.div) {
  7936. return;
  7937. }
  7938. this.div.setAttribute("hidden", "true");
  7939. }
  7940. }
  7941. exports.AnnotationLayerBuilder = AnnotationLayerBuilder;
  7942. class DefaultAnnotationLayerFactory {
  7943. createAnnotationLayerBuilder(pageDiv, pdfPage, imageResourcesPath = "", renderInteractiveForms = false, l10n = _ui_utils.NullL10n) {
  7944. return new AnnotationLayerBuilder({
  7945. pageDiv,
  7946. pdfPage,
  7947. imageResourcesPath,
  7948. renderInteractiveForms,
  7949. linkService: new _pdf_link_service.SimpleLinkService(),
  7950. l10n
  7951. });
  7952. }
  7953. }
  7954. exports.DefaultAnnotationLayerFactory = DefaultAnnotationLayerFactory;
  7955. /***/ }),
  7956. /* 27 */
  7957. /***/ (function(module, exports, __webpack_require__) {
  7958. "use strict";
  7959. Object.defineProperty(exports, "__esModule", {
  7960. value: true
  7961. });
  7962. exports.PDFPageView = void 0;
  7963. var _ui_utils = __webpack_require__(2);
  7964. var _pdfjsLib = __webpack_require__(4);
  7965. var _pdf_rendering_queue = __webpack_require__(8);
  7966. var _viewer_compatibility = __webpack_require__(5);
  7967. const MAX_CANVAS_PIXELS = _viewer_compatibility.viewerCompatibilityParams.maxCanvasPixels || 16777216;
  7968. class PDFPageView {
  7969. constructor(options) {
  7970. const container = options.container;
  7971. const defaultViewport = options.defaultViewport;
  7972. this.id = options.id;
  7973. this.renderingId = "page" + this.id;
  7974. this.pdfPage = null;
  7975. this.pageLabel = null;
  7976. this.rotation = 0;
  7977. this.scale = options.scale || _ui_utils.DEFAULT_SCALE;
  7978. this.viewport = defaultViewport;
  7979. this.pdfPageRotate = defaultViewport.rotation;
  7980. this.hasRestrictedScaling = false;
  7981. this.textLayerMode = Number.isInteger(options.textLayerMode) ? options.textLayerMode : _ui_utils.TextLayerMode.ENABLE;
  7982. this.imageResourcesPath = options.imageResourcesPath || "";
  7983. this.renderInteractiveForms = options.renderInteractiveForms || false;
  7984. this.useOnlyCssZoom = options.useOnlyCssZoom || false;
  7985. this.maxCanvasPixels = options.maxCanvasPixels || MAX_CANVAS_PIXELS;
  7986. this.eventBus = options.eventBus || (0, _ui_utils.getGlobalEventBus)();
  7987. this.renderingQueue = options.renderingQueue;
  7988. this.textLayerFactory = options.textLayerFactory;
  7989. this.annotationLayerFactory = options.annotationLayerFactory;
  7990. this.renderer = options.renderer || _ui_utils.RendererType.CANVAS;
  7991. this.enableWebGL = options.enableWebGL || false;
  7992. this.l10n = options.l10n || _ui_utils.NullL10n;
  7993. this.paintTask = null;
  7994. this.paintedViewportMap = new WeakMap();
  7995. this.renderingState = _pdf_rendering_queue.RenderingStates.INITIAL;
  7996. this.resume = null;
  7997. this.error = null;
  7998. this.annotationLayer = null;
  7999. this.textLayer = null;
  8000. this.zoomLayer = null;
  8001. const div = document.createElement("div");
  8002. div.className = "page";
  8003. div.style.width = Math.floor(this.viewport.width) + "px";
  8004. div.style.height = Math.floor(this.viewport.height) + "px";
  8005. div.setAttribute("data-page-number", this.id);
  8006. this.div = div;
  8007. container.appendChild(div);
  8008. }
  8009. setPdfPage(pdfPage) {
  8010. this.pdfPage = pdfPage;
  8011. this.pdfPageRotate = pdfPage.rotate;
  8012. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  8013. this.viewport = pdfPage.getViewport({
  8014. scale: this.scale * _ui_utils.CSS_UNITS,
  8015. rotation: totalRotation
  8016. });
  8017. this.stats = pdfPage.stats;
  8018. this.reset();
  8019. }
  8020. destroy() {
  8021. this.reset();
  8022. if (this.pdfPage) {
  8023. this.pdfPage.cleanup();
  8024. }
  8025. }
  8026. _resetZoomLayer(removeFromDOM = false) {
  8027. if (!this.zoomLayer) {
  8028. return;
  8029. }
  8030. const zoomLayerCanvas = this.zoomLayer.firstChild;
  8031. this.paintedViewportMap.delete(zoomLayerCanvas);
  8032. zoomLayerCanvas.width = 0;
  8033. zoomLayerCanvas.height = 0;
  8034. if (removeFromDOM) {
  8035. this.zoomLayer.remove();
  8036. }
  8037. this.zoomLayer = null;
  8038. }
  8039. reset(keepZoomLayer = false, keepAnnotations = false) {
  8040. this.cancelRendering(keepAnnotations);
  8041. this.renderingState = _pdf_rendering_queue.RenderingStates.INITIAL;
  8042. const div = this.div;
  8043. div.style.width = Math.floor(this.viewport.width) + "px";
  8044. div.style.height = Math.floor(this.viewport.height) + "px";
  8045. const childNodes = div.childNodes;
  8046. const currentZoomLayerNode = keepZoomLayer && this.zoomLayer || null;
  8047. const currentAnnotationNode = keepAnnotations && this.annotationLayer && this.annotationLayer.div || null;
  8048. for (let i = childNodes.length - 1; i >= 0; i--) {
  8049. const node = childNodes[i];
  8050. if (currentZoomLayerNode === node || currentAnnotationNode === node) {
  8051. continue;
  8052. }
  8053. div.removeChild(node);
  8054. }
  8055. div.removeAttribute("data-loaded");
  8056. if (currentAnnotationNode) {
  8057. this.annotationLayer.hide();
  8058. } else if (this.annotationLayer) {
  8059. this.annotationLayer.cancel();
  8060. this.annotationLayer = null;
  8061. }
  8062. if (!currentZoomLayerNode) {
  8063. if (this.canvas) {
  8064. this.paintedViewportMap.delete(this.canvas);
  8065. this.canvas.width = 0;
  8066. this.canvas.height = 0;
  8067. delete this.canvas;
  8068. }
  8069. this._resetZoomLayer();
  8070. }
  8071. if (this.svg) {
  8072. this.paintedViewportMap.delete(this.svg);
  8073. delete this.svg;
  8074. }
  8075. this.loadingIconDiv = document.createElement("div");
  8076. this.loadingIconDiv.className = "loadingIcon";
  8077. div.appendChild(this.loadingIconDiv);
  8078. }
  8079. update(scale, rotation) {
  8080. this.scale = scale || this.scale;
  8081. if (typeof rotation !== "undefined") {
  8082. this.rotation = rotation;
  8083. }
  8084. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  8085. this.viewport = this.viewport.clone({
  8086. scale: this.scale * _ui_utils.CSS_UNITS,
  8087. rotation: totalRotation
  8088. });
  8089. if (this.svg) {
  8090. this.cssTransform(this.svg, true);
  8091. this.eventBus.dispatch("pagerendered", {
  8092. source: this,
  8093. pageNumber: this.id,
  8094. cssTransform: true,
  8095. timestamp: performance.now()
  8096. });
  8097. return;
  8098. }
  8099. let isScalingRestricted = false;
  8100. if (this.canvas && this.maxCanvasPixels > 0) {
  8101. const outputScale = this.outputScale;
  8102. if ((Math.floor(this.viewport.width) * outputScale.sx | 0) * (Math.floor(this.viewport.height) * outputScale.sy | 0) > this.maxCanvasPixels) {
  8103. isScalingRestricted = true;
  8104. }
  8105. }
  8106. if (this.canvas) {
  8107. if (this.useOnlyCssZoom || this.hasRestrictedScaling && isScalingRestricted) {
  8108. this.cssTransform(this.canvas, true);
  8109. this.eventBus.dispatch("pagerendered", {
  8110. source: this,
  8111. pageNumber: this.id,
  8112. cssTransform: true,
  8113. timestamp: performance.now()
  8114. });
  8115. return;
  8116. }
  8117. if (!this.zoomLayer && !this.canvas.hasAttribute("hidden")) {
  8118. this.zoomLayer = this.canvas.parentNode;
  8119. this.zoomLayer.style.position = "absolute";
  8120. }
  8121. }
  8122. if (this.zoomLayer) {
  8123. this.cssTransform(this.zoomLayer.firstChild);
  8124. }
  8125. this.reset(true, true);
  8126. }
  8127. cancelRendering(keepAnnotations = false) {
  8128. if (this.paintTask) {
  8129. this.paintTask.cancel();
  8130. this.paintTask = null;
  8131. }
  8132. this.resume = null;
  8133. if (this.textLayer) {
  8134. this.textLayer.cancel();
  8135. this.textLayer = null;
  8136. }
  8137. if (!keepAnnotations && this.annotationLayer) {
  8138. this.annotationLayer.cancel();
  8139. this.annotationLayer = null;
  8140. }
  8141. }
  8142. cssTransform(target, redrawAnnotations = false) {
  8143. const width = this.viewport.width;
  8144. const height = this.viewport.height;
  8145. const div = this.div;
  8146. target.style.width = target.parentNode.style.width = div.style.width = Math.floor(width) + "px";
  8147. target.style.height = target.parentNode.style.height = div.style.height = Math.floor(height) + "px";
  8148. const relativeRotation = this.viewport.rotation - this.paintedViewportMap.get(target).rotation;
  8149. const absRotation = Math.abs(relativeRotation);
  8150. let scaleX = 1,
  8151. scaleY = 1;
  8152. if (absRotation === 90 || absRotation === 270) {
  8153. scaleX = height / width;
  8154. scaleY = width / height;
  8155. }
  8156. const cssTransform = "rotate(" + relativeRotation + "deg) " + "scale(" + scaleX + "," + scaleY + ")";
  8157. target.style.transform = cssTransform;
  8158. if (this.textLayer) {
  8159. const textLayerViewport = this.textLayer.viewport;
  8160. const textRelativeRotation = this.viewport.rotation - textLayerViewport.rotation;
  8161. const textAbsRotation = Math.abs(textRelativeRotation);
  8162. let scale = width / textLayerViewport.width;
  8163. if (textAbsRotation === 90 || textAbsRotation === 270) {
  8164. scale = width / textLayerViewport.height;
  8165. }
  8166. const textLayerDiv = this.textLayer.textLayerDiv;
  8167. let transX, transY;
  8168. switch (textAbsRotation) {
  8169. case 0:
  8170. transX = transY = 0;
  8171. break;
  8172. case 90:
  8173. transX = 0;
  8174. transY = "-" + textLayerDiv.style.height;
  8175. break;
  8176. case 180:
  8177. transX = "-" + textLayerDiv.style.width;
  8178. transY = "-" + textLayerDiv.style.height;
  8179. break;
  8180. case 270:
  8181. transX = "-" + textLayerDiv.style.width;
  8182. transY = 0;
  8183. break;
  8184. default:
  8185. console.error("Bad rotation value.");
  8186. break;
  8187. }
  8188. textLayerDiv.style.transform = "rotate(" + textAbsRotation + "deg) " + "scale(" + scale + ", " + scale + ") " + "translate(" + transX + ", " + transY + ")";
  8189. textLayerDiv.style.transformOrigin = "0% 0%";
  8190. }
  8191. if (redrawAnnotations && this.annotationLayer) {
  8192. this.annotationLayer.render(this.viewport, "display");
  8193. }
  8194. }
  8195. get width() {
  8196. return this.viewport.width;
  8197. }
  8198. get height() {
  8199. return this.viewport.height;
  8200. }
  8201. getPagePoint(x, y) {
  8202. return this.viewport.convertToPdfPoint(x, y);
  8203. }
  8204. draw() {
  8205. if (this.renderingState !== _pdf_rendering_queue.RenderingStates.INITIAL) {
  8206. console.error("Must be in new state before drawing");
  8207. this.reset();
  8208. }
  8209. const {
  8210. div,
  8211. pdfPage
  8212. } = this;
  8213. if (!pdfPage) {
  8214. this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
  8215. if (this.loadingIconDiv) {
  8216. div.removeChild(this.loadingIconDiv);
  8217. delete this.loadingIconDiv;
  8218. }
  8219. return Promise.reject(new Error("pdfPage is not loaded"));
  8220. }
  8221. this.renderingState = _pdf_rendering_queue.RenderingStates.RUNNING;
  8222. const canvasWrapper = document.createElement("div");
  8223. canvasWrapper.style.width = div.style.width;
  8224. canvasWrapper.style.height = div.style.height;
  8225. canvasWrapper.classList.add("canvasWrapper");
  8226. if (this.annotationLayer && this.annotationLayer.div) {
  8227. div.insertBefore(canvasWrapper, this.annotationLayer.div);
  8228. } else {
  8229. div.appendChild(canvasWrapper);
  8230. }
  8231. let textLayer = null;
  8232. if (this.textLayerMode !== _ui_utils.TextLayerMode.DISABLE && this.textLayerFactory) {
  8233. const textLayerDiv = document.createElement("div");
  8234. textLayerDiv.className = "textLayer";
  8235. textLayerDiv.style.width = canvasWrapper.style.width;
  8236. textLayerDiv.style.height = canvasWrapper.style.height;
  8237. if (this.annotationLayer && this.annotationLayer.div) {
  8238. div.insertBefore(textLayerDiv, this.annotationLayer.div);
  8239. } else {
  8240. div.appendChild(textLayerDiv);
  8241. }
  8242. textLayer = this.textLayerFactory.createTextLayerBuilder(textLayerDiv, this.id - 1, this.viewport, this.textLayerMode === _ui_utils.TextLayerMode.ENABLE_ENHANCE, this.eventBus);
  8243. }
  8244. this.textLayer = textLayer;
  8245. let renderContinueCallback = null;
  8246. if (this.renderingQueue) {
  8247. renderContinueCallback = cont => {
  8248. if (!this.renderingQueue.isHighestPriority(this)) {
  8249. this.renderingState = _pdf_rendering_queue.RenderingStates.PAUSED;
  8250. this.resume = () => {
  8251. this.renderingState = _pdf_rendering_queue.RenderingStates.RUNNING;
  8252. cont();
  8253. };
  8254. return;
  8255. }
  8256. cont();
  8257. };
  8258. }
  8259. const finishPaintTask = async error => {
  8260. if (paintTask === this.paintTask) {
  8261. this.paintTask = null;
  8262. }
  8263. if (error instanceof _pdfjsLib.RenderingCancelledException) {
  8264. this.error = null;
  8265. return;
  8266. }
  8267. this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
  8268. if (this.loadingIconDiv) {
  8269. div.removeChild(this.loadingIconDiv);
  8270. delete this.loadingIconDiv;
  8271. }
  8272. this._resetZoomLayer(true);
  8273. this.error = error;
  8274. this.stats = pdfPage.stats;
  8275. this.eventBus.dispatch("pagerendered", {
  8276. source: this,
  8277. pageNumber: this.id,
  8278. cssTransform: false,
  8279. timestamp: performance.now()
  8280. });
  8281. if (error) {
  8282. throw error;
  8283. }
  8284. };
  8285. const paintTask = this.renderer === _ui_utils.RendererType.SVG ? this.paintOnSvg(canvasWrapper) : this.paintOnCanvas(canvasWrapper);
  8286. paintTask.onRenderContinue = renderContinueCallback;
  8287. this.paintTask = paintTask;
  8288. const resultPromise = paintTask.promise.then(function () {
  8289. return finishPaintTask(null).then(function () {
  8290. if (textLayer) {
  8291. const readableStream = pdfPage.streamTextContent({
  8292. normalizeWhitespace: true
  8293. });
  8294. textLayer.setTextContentStream(readableStream);
  8295. textLayer.render();
  8296. }
  8297. });
  8298. }, function (reason) {
  8299. return finishPaintTask(reason);
  8300. });
  8301. if (this.annotationLayerFactory) {
  8302. if (!this.annotationLayer) {
  8303. this.annotationLayer = this.annotationLayerFactory.createAnnotationLayerBuilder(div, pdfPage, this.imageResourcesPath, this.renderInteractiveForms, this.l10n);
  8304. }
  8305. this.annotationLayer.render(this.viewport, "display");
  8306. }
  8307. div.setAttribute("data-loaded", true);
  8308. this.eventBus.dispatch("pagerender", {
  8309. source: this,
  8310. pageNumber: this.id
  8311. });
  8312. return resultPromise;
  8313. }
  8314. paintOnCanvas(canvasWrapper) {
  8315. const renderCapability = (0, _pdfjsLib.createPromiseCapability)();
  8316. const result = {
  8317. promise: renderCapability.promise,
  8318. onRenderContinue(cont) {
  8319. cont();
  8320. },
  8321. cancel() {
  8322. renderTask.cancel();
  8323. }
  8324. };
  8325. const viewport = this.viewport;
  8326. const canvas = document.createElement("canvas");
  8327. this.l10n.get("page_canvas", {
  8328. page: this.id
  8329. }, "Page {{page}}").then(msg => {
  8330. canvas.setAttribute("aria-label", msg);
  8331. });
  8332. canvas.setAttribute("hidden", "hidden");
  8333. let isCanvasHidden = true;
  8334. const showCanvas = function () {
  8335. if (isCanvasHidden) {
  8336. canvas.removeAttribute("hidden");
  8337. isCanvasHidden = false;
  8338. }
  8339. };
  8340. canvasWrapper.appendChild(canvas);
  8341. this.canvas = canvas;
  8342. canvas.mozOpaque = true;
  8343. const ctx = canvas.getContext("2d", {
  8344. alpha: false
  8345. });
  8346. const outputScale = (0, _ui_utils.getOutputScale)(ctx);
  8347. this.outputScale = outputScale;
  8348. if (this.useOnlyCssZoom) {
  8349. const actualSizeViewport = viewport.clone({
  8350. scale: _ui_utils.CSS_UNITS
  8351. });
  8352. outputScale.sx *= actualSizeViewport.width / viewport.width;
  8353. outputScale.sy *= actualSizeViewport.height / viewport.height;
  8354. outputScale.scaled = true;
  8355. }
  8356. if (this.maxCanvasPixels > 0) {
  8357. const pixelsInViewport = viewport.width * viewport.height;
  8358. const maxScale = Math.sqrt(this.maxCanvasPixels / pixelsInViewport);
  8359. if (outputScale.sx > maxScale || outputScale.sy > maxScale) {
  8360. outputScale.sx = maxScale;
  8361. outputScale.sy = maxScale;
  8362. outputScale.scaled = true;
  8363. this.hasRestrictedScaling = true;
  8364. } else {
  8365. this.hasRestrictedScaling = false;
  8366. }
  8367. }
  8368. const sfx = (0, _ui_utils.approximateFraction)(outputScale.sx);
  8369. const sfy = (0, _ui_utils.approximateFraction)(outputScale.sy);
  8370. canvas.width = (0, _ui_utils.roundToDivide)(viewport.width * outputScale.sx, sfx[0]);
  8371. canvas.height = (0, _ui_utils.roundToDivide)(viewport.height * outputScale.sy, sfy[0]);
  8372. canvas.style.width = (0, _ui_utils.roundToDivide)(viewport.width, sfx[1]) + "px";
  8373. canvas.style.height = (0, _ui_utils.roundToDivide)(viewport.height, sfy[1]) + "px";
  8374. this.paintedViewportMap.set(canvas, viewport);
  8375. const transform = !outputScale.scaled ? null : [outputScale.sx, 0, 0, outputScale.sy, 0, 0];
  8376. const renderContext = {
  8377. canvasContext: ctx,
  8378. transform,
  8379. viewport: this.viewport,
  8380. enableWebGL: this.enableWebGL,
  8381. renderInteractiveForms: this.renderInteractiveForms
  8382. };
  8383. const renderTask = this.pdfPage.render(renderContext);
  8384. renderTask.onContinue = function (cont) {
  8385. showCanvas();
  8386. if (result.onRenderContinue) {
  8387. result.onRenderContinue(cont);
  8388. } else {
  8389. cont();
  8390. }
  8391. };
  8392. renderTask.promise.then(function () {
  8393. showCanvas();
  8394. renderCapability.resolve(undefined);
  8395. }, function (error) {
  8396. showCanvas();
  8397. renderCapability.reject(error);
  8398. });
  8399. return result;
  8400. }
  8401. paintOnSvg(wrapper) {
  8402. let cancelled = false;
  8403. const ensureNotCancelled = () => {
  8404. if (cancelled) {
  8405. throw new _pdfjsLib.RenderingCancelledException(`Rendering cancelled, page ${this.id}`, "svg");
  8406. }
  8407. };
  8408. const pdfPage = this.pdfPage;
  8409. const actualSizeViewport = this.viewport.clone({
  8410. scale: _ui_utils.CSS_UNITS
  8411. });
  8412. const promise = pdfPage.getOperatorList().then(opList => {
  8413. ensureNotCancelled();
  8414. const svgGfx = new _pdfjsLib.SVGGraphics(pdfPage.commonObjs, pdfPage.objs);
  8415. return svgGfx.getSVG(opList, actualSizeViewport).then(svg => {
  8416. ensureNotCancelled();
  8417. this.svg = svg;
  8418. this.paintedViewportMap.set(svg, actualSizeViewport);
  8419. svg.style.width = wrapper.style.width;
  8420. svg.style.height = wrapper.style.height;
  8421. this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
  8422. wrapper.appendChild(svg);
  8423. });
  8424. });
  8425. return {
  8426. promise,
  8427. onRenderContinue(cont) {
  8428. cont();
  8429. },
  8430. cancel() {
  8431. cancelled = true;
  8432. }
  8433. };
  8434. }
  8435. setPageLabel(label) {
  8436. this.pageLabel = typeof label === "string" ? label : null;
  8437. if (this.pageLabel !== null) {
  8438. this.div.setAttribute("data-page-label", this.pageLabel);
  8439. } else {
  8440. this.div.removeAttribute("data-page-label");
  8441. }
  8442. }
  8443. }
  8444. exports.PDFPageView = PDFPageView;
  8445. /***/ }),
  8446. /* 28 */
  8447. /***/ (function(module, exports, __webpack_require__) {
  8448. "use strict";
  8449. Object.defineProperty(exports, "__esModule", {
  8450. value: true
  8451. });
  8452. exports.DefaultTextLayerFactory = exports.TextLayerBuilder = void 0;
  8453. var _ui_utils = __webpack_require__(2);
  8454. var _pdfjsLib = __webpack_require__(4);
  8455. const EXPAND_DIVS_TIMEOUT = 300;
  8456. class TextLayerBuilder {
  8457. constructor({
  8458. textLayerDiv,
  8459. eventBus,
  8460. pageIndex,
  8461. viewport,
  8462. findController = null,
  8463. enhanceTextSelection = false
  8464. }) {
  8465. this.textLayerDiv = textLayerDiv;
  8466. this.eventBus = eventBus || (0, _ui_utils.getGlobalEventBus)();
  8467. this.textContent = null;
  8468. this.textContentItemsStr = [];
  8469. this.textContentStream = null;
  8470. this.renderingDone = false;
  8471. this.pageIdx = pageIndex;
  8472. this.pageNumber = this.pageIdx + 1;
  8473. this.matches = [];
  8474. this.viewport = viewport;
  8475. this.textDivs = [];
  8476. this.findController = findController;
  8477. this.textLayerRenderTask = null;
  8478. this.enhanceTextSelection = enhanceTextSelection;
  8479. this._onUpdateTextLayerMatches = null;
  8480. this._bindMouse();
  8481. }
  8482. _finishRendering() {
  8483. this.renderingDone = true;
  8484. if (!this.enhanceTextSelection) {
  8485. const endOfContent = document.createElement("div");
  8486. endOfContent.className = "endOfContent";
  8487. this.textLayerDiv.appendChild(endOfContent);
  8488. }
  8489. this.eventBus.dispatch("textlayerrendered", {
  8490. source: this,
  8491. pageNumber: this.pageNumber,
  8492. numTextDivs: this.textDivs.length
  8493. });
  8494. }
  8495. render(timeout = 0) {
  8496. if (!(this.textContent || this.textContentStream) || this.renderingDone) {
  8497. return;
  8498. }
  8499. this.cancel();
  8500. this.textDivs = [];
  8501. const textLayerFrag = document.createDocumentFragment();
  8502. this.textLayerRenderTask = (0, _pdfjsLib.renderTextLayer)({
  8503. textContent: this.textContent,
  8504. textContentStream: this.textContentStream,
  8505. container: textLayerFrag,
  8506. viewport: this.viewport,
  8507. textDivs: this.textDivs,
  8508. textContentItemsStr: this.textContentItemsStr,
  8509. timeout,
  8510. enhanceTextSelection: this.enhanceTextSelection
  8511. });
  8512. this.textLayerRenderTask.promise.then(() => {
  8513. this.textLayerDiv.appendChild(textLayerFrag);
  8514. this._finishRendering();
  8515. this._updateMatches();
  8516. }, function (reason) {});
  8517. if (!this._onUpdateTextLayerMatches) {
  8518. this._onUpdateTextLayerMatches = evt => {
  8519. if (evt.pageIndex === this.pageIdx || evt.pageIndex === -1) {
  8520. this._updateMatches();
  8521. }
  8522. };
  8523. this.eventBus._on("updatetextlayermatches", this._onUpdateTextLayerMatches);
  8524. }
  8525. }
  8526. cancel() {
  8527. if (this.textLayerRenderTask) {
  8528. this.textLayerRenderTask.cancel();
  8529. this.textLayerRenderTask = null;
  8530. }
  8531. if (this._onUpdateTextLayerMatches) {
  8532. this.eventBus._off("updatetextlayermatches", this._onUpdateTextLayerMatches);
  8533. this._onUpdateTextLayerMatches = null;
  8534. }
  8535. }
  8536. setTextContentStream(readableStream) {
  8537. this.cancel();
  8538. this.textContentStream = readableStream;
  8539. }
  8540. setTextContent(textContent) {
  8541. this.cancel();
  8542. this.textContent = textContent;
  8543. }
  8544. _convertMatches(matches, matchesLength) {
  8545. if (!matches) {
  8546. return [];
  8547. }
  8548. const {
  8549. findController,
  8550. textContentItemsStr
  8551. } = this;
  8552. let i = 0,
  8553. iIndex = 0;
  8554. const end = textContentItemsStr.length - 1;
  8555. const queryLen = findController.state.query.length;
  8556. const result = [];
  8557. for (let m = 0, mm = matches.length; m < mm; m++) {
  8558. let matchIdx = matches[m];
  8559. while (i !== end && matchIdx >= iIndex + textContentItemsStr[i].length) {
  8560. iIndex += textContentItemsStr[i].length;
  8561. i++;
  8562. }
  8563. if (i === textContentItemsStr.length) {
  8564. console.error("Could not find a matching mapping");
  8565. }
  8566. const match = {
  8567. begin: {
  8568. divIdx: i,
  8569. offset: matchIdx - iIndex
  8570. }
  8571. };
  8572. if (matchesLength) {
  8573. matchIdx += matchesLength[m];
  8574. } else {
  8575. matchIdx += queryLen;
  8576. }
  8577. while (i !== end && matchIdx > iIndex + textContentItemsStr[i].length) {
  8578. iIndex += textContentItemsStr[i].length;
  8579. i++;
  8580. }
  8581. match.end = {
  8582. divIdx: i,
  8583. offset: matchIdx - iIndex
  8584. };
  8585. result.push(match);
  8586. }
  8587. return result;
  8588. }
  8589. _renderMatches(matches) {
  8590. if (matches.length === 0) {
  8591. return;
  8592. }
  8593. const {
  8594. findController,
  8595. pageIdx,
  8596. textContentItemsStr,
  8597. textDivs
  8598. } = this;
  8599. const isSelectedPage = pageIdx === findController.selected.pageIdx;
  8600. const selectedMatchIdx = findController.selected.matchIdx;
  8601. const highlightAll = findController.state.highlightAll;
  8602. let prevEnd = null;
  8603. const infinity = {
  8604. divIdx: -1,
  8605. offset: undefined
  8606. };
  8607. function beginText(begin, className) {
  8608. const divIdx = begin.divIdx;
  8609. textDivs[divIdx].textContent = "";
  8610. appendTextToDiv(divIdx, 0, begin.offset, className);
  8611. }
  8612. function appendTextToDiv(divIdx, fromOffset, toOffset, className) {
  8613. const div = textDivs[divIdx];
  8614. const content = textContentItemsStr[divIdx].substring(fromOffset, toOffset);
  8615. const node = document.createTextNode(content);
  8616. if (className) {
  8617. const span = document.createElement("span");
  8618. span.className = className;
  8619. span.appendChild(node);
  8620. div.appendChild(span);
  8621. return;
  8622. }
  8623. div.appendChild(node);
  8624. }
  8625. let i0 = selectedMatchIdx,
  8626. i1 = i0 + 1;
  8627. if (highlightAll) {
  8628. i0 = 0;
  8629. i1 = matches.length;
  8630. } else if (!isSelectedPage) {
  8631. return;
  8632. }
  8633. for (let i = i0; i < i1; i++) {
  8634. const match = matches[i];
  8635. const begin = match.begin;
  8636. const end = match.end;
  8637. const isSelected = isSelectedPage && i === selectedMatchIdx;
  8638. const highlightSuffix = isSelected ? " selected" : "";
  8639. if (isSelected) {
  8640. findController.scrollMatchIntoView({
  8641. element: textDivs[begin.divIdx],
  8642. pageIndex: pageIdx,
  8643. matchIndex: selectedMatchIdx
  8644. });
  8645. }
  8646. if (!prevEnd || begin.divIdx !== prevEnd.divIdx) {
  8647. if (prevEnd !== null) {
  8648. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset);
  8649. }
  8650. beginText(begin);
  8651. } else {
  8652. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, begin.offset);
  8653. }
  8654. if (begin.divIdx === end.divIdx) {
  8655. appendTextToDiv(begin.divIdx, begin.offset, end.offset, "highlight" + highlightSuffix);
  8656. } else {
  8657. appendTextToDiv(begin.divIdx, begin.offset, infinity.offset, "highlight begin" + highlightSuffix);
  8658. for (let n0 = begin.divIdx + 1, n1 = end.divIdx; n0 < n1; n0++) {
  8659. textDivs[n0].className = "highlight middle" + highlightSuffix;
  8660. }
  8661. beginText(end, "highlight end" + highlightSuffix);
  8662. }
  8663. prevEnd = end;
  8664. }
  8665. if (prevEnd) {
  8666. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset);
  8667. }
  8668. }
  8669. _updateMatches() {
  8670. if (!this.renderingDone) {
  8671. return;
  8672. }
  8673. const {
  8674. findController,
  8675. matches,
  8676. pageIdx,
  8677. textContentItemsStr,
  8678. textDivs
  8679. } = this;
  8680. let clearedUntilDivIdx = -1;
  8681. for (let i = 0, ii = matches.length; i < ii; i++) {
  8682. const match = matches[i];
  8683. const begin = Math.max(clearedUntilDivIdx, match.begin.divIdx);
  8684. for (let n = begin, end = match.end.divIdx; n <= end; n++) {
  8685. const div = textDivs[n];
  8686. div.textContent = textContentItemsStr[n];
  8687. div.className = "";
  8688. }
  8689. clearedUntilDivIdx = match.end.divIdx + 1;
  8690. }
  8691. if (!findController || !findController.highlightMatches) {
  8692. return;
  8693. }
  8694. const pageMatches = findController.pageMatches[pageIdx] || null;
  8695. const pageMatchesLength = findController.pageMatchesLength[pageIdx] || null;
  8696. this.matches = this._convertMatches(pageMatches, pageMatchesLength);
  8697. this._renderMatches(this.matches);
  8698. }
  8699. _bindMouse() {
  8700. const div = this.textLayerDiv;
  8701. let expandDivsTimer = null;
  8702. div.addEventListener("mousedown", evt => {
  8703. if (this.enhanceTextSelection && this.textLayerRenderTask) {
  8704. this.textLayerRenderTask.expandTextDivs(true);
  8705. if (expandDivsTimer) {
  8706. clearTimeout(expandDivsTimer);
  8707. expandDivsTimer = null;
  8708. }
  8709. return;
  8710. }
  8711. const end = div.querySelector(".endOfContent");
  8712. if (!end) {
  8713. return;
  8714. }
  8715. let adjustTop = evt.target !== div;
  8716. adjustTop = adjustTop && window.getComputedStyle(end).getPropertyValue("-moz-user-select") !== "none";
  8717. if (adjustTop) {
  8718. const divBounds = div.getBoundingClientRect();
  8719. const r = Math.max(0, (evt.pageY - divBounds.top) / divBounds.height);
  8720. end.style.top = (r * 100).toFixed(2) + "%";
  8721. }
  8722. end.classList.add("active");
  8723. });
  8724. div.addEventListener("mouseup", () => {
  8725. if (this.enhanceTextSelection && this.textLayerRenderTask) {
  8726. expandDivsTimer = setTimeout(() => {
  8727. if (this.textLayerRenderTask) {
  8728. this.textLayerRenderTask.expandTextDivs(false);
  8729. }
  8730. expandDivsTimer = null;
  8731. }, EXPAND_DIVS_TIMEOUT);
  8732. return;
  8733. }
  8734. const end = div.querySelector(".endOfContent");
  8735. if (!end) {
  8736. return;
  8737. }
  8738. end.style.top = "";
  8739. end.classList.remove("active");
  8740. });
  8741. }
  8742. }
  8743. exports.TextLayerBuilder = TextLayerBuilder;
  8744. class DefaultTextLayerFactory {
  8745. createTextLayerBuilder(textLayerDiv, pageIndex, viewport, enhanceTextSelection = false, eventBus) {
  8746. return new TextLayerBuilder({
  8747. textLayerDiv,
  8748. pageIndex,
  8749. viewport,
  8750. enhanceTextSelection,
  8751. eventBus
  8752. });
  8753. }
  8754. }
  8755. exports.DefaultTextLayerFactory = DefaultTextLayerFactory;
  8756. /***/ }),
  8757. /* 29 */
  8758. /***/ (function(module, exports, __webpack_require__) {
  8759. "use strict";
  8760. Object.defineProperty(exports, "__esModule", {
  8761. value: true
  8762. });
  8763. exports.SecondaryToolbar = void 0;
  8764. var _ui_utils = __webpack_require__(2);
  8765. var _pdf_cursor_tools = __webpack_require__(6);
  8766. var _pdf_single_page_viewer = __webpack_require__(30);
  8767. class SecondaryToolbar {
  8768. constructor(options, mainContainer, eventBus) {
  8769. this.toolbar = options.toolbar;
  8770. this.toggleButton = options.toggleButton;
  8771. this.toolbarButtonContainer = options.toolbarButtonContainer;
  8772. this.buttons = [{
  8773. element: options.presentationModeButton,
  8774. eventName: "presentationmode",
  8775. close: true
  8776. }, {
  8777. element: options.openFileButton,
  8778. eventName: "openfile",
  8779. close: true
  8780. }, {
  8781. element: options.printButton,
  8782. eventName: "print",
  8783. close: true
  8784. }, {
  8785. element: options.downloadButton,
  8786. eventName: "download",
  8787. close: true
  8788. }, {
  8789. element: options.viewBookmarkButton,
  8790. eventName: null,
  8791. close: true
  8792. }, {
  8793. element: options.firstPageButton,
  8794. eventName: "firstpage",
  8795. close: true
  8796. }, {
  8797. element: options.lastPageButton,
  8798. eventName: "lastpage",
  8799. close: true
  8800. }, {
  8801. element: options.pageRotateCwButton,
  8802. eventName: "rotatecw",
  8803. close: false
  8804. }, {
  8805. element: options.pageRotateCcwButton,
  8806. eventName: "rotateccw",
  8807. close: false
  8808. }, {
  8809. element: options.cursorSelectToolButton,
  8810. eventName: "switchcursortool",
  8811. eventDetails: {
  8812. tool: _pdf_cursor_tools.CursorTool.SELECT
  8813. },
  8814. close: true
  8815. }, {
  8816. element: options.cursorHandToolButton,
  8817. eventName: "switchcursortool",
  8818. eventDetails: {
  8819. tool: _pdf_cursor_tools.CursorTool.HAND
  8820. },
  8821. close: true
  8822. }, {
  8823. element: options.scrollVerticalButton,
  8824. eventName: "switchscrollmode",
  8825. eventDetails: {
  8826. mode: _ui_utils.ScrollMode.VERTICAL
  8827. },
  8828. close: true
  8829. }, {
  8830. element: options.scrollHorizontalButton,
  8831. eventName: "switchscrollmode",
  8832. eventDetails: {
  8833. mode: _ui_utils.ScrollMode.HORIZONTAL
  8834. },
  8835. close: true
  8836. }, {
  8837. element: options.scrollWrappedButton,
  8838. eventName: "switchscrollmode",
  8839. eventDetails: {
  8840. mode: _ui_utils.ScrollMode.WRAPPED
  8841. },
  8842. close: true
  8843. }, {
  8844. element: options.spreadNoneButton,
  8845. eventName: "switchspreadmode",
  8846. eventDetails: {
  8847. mode: _ui_utils.SpreadMode.NONE
  8848. },
  8849. close: true
  8850. }, {
  8851. element: options.spreadOddButton,
  8852. eventName: "switchspreadmode",
  8853. eventDetails: {
  8854. mode: _ui_utils.SpreadMode.ODD
  8855. },
  8856. close: true
  8857. }, {
  8858. element: options.spreadEvenButton,
  8859. eventName: "switchspreadmode",
  8860. eventDetails: {
  8861. mode: _ui_utils.SpreadMode.EVEN
  8862. },
  8863. close: true
  8864. }, {
  8865. element: options.documentPropertiesButton,
  8866. eventName: "documentproperties",
  8867. close: true
  8868. }];
  8869. this.items = {
  8870. firstPage: options.firstPageButton,
  8871. lastPage: options.lastPageButton,
  8872. pageRotateCw: options.pageRotateCwButton,
  8873. pageRotateCcw: options.pageRotateCcwButton
  8874. };
  8875. this.mainContainer = mainContainer;
  8876. this.eventBus = eventBus;
  8877. this.opened = false;
  8878. this.containerHeight = null;
  8879. this.previousContainerHeight = null;
  8880. this.reset();
  8881. this._bindClickListeners();
  8882. this._bindCursorToolsListener(options);
  8883. this._bindScrollModeListener(options);
  8884. this._bindSpreadModeListener(options);
  8885. this.eventBus._on("resize", this._setMaxHeight.bind(this));
  8886. this.eventBus._on("baseviewerinit", evt => {
  8887. if (evt.source instanceof _pdf_single_page_viewer.PDFSinglePageViewer) {
  8888. this.toolbarButtonContainer.classList.add("hiddenScrollModeButtons", "hiddenSpreadModeButtons");
  8889. } else {
  8890. this.toolbarButtonContainer.classList.remove("hiddenScrollModeButtons", "hiddenSpreadModeButtons");
  8891. }
  8892. });
  8893. }
  8894. get isOpen() {
  8895. return this.opened;
  8896. }
  8897. setPageNumber(pageNumber) {
  8898. this.pageNumber = pageNumber;
  8899. this._updateUIState();
  8900. }
  8901. setPagesCount(pagesCount) {
  8902. this.pagesCount = pagesCount;
  8903. this._updateUIState();
  8904. }
  8905. reset() {
  8906. this.pageNumber = 0;
  8907. this.pagesCount = 0;
  8908. this._updateUIState();
  8909. this.eventBus.dispatch("secondarytoolbarreset", {
  8910. source: this
  8911. });
  8912. }
  8913. _updateUIState() {
  8914. this.items.firstPage.disabled = this.pageNumber <= 1;
  8915. this.items.lastPage.disabled = this.pageNumber >= this.pagesCount;
  8916. this.items.pageRotateCw.disabled = this.pagesCount === 0;
  8917. this.items.pageRotateCcw.disabled = this.pagesCount === 0;
  8918. }
  8919. _bindClickListeners() {
  8920. this.toggleButton.addEventListener("click", this.toggle.bind(this));
  8921. for (const {
  8922. element,
  8923. eventName,
  8924. close,
  8925. eventDetails
  8926. } of this.buttons) {
  8927. element.addEventListener("click", evt => {
  8928. if (eventName !== null) {
  8929. const details = {
  8930. source: this
  8931. };
  8932. for (const property in eventDetails) {
  8933. details[property] = eventDetails[property];
  8934. }
  8935. this.eventBus.dispatch(eventName, details);
  8936. }
  8937. if (close) {
  8938. this.close();
  8939. }
  8940. });
  8941. }
  8942. }
  8943. _bindCursorToolsListener(buttons) {
  8944. this.eventBus._on("cursortoolchanged", function ({
  8945. tool
  8946. }) {
  8947. buttons.cursorSelectToolButton.classList.toggle("toggled", tool === _pdf_cursor_tools.CursorTool.SELECT);
  8948. buttons.cursorHandToolButton.classList.toggle("toggled", tool === _pdf_cursor_tools.CursorTool.HAND);
  8949. });
  8950. }
  8951. _bindScrollModeListener(buttons) {
  8952. function scrollModeChanged({
  8953. mode
  8954. }) {
  8955. buttons.scrollVerticalButton.classList.toggle("toggled", mode === _ui_utils.ScrollMode.VERTICAL);
  8956. buttons.scrollHorizontalButton.classList.toggle("toggled", mode === _ui_utils.ScrollMode.HORIZONTAL);
  8957. buttons.scrollWrappedButton.classList.toggle("toggled", mode === _ui_utils.ScrollMode.WRAPPED);
  8958. const isScrollModeHorizontal = mode === _ui_utils.ScrollMode.HORIZONTAL;
  8959. buttons.spreadNoneButton.disabled = isScrollModeHorizontal;
  8960. buttons.spreadOddButton.disabled = isScrollModeHorizontal;
  8961. buttons.spreadEvenButton.disabled = isScrollModeHorizontal;
  8962. }
  8963. this.eventBus._on("scrollmodechanged", scrollModeChanged);
  8964. this.eventBus._on("secondarytoolbarreset", evt => {
  8965. if (evt.source === this) {
  8966. scrollModeChanged({
  8967. mode: _ui_utils.ScrollMode.VERTICAL
  8968. });
  8969. }
  8970. });
  8971. }
  8972. _bindSpreadModeListener(buttons) {
  8973. function spreadModeChanged({
  8974. mode
  8975. }) {
  8976. buttons.spreadNoneButton.classList.toggle("toggled", mode === _ui_utils.SpreadMode.NONE);
  8977. buttons.spreadOddButton.classList.toggle("toggled", mode === _ui_utils.SpreadMode.ODD);
  8978. buttons.spreadEvenButton.classList.toggle("toggled", mode === _ui_utils.SpreadMode.EVEN);
  8979. }
  8980. this.eventBus._on("spreadmodechanged", spreadModeChanged);
  8981. this.eventBus._on("secondarytoolbarreset", evt => {
  8982. if (evt.source === this) {
  8983. spreadModeChanged({
  8984. mode: _ui_utils.SpreadMode.NONE
  8985. });
  8986. }
  8987. });
  8988. }
  8989. open() {
  8990. if (this.opened) {
  8991. return;
  8992. }
  8993. this.opened = true;
  8994. this._setMaxHeight();
  8995. this.toggleButton.classList.add("toggled");
  8996. this.toolbar.classList.remove("hidden");
  8997. }
  8998. close() {
  8999. if (!this.opened) {
  9000. return;
  9001. }
  9002. this.opened = false;
  9003. this.toolbar.classList.add("hidden");
  9004. this.toggleButton.classList.remove("toggled");
  9005. }
  9006. toggle() {
  9007. if (this.opened) {
  9008. this.close();
  9009. } else {
  9010. this.open();
  9011. }
  9012. }
  9013. _setMaxHeight() {
  9014. if (!this.opened) {
  9015. return;
  9016. }
  9017. this.containerHeight = this.mainContainer.clientHeight;
  9018. if (this.containerHeight === this.previousContainerHeight) {
  9019. return;
  9020. }
  9021. this.toolbarButtonContainer.style.maxHeight = `${this.containerHeight - _ui_utils.SCROLLBAR_PADDING}px`;
  9022. this.previousContainerHeight = this.containerHeight;
  9023. }
  9024. }
  9025. exports.SecondaryToolbar = SecondaryToolbar;
  9026. /***/ }),
  9027. /* 30 */
  9028. /***/ (function(module, exports, __webpack_require__) {
  9029. "use strict";
  9030. Object.defineProperty(exports, "__esModule", {
  9031. value: true
  9032. });
  9033. exports.PDFSinglePageViewer = void 0;
  9034. var _base_viewer = __webpack_require__(25);
  9035. var _pdfjsLib = __webpack_require__(4);
  9036. class PDFSinglePageViewer extends _base_viewer.BaseViewer {
  9037. constructor(options) {
  9038. super(options);
  9039. this.eventBus._on("pagesinit", evt => {
  9040. this._ensurePageViewVisible();
  9041. });
  9042. }
  9043. get _setDocumentViewerElement() {
  9044. return (0, _pdfjsLib.shadow)(this, "_setDocumentViewerElement", this._shadowViewer);
  9045. }
  9046. _resetView() {
  9047. super._resetView();
  9048. this._previousPageNumber = 1;
  9049. this._shadowViewer = document.createDocumentFragment();
  9050. this._updateScrollDown = null;
  9051. }
  9052. _ensurePageViewVisible() {
  9053. const pageView = this._pages[this._currentPageNumber - 1];
  9054. const previousPageView = this._pages[this._previousPageNumber - 1];
  9055. const viewerNodes = this.viewer.childNodes;
  9056. switch (viewerNodes.length) {
  9057. case 0:
  9058. this.viewer.appendChild(pageView.div);
  9059. break;
  9060. case 1:
  9061. if (viewerNodes[0] !== previousPageView.div) {
  9062. throw new Error("_ensurePageViewVisible: Unexpected previously visible page.");
  9063. }
  9064. if (pageView === previousPageView) {
  9065. break;
  9066. }
  9067. this._shadowViewer.appendChild(previousPageView.div);
  9068. this.viewer.appendChild(pageView.div);
  9069. this.container.scrollTop = 0;
  9070. break;
  9071. default:
  9072. throw new Error("_ensurePageViewVisible: Only one page should be visible at a time.");
  9073. }
  9074. this._previousPageNumber = this._currentPageNumber;
  9075. }
  9076. _scrollUpdate() {
  9077. if (this._updateScrollDown) {
  9078. this._updateScrollDown();
  9079. }
  9080. super._scrollUpdate();
  9081. }
  9082. _scrollIntoView({
  9083. pageDiv,
  9084. pageSpot = null,
  9085. pageNumber = null
  9086. }) {
  9087. if (pageNumber) {
  9088. this._setCurrentPageNumber(pageNumber);
  9089. }
  9090. const scrolledDown = this._currentPageNumber >= this._previousPageNumber;
  9091. this._ensurePageViewVisible();
  9092. this.update();
  9093. super._scrollIntoView({
  9094. pageDiv,
  9095. pageSpot,
  9096. pageNumber
  9097. });
  9098. this._updateScrollDown = () => {
  9099. this.scroll.down = scrolledDown;
  9100. this._updateScrollDown = null;
  9101. };
  9102. }
  9103. _getVisiblePages() {
  9104. return this._getCurrentVisiblePage();
  9105. }
  9106. _updateHelper(visiblePages) {}
  9107. get _isScrollModeHorizontal() {
  9108. return (0, _pdfjsLib.shadow)(this, "_isScrollModeHorizontal", false);
  9109. }
  9110. _updateScrollMode() {}
  9111. _updateSpreadMode() {}
  9112. }
  9113. exports.PDFSinglePageViewer = PDFSinglePageViewer;
  9114. /***/ }),
  9115. /* 31 */
  9116. /***/ (function(module, exports, __webpack_require__) {
  9117. "use strict";
  9118. Object.defineProperty(exports, "__esModule", {
  9119. value: true
  9120. });
  9121. exports.Toolbar = void 0;
  9122. var _ui_utils = __webpack_require__(2);
  9123. const PAGE_NUMBER_LOADING_INDICATOR = "visiblePageIsLoading";
  9124. const SCALE_SELECT_CONTAINER_WIDTH = 140;
  9125. const SCALE_SELECT_WIDTH = 162;
  9126. class Toolbar {
  9127. constructor(options, eventBus, l10n = _ui_utils.NullL10n) {
  9128. this.toolbar = options.container;
  9129. this.eventBus = eventBus;
  9130. this.l10n = l10n;
  9131. this.buttons = [{
  9132. element: options.previous,
  9133. eventName: "previouspage"
  9134. }, {
  9135. element: options.next,
  9136. eventName: "nextpage"
  9137. }, {
  9138. element: options.zoomIn,
  9139. eventName: "zoomin"
  9140. }, {
  9141. element: options.zoomOut,
  9142. eventName: "zoomout"
  9143. }, {
  9144. element: options.openFile,
  9145. eventName: "openfile"
  9146. }, {
  9147. element: options.print,
  9148. eventName: "print"
  9149. }, {
  9150. element: options.presentationModeButton,
  9151. eventName: "presentationmode"
  9152. }, {
  9153. element: options.download,
  9154. eventName: "download"
  9155. }, {
  9156. element: options.viewBookmark,
  9157. eventName: null
  9158. }];
  9159. this.items = {
  9160. numPages: options.numPages,
  9161. pageNumber: options.pageNumber,
  9162. scaleSelectContainer: options.scaleSelectContainer,
  9163. scaleSelect: options.scaleSelect,
  9164. customScaleOption: options.customScaleOption,
  9165. previous: options.previous,
  9166. next: options.next,
  9167. zoomIn: options.zoomIn,
  9168. zoomOut: options.zoomOut
  9169. };
  9170. this._wasLocalized = false;
  9171. this.reset();
  9172. this._bindListeners();
  9173. }
  9174. setPageNumber(pageNumber, pageLabel) {
  9175. this.pageNumber = pageNumber;
  9176. this.pageLabel = pageLabel;
  9177. this._updateUIState(false);
  9178. }
  9179. setPagesCount(pagesCount, hasPageLabels) {
  9180. this.pagesCount = pagesCount;
  9181. this.hasPageLabels = hasPageLabels;
  9182. this._updateUIState(true);
  9183. }
  9184. setPageScale(pageScaleValue, pageScale) {
  9185. this.pageScaleValue = (pageScaleValue || pageScale).toString();
  9186. this.pageScale = pageScale;
  9187. this._updateUIState(false);
  9188. }
  9189. reset() {
  9190. this.pageNumber = 0;
  9191. this.pageLabel = null;
  9192. this.hasPageLabels = false;
  9193. this.pagesCount = 0;
  9194. this.pageScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  9195. this.pageScale = _ui_utils.DEFAULT_SCALE;
  9196. this._updateUIState(true);
  9197. this.updateLoadingIndicatorState();
  9198. }
  9199. _bindListeners() {
  9200. const {
  9201. pageNumber,
  9202. scaleSelect
  9203. } = this.items;
  9204. const self = this;
  9205. for (const {
  9206. element,
  9207. eventName
  9208. } of this.buttons) {
  9209. element.addEventListener("click", evt => {
  9210. if (eventName !== null) {
  9211. this.eventBus.dispatch(eventName, {
  9212. source: this
  9213. });
  9214. }
  9215. });
  9216. }
  9217. pageNumber.addEventListener("click", function () {
  9218. this.select();
  9219. });
  9220. pageNumber.addEventListener("change", function () {
  9221. self.eventBus.dispatch("pagenumberchanged", {
  9222. source: self,
  9223. value: this.value
  9224. });
  9225. });
  9226. scaleSelect.addEventListener("change", function () {
  9227. if (this.value === "custom") {
  9228. return;
  9229. }
  9230. self.eventBus.dispatch("scalechanged", {
  9231. source: self,
  9232. value: this.value
  9233. });
  9234. });
  9235. scaleSelect.oncontextmenu = _ui_utils.noContextMenuHandler;
  9236. this.eventBus._on("localized", () => {
  9237. this._wasLocalized = true;
  9238. this._adjustScaleWidth();
  9239. this._updateUIState(true);
  9240. });
  9241. }
  9242. _updateUIState(resetNumPages = false) {
  9243. if (!this._wasLocalized) {
  9244. return;
  9245. }
  9246. const {
  9247. pageNumber,
  9248. pagesCount,
  9249. pageScaleValue,
  9250. pageScale,
  9251. items
  9252. } = this;
  9253. if (resetNumPages) {
  9254. if (this.hasPageLabels) {
  9255. items.pageNumber.type = "text";
  9256. } else {
  9257. items.pageNumber.type = "number";
  9258. this.l10n.get("of_pages", {
  9259. pagesCount
  9260. }, "of {{pagesCount}}").then(msg => {
  9261. items.numPages.textContent = msg;
  9262. });
  9263. }
  9264. items.pageNumber.max = pagesCount;
  9265. }
  9266. if (this.hasPageLabels) {
  9267. items.pageNumber.value = this.pageLabel;
  9268. this.l10n.get("page_of_pages", {
  9269. pageNumber,
  9270. pagesCount
  9271. }, "({{pageNumber}} of {{pagesCount}})").then(msg => {
  9272. items.numPages.textContent = msg;
  9273. });
  9274. } else {
  9275. items.pageNumber.value = pageNumber;
  9276. }
  9277. items.previous.disabled = pageNumber <= 1;
  9278. items.next.disabled = pageNumber >= pagesCount;
  9279. items.zoomOut.disabled = pageScale <= _ui_utils.MIN_SCALE;
  9280. items.zoomIn.disabled = pageScale >= _ui_utils.MAX_SCALE;
  9281. const customScale = Math.round(pageScale * 10000) / 100;
  9282. this.l10n.get("page_scale_percent", {
  9283. scale: customScale
  9284. }, "{{scale}}%").then(msg => {
  9285. let predefinedValueFound = false;
  9286. for (const option of items.scaleSelect.options) {
  9287. if (option.value !== pageScaleValue) {
  9288. option.selected = false;
  9289. continue;
  9290. }
  9291. option.selected = true;
  9292. predefinedValueFound = true;
  9293. }
  9294. if (!predefinedValueFound) {
  9295. items.customScaleOption.textContent = msg;
  9296. items.customScaleOption.selected = true;
  9297. }
  9298. });
  9299. }
  9300. updateLoadingIndicatorState(loading = false) {
  9301. const pageNumberInput = this.items.pageNumber;
  9302. pageNumberInput.classList.toggle(PAGE_NUMBER_LOADING_INDICATOR, loading);
  9303. }
  9304. async _adjustScaleWidth() {
  9305. const {
  9306. items,
  9307. l10n
  9308. } = this;
  9309. const predefinedValuesPromise = Promise.all([l10n.get("page_scale_auto", null, "Automatic Zoom"), l10n.get("page_scale_actual", null, "Actual Size"), l10n.get("page_scale_fit", null, "Page Fit"), l10n.get("page_scale_width", null, "Page Width")]);
  9310. let canvas = document.createElement("canvas");
  9311. canvas.mozOpaque = true;
  9312. let ctx = canvas.getContext("2d", {
  9313. alpha: false
  9314. });
  9315. await _ui_utils.animationStarted;
  9316. const {
  9317. fontSize,
  9318. fontFamily
  9319. } = getComputedStyle(items.scaleSelect);
  9320. ctx.font = `${fontSize} ${fontFamily}`;
  9321. let maxWidth = 0;
  9322. for (const predefinedValue of await predefinedValuesPromise) {
  9323. const {
  9324. width
  9325. } = ctx.measureText(predefinedValue);
  9326. if (width > maxWidth) {
  9327. maxWidth = width;
  9328. }
  9329. }
  9330. const overflow = SCALE_SELECT_WIDTH - SCALE_SELECT_CONTAINER_WIDTH;
  9331. maxWidth += 1.5 * overflow;
  9332. if (maxWidth > SCALE_SELECT_CONTAINER_WIDTH) {
  9333. items.scaleSelect.style.width = `${maxWidth + overflow}px`;
  9334. items.scaleSelectContainer.style.width = `${maxWidth}px`;
  9335. }
  9336. canvas.width = 0;
  9337. canvas.height = 0;
  9338. canvas = ctx = null;
  9339. }
  9340. }
  9341. exports.Toolbar = Toolbar;
  9342. /***/ }),
  9343. /* 32 */
  9344. /***/ (function(module, exports, __webpack_require__) {
  9345. "use strict";
  9346. Object.defineProperty(exports, "__esModule", {
  9347. value: true
  9348. });
  9349. exports.ViewHistory = void 0;
  9350. const DEFAULT_VIEW_HISTORY_CACHE_SIZE = 20;
  9351. class ViewHistory {
  9352. constructor(fingerprint, cacheSize = DEFAULT_VIEW_HISTORY_CACHE_SIZE) {
  9353. this.fingerprint = fingerprint;
  9354. this.cacheSize = cacheSize;
  9355. this._initializedPromise = this._readFromStorage().then(databaseStr => {
  9356. const database = JSON.parse(databaseStr || "{}");
  9357. if (!("files" in database)) {
  9358. database.files = [];
  9359. } else {
  9360. while (database.files.length >= this.cacheSize) {
  9361. database.files.shift();
  9362. }
  9363. }
  9364. let index = -1;
  9365. for (let i = 0, length = database.files.length; i < length; i++) {
  9366. const branch = database.files[i];
  9367. if (branch.fingerprint === this.fingerprint) {
  9368. index = i;
  9369. break;
  9370. }
  9371. }
  9372. if (index === -1) {
  9373. index = database.files.push({
  9374. fingerprint: this.fingerprint
  9375. }) - 1;
  9376. }
  9377. this.file = database.files[index];
  9378. this.database = database;
  9379. });
  9380. }
  9381. async _writeToStorage() {
  9382. const databaseStr = JSON.stringify(this.database);
  9383. localStorage.setItem("pdfjs.history", databaseStr);
  9384. }
  9385. async _readFromStorage() {
  9386. return localStorage.getItem("pdfjs.history");
  9387. }
  9388. async set(name, val) {
  9389. await this._initializedPromise;
  9390. this.file[name] = val;
  9391. return this._writeToStorage();
  9392. }
  9393. async setMultiple(properties) {
  9394. await this._initializedPromise;
  9395. for (const name in properties) {
  9396. this.file[name] = properties[name];
  9397. }
  9398. return this._writeToStorage();
  9399. }
  9400. async get(name, defaultValue) {
  9401. await this._initializedPromise;
  9402. const val = this.file[name];
  9403. return val !== undefined ? val : defaultValue;
  9404. }
  9405. async getMultiple(properties) {
  9406. await this._initializedPromise;
  9407. const values = Object.create(null);
  9408. for (const name in properties) {
  9409. const val = this.file[name];
  9410. values[name] = val !== undefined ? val : properties[name];
  9411. }
  9412. return values;
  9413. }
  9414. }
  9415. exports.ViewHistory = ViewHistory;
  9416. /***/ }),
  9417. /* 33 */
  9418. /***/ (function(module, exports, __webpack_require__) {
  9419. "use strict";
  9420. Object.defineProperty(exports, "__esModule", {
  9421. value: true
  9422. });
  9423. exports.GenericCom = void 0;
  9424. var _app = __webpack_require__(1);
  9425. var _preferences = __webpack_require__(34);
  9426. var _download_manager = __webpack_require__(35);
  9427. var _genericl10n = __webpack_require__(36);
  9428. ;
  9429. const GenericCom = {};
  9430. exports.GenericCom = GenericCom;
  9431. class GenericPreferences extends _preferences.BasePreferences {
  9432. async _writeToStorage(prefObj) {
  9433. localStorage.setItem("pdfjs.preferences", JSON.stringify(prefObj));
  9434. }
  9435. async _readFromStorage(prefObj) {
  9436. return JSON.parse(localStorage.getItem("pdfjs.preferences"));
  9437. }
  9438. }
  9439. class GenericExternalServices extends _app.DefaultExternalServices {
  9440. static createDownloadManager(options) {
  9441. return new _download_manager.DownloadManager(options);
  9442. }
  9443. static createPreferences() {
  9444. return new GenericPreferences();
  9445. }
  9446. static createL10n({
  9447. locale = "en-US"
  9448. }) {
  9449. return new _genericl10n.GenericL10n(locale);
  9450. }
  9451. }
  9452. _app.PDFViewerApplication.externalServices = GenericExternalServices;
  9453. /***/ }),
  9454. /* 34 */
  9455. /***/ (function(module, exports, __webpack_require__) {
  9456. "use strict";
  9457. Object.defineProperty(exports, "__esModule", {
  9458. value: true
  9459. });
  9460. exports.BasePreferences = void 0;
  9461. let defaultPreferences = null;
  9462. function getDefaultPreferences() {
  9463. if (!defaultPreferences) {
  9464. defaultPreferences = Promise.resolve({
  9465. "cursorToolOnLoad": 0,
  9466. "defaultZoomValue": "",
  9467. "disablePageLabels": false,
  9468. "enablePrintAutoRotate": false,
  9469. "enableWebGL": false,
  9470. "eventBusDispatchToDOM": false,
  9471. "externalLinkTarget": 0,
  9472. "historyUpdateUrl": false,
  9473. "ignoreDestinationZoom": false,
  9474. "pdfBugEnabled": false,
  9475. "renderer": "canvas",
  9476. "renderInteractiveForms": false,
  9477. "sidebarViewOnLoad": -1,
  9478. "scrollModeOnLoad": -1,
  9479. "spreadModeOnLoad": -1,
  9480. "textLayerMode": 1,
  9481. "useOnlyCssZoom": false,
  9482. "viewOnLoad": 0,
  9483. "disableAutoFetch": false,
  9484. "disableFontFace": false,
  9485. "disableRange": false,
  9486. "disableStream": false
  9487. });
  9488. }
  9489. return defaultPreferences;
  9490. }
  9491. class BasePreferences {
  9492. constructor() {
  9493. if (this.constructor === BasePreferences) {
  9494. throw new Error("Cannot initialize BasePreferences.");
  9495. }
  9496. this.prefs = null;
  9497. this._initializedPromise = getDefaultPreferences().then(defaults => {
  9498. Object.defineProperty(this, "defaults", {
  9499. value: Object.freeze(defaults),
  9500. writable: false,
  9501. enumerable: true,
  9502. configurable: false
  9503. });
  9504. this.prefs = Object.assign(Object.create(null), defaults);
  9505. return this._readFromStorage(defaults);
  9506. }).then(prefs => {
  9507. if (!prefs) {
  9508. return;
  9509. }
  9510. for (const name in prefs) {
  9511. const defaultValue = this.defaults[name],
  9512. prefValue = prefs[name];
  9513. if (defaultValue === undefined || typeof prefValue !== typeof defaultValue) {
  9514. continue;
  9515. }
  9516. this.prefs[name] = prefValue;
  9517. }
  9518. });
  9519. }
  9520. async _writeToStorage(prefObj) {
  9521. throw new Error("Not implemented: _writeToStorage");
  9522. }
  9523. async _readFromStorage(prefObj) {
  9524. throw new Error("Not implemented: _readFromStorage");
  9525. }
  9526. async reset() {
  9527. await this._initializedPromise;
  9528. this.prefs = Object.assign(Object.create(null), this.defaults);
  9529. return this._writeToStorage(this.defaults);
  9530. }
  9531. async set(name, value) {
  9532. await this._initializedPromise;
  9533. const defaultValue = this.defaults[name];
  9534. if (defaultValue === undefined) {
  9535. throw new Error(`Set preference: "${name}" is undefined.`);
  9536. } else if (value === undefined) {
  9537. throw new Error("Set preference: no value is specified.");
  9538. }
  9539. const valueType = typeof value;
  9540. const defaultType = typeof defaultValue;
  9541. if (valueType !== defaultType) {
  9542. if (valueType === "number" && defaultType === "string") {
  9543. value = value.toString();
  9544. } else {
  9545. throw new Error(`Set preference: "${value}" is a ${valueType}, ` + `expected a ${defaultType}.`);
  9546. }
  9547. } else {
  9548. if (valueType === "number" && !Number.isInteger(value)) {
  9549. throw new Error(`Set preference: "${value}" must be an integer.`);
  9550. }
  9551. }
  9552. this.prefs[name] = value;
  9553. return this._writeToStorage(this.prefs);
  9554. }
  9555. async get(name) {
  9556. await this._initializedPromise;
  9557. const defaultValue = this.defaults[name];
  9558. if (defaultValue === undefined) {
  9559. throw new Error(`Get preference: "${name}" is undefined.`);
  9560. } else {
  9561. const prefValue = this.prefs[name];
  9562. if (prefValue !== undefined) {
  9563. return prefValue;
  9564. }
  9565. }
  9566. return defaultValue;
  9567. }
  9568. async getAll() {
  9569. await this._initializedPromise;
  9570. return Object.assign(Object.create(null), this.defaults, this.prefs);
  9571. }
  9572. }
  9573. exports.BasePreferences = BasePreferences;
  9574. /***/ }),
  9575. /* 35 */
  9576. /***/ (function(module, exports, __webpack_require__) {
  9577. "use strict";
  9578. Object.defineProperty(exports, "__esModule", {
  9579. value: true
  9580. });
  9581. exports.DownloadManager = void 0;
  9582. var _pdfjsLib = __webpack_require__(4);
  9583. ;
  9584. const DISABLE_CREATE_OBJECT_URL = _pdfjsLib.apiCompatibilityParams.disableCreateObjectURL || false;
  9585. function download(blobUrl, filename) {
  9586. const a = document.createElement("a");
  9587. if (!a.click) {
  9588. throw new Error('DownloadManager: "a.click()" is not supported.');
  9589. }
  9590. a.href = blobUrl;
  9591. a.target = "_parent";
  9592. if ("download" in a) {
  9593. a.download = filename;
  9594. }
  9595. (document.body || document.documentElement).appendChild(a);
  9596. a.click();
  9597. a.remove();
  9598. }
  9599. class DownloadManager {
  9600. constructor({
  9601. disableCreateObjectURL = DISABLE_CREATE_OBJECT_URL
  9602. }) {
  9603. this.disableCreateObjectURL = disableCreateObjectURL;
  9604. }
  9605. downloadUrl(url, filename) {
  9606. if (!(0, _pdfjsLib.createValidAbsoluteUrl)(url, "http://example.com")) {
  9607. return;
  9608. }
  9609. download(url + "#pdfjs.action=download", filename);
  9610. }
  9611. downloadData(data, filename, contentType) {
  9612. if (navigator.msSaveBlob) {
  9613. navigator.msSaveBlob(new Blob([data], {
  9614. type: contentType
  9615. }), filename);
  9616. return;
  9617. }
  9618. const blobUrl = (0, _pdfjsLib.createObjectURL)(data, contentType, this.disableCreateObjectURL);
  9619. download(blobUrl, filename);
  9620. }
  9621. download(blob, url, filename) {
  9622. if (navigator.msSaveBlob) {
  9623. if (!navigator.msSaveBlob(blob, filename)) {
  9624. this.downloadUrl(url, filename);
  9625. }
  9626. return;
  9627. }
  9628. if (this.disableCreateObjectURL) {
  9629. this.downloadUrl(url, filename);
  9630. return;
  9631. }
  9632. const blobUrl = URL.createObjectURL(blob);
  9633. download(blobUrl, filename);
  9634. }
  9635. }
  9636. exports.DownloadManager = DownloadManager;
  9637. /***/ }),
  9638. /* 36 */
  9639. /***/ (function(module, exports, __webpack_require__) {
  9640. "use strict";
  9641. Object.defineProperty(exports, "__esModule", {
  9642. value: true
  9643. });
  9644. exports.GenericL10n = void 0;
  9645. __webpack_require__(37);
  9646. const webL10n = document.webL10n;
  9647. class GenericL10n {
  9648. constructor(lang) {
  9649. this._lang = lang;
  9650. this._ready = new Promise((resolve, reject) => {
  9651. webL10n.setLanguage(lang, () => {
  9652. resolve(webL10n);
  9653. });
  9654. });
  9655. }
  9656. async getLanguage() {
  9657. const l10n = await this._ready;
  9658. return l10n.getLanguage();
  9659. }
  9660. async getDirection() {
  9661. const l10n = await this._ready;
  9662. return l10n.getDirection();
  9663. }
  9664. async get(property, args, fallback) {
  9665. const l10n = await this._ready;
  9666. return l10n.get(property, args, fallback);
  9667. }
  9668. async translate(element) {
  9669. const l10n = await this._ready;
  9670. return l10n.translate(element);
  9671. }
  9672. }
  9673. exports.GenericL10n = GenericL10n;
  9674. /***/ }),
  9675. /* 37 */
  9676. /***/ (function(module, exports, __webpack_require__) {
  9677. "use strict";
  9678. document.webL10n = function (window, document, undefined) {
  9679. var gL10nData = {};
  9680. var gTextData = '';
  9681. var gTextProp = 'textContent';
  9682. var gLanguage = '';
  9683. var gMacros = {};
  9684. var gReadyState = 'loading';
  9685. var gAsyncResourceLoading = true;
  9686. function getL10nResourceLinks() {
  9687. return document.querySelectorAll('link[type="application/l10n"]');
  9688. }
  9689. function getL10nDictionary() {
  9690. var script = document.querySelector('script[type="application/l10n"]');
  9691. return script ? JSON.parse(script.innerHTML) : null;
  9692. }
  9693. function getTranslatableChildren(element) {
  9694. return element ? element.querySelectorAll('*[data-l10n-id]') : [];
  9695. }
  9696. function getL10nAttributes(element) {
  9697. if (!element) return {};
  9698. var l10nId = element.getAttribute('data-l10n-id');
  9699. var l10nArgs = element.getAttribute('data-l10n-args');
  9700. var args = {};
  9701. if (l10nArgs) {
  9702. try {
  9703. args = JSON.parse(l10nArgs);
  9704. } catch (e) {
  9705. console.warn('could not parse arguments for #' + l10nId);
  9706. }
  9707. }
  9708. return {
  9709. id: l10nId,
  9710. args: args
  9711. };
  9712. }
  9713. function xhrLoadText(url, onSuccess, onFailure) {
  9714. onSuccess = onSuccess || function _onSuccess(data) {};
  9715. onFailure = onFailure || function _onFailure() {};
  9716. var xhr = new XMLHttpRequest();
  9717. xhr.open('GET', url, gAsyncResourceLoading);
  9718. if (xhr.overrideMimeType) {
  9719. xhr.overrideMimeType('text/plain; charset=utf-8');
  9720. }
  9721. xhr.onreadystatechange = function () {
  9722. if (xhr.readyState == 4) {
  9723. if (xhr.status == 200 || xhr.status === 0) {
  9724. onSuccess(xhr.responseText);
  9725. } else {
  9726. onFailure();
  9727. }
  9728. }
  9729. };
  9730. xhr.onerror = onFailure;
  9731. xhr.ontimeout = onFailure;
  9732. try {
  9733. xhr.send(null);
  9734. } catch (e) {
  9735. onFailure();
  9736. }
  9737. }
  9738. function parseResource(href, lang, successCallback, failureCallback) {
  9739. var baseURL = href.replace(/[^\/]*$/, '') || './';
  9740. function evalString(text) {
  9741. if (text.lastIndexOf('\\') < 0) return text;
  9742. 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, "'");
  9743. }
  9744. function parseProperties(text, parsedPropertiesCallback) {
  9745. var dictionary = {};
  9746. var reBlank = /^\s*|\s*$/;
  9747. var reComment = /^\s*#|^\s*$/;
  9748. var reSection = /^\s*\[(.*)\]\s*$/;
  9749. var reImport = /^\s*@import\s+url\((.*)\)\s*$/i;
  9750. var reSplit = /^([^=\s]*)\s*=\s*(.+)$/;
  9751. function parseRawLines(rawText, extendedSyntax, parsedRawLinesCallback) {
  9752. var entries = rawText.replace(reBlank, '').split(/[\r\n]+/);
  9753. var currentLang = '*';
  9754. var genericLang = lang.split('-', 1)[0];
  9755. var skipLang = false;
  9756. var match = '';
  9757. function nextEntry() {
  9758. while (true) {
  9759. if (!entries.length) {
  9760. parsedRawLinesCallback();
  9761. return;
  9762. }
  9763. var line = entries.shift();
  9764. if (reComment.test(line)) continue;
  9765. if (extendedSyntax) {
  9766. match = reSection.exec(line);
  9767. if (match) {
  9768. currentLang = match[1].toLowerCase();
  9769. skipLang = currentLang !== '*' && currentLang !== lang && currentLang !== genericLang;
  9770. continue;
  9771. } else if (skipLang) {
  9772. continue;
  9773. }
  9774. match = reImport.exec(line);
  9775. if (match) {
  9776. loadImport(baseURL + match[1], nextEntry);
  9777. return;
  9778. }
  9779. }
  9780. var tmp = line.match(reSplit);
  9781. if (tmp && tmp.length == 3) {
  9782. dictionary[tmp[1]] = evalString(tmp[2]);
  9783. }
  9784. }
  9785. }
  9786. nextEntry();
  9787. }
  9788. function loadImport(url, callback) {
  9789. xhrLoadText(url, function (content) {
  9790. parseRawLines(content, false, callback);
  9791. }, function () {
  9792. console.warn(url + ' not found.');
  9793. callback();
  9794. });
  9795. }
  9796. parseRawLines(text, true, function () {
  9797. parsedPropertiesCallback(dictionary);
  9798. });
  9799. }
  9800. xhrLoadText(href, function (response) {
  9801. gTextData += response;
  9802. parseProperties(response, function (data) {
  9803. for (var key in data) {
  9804. var id,
  9805. prop,
  9806. index = key.lastIndexOf('.');
  9807. if (index > 0) {
  9808. id = key.substring(0, index);
  9809. prop = key.substring(index + 1);
  9810. } else {
  9811. id = key;
  9812. prop = gTextProp;
  9813. }
  9814. if (!gL10nData[id]) {
  9815. gL10nData[id] = {};
  9816. }
  9817. gL10nData[id][prop] = data[key];
  9818. }
  9819. if (successCallback) {
  9820. successCallback();
  9821. }
  9822. });
  9823. }, failureCallback);
  9824. }
  9825. function loadLocale(lang, callback) {
  9826. if (lang) {
  9827. lang = lang.toLowerCase();
  9828. }
  9829. callback = callback || function _callback() {};
  9830. clear();
  9831. gLanguage = lang;
  9832. var langLinks = getL10nResourceLinks();
  9833. var langCount = langLinks.length;
  9834. if (langCount === 0) {
  9835. var dict = getL10nDictionary();
  9836. if (dict && dict.locales && dict.default_locale) {
  9837. console.log('using the embedded JSON directory, early way out');
  9838. gL10nData = dict.locales[lang];
  9839. if (!gL10nData) {
  9840. var defaultLocale = dict.default_locale.toLowerCase();
  9841. for (var anyCaseLang in dict.locales) {
  9842. anyCaseLang = anyCaseLang.toLowerCase();
  9843. if (anyCaseLang === lang) {
  9844. gL10nData = dict.locales[lang];
  9845. break;
  9846. } else if (anyCaseLang === defaultLocale) {
  9847. gL10nData = dict.locales[defaultLocale];
  9848. }
  9849. }
  9850. }
  9851. callback();
  9852. } else {
  9853. console.log('no resource to load, early way out');
  9854. }
  9855. gReadyState = 'complete';
  9856. return;
  9857. }
  9858. var onResourceLoaded = null;
  9859. var gResourceCount = 0;
  9860. onResourceLoaded = function () {
  9861. gResourceCount++;
  9862. if (gResourceCount >= langCount) {
  9863. callback();
  9864. gReadyState = 'complete';
  9865. }
  9866. };
  9867. function L10nResourceLink(link) {
  9868. var href = link.href;
  9869. this.load = function (lang, callback) {
  9870. parseResource(href, lang, callback, function () {
  9871. console.warn(href + ' not found.');
  9872. console.warn('"' + lang + '" resource not found');
  9873. gLanguage = '';
  9874. callback();
  9875. });
  9876. };
  9877. }
  9878. for (var i = 0; i < langCount; i++) {
  9879. var resource = new L10nResourceLink(langLinks[i]);
  9880. resource.load(lang, onResourceLoaded);
  9881. }
  9882. }
  9883. function clear() {
  9884. gL10nData = {};
  9885. gTextData = '';
  9886. gLanguage = '';
  9887. }
  9888. function getPluralRules(lang) {
  9889. var locales2rules = {
  9890. 'af': 3,
  9891. 'ak': 4,
  9892. 'am': 4,
  9893. 'ar': 1,
  9894. 'asa': 3,
  9895. 'az': 0,
  9896. 'be': 11,
  9897. 'bem': 3,
  9898. 'bez': 3,
  9899. 'bg': 3,
  9900. 'bh': 4,
  9901. 'bm': 0,
  9902. 'bn': 3,
  9903. 'bo': 0,
  9904. 'br': 20,
  9905. 'brx': 3,
  9906. 'bs': 11,
  9907. 'ca': 3,
  9908. 'cgg': 3,
  9909. 'chr': 3,
  9910. 'cs': 12,
  9911. 'cy': 17,
  9912. 'da': 3,
  9913. 'de': 3,
  9914. 'dv': 3,
  9915. 'dz': 0,
  9916. 'ee': 3,
  9917. 'el': 3,
  9918. 'en': 3,
  9919. 'eo': 3,
  9920. 'es': 3,
  9921. 'et': 3,
  9922. 'eu': 3,
  9923. 'fa': 0,
  9924. 'ff': 5,
  9925. 'fi': 3,
  9926. 'fil': 4,
  9927. 'fo': 3,
  9928. 'fr': 5,
  9929. 'fur': 3,
  9930. 'fy': 3,
  9931. 'ga': 8,
  9932. 'gd': 24,
  9933. 'gl': 3,
  9934. 'gsw': 3,
  9935. 'gu': 3,
  9936. 'guw': 4,
  9937. 'gv': 23,
  9938. 'ha': 3,
  9939. 'haw': 3,
  9940. 'he': 2,
  9941. 'hi': 4,
  9942. 'hr': 11,
  9943. 'hu': 0,
  9944. 'id': 0,
  9945. 'ig': 0,
  9946. 'ii': 0,
  9947. 'is': 3,
  9948. 'it': 3,
  9949. 'iu': 7,
  9950. 'ja': 0,
  9951. 'jmc': 3,
  9952. 'jv': 0,
  9953. 'ka': 0,
  9954. 'kab': 5,
  9955. 'kaj': 3,
  9956. 'kcg': 3,
  9957. 'kde': 0,
  9958. 'kea': 0,
  9959. 'kk': 3,
  9960. 'kl': 3,
  9961. 'km': 0,
  9962. 'kn': 0,
  9963. 'ko': 0,
  9964. 'ksb': 3,
  9965. 'ksh': 21,
  9966. 'ku': 3,
  9967. 'kw': 7,
  9968. 'lag': 18,
  9969. 'lb': 3,
  9970. 'lg': 3,
  9971. 'ln': 4,
  9972. 'lo': 0,
  9973. 'lt': 10,
  9974. 'lv': 6,
  9975. 'mas': 3,
  9976. 'mg': 4,
  9977. 'mk': 16,
  9978. 'ml': 3,
  9979. 'mn': 3,
  9980. 'mo': 9,
  9981. 'mr': 3,
  9982. 'ms': 0,
  9983. 'mt': 15,
  9984. 'my': 0,
  9985. 'nah': 3,
  9986. 'naq': 7,
  9987. 'nb': 3,
  9988. 'nd': 3,
  9989. 'ne': 3,
  9990. 'nl': 3,
  9991. 'nn': 3,
  9992. 'no': 3,
  9993. 'nr': 3,
  9994. 'nso': 4,
  9995. 'ny': 3,
  9996. 'nyn': 3,
  9997. 'om': 3,
  9998. 'or': 3,
  9999. 'pa': 3,
  10000. 'pap': 3,
  10001. 'pl': 13,
  10002. 'ps': 3,
  10003. 'pt': 3,
  10004. 'rm': 3,
  10005. 'ro': 9,
  10006. 'rof': 3,
  10007. 'ru': 11,
  10008. 'rwk': 3,
  10009. 'sah': 0,
  10010. 'saq': 3,
  10011. 'se': 7,
  10012. 'seh': 3,
  10013. 'ses': 0,
  10014. 'sg': 0,
  10015. 'sh': 11,
  10016. 'shi': 19,
  10017. 'sk': 12,
  10018. 'sl': 14,
  10019. 'sma': 7,
  10020. 'smi': 7,
  10021. 'smj': 7,
  10022. 'smn': 7,
  10023. 'sms': 7,
  10024. 'sn': 3,
  10025. 'so': 3,
  10026. 'sq': 3,
  10027. 'sr': 11,
  10028. 'ss': 3,
  10029. 'ssy': 3,
  10030. 'st': 3,
  10031. 'sv': 3,
  10032. 'sw': 3,
  10033. 'syr': 3,
  10034. 'ta': 3,
  10035. 'te': 3,
  10036. 'teo': 3,
  10037. 'th': 0,
  10038. 'ti': 4,
  10039. 'tig': 3,
  10040. 'tk': 3,
  10041. 'tl': 4,
  10042. 'tn': 3,
  10043. 'to': 0,
  10044. 'tr': 0,
  10045. 'ts': 3,
  10046. 'tzm': 22,
  10047. 'uk': 11,
  10048. 'ur': 3,
  10049. 've': 3,
  10050. 'vi': 0,
  10051. 'vun': 3,
  10052. 'wa': 4,
  10053. 'wae': 3,
  10054. 'wo': 0,
  10055. 'xh': 3,
  10056. 'xog': 3,
  10057. 'yo': 0,
  10058. 'zh': 0,
  10059. 'zu': 3
  10060. };
  10061. function isIn(n, list) {
  10062. return list.indexOf(n) !== -1;
  10063. }
  10064. function isBetween(n, start, end) {
  10065. return start <= n && n <= end;
  10066. }
  10067. var pluralRules = {
  10068. '0': function (n) {
  10069. return 'other';
  10070. },
  10071. '1': function (n) {
  10072. if (isBetween(n % 100, 3, 10)) return 'few';
  10073. if (n === 0) return 'zero';
  10074. if (isBetween(n % 100, 11, 99)) return 'many';
  10075. if (n == 2) return 'two';
  10076. if (n == 1) return 'one';
  10077. return 'other';
  10078. },
  10079. '2': function (n) {
  10080. if (n !== 0 && n % 10 === 0) return 'many';
  10081. if (n == 2) return 'two';
  10082. if (n == 1) return 'one';
  10083. return 'other';
  10084. },
  10085. '3': function (n) {
  10086. if (n == 1) return 'one';
  10087. return 'other';
  10088. },
  10089. '4': function (n) {
  10090. if (isBetween(n, 0, 1)) return 'one';
  10091. return 'other';
  10092. },
  10093. '5': function (n) {
  10094. if (isBetween(n, 0, 2) && n != 2) return 'one';
  10095. return 'other';
  10096. },
  10097. '6': function (n) {
  10098. if (n === 0) return 'zero';
  10099. if (n % 10 == 1 && n % 100 != 11) return 'one';
  10100. return 'other';
  10101. },
  10102. '7': function (n) {
  10103. if (n == 2) return 'two';
  10104. if (n == 1) return 'one';
  10105. return 'other';
  10106. },
  10107. '8': function (n) {
  10108. if (isBetween(n, 3, 6)) return 'few';
  10109. if (isBetween(n, 7, 10)) return 'many';
  10110. if (n == 2) return 'two';
  10111. if (n == 1) return 'one';
  10112. return 'other';
  10113. },
  10114. '9': function (n) {
  10115. if (n === 0 || n != 1 && isBetween(n % 100, 1, 19)) return 'few';
  10116. if (n == 1) return 'one';
  10117. return 'other';
  10118. },
  10119. '10': function (n) {
  10120. if (isBetween(n % 10, 2, 9) && !isBetween(n % 100, 11, 19)) return 'few';
  10121. if (n % 10 == 1 && !isBetween(n % 100, 11, 19)) return 'one';
  10122. return 'other';
  10123. },
  10124. '11': function (n) {
  10125. if (isBetween(n % 10, 2, 4) && !isBetween(n % 100, 12, 14)) return 'few';
  10126. if (n % 10 === 0 || isBetween(n % 10, 5, 9) || isBetween(n % 100, 11, 14)) return 'many';
  10127. if (n % 10 == 1 && n % 100 != 11) return 'one';
  10128. return 'other';
  10129. },
  10130. '12': function (n) {
  10131. if (isBetween(n, 2, 4)) return 'few';
  10132. if (n == 1) return 'one';
  10133. return 'other';
  10134. },
  10135. '13': function (n) {
  10136. if (isBetween(n % 10, 2, 4) && !isBetween(n % 100, 12, 14)) return 'few';
  10137. if (n != 1 && isBetween(n % 10, 0, 1) || isBetween(n % 10, 5, 9) || isBetween(n % 100, 12, 14)) return 'many';
  10138. if (n == 1) return 'one';
  10139. return 'other';
  10140. },
  10141. '14': function (n) {
  10142. if (isBetween(n % 100, 3, 4)) return 'few';
  10143. if (n % 100 == 2) return 'two';
  10144. if (n % 100 == 1) return 'one';
  10145. return 'other';
  10146. },
  10147. '15': function (n) {
  10148. if (n === 0 || isBetween(n % 100, 2, 10)) return 'few';
  10149. if (isBetween(n % 100, 11, 19)) return 'many';
  10150. if (n == 1) return 'one';
  10151. return 'other';
  10152. },
  10153. '16': function (n) {
  10154. if (n % 10 == 1 && n != 11) return 'one';
  10155. return 'other';
  10156. },
  10157. '17': function (n) {
  10158. if (n == 3) return 'few';
  10159. if (n === 0) return 'zero';
  10160. if (n == 6) return 'many';
  10161. if (n == 2) return 'two';
  10162. if (n == 1) return 'one';
  10163. return 'other';
  10164. },
  10165. '18': function (n) {
  10166. if (n === 0) return 'zero';
  10167. if (isBetween(n, 0, 2) && n !== 0 && n != 2) return 'one';
  10168. return 'other';
  10169. },
  10170. '19': function (n) {
  10171. if (isBetween(n, 2, 10)) return 'few';
  10172. if (isBetween(n, 0, 1)) return 'one';
  10173. return 'other';
  10174. },
  10175. '20': function (n) {
  10176. 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';
  10177. if (n % 1000000 === 0 && n !== 0) return 'many';
  10178. if (n % 10 == 2 && !isIn(n % 100, [12, 72, 92])) return 'two';
  10179. if (n % 10 == 1 && !isIn(n % 100, [11, 71, 91])) return 'one';
  10180. return 'other';
  10181. },
  10182. '21': function (n) {
  10183. if (n === 0) return 'zero';
  10184. if (n == 1) return 'one';
  10185. return 'other';
  10186. },
  10187. '22': function (n) {
  10188. if (isBetween(n, 0, 1) || isBetween(n, 11, 99)) return 'one';
  10189. return 'other';
  10190. },
  10191. '23': function (n) {
  10192. if (isBetween(n % 10, 1, 2) || n % 20 === 0) return 'one';
  10193. return 'other';
  10194. },
  10195. '24': function (n) {
  10196. if (isBetween(n, 3, 10) || isBetween(n, 13, 19)) return 'few';
  10197. if (isIn(n, [2, 12])) return 'two';
  10198. if (isIn(n, [1, 11])) return 'one';
  10199. return 'other';
  10200. }
  10201. };
  10202. var index = locales2rules[lang.replace(/-.*$/, '')];
  10203. if (!(index in pluralRules)) {
  10204. console.warn('plural form unknown for [' + lang + ']');
  10205. return function () {
  10206. return 'other';
  10207. };
  10208. }
  10209. return pluralRules[index];
  10210. }
  10211. gMacros.plural = function (str, param, key, prop) {
  10212. var n = parseFloat(param);
  10213. if (isNaN(n)) return str;
  10214. if (prop != gTextProp) return str;
  10215. if (!gMacros._pluralRules) {
  10216. gMacros._pluralRules = getPluralRules(gLanguage);
  10217. }
  10218. var index = '[' + gMacros._pluralRules(n) + ']';
  10219. if (n === 0 && key + '[zero]' in gL10nData) {
  10220. str = gL10nData[key + '[zero]'][prop];
  10221. } else if (n == 1 && key + '[one]' in gL10nData) {
  10222. str = gL10nData[key + '[one]'][prop];
  10223. } else if (n == 2 && key + '[two]' in gL10nData) {
  10224. str = gL10nData[key + '[two]'][prop];
  10225. } else if (key + index in gL10nData) {
  10226. str = gL10nData[key + index][prop];
  10227. } else if (key + '[other]' in gL10nData) {
  10228. str = gL10nData[key + '[other]'][prop];
  10229. }
  10230. return str;
  10231. };
  10232. function getL10nData(key, args, fallback) {
  10233. var data = gL10nData[key];
  10234. if (!data) {
  10235. console.warn('#' + key + ' is undefined.');
  10236. if (!fallback) {
  10237. return null;
  10238. }
  10239. data = fallback;
  10240. }
  10241. var rv = {};
  10242. for (var prop in data) {
  10243. var str = data[prop];
  10244. str = substIndexes(str, args, key, prop);
  10245. str = substArguments(str, args, key);
  10246. rv[prop] = str;
  10247. }
  10248. return rv;
  10249. }
  10250. function substIndexes(str, args, key, prop) {
  10251. var reIndex = /\{\[\s*([a-zA-Z]+)\(([a-zA-Z]+)\)\s*\]\}/;
  10252. var reMatch = reIndex.exec(str);
  10253. if (!reMatch || !reMatch.length) return str;
  10254. var macroName = reMatch[1];
  10255. var paramName = reMatch[2];
  10256. var param;
  10257. if (args && paramName in args) {
  10258. param = args[paramName];
  10259. } else if (paramName in gL10nData) {
  10260. param = gL10nData[paramName];
  10261. }
  10262. if (macroName in gMacros) {
  10263. var macro = gMacros[macroName];
  10264. str = macro(str, param, key, prop);
  10265. }
  10266. return str;
  10267. }
  10268. function substArguments(str, args, key) {
  10269. var reArgs = /\{\{\s*(.+?)\s*\}\}/g;
  10270. return str.replace(reArgs, function (matched_text, arg) {
  10271. if (args && arg in args) {
  10272. return args[arg];
  10273. }
  10274. if (arg in gL10nData) {
  10275. return gL10nData[arg];
  10276. }
  10277. console.log('argument {{' + arg + '}} for #' + key + ' is undefined.');
  10278. return matched_text;
  10279. });
  10280. }
  10281. function translateElement(element) {
  10282. var l10n = getL10nAttributes(element);
  10283. if (!l10n.id) return;
  10284. var data = getL10nData(l10n.id, l10n.args);
  10285. if (!data) {
  10286. console.warn('#' + l10n.id + ' is undefined.');
  10287. return;
  10288. }
  10289. if (data[gTextProp]) {
  10290. if (getChildElementCount(element) === 0) {
  10291. element[gTextProp] = data[gTextProp];
  10292. } else {
  10293. var children = element.childNodes;
  10294. var found = false;
  10295. for (var i = 0, l = children.length; i < l; i++) {
  10296. if (children[i].nodeType === 3 && /\S/.test(children[i].nodeValue)) {
  10297. if (found) {
  10298. children[i].nodeValue = '';
  10299. } else {
  10300. children[i].nodeValue = data[gTextProp];
  10301. found = true;
  10302. }
  10303. }
  10304. }
  10305. if (!found) {
  10306. var textNode = document.createTextNode(data[gTextProp]);
  10307. element.insertBefore(textNode, element.firstChild);
  10308. }
  10309. }
  10310. delete data[gTextProp];
  10311. }
  10312. for (var k in data) {
  10313. element[k] = data[k];
  10314. }
  10315. }
  10316. function getChildElementCount(element) {
  10317. if (element.children) {
  10318. return element.children.length;
  10319. }
  10320. if (typeof element.childElementCount !== 'undefined') {
  10321. return element.childElementCount;
  10322. }
  10323. var count = 0;
  10324. for (var i = 0; i < element.childNodes.length; i++) {
  10325. count += element.nodeType === 1 ? 1 : 0;
  10326. }
  10327. return count;
  10328. }
  10329. function translateFragment(element) {
  10330. element = element || document.documentElement;
  10331. var children = getTranslatableChildren(element);
  10332. var elementCount = children.length;
  10333. for (var i = 0; i < elementCount; i++) {
  10334. translateElement(children[i]);
  10335. }
  10336. translateElement(element);
  10337. }
  10338. return {
  10339. get: function (key, args, fallbackString) {
  10340. var index = key.lastIndexOf('.');
  10341. var prop = gTextProp;
  10342. if (index > 0) {
  10343. prop = key.substring(index + 1);
  10344. key = key.substring(0, index);
  10345. }
  10346. var fallback;
  10347. if (fallbackString) {
  10348. fallback = {};
  10349. fallback[prop] = fallbackString;
  10350. }
  10351. var data = getL10nData(key, args, fallback);
  10352. if (data && prop in data) {
  10353. return data[prop];
  10354. }
  10355. return '{{' + key + '}}';
  10356. },
  10357. getData: function () {
  10358. return gL10nData;
  10359. },
  10360. getText: function () {
  10361. return gTextData;
  10362. },
  10363. getLanguage: function () {
  10364. return gLanguage;
  10365. },
  10366. setLanguage: function (lang, callback) {
  10367. loadLocale(lang, function () {
  10368. if (callback) callback();
  10369. });
  10370. },
  10371. getDirection: function () {
  10372. var rtlList = ['ar', 'he', 'fa', 'ps', 'ur'];
  10373. var shortCode = gLanguage.split('-', 1)[0];
  10374. return rtlList.indexOf(shortCode) >= 0 ? 'rtl' : 'ltr';
  10375. },
  10376. translate: translateFragment,
  10377. getReadyState: function () {
  10378. return gReadyState;
  10379. },
  10380. ready: function (callback) {
  10381. if (!callback) {
  10382. return;
  10383. } else if (gReadyState == 'complete' || gReadyState == 'interactive') {
  10384. window.setTimeout(function () {
  10385. callback();
  10386. });
  10387. } else if (document.addEventListener) {
  10388. document.addEventListener('localized', function once() {
  10389. document.removeEventListener('localized', once);
  10390. callback();
  10391. });
  10392. }
  10393. }
  10394. };
  10395. }(window, document);
  10396. /***/ }),
  10397. /* 38 */
  10398. /***/ (function(module, exports, __webpack_require__) {
  10399. "use strict";
  10400. Object.defineProperty(exports, "__esModule", {
  10401. value: true
  10402. });
  10403. exports.PDFPrintService = PDFPrintService;
  10404. var _ui_utils = __webpack_require__(2);
  10405. var _app = __webpack_require__(1);
  10406. var _app_options = __webpack_require__(3);
  10407. let activeService = null;
  10408. let overlayManager = null;
  10409. function renderPage(activeServiceOnEntry, pdfDocument, pageNumber, size) {
  10410. const scratchCanvas = activeService.scratchCanvas;
  10411. const PRINT_RESOLUTION = _app_options.AppOptions.get("printResolution") || 150;
  10412. const PRINT_UNITS = PRINT_RESOLUTION / 72.0;
  10413. scratchCanvas.width = Math.floor(size.width * PRINT_UNITS);
  10414. scratchCanvas.height = Math.floor(size.height * PRINT_UNITS);
  10415. const width = Math.floor(size.width * _ui_utils.CSS_UNITS) + "px";
  10416. const height = Math.floor(size.height * _ui_utils.CSS_UNITS) + "px";
  10417. const ctx = scratchCanvas.getContext("2d");
  10418. ctx.save();
  10419. ctx.fillStyle = "rgb(255, 255, 255)";
  10420. ctx.fillRect(0, 0, scratchCanvas.width, scratchCanvas.height);
  10421. ctx.restore();
  10422. return pdfDocument.getPage(pageNumber).then(function (pdfPage) {
  10423. const renderContext = {
  10424. canvasContext: ctx,
  10425. transform: [PRINT_UNITS, 0, 0, PRINT_UNITS, 0, 0],
  10426. viewport: pdfPage.getViewport({
  10427. scale: 1,
  10428. rotation: size.rotation
  10429. }),
  10430. intent: "print"
  10431. };
  10432. return pdfPage.render(renderContext).promise;
  10433. }).then(function () {
  10434. return {
  10435. width,
  10436. height
  10437. };
  10438. });
  10439. }
  10440. function PDFPrintService(pdfDocument, pagesOverview, printContainer, l10n) {
  10441. this.pdfDocument = pdfDocument;
  10442. this.pagesOverview = pagesOverview;
  10443. this.printContainer = printContainer;
  10444. this.l10n = l10n || _ui_utils.NullL10n;
  10445. this.disableCreateObjectURL = pdfDocument.loadingParams["disableCreateObjectURL"];
  10446. this.currentPage = -1;
  10447. this.scratchCanvas = document.createElement("canvas");
  10448. }
  10449. PDFPrintService.prototype = {
  10450. layout() {
  10451. this.throwIfInactive();
  10452. const body = document.querySelector("body");
  10453. body.setAttribute("data-pdfjsprinting", true);
  10454. const hasEqualPageSizes = this.pagesOverview.every(function (size) {
  10455. return size.width === this.pagesOverview[0].width && size.height === this.pagesOverview[0].height;
  10456. }, this);
  10457. if (!hasEqualPageSizes) {
  10458. console.warn("Not all pages have the same size. The printed " + "result may be incorrect!");
  10459. }
  10460. this.pageStyleSheet = document.createElement("style");
  10461. const pageSize = this.pagesOverview[0];
  10462. this.pageStyleSheet.textContent = "@supports ((size:A4) and (size:1pt 1pt)) {" + "@page { size: " + pageSize.width + "pt " + pageSize.height + "pt;}" + "}";
  10463. body.appendChild(this.pageStyleSheet);
  10464. },
  10465. destroy() {
  10466. if (activeService !== this) {
  10467. return;
  10468. }
  10469. this.printContainer.textContent = "";
  10470. const body = document.querySelector("body");
  10471. body.removeAttribute("data-pdfjsprinting");
  10472. if (this.pageStyleSheet) {
  10473. this.pageStyleSheet.remove();
  10474. this.pageStyleSheet = null;
  10475. }
  10476. this.scratchCanvas.width = this.scratchCanvas.height = 0;
  10477. this.scratchCanvas = null;
  10478. activeService = null;
  10479. ensureOverlay().then(function () {
  10480. if (overlayManager.active !== "printServiceOverlay") {
  10481. return;
  10482. }
  10483. overlayManager.close("printServiceOverlay");
  10484. });
  10485. },
  10486. renderPages() {
  10487. const pageCount = this.pagesOverview.length;
  10488. const renderNextPage = (resolve, reject) => {
  10489. this.throwIfInactive();
  10490. if (++this.currentPage >= pageCount) {
  10491. renderProgress(pageCount, pageCount, this.l10n);
  10492. resolve();
  10493. return;
  10494. }
  10495. const index = this.currentPage;
  10496. renderProgress(index, pageCount, this.l10n);
  10497. renderPage(this, this.pdfDocument, index + 1, this.pagesOverview[index]).then(this.useRenderedPage.bind(this)).then(function () {
  10498. renderNextPage(resolve, reject);
  10499. }, reject);
  10500. };
  10501. return new Promise(renderNextPage);
  10502. },
  10503. useRenderedPage(printItem) {
  10504. this.throwIfInactive();
  10505. const img = document.createElement("img");
  10506. img.style.width = printItem.width;
  10507. img.style.height = printItem.height;
  10508. const scratchCanvas = this.scratchCanvas;
  10509. if ("toBlob" in scratchCanvas && !this.disableCreateObjectURL) {
  10510. scratchCanvas.toBlob(function (blob) {
  10511. img.src = URL.createObjectURL(blob);
  10512. });
  10513. } else {
  10514. img.src = scratchCanvas.toDataURL();
  10515. }
  10516. const wrapper = document.createElement("div");
  10517. wrapper.appendChild(img);
  10518. this.printContainer.appendChild(wrapper);
  10519. return new Promise(function (resolve, reject) {
  10520. img.onload = resolve;
  10521. img.onerror = reject;
  10522. });
  10523. },
  10524. performPrint() {
  10525. this.throwIfInactive();
  10526. return new Promise(resolve => {
  10527. setTimeout(() => {
  10528. if (!this.active) {
  10529. resolve();
  10530. return;
  10531. }
  10532. print.call(window);
  10533. setTimeout(resolve, 20);
  10534. }, 0);
  10535. });
  10536. },
  10537. get active() {
  10538. return this === activeService;
  10539. },
  10540. throwIfInactive() {
  10541. if (!this.active) {
  10542. throw new Error("This print request was cancelled or completed.");
  10543. }
  10544. }
  10545. };
  10546. const print = window.print;
  10547. window.print = function () {
  10548. if (activeService) {
  10549. console.warn("Ignored window.print() because of a pending print job.");
  10550. return;
  10551. }
  10552. ensureOverlay().then(function () {
  10553. if (activeService) {
  10554. overlayManager.open("printServiceOverlay");
  10555. }
  10556. });
  10557. try {
  10558. dispatchEvent("beforeprint");
  10559. } finally {
  10560. if (!activeService) {
  10561. console.error("Expected print service to be initialized.");
  10562. ensureOverlay().then(function () {
  10563. if (overlayManager.active === "printServiceOverlay") {
  10564. overlayManager.close("printServiceOverlay");
  10565. }
  10566. });
  10567. return;
  10568. }
  10569. const activeServiceOnEntry = activeService;
  10570. activeService.renderPages().then(function () {
  10571. return activeServiceOnEntry.performPrint();
  10572. }).catch(function () {}).then(function () {
  10573. if (activeServiceOnEntry.active) {
  10574. abort();
  10575. }
  10576. });
  10577. }
  10578. };
  10579. function dispatchEvent(eventType) {
  10580. const event = document.createEvent("CustomEvent");
  10581. event.initCustomEvent(eventType, false, false, "custom");
  10582. window.dispatchEvent(event);
  10583. }
  10584. function abort() {
  10585. if (activeService) {
  10586. activeService.destroy();
  10587. dispatchEvent("afterprint");
  10588. }
  10589. }
  10590. function renderProgress(index, total, l10n) {
  10591. const progressContainer = document.getElementById("printServiceOverlay");
  10592. const progress = Math.round(100 * index / total);
  10593. const progressBar = progressContainer.querySelector("progress");
  10594. const progressPerc = progressContainer.querySelector(".relative-progress");
  10595. progressBar.value = progress;
  10596. l10n.get("print_progress_percent", {
  10597. progress
  10598. }, progress + "%").then(msg => {
  10599. progressPerc.textContent = msg;
  10600. });
  10601. }
  10602. window.addEventListener("keydown", function (event) {
  10603. if (event.keyCode === 80 && (event.ctrlKey || event.metaKey) && !event.altKey && (!event.shiftKey || window.chrome || window.opera)) {
  10604. window.print();
  10605. event.preventDefault();
  10606. if (event.stopImmediatePropagation) {
  10607. event.stopImmediatePropagation();
  10608. } else {
  10609. event.stopPropagation();
  10610. }
  10611. }
  10612. }, true);
  10613. if ("onbeforeprint" in window) {
  10614. const stopPropagationIfNeeded = function (event) {
  10615. if (event.detail !== "custom" && event.stopImmediatePropagation) {
  10616. event.stopImmediatePropagation();
  10617. }
  10618. };
  10619. window.addEventListener("beforeprint", stopPropagationIfNeeded);
  10620. window.addEventListener("afterprint", stopPropagationIfNeeded);
  10621. }
  10622. let overlayPromise;
  10623. function ensureOverlay() {
  10624. if (!overlayPromise) {
  10625. overlayManager = _app.PDFViewerApplication.overlayManager;
  10626. if (!overlayManager) {
  10627. throw new Error("The overlay manager has not yet been initialized.");
  10628. }
  10629. overlayPromise = overlayManager.register("printServiceOverlay", document.getElementById("printServiceOverlay"), abort, true);
  10630. document.getElementById("printCancel").onclick = abort;
  10631. }
  10632. return overlayPromise;
  10633. }
  10634. _app.PDFPrintServiceFactory.instance = {
  10635. supportsPrinting: true,
  10636. createPrintService(pdfDocument, pagesOverview, printContainer, l10n) {
  10637. if (activeService) {
  10638. throw new Error("The print service is created and active.");
  10639. }
  10640. activeService = new PDFPrintService(pdfDocument, pagesOverview, printContainer, l10n);
  10641. return activeService;
  10642. }
  10643. };
  10644. /***/ })
  10645. /******/ ]);
  10646. //# sourceMappingURL=viewer.js.map