viewer.js 352 KB

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