viewer.js 347 KB

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