viewer.js 380 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * Javascript code in this page
  4. *
  5. * Copyright 2021 Mozilla Foundation
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. *
  19. * @licend The above is the entire license notice for the
  20. * Javascript code in this page
  21. */
  22. /******/ (() => { // webpackBootstrap
  23. /******/ "use strict";
  24. /******/ var __webpack_modules__ = ([
  25. /* 0 */,
  26. /* 1 */
  27. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  28. Object.defineProperty(exports, "__esModule", ({
  29. value: true
  30. }));
  31. exports.OptionKind = exports.AppOptions = void 0;
  32. var _viewer_compatibility = __webpack_require__(2);
  33. const OptionKind = {
  34. VIEWER: 0x02,
  35. API: 0x04,
  36. WORKER: 0x08,
  37. PREFERENCE: 0x80
  38. };
  39. exports.OptionKind = OptionKind;
  40. const defaultOptions = {
  41. cursorToolOnLoad: {
  42. value: 0,
  43. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  44. },
  45. defaultUrl: {
  46. value: "compressed.tracemonkey-pldi-09.pdf",
  47. kind: OptionKind.VIEWER
  48. },
  49. defaultZoomValue: {
  50. value: "",
  51. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  52. },
  53. disableHistory: {
  54. value: false,
  55. kind: OptionKind.VIEWER
  56. },
  57. disablePageLabels: {
  58. value: false,
  59. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  60. },
  61. enablePermissions: {
  62. value: false,
  63. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  64. },
  65. enablePrintAutoRotate: {
  66. value: true,
  67. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  68. },
  69. enableScripting: {
  70. value: true,
  71. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  72. },
  73. enableWebGL: {
  74. value: false,
  75. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  76. },
  77. externalLinkRel: {
  78. value: "noopener noreferrer nofollow",
  79. kind: OptionKind.VIEWER
  80. },
  81. externalLinkTarget: {
  82. value: 0,
  83. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  84. },
  85. historyUpdateUrl: {
  86. value: false,
  87. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  88. },
  89. ignoreDestinationZoom: {
  90. value: false,
  91. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  92. },
  93. imageResourcesPath: {
  94. value: "./images/",
  95. kind: OptionKind.VIEWER
  96. },
  97. maxCanvasPixels: {
  98. value: 16777216,
  99. compatibility: _viewer_compatibility.viewerCompatibilityParams.maxCanvasPixels,
  100. kind: OptionKind.VIEWER
  101. },
  102. pdfBugEnabled: {
  103. value: false,
  104. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  105. },
  106. printResolution: {
  107. value: 150,
  108. kind: OptionKind.VIEWER
  109. },
  110. renderer: {
  111. value: "canvas",
  112. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  113. },
  114. renderInteractiveForms: {
  115. value: true,
  116. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  117. },
  118. sidebarViewOnLoad: {
  119. value: -1,
  120. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  121. },
  122. scrollModeOnLoad: {
  123. value: -1,
  124. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  125. },
  126. spreadModeOnLoad: {
  127. value: -1,
  128. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  129. },
  130. textLayerMode: {
  131. value: 1,
  132. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  133. },
  134. useOnlyCssZoom: {
  135. value: false,
  136. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  137. },
  138. viewerCssTheme: {
  139. value: 0,
  140. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  141. },
  142. viewOnLoad: {
  143. value: 0,
  144. kind: OptionKind.VIEWER + OptionKind.PREFERENCE
  145. },
  146. cMapPacked: {
  147. value: true,
  148. kind: OptionKind.API
  149. },
  150. cMapUrl: {
  151. value: "../web/cmaps/",
  152. kind: OptionKind.API
  153. },
  154. disableAutoFetch: {
  155. value: false,
  156. kind: OptionKind.API + OptionKind.PREFERENCE
  157. },
  158. disableFontFace: {
  159. value: false,
  160. kind: OptionKind.API + OptionKind.PREFERENCE
  161. },
  162. disableRange: {
  163. value: false,
  164. kind: OptionKind.API + OptionKind.PREFERENCE
  165. },
  166. disableStream: {
  167. value: false,
  168. kind: OptionKind.API + OptionKind.PREFERENCE
  169. },
  170. docBaseUrl: {
  171. value: "",
  172. kind: OptionKind.API
  173. },
  174. enableXfa: {
  175. value: false,
  176. kind: OptionKind.API
  177. },
  178. fontExtraProperties: {
  179. value: false,
  180. kind: OptionKind.API
  181. },
  182. isEvalSupported: {
  183. value: true,
  184. kind: OptionKind.API
  185. },
  186. maxImageSize: {
  187. value: -1,
  188. kind: OptionKind.API
  189. },
  190. pdfBug: {
  191. value: false,
  192. kind: OptionKind.API
  193. },
  194. verbosity: {
  195. value: 1,
  196. kind: OptionKind.API
  197. },
  198. workerPort: {
  199. value: null,
  200. kind: OptionKind.WORKER
  201. },
  202. workerSrc: {
  203. value: "../pdfBuild/pdf.worker.js",
  204. kind: OptionKind.WORKER
  205. }
  206. };
  207. {
  208. defaultOptions.disablePreferences = {
  209. value: false,
  210. kind: OptionKind.VIEWER
  211. };
  212. defaultOptions.locale = {
  213. value: typeof navigator !== "undefined" ? navigator.language : "en-US",
  214. kind: OptionKind.VIEWER
  215. };
  216. defaultOptions.sandboxBundleSrc = {
  217. value: "../pdfBuild/pdf.sandbox.js",
  218. kind: OptionKind.VIEWER
  219. };
  220. }
  221. const userOptions = Object.create(null);
  222. class AppOptions {
  223. constructor() {
  224. throw new Error("Cannot initialize AppOptions.");
  225. }
  226. static get(name) {
  227. const userOption = userOptions[name];
  228. if (userOption !== undefined) {
  229. return userOption;
  230. }
  231. const defaultOption = defaultOptions[name];
  232. if (defaultOption !== undefined) {
  233. return defaultOption.compatibility ?? defaultOption.value;
  234. }
  235. return undefined;
  236. }
  237. static getAll(kind = null) {
  238. const options = Object.create(null);
  239. for (const name in defaultOptions) {
  240. const defaultOption = defaultOptions[name];
  241. if (kind) {
  242. if ((kind & defaultOption.kind) === 0) {
  243. continue;
  244. }
  245. if (kind === OptionKind.PREFERENCE) {
  246. const value = defaultOption.value,
  247. valueType = typeof value;
  248. if (valueType === "boolean" || valueType === "string" || valueType === "number" && Number.isInteger(value)) {
  249. options[name] = value;
  250. continue;
  251. }
  252. throw new Error(`Invalid type for preference: ${name}`);
  253. }
  254. }
  255. const userOption = userOptions[name];
  256. options[name] = userOption !== undefined ? userOption : defaultOption.compatibility ?? defaultOption.value;
  257. }
  258. return options;
  259. }
  260. static set(name, value) {
  261. userOptions[name] = value;
  262. }
  263. static setAll(options) {
  264. for (const name in options) {
  265. userOptions[name] = options[name];
  266. }
  267. }
  268. static remove(name) {
  269. delete userOptions[name];
  270. }
  271. }
  272. exports.AppOptions = AppOptions;
  273. /***/ }),
  274. /* 2 */
  275. /***/ ((__unused_webpack_module, exports) => {
  276. Object.defineProperty(exports, "__esModule", ({
  277. value: true
  278. }));
  279. exports.viewerCompatibilityParams = void 0;
  280. const compatibilityParams = Object.create(null);
  281. {
  282. const userAgent = typeof navigator !== "undefined" && navigator.userAgent || "";
  283. const platform = typeof navigator !== "undefined" && navigator.platform || "";
  284. const maxTouchPoints = typeof navigator !== "undefined" && navigator.maxTouchPoints || 1;
  285. const isAndroid = /Android/.test(userAgent);
  286. const isIOS = /\b(iPad|iPhone|iPod)(?=;)/.test(userAgent) || platform === "MacIntel" && maxTouchPoints > 1;
  287. const isIOSChrome = /CriOS/.test(userAgent);
  288. (function checkOnBlobSupport() {
  289. if (isIOSChrome) {
  290. compatibilityParams.disableCreateObjectURL = true;
  291. }
  292. })();
  293. (function checkCanvasSizeLimitation() {
  294. if (isIOS || isAndroid) {
  295. compatibilityParams.maxCanvasPixels = 5242880;
  296. }
  297. })();
  298. }
  299. const viewerCompatibilityParams = Object.freeze(compatibilityParams);
  300. exports.viewerCompatibilityParams = viewerCompatibilityParams;
  301. /***/ }),
  302. /* 3 */
  303. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  304. Object.defineProperty(exports, "__esModule", ({
  305. value: true
  306. }));
  307. exports.PDFViewerApplication = exports.PDFPrintServiceFactory = exports.DefaultExternalServices = void 0;
  308. var _ui_utils = __webpack_require__(4);
  309. var _app_options = __webpack_require__(1);
  310. var _pdfjsLib = __webpack_require__(5);
  311. var _pdf_cursor_tools = __webpack_require__(6);
  312. var _pdf_rendering_queue = __webpack_require__(8);
  313. var _overlay_manager = __webpack_require__(9);
  314. var _password_prompt = __webpack_require__(10);
  315. var _pdf_attachment_viewer = __webpack_require__(11);
  316. var _pdf_document_properties = __webpack_require__(13);
  317. var _pdf_find_bar = __webpack_require__(14);
  318. var _pdf_find_controller = __webpack_require__(15);
  319. var _pdf_history = __webpack_require__(17);
  320. var _pdf_layer_viewer = __webpack_require__(18);
  321. var _pdf_link_service = __webpack_require__(19);
  322. var _pdf_outline_viewer = __webpack_require__(20);
  323. var _pdf_presentation_mode = __webpack_require__(21);
  324. var _pdf_scripting_manager = __webpack_require__(22);
  325. var _pdf_sidebar = __webpack_require__(23);
  326. var _pdf_sidebar_resizer = __webpack_require__(24);
  327. var _pdf_thumbnail_viewer = __webpack_require__(25);
  328. var _pdf_viewer = __webpack_require__(27);
  329. var _secondary_toolbar = __webpack_require__(34);
  330. var _toolbar = __webpack_require__(36);
  331. var _viewer_compatibility = __webpack_require__(2);
  332. var _view_history = __webpack_require__(37);
  333. const DEFAULT_SCALE_DELTA = 1.1;
  334. const DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT = 5000;
  335. const FORCE_PAGES_LOADED_TIMEOUT = 10000;
  336. const WHEEL_ZOOM_DISABLED_TIMEOUT = 1000;
  337. const ENABLE_PERMISSIONS_CLASS = "enablePermissions";
  338. const ViewOnLoad = {
  339. UNKNOWN: -1,
  340. PREVIOUS: 0,
  341. INITIAL: 1
  342. };
  343. const ViewerCssTheme = {
  344. AUTOMATIC: 0,
  345. LIGHT: 1,
  346. DARK: 2
  347. };
  348. const KNOWN_VERSIONS = ["1.0", "1.1", "1.2", "1.3", "1.4", "1.5", "1.6", "1.7", "1.8", "1.9", "2.0", "2.1", "2.2", "2.3"];
  349. const KNOWN_GENERATORS = ["acrobat distiller", "acrobat pdfwriter", "adobe livecycle", "adobe pdf library", "adobe photoshop", "ghostscript", "tcpdf", "cairo", "dvipdfm", "dvips", "pdftex", "pdfkit", "itext", "prince", "quarkxpress", "mac os x", "microsoft", "openoffice", "oracle", "luradocument", "pdf-xchange", "antenna house", "aspose.cells", "fpdf"];
  350. class DefaultExternalServices {
  351. constructor() {
  352. throw new Error("Cannot initialize DefaultExternalServices.");
  353. }
  354. static updateFindControlState(data) {}
  355. static updateFindMatchesCount(data) {}
  356. static initPassiveLoading(callbacks) {}
  357. static async fallback(data) {}
  358. static reportTelemetry(data) {}
  359. static createDownloadManager(options) {
  360. throw new Error("Not implemented: createDownloadManager");
  361. }
  362. static createPreferences() {
  363. throw new Error("Not implemented: createPreferences");
  364. }
  365. static createL10n(options) {
  366. throw new Error("Not implemented: createL10n");
  367. }
  368. static createScripting(options) {
  369. throw new Error("Not implemented: createScripting");
  370. }
  371. static get supportsIntegratedFind() {
  372. return (0, _pdfjsLib.shadow)(this, "supportsIntegratedFind", false);
  373. }
  374. static get supportsDocumentFonts() {
  375. return (0, _pdfjsLib.shadow)(this, "supportsDocumentFonts", true);
  376. }
  377. static get supportedMouseWheelZoomModifierKeys() {
  378. return (0, _pdfjsLib.shadow)(this, "supportedMouseWheelZoomModifierKeys", {
  379. ctrlKey: true,
  380. metaKey: true
  381. });
  382. }
  383. static get isInAutomation() {
  384. return (0, _pdfjsLib.shadow)(this, "isInAutomation", false);
  385. }
  386. }
  387. exports.DefaultExternalServices = DefaultExternalServices;
  388. const PDFViewerApplication = {
  389. initialBookmark: document.location.hash.substring(1),
  390. _initializedCapability: (0, _pdfjsLib.createPromiseCapability)(),
  391. fellback: false,
  392. appConfig: null,
  393. pdfDocument: null,
  394. pdfLoadingTask: null,
  395. printService: null,
  396. pdfViewer: null,
  397. pdfThumbnailViewer: null,
  398. pdfRenderingQueue: null,
  399. pdfPresentationMode: null,
  400. pdfDocumentProperties: null,
  401. pdfLinkService: null,
  402. pdfHistory: null,
  403. pdfSidebar: null,
  404. pdfSidebarResizer: null,
  405. pdfOutlineViewer: null,
  406. pdfAttachmentViewer: null,
  407. pdfLayerViewer: null,
  408. pdfCursorTools: null,
  409. pdfScriptingManager: null,
  410. store: null,
  411. downloadManager: null,
  412. overlayManager: null,
  413. preferences: null,
  414. toolbar: null,
  415. secondaryToolbar: null,
  416. eventBus: null,
  417. l10n: null,
  418. isInitialViewSet: false,
  419. downloadComplete: false,
  420. isViewerEmbedded: window.parent !== window,
  421. url: "",
  422. baseUrl: "",
  423. externalServices: DefaultExternalServices,
  424. _boundEvents: Object.create(null),
  425. documentInfo: null,
  426. metadata: null,
  427. _contentDispositionFilename: null,
  428. _contentLength: null,
  429. triggerDelayedFallback: null,
  430. _saveInProgress: false,
  431. _wheelUnusedTicks: 0,
  432. _idleCallbacks: new Set(),
  433. async initialize(appConfig) {
  434. this.preferences = this.externalServices.createPreferences();
  435. this.appConfig = appConfig;
  436. await this._readPreferences();
  437. await this._parseHashParameters();
  438. this._forceCssTheme();
  439. await this._initializeL10n();
  440. if (this.isViewerEmbedded && _app_options.AppOptions.get("externalLinkTarget") === _pdfjsLib.LinkTarget.NONE) {
  441. _app_options.AppOptions.set("externalLinkTarget", _pdfjsLib.LinkTarget.TOP);
  442. }
  443. await this._initializeViewerComponents();
  444. this.bindEvents();
  445. this.bindWindowEvents();
  446. const appContainer = appConfig.appContainer || document.documentElement;
  447. this.l10n.translate(appContainer).then(() => {
  448. this.eventBus.dispatch("localized", {
  449. source: this
  450. });
  451. });
  452. this._initializedCapability.resolve();
  453. },
  454. async _readPreferences() {
  455. if (_app_options.AppOptions.get("disablePreferences")) {
  456. return;
  457. }
  458. try {
  459. _app_options.AppOptions.setAll(await this.preferences.getAll());
  460. } catch (reason) {
  461. console.error(`_readPreferences: "${reason?.message}".`);
  462. }
  463. },
  464. async _parseHashParameters() {
  465. if (!_app_options.AppOptions.get("pdfBugEnabled")) {
  466. return undefined;
  467. }
  468. const hash = document.location.hash.substring(1);
  469. if (!hash) {
  470. return undefined;
  471. }
  472. const hashParams = (0, _ui_utils.parseQueryString)(hash),
  473. waitOn = [];
  474. if ("disableworker" in hashParams && hashParams.disableworker === "true") {
  475. waitOn.push(loadFakeWorker());
  476. }
  477. if ("disablerange" in hashParams) {
  478. _app_options.AppOptions.set("disableRange", hashParams.disablerange === "true");
  479. }
  480. if ("disablestream" in hashParams) {
  481. _app_options.AppOptions.set("disableStream", hashParams.disablestream === "true");
  482. }
  483. if ("disableautofetch" in hashParams) {
  484. _app_options.AppOptions.set("disableAutoFetch", hashParams.disableautofetch === "true");
  485. }
  486. if ("disablefontface" in hashParams) {
  487. _app_options.AppOptions.set("disableFontFace", hashParams.disablefontface === "true");
  488. }
  489. if ("disablehistory" in hashParams) {
  490. _app_options.AppOptions.set("disableHistory", hashParams.disablehistory === "true");
  491. }
  492. if ("webgl" in hashParams) {
  493. _app_options.AppOptions.set("enableWebGL", hashParams.webgl === "true");
  494. }
  495. if ("verbosity" in hashParams) {
  496. _app_options.AppOptions.set("verbosity", hashParams.verbosity | 0);
  497. }
  498. if ("textlayer" in hashParams) {
  499. switch (hashParams.textlayer) {
  500. case "off":
  501. _app_options.AppOptions.set("textLayerMode", _ui_utils.TextLayerMode.DISABLE);
  502. break;
  503. case "visible":
  504. case "shadow":
  505. case "hover":
  506. const viewer = this.appConfig.viewerContainer;
  507. viewer.classList.add("textLayer-" + hashParams.textlayer);
  508. break;
  509. }
  510. }
  511. if ("pdfbug" in hashParams) {
  512. _app_options.AppOptions.set("pdfBug", true);
  513. _app_options.AppOptions.set("fontExtraProperties", true);
  514. const enabled = hashParams.pdfbug.split(",");
  515. waitOn.push(loadAndEnablePDFBug(enabled));
  516. }
  517. if ("locale" in hashParams) {
  518. _app_options.AppOptions.set("locale", hashParams.locale);
  519. }
  520. if (waitOn.length === 0) {
  521. return undefined;
  522. }
  523. return Promise.all(waitOn).catch(reason => {
  524. console.error(`_parseHashParameters: "${reason.message}".`);
  525. });
  526. },
  527. async _initializeL10n() {
  528. this.l10n = this.externalServices.createL10n({
  529. locale: _app_options.AppOptions.get("locale")
  530. });
  531. const dir = await this.l10n.getDirection();
  532. document.getElementsByTagName("html")[0].dir = dir;
  533. },
  534. _forceCssTheme() {
  535. const cssTheme = _app_options.AppOptions.get("viewerCssTheme");
  536. if (cssTheme === ViewerCssTheme.AUTOMATIC || !Object.values(ViewerCssTheme).includes(cssTheme)) {
  537. return;
  538. }
  539. try {
  540. const styleSheet = document.styleSheets[0];
  541. const cssRules = styleSheet?.cssRules || [];
  542. for (let i = 0, ii = cssRules.length; i < ii; i++) {
  543. const rule = cssRules[i];
  544. if (rule instanceof CSSMediaRule && rule.media?.[0] === "(prefers-color-scheme: dark)") {
  545. if (cssTheme === ViewerCssTheme.LIGHT) {
  546. styleSheet.deleteRule(i);
  547. return;
  548. }
  549. const darkRules = /^@media \(prefers-color-scheme: dark\) {\n\s*([\w\s-.,:;/\\{}()]+)\n}$/.exec(rule.cssText);
  550. if (darkRules?.[1]) {
  551. styleSheet.deleteRule(i);
  552. styleSheet.insertRule(darkRules[1], i);
  553. }
  554. return;
  555. }
  556. }
  557. } catch (reason) {
  558. console.error(`_forceCssTheme: "${reason?.message}".`);
  559. }
  560. },
  561. async _initializeViewerComponents() {
  562. const appConfig = this.appConfig;
  563. const eventBus = appConfig.eventBus || new _ui_utils.EventBus({
  564. isInAutomation: this.externalServices.isInAutomation
  565. });
  566. this.eventBus = eventBus;
  567. this.overlayManager = new _overlay_manager.OverlayManager();
  568. const pdfRenderingQueue = new _pdf_rendering_queue.PDFRenderingQueue();
  569. pdfRenderingQueue.onIdle = this._cleanup.bind(this);
  570. this.pdfRenderingQueue = pdfRenderingQueue;
  571. const pdfLinkService = new _pdf_link_service.PDFLinkService({
  572. eventBus,
  573. externalLinkTarget: _app_options.AppOptions.get("externalLinkTarget"),
  574. externalLinkRel: _app_options.AppOptions.get("externalLinkRel"),
  575. ignoreDestinationZoom: _app_options.AppOptions.get("ignoreDestinationZoom")
  576. });
  577. this.pdfLinkService = pdfLinkService;
  578. const downloadManager = this.externalServices.createDownloadManager();
  579. this.downloadManager = downloadManager;
  580. const findController = new _pdf_find_controller.PDFFindController({
  581. linkService: pdfLinkService,
  582. eventBus
  583. });
  584. this.findController = findController;
  585. const pdfScriptingManager = new _pdf_scripting_manager.PDFScriptingManager({
  586. eventBus,
  587. sandboxBundleSrc: _app_options.AppOptions.get("sandboxBundleSrc"),
  588. scriptingFactory: this.externalServices,
  589. docPropertiesLookup: this._scriptingDocProperties.bind(this)
  590. });
  591. this.pdfScriptingManager = pdfScriptingManager;
  592. const container = appConfig.mainContainer;
  593. const viewer = appConfig.viewerContainer;
  594. this.pdfViewer = new _pdf_viewer.PDFViewer({
  595. container,
  596. viewer,
  597. eventBus,
  598. renderingQueue: pdfRenderingQueue,
  599. linkService: pdfLinkService,
  600. downloadManager,
  601. findController,
  602. scriptingManager: pdfScriptingManager,
  603. renderer: _app_options.AppOptions.get("renderer"),
  604. enableWebGL: _app_options.AppOptions.get("enableWebGL"),
  605. l10n: this.l10n,
  606. textLayerMode: _app_options.AppOptions.get("textLayerMode"),
  607. imageResourcesPath: _app_options.AppOptions.get("imageResourcesPath"),
  608. renderInteractiveForms: _app_options.AppOptions.get("renderInteractiveForms"),
  609. enablePrintAutoRotate: _app_options.AppOptions.get("enablePrintAutoRotate"),
  610. useOnlyCssZoom: _app_options.AppOptions.get("useOnlyCssZoom"),
  611. maxCanvasPixels: _app_options.AppOptions.get("maxCanvasPixels"),
  612. enableScripting: _app_options.AppOptions.get("enableScripting")
  613. });
  614. pdfRenderingQueue.setViewer(this.pdfViewer);
  615. pdfLinkService.setViewer(this.pdfViewer);
  616. pdfScriptingManager.setViewer(this.pdfViewer);
  617. this.pdfThumbnailViewer = new _pdf_thumbnail_viewer.PDFThumbnailViewer({
  618. container: appConfig.sidebar.thumbnailView,
  619. eventBus,
  620. renderingQueue: pdfRenderingQueue,
  621. linkService: pdfLinkService,
  622. l10n: this.l10n
  623. });
  624. pdfRenderingQueue.setThumbnailViewer(this.pdfThumbnailViewer);
  625. this.pdfHistory = new _pdf_history.PDFHistory({
  626. linkService: pdfLinkService,
  627. eventBus
  628. });
  629. pdfLinkService.setHistory(this.pdfHistory);
  630. if (!this.supportsIntegratedFind) {
  631. this.findBar = new _pdf_find_bar.PDFFindBar(appConfig.findBar, eventBus, this.l10n);
  632. }
  633. this.pdfDocumentProperties = new _pdf_document_properties.PDFDocumentProperties(appConfig.documentProperties, this.overlayManager, eventBus, this.l10n);
  634. this.pdfCursorTools = new _pdf_cursor_tools.PDFCursorTools({
  635. container,
  636. eventBus,
  637. cursorToolOnLoad: _app_options.AppOptions.get("cursorToolOnLoad")
  638. });
  639. this.toolbar = new _toolbar.Toolbar(appConfig.toolbar, eventBus, this.l10n);
  640. this.secondaryToolbar = new _secondary_toolbar.SecondaryToolbar(appConfig.secondaryToolbar, container, eventBus);
  641. if (this.supportsFullscreen) {
  642. this.pdfPresentationMode = new _pdf_presentation_mode.PDFPresentationMode({
  643. container,
  644. pdfViewer: this.pdfViewer,
  645. eventBus
  646. });
  647. }
  648. this.passwordPrompt = new _password_prompt.PasswordPrompt(appConfig.passwordOverlay, this.overlayManager, this.l10n, this.isViewerEmbedded);
  649. this.pdfOutlineViewer = new _pdf_outline_viewer.PDFOutlineViewer({
  650. container: appConfig.sidebar.outlineView,
  651. eventBus,
  652. linkService: pdfLinkService
  653. });
  654. this.pdfAttachmentViewer = new _pdf_attachment_viewer.PDFAttachmentViewer({
  655. container: appConfig.sidebar.attachmentsView,
  656. eventBus,
  657. downloadManager
  658. });
  659. this.pdfLayerViewer = new _pdf_layer_viewer.PDFLayerViewer({
  660. container: appConfig.sidebar.layersView,
  661. eventBus,
  662. l10n: this.l10n
  663. });
  664. this.pdfSidebar = new _pdf_sidebar.PDFSidebar({
  665. elements: appConfig.sidebar,
  666. pdfViewer: this.pdfViewer,
  667. pdfThumbnailViewer: this.pdfThumbnailViewer,
  668. eventBus,
  669. l10n: this.l10n
  670. });
  671. this.pdfSidebar.onToggled = this.forceRendering.bind(this);
  672. this.pdfSidebarResizer = new _pdf_sidebar_resizer.PDFSidebarResizer(appConfig.sidebarResizer, eventBus, this.l10n);
  673. },
  674. run(config) {
  675. this.initialize(config).then(webViewerInitialized);
  676. },
  677. get initialized() {
  678. return this._initializedCapability.settled;
  679. },
  680. get initializedPromise() {
  681. return this._initializedCapability.promise;
  682. },
  683. zoomIn(ticks) {
  684. if (this.pdfViewer.isInPresentationMode) {
  685. return;
  686. }
  687. let newScale = this.pdfViewer.currentScale;
  688. do {
  689. newScale = (newScale * DEFAULT_SCALE_DELTA).toFixed(2);
  690. newScale = Math.ceil(newScale * 10) / 10;
  691. newScale = Math.min(_ui_utils.MAX_SCALE, newScale);
  692. } while (--ticks > 0 && newScale < _ui_utils.MAX_SCALE);
  693. this.pdfViewer.currentScaleValue = newScale;
  694. },
  695. zoomOut(ticks) {
  696. if (this.pdfViewer.isInPresentationMode) {
  697. return;
  698. }
  699. let newScale = this.pdfViewer.currentScale;
  700. do {
  701. newScale = (newScale / DEFAULT_SCALE_DELTA).toFixed(2);
  702. newScale = Math.floor(newScale * 10) / 10;
  703. newScale = Math.max(_ui_utils.MIN_SCALE, newScale);
  704. } while (--ticks > 0 && newScale > _ui_utils.MIN_SCALE);
  705. this.pdfViewer.currentScaleValue = newScale;
  706. },
  707. zoomReset() {
  708. if (this.pdfViewer.isInPresentationMode) {
  709. return;
  710. }
  711. this.pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  712. },
  713. get pagesCount() {
  714. return this.pdfDocument ? this.pdfDocument.numPages : 0;
  715. },
  716. get page() {
  717. return this.pdfViewer.currentPageNumber;
  718. },
  719. set page(val) {
  720. this.pdfViewer.currentPageNumber = val;
  721. },
  722. get supportsPrinting() {
  723. return PDFPrintServiceFactory.instance.supportsPrinting;
  724. },
  725. get supportsFullscreen() {
  726. const doc = document.documentElement;
  727. let support = !!(doc.requestFullscreen || doc.mozRequestFullScreen || doc.webkitRequestFullScreen);
  728. if (document.fullscreenEnabled === false || document.mozFullScreenEnabled === false || document.webkitFullscreenEnabled === false) {
  729. support = false;
  730. }
  731. return (0, _pdfjsLib.shadow)(this, "supportsFullscreen", support);
  732. },
  733. get supportsIntegratedFind() {
  734. return this.externalServices.supportsIntegratedFind;
  735. },
  736. get supportsDocumentFonts() {
  737. return this.externalServices.supportsDocumentFonts;
  738. },
  739. get loadingBar() {
  740. const bar = new _ui_utils.ProgressBar("#loadingBar");
  741. return (0, _pdfjsLib.shadow)(this, "loadingBar", bar);
  742. },
  743. get supportedMouseWheelZoomModifierKeys() {
  744. return this.externalServices.supportedMouseWheelZoomModifierKeys;
  745. },
  746. initPassiveLoading() {
  747. throw new Error("Not implemented: initPassiveLoading");
  748. },
  749. setTitleUsingUrl(url = "") {
  750. this.url = url;
  751. this.baseUrl = url.split("#")[0];
  752. let title = (0, _pdfjsLib.getPdfFilenameFromUrl)(url, "");
  753. if (!title) {
  754. try {
  755. title = decodeURIComponent((0, _pdfjsLib.getFilenameFromUrl)(url)) || url;
  756. } catch (ex) {
  757. title = url;
  758. }
  759. }
  760. this.setTitle(title);
  761. },
  762. setTitle(title) {
  763. if (this.isViewerEmbedded) {
  764. return;
  765. }
  766. document.title = title;
  767. },
  768. get _docFilename() {
  769. return this._contentDispositionFilename || (0, _pdfjsLib.getPdfFilenameFromUrl)(this.url);
  770. },
  771. _cancelIdleCallbacks() {
  772. if (!this._idleCallbacks.size) {
  773. return;
  774. }
  775. for (const callback of this._idleCallbacks) {
  776. window.cancelIdleCallback(callback);
  777. }
  778. this._idleCallbacks.clear();
  779. },
  780. async close() {
  781. this._unblockDocumentLoadEvent();
  782. const {
  783. container
  784. } = this.appConfig.errorWrapper;
  785. container.hidden = true;
  786. if (!this.pdfLoadingTask) {
  787. return;
  788. }
  789. if (this.pdfDocument?.annotationStorage.size > 0 && this._annotationStorageModified) {
  790. try {
  791. await this.save({
  792. sourceEventType: "save"
  793. });
  794. } catch (reason) {}
  795. }
  796. const promises = [];
  797. promises.push(this.pdfLoadingTask.destroy());
  798. this.pdfLoadingTask = null;
  799. if (this.pdfDocument) {
  800. this.pdfDocument = null;
  801. this.pdfThumbnailViewer.setDocument(null);
  802. this.pdfViewer.setDocument(null);
  803. this.pdfLinkService.setDocument(null);
  804. this.pdfDocumentProperties.setDocument(null);
  805. }
  806. webViewerResetPermissions();
  807. this.store = null;
  808. this.isInitialViewSet = false;
  809. this.downloadComplete = false;
  810. this.url = "";
  811. this.baseUrl = "";
  812. this.documentInfo = null;
  813. this.metadata = null;
  814. this._contentDispositionFilename = null;
  815. this._contentLength = null;
  816. this.triggerDelayedFallback = null;
  817. this._saveInProgress = false;
  818. this._cancelIdleCallbacks();
  819. promises.push(this.pdfScriptingManager.destroyPromise);
  820. this.pdfSidebar.reset();
  821. this.pdfOutlineViewer.reset();
  822. this.pdfAttachmentViewer.reset();
  823. this.pdfLayerViewer.reset();
  824. if (this.pdfHistory) {
  825. this.pdfHistory.reset();
  826. }
  827. if (this.findBar) {
  828. this.findBar.reset();
  829. }
  830. this.toolbar.reset();
  831. this.secondaryToolbar.reset();
  832. if (typeof PDFBug !== "undefined") {
  833. PDFBug.cleanup();
  834. }
  835. await Promise.all(promises);
  836. },
  837. async open(file, args) {
  838. if (this.pdfLoadingTask) {
  839. await this.close();
  840. }
  841. const workerParameters = _app_options.AppOptions.getAll(_app_options.OptionKind.WORKER);
  842. for (const key in workerParameters) {
  843. _pdfjsLib.GlobalWorkerOptions[key] = workerParameters[key];
  844. }
  845. const parameters = Object.create(null);
  846. if (typeof file === "string") {
  847. this.setTitleUsingUrl(file);
  848. parameters.url = file;
  849. } else if (file && "byteLength" in file) {
  850. parameters.data = file;
  851. } else if (file.url && file.originalUrl) {
  852. this.setTitleUsingUrl(file.originalUrl);
  853. parameters.url = file.url;
  854. }
  855. const apiParameters = _app_options.AppOptions.getAll(_app_options.OptionKind.API);
  856. for (const key in apiParameters) {
  857. let value = apiParameters[key];
  858. if (key === "docBaseUrl" && !value) {}
  859. parameters[key] = value;
  860. }
  861. if (args) {
  862. for (const key in args) {
  863. parameters[key] = args[key];
  864. }
  865. }
  866. const loadingTask = (0, _pdfjsLib.getDocument)(parameters);
  867. this.pdfLoadingTask = loadingTask;
  868. loadingTask.onPassword = (updateCallback, reason) => {
  869. this.pdfLinkService.externalLinkEnabled = false;
  870. this.passwordPrompt.setUpdateCallback(updateCallback, reason);
  871. this.passwordPrompt.open();
  872. };
  873. loadingTask.onProgress = ({
  874. loaded,
  875. total
  876. }) => {
  877. this.progress(loaded / total);
  878. };
  879. loadingTask.onUnsupportedFeature = this.fallback.bind(this);
  880. return loadingTask.promise.then(pdfDocument => {
  881. this.load(pdfDocument);
  882. }, exception => {
  883. if (loadingTask !== this.pdfLoadingTask) {
  884. return undefined;
  885. }
  886. let key = "loading_error";
  887. if (exception instanceof _pdfjsLib.InvalidPDFException) {
  888. key = "invalid_file_error";
  889. } else if (exception instanceof _pdfjsLib.MissingPDFException) {
  890. key = "missing_file_error";
  891. } else if (exception instanceof _pdfjsLib.UnexpectedResponseException) {
  892. key = "unexpected_response_error";
  893. }
  894. return this.l10n.get(key).then(msg => {
  895. this._documentError(msg, {
  896. message: exception?.message
  897. });
  898. throw exception;
  899. });
  900. });
  901. },
  902. _ensureDownloadComplete() {
  903. if (this.pdfDocument && this.downloadComplete) {
  904. return;
  905. }
  906. throw new Error("PDF document not downloaded.");
  907. },
  908. async download({
  909. sourceEventType = "download"
  910. } = {}) {
  911. const url = this.baseUrl,
  912. filename = this._docFilename;
  913. try {
  914. this._ensureDownloadComplete();
  915. const data = await this.pdfDocument.getData();
  916. const blob = new Blob([data], {
  917. type: "application/pdf"
  918. });
  919. await this.downloadManager.download(blob, url, filename, sourceEventType);
  920. } catch (reason) {
  921. await this.downloadManager.downloadUrl(url, filename);
  922. }
  923. },
  924. async save({
  925. sourceEventType = "download"
  926. } = {}) {
  927. if (this._saveInProgress) {
  928. return;
  929. }
  930. this._saveInProgress = true;
  931. await this.pdfScriptingManager.dispatchWillSave();
  932. const url = this.baseUrl,
  933. filename = this._docFilename;
  934. try {
  935. this._ensureDownloadComplete();
  936. const data = await this.pdfDocument.saveDocument(this.pdfDocument.annotationStorage);
  937. const blob = new Blob([data], {
  938. type: "application/pdf"
  939. });
  940. await this.downloadManager.download(blob, url, filename, sourceEventType);
  941. } catch (reason) {
  942. await this.download({
  943. sourceEventType
  944. });
  945. } finally {
  946. await this.pdfScriptingManager.dispatchDidSave();
  947. this._saveInProgress = false;
  948. }
  949. },
  950. downloadOrSave(options) {
  951. if (this.pdfDocument?.annotationStorage.size > 0) {
  952. this.save(options);
  953. } else {
  954. this.download(options);
  955. }
  956. },
  957. _delayedFallback(featureId) {
  958. this.externalServices.reportTelemetry({
  959. type: "unsupportedFeature",
  960. featureId
  961. });
  962. if (!this.triggerDelayedFallback) {
  963. this.triggerDelayedFallback = () => {
  964. this.fallback(featureId);
  965. this.triggerDelayedFallback = null;
  966. };
  967. }
  968. },
  969. fallback(featureId) {
  970. this.externalServices.reportTelemetry({
  971. type: "unsupportedFeature",
  972. featureId
  973. });
  974. switch (featureId) {
  975. case _pdfjsLib.UNSUPPORTED_FEATURES.errorFontLoadNative:
  976. case _pdfjsLib.UNSUPPORTED_FEATURES.errorFontMissing:
  977. return;
  978. }
  979. if (this.fellback) {
  980. return;
  981. }
  982. this.fellback = true;
  983. this.externalServices.fallback({
  984. featureId,
  985. url: this.baseUrl
  986. }).then(download => {
  987. if (!download) {
  988. return;
  989. }
  990. this.download({
  991. sourceEventType: "download"
  992. });
  993. });
  994. },
  995. _documentError(message, moreInfo = null) {
  996. this._unblockDocumentLoadEvent();
  997. this._otherError(message, moreInfo);
  998. },
  999. _otherError(message, moreInfo = null) {
  1000. const moreInfoText = [this.l10n.get("error_version_info", {
  1001. version: _pdfjsLib.version || "?",
  1002. build: _pdfjsLib.build || "?"
  1003. })];
  1004. if (moreInfo) {
  1005. moreInfoText.push(this.l10n.get("error_message", {
  1006. message: moreInfo.message
  1007. }));
  1008. if (moreInfo.stack) {
  1009. moreInfoText.push(this.l10n.get("error_stack", {
  1010. stack: moreInfo.stack
  1011. }));
  1012. } else {
  1013. if (moreInfo.filename) {
  1014. moreInfoText.push(this.l10n.get("error_file", {
  1015. file: moreInfo.filename
  1016. }));
  1017. }
  1018. if (moreInfo.lineNumber) {
  1019. moreInfoText.push(this.l10n.get("error_line", {
  1020. line: moreInfo.lineNumber
  1021. }));
  1022. }
  1023. }
  1024. }
  1025. const errorWrapperConfig = this.appConfig.errorWrapper;
  1026. const errorWrapper = errorWrapperConfig.container;
  1027. errorWrapper.hidden = false;
  1028. const errorMessage = errorWrapperConfig.errorMessage;
  1029. errorMessage.textContent = message;
  1030. const closeButton = errorWrapperConfig.closeButton;
  1031. closeButton.onclick = function () {
  1032. errorWrapper.hidden = true;
  1033. };
  1034. const errorMoreInfo = errorWrapperConfig.errorMoreInfo;
  1035. const moreInfoButton = errorWrapperConfig.moreInfoButton;
  1036. const lessInfoButton = errorWrapperConfig.lessInfoButton;
  1037. moreInfoButton.onclick = function () {
  1038. errorMoreInfo.hidden = false;
  1039. moreInfoButton.hidden = true;
  1040. lessInfoButton.hidden = false;
  1041. errorMoreInfo.style.height = errorMoreInfo.scrollHeight + "px";
  1042. };
  1043. lessInfoButton.onclick = function () {
  1044. errorMoreInfo.hidden = true;
  1045. moreInfoButton.hidden = false;
  1046. lessInfoButton.hidden = true;
  1047. };
  1048. moreInfoButton.oncontextmenu = _ui_utils.noContextMenuHandler;
  1049. lessInfoButton.oncontextmenu = _ui_utils.noContextMenuHandler;
  1050. closeButton.oncontextmenu = _ui_utils.noContextMenuHandler;
  1051. moreInfoButton.hidden = false;
  1052. lessInfoButton.hidden = true;
  1053. Promise.all(moreInfoText).then(parts => {
  1054. errorMoreInfo.value = parts.join("\n");
  1055. });
  1056. },
  1057. progress(level) {
  1058. if (this.downloadComplete) {
  1059. return;
  1060. }
  1061. const percent = Math.round(level * 100);
  1062. if (percent > this.loadingBar.percent || isNaN(percent)) {
  1063. this.loadingBar.percent = percent;
  1064. const disableAutoFetch = this.pdfDocument ? this.pdfDocument.loadingParams.disableAutoFetch : _app_options.AppOptions.get("disableAutoFetch");
  1065. if (disableAutoFetch && percent) {
  1066. if (this.disableAutoFetchLoadingBarTimeout) {
  1067. clearTimeout(this.disableAutoFetchLoadingBarTimeout);
  1068. this.disableAutoFetchLoadingBarTimeout = null;
  1069. }
  1070. this.loadingBar.show();
  1071. this.disableAutoFetchLoadingBarTimeout = setTimeout(() => {
  1072. this.loadingBar.hide();
  1073. this.disableAutoFetchLoadingBarTimeout = null;
  1074. }, DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT);
  1075. }
  1076. }
  1077. },
  1078. load(pdfDocument) {
  1079. this.pdfDocument = pdfDocument;
  1080. pdfDocument.getDownloadInfo().then(({
  1081. length
  1082. }) => {
  1083. this._contentLength = length;
  1084. this.downloadComplete = true;
  1085. this.loadingBar.hide();
  1086. firstPagePromise.then(() => {
  1087. this.eventBus.dispatch("documentloaded", {
  1088. source: this
  1089. });
  1090. });
  1091. });
  1092. const pageLayoutPromise = pdfDocument.getPageLayout().catch(function () {});
  1093. const pageModePromise = pdfDocument.getPageMode().catch(function () {});
  1094. const openActionPromise = pdfDocument.getOpenAction().catch(function () {});
  1095. this.toolbar.setPagesCount(pdfDocument.numPages, false);
  1096. this.secondaryToolbar.setPagesCount(pdfDocument.numPages);
  1097. let baseDocumentUrl;
  1098. baseDocumentUrl = null;
  1099. this.pdfLinkService.setDocument(pdfDocument, baseDocumentUrl);
  1100. this.pdfDocumentProperties.setDocument(pdfDocument, this.url);
  1101. const pdfViewer = this.pdfViewer;
  1102. pdfViewer.setDocument(pdfDocument);
  1103. const {
  1104. firstPagePromise,
  1105. onePageRendered,
  1106. pagesPromise
  1107. } = pdfViewer;
  1108. const pdfThumbnailViewer = this.pdfThumbnailViewer;
  1109. pdfThumbnailViewer.setDocument(pdfDocument);
  1110. const storedPromise = (this.store = new _view_history.ViewHistory(pdfDocument.fingerprint)).getMultiple({
  1111. page: null,
  1112. zoom: _ui_utils.DEFAULT_SCALE_VALUE,
  1113. scrollLeft: "0",
  1114. scrollTop: "0",
  1115. rotation: null,
  1116. sidebarView: _ui_utils.SidebarView.UNKNOWN,
  1117. scrollMode: _ui_utils.ScrollMode.UNKNOWN,
  1118. spreadMode: _ui_utils.SpreadMode.UNKNOWN
  1119. }).catch(() => {
  1120. return Object.create(null);
  1121. });
  1122. firstPagePromise.then(pdfPage => {
  1123. this.loadingBar.setWidth(this.appConfig.viewerContainer);
  1124. this._initializeAnnotationStorageCallbacks(pdfDocument);
  1125. Promise.all([_ui_utils.animationStarted, storedPromise, pageLayoutPromise, pageModePromise, openActionPromise]).then(async ([timeStamp, stored, pageLayout, pageMode, openAction]) => {
  1126. const viewOnLoad = _app_options.AppOptions.get("viewOnLoad");
  1127. this._initializePdfHistory({
  1128. fingerprint: pdfDocument.fingerprint,
  1129. viewOnLoad,
  1130. initialDest: openAction?.dest
  1131. });
  1132. const initialBookmark = this.initialBookmark;
  1133. const zoom = _app_options.AppOptions.get("defaultZoomValue");
  1134. let hash = zoom ? `zoom=${zoom}` : null;
  1135. let rotation = null;
  1136. let sidebarView = _app_options.AppOptions.get("sidebarViewOnLoad");
  1137. let scrollMode = _app_options.AppOptions.get("scrollModeOnLoad");
  1138. let spreadMode = _app_options.AppOptions.get("spreadModeOnLoad");
  1139. if (stored.page && viewOnLoad !== ViewOnLoad.INITIAL) {
  1140. hash = `page=${stored.page}&zoom=${zoom || stored.zoom},` + `${stored.scrollLeft},${stored.scrollTop}`;
  1141. rotation = parseInt(stored.rotation, 10);
  1142. if (sidebarView === _ui_utils.SidebarView.UNKNOWN) {
  1143. sidebarView = stored.sidebarView | 0;
  1144. }
  1145. if (scrollMode === _ui_utils.ScrollMode.UNKNOWN) {
  1146. scrollMode = stored.scrollMode | 0;
  1147. }
  1148. if (spreadMode === _ui_utils.SpreadMode.UNKNOWN) {
  1149. spreadMode = stored.spreadMode | 0;
  1150. }
  1151. }
  1152. if (pageMode && sidebarView === _ui_utils.SidebarView.UNKNOWN) {
  1153. sidebarView = (0, _ui_utils.apiPageModeToSidebarView)(pageMode);
  1154. }
  1155. if (pageLayout && spreadMode === _ui_utils.SpreadMode.UNKNOWN) {
  1156. spreadMode = (0, _ui_utils.apiPageLayoutToSpreadMode)(pageLayout);
  1157. }
  1158. this.setInitialView(hash, {
  1159. rotation,
  1160. sidebarView,
  1161. scrollMode,
  1162. spreadMode
  1163. });
  1164. this.eventBus.dispatch("documentinit", {
  1165. source: this
  1166. });
  1167. if (!this.isViewerEmbedded) {
  1168. pdfViewer.focus();
  1169. }
  1170. this._initializePermissions(pdfDocument);
  1171. await Promise.race([pagesPromise, new Promise(resolve => {
  1172. setTimeout(resolve, FORCE_PAGES_LOADED_TIMEOUT);
  1173. })]);
  1174. if (!initialBookmark && !hash) {
  1175. return;
  1176. }
  1177. if (pdfViewer.hasEqualPageSizes) {
  1178. return;
  1179. }
  1180. this.initialBookmark = initialBookmark;
  1181. pdfViewer.currentScaleValue = pdfViewer.currentScaleValue;
  1182. this.setInitialView(hash);
  1183. }).catch(() => {
  1184. this.setInitialView();
  1185. }).then(function () {
  1186. pdfViewer.update();
  1187. });
  1188. });
  1189. pagesPromise.then(() => {
  1190. this._unblockDocumentLoadEvent();
  1191. this._initializeAutoPrint(pdfDocument, openActionPromise);
  1192. });
  1193. onePageRendered.then(() => {
  1194. pdfDocument.getOutline().then(outline => {
  1195. this.pdfOutlineViewer.render({
  1196. outline,
  1197. pdfDocument
  1198. });
  1199. });
  1200. pdfDocument.getAttachments().then(attachments => {
  1201. this.pdfAttachmentViewer.render({
  1202. attachments
  1203. });
  1204. });
  1205. pdfViewer.optionalContentConfigPromise.then(optionalContentConfig => {
  1206. this.pdfLayerViewer.render({
  1207. optionalContentConfig,
  1208. pdfDocument
  1209. });
  1210. });
  1211. if ("requestIdleCallback" in window) {
  1212. const callback = window.requestIdleCallback(() => {
  1213. this._collectTelemetry(pdfDocument);
  1214. this._idleCallbacks.delete(callback);
  1215. }, {
  1216. timeout: 1000
  1217. });
  1218. this._idleCallbacks.add(callback);
  1219. }
  1220. });
  1221. this._initializePageLabels(pdfDocument);
  1222. this._initializeMetadata(pdfDocument);
  1223. },
  1224. async _scriptingDocProperties(pdfDocument) {
  1225. if (!this.documentInfo) {
  1226. await new Promise(resolve => {
  1227. this.eventBus._on("metadataloaded", resolve, {
  1228. once: true
  1229. });
  1230. });
  1231. if (pdfDocument !== this.pdfDocument) {
  1232. return null;
  1233. }
  1234. }
  1235. if (!this._contentLength) {
  1236. await new Promise(resolve => {
  1237. this.eventBus._on("documentloaded", resolve, {
  1238. once: true
  1239. });
  1240. });
  1241. if (pdfDocument !== this.pdfDocument) {
  1242. return null;
  1243. }
  1244. }
  1245. return { ...this.documentInfo,
  1246. baseURL: this.baseUrl,
  1247. filesize: this._contentLength,
  1248. filename: this._docFilename,
  1249. metadata: this.metadata?.getRaw(),
  1250. authors: this.metadata?.get("dc:creator"),
  1251. numPages: this.pagesCount,
  1252. URL: this.url
  1253. };
  1254. },
  1255. async _collectTelemetry(pdfDocument) {
  1256. const markInfo = await this.pdfDocument.getMarkInfo();
  1257. if (pdfDocument !== this.pdfDocument) {
  1258. return;
  1259. }
  1260. const tagged = markInfo?.Marked || false;
  1261. this.externalServices.reportTelemetry({
  1262. type: "tagged",
  1263. tagged
  1264. });
  1265. },
  1266. async _initializeAutoPrint(pdfDocument, openActionPromise) {
  1267. const [openAction, javaScript] = await Promise.all([openActionPromise, !this.pdfViewer.enableScripting ? pdfDocument.getJavaScript() : null]);
  1268. if (pdfDocument !== this.pdfDocument) {
  1269. return;
  1270. }
  1271. let triggerAutoPrint = false;
  1272. if (openAction?.action === "Print") {
  1273. triggerAutoPrint = true;
  1274. }
  1275. if (javaScript) {
  1276. javaScript.some(js => {
  1277. if (!js) {
  1278. return false;
  1279. }
  1280. console.warn("Warning: JavaScript is not supported");
  1281. this._delayedFallback(_pdfjsLib.UNSUPPORTED_FEATURES.javaScript);
  1282. return true;
  1283. });
  1284. if (!triggerAutoPrint) {
  1285. for (const js of javaScript) {
  1286. if (js && _ui_utils.AutoPrintRegExp.test(js)) {
  1287. triggerAutoPrint = true;
  1288. break;
  1289. }
  1290. }
  1291. }
  1292. }
  1293. if (triggerAutoPrint) {
  1294. this.triggerPrinting();
  1295. }
  1296. },
  1297. async _initializeMetadata(pdfDocument) {
  1298. const {
  1299. info,
  1300. metadata,
  1301. contentDispositionFilename,
  1302. contentLength
  1303. } = await pdfDocument.getMetadata();
  1304. if (pdfDocument !== this.pdfDocument) {
  1305. return;
  1306. }
  1307. this.documentInfo = info;
  1308. this.metadata = metadata;
  1309. this._contentDispositionFilename ?? (this._contentDispositionFilename = contentDispositionFilename);
  1310. this._contentLength ?? (this._contentLength = contentLength);
  1311. console.log(`PDF ${pdfDocument.fingerprint} [${info.PDFFormatVersion} ` + `${(info.Producer || "-").trim()} / ${(info.Creator || "-").trim()}] ` + `(PDF.js: ${_pdfjsLib.version || "-"}` + `${this.pdfViewer.enableWebGL ? " [WebGL]" : ""})`);
  1312. let pdfTitle = info?.Title;
  1313. const metadataTitle = metadata?.get("dc:title");
  1314. if (metadataTitle) {
  1315. if (metadataTitle !== "Untitled" && !/[\uFFF0-\uFFFF]/g.test(metadataTitle)) {
  1316. pdfTitle = metadataTitle;
  1317. }
  1318. }
  1319. if (pdfTitle) {
  1320. this.setTitle(`${pdfTitle} - ${contentDispositionFilename || document.title}`);
  1321. } else if (contentDispositionFilename) {
  1322. this.setTitle(contentDispositionFilename);
  1323. }
  1324. if (info.IsXFAPresent && !info.IsAcroFormPresent && !pdfDocument.isPureXfa) {
  1325. console.warn("Warning: XFA is not supported");
  1326. this._delayedFallback(_pdfjsLib.UNSUPPORTED_FEATURES.forms);
  1327. } else if ((info.IsAcroFormPresent || info.IsXFAPresent) && !this.pdfViewer.renderInteractiveForms) {
  1328. console.warn("Warning: Interactive form support is not enabled");
  1329. this._delayedFallback(_pdfjsLib.UNSUPPORTED_FEATURES.forms);
  1330. }
  1331. let versionId = "other";
  1332. if (KNOWN_VERSIONS.includes(info.PDFFormatVersion)) {
  1333. versionId = `v${info.PDFFormatVersion.replace(".", "_")}`;
  1334. }
  1335. let generatorId = "other";
  1336. if (info.Producer) {
  1337. const producer = info.Producer.toLowerCase();
  1338. KNOWN_GENERATORS.some(function (generator) {
  1339. if (!producer.includes(generator)) {
  1340. return false;
  1341. }
  1342. generatorId = generator.replace(/[ .-]/g, "_");
  1343. return true;
  1344. });
  1345. }
  1346. let formType = null;
  1347. if (info.IsXFAPresent) {
  1348. formType = "xfa";
  1349. } else if (info.IsAcroFormPresent) {
  1350. formType = "acroform";
  1351. }
  1352. this.externalServices.reportTelemetry({
  1353. type: "documentInfo",
  1354. version: versionId,
  1355. generator: generatorId,
  1356. formType
  1357. });
  1358. this.eventBus.dispatch("metadataloaded", {
  1359. source: this
  1360. });
  1361. },
  1362. async _initializePageLabels(pdfDocument) {
  1363. const labels = await pdfDocument.getPageLabels();
  1364. if (pdfDocument !== this.pdfDocument) {
  1365. return;
  1366. }
  1367. if (!labels || _app_options.AppOptions.get("disablePageLabels")) {
  1368. return;
  1369. }
  1370. const numLabels = labels.length;
  1371. if (numLabels !== this.pagesCount) {
  1372. console.error("The number of Page Labels does not match the number of pages in the document.");
  1373. return;
  1374. }
  1375. let i = 0;
  1376. while (i < numLabels && labels[i] === (i + 1).toString()) {
  1377. i++;
  1378. }
  1379. if (i === numLabels) {
  1380. return;
  1381. }
  1382. const {
  1383. pdfViewer,
  1384. pdfThumbnailViewer,
  1385. toolbar
  1386. } = this;
  1387. pdfViewer.setPageLabels(labels);
  1388. pdfThumbnailViewer.setPageLabels(labels);
  1389. toolbar.setPagesCount(numLabels, true);
  1390. toolbar.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
  1391. },
  1392. _initializePdfHistory({
  1393. fingerprint,
  1394. viewOnLoad,
  1395. initialDest = null
  1396. }) {
  1397. if (this.isViewerEmbedded || _app_options.AppOptions.get("disableHistory")) {
  1398. return;
  1399. }
  1400. this.pdfHistory.initialize({
  1401. fingerprint,
  1402. resetHistory: viewOnLoad === ViewOnLoad.INITIAL,
  1403. updateUrl: _app_options.AppOptions.get("historyUpdateUrl")
  1404. });
  1405. if (this.pdfHistory.initialBookmark) {
  1406. this.initialBookmark = this.pdfHistory.initialBookmark;
  1407. this.initialRotation = this.pdfHistory.initialRotation;
  1408. }
  1409. if (initialDest && !this.initialBookmark && viewOnLoad === ViewOnLoad.UNKNOWN) {
  1410. this.initialBookmark = JSON.stringify(initialDest);
  1411. this.pdfHistory.push({
  1412. explicitDest: initialDest,
  1413. pageNumber: null
  1414. });
  1415. }
  1416. },
  1417. async _initializePermissions(pdfDocument) {
  1418. const permissions = await pdfDocument.getPermissions();
  1419. if (pdfDocument !== this.pdfDocument) {
  1420. return;
  1421. }
  1422. if (!permissions || !_app_options.AppOptions.get("enablePermissions")) {
  1423. return;
  1424. }
  1425. if (!permissions.includes(_pdfjsLib.PermissionFlag.COPY)) {
  1426. this.appConfig.viewerContainer.classList.add(ENABLE_PERMISSIONS_CLASS);
  1427. }
  1428. },
  1429. _initializeAnnotationStorageCallbacks(pdfDocument) {
  1430. if (pdfDocument !== this.pdfDocument) {
  1431. return;
  1432. }
  1433. const {
  1434. annotationStorage
  1435. } = pdfDocument;
  1436. annotationStorage.onSetModified = () => {
  1437. window.addEventListener("beforeunload", beforeUnload);
  1438. this._annotationStorageModified = true;
  1439. };
  1440. annotationStorage.onResetModified = () => {
  1441. window.removeEventListener("beforeunload", beforeUnload);
  1442. delete this._annotationStorageModified;
  1443. };
  1444. },
  1445. setInitialView(storedHash, {
  1446. rotation,
  1447. sidebarView,
  1448. scrollMode,
  1449. spreadMode
  1450. } = {}) {
  1451. const setRotation = angle => {
  1452. if ((0, _ui_utils.isValidRotation)(angle)) {
  1453. this.pdfViewer.pagesRotation = angle;
  1454. }
  1455. };
  1456. const setViewerModes = (scroll, spread) => {
  1457. if ((0, _ui_utils.isValidScrollMode)(scroll)) {
  1458. this.pdfViewer.scrollMode = scroll;
  1459. }
  1460. if ((0, _ui_utils.isValidSpreadMode)(spread)) {
  1461. this.pdfViewer.spreadMode = spread;
  1462. }
  1463. };
  1464. this.isInitialViewSet = true;
  1465. this.pdfSidebar.setInitialView(sidebarView);
  1466. setViewerModes(scrollMode, spreadMode);
  1467. if (this.initialBookmark) {
  1468. setRotation(this.initialRotation);
  1469. delete this.initialRotation;
  1470. this.pdfLinkService.setHash(this.initialBookmark);
  1471. this.initialBookmark = null;
  1472. } else if (storedHash) {
  1473. setRotation(rotation);
  1474. this.pdfLinkService.setHash(storedHash);
  1475. }
  1476. this.toolbar.setPageNumber(this.pdfViewer.currentPageNumber, this.pdfViewer.currentPageLabel);
  1477. this.secondaryToolbar.setPageNumber(this.pdfViewer.currentPageNumber);
  1478. if (!this.pdfViewer.currentScaleValue) {
  1479. this.pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  1480. }
  1481. },
  1482. _cleanup() {
  1483. if (!this.pdfDocument) {
  1484. return;
  1485. }
  1486. this.pdfViewer.cleanup();
  1487. this.pdfThumbnailViewer.cleanup();
  1488. this.pdfDocument.cleanup(this.pdfViewer.renderer === _ui_utils.RendererType.SVG);
  1489. },
  1490. forceRendering() {
  1491. this.pdfRenderingQueue.printing = !!this.printService;
  1492. this.pdfRenderingQueue.isThumbnailViewEnabled = this.pdfSidebar.isThumbnailViewVisible;
  1493. this.pdfRenderingQueue.renderHighestPriority();
  1494. },
  1495. beforePrint() {
  1496. this.pdfScriptingManager.dispatchWillPrint();
  1497. if (this.printService) {
  1498. return;
  1499. }
  1500. if (!this.supportsPrinting) {
  1501. this.l10n.get("printing_not_supported").then(msg => {
  1502. this._otherError(msg);
  1503. });
  1504. return;
  1505. }
  1506. if (!this.pdfViewer.pageViewsReady) {
  1507. this.l10n.get("printing_not_ready").then(msg => {
  1508. window.alert(msg);
  1509. });
  1510. return;
  1511. }
  1512. const pagesOverview = this.pdfViewer.getPagesOverview();
  1513. const printContainer = this.appConfig.printContainer;
  1514. const printResolution = _app_options.AppOptions.get("printResolution");
  1515. const optionalContentConfigPromise = this.pdfViewer.optionalContentConfigPromise;
  1516. const printService = PDFPrintServiceFactory.instance.createPrintService(this.pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise, this.l10n);
  1517. this.printService = printService;
  1518. this.forceRendering();
  1519. printService.layout();
  1520. this.externalServices.reportTelemetry({
  1521. type: "print"
  1522. });
  1523. },
  1524. afterPrint() {
  1525. this.pdfScriptingManager.dispatchDidPrint();
  1526. if (this.printService) {
  1527. this.printService.destroy();
  1528. this.printService = null;
  1529. if (this.pdfDocument) {
  1530. this.pdfDocument.annotationStorage.resetModified();
  1531. }
  1532. }
  1533. this.forceRendering();
  1534. },
  1535. rotatePages(delta) {
  1536. this.pdfViewer.pagesRotation += delta;
  1537. },
  1538. requestPresentationMode() {
  1539. if (!this.pdfPresentationMode) {
  1540. return;
  1541. }
  1542. this.pdfPresentationMode.request();
  1543. },
  1544. triggerPrinting() {
  1545. if (!this.supportsPrinting) {
  1546. return;
  1547. }
  1548. window.print();
  1549. },
  1550. bindEvents() {
  1551. const {
  1552. eventBus,
  1553. _boundEvents
  1554. } = this;
  1555. _boundEvents.beforePrint = this.beforePrint.bind(this);
  1556. _boundEvents.afterPrint = this.afterPrint.bind(this);
  1557. eventBus._on("resize", webViewerResize);
  1558. eventBus._on("hashchange", webViewerHashchange);
  1559. eventBus._on("beforeprint", _boundEvents.beforePrint);
  1560. eventBus._on("afterprint", _boundEvents.afterPrint);
  1561. eventBus._on("pagerendered", webViewerPageRendered);
  1562. eventBus._on("updateviewarea", webViewerUpdateViewarea);
  1563. eventBus._on("pagechanging", webViewerPageChanging);
  1564. eventBus._on("scalechanging", webViewerScaleChanging);
  1565. eventBus._on("rotationchanging", webViewerRotationChanging);
  1566. eventBus._on("sidebarviewchanged", webViewerSidebarViewChanged);
  1567. eventBus._on("pagemode", webViewerPageMode);
  1568. eventBus._on("namedaction", webViewerNamedAction);
  1569. eventBus._on("presentationmodechanged", webViewerPresentationModeChanged);
  1570. eventBus._on("presentationmode", webViewerPresentationMode);
  1571. eventBus._on("print", webViewerPrint);
  1572. eventBus._on("download", webViewerDownload);
  1573. eventBus._on("save", webViewerSave);
  1574. eventBus._on("firstpage", webViewerFirstPage);
  1575. eventBus._on("lastpage", webViewerLastPage);
  1576. eventBus._on("nextpage", webViewerNextPage);
  1577. eventBus._on("previouspage", webViewerPreviousPage);
  1578. eventBus._on("zoomin", webViewerZoomIn);
  1579. eventBus._on("zoomout", webViewerZoomOut);
  1580. eventBus._on("zoomreset", webViewerZoomReset);
  1581. eventBus._on("pagenumberchanged", webViewerPageNumberChanged);
  1582. eventBus._on("scalechanged", webViewerScaleChanged);
  1583. eventBus._on("rotatecw", webViewerRotateCw);
  1584. eventBus._on("rotateccw", webViewerRotateCcw);
  1585. eventBus._on("optionalcontentconfig", webViewerOptionalContentConfig);
  1586. eventBus._on("switchscrollmode", webViewerSwitchScrollMode);
  1587. eventBus._on("scrollmodechanged", webViewerScrollModeChanged);
  1588. eventBus._on("switchspreadmode", webViewerSwitchSpreadMode);
  1589. eventBus._on("spreadmodechanged", webViewerSpreadModeChanged);
  1590. eventBus._on("documentproperties", webViewerDocumentProperties);
  1591. eventBus._on("find", webViewerFind);
  1592. eventBus._on("findfromurlhash", webViewerFindFromUrlHash);
  1593. eventBus._on("updatefindmatchescount", webViewerUpdateFindMatchesCount);
  1594. eventBus._on("updatefindcontrolstate", webViewerUpdateFindControlState);
  1595. if (_app_options.AppOptions.get("pdfBug")) {
  1596. _boundEvents.reportPageStatsPDFBug = reportPageStatsPDFBug;
  1597. eventBus._on("pagerendered", _boundEvents.reportPageStatsPDFBug);
  1598. eventBus._on("pagechanging", _boundEvents.reportPageStatsPDFBug);
  1599. }
  1600. eventBus._on("fileinputchange", webViewerFileInputChange);
  1601. eventBus._on("openfile", webViewerOpenFile);
  1602. },
  1603. bindWindowEvents() {
  1604. const {
  1605. eventBus,
  1606. _boundEvents
  1607. } = this;
  1608. _boundEvents.windowResize = () => {
  1609. eventBus.dispatch("resize", {
  1610. source: window
  1611. });
  1612. };
  1613. _boundEvents.windowHashChange = () => {
  1614. eventBus.dispatch("hashchange", {
  1615. source: window,
  1616. hash: document.location.hash.substring(1)
  1617. });
  1618. };
  1619. _boundEvents.windowBeforePrint = () => {
  1620. eventBus.dispatch("beforeprint", {
  1621. source: window
  1622. });
  1623. };
  1624. _boundEvents.windowAfterPrint = () => {
  1625. eventBus.dispatch("afterprint", {
  1626. source: window
  1627. });
  1628. };
  1629. _boundEvents.windowUpdateFromSandbox = event => {
  1630. eventBus.dispatch("updatefromsandbox", {
  1631. source: window,
  1632. detail: event.detail
  1633. });
  1634. };
  1635. window.addEventListener("visibilitychange", webViewerVisibilityChange);
  1636. window.addEventListener("wheel", webViewerWheel, {
  1637. passive: false
  1638. });
  1639. window.addEventListener("touchstart", webViewerTouchStart, {
  1640. passive: false
  1641. });
  1642. window.addEventListener("click", webViewerClick);
  1643. window.addEventListener("keydown", webViewerKeyDown);
  1644. window.addEventListener("keyup", webViewerKeyUp);
  1645. window.addEventListener("resize", _boundEvents.windowResize);
  1646. window.addEventListener("hashchange", _boundEvents.windowHashChange);
  1647. window.addEventListener("beforeprint", _boundEvents.windowBeforePrint);
  1648. window.addEventListener("afterprint", _boundEvents.windowAfterPrint);
  1649. window.addEventListener("updatefromsandbox", _boundEvents.windowUpdateFromSandbox);
  1650. },
  1651. unbindEvents() {
  1652. const {
  1653. eventBus,
  1654. _boundEvents
  1655. } = this;
  1656. eventBus._off("resize", webViewerResize);
  1657. eventBus._off("hashchange", webViewerHashchange);
  1658. eventBus._off("beforeprint", _boundEvents.beforePrint);
  1659. eventBus._off("afterprint", _boundEvents.afterPrint);
  1660. eventBus._off("pagerendered", webViewerPageRendered);
  1661. eventBus._off("updateviewarea", webViewerUpdateViewarea);
  1662. eventBus._off("pagechanging", webViewerPageChanging);
  1663. eventBus._off("scalechanging", webViewerScaleChanging);
  1664. eventBus._off("rotationchanging", webViewerRotationChanging);
  1665. eventBus._off("sidebarviewchanged", webViewerSidebarViewChanged);
  1666. eventBus._off("pagemode", webViewerPageMode);
  1667. eventBus._off("namedaction", webViewerNamedAction);
  1668. eventBus._off("presentationmodechanged", webViewerPresentationModeChanged);
  1669. eventBus._off("presentationmode", webViewerPresentationMode);
  1670. eventBus._off("print", webViewerPrint);
  1671. eventBus._off("download", webViewerDownload);
  1672. eventBus._off("save", webViewerSave);
  1673. eventBus._off("firstpage", webViewerFirstPage);
  1674. eventBus._off("lastpage", webViewerLastPage);
  1675. eventBus._off("nextpage", webViewerNextPage);
  1676. eventBus._off("previouspage", webViewerPreviousPage);
  1677. eventBus._off("zoomin", webViewerZoomIn);
  1678. eventBus._off("zoomout", webViewerZoomOut);
  1679. eventBus._off("zoomreset", webViewerZoomReset);
  1680. eventBus._off("pagenumberchanged", webViewerPageNumberChanged);
  1681. eventBus._off("scalechanged", webViewerScaleChanged);
  1682. eventBus._off("rotatecw", webViewerRotateCw);
  1683. eventBus._off("rotateccw", webViewerRotateCcw);
  1684. eventBus._off("optionalcontentconfig", webViewerOptionalContentConfig);
  1685. eventBus._off("switchscrollmode", webViewerSwitchScrollMode);
  1686. eventBus._off("scrollmodechanged", webViewerScrollModeChanged);
  1687. eventBus._off("switchspreadmode", webViewerSwitchSpreadMode);
  1688. eventBus._off("spreadmodechanged", webViewerSpreadModeChanged);
  1689. eventBus._off("documentproperties", webViewerDocumentProperties);
  1690. eventBus._off("find", webViewerFind);
  1691. eventBus._off("findfromurlhash", webViewerFindFromUrlHash);
  1692. eventBus._off("updatefindmatchescount", webViewerUpdateFindMatchesCount);
  1693. eventBus._off("updatefindcontrolstate", webViewerUpdateFindControlState);
  1694. if (_boundEvents.reportPageStatsPDFBug) {
  1695. eventBus._off("pagerendered", _boundEvents.reportPageStatsPDFBug);
  1696. eventBus._off("pagechanging", _boundEvents.reportPageStatsPDFBug);
  1697. _boundEvents.reportPageStatsPDFBug = null;
  1698. }
  1699. eventBus._off("fileinputchange", webViewerFileInputChange);
  1700. eventBus._off("openfile", webViewerOpenFile);
  1701. _boundEvents.beforePrint = null;
  1702. _boundEvents.afterPrint = null;
  1703. },
  1704. unbindWindowEvents() {
  1705. const {
  1706. _boundEvents
  1707. } = this;
  1708. window.removeEventListener("visibilitychange", webViewerVisibilityChange);
  1709. window.removeEventListener("wheel", webViewerWheel, {
  1710. passive: false
  1711. });
  1712. window.removeEventListener("touchstart", webViewerTouchStart, {
  1713. passive: false
  1714. });
  1715. window.removeEventListener("click", webViewerClick);
  1716. window.removeEventListener("keydown", webViewerKeyDown);
  1717. window.removeEventListener("keyup", webViewerKeyUp);
  1718. window.removeEventListener("resize", _boundEvents.windowResize);
  1719. window.removeEventListener("hashchange", _boundEvents.windowHashChange);
  1720. window.removeEventListener("beforeprint", _boundEvents.windowBeforePrint);
  1721. window.removeEventListener("afterprint", _boundEvents.windowAfterPrint);
  1722. window.removeEventListener("updatefromsandbox", _boundEvents.windowUpdateFromSandbox);
  1723. _boundEvents.windowResize = null;
  1724. _boundEvents.windowHashChange = null;
  1725. _boundEvents.windowBeforePrint = null;
  1726. _boundEvents.windowAfterPrint = null;
  1727. _boundEvents.windowUpdateFromSandbox = null;
  1728. },
  1729. accumulateWheelTicks(ticks) {
  1730. if (this._wheelUnusedTicks > 0 && ticks < 0 || this._wheelUnusedTicks < 0 && ticks > 0) {
  1731. this._wheelUnusedTicks = 0;
  1732. }
  1733. this._wheelUnusedTicks += ticks;
  1734. const wholeTicks = Math.sign(this._wheelUnusedTicks) * Math.floor(Math.abs(this._wheelUnusedTicks));
  1735. this._wheelUnusedTicks -= wholeTicks;
  1736. return wholeTicks;
  1737. },
  1738. _unblockDocumentLoadEvent() {
  1739. if (document.blockUnblockOnload) {
  1740. document.blockUnblockOnload(false);
  1741. }
  1742. this._unblockDocumentLoadEvent = () => {};
  1743. },
  1744. get scriptingReady() {
  1745. return this.pdfScriptingManager.ready;
  1746. }
  1747. };
  1748. exports.PDFViewerApplication = PDFViewerApplication;
  1749. let validateFileURL;
  1750. {
  1751. const HOSTED_VIEWER_ORIGINS = ["null", "http://mozilla.github.io", "https://mozilla.github.io"];
  1752. validateFileURL = function (file) {
  1753. if (file === undefined) {
  1754. return;
  1755. }
  1756. try {
  1757. const viewerOrigin = new URL(window.location.href).origin || "null";
  1758. if (HOSTED_VIEWER_ORIGINS.includes(viewerOrigin)) {
  1759. return;
  1760. }
  1761. const {
  1762. origin,
  1763. protocol
  1764. } = new URL(file, window.location.href);
  1765. // if (origin !== viewerOrigin && protocol !== "blob:") {
  1766. // throw new Error("file origin does not match viewer's");
  1767. // }
  1768. } catch (ex) {
  1769. PDFViewerApplication.l10n.get("loading_error").then(msg => {
  1770. PDFViewerApplication._documentError(msg, {
  1771. message: ex?.message
  1772. });
  1773. });
  1774. throw ex;
  1775. }
  1776. };
  1777. }
  1778. async function loadFakeWorker() {
  1779. if (!_pdfjsLib.GlobalWorkerOptions.workerSrc) {
  1780. _pdfjsLib.GlobalWorkerOptions.workerSrc = _app_options.AppOptions.get("workerSrc");
  1781. }
  1782. return (0, _pdfjsLib.loadScript)(_pdfjsLib.PDFWorker.getWorkerSrc());
  1783. }
  1784. function loadAndEnablePDFBug(enabledTabs) {
  1785. const appConfig = PDFViewerApplication.appConfig;
  1786. return (0, _pdfjsLib.loadScript)(appConfig.debuggerScriptPath).then(function () {
  1787. PDFBug.enable(enabledTabs);
  1788. PDFBug.init({
  1789. OPS: _pdfjsLib.OPS
  1790. }, appConfig.mainContainer);
  1791. });
  1792. }
  1793. function reportPageStatsPDFBug({
  1794. pageNumber
  1795. }) {
  1796. if (typeof Stats === "undefined" || !Stats.enabled) {
  1797. return;
  1798. }
  1799. const pageView = PDFViewerApplication.pdfViewer.getPageView(pageNumber - 1);
  1800. const pageStats = pageView?.pdfPage?.stats;
  1801. if (!pageStats) {
  1802. return;
  1803. }
  1804. Stats.add(pageNumber, pageStats);
  1805. }
  1806. function webViewerInitialized() {
  1807. const appConfig = PDFViewerApplication.appConfig;
  1808. let file;
  1809. const queryString = document.location.search.substring(1);
  1810. const params = (0, _ui_utils.parseQueryString)(queryString);
  1811. file = "file" in params ? params.file : _app_options.AppOptions.get("defaultUrl");
  1812. validateFileURL(file);
  1813. const fileInput = document.createElement("input");
  1814. fileInput.id = appConfig.openFileInputName;
  1815. fileInput.className = "fileInput";
  1816. fileInput.setAttribute("type", "file");
  1817. fileInput.oncontextmenu = _ui_utils.noContextMenuHandler;
  1818. document.body.appendChild(fileInput);
  1819. if (!window.File || !window.FileReader || !window.FileList || !window.Blob) {
  1820. appConfig.toolbar.openFile.hidden = true;
  1821. appConfig.secondaryToolbar.openFileButton.hidden = true;
  1822. } else {
  1823. fileInput.value = null;
  1824. }
  1825. fileInput.addEventListener("change", function (evt) {
  1826. const files = evt.target.files;
  1827. if (!files || files.length === 0) {
  1828. return;
  1829. }
  1830. PDFViewerApplication.eventBus.dispatch("fileinputchange", {
  1831. source: this,
  1832. fileInput: evt.target
  1833. });
  1834. });
  1835. appConfig.mainContainer.addEventListener("dragover", function (evt) {
  1836. evt.preventDefault();
  1837. evt.dataTransfer.dropEffect = "move";
  1838. });
  1839. appConfig.mainContainer.addEventListener("drop", function (evt) {
  1840. evt.preventDefault();
  1841. const files = evt.dataTransfer.files;
  1842. if (!files || files.length === 0) {
  1843. return;
  1844. }
  1845. PDFViewerApplication.eventBus.dispatch("fileinputchange", {
  1846. source: this,
  1847. fileInput: evt.dataTransfer
  1848. });
  1849. });
  1850. if (!PDFViewerApplication.supportsDocumentFonts) {
  1851. _app_options.AppOptions.set("disableFontFace", true);
  1852. PDFViewerApplication.l10n.get("web_fonts_disabled").then(msg => {
  1853. console.warn(msg);
  1854. });
  1855. }
  1856. if (!PDFViewerApplication.supportsPrinting) {
  1857. appConfig.toolbar.print.classList.add("hidden");
  1858. appConfig.secondaryToolbar.printButton.classList.add("hidden");
  1859. }
  1860. if (!PDFViewerApplication.supportsFullscreen) {
  1861. appConfig.toolbar.presentationModeButton.classList.add("hidden");
  1862. appConfig.secondaryToolbar.presentationModeButton.classList.add("hidden");
  1863. }
  1864. if (PDFViewerApplication.supportsIntegratedFind) {
  1865. appConfig.toolbar.viewFind.classList.add("hidden");
  1866. }
  1867. appConfig.mainContainer.addEventListener("transitionend", function (evt) {
  1868. if (evt.target === this) {
  1869. PDFViewerApplication.eventBus.dispatch("resize", {
  1870. source: this
  1871. });
  1872. }
  1873. }, true);
  1874. try {
  1875. webViewerOpenFileViaURL(file);
  1876. } catch (reason) {
  1877. PDFViewerApplication.l10n.get("loading_error").then(msg => {
  1878. PDFViewerApplication._documentError(msg, reason);
  1879. });
  1880. }
  1881. }
  1882. function webViewerOpenFileViaURL(file) {
  1883. if (file) {
  1884. PDFViewerApplication.open(file);
  1885. }
  1886. }
  1887. function webViewerResetPermissions() {
  1888. const {
  1889. appConfig
  1890. } = PDFViewerApplication;
  1891. if (!appConfig) {
  1892. return;
  1893. }
  1894. appConfig.viewerContainer.classList.remove(ENABLE_PERMISSIONS_CLASS);
  1895. }
  1896. function webViewerPageRendered({
  1897. pageNumber,
  1898. timestamp,
  1899. error
  1900. }) {
  1901. if (pageNumber === PDFViewerApplication.page) {
  1902. PDFViewerApplication.toolbar.updateLoadingIndicatorState(false);
  1903. }
  1904. if (PDFViewerApplication.pdfSidebar.isThumbnailViewVisible) {
  1905. const pageView = PDFViewerApplication.pdfViewer.getPageView(pageNumber - 1);
  1906. const thumbnailView = PDFViewerApplication.pdfThumbnailViewer.getThumbnail(pageNumber - 1);
  1907. if (pageView && thumbnailView) {
  1908. thumbnailView.setImage(pageView);
  1909. }
  1910. }
  1911. if (error) {
  1912. PDFViewerApplication.l10n.get("rendering_error").then(msg => {
  1913. PDFViewerApplication._otherError(msg, error);
  1914. });
  1915. }
  1916. PDFViewerApplication.externalServices.reportTelemetry({
  1917. type: "pageInfo",
  1918. timestamp
  1919. });
  1920. PDFViewerApplication.pdfDocument.getStats().then(function (stats) {
  1921. PDFViewerApplication.externalServices.reportTelemetry({
  1922. type: "documentStats",
  1923. stats
  1924. });
  1925. });
  1926. }
  1927. function webViewerPageMode({
  1928. mode
  1929. }) {
  1930. let view;
  1931. switch (mode) {
  1932. case "thumbs":
  1933. view = _ui_utils.SidebarView.THUMBS;
  1934. break;
  1935. case "bookmarks":
  1936. case "outline":
  1937. view = _ui_utils.SidebarView.OUTLINE;
  1938. break;
  1939. case "attachments":
  1940. view = _ui_utils.SidebarView.ATTACHMENTS;
  1941. break;
  1942. case "layers":
  1943. view = _ui_utils.SidebarView.LAYERS;
  1944. break;
  1945. case "none":
  1946. view = _ui_utils.SidebarView.NONE;
  1947. break;
  1948. default:
  1949. console.error('Invalid "pagemode" hash parameter: ' + mode);
  1950. return;
  1951. }
  1952. PDFViewerApplication.pdfSidebar.switchView(view, true);
  1953. }
  1954. function webViewerNamedAction(evt) {
  1955. switch (evt.action) {
  1956. case "GoToPage":
  1957. PDFViewerApplication.appConfig.toolbar.pageNumber.select();
  1958. break;
  1959. case "Find":
  1960. if (!PDFViewerApplication.supportsIntegratedFind) {
  1961. PDFViewerApplication.findBar.toggle();
  1962. }
  1963. break;
  1964. case "Print":
  1965. PDFViewerApplication.triggerPrinting();
  1966. break;
  1967. case "SaveAs":
  1968. webViewerSave();
  1969. break;
  1970. }
  1971. }
  1972. function webViewerPresentationModeChanged(evt) {
  1973. PDFViewerApplication.pdfViewer.presentationModeState = evt.state;
  1974. }
  1975. function webViewerSidebarViewChanged(evt) {
  1976. PDFViewerApplication.pdfRenderingQueue.isThumbnailViewEnabled = PDFViewerApplication.pdfSidebar.isThumbnailViewVisible;
  1977. const store = PDFViewerApplication.store;
  1978. if (store && PDFViewerApplication.isInitialViewSet) {
  1979. store.set("sidebarView", evt.view).catch(function () {});
  1980. }
  1981. }
  1982. function webViewerUpdateViewarea(evt) {
  1983. const location = evt.location,
  1984. store = PDFViewerApplication.store;
  1985. if (store && PDFViewerApplication.isInitialViewSet) {
  1986. store.setMultiple({
  1987. page: location.pageNumber,
  1988. zoom: location.scale,
  1989. scrollLeft: location.left,
  1990. scrollTop: location.top,
  1991. rotation: location.rotation
  1992. }).catch(function () {});
  1993. }
  1994. const href = PDFViewerApplication.pdfLinkService.getAnchorUrl(location.pdfOpenParams);
  1995. PDFViewerApplication.appConfig.toolbar.viewBookmark.href = href;
  1996. PDFViewerApplication.appConfig.secondaryToolbar.viewBookmarkButton.href = href;
  1997. const currentPage = PDFViewerApplication.pdfViewer.getPageView(PDFViewerApplication.page - 1);
  1998. const loading = currentPage?.renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED;
  1999. PDFViewerApplication.toolbar.updateLoadingIndicatorState(loading);
  2000. }
  2001. function webViewerScrollModeChanged(evt) {
  2002. const store = PDFViewerApplication.store;
  2003. if (store && PDFViewerApplication.isInitialViewSet) {
  2004. store.set("scrollMode", evt.mode).catch(function () {});
  2005. }
  2006. }
  2007. function webViewerSpreadModeChanged(evt) {
  2008. const store = PDFViewerApplication.store;
  2009. if (store && PDFViewerApplication.isInitialViewSet) {
  2010. store.set("spreadMode", evt.mode).catch(function () {});
  2011. }
  2012. }
  2013. function webViewerResize() {
  2014. const {
  2015. pdfDocument,
  2016. pdfViewer
  2017. } = PDFViewerApplication;
  2018. if (!pdfDocument) {
  2019. return;
  2020. }
  2021. const currentScaleValue = pdfViewer.currentScaleValue;
  2022. if (currentScaleValue === "auto" || currentScaleValue === "page-fit" || currentScaleValue === "page-width") {
  2023. pdfViewer.currentScaleValue = currentScaleValue;
  2024. }
  2025. pdfViewer.update();
  2026. }
  2027. function webViewerHashchange(evt) {
  2028. const hash = evt.hash;
  2029. if (!hash) {
  2030. return;
  2031. }
  2032. if (!PDFViewerApplication.isInitialViewSet) {
  2033. PDFViewerApplication.initialBookmark = hash;
  2034. } else if (!PDFViewerApplication.pdfHistory.popStateInProgress) {
  2035. PDFViewerApplication.pdfLinkService.setHash(hash);
  2036. }
  2037. }
  2038. let webViewerFileInputChange, webViewerOpenFile;
  2039. {
  2040. webViewerFileInputChange = function (evt) {
  2041. if (PDFViewerApplication.pdfViewer?.isInPresentationMode) {
  2042. return;
  2043. }
  2044. const file = evt.fileInput.files[0];
  2045. if (!_viewer_compatibility.viewerCompatibilityParams.disableCreateObjectURL) {
  2046. let url = URL.createObjectURL(file);
  2047. if (file.name) {
  2048. url = {
  2049. url,
  2050. originalUrl: file.name
  2051. };
  2052. }
  2053. PDFViewerApplication.open(url);
  2054. } else {
  2055. PDFViewerApplication.setTitleUsingUrl(file.name);
  2056. const fileReader = new FileReader();
  2057. fileReader.onload = function webViewerChangeFileReaderOnload(event) {
  2058. const buffer = event.target.result;
  2059. PDFViewerApplication.open(new Uint8Array(buffer));
  2060. };
  2061. fileReader.readAsArrayBuffer(file);
  2062. }
  2063. const appConfig = PDFViewerApplication.appConfig;
  2064. appConfig.toolbar.viewBookmark.hidden = true;
  2065. appConfig.secondaryToolbar.viewBookmarkButton.hidden = true;
  2066. appConfig.toolbar.download.hidden = true;
  2067. appConfig.secondaryToolbar.downloadButton.hidden = true;
  2068. };
  2069. webViewerOpenFile = function (evt) {
  2070. const openFileInputName = PDFViewerApplication.appConfig.openFileInputName;
  2071. document.getElementById(openFileInputName).click();
  2072. };
  2073. }
  2074. function webViewerPresentationMode() {
  2075. PDFViewerApplication.requestPresentationMode();
  2076. }
  2077. function webViewerPrint() {
  2078. PDFViewerApplication.triggerPrinting();
  2079. }
  2080. function webViewerDownload() {
  2081. PDFViewerApplication.downloadOrSave({
  2082. sourceEventType: "download"
  2083. });
  2084. }
  2085. function webViewerSave() {
  2086. PDFViewerApplication.downloadOrSave({
  2087. sourceEventType: "save"
  2088. });
  2089. }
  2090. function webViewerFirstPage() {
  2091. if (PDFViewerApplication.pdfDocument) {
  2092. PDFViewerApplication.page = 1;
  2093. }
  2094. }
  2095. function webViewerLastPage() {
  2096. if (PDFViewerApplication.pdfDocument) {
  2097. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  2098. }
  2099. }
  2100. function webViewerNextPage() {
  2101. PDFViewerApplication.pdfViewer.nextPage();
  2102. }
  2103. function webViewerPreviousPage() {
  2104. PDFViewerApplication.pdfViewer.previousPage();
  2105. }
  2106. function webViewerZoomIn() {
  2107. PDFViewerApplication.zoomIn();
  2108. }
  2109. function webViewerZoomOut() {
  2110. PDFViewerApplication.zoomOut();
  2111. }
  2112. function webViewerZoomReset() {
  2113. PDFViewerApplication.zoomReset();
  2114. }
  2115. function webViewerPageNumberChanged(evt) {
  2116. const pdfViewer = PDFViewerApplication.pdfViewer;
  2117. if (evt.value !== "") {
  2118. PDFViewerApplication.pdfLinkService.goToPage(evt.value);
  2119. }
  2120. if (evt.value !== pdfViewer.currentPageNumber.toString() && evt.value !== pdfViewer.currentPageLabel) {
  2121. PDFViewerApplication.toolbar.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
  2122. }
  2123. }
  2124. function webViewerScaleChanged(evt) {
  2125. PDFViewerApplication.pdfViewer.currentScaleValue = evt.value;
  2126. }
  2127. function webViewerRotateCw() {
  2128. PDFViewerApplication.rotatePages(90);
  2129. }
  2130. function webViewerRotateCcw() {
  2131. PDFViewerApplication.rotatePages(-90);
  2132. }
  2133. function webViewerOptionalContentConfig(evt) {
  2134. PDFViewerApplication.pdfViewer.optionalContentConfigPromise = evt.promise;
  2135. }
  2136. function webViewerSwitchScrollMode(evt) {
  2137. PDFViewerApplication.pdfViewer.scrollMode = evt.mode;
  2138. }
  2139. function webViewerSwitchSpreadMode(evt) {
  2140. PDFViewerApplication.pdfViewer.spreadMode = evt.mode;
  2141. }
  2142. function webViewerDocumentProperties() {
  2143. PDFViewerApplication.pdfDocumentProperties.open();
  2144. }
  2145. function webViewerFind(evt) {
  2146. PDFViewerApplication.findController.executeCommand("find" + evt.type, {
  2147. query: evt.query,
  2148. phraseSearch: evt.phraseSearch,
  2149. caseSensitive: evt.caseSensitive,
  2150. entireWord: evt.entireWord,
  2151. highlightAll: evt.highlightAll,
  2152. findPrevious: evt.findPrevious
  2153. });
  2154. }
  2155. function webViewerFindFromUrlHash(evt) {
  2156. PDFViewerApplication.findController.executeCommand("find", {
  2157. query: evt.query,
  2158. phraseSearch: evt.phraseSearch,
  2159. caseSensitive: false,
  2160. entireWord: false,
  2161. highlightAll: true,
  2162. findPrevious: false
  2163. });
  2164. }
  2165. function webViewerUpdateFindMatchesCount({
  2166. matchesCount
  2167. }) {
  2168. if (PDFViewerApplication.supportsIntegratedFind) {
  2169. PDFViewerApplication.externalServices.updateFindMatchesCount(matchesCount);
  2170. } else {
  2171. PDFViewerApplication.findBar.updateResultsCount(matchesCount);
  2172. }
  2173. }
  2174. function webViewerUpdateFindControlState({
  2175. state,
  2176. previous,
  2177. matchesCount,
  2178. rawQuery
  2179. }) {
  2180. if (PDFViewerApplication.supportsIntegratedFind) {
  2181. PDFViewerApplication.externalServices.updateFindControlState({
  2182. result: state,
  2183. findPrevious: previous,
  2184. matchesCount,
  2185. rawQuery
  2186. });
  2187. } else {
  2188. PDFViewerApplication.findBar.updateUIState(state, previous, matchesCount);
  2189. }
  2190. }
  2191. function webViewerScaleChanging(evt) {
  2192. PDFViewerApplication.toolbar.setPageScale(evt.presetValue, evt.scale);
  2193. PDFViewerApplication.pdfViewer.update();
  2194. }
  2195. function webViewerRotationChanging(evt) {
  2196. PDFViewerApplication.pdfThumbnailViewer.pagesRotation = evt.pagesRotation;
  2197. PDFViewerApplication.forceRendering();
  2198. PDFViewerApplication.pdfViewer.currentPageNumber = evt.pageNumber;
  2199. }
  2200. function webViewerPageChanging({
  2201. pageNumber,
  2202. pageLabel
  2203. }) {
  2204. PDFViewerApplication.toolbar.setPageNumber(pageNumber, pageLabel);
  2205. PDFViewerApplication.secondaryToolbar.setPageNumber(pageNumber);
  2206. if (PDFViewerApplication.pdfSidebar.isThumbnailViewVisible) {
  2207. PDFViewerApplication.pdfThumbnailViewer.scrollThumbnailIntoView(pageNumber);
  2208. }
  2209. }
  2210. function webViewerVisibilityChange(evt) {
  2211. if (document.visibilityState === "visible") {
  2212. setZoomDisabledTimeout();
  2213. }
  2214. }
  2215. let zoomDisabledTimeout = null;
  2216. function setZoomDisabledTimeout() {
  2217. if (zoomDisabledTimeout) {
  2218. clearTimeout(zoomDisabledTimeout);
  2219. }
  2220. zoomDisabledTimeout = setTimeout(function () {
  2221. zoomDisabledTimeout = null;
  2222. }, WHEEL_ZOOM_DISABLED_TIMEOUT);
  2223. }
  2224. function webViewerWheel(evt) {
  2225. const {
  2226. pdfViewer,
  2227. supportedMouseWheelZoomModifierKeys
  2228. } = PDFViewerApplication;
  2229. if (pdfViewer.isInPresentationMode) {
  2230. return;
  2231. }
  2232. if (evt.ctrlKey && supportedMouseWheelZoomModifierKeys.ctrlKey || evt.metaKey && supportedMouseWheelZoomModifierKeys.metaKey) {
  2233. evt.preventDefault();
  2234. if (zoomDisabledTimeout || document.visibilityState === "hidden") {
  2235. return;
  2236. }
  2237. const previousScale = pdfViewer.currentScale;
  2238. const delta = (0, _ui_utils.normalizeWheelEventDirection)(evt);
  2239. let ticks = 0;
  2240. if (evt.deltaMode === WheelEvent.DOM_DELTA_LINE || evt.deltaMode === WheelEvent.DOM_DELTA_PAGE) {
  2241. if (Math.abs(delta) >= 1) {
  2242. ticks = Math.sign(delta);
  2243. } else {
  2244. ticks = PDFViewerApplication.accumulateWheelTicks(delta);
  2245. }
  2246. } else {
  2247. const PIXELS_PER_LINE_SCALE = 30;
  2248. ticks = PDFViewerApplication.accumulateWheelTicks(delta / PIXELS_PER_LINE_SCALE);
  2249. }
  2250. if (ticks < 0) {
  2251. PDFViewerApplication.zoomOut(-ticks);
  2252. } else if (ticks > 0) {
  2253. PDFViewerApplication.zoomIn(ticks);
  2254. }
  2255. const currentScale = pdfViewer.currentScale;
  2256. if (previousScale !== currentScale) {
  2257. const scaleCorrectionFactor = currentScale / previousScale - 1;
  2258. const rect = pdfViewer.container.getBoundingClientRect();
  2259. const dx = evt.clientX - rect.left;
  2260. const dy = evt.clientY - rect.top;
  2261. pdfViewer.container.scrollLeft += dx * scaleCorrectionFactor;
  2262. pdfViewer.container.scrollTop += dy * scaleCorrectionFactor;
  2263. }
  2264. } else {
  2265. setZoomDisabledTimeout();
  2266. }
  2267. }
  2268. function webViewerTouchStart(evt) {
  2269. if (evt.touches.length > 1) {
  2270. evt.preventDefault();
  2271. }
  2272. }
  2273. function webViewerClick(evt) {
  2274. if (PDFViewerApplication.triggerDelayedFallback && PDFViewerApplication.pdfViewer.containsElement(evt.target)) {
  2275. PDFViewerApplication.triggerDelayedFallback();
  2276. }
  2277. if (!PDFViewerApplication.secondaryToolbar.isOpen) {
  2278. return;
  2279. }
  2280. const appConfig = PDFViewerApplication.appConfig;
  2281. if (PDFViewerApplication.pdfViewer.containsElement(evt.target) || appConfig.toolbar.container.contains(evt.target) && evt.target !== appConfig.secondaryToolbar.toggleButton) {
  2282. PDFViewerApplication.secondaryToolbar.close();
  2283. }
  2284. }
  2285. function webViewerKeyUp(evt) {
  2286. if (evt.keyCode === 9) {
  2287. if (PDFViewerApplication.triggerDelayedFallback) {
  2288. PDFViewerApplication.triggerDelayedFallback();
  2289. }
  2290. }
  2291. }
  2292. function webViewerKeyDown(evt) {
  2293. if (PDFViewerApplication.overlayManager.active) {
  2294. return;
  2295. }
  2296. let handled = false,
  2297. ensureViewerFocused = false;
  2298. const cmd = (evt.ctrlKey ? 1 : 0) | (evt.altKey ? 2 : 0) | (evt.shiftKey ? 4 : 0) | (evt.metaKey ? 8 : 0);
  2299. const pdfViewer = PDFViewerApplication.pdfViewer;
  2300. const isViewerInPresentationMode = pdfViewer?.isInPresentationMode;
  2301. if (cmd === 1 || cmd === 8 || cmd === 5 || cmd === 12) {
  2302. switch (evt.keyCode) {
  2303. case 70:
  2304. if (!PDFViewerApplication.supportsIntegratedFind && !evt.shiftKey) {
  2305. PDFViewerApplication.findBar.open();
  2306. handled = true;
  2307. }
  2308. break;
  2309. case 71:
  2310. if (!PDFViewerApplication.supportsIntegratedFind) {
  2311. const findState = PDFViewerApplication.findController.state;
  2312. if (findState) {
  2313. PDFViewerApplication.findController.executeCommand("findagain", {
  2314. query: findState.query,
  2315. phraseSearch: findState.phraseSearch,
  2316. caseSensitive: findState.caseSensitive,
  2317. entireWord: findState.entireWord,
  2318. highlightAll: findState.highlightAll,
  2319. findPrevious: cmd === 5 || cmd === 12
  2320. });
  2321. }
  2322. handled = true;
  2323. }
  2324. break;
  2325. case 61:
  2326. case 107:
  2327. case 187:
  2328. case 171:
  2329. if (!isViewerInPresentationMode) {
  2330. PDFViewerApplication.zoomIn();
  2331. }
  2332. handled = true;
  2333. break;
  2334. case 173:
  2335. case 109:
  2336. case 189:
  2337. if (!isViewerInPresentationMode) {
  2338. PDFViewerApplication.zoomOut();
  2339. }
  2340. handled = true;
  2341. break;
  2342. case 48:
  2343. case 96:
  2344. if (!isViewerInPresentationMode) {
  2345. setTimeout(function () {
  2346. PDFViewerApplication.zoomReset();
  2347. });
  2348. handled = false;
  2349. }
  2350. break;
  2351. case 38:
  2352. if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
  2353. PDFViewerApplication.page = 1;
  2354. handled = true;
  2355. ensureViewerFocused = true;
  2356. }
  2357. break;
  2358. case 40:
  2359. if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  2360. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  2361. handled = true;
  2362. ensureViewerFocused = true;
  2363. }
  2364. break;
  2365. }
  2366. }
  2367. const {
  2368. eventBus
  2369. } = PDFViewerApplication;
  2370. if (cmd === 1 || cmd === 8) {
  2371. switch (evt.keyCode) {
  2372. case 83:
  2373. eventBus.dispatch("download", {
  2374. source: window
  2375. });
  2376. handled = true;
  2377. break;
  2378. case 79:
  2379. {
  2380. eventBus.dispatch("openfile", {
  2381. source: window
  2382. });
  2383. handled = true;
  2384. }
  2385. break;
  2386. }
  2387. }
  2388. if (cmd === 3 || cmd === 10) {
  2389. switch (evt.keyCode) {
  2390. case 80:
  2391. PDFViewerApplication.requestPresentationMode();
  2392. handled = true;
  2393. break;
  2394. case 71:
  2395. PDFViewerApplication.appConfig.toolbar.pageNumber.select();
  2396. handled = true;
  2397. break;
  2398. }
  2399. }
  2400. if (handled) {
  2401. if (ensureViewerFocused && !isViewerInPresentationMode) {
  2402. pdfViewer.focus();
  2403. }
  2404. evt.preventDefault();
  2405. return;
  2406. }
  2407. const curElement = (0, _ui_utils.getActiveOrFocusedElement)();
  2408. const curElementTagName = curElement?.tagName.toUpperCase();
  2409. if (curElementTagName === "INPUT" || curElementTagName === "TEXTAREA" || curElementTagName === "SELECT" || curElement?.isContentEditable) {
  2410. if (evt.keyCode !== 27) {
  2411. return;
  2412. }
  2413. }
  2414. if (cmd === 0) {
  2415. let turnPage = 0,
  2416. turnOnlyIfPageFit = false;
  2417. switch (evt.keyCode) {
  2418. case 38:
  2419. case 33:
  2420. if (pdfViewer.isVerticalScrollbarEnabled) {
  2421. turnOnlyIfPageFit = true;
  2422. }
  2423. turnPage = -1;
  2424. break;
  2425. case 8:
  2426. if (!isViewerInPresentationMode) {
  2427. turnOnlyIfPageFit = true;
  2428. }
  2429. turnPage = -1;
  2430. break;
  2431. case 37:
  2432. if (pdfViewer.isHorizontalScrollbarEnabled) {
  2433. turnOnlyIfPageFit = true;
  2434. }
  2435. case 75:
  2436. case 80:
  2437. turnPage = -1;
  2438. break;
  2439. case 27:
  2440. if (PDFViewerApplication.secondaryToolbar.isOpen) {
  2441. PDFViewerApplication.secondaryToolbar.close();
  2442. handled = true;
  2443. }
  2444. if (!PDFViewerApplication.supportsIntegratedFind && PDFViewerApplication.findBar.opened) {
  2445. PDFViewerApplication.findBar.close();
  2446. handled = true;
  2447. }
  2448. break;
  2449. case 40:
  2450. case 34:
  2451. if (pdfViewer.isVerticalScrollbarEnabled) {
  2452. turnOnlyIfPageFit = true;
  2453. }
  2454. turnPage = 1;
  2455. break;
  2456. case 13:
  2457. case 32:
  2458. if (!isViewerInPresentationMode) {
  2459. turnOnlyIfPageFit = true;
  2460. }
  2461. turnPage = 1;
  2462. break;
  2463. case 39:
  2464. if (pdfViewer.isHorizontalScrollbarEnabled) {
  2465. turnOnlyIfPageFit = true;
  2466. }
  2467. case 74:
  2468. case 78:
  2469. turnPage = 1;
  2470. break;
  2471. case 36:
  2472. if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
  2473. PDFViewerApplication.page = 1;
  2474. handled = true;
  2475. ensureViewerFocused = true;
  2476. }
  2477. break;
  2478. case 35:
  2479. if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  2480. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  2481. handled = true;
  2482. ensureViewerFocused = true;
  2483. }
  2484. break;
  2485. case 83:
  2486. PDFViewerApplication.pdfCursorTools.switchTool(_pdf_cursor_tools.CursorTool.SELECT);
  2487. break;
  2488. case 72:
  2489. PDFViewerApplication.pdfCursorTools.switchTool(_pdf_cursor_tools.CursorTool.HAND);
  2490. break;
  2491. case 82:
  2492. PDFViewerApplication.rotatePages(90);
  2493. break;
  2494. case 115:
  2495. PDFViewerApplication.pdfSidebar.toggle();
  2496. break;
  2497. }
  2498. if (turnPage !== 0 && (!turnOnlyIfPageFit || pdfViewer.currentScaleValue === "page-fit")) {
  2499. if (turnPage > 0) {
  2500. pdfViewer.nextPage();
  2501. } else {
  2502. pdfViewer.previousPage();
  2503. }
  2504. handled = true;
  2505. }
  2506. }
  2507. if (cmd === 4) {
  2508. switch (evt.keyCode) {
  2509. case 13:
  2510. case 32:
  2511. if (!isViewerInPresentationMode && pdfViewer.currentScaleValue !== "page-fit") {
  2512. break;
  2513. }
  2514. if (PDFViewerApplication.page > 1) {
  2515. PDFViewerApplication.page--;
  2516. }
  2517. handled = true;
  2518. break;
  2519. case 82:
  2520. PDFViewerApplication.rotatePages(-90);
  2521. break;
  2522. }
  2523. }
  2524. if (!handled && !isViewerInPresentationMode) {
  2525. if (evt.keyCode >= 33 && evt.keyCode <= 40 || evt.keyCode === 32 && curElementTagName !== "BUTTON") {
  2526. ensureViewerFocused = true;
  2527. }
  2528. }
  2529. if (ensureViewerFocused && !pdfViewer.containsElement(curElement)) {
  2530. pdfViewer.focus();
  2531. }
  2532. if (handled) {
  2533. evt.preventDefault();
  2534. }
  2535. }
  2536. function beforeUnload(evt) {
  2537. evt.preventDefault();
  2538. evt.returnValue = "";
  2539. return false;
  2540. }
  2541. const PDFPrintServiceFactory = {
  2542. instance: {
  2543. supportsPrinting: false,
  2544. createPrintService() {
  2545. throw new Error("Not implemented: createPrintService");
  2546. }
  2547. }
  2548. };
  2549. exports.PDFPrintServiceFactory = PDFPrintServiceFactory;
  2550. /***/ }),
  2551. /* 4 */
  2552. /***/ ((__unused_webpack_module, exports) => {
  2553. Object.defineProperty(exports, "__esModule", ({
  2554. value: true
  2555. }));
  2556. exports.apiPageLayoutToSpreadMode = apiPageLayoutToSpreadMode;
  2557. exports.apiPageModeToSidebarView = apiPageModeToSidebarView;
  2558. exports.approximateFraction = approximateFraction;
  2559. exports.backtrackBeforeAllVisibleElements = backtrackBeforeAllVisibleElements;
  2560. exports.binarySearchFirstItem = binarySearchFirstItem;
  2561. exports.getActiveOrFocusedElement = getActiveOrFocusedElement;
  2562. exports.getOutputScale = getOutputScale;
  2563. exports.getPageSizeInches = getPageSizeInches;
  2564. exports.getVisibleElements = getVisibleElements;
  2565. exports.isPortraitOrientation = isPortraitOrientation;
  2566. exports.isValidRotation = isValidRotation;
  2567. exports.isValidScrollMode = isValidScrollMode;
  2568. exports.isValidSpreadMode = isValidSpreadMode;
  2569. exports.moveToEndOfArray = moveToEndOfArray;
  2570. exports.noContextMenuHandler = noContextMenuHandler;
  2571. exports.normalizeWheelEventDelta = normalizeWheelEventDelta;
  2572. exports.normalizeWheelEventDirection = normalizeWheelEventDirection;
  2573. exports.parseQueryString = parseQueryString;
  2574. exports.roundToDivide = roundToDivide;
  2575. exports.scrollIntoView = scrollIntoView;
  2576. exports.waitOnEventOrTimeout = waitOnEventOrTimeout;
  2577. exports.watchScroll = watchScroll;
  2578. exports.WaitOnType = exports.VERTICAL_PADDING = exports.UNKNOWN_SCALE = exports.TextLayerMode = exports.SpreadMode = exports.SidebarView = exports.ScrollMode = exports.SCROLLBAR_PADDING = exports.RendererType = exports.ProgressBar = exports.PresentationModeState = exports.MIN_SCALE = exports.MAX_SCALE = exports.MAX_AUTO_SCALE = exports.EventBus = exports.DEFAULT_SCALE_VALUE = exports.DEFAULT_SCALE = exports.CSS_UNITS = exports.AutoPrintRegExp = exports.animationStarted = void 0;
  2579. const CSS_UNITS = 96.0 / 72.0;
  2580. exports.CSS_UNITS = CSS_UNITS;
  2581. const DEFAULT_SCALE_VALUE = "auto";
  2582. exports.DEFAULT_SCALE_VALUE = DEFAULT_SCALE_VALUE;
  2583. const DEFAULT_SCALE = 1.0;
  2584. exports.DEFAULT_SCALE = DEFAULT_SCALE;
  2585. const MIN_SCALE = 0.1;
  2586. exports.MIN_SCALE = MIN_SCALE;
  2587. const MAX_SCALE = 10.0;
  2588. exports.MAX_SCALE = MAX_SCALE;
  2589. const UNKNOWN_SCALE = 0;
  2590. exports.UNKNOWN_SCALE = UNKNOWN_SCALE;
  2591. const MAX_AUTO_SCALE = 1.25;
  2592. exports.MAX_AUTO_SCALE = MAX_AUTO_SCALE;
  2593. const SCROLLBAR_PADDING = 40;
  2594. exports.SCROLLBAR_PADDING = SCROLLBAR_PADDING;
  2595. const VERTICAL_PADDING = 5;
  2596. exports.VERTICAL_PADDING = VERTICAL_PADDING;
  2597. const LOADINGBAR_END_OFFSET_VAR = "--loadingBar-end-offset";
  2598. const PresentationModeState = {
  2599. UNKNOWN: 0,
  2600. NORMAL: 1,
  2601. CHANGING: 2,
  2602. FULLSCREEN: 3
  2603. };
  2604. exports.PresentationModeState = PresentationModeState;
  2605. const SidebarView = {
  2606. UNKNOWN: -1,
  2607. NONE: 0,
  2608. THUMBS: 1,
  2609. OUTLINE: 2,
  2610. ATTACHMENTS: 3,
  2611. LAYERS: 4
  2612. };
  2613. exports.SidebarView = SidebarView;
  2614. const RendererType = {
  2615. CANVAS: "canvas",
  2616. SVG: "svg"
  2617. };
  2618. exports.RendererType = RendererType;
  2619. const TextLayerMode = {
  2620. DISABLE: 0,
  2621. ENABLE: 1,
  2622. ENABLE_ENHANCE: 2
  2623. };
  2624. exports.TextLayerMode = TextLayerMode;
  2625. const ScrollMode = {
  2626. UNKNOWN: -1,
  2627. VERTICAL: 0,
  2628. HORIZONTAL: 1,
  2629. WRAPPED: 2
  2630. };
  2631. exports.ScrollMode = ScrollMode;
  2632. const SpreadMode = {
  2633. UNKNOWN: -1,
  2634. NONE: 0,
  2635. ODD: 1,
  2636. EVEN: 2
  2637. };
  2638. exports.SpreadMode = SpreadMode;
  2639. const AutoPrintRegExp = /\bprint\s*\(/;
  2640. exports.AutoPrintRegExp = AutoPrintRegExp;
  2641. function getOutputScale(ctx) {
  2642. const devicePixelRatio = window.devicePixelRatio || 1;
  2643. const backingStoreRatio = ctx.webkitBackingStorePixelRatio || ctx.mozBackingStorePixelRatio || ctx.backingStorePixelRatio || 1;
  2644. const pixelRatio = devicePixelRatio / backingStoreRatio;
  2645. return {
  2646. sx: pixelRatio,
  2647. sy: pixelRatio,
  2648. scaled: pixelRatio !== 1
  2649. };
  2650. }
  2651. function scrollIntoView(element, spot, skipOverflowHiddenElements = false) {
  2652. let parent = element.offsetParent;
  2653. if (!parent) {
  2654. console.error("offsetParent is not set -- cannot scroll");
  2655. return;
  2656. }
  2657. let offsetY = element.offsetTop + element.clientTop;
  2658. let offsetX = element.offsetLeft + element.clientLeft;
  2659. while (parent.clientHeight === parent.scrollHeight && parent.clientWidth === parent.scrollWidth || skipOverflowHiddenElements && getComputedStyle(parent).overflow === "hidden") {
  2660. if (parent.dataset._scaleY) {
  2661. offsetY /= parent.dataset._scaleY;
  2662. offsetX /= parent.dataset._scaleX;
  2663. }
  2664. offsetY += parent.offsetTop;
  2665. offsetX += parent.offsetLeft;
  2666. parent = parent.offsetParent;
  2667. if (!parent) {
  2668. return;
  2669. }
  2670. }
  2671. if (spot) {
  2672. if (spot.top !== undefined) {
  2673. offsetY += spot.top;
  2674. }
  2675. if (spot.left !== undefined) {
  2676. offsetX += spot.left;
  2677. parent.scrollLeft = offsetX;
  2678. }
  2679. }
  2680. parent.scrollTop = offsetY;
  2681. }
  2682. function watchScroll(viewAreaElement, callback) {
  2683. const debounceScroll = function (evt) {
  2684. if (rAF) {
  2685. return;
  2686. }
  2687. rAF = window.requestAnimationFrame(function viewAreaElementScrolled() {
  2688. rAF = null;
  2689. const currentX = viewAreaElement.scrollLeft;
  2690. const lastX = state.lastX;
  2691. if (currentX !== lastX) {
  2692. state.right = currentX > lastX;
  2693. }
  2694. state.lastX = currentX;
  2695. const currentY = viewAreaElement.scrollTop;
  2696. const lastY = state.lastY;
  2697. if (currentY !== lastY) {
  2698. state.down = currentY > lastY;
  2699. }
  2700. state.lastY = currentY;
  2701. callback(state);
  2702. });
  2703. };
  2704. const state = {
  2705. right: true,
  2706. down: true,
  2707. lastX: viewAreaElement.scrollLeft,
  2708. lastY: viewAreaElement.scrollTop,
  2709. _eventHandler: debounceScroll
  2710. };
  2711. let rAF = null;
  2712. viewAreaElement.addEventListener("scroll", debounceScroll, true);
  2713. return state;
  2714. }
  2715. function parseQueryString(query) {
  2716. const parts = query.split("&");
  2717. const params = Object.create(null);
  2718. for (let i = 0, ii = parts.length; i < ii; ++i) {
  2719. const param = parts[i].split("=");
  2720. const key = param[0].toLowerCase();
  2721. const value = param.length > 1 ? param[1] : null;
  2722. params[decodeURIComponent(key)] = decodeURIComponent(value);
  2723. }
  2724. return params;
  2725. }
  2726. function binarySearchFirstItem(items, condition) {
  2727. let minIndex = 0;
  2728. let maxIndex = items.length - 1;
  2729. if (maxIndex < 0 || !condition(items[maxIndex])) {
  2730. return items.length;
  2731. }
  2732. if (condition(items[minIndex])) {
  2733. return minIndex;
  2734. }
  2735. while (minIndex < maxIndex) {
  2736. const currentIndex = minIndex + maxIndex >> 1;
  2737. const currentItem = items[currentIndex];
  2738. if (condition(currentItem)) {
  2739. maxIndex = currentIndex;
  2740. } else {
  2741. minIndex = currentIndex + 1;
  2742. }
  2743. }
  2744. return minIndex;
  2745. }
  2746. function approximateFraction(x) {
  2747. if (Math.floor(x) === x) {
  2748. return [x, 1];
  2749. }
  2750. const xinv = 1 / x;
  2751. const limit = 8;
  2752. if (xinv > limit) {
  2753. return [1, limit];
  2754. } else if (Math.floor(xinv) === xinv) {
  2755. return [1, xinv];
  2756. }
  2757. const x_ = x > 1 ? xinv : x;
  2758. let a = 0,
  2759. b = 1,
  2760. c = 1,
  2761. d = 1;
  2762. while (true) {
  2763. const p = a + c,
  2764. q = b + d;
  2765. if (q > limit) {
  2766. break;
  2767. }
  2768. if (x_ <= p / q) {
  2769. c = p;
  2770. d = q;
  2771. } else {
  2772. a = p;
  2773. b = q;
  2774. }
  2775. }
  2776. let result;
  2777. if (x_ - a / b < c / d - x_) {
  2778. result = x_ === x ? [a, b] : [b, a];
  2779. } else {
  2780. result = x_ === x ? [c, d] : [d, c];
  2781. }
  2782. return result;
  2783. }
  2784. function roundToDivide(x, div) {
  2785. const r = x % div;
  2786. return r === 0 ? x : Math.round(x - r + div);
  2787. }
  2788. function getPageSizeInches({
  2789. view,
  2790. userUnit,
  2791. rotate
  2792. }) {
  2793. const [x1, y1, x2, y2] = view;
  2794. const changeOrientation = rotate % 180 !== 0;
  2795. const width = (x2 - x1) / 72 * userUnit;
  2796. const height = (y2 - y1) / 72 * userUnit;
  2797. return {
  2798. width: changeOrientation ? height : width,
  2799. height: changeOrientation ? width : height
  2800. };
  2801. }
  2802. function backtrackBeforeAllVisibleElements(index, views, top) {
  2803. if (index < 2) {
  2804. return index;
  2805. }
  2806. let elt = views[index].div;
  2807. let pageTop = elt.offsetTop + elt.clientTop;
  2808. if (pageTop >= top) {
  2809. elt = views[index - 1].div;
  2810. pageTop = elt.offsetTop + elt.clientTop;
  2811. }
  2812. for (let i = index - 2; i >= 0; --i) {
  2813. elt = views[i].div;
  2814. if (elt.offsetTop + elt.clientTop + elt.clientHeight <= pageTop) {
  2815. break;
  2816. }
  2817. index = i;
  2818. }
  2819. return index;
  2820. }
  2821. function getVisibleElements({
  2822. scrollEl,
  2823. views,
  2824. sortByVisibility = false,
  2825. horizontal = false,
  2826. rtl = false
  2827. }) {
  2828. const top = scrollEl.scrollTop,
  2829. bottom = top + scrollEl.clientHeight;
  2830. const left = scrollEl.scrollLeft,
  2831. right = left + scrollEl.clientWidth;
  2832. function isElementBottomAfterViewTop(view) {
  2833. const element = view.div;
  2834. const elementBottom = element.offsetTop + element.clientTop + element.clientHeight;
  2835. return elementBottom > top;
  2836. }
  2837. function isElementNextAfterViewHorizontally(view) {
  2838. const element = view.div;
  2839. const elementLeft = element.offsetLeft + element.clientLeft;
  2840. const elementRight = elementLeft + element.clientWidth;
  2841. return rtl ? elementLeft < right : elementRight > left;
  2842. }
  2843. const visible = [],
  2844. numViews = views.length;
  2845. let firstVisibleElementInd = binarySearchFirstItem(views, horizontal ? isElementNextAfterViewHorizontally : isElementBottomAfterViewTop);
  2846. if (firstVisibleElementInd > 0 && firstVisibleElementInd < numViews && !horizontal) {
  2847. firstVisibleElementInd = backtrackBeforeAllVisibleElements(firstVisibleElementInd, views, top);
  2848. }
  2849. let lastEdge = horizontal ? right : -1;
  2850. for (let i = firstVisibleElementInd; i < numViews; i++) {
  2851. const view = views[i],
  2852. element = view.div;
  2853. const currentWidth = element.offsetLeft + element.clientLeft;
  2854. const currentHeight = element.offsetTop + element.clientTop;
  2855. const viewWidth = element.clientWidth,
  2856. viewHeight = element.clientHeight;
  2857. const viewRight = currentWidth + viewWidth;
  2858. const viewBottom = currentHeight + viewHeight;
  2859. if (lastEdge === -1) {
  2860. if (viewBottom >= bottom) {
  2861. lastEdge = viewBottom;
  2862. }
  2863. } else if ((horizontal ? currentWidth : currentHeight) > lastEdge) {
  2864. break;
  2865. }
  2866. if (viewBottom <= top || currentHeight >= bottom || viewRight <= left || currentWidth >= right) {
  2867. continue;
  2868. }
  2869. const hiddenHeight = Math.max(0, top - currentHeight) + Math.max(0, viewBottom - bottom);
  2870. const hiddenWidth = Math.max(0, left - currentWidth) + Math.max(0, viewRight - right);
  2871. const fractionHeight = (viewHeight - hiddenHeight) / viewHeight,
  2872. fractionWidth = (viewWidth - hiddenWidth) / viewWidth;
  2873. const percent = fractionHeight * fractionWidth * 100 | 0;
  2874. visible.push({
  2875. id: view.id,
  2876. x: currentWidth,
  2877. y: currentHeight,
  2878. view,
  2879. percent,
  2880. widthPercent: fractionWidth * 100 | 0
  2881. });
  2882. }
  2883. const first = visible[0],
  2884. last = visible[visible.length - 1];
  2885. if (sortByVisibility) {
  2886. visible.sort(function (a, b) {
  2887. const pc = a.percent - b.percent;
  2888. if (Math.abs(pc) > 0.001) {
  2889. return -pc;
  2890. }
  2891. return a.id - b.id;
  2892. });
  2893. }
  2894. return {
  2895. first,
  2896. last,
  2897. views: visible
  2898. };
  2899. }
  2900. function noContextMenuHandler(evt) {
  2901. evt.preventDefault();
  2902. }
  2903. function normalizeWheelEventDirection(evt) {
  2904. let delta = Math.hypot(evt.deltaX, evt.deltaY);
  2905. const angle = Math.atan2(evt.deltaY, evt.deltaX);
  2906. if (-0.25 * Math.PI < angle && angle < 0.75 * Math.PI) {
  2907. delta = -delta;
  2908. }
  2909. return delta;
  2910. }
  2911. function normalizeWheelEventDelta(evt) {
  2912. let delta = normalizeWheelEventDirection(evt);
  2913. const MOUSE_DOM_DELTA_PIXEL_MODE = 0;
  2914. const MOUSE_DOM_DELTA_LINE_MODE = 1;
  2915. const MOUSE_PIXELS_PER_LINE = 30;
  2916. const MOUSE_LINES_PER_PAGE = 30;
  2917. if (evt.deltaMode === MOUSE_DOM_DELTA_PIXEL_MODE) {
  2918. delta /= MOUSE_PIXELS_PER_LINE * MOUSE_LINES_PER_PAGE;
  2919. } else if (evt.deltaMode === MOUSE_DOM_DELTA_LINE_MODE) {
  2920. delta /= MOUSE_LINES_PER_PAGE;
  2921. }
  2922. return delta;
  2923. }
  2924. function isValidRotation(angle) {
  2925. return Number.isInteger(angle) && angle % 90 === 0;
  2926. }
  2927. function isValidScrollMode(mode) {
  2928. return Number.isInteger(mode) && Object.values(ScrollMode).includes(mode) && mode !== ScrollMode.UNKNOWN;
  2929. }
  2930. function isValidSpreadMode(mode) {
  2931. return Number.isInteger(mode) && Object.values(SpreadMode).includes(mode) && mode !== SpreadMode.UNKNOWN;
  2932. }
  2933. function isPortraitOrientation(size) {
  2934. return size.width <= size.height;
  2935. }
  2936. const WaitOnType = {
  2937. EVENT: "event",
  2938. TIMEOUT: "timeout"
  2939. };
  2940. exports.WaitOnType = WaitOnType;
  2941. function waitOnEventOrTimeout({
  2942. target,
  2943. name,
  2944. delay = 0
  2945. }) {
  2946. return new Promise(function (resolve, reject) {
  2947. if (typeof target !== "object" || !(name && typeof name === "string") || !(Number.isInteger(delay) && delay >= 0)) {
  2948. throw new Error("waitOnEventOrTimeout - invalid parameters.");
  2949. }
  2950. function handler(type) {
  2951. if (target instanceof EventBus) {
  2952. target._off(name, eventHandler);
  2953. } else {
  2954. target.removeEventListener(name, eventHandler);
  2955. }
  2956. if (timeout) {
  2957. clearTimeout(timeout);
  2958. }
  2959. resolve(type);
  2960. }
  2961. const eventHandler = handler.bind(null, WaitOnType.EVENT);
  2962. if (target instanceof EventBus) {
  2963. target._on(name, eventHandler);
  2964. } else {
  2965. target.addEventListener(name, eventHandler);
  2966. }
  2967. const timeoutHandler = handler.bind(null, WaitOnType.TIMEOUT);
  2968. const timeout = setTimeout(timeoutHandler, delay);
  2969. });
  2970. }
  2971. const animationStarted = new Promise(function (resolve) {
  2972. window.requestAnimationFrame(resolve);
  2973. });
  2974. exports.animationStarted = animationStarted;
  2975. function dispatchDOMEvent(eventName, args = null) {
  2976. throw new Error("Not implemented: dispatchDOMEvent");
  2977. }
  2978. class EventBus {
  2979. constructor(options) {
  2980. this._listeners = Object.create(null);
  2981. }
  2982. on(eventName, listener, options = null) {
  2983. this._on(eventName, listener, {
  2984. external: true,
  2985. once: options?.once
  2986. });
  2987. }
  2988. off(eventName, listener, options = null) {
  2989. this._off(eventName, listener, {
  2990. external: true,
  2991. once: options?.once
  2992. });
  2993. }
  2994. dispatch(eventName) {
  2995. const eventListeners = this._listeners[eventName];
  2996. if (!eventListeners || eventListeners.length === 0) {
  2997. return;
  2998. }
  2999. const args = Array.prototype.slice.call(arguments, 1);
  3000. let externalListeners;
  3001. eventListeners.slice(0).forEach(({
  3002. listener,
  3003. external,
  3004. once
  3005. }) => {
  3006. if (once) {
  3007. this._off(eventName, listener);
  3008. }
  3009. if (external) {
  3010. (externalListeners || (externalListeners = [])).push(listener);
  3011. return;
  3012. }
  3013. listener.apply(null, args);
  3014. });
  3015. if (externalListeners) {
  3016. externalListeners.forEach(listener => {
  3017. listener.apply(null, args);
  3018. });
  3019. externalListeners = null;
  3020. }
  3021. }
  3022. _on(eventName, listener, options = null) {
  3023. var _this$_listeners;
  3024. const eventListeners = (_this$_listeners = this._listeners)[eventName] || (_this$_listeners[eventName] = []);
  3025. eventListeners.push({
  3026. listener,
  3027. external: options?.external === true,
  3028. once: options?.once === true
  3029. });
  3030. }
  3031. _off(eventName, listener, options = null) {
  3032. const eventListeners = this._listeners[eventName];
  3033. if (!eventListeners) {
  3034. return;
  3035. }
  3036. for (let i = 0, ii = eventListeners.length; i < ii; i++) {
  3037. if (eventListeners[i].listener === listener) {
  3038. eventListeners.splice(i, 1);
  3039. return;
  3040. }
  3041. }
  3042. }
  3043. }
  3044. exports.EventBus = EventBus;
  3045. function clamp(v, min, max) {
  3046. return Math.min(Math.max(v, min), max);
  3047. }
  3048. class ProgressBar {
  3049. constructor(id, {
  3050. height,
  3051. width,
  3052. units
  3053. } = {}) {
  3054. this.visible = true;
  3055. this.div = document.querySelector(id + " .progress");
  3056. this.bar = this.div.parentNode;
  3057. this.height = height || 100;
  3058. this.width = width || 100;
  3059. this.units = units || "%";
  3060. this.div.style.height = this.height + this.units;
  3061. this.percent = 0;
  3062. }
  3063. _updateBar() {
  3064. if (this._indeterminate) {
  3065. this.div.classList.add("indeterminate");
  3066. this.div.style.width = this.width + this.units;
  3067. return;
  3068. }
  3069. this.div.classList.remove("indeterminate");
  3070. const progressSize = this.width * this._percent / 100;
  3071. this.div.style.width = progressSize + this.units;
  3072. }
  3073. get percent() {
  3074. return this._percent;
  3075. }
  3076. set percent(val) {
  3077. this._indeterminate = isNaN(val);
  3078. this._percent = clamp(val, 0, 100);
  3079. this._updateBar();
  3080. }
  3081. setWidth(viewer) {
  3082. if (!viewer) {
  3083. return;
  3084. }
  3085. const container = viewer.parentNode;
  3086. const scrollbarWidth = container.offsetWidth - viewer.offsetWidth;
  3087. if (scrollbarWidth > 0) {
  3088. const doc = document.documentElement;
  3089. doc.style.setProperty(LOADINGBAR_END_OFFSET_VAR, `${scrollbarWidth}px`);
  3090. }
  3091. }
  3092. hide() {
  3093. if (!this.visible) {
  3094. return;
  3095. }
  3096. this.visible = false;
  3097. this.bar.classList.add("hidden");
  3098. }
  3099. show() {
  3100. if (this.visible) {
  3101. return;
  3102. }
  3103. this.visible = true;
  3104. this.bar.classList.remove("hidden");
  3105. }
  3106. }
  3107. exports.ProgressBar = ProgressBar;
  3108. function moveToEndOfArray(arr, condition) {
  3109. const moved = [],
  3110. len = arr.length;
  3111. let write = 0;
  3112. for (let read = 0; read < len; ++read) {
  3113. if (condition(arr[read])) {
  3114. moved.push(arr[read]);
  3115. } else {
  3116. arr[write] = arr[read];
  3117. ++write;
  3118. }
  3119. }
  3120. for (let read = 0; write < len; ++read, ++write) {
  3121. arr[write] = moved[read];
  3122. }
  3123. }
  3124. function getActiveOrFocusedElement() {
  3125. let curRoot = document;
  3126. let curActiveOrFocused = curRoot.activeElement || curRoot.querySelector(":focus");
  3127. while (curActiveOrFocused?.shadowRoot) {
  3128. curRoot = curActiveOrFocused.shadowRoot;
  3129. curActiveOrFocused = curRoot.activeElement || curRoot.querySelector(":focus");
  3130. }
  3131. return curActiveOrFocused;
  3132. }
  3133. function apiPageLayoutToSpreadMode(layout) {
  3134. switch (layout) {
  3135. case "SinglePage":
  3136. case "OneColumn":
  3137. return SpreadMode.NONE;
  3138. case "TwoColumnLeft":
  3139. case "TwoPageLeft":
  3140. return SpreadMode.ODD;
  3141. case "TwoColumnRight":
  3142. case "TwoPageRight":
  3143. return SpreadMode.EVEN;
  3144. }
  3145. return SpreadMode.NONE;
  3146. }
  3147. function apiPageModeToSidebarView(mode) {
  3148. switch (mode) {
  3149. case "UseNone":
  3150. return SidebarView.NONE;
  3151. case "UseThumbs":
  3152. return SidebarView.THUMBS;
  3153. case "UseOutlines":
  3154. return SidebarView.OUTLINE;
  3155. case "UseAttachments":
  3156. return SidebarView.ATTACHMENTS;
  3157. case "UseOC":
  3158. return SidebarView.LAYERS;
  3159. }
  3160. return SidebarView.NONE;
  3161. }
  3162. /***/ }),
  3163. /* 5 */
  3164. /***/ ((module) => {
  3165. let pdfjsLib;
  3166. if (typeof window !== "undefined" && window["pdfjs-dist/pdfBuild/pdf"]) {
  3167. pdfjsLib = window["pdfjs-dist/pdfBuild/pdf"];
  3168. } else {
  3169. pdfjsLib = require("../pdfBuild/pdf.js");
  3170. }
  3171. module.exports = pdfjsLib;
  3172. /***/ }),
  3173. /* 6 */
  3174. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3175. Object.defineProperty(exports, "__esModule", ({
  3176. value: true
  3177. }));
  3178. exports.PDFCursorTools = exports.CursorTool = void 0;
  3179. var _grab_to_pan = __webpack_require__(7);
  3180. var _ui_utils = __webpack_require__(4);
  3181. const CursorTool = {
  3182. SELECT: 0,
  3183. HAND: 1,
  3184. ZOOM: 2
  3185. };
  3186. exports.CursorTool = CursorTool;
  3187. class PDFCursorTools {
  3188. constructor({
  3189. container,
  3190. eventBus,
  3191. cursorToolOnLoad = CursorTool.SELECT
  3192. }) {
  3193. this.container = container;
  3194. this.eventBus = eventBus;
  3195. this.active = CursorTool.SELECT;
  3196. this.activeBeforePresentationMode = null;
  3197. this.handTool = new _grab_to_pan.GrabToPan({
  3198. element: this.container
  3199. });
  3200. this._addEventListeners();
  3201. Promise.resolve().then(() => {
  3202. this.switchTool(cursorToolOnLoad);
  3203. });
  3204. }
  3205. get activeTool() {
  3206. return this.active;
  3207. }
  3208. switchTool(tool) {
  3209. if (this.activeBeforePresentationMode !== null) {
  3210. return;
  3211. }
  3212. if (tool === this.active) {
  3213. return;
  3214. }
  3215. const disableActiveTool = () => {
  3216. switch (this.active) {
  3217. case CursorTool.SELECT:
  3218. break;
  3219. case CursorTool.HAND:
  3220. this.handTool.deactivate();
  3221. break;
  3222. case CursorTool.ZOOM:
  3223. }
  3224. };
  3225. switch (tool) {
  3226. case CursorTool.SELECT:
  3227. disableActiveTool();
  3228. break;
  3229. case CursorTool.HAND:
  3230. disableActiveTool();
  3231. this.handTool.activate();
  3232. break;
  3233. case CursorTool.ZOOM:
  3234. default:
  3235. console.error(`switchTool: "${tool}" is an unsupported value.`);
  3236. return;
  3237. }
  3238. this.active = tool;
  3239. this._dispatchEvent();
  3240. }
  3241. _dispatchEvent() {
  3242. this.eventBus.dispatch("cursortoolchanged", {
  3243. source: this,
  3244. tool: this.active
  3245. });
  3246. }
  3247. _addEventListeners() {
  3248. this.eventBus._on("switchcursortool", evt => {
  3249. this.switchTool(evt.tool);
  3250. });
  3251. this.eventBus._on("presentationmodechanged", evt => {
  3252. switch (evt.state) {
  3253. case _ui_utils.PresentationModeState.FULLSCREEN:
  3254. {
  3255. const previouslyActive = this.active;
  3256. this.switchTool(CursorTool.SELECT);
  3257. this.activeBeforePresentationMode = previouslyActive;
  3258. break;
  3259. }
  3260. case _ui_utils.PresentationModeState.NORMAL:
  3261. {
  3262. const previouslyActive = this.activeBeforePresentationMode;
  3263. this.activeBeforePresentationMode = null;
  3264. this.switchTool(previouslyActive);
  3265. break;
  3266. }
  3267. }
  3268. });
  3269. }
  3270. }
  3271. exports.PDFCursorTools = PDFCursorTools;
  3272. /***/ }),
  3273. /* 7 */
  3274. /***/ ((__unused_webpack_module, exports) => {
  3275. Object.defineProperty(exports, "__esModule", ({
  3276. value: true
  3277. }));
  3278. exports.GrabToPan = GrabToPan;
  3279. function GrabToPan(options) {
  3280. this.element = options.element;
  3281. this.document = options.element.ownerDocument;
  3282. if (typeof options.ignoreTarget === "function") {
  3283. this.ignoreTarget = options.ignoreTarget;
  3284. }
  3285. this.onActiveChanged = options.onActiveChanged;
  3286. this.activate = this.activate.bind(this);
  3287. this.deactivate = this.deactivate.bind(this);
  3288. this.toggle = this.toggle.bind(this);
  3289. this._onmousedown = this._onmousedown.bind(this);
  3290. this._onmousemove = this._onmousemove.bind(this);
  3291. this._endPan = this._endPan.bind(this);
  3292. const overlay = this.overlay = document.createElement("div");
  3293. overlay.className = "grab-to-pan-grabbing";
  3294. }
  3295. GrabToPan.prototype = {
  3296. CSS_CLASS_GRAB: "grab-to-pan-grab",
  3297. activate: function GrabToPan_activate() {
  3298. if (!this.active) {
  3299. this.active = true;
  3300. this.element.addEventListener("mousedown", this._onmousedown, true);
  3301. this.element.classList.add(this.CSS_CLASS_GRAB);
  3302. if (this.onActiveChanged) {
  3303. this.onActiveChanged(true);
  3304. }
  3305. }
  3306. },
  3307. deactivate: function GrabToPan_deactivate() {
  3308. if (this.active) {
  3309. this.active = false;
  3310. this.element.removeEventListener("mousedown", this._onmousedown, true);
  3311. this._endPan();
  3312. this.element.classList.remove(this.CSS_CLASS_GRAB);
  3313. if (this.onActiveChanged) {
  3314. this.onActiveChanged(false);
  3315. }
  3316. }
  3317. },
  3318. toggle: function GrabToPan_toggle() {
  3319. if (this.active) {
  3320. this.deactivate();
  3321. } else {
  3322. this.activate();
  3323. }
  3324. },
  3325. ignoreTarget: function GrabToPan_ignoreTarget(node) {
  3326. return node.matches("a[href], a[href] *, input, textarea, button, button *, select, option");
  3327. },
  3328. _onmousedown: function GrabToPan__onmousedown(event) {
  3329. if (event.button !== 0 || this.ignoreTarget(event.target)) {
  3330. return;
  3331. }
  3332. if (event.originalTarget) {
  3333. try {
  3334. event.originalTarget.tagName;
  3335. } catch (e) {
  3336. return;
  3337. }
  3338. }
  3339. this.scrollLeftStart = this.element.scrollLeft;
  3340. this.scrollTopStart = this.element.scrollTop;
  3341. this.clientXStart = event.clientX;
  3342. this.clientYStart = event.clientY;
  3343. this.document.addEventListener("mousemove", this._onmousemove, true);
  3344. this.document.addEventListener("mouseup", this._endPan, true);
  3345. this.element.addEventListener("scroll", this._endPan, true);
  3346. event.preventDefault();
  3347. event.stopPropagation();
  3348. const focusedElement = document.activeElement;
  3349. if (focusedElement && !focusedElement.contains(event.target)) {
  3350. focusedElement.blur();
  3351. }
  3352. },
  3353. _onmousemove: function GrabToPan__onmousemove(event) {
  3354. this.element.removeEventListener("scroll", this._endPan, true);
  3355. if (isLeftMouseReleased(event)) {
  3356. this._endPan();
  3357. return;
  3358. }
  3359. const xDiff = event.clientX - this.clientXStart;
  3360. const yDiff = event.clientY - this.clientYStart;
  3361. const scrollTop = this.scrollTopStart - yDiff;
  3362. const scrollLeft = this.scrollLeftStart - xDiff;
  3363. if (this.element.scrollTo) {
  3364. this.element.scrollTo({
  3365. top: scrollTop,
  3366. left: scrollLeft,
  3367. behavior: "instant"
  3368. });
  3369. } else {
  3370. this.element.scrollTop = scrollTop;
  3371. this.element.scrollLeft = scrollLeft;
  3372. }
  3373. if (!this.overlay.parentNode) {
  3374. document.body.appendChild(this.overlay);
  3375. }
  3376. },
  3377. _endPan: function GrabToPan__endPan() {
  3378. this.element.removeEventListener("scroll", this._endPan, true);
  3379. this.document.removeEventListener("mousemove", this._onmousemove, true);
  3380. this.document.removeEventListener("mouseup", this._endPan, true);
  3381. this.overlay.remove();
  3382. }
  3383. };
  3384. function isLeftMouseReleased(event) {
  3385. if ("buttons" in event) {
  3386. return !(event.buttons & 1);
  3387. }
  3388. const chrome = window.chrome;
  3389. const isChrome15OrOpera15plus = chrome && (chrome.webstore || chrome.app);
  3390. const isSafari6plus = /Apple/.test(navigator.vendor) && /Version\/([6-9]\d*|[1-5]\d+)/.test(navigator.userAgent);
  3391. if (isChrome15OrOpera15plus || isSafari6plus) {
  3392. return event.which === 0;
  3393. }
  3394. return false;
  3395. }
  3396. /***/ }),
  3397. /* 8 */
  3398. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3399. Object.defineProperty(exports, "__esModule", ({
  3400. value: true
  3401. }));
  3402. exports.RenderingStates = exports.PDFRenderingQueue = void 0;
  3403. var _pdfjsLib = __webpack_require__(5);
  3404. const CLEANUP_TIMEOUT = 30000;
  3405. const RenderingStates = {
  3406. INITIAL: 0,
  3407. RUNNING: 1,
  3408. PAUSED: 2,
  3409. FINISHED: 3
  3410. };
  3411. exports.RenderingStates = RenderingStates;
  3412. class PDFRenderingQueue {
  3413. constructor() {
  3414. this.pdfViewer = null;
  3415. this.pdfThumbnailViewer = null;
  3416. this.onIdle = null;
  3417. this.highestPriorityPage = null;
  3418. this.idleTimeout = null;
  3419. this.printing = false;
  3420. this.isThumbnailViewEnabled = false;
  3421. }
  3422. setViewer(pdfViewer) {
  3423. this.pdfViewer = pdfViewer;
  3424. }
  3425. setThumbnailViewer(pdfThumbnailViewer) {
  3426. this.pdfThumbnailViewer = pdfThumbnailViewer;
  3427. }
  3428. isHighestPriority(view) {
  3429. return this.highestPriorityPage === view.renderingId;
  3430. }
  3431. renderHighestPriority(currentlyVisiblePages) {
  3432. if (this.idleTimeout) {
  3433. clearTimeout(this.idleTimeout);
  3434. this.idleTimeout = null;
  3435. }
  3436. if (this.pdfViewer.forceRendering(currentlyVisiblePages)) {
  3437. return;
  3438. }
  3439. if (this.pdfThumbnailViewer && this.isThumbnailViewEnabled) {
  3440. if (this.pdfThumbnailViewer.forceRendering()) {
  3441. return;
  3442. }
  3443. }
  3444. if (this.printing) {
  3445. return;
  3446. }
  3447. if (this.onIdle) {
  3448. this.idleTimeout = setTimeout(this.onIdle.bind(this), CLEANUP_TIMEOUT);
  3449. }
  3450. }
  3451. getHighestPriority(visible, views, scrolledDown) {
  3452. const visibleViews = visible.views;
  3453. const numVisible = visibleViews.length;
  3454. if (numVisible === 0) {
  3455. return null;
  3456. }
  3457. for (let i = 0; i < numVisible; ++i) {
  3458. const view = visibleViews[i].view;
  3459. if (!this.isViewFinished(view)) {
  3460. return view;
  3461. }
  3462. }
  3463. if (scrolledDown) {
  3464. const nextPageIndex = visible.last.id;
  3465. if (views[nextPageIndex] && !this.isViewFinished(views[nextPageIndex])) {
  3466. return views[nextPageIndex];
  3467. }
  3468. } else {
  3469. const previousPageIndex = visible.first.id - 2;
  3470. if (views[previousPageIndex] && !this.isViewFinished(views[previousPageIndex])) {
  3471. return views[previousPageIndex];
  3472. }
  3473. }
  3474. return null;
  3475. }
  3476. isViewFinished(view) {
  3477. return view.renderingState === RenderingStates.FINISHED;
  3478. }
  3479. renderView(view) {
  3480. switch (view.renderingState) {
  3481. case RenderingStates.FINISHED:
  3482. return false;
  3483. case RenderingStates.PAUSED:
  3484. this.highestPriorityPage = view.renderingId;
  3485. view.resume();
  3486. break;
  3487. case RenderingStates.RUNNING:
  3488. this.highestPriorityPage = view.renderingId;
  3489. break;
  3490. case RenderingStates.INITIAL:
  3491. this.highestPriorityPage = view.renderingId;
  3492. view.draw().finally(() => {
  3493. this.renderHighestPriority();
  3494. }).catch(reason => {
  3495. if (reason instanceof _pdfjsLib.RenderingCancelledException) {
  3496. return;
  3497. }
  3498. console.error(`renderView: "${reason}"`);
  3499. });
  3500. break;
  3501. }
  3502. return true;
  3503. }
  3504. }
  3505. exports.PDFRenderingQueue = PDFRenderingQueue;
  3506. /***/ }),
  3507. /* 9 */
  3508. /***/ ((__unused_webpack_module, exports) => {
  3509. Object.defineProperty(exports, "__esModule", ({
  3510. value: true
  3511. }));
  3512. exports.OverlayManager = void 0;
  3513. class OverlayManager {
  3514. constructor() {
  3515. this._overlays = {};
  3516. this._active = null;
  3517. this._keyDownBound = this._keyDown.bind(this);
  3518. }
  3519. get active() {
  3520. return this._active;
  3521. }
  3522. async register(name, element, callerCloseMethod = null, canForceClose = false) {
  3523. let container;
  3524. if (!name || !element || !(container = element.parentNode)) {
  3525. throw new Error("Not enough parameters.");
  3526. } else if (this._overlays[name]) {
  3527. throw new Error("The overlay is already registered.");
  3528. }
  3529. this._overlays[name] = {
  3530. element,
  3531. container,
  3532. callerCloseMethod,
  3533. canForceClose
  3534. };
  3535. }
  3536. async unregister(name) {
  3537. if (!this._overlays[name]) {
  3538. throw new Error("The overlay does not exist.");
  3539. } else if (this._active === name) {
  3540. throw new Error("The overlay cannot be removed while it is active.");
  3541. }
  3542. delete this._overlays[name];
  3543. }
  3544. async open(name) {
  3545. if (!this._overlays[name]) {
  3546. throw new Error("The overlay does not exist.");
  3547. } else if (this._active) {
  3548. if (this._overlays[name].canForceClose) {
  3549. this._closeThroughCaller();
  3550. } else if (this._active === name) {
  3551. throw new Error("The overlay is already active.");
  3552. } else {
  3553. throw new Error("Another overlay is currently active.");
  3554. }
  3555. }
  3556. this._active = name;
  3557. this._overlays[this._active].element.classList.remove("hidden");
  3558. this._overlays[this._active].container.classList.remove("hidden");
  3559. window.addEventListener("keydown", this._keyDownBound);
  3560. }
  3561. async close(name) {
  3562. if (!this._overlays[name]) {
  3563. throw new Error("The overlay does not exist.");
  3564. } else if (!this._active) {
  3565. throw new Error("The overlay is currently not active.");
  3566. } else if (this._active !== name) {
  3567. throw new Error("Another overlay is currently active.");
  3568. }
  3569. this._overlays[this._active].container.classList.add("hidden");
  3570. this._overlays[this._active].element.classList.add("hidden");
  3571. this._active = null;
  3572. window.removeEventListener("keydown", this._keyDownBound);
  3573. }
  3574. _keyDown(evt) {
  3575. if (this._active && evt.keyCode === 27) {
  3576. this._closeThroughCaller();
  3577. evt.preventDefault();
  3578. }
  3579. }
  3580. _closeThroughCaller() {
  3581. if (this._overlays[this._active].callerCloseMethod) {
  3582. this._overlays[this._active].callerCloseMethod();
  3583. }
  3584. if (this._active) {
  3585. this.close(this._active);
  3586. }
  3587. }
  3588. }
  3589. exports.OverlayManager = OverlayManager;
  3590. /***/ }),
  3591. /* 10 */
  3592. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3593. Object.defineProperty(exports, "__esModule", ({
  3594. value: true
  3595. }));
  3596. exports.PasswordPrompt = void 0;
  3597. var _pdfjsLib = __webpack_require__(5);
  3598. class PasswordPrompt {
  3599. constructor(options, overlayManager, l10n, isViewerEmbedded = false) {
  3600. this.overlayName = options.overlayName;
  3601. this.container = options.container;
  3602. this.label = options.label;
  3603. this.input = options.input;
  3604. this.submitButton = options.submitButton;
  3605. this.cancelButton = options.cancelButton;
  3606. this.overlayManager = overlayManager;
  3607. this.l10n = l10n;
  3608. this._isViewerEmbedded = isViewerEmbedded;
  3609. this.updateCallback = null;
  3610. this.reason = null;
  3611. this.submitButton.addEventListener("click", this.verify.bind(this));
  3612. this.cancelButton.addEventListener("click", this.close.bind(this));
  3613. this.input.addEventListener("keydown", e => {
  3614. if (e.keyCode === 13) {
  3615. this.verify();
  3616. }
  3617. });
  3618. this.overlayManager.register(this.overlayName, this.container, this.close.bind(this), true);
  3619. }
  3620. async open() {
  3621. await this.overlayManager.open(this.overlayName);
  3622. const passwordIncorrect = this.reason === _pdfjsLib.PasswordResponses.INCORRECT_PASSWORD;
  3623. if (!this._isViewerEmbedded || passwordIncorrect) {
  3624. this.input.focus();
  3625. }
  3626. this.label.textContent = await this.l10n.get(`password_${passwordIncorrect ? "invalid" : "label"}`);
  3627. }
  3628. close() {
  3629. this.overlayManager.close(this.overlayName).then(() => {
  3630. this.input.value = "";
  3631. });
  3632. }
  3633. verify() {
  3634. const password = this.input.value;
  3635. if (password?.length > 0) {
  3636. this.close();
  3637. this.updateCallback(password);
  3638. }
  3639. }
  3640. setUpdateCallback(updateCallback, reason) {
  3641. this.updateCallback = updateCallback;
  3642. this.reason = reason;
  3643. }
  3644. }
  3645. exports.PasswordPrompt = PasswordPrompt;
  3646. /***/ }),
  3647. /* 11 */
  3648. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3649. Object.defineProperty(exports, "__esModule", ({
  3650. value: true
  3651. }));
  3652. exports.PDFAttachmentViewer = void 0;
  3653. var _pdfjsLib = __webpack_require__(5);
  3654. var _base_tree_viewer = __webpack_require__(12);
  3655. class PDFAttachmentViewer extends _base_tree_viewer.BaseTreeViewer {
  3656. constructor(options) {
  3657. super(options);
  3658. this.downloadManager = options.downloadManager;
  3659. this.eventBus._on("fileattachmentannotation", this._appendAttachment.bind(this));
  3660. }
  3661. reset(keepRenderedCapability = false) {
  3662. super.reset();
  3663. this._attachments = null;
  3664. if (!keepRenderedCapability) {
  3665. this._renderedCapability = (0, _pdfjsLib.createPromiseCapability)();
  3666. }
  3667. if (this._pendingDispatchEvent) {
  3668. clearTimeout(this._pendingDispatchEvent);
  3669. }
  3670. this._pendingDispatchEvent = null;
  3671. }
  3672. _dispatchEvent(attachmentsCount) {
  3673. this._renderedCapability.resolve();
  3674. if (this._pendingDispatchEvent) {
  3675. clearTimeout(this._pendingDispatchEvent);
  3676. this._pendingDispatchEvent = null;
  3677. }
  3678. if (attachmentsCount === 0) {
  3679. this._pendingDispatchEvent = setTimeout(() => {
  3680. this.eventBus.dispatch("attachmentsloaded", {
  3681. source: this,
  3682. attachmentsCount: 0
  3683. });
  3684. this._pendingDispatchEvent = null;
  3685. });
  3686. return;
  3687. }
  3688. this.eventBus.dispatch("attachmentsloaded", {
  3689. source: this,
  3690. attachmentsCount
  3691. });
  3692. }
  3693. _bindLink(element, {
  3694. content,
  3695. filename
  3696. }) {
  3697. element.onclick = () => {
  3698. this.downloadManager.openOrDownloadData(element, content, filename);
  3699. return false;
  3700. };
  3701. }
  3702. render({
  3703. attachments,
  3704. keepRenderedCapability = false
  3705. }) {
  3706. if (this._attachments) {
  3707. this.reset(keepRenderedCapability);
  3708. }
  3709. this._attachments = attachments || null;
  3710. if (!attachments) {
  3711. this._dispatchEvent(0);
  3712. return;
  3713. }
  3714. const names = Object.keys(attachments).sort(function (a, b) {
  3715. return a.toLowerCase().localeCompare(b.toLowerCase());
  3716. });
  3717. const fragment = document.createDocumentFragment();
  3718. let attachmentsCount = 0;
  3719. for (const name of names) {
  3720. const item = attachments[name];
  3721. const content = item.content,
  3722. filename = (0, _pdfjsLib.getFilenameFromUrl)(item.filename);
  3723. const div = document.createElement("div");
  3724. div.className = "treeItem";
  3725. const element = document.createElement("a");
  3726. this._bindLink(element, {
  3727. content,
  3728. filename
  3729. });
  3730. element.textContent = this._normalizeTextContent(filename);
  3731. div.appendChild(element);
  3732. fragment.appendChild(div);
  3733. attachmentsCount++;
  3734. }
  3735. this._finishRendering(fragment, attachmentsCount);
  3736. }
  3737. _appendAttachment({
  3738. id,
  3739. filename,
  3740. content
  3741. }) {
  3742. const renderedPromise = this._renderedCapability.promise;
  3743. renderedPromise.then(() => {
  3744. if (renderedPromise !== this._renderedCapability.promise) {
  3745. return;
  3746. }
  3747. let attachments = this._attachments;
  3748. if (!attachments) {
  3749. attachments = Object.create(null);
  3750. } else {
  3751. for (const name in attachments) {
  3752. if (id === name) {
  3753. return;
  3754. }
  3755. }
  3756. }
  3757. attachments[id] = {
  3758. filename,
  3759. content
  3760. };
  3761. this.render({
  3762. attachments,
  3763. keepRenderedCapability: true
  3764. });
  3765. });
  3766. }
  3767. }
  3768. exports.PDFAttachmentViewer = PDFAttachmentViewer;
  3769. /***/ }),
  3770. /* 12 */
  3771. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3772. Object.defineProperty(exports, "__esModule", ({
  3773. value: true
  3774. }));
  3775. exports.BaseTreeViewer = void 0;
  3776. var _pdfjsLib = __webpack_require__(5);
  3777. const TREEITEM_OFFSET_TOP = -100;
  3778. const TREEITEM_SELECTED_CLASS = "selected";
  3779. class BaseTreeViewer {
  3780. constructor(options) {
  3781. if (this.constructor === BaseTreeViewer) {
  3782. throw new Error("Cannot initialize BaseTreeViewer.");
  3783. }
  3784. this.container = options.container;
  3785. this.eventBus = options.eventBus;
  3786. this.reset();
  3787. }
  3788. reset() {
  3789. this._pdfDocument = null;
  3790. this._lastToggleIsShow = true;
  3791. this._currentTreeItem = null;
  3792. this.container.textContent = "";
  3793. this.container.classList.remove("treeWithDeepNesting");
  3794. }
  3795. _dispatchEvent(count) {
  3796. throw new Error("Not implemented: _dispatchEvent");
  3797. }
  3798. _bindLink(element, params) {
  3799. throw new Error("Not implemented: _bindLink");
  3800. }
  3801. _normalizeTextContent(str) {
  3802. return (0, _pdfjsLib.removeNullCharacters)(str) || "\u2013";
  3803. }
  3804. _addToggleButton(div, hidden = false) {
  3805. const toggler = document.createElement("div");
  3806. toggler.className = "treeItemToggler";
  3807. if (hidden) {
  3808. toggler.classList.add("treeItemsHidden");
  3809. }
  3810. toggler.onclick = evt => {
  3811. evt.stopPropagation();
  3812. toggler.classList.toggle("treeItemsHidden");
  3813. if (evt.shiftKey) {
  3814. const shouldShowAll = !toggler.classList.contains("treeItemsHidden");
  3815. this._toggleTreeItem(div, shouldShowAll);
  3816. }
  3817. };
  3818. div.insertBefore(toggler, div.firstChild);
  3819. }
  3820. _toggleTreeItem(root, show = false) {
  3821. this._lastToggleIsShow = show;
  3822. for (const toggler of root.querySelectorAll(".treeItemToggler")) {
  3823. toggler.classList.toggle("treeItemsHidden", !show);
  3824. }
  3825. }
  3826. _toggleAllTreeItems() {
  3827. this._toggleTreeItem(this.container, !this._lastToggleIsShow);
  3828. }
  3829. _finishRendering(fragment, count, hasAnyNesting = false) {
  3830. if (hasAnyNesting) {
  3831. this.container.classList.add("treeWithDeepNesting");
  3832. this._lastToggleIsShow = !fragment.querySelector(".treeItemsHidden");
  3833. }
  3834. this.container.appendChild(fragment);
  3835. this._dispatchEvent(count);
  3836. }
  3837. render(params) {
  3838. throw new Error("Not implemented: render");
  3839. }
  3840. _updateCurrentTreeItem(treeItem = null) {
  3841. if (this._currentTreeItem) {
  3842. this._currentTreeItem.classList.remove(TREEITEM_SELECTED_CLASS);
  3843. this._currentTreeItem = null;
  3844. }
  3845. if (treeItem) {
  3846. treeItem.classList.add(TREEITEM_SELECTED_CLASS);
  3847. this._currentTreeItem = treeItem;
  3848. }
  3849. }
  3850. _scrollToCurrentTreeItem(treeItem) {
  3851. if (!treeItem) {
  3852. return;
  3853. }
  3854. let currentNode = treeItem.parentNode;
  3855. while (currentNode && currentNode !== this.container) {
  3856. if (currentNode.classList.contains("treeItem")) {
  3857. const toggler = currentNode.firstElementChild;
  3858. toggler?.classList.remove("treeItemsHidden");
  3859. }
  3860. currentNode = currentNode.parentNode;
  3861. }
  3862. this._updateCurrentTreeItem(treeItem);
  3863. this.container.scrollTo(treeItem.offsetLeft, treeItem.offsetTop + TREEITEM_OFFSET_TOP);
  3864. }
  3865. }
  3866. exports.BaseTreeViewer = BaseTreeViewer;
  3867. /***/ }),
  3868. /* 13 */
  3869. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  3870. Object.defineProperty(exports, "__esModule", ({
  3871. value: true
  3872. }));
  3873. exports.PDFDocumentProperties = void 0;
  3874. var _pdfjsLib = __webpack_require__(5);
  3875. var _ui_utils = __webpack_require__(4);
  3876. const DEFAULT_FIELD_CONTENT = "-";
  3877. const NON_METRIC_LOCALES = ["en-us", "en-lr", "my"];
  3878. const US_PAGE_NAMES = {
  3879. "8.5x11": "Letter",
  3880. "8.5x14": "Legal"
  3881. };
  3882. const METRIC_PAGE_NAMES = {
  3883. "297x420": "A3",
  3884. "210x297": "A4"
  3885. };
  3886. function getPageName(size, isPortrait, pageNames) {
  3887. const width = isPortrait ? size.width : size.height;
  3888. const height = isPortrait ? size.height : size.width;
  3889. return pageNames[`${width}x${height}`];
  3890. }
  3891. class PDFDocumentProperties {
  3892. constructor({
  3893. overlayName,
  3894. fields,
  3895. container,
  3896. closeButton
  3897. }, overlayManager, eventBus, l10n) {
  3898. this.overlayName = overlayName;
  3899. this.fields = fields;
  3900. this.container = container;
  3901. this.overlayManager = overlayManager;
  3902. this.l10n = l10n;
  3903. this._reset();
  3904. closeButton.addEventListener("click", this.close.bind(this));
  3905. this.overlayManager.register(this.overlayName, this.container, this.close.bind(this));
  3906. eventBus._on("pagechanging", evt => {
  3907. this._currentPageNumber = evt.pageNumber;
  3908. });
  3909. eventBus._on("rotationchanging", evt => {
  3910. this._pagesRotation = evt.pagesRotation;
  3911. });
  3912. this._isNonMetricLocale = true;
  3913. l10n.getLanguage().then(locale => {
  3914. this._isNonMetricLocale = NON_METRIC_LOCALES.includes(locale);
  3915. });
  3916. }
  3917. async open() {
  3918. const freezeFieldData = data => {
  3919. Object.defineProperty(this, "fieldData", {
  3920. value: Object.freeze(data),
  3921. writable: false,
  3922. enumerable: true,
  3923. configurable: true
  3924. });
  3925. };
  3926. await Promise.all([this.overlayManager.open(this.overlayName), this._dataAvailableCapability.promise]);
  3927. const currentPageNumber = this._currentPageNumber;
  3928. const pagesRotation = this._pagesRotation;
  3929. if (this.fieldData && currentPageNumber === this.fieldData._currentPageNumber && pagesRotation === this.fieldData._pagesRotation) {
  3930. this._updateUI();
  3931. return;
  3932. }
  3933. const {
  3934. info,
  3935. contentDispositionFilename,
  3936. contentLength
  3937. } = await this.pdfDocument.getMetadata();
  3938. const [fileName, fileSize, creationDate, modificationDate, pageSize, isLinearized] = await Promise.all([contentDispositionFilename || (0, _pdfjsLib.getPdfFilenameFromUrl)(this.url), this._parseFileSize(contentLength), this._parseDate(info.CreationDate), this._parseDate(info.ModDate), this.pdfDocument.getPage(currentPageNumber).then(pdfPage => {
  3939. return this._parsePageSize((0, _ui_utils.getPageSizeInches)(pdfPage), pagesRotation);
  3940. }), this._parseLinearization(info.IsLinearized)]);
  3941. freezeFieldData({
  3942. fileName,
  3943. fileSize,
  3944. title: info.Title,
  3945. author: info.Author,
  3946. subject: info.Subject,
  3947. keywords: info.Keywords,
  3948. creationDate,
  3949. modificationDate,
  3950. creator: info.Creator,
  3951. producer: info.Producer,
  3952. version: info.PDFFormatVersion,
  3953. pageCount: this.pdfDocument.numPages,
  3954. pageSize,
  3955. linearized: isLinearized,
  3956. _currentPageNumber: currentPageNumber,
  3957. _pagesRotation: pagesRotation
  3958. });
  3959. this._updateUI();
  3960. const {
  3961. length
  3962. } = await this.pdfDocument.getDownloadInfo();
  3963. if (contentLength === length) {
  3964. return;
  3965. }
  3966. const data = Object.assign(Object.create(null), this.fieldData);
  3967. data.fileSize = await this._parseFileSize(length);
  3968. freezeFieldData(data);
  3969. this._updateUI();
  3970. }
  3971. close() {
  3972. this.overlayManager.close(this.overlayName);
  3973. }
  3974. setDocument(pdfDocument, url = null) {
  3975. if (this.pdfDocument) {
  3976. this._reset();
  3977. this._updateUI(true);
  3978. }
  3979. if (!pdfDocument) {
  3980. return;
  3981. }
  3982. this.pdfDocument = pdfDocument;
  3983. this.url = url;
  3984. this._dataAvailableCapability.resolve();
  3985. }
  3986. _reset() {
  3987. this.pdfDocument = null;
  3988. this.url = null;
  3989. delete this.fieldData;
  3990. this._dataAvailableCapability = (0, _pdfjsLib.createPromiseCapability)();
  3991. this._currentPageNumber = 1;
  3992. this._pagesRotation = 0;
  3993. }
  3994. _updateUI(reset = false) {
  3995. if (reset || !this.fieldData) {
  3996. for (const id in this.fields) {
  3997. this.fields[id].textContent = DEFAULT_FIELD_CONTENT;
  3998. }
  3999. return;
  4000. }
  4001. if (this.overlayManager.active !== this.overlayName) {
  4002. return;
  4003. }
  4004. for (const id in this.fields) {
  4005. const content = this.fieldData[id];
  4006. this.fields[id].textContent = content || content === 0 ? content : DEFAULT_FIELD_CONTENT;
  4007. }
  4008. }
  4009. async _parseFileSize(fileSize = 0) {
  4010. const kb = fileSize / 1024,
  4011. mb = kb / 1024;
  4012. if (!kb) {
  4013. return undefined;
  4014. }
  4015. return this.l10n.get(`document_properties_${mb >= 1 ? "mb" : "kb"}`, {
  4016. size_mb: mb >= 1 && (+mb.toPrecision(3)).toLocaleString(),
  4017. size_kb: mb < 1 && (+kb.toPrecision(3)).toLocaleString(),
  4018. size_b: fileSize.toLocaleString()
  4019. });
  4020. }
  4021. async _parsePageSize(pageSizeInches, pagesRotation) {
  4022. if (!pageSizeInches) {
  4023. return undefined;
  4024. }
  4025. if (pagesRotation % 180 !== 0) {
  4026. pageSizeInches = {
  4027. width: pageSizeInches.height,
  4028. height: pageSizeInches.width
  4029. };
  4030. }
  4031. const isPortrait = (0, _ui_utils.isPortraitOrientation)(pageSizeInches);
  4032. let sizeInches = {
  4033. width: Math.round(pageSizeInches.width * 100) / 100,
  4034. height: Math.round(pageSizeInches.height * 100) / 100
  4035. };
  4036. let sizeMillimeters = {
  4037. width: Math.round(pageSizeInches.width * 25.4 * 10) / 10,
  4038. height: Math.round(pageSizeInches.height * 25.4 * 10) / 10
  4039. };
  4040. let rawName = getPageName(sizeInches, isPortrait, US_PAGE_NAMES) || getPageName(sizeMillimeters, isPortrait, METRIC_PAGE_NAMES);
  4041. if (!rawName && !(Number.isInteger(sizeMillimeters.width) && Number.isInteger(sizeMillimeters.height))) {
  4042. const exactMillimeters = {
  4043. width: pageSizeInches.width * 25.4,
  4044. height: pageSizeInches.height * 25.4
  4045. };
  4046. const intMillimeters = {
  4047. width: Math.round(sizeMillimeters.width),
  4048. height: Math.round(sizeMillimeters.height)
  4049. };
  4050. if (Math.abs(exactMillimeters.width - intMillimeters.width) < 0.1 && Math.abs(exactMillimeters.height - intMillimeters.height) < 0.1) {
  4051. rawName = getPageName(intMillimeters, isPortrait, METRIC_PAGE_NAMES);
  4052. if (rawName) {
  4053. sizeInches = {
  4054. width: Math.round(intMillimeters.width / 25.4 * 100) / 100,
  4055. height: Math.round(intMillimeters.height / 25.4 * 100) / 100
  4056. };
  4057. sizeMillimeters = intMillimeters;
  4058. }
  4059. }
  4060. }
  4061. const [{
  4062. width,
  4063. height
  4064. }, unit, name, orientation] = await Promise.all([this._isNonMetricLocale ? sizeInches : sizeMillimeters, this.l10n.get(`document_properties_page_size_unit_${this._isNonMetricLocale ? "inches" : "millimeters"}`), rawName && this.l10n.get(`document_properties_page_size_name_${rawName.toLowerCase()}`), this.l10n.get(`document_properties_page_size_orientation_${isPortrait ? "portrait" : "landscape"}`)]);
  4065. return this.l10n.get(`document_properties_page_size_dimension_${name ? "name_" : ""}string`, {
  4066. width: width.toLocaleString(),
  4067. height: height.toLocaleString(),
  4068. unit,
  4069. name,
  4070. orientation
  4071. });
  4072. }
  4073. async _parseDate(inputDate) {
  4074. const dateObject = _pdfjsLib.PDFDateString.toDateObject(inputDate);
  4075. if (!dateObject) {
  4076. return undefined;
  4077. }
  4078. return this.l10n.get("document_properties_date_string", {
  4079. date: dateObject.toLocaleDateString(),
  4080. time: dateObject.toLocaleTimeString()
  4081. });
  4082. }
  4083. _parseLinearization(isLinearized) {
  4084. return this.l10n.get(`document_properties_linearized_${isLinearized ? "yes" : "no"}`);
  4085. }
  4086. }
  4087. exports.PDFDocumentProperties = PDFDocumentProperties;
  4088. /***/ }),
  4089. /* 14 */
  4090. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4091. Object.defineProperty(exports, "__esModule", ({
  4092. value: true
  4093. }));
  4094. exports.PDFFindBar = void 0;
  4095. var _pdf_find_controller = __webpack_require__(15);
  4096. const MATCHES_COUNT_LIMIT = 1000;
  4097. class PDFFindBar {
  4098. constructor(options, eventBus, l10n) {
  4099. this.opened = false;
  4100. this.bar = options.bar;
  4101. this.toggleButton = options.toggleButton;
  4102. this.findField = options.findField;
  4103. this.highlightAll = options.highlightAllCheckbox;
  4104. this.caseSensitive = options.caseSensitiveCheckbox;
  4105. this.entireWord = options.entireWordCheckbox;
  4106. this.findMsg = options.findMsg;
  4107. this.findResultsCount = options.findResultsCount;
  4108. this.findPreviousButton = options.findPreviousButton;
  4109. this.findNextButton = options.findNextButton;
  4110. this.eventBus = eventBus;
  4111. this.l10n = l10n;
  4112. this.toggleButton.addEventListener("click", () => {
  4113. this.toggle();
  4114. });
  4115. this.findField.addEventListener("input", () => {
  4116. this.dispatchEvent("");
  4117. });
  4118. this.bar.addEventListener("keydown", e => {
  4119. switch (e.keyCode) {
  4120. case 13:
  4121. if (e.target === this.findField) {
  4122. this.dispatchEvent("again", e.shiftKey);
  4123. }
  4124. break;
  4125. case 27:
  4126. this.close();
  4127. break;
  4128. }
  4129. });
  4130. this.findPreviousButton.addEventListener("click", () => {
  4131. this.dispatchEvent("again", true);
  4132. });
  4133. this.findNextButton.addEventListener("click", () => {
  4134. this.dispatchEvent("again", false);
  4135. });
  4136. this.highlightAll.addEventListener("click", () => {
  4137. this.dispatchEvent("highlightallchange");
  4138. });
  4139. this.caseSensitive.addEventListener("click", () => {
  4140. this.dispatchEvent("casesensitivitychange");
  4141. });
  4142. this.entireWord.addEventListener("click", () => {
  4143. this.dispatchEvent("entirewordchange");
  4144. });
  4145. this.eventBus._on("resize", this._adjustWidth.bind(this));
  4146. }
  4147. reset() {
  4148. this.updateUIState();
  4149. }
  4150. dispatchEvent(type, findPrev) {
  4151. this.eventBus.dispatch("find", {
  4152. source: this,
  4153. type,
  4154. query: this.findField.value,
  4155. phraseSearch: true,
  4156. caseSensitive: this.caseSensitive.checked,
  4157. entireWord: this.entireWord.checked,
  4158. highlightAll: this.highlightAll.checked,
  4159. findPrevious: findPrev
  4160. });
  4161. }
  4162. updateUIState(state, previous, matchesCount) {
  4163. let findMsg = Promise.resolve("");
  4164. let status = "";
  4165. switch (state) {
  4166. case _pdf_find_controller.FindState.FOUND:
  4167. break;
  4168. case _pdf_find_controller.FindState.PENDING:
  4169. status = "pending";
  4170. break;
  4171. case _pdf_find_controller.FindState.NOT_FOUND:
  4172. findMsg = this.l10n.get("find_not_found");
  4173. status = "notFound";
  4174. break;
  4175. case _pdf_find_controller.FindState.WRAPPED:
  4176. findMsg = this.l10n.get(`find_reached_${previous ? "top" : "bottom"}`);
  4177. break;
  4178. }
  4179. this.findField.setAttribute("data-status", status);
  4180. findMsg.then(msg => {
  4181. this.findMsg.textContent = msg;
  4182. this._adjustWidth();
  4183. });
  4184. this.updateResultsCount(matchesCount);
  4185. }
  4186. updateResultsCount({
  4187. current = 0,
  4188. total = 0
  4189. } = {}) {
  4190. const limit = MATCHES_COUNT_LIMIT;
  4191. let matchCountMsg = Promise.resolve("");
  4192. if (total > 0) {
  4193. if (total > limit) {
  4194. let key = "find_match_count_limit";
  4195. matchCountMsg = this.l10n.get(key, {
  4196. limit
  4197. });
  4198. } else {
  4199. let key = "find_match_count";
  4200. matchCountMsg = this.l10n.get(key, {
  4201. current,
  4202. total
  4203. });
  4204. }
  4205. }
  4206. matchCountMsg.then(msg => {
  4207. this.findResultsCount.textContent = msg;
  4208. this.findResultsCount.classList.toggle("hidden", !total);
  4209. this._adjustWidth();
  4210. });
  4211. }
  4212. open() {
  4213. if (!this.opened) {
  4214. this.opened = true;
  4215. this.toggleButton.classList.add("toggled");
  4216. this.toggleButton.setAttribute("aria-expanded", "true");
  4217. this.bar.classList.remove("hidden");
  4218. }
  4219. this.findField.select();
  4220. this.findField.focus();
  4221. this._adjustWidth();
  4222. }
  4223. close() {
  4224. if (!this.opened) {
  4225. return;
  4226. }
  4227. this.opened = false;
  4228. this.toggleButton.classList.remove("toggled");
  4229. this.toggleButton.setAttribute("aria-expanded", "false");
  4230. this.bar.classList.add("hidden");
  4231. this.eventBus.dispatch("findbarclose", {
  4232. source: this
  4233. });
  4234. }
  4235. toggle() {
  4236. if (this.opened) {
  4237. this.close();
  4238. } else {
  4239. this.open();
  4240. }
  4241. }
  4242. _adjustWidth() {
  4243. if (!this.opened) {
  4244. return;
  4245. }
  4246. this.bar.classList.remove("wrapContainers");
  4247. const findbarHeight = this.bar.clientHeight;
  4248. const inputContainerHeight = this.bar.firstElementChild.clientHeight;
  4249. if (findbarHeight > inputContainerHeight) {
  4250. this.bar.classList.add("wrapContainers");
  4251. }
  4252. }
  4253. }
  4254. exports.PDFFindBar = PDFFindBar;
  4255. /***/ }),
  4256. /* 15 */
  4257. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4258. Object.defineProperty(exports, "__esModule", ({
  4259. value: true
  4260. }));
  4261. exports.PDFFindController = exports.FindState = void 0;
  4262. var _pdfjsLib = __webpack_require__(5);
  4263. var _pdf_find_utils = __webpack_require__(16);
  4264. var _ui_utils = __webpack_require__(4);
  4265. const FindState = {
  4266. FOUND: 0,
  4267. NOT_FOUND: 1,
  4268. WRAPPED: 2,
  4269. PENDING: 3
  4270. };
  4271. exports.FindState = FindState;
  4272. const FIND_TIMEOUT = 250;
  4273. const MATCH_SCROLL_OFFSET_TOP = -50;
  4274. const MATCH_SCROLL_OFFSET_LEFT = -400;
  4275. const CHARACTERS_TO_NORMALIZE = {
  4276. "\u2018": "'",
  4277. "\u2019": "'",
  4278. "\u201A": "'",
  4279. "\u201B": "'",
  4280. "\u201C": '"',
  4281. "\u201D": '"',
  4282. "\u201E": '"',
  4283. "\u201F": '"',
  4284. "\u00BC": "1/4",
  4285. "\u00BD": "1/2",
  4286. "\u00BE": "3/4"
  4287. };
  4288. let normalizationRegex = null;
  4289. function normalize(text) {
  4290. if (!normalizationRegex) {
  4291. const replace = Object.keys(CHARACTERS_TO_NORMALIZE).join("");
  4292. normalizationRegex = new RegExp(`[${replace}]`, "g");
  4293. }
  4294. let diffs = null;
  4295. const normalizedText = text.replace(normalizationRegex, function (ch, index) {
  4296. const normalizedCh = CHARACTERS_TO_NORMALIZE[ch],
  4297. diff = normalizedCh.length - ch.length;
  4298. if (diff !== 0) {
  4299. (diffs || (diffs = [])).push([index, diff]);
  4300. }
  4301. return normalizedCh;
  4302. });
  4303. return [normalizedText, diffs];
  4304. }
  4305. function getOriginalIndex(matchIndex, diffs = null) {
  4306. if (!diffs) {
  4307. return matchIndex;
  4308. }
  4309. let totalDiff = 0;
  4310. for (const [index, diff] of diffs) {
  4311. const currentIndex = index + totalDiff;
  4312. if (currentIndex >= matchIndex) {
  4313. break;
  4314. }
  4315. if (currentIndex + diff > matchIndex) {
  4316. totalDiff += matchIndex - currentIndex;
  4317. break;
  4318. }
  4319. totalDiff += diff;
  4320. }
  4321. return matchIndex - totalDiff;
  4322. }
  4323. class PDFFindController {
  4324. constructor({
  4325. linkService,
  4326. eventBus
  4327. }) {
  4328. this._linkService = linkService;
  4329. this._eventBus = eventBus;
  4330. this._reset();
  4331. eventBus._on("findbarclose", this._onFindBarClose.bind(this));
  4332. }
  4333. get highlightMatches() {
  4334. return this._highlightMatches;
  4335. }
  4336. get pageMatches() {
  4337. return this._pageMatches;
  4338. }
  4339. get pageMatchesLength() {
  4340. return this._pageMatchesLength;
  4341. }
  4342. get selected() {
  4343. return this._selected;
  4344. }
  4345. get state() {
  4346. return this._state;
  4347. }
  4348. setDocument(pdfDocument) {
  4349. if (this._pdfDocument) {
  4350. this._reset();
  4351. }
  4352. if (!pdfDocument) {
  4353. return;
  4354. }
  4355. this._pdfDocument = pdfDocument;
  4356. this._firstPageCapability.resolve();
  4357. }
  4358. executeCommand(cmd, state) {
  4359. if (!state) {
  4360. return;
  4361. }
  4362. const pdfDocument = this._pdfDocument;
  4363. if (this._state === null || this._shouldDirtyMatch(cmd, state)) {
  4364. this._dirtyMatch = true;
  4365. }
  4366. this._state = state;
  4367. if (cmd !== "findhighlightallchange") {
  4368. this._updateUIState(FindState.PENDING);
  4369. }
  4370. this._firstPageCapability.promise.then(() => {
  4371. if (!this._pdfDocument || pdfDocument && this._pdfDocument !== pdfDocument) {
  4372. return;
  4373. }
  4374. this._extractText();
  4375. const findbarClosed = !this._highlightMatches;
  4376. const pendingTimeout = !!this._findTimeout;
  4377. if (this._findTimeout) {
  4378. clearTimeout(this._findTimeout);
  4379. this._findTimeout = null;
  4380. }
  4381. if (cmd === "find") {
  4382. this._findTimeout = setTimeout(() => {
  4383. this._nextMatch();
  4384. this._findTimeout = null;
  4385. }, FIND_TIMEOUT);
  4386. } else if (this._dirtyMatch) {
  4387. this._nextMatch();
  4388. } else if (cmd === "findagain") {
  4389. this._nextMatch();
  4390. if (findbarClosed && this._state.highlightAll) {
  4391. this._updateAllPages();
  4392. }
  4393. } else if (cmd === "findhighlightallchange") {
  4394. if (pendingTimeout) {
  4395. this._nextMatch();
  4396. } else {
  4397. this._highlightMatches = true;
  4398. }
  4399. this._updateAllPages();
  4400. } else {
  4401. this._nextMatch();
  4402. }
  4403. });
  4404. }
  4405. scrollMatchIntoView({
  4406. element = null,
  4407. pageIndex = -1,
  4408. matchIndex = -1
  4409. }) {
  4410. if (!this._scrollMatches || !element) {
  4411. return;
  4412. } else if (matchIndex === -1 || matchIndex !== this._selected.matchIdx) {
  4413. return;
  4414. } else if (pageIndex === -1 || pageIndex !== this._selected.pageIdx) {
  4415. return;
  4416. }
  4417. this._scrollMatches = false;
  4418. const spot = {
  4419. top: MATCH_SCROLL_OFFSET_TOP,
  4420. left: MATCH_SCROLL_OFFSET_LEFT
  4421. };
  4422. (0, _ui_utils.scrollIntoView)(element, spot, true);
  4423. }
  4424. _reset() {
  4425. this._highlightMatches = false;
  4426. this._scrollMatches = false;
  4427. this._pdfDocument = null;
  4428. this._pageMatches = [];
  4429. this._pageMatchesLength = [];
  4430. this._state = null;
  4431. this._selected = {
  4432. pageIdx: -1,
  4433. matchIdx: -1
  4434. };
  4435. this._offset = {
  4436. pageIdx: null,
  4437. matchIdx: null,
  4438. wrapped: false
  4439. };
  4440. this._extractTextPromises = [];
  4441. this._pageContents = [];
  4442. this._pageDiffs = [];
  4443. this._matchesCountTotal = 0;
  4444. this._pagesToSearch = null;
  4445. this._pendingFindMatches = Object.create(null);
  4446. this._resumePageIdx = null;
  4447. this._dirtyMatch = false;
  4448. clearTimeout(this._findTimeout);
  4449. this._findTimeout = null;
  4450. this._firstPageCapability = (0, _pdfjsLib.createPromiseCapability)();
  4451. }
  4452. get _query() {
  4453. if (this._state.query !== this._rawQuery) {
  4454. this._rawQuery = this._state.query;
  4455. [this._normalizedQuery] = normalize(this._state.query);
  4456. }
  4457. return this._normalizedQuery;
  4458. }
  4459. _shouldDirtyMatch(cmd, state) {
  4460. if (state.query !== this._state.query) {
  4461. return true;
  4462. }
  4463. switch (cmd) {
  4464. case "findagain":
  4465. const pageNumber = this._selected.pageIdx + 1;
  4466. const linkService = this._linkService;
  4467. if (pageNumber >= 1 && pageNumber <= linkService.pagesCount && pageNumber !== linkService.page && !linkService.isPageVisible(pageNumber)) {
  4468. return true;
  4469. }
  4470. return false;
  4471. case "findhighlightallchange":
  4472. return false;
  4473. }
  4474. return true;
  4475. }
  4476. _prepareMatches(matchesWithLength, matches, matchesLength) {
  4477. function isSubTerm(currentIndex) {
  4478. const currentElem = matchesWithLength[currentIndex];
  4479. const nextElem = matchesWithLength[currentIndex + 1];
  4480. if (currentIndex < matchesWithLength.length - 1 && currentElem.match === nextElem.match) {
  4481. currentElem.skipped = true;
  4482. return true;
  4483. }
  4484. for (let i = currentIndex - 1; i >= 0; i--) {
  4485. const prevElem = matchesWithLength[i];
  4486. if (prevElem.skipped) {
  4487. continue;
  4488. }
  4489. if (prevElem.match + prevElem.matchLength < currentElem.match) {
  4490. break;
  4491. }
  4492. if (prevElem.match + prevElem.matchLength >= currentElem.match + currentElem.matchLength) {
  4493. currentElem.skipped = true;
  4494. return true;
  4495. }
  4496. }
  4497. return false;
  4498. }
  4499. matchesWithLength.sort(function (a, b) {
  4500. return a.match === b.match ? a.matchLength - b.matchLength : a.match - b.match;
  4501. });
  4502. for (let i = 0, len = matchesWithLength.length; i < len; i++) {
  4503. if (isSubTerm(i)) {
  4504. continue;
  4505. }
  4506. matches.push(matchesWithLength[i].match);
  4507. matchesLength.push(matchesWithLength[i].matchLength);
  4508. }
  4509. }
  4510. _isEntireWord(content, startIdx, length) {
  4511. if (startIdx > 0) {
  4512. const first = content.charCodeAt(startIdx);
  4513. const limit = content.charCodeAt(startIdx - 1);
  4514. if ((0, _pdf_find_utils.getCharacterType)(first) === (0, _pdf_find_utils.getCharacterType)(limit)) {
  4515. return false;
  4516. }
  4517. }
  4518. const endIdx = startIdx + length - 1;
  4519. if (endIdx < content.length - 1) {
  4520. const last = content.charCodeAt(endIdx);
  4521. const limit = content.charCodeAt(endIdx + 1);
  4522. if ((0, _pdf_find_utils.getCharacterType)(last) === (0, _pdf_find_utils.getCharacterType)(limit)) {
  4523. return false;
  4524. }
  4525. }
  4526. return true;
  4527. }
  4528. _calculatePhraseMatch(query, pageIndex, pageContent, pageDiffs, entireWord) {
  4529. const matches = [],
  4530. matchesLength = [];
  4531. const queryLen = query.length;
  4532. let matchIdx = -queryLen;
  4533. while (true) {
  4534. matchIdx = pageContent.indexOf(query, matchIdx + queryLen);
  4535. if (matchIdx === -1) {
  4536. break;
  4537. }
  4538. if (entireWord && !this._isEntireWord(pageContent, matchIdx, queryLen)) {
  4539. continue;
  4540. }
  4541. const originalMatchIdx = getOriginalIndex(matchIdx, pageDiffs),
  4542. matchEnd = matchIdx + queryLen - 1,
  4543. originalQueryLen = getOriginalIndex(matchEnd, pageDiffs) - originalMatchIdx + 1;
  4544. matches.push(originalMatchIdx);
  4545. matchesLength.push(originalQueryLen);
  4546. }
  4547. this._pageMatches[pageIndex] = matches;
  4548. this._pageMatchesLength[pageIndex] = matchesLength;
  4549. }
  4550. _calculateWordMatch(query, pageIndex, pageContent, pageDiffs, entireWord) {
  4551. const matchesWithLength = [];
  4552. const queryArray = query.match(/\S+/g);
  4553. for (let i = 0, len = queryArray.length; i < len; i++) {
  4554. const subquery = queryArray[i];
  4555. const subqueryLen = subquery.length;
  4556. let matchIdx = -subqueryLen;
  4557. while (true) {
  4558. matchIdx = pageContent.indexOf(subquery, matchIdx + subqueryLen);
  4559. if (matchIdx === -1) {
  4560. break;
  4561. }
  4562. if (entireWord && !this._isEntireWord(pageContent, matchIdx, subqueryLen)) {
  4563. continue;
  4564. }
  4565. const originalMatchIdx = getOriginalIndex(matchIdx, pageDiffs),
  4566. matchEnd = matchIdx + subqueryLen - 1,
  4567. originalQueryLen = getOriginalIndex(matchEnd, pageDiffs) - originalMatchIdx + 1;
  4568. matchesWithLength.push({
  4569. match: originalMatchIdx,
  4570. matchLength: originalQueryLen,
  4571. skipped: false
  4572. });
  4573. }
  4574. }
  4575. this._pageMatchesLength[pageIndex] = [];
  4576. this._pageMatches[pageIndex] = [];
  4577. this._prepareMatches(matchesWithLength, this._pageMatches[pageIndex], this._pageMatchesLength[pageIndex]);
  4578. }
  4579. _calculateMatch(pageIndex) {
  4580. let pageContent = this._pageContents[pageIndex];
  4581. const pageDiffs = this._pageDiffs[pageIndex];
  4582. let query = this._query;
  4583. const {
  4584. caseSensitive,
  4585. entireWord,
  4586. phraseSearch
  4587. } = this._state;
  4588. if (query.length === 0) {
  4589. return;
  4590. }
  4591. if (!caseSensitive) {
  4592. pageContent = pageContent.toLowerCase();
  4593. query = query.toLowerCase();
  4594. }
  4595. if (phraseSearch) {
  4596. this._calculatePhraseMatch(query, pageIndex, pageContent, pageDiffs, entireWord);
  4597. } else {
  4598. this._calculateWordMatch(query, pageIndex, pageContent, pageDiffs, entireWord);
  4599. }
  4600. if (this._state.highlightAll) {
  4601. this._updatePage(pageIndex);
  4602. }
  4603. if (this._resumePageIdx === pageIndex) {
  4604. this._resumePageIdx = null;
  4605. this._nextPageMatch();
  4606. }
  4607. const pageMatchesCount = this._pageMatches[pageIndex].length;
  4608. if (pageMatchesCount > 0) {
  4609. this._matchesCountTotal += pageMatchesCount;
  4610. this._updateUIResultsCount();
  4611. }
  4612. }
  4613. _extractText() {
  4614. if (this._extractTextPromises.length > 0) {
  4615. return;
  4616. }
  4617. let promise = Promise.resolve();
  4618. for (let i = 0, ii = this._linkService.pagesCount; i < ii; i++) {
  4619. const extractTextCapability = (0, _pdfjsLib.createPromiseCapability)();
  4620. this._extractTextPromises[i] = extractTextCapability.promise;
  4621. promise = promise.then(() => {
  4622. return this._pdfDocument.getPage(i + 1).then(pdfPage => {
  4623. return pdfPage.getTextContent({
  4624. normalizeWhitespace: true
  4625. });
  4626. }).then(textContent => {
  4627. const textItems = textContent.items;
  4628. const strBuf = [];
  4629. for (let j = 0, jj = textItems.length; j < jj; j++) {
  4630. strBuf.push(textItems[j].str);
  4631. }
  4632. [this._pageContents[i], this._pageDiffs[i]] = normalize(strBuf.join(""));
  4633. extractTextCapability.resolve(i);
  4634. }, reason => {
  4635. console.error(`Unable to get text content for page ${i + 1}`, reason);
  4636. this._pageContents[i] = "";
  4637. this._pageDiffs[i] = null;
  4638. extractTextCapability.resolve(i);
  4639. });
  4640. });
  4641. }
  4642. }
  4643. _updatePage(index) {
  4644. if (this._scrollMatches && this._selected.pageIdx === index) {
  4645. this._linkService.page = index + 1;
  4646. }
  4647. this._eventBus.dispatch("updatetextlayermatches", {
  4648. source: this,
  4649. pageIndex: index
  4650. });
  4651. }
  4652. _updateAllPages() {
  4653. this._eventBus.dispatch("updatetextlayermatches", {
  4654. source: this,
  4655. pageIndex: -1
  4656. });
  4657. }
  4658. _nextMatch() {
  4659. const previous = this._state.findPrevious;
  4660. const currentPageIndex = this._linkService.page - 1;
  4661. const numPages = this._linkService.pagesCount;
  4662. this._highlightMatches = true;
  4663. if (this._dirtyMatch) {
  4664. this._dirtyMatch = false;
  4665. this._selected.pageIdx = this._selected.matchIdx = -1;
  4666. this._offset.pageIdx = currentPageIndex;
  4667. this._offset.matchIdx = null;
  4668. this._offset.wrapped = false;
  4669. this._resumePageIdx = null;
  4670. this._pageMatches.length = 0;
  4671. this._pageMatchesLength.length = 0;
  4672. this._matchesCountTotal = 0;
  4673. this._updateAllPages();
  4674. for (let i = 0; i < numPages; i++) {
  4675. if (this._pendingFindMatches[i] === true) {
  4676. continue;
  4677. }
  4678. this._pendingFindMatches[i] = true;
  4679. this._extractTextPromises[i].then(pageIdx => {
  4680. delete this._pendingFindMatches[pageIdx];
  4681. this._calculateMatch(pageIdx);
  4682. });
  4683. }
  4684. }
  4685. if (this._query === "") {
  4686. this._updateUIState(FindState.FOUND);
  4687. return;
  4688. }
  4689. if (this._resumePageIdx) {
  4690. return;
  4691. }
  4692. const offset = this._offset;
  4693. this._pagesToSearch = numPages;
  4694. if (offset.matchIdx !== null) {
  4695. const numPageMatches = this._pageMatches[offset.pageIdx].length;
  4696. if (!previous && offset.matchIdx + 1 < numPageMatches || previous && offset.matchIdx > 0) {
  4697. offset.matchIdx = previous ? offset.matchIdx - 1 : offset.matchIdx + 1;
  4698. this._updateMatch(true);
  4699. return;
  4700. }
  4701. this._advanceOffsetPage(previous);
  4702. }
  4703. this._nextPageMatch();
  4704. }
  4705. _matchesReady(matches) {
  4706. const offset = this._offset;
  4707. const numMatches = matches.length;
  4708. const previous = this._state.findPrevious;
  4709. if (numMatches) {
  4710. offset.matchIdx = previous ? numMatches - 1 : 0;
  4711. this._updateMatch(true);
  4712. return true;
  4713. }
  4714. this._advanceOffsetPage(previous);
  4715. if (offset.wrapped) {
  4716. offset.matchIdx = null;
  4717. if (this._pagesToSearch < 0) {
  4718. this._updateMatch(false);
  4719. return true;
  4720. }
  4721. }
  4722. return false;
  4723. }
  4724. _nextPageMatch() {
  4725. if (this._resumePageIdx !== null) {
  4726. console.error("There can only be one pending page.");
  4727. }
  4728. let matches = null;
  4729. do {
  4730. const pageIdx = this._offset.pageIdx;
  4731. matches = this._pageMatches[pageIdx];
  4732. if (!matches) {
  4733. this._resumePageIdx = pageIdx;
  4734. break;
  4735. }
  4736. } while (!this._matchesReady(matches));
  4737. }
  4738. _advanceOffsetPage(previous) {
  4739. const offset = this._offset;
  4740. const numPages = this._linkService.pagesCount;
  4741. offset.pageIdx = previous ? offset.pageIdx - 1 : offset.pageIdx + 1;
  4742. offset.matchIdx = null;
  4743. this._pagesToSearch--;
  4744. if (offset.pageIdx >= numPages || offset.pageIdx < 0) {
  4745. offset.pageIdx = previous ? numPages - 1 : 0;
  4746. offset.wrapped = true;
  4747. }
  4748. }
  4749. _updateMatch(found = false) {
  4750. let state = FindState.NOT_FOUND;
  4751. const wrapped = this._offset.wrapped;
  4752. this._offset.wrapped = false;
  4753. if (found) {
  4754. const previousPage = this._selected.pageIdx;
  4755. this._selected.pageIdx = this._offset.pageIdx;
  4756. this._selected.matchIdx = this._offset.matchIdx;
  4757. state = wrapped ? FindState.WRAPPED : FindState.FOUND;
  4758. if (previousPage !== -1 && previousPage !== this._selected.pageIdx) {
  4759. this._updatePage(previousPage);
  4760. }
  4761. }
  4762. this._updateUIState(state, this._state.findPrevious);
  4763. if (this._selected.pageIdx !== -1) {
  4764. this._scrollMatches = true;
  4765. this._updatePage(this._selected.pageIdx);
  4766. }
  4767. }
  4768. _onFindBarClose(evt) {
  4769. const pdfDocument = this._pdfDocument;
  4770. this._firstPageCapability.promise.then(() => {
  4771. if (!this._pdfDocument || pdfDocument && this._pdfDocument !== pdfDocument) {
  4772. return;
  4773. }
  4774. if (this._findTimeout) {
  4775. clearTimeout(this._findTimeout);
  4776. this._findTimeout = null;
  4777. }
  4778. if (this._resumePageIdx) {
  4779. this._resumePageIdx = null;
  4780. this._dirtyMatch = true;
  4781. }
  4782. this._updateUIState(FindState.FOUND);
  4783. this._highlightMatches = false;
  4784. this._updateAllPages();
  4785. });
  4786. }
  4787. _requestMatchesCount() {
  4788. const {
  4789. pageIdx,
  4790. matchIdx
  4791. } = this._selected;
  4792. let current = 0,
  4793. total = this._matchesCountTotal;
  4794. if (matchIdx !== -1) {
  4795. for (let i = 0; i < pageIdx; i++) {
  4796. current += this._pageMatches[i]?.length || 0;
  4797. }
  4798. current += matchIdx + 1;
  4799. }
  4800. if (current < 1 || current > total) {
  4801. current = total = 0;
  4802. }
  4803. return {
  4804. current,
  4805. total
  4806. };
  4807. }
  4808. _updateUIResultsCount() {
  4809. this._eventBus.dispatch("updatefindmatchescount", {
  4810. source: this,
  4811. matchesCount: this._requestMatchesCount()
  4812. });
  4813. }
  4814. _updateUIState(state, previous) {
  4815. this._eventBus.dispatch("updatefindcontrolstate", {
  4816. source: this,
  4817. state,
  4818. previous,
  4819. matchesCount: this._requestMatchesCount(),
  4820. rawQuery: this._state?.query ?? null
  4821. });
  4822. }
  4823. }
  4824. exports.PDFFindController = PDFFindController;
  4825. /***/ }),
  4826. /* 16 */
  4827. /***/ ((__unused_webpack_module, exports) => {
  4828. Object.defineProperty(exports, "__esModule", ({
  4829. value: true
  4830. }));
  4831. exports.getCharacterType = getCharacterType;
  4832. exports.CharacterType = void 0;
  4833. const CharacterType = {
  4834. SPACE: 0,
  4835. ALPHA_LETTER: 1,
  4836. PUNCT: 2,
  4837. HAN_LETTER: 3,
  4838. KATAKANA_LETTER: 4,
  4839. HIRAGANA_LETTER: 5,
  4840. HALFWIDTH_KATAKANA_LETTER: 6,
  4841. THAI_LETTER: 7
  4842. };
  4843. exports.CharacterType = CharacterType;
  4844. function isAlphabeticalScript(charCode) {
  4845. return charCode < 0x2e80;
  4846. }
  4847. function isAscii(charCode) {
  4848. return (charCode & 0xff80) === 0;
  4849. }
  4850. function isAsciiAlpha(charCode) {
  4851. return charCode >= 0x61 && charCode <= 0x7a || charCode >= 0x41 && charCode <= 0x5a;
  4852. }
  4853. function isAsciiDigit(charCode) {
  4854. return charCode >= 0x30 && charCode <= 0x39;
  4855. }
  4856. function isAsciiSpace(charCode) {
  4857. return charCode === 0x20 || charCode === 0x09 || charCode === 0x0d || charCode === 0x0a;
  4858. }
  4859. function isHan(charCode) {
  4860. return charCode >= 0x3400 && charCode <= 0x9fff || charCode >= 0xf900 && charCode <= 0xfaff;
  4861. }
  4862. function isKatakana(charCode) {
  4863. return charCode >= 0x30a0 && charCode <= 0x30ff;
  4864. }
  4865. function isHiragana(charCode) {
  4866. return charCode >= 0x3040 && charCode <= 0x309f;
  4867. }
  4868. function isHalfwidthKatakana(charCode) {
  4869. return charCode >= 0xff60 && charCode <= 0xff9f;
  4870. }
  4871. function isThai(charCode) {
  4872. return (charCode & 0xff80) === 0x0e00;
  4873. }
  4874. function getCharacterType(charCode) {
  4875. if (isAlphabeticalScript(charCode)) {
  4876. if (isAscii(charCode)) {
  4877. if (isAsciiSpace(charCode)) {
  4878. return CharacterType.SPACE;
  4879. } else if (isAsciiAlpha(charCode) || isAsciiDigit(charCode) || charCode === 0x5f) {
  4880. return CharacterType.ALPHA_LETTER;
  4881. }
  4882. return CharacterType.PUNCT;
  4883. } else if (isThai(charCode)) {
  4884. return CharacterType.THAI_LETTER;
  4885. } else if (charCode === 0xa0) {
  4886. return CharacterType.SPACE;
  4887. }
  4888. return CharacterType.ALPHA_LETTER;
  4889. }
  4890. if (isHan(charCode)) {
  4891. return CharacterType.HAN_LETTER;
  4892. } else if (isKatakana(charCode)) {
  4893. return CharacterType.KATAKANA_LETTER;
  4894. } else if (isHiragana(charCode)) {
  4895. return CharacterType.HIRAGANA_LETTER;
  4896. } else if (isHalfwidthKatakana(charCode)) {
  4897. return CharacterType.HALFWIDTH_KATAKANA_LETTER;
  4898. }
  4899. return CharacterType.ALPHA_LETTER;
  4900. }
  4901. /***/ }),
  4902. /* 17 */
  4903. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4904. Object.defineProperty(exports, "__esModule", ({
  4905. value: true
  4906. }));
  4907. exports.isDestArraysEqual = isDestArraysEqual;
  4908. exports.isDestHashesEqual = isDestHashesEqual;
  4909. exports.PDFHistory = void 0;
  4910. var _ui_utils = __webpack_require__(4);
  4911. const HASH_CHANGE_TIMEOUT = 1000;
  4912. const POSITION_UPDATED_THRESHOLD = 50;
  4913. const UPDATE_VIEWAREA_TIMEOUT = 1000;
  4914. function getCurrentHash() {
  4915. return document.location.hash;
  4916. }
  4917. class PDFHistory {
  4918. constructor({
  4919. linkService,
  4920. eventBus
  4921. }) {
  4922. this.linkService = linkService;
  4923. this.eventBus = eventBus;
  4924. this._initialized = false;
  4925. this._fingerprint = "";
  4926. this.reset();
  4927. this._boundEvents = null;
  4928. this._isViewerInPresentationMode = false;
  4929. this.eventBus._on("presentationmodechanged", evt => {
  4930. this._isViewerInPresentationMode = evt.state !== _ui_utils.PresentationModeState.NORMAL;
  4931. });
  4932. this.eventBus._on("pagesinit", () => {
  4933. this._isPagesLoaded = false;
  4934. this.eventBus._on("pagesloaded", evt => {
  4935. this._isPagesLoaded = !!evt.pagesCount;
  4936. }, {
  4937. once: true
  4938. });
  4939. });
  4940. }
  4941. initialize({
  4942. fingerprint,
  4943. resetHistory = false,
  4944. updateUrl = false
  4945. }) {
  4946. if (!fingerprint || typeof fingerprint !== "string") {
  4947. console.error('PDFHistory.initialize: The "fingerprint" must be a non-empty string.');
  4948. return;
  4949. }
  4950. if (this._initialized) {
  4951. this.reset();
  4952. }
  4953. const reInitialized = this._fingerprint !== "" && this._fingerprint !== fingerprint;
  4954. this._fingerprint = fingerprint;
  4955. this._updateUrl = updateUrl === true;
  4956. this._initialized = true;
  4957. this._bindEvents();
  4958. const state = window.history.state;
  4959. this._popStateInProgress = false;
  4960. this._blockHashChange = 0;
  4961. this._currentHash = getCurrentHash();
  4962. this._numPositionUpdates = 0;
  4963. this._uid = this._maxUid = 0;
  4964. this._destination = null;
  4965. this._position = null;
  4966. if (!this._isValidState(state, true) || resetHistory) {
  4967. const {
  4968. hash,
  4969. page,
  4970. rotation
  4971. } = this._parseCurrentHash(true);
  4972. if (!hash || reInitialized || resetHistory) {
  4973. this._pushOrReplaceState(null, true);
  4974. return;
  4975. }
  4976. this._pushOrReplaceState({
  4977. hash,
  4978. page,
  4979. rotation
  4980. }, true);
  4981. return;
  4982. }
  4983. const destination = state.destination;
  4984. this._updateInternalState(destination, state.uid, true);
  4985. if (destination.rotation !== undefined) {
  4986. this._initialRotation = destination.rotation;
  4987. }
  4988. if (destination.dest) {
  4989. this._initialBookmark = JSON.stringify(destination.dest);
  4990. this._destination.page = null;
  4991. } else if (destination.hash) {
  4992. this._initialBookmark = destination.hash;
  4993. } else if (destination.page) {
  4994. this._initialBookmark = `page=${destination.page}`;
  4995. }
  4996. }
  4997. reset() {
  4998. if (this._initialized) {
  4999. this._pageHide();
  5000. this._initialized = false;
  5001. this._unbindEvents();
  5002. }
  5003. if (this._updateViewareaTimeout) {
  5004. clearTimeout(this._updateViewareaTimeout);
  5005. this._updateViewareaTimeout = null;
  5006. }
  5007. this._initialBookmark = null;
  5008. this._initialRotation = null;
  5009. }
  5010. push({
  5011. namedDest = null,
  5012. explicitDest,
  5013. pageNumber
  5014. }) {
  5015. if (!this._initialized) {
  5016. return;
  5017. }
  5018. if (namedDest && typeof namedDest !== "string") {
  5019. console.error("PDFHistory.push: " + `"${namedDest}" is not a valid namedDest parameter.`);
  5020. return;
  5021. } else if (!Array.isArray(explicitDest)) {
  5022. console.error("PDFHistory.push: " + `"${explicitDest}" is not a valid explicitDest parameter.`);
  5023. return;
  5024. } else if (!this._isValidPage(pageNumber)) {
  5025. if (pageNumber !== null || this._destination) {
  5026. console.error("PDFHistory.push: " + `"${pageNumber}" is not a valid pageNumber parameter.`);
  5027. return;
  5028. }
  5029. }
  5030. const hash = namedDest || JSON.stringify(explicitDest);
  5031. if (!hash) {
  5032. return;
  5033. }
  5034. let forceReplace = false;
  5035. if (this._destination && (isDestHashesEqual(this._destination.hash, hash) || isDestArraysEqual(this._destination.dest, explicitDest))) {
  5036. if (this._destination.page) {
  5037. return;
  5038. }
  5039. forceReplace = true;
  5040. }
  5041. if (this._popStateInProgress && !forceReplace) {
  5042. return;
  5043. }
  5044. this._pushOrReplaceState({
  5045. dest: explicitDest,
  5046. hash,
  5047. page: pageNumber,
  5048. rotation: this.linkService.rotation
  5049. }, forceReplace);
  5050. if (!this._popStateInProgress) {
  5051. this._popStateInProgress = true;
  5052. Promise.resolve().then(() => {
  5053. this._popStateInProgress = false;
  5054. });
  5055. }
  5056. }
  5057. pushPage(pageNumber) {
  5058. if (!this._initialized) {
  5059. return;
  5060. }
  5061. if (!this._isValidPage(pageNumber)) {
  5062. console.error(`PDFHistory.pushPage: "${pageNumber}" is not a valid page number.`);
  5063. return;
  5064. }
  5065. if (this._destination?.page === pageNumber) {
  5066. return;
  5067. }
  5068. if (this._popStateInProgress) {
  5069. return;
  5070. }
  5071. this._pushOrReplaceState({
  5072. dest: null,
  5073. hash: `page=${pageNumber}`,
  5074. page: pageNumber,
  5075. rotation: this.linkService.rotation
  5076. });
  5077. if (!this._popStateInProgress) {
  5078. this._popStateInProgress = true;
  5079. Promise.resolve().then(() => {
  5080. this._popStateInProgress = false;
  5081. });
  5082. }
  5083. }
  5084. pushCurrentPosition() {
  5085. if (!this._initialized || this._popStateInProgress) {
  5086. return;
  5087. }
  5088. this._tryPushCurrentPosition();
  5089. }
  5090. back() {
  5091. if (!this._initialized || this._popStateInProgress) {
  5092. return;
  5093. }
  5094. const state = window.history.state;
  5095. if (this._isValidState(state) && state.uid > 0) {
  5096. window.history.back();
  5097. }
  5098. }
  5099. forward() {
  5100. if (!this._initialized || this._popStateInProgress) {
  5101. return;
  5102. }
  5103. const state = window.history.state;
  5104. if (this._isValidState(state) && state.uid < this._maxUid) {
  5105. window.history.forward();
  5106. }
  5107. }
  5108. get popStateInProgress() {
  5109. return this._initialized && (this._popStateInProgress || this._blockHashChange > 0);
  5110. }
  5111. get initialBookmark() {
  5112. return this._initialized ? this._initialBookmark : null;
  5113. }
  5114. get initialRotation() {
  5115. return this._initialized ? this._initialRotation : null;
  5116. }
  5117. _pushOrReplaceState(destination, forceReplace = false) {
  5118. const shouldReplace = forceReplace || !this._destination;
  5119. const newState = {
  5120. fingerprint: this._fingerprint,
  5121. uid: shouldReplace ? this._uid : this._uid + 1,
  5122. destination
  5123. };
  5124. this._updateInternalState(destination, newState.uid);
  5125. let newUrl;
  5126. if (this._updateUrl && destination?.hash) {
  5127. const baseUrl = document.location.href.split("#")[0];
  5128. if (!baseUrl.startsWith("file://")) {
  5129. newUrl = `${baseUrl}#${destination.hash}`;
  5130. }
  5131. }
  5132. if (shouldReplace) {
  5133. window.history.replaceState(newState, "", newUrl);
  5134. } else {
  5135. window.history.pushState(newState, "", newUrl);
  5136. }
  5137. }
  5138. _tryPushCurrentPosition(temporary = false) {
  5139. if (!this._position) {
  5140. return;
  5141. }
  5142. let position = this._position;
  5143. if (temporary) {
  5144. position = Object.assign(Object.create(null), this._position);
  5145. position.temporary = true;
  5146. }
  5147. if (!this._destination) {
  5148. this._pushOrReplaceState(position);
  5149. return;
  5150. }
  5151. if (this._destination.temporary) {
  5152. this._pushOrReplaceState(position, true);
  5153. return;
  5154. }
  5155. if (this._destination.hash === position.hash) {
  5156. return;
  5157. }
  5158. if (!this._destination.page && (POSITION_UPDATED_THRESHOLD <= 0 || this._numPositionUpdates <= POSITION_UPDATED_THRESHOLD)) {
  5159. return;
  5160. }
  5161. let forceReplace = false;
  5162. if (this._destination.page >= position.first && this._destination.page <= position.page) {
  5163. if (this._destination.dest !== undefined || !this._destination.first) {
  5164. return;
  5165. }
  5166. forceReplace = true;
  5167. }
  5168. this._pushOrReplaceState(position, forceReplace);
  5169. }
  5170. _isValidPage(val) {
  5171. return Number.isInteger(val) && val > 0 && val <= this.linkService.pagesCount;
  5172. }
  5173. _isValidState(state, checkReload = false) {
  5174. if (!state) {
  5175. return false;
  5176. }
  5177. if (state.fingerprint !== this._fingerprint) {
  5178. if (checkReload) {
  5179. if (typeof state.fingerprint !== "string" || state.fingerprint.length !== this._fingerprint.length) {
  5180. return false;
  5181. }
  5182. const [perfEntry] = performance.getEntriesByType("navigation");
  5183. if (perfEntry?.type !== "reload") {
  5184. return false;
  5185. }
  5186. } else {
  5187. return false;
  5188. }
  5189. }
  5190. if (!Number.isInteger(state.uid) || state.uid < 0) {
  5191. return false;
  5192. }
  5193. if (state.destination === null || typeof state.destination !== "object") {
  5194. return false;
  5195. }
  5196. return true;
  5197. }
  5198. _updateInternalState(destination, uid, removeTemporary = false) {
  5199. if (this._updateViewareaTimeout) {
  5200. clearTimeout(this._updateViewareaTimeout);
  5201. this._updateViewareaTimeout = null;
  5202. }
  5203. if (removeTemporary && destination?.temporary) {
  5204. delete destination.temporary;
  5205. }
  5206. this._destination = destination;
  5207. this._uid = uid;
  5208. this._maxUid = Math.max(this._maxUid, uid);
  5209. this._numPositionUpdates = 0;
  5210. }
  5211. _parseCurrentHash(checkNameddest = false) {
  5212. const hash = unescape(getCurrentHash()).substring(1);
  5213. const params = (0, _ui_utils.parseQueryString)(hash);
  5214. const nameddest = params.nameddest || "";
  5215. let page = params.page | 0;
  5216. if (!this._isValidPage(page) || checkNameddest && nameddest.length > 0) {
  5217. page = null;
  5218. }
  5219. return {
  5220. hash,
  5221. page,
  5222. rotation: this.linkService.rotation
  5223. };
  5224. }
  5225. _updateViewarea({
  5226. location
  5227. }) {
  5228. if (this._updateViewareaTimeout) {
  5229. clearTimeout(this._updateViewareaTimeout);
  5230. this._updateViewareaTimeout = null;
  5231. }
  5232. this._position = {
  5233. hash: this._isViewerInPresentationMode ? `page=${location.pageNumber}` : location.pdfOpenParams.substring(1),
  5234. page: this.linkService.page,
  5235. first: location.pageNumber,
  5236. rotation: location.rotation
  5237. };
  5238. if (this._popStateInProgress) {
  5239. return;
  5240. }
  5241. if (POSITION_UPDATED_THRESHOLD > 0 && this._isPagesLoaded && this._destination && !this._destination.page) {
  5242. this._numPositionUpdates++;
  5243. }
  5244. if (UPDATE_VIEWAREA_TIMEOUT > 0) {
  5245. this._updateViewareaTimeout = setTimeout(() => {
  5246. if (!this._popStateInProgress) {
  5247. this._tryPushCurrentPosition(true);
  5248. }
  5249. this._updateViewareaTimeout = null;
  5250. }, UPDATE_VIEWAREA_TIMEOUT);
  5251. }
  5252. }
  5253. _popState({
  5254. state
  5255. }) {
  5256. const newHash = getCurrentHash(),
  5257. hashChanged = this._currentHash !== newHash;
  5258. this._currentHash = newHash;
  5259. if (!state) {
  5260. this._uid++;
  5261. const {
  5262. hash,
  5263. page,
  5264. rotation
  5265. } = this._parseCurrentHash();
  5266. this._pushOrReplaceState({
  5267. hash,
  5268. page,
  5269. rotation
  5270. }, true);
  5271. return;
  5272. }
  5273. if (!this._isValidState(state)) {
  5274. return;
  5275. }
  5276. this._popStateInProgress = true;
  5277. if (hashChanged) {
  5278. this._blockHashChange++;
  5279. (0, _ui_utils.waitOnEventOrTimeout)({
  5280. target: window,
  5281. name: "hashchange",
  5282. delay: HASH_CHANGE_TIMEOUT
  5283. }).then(() => {
  5284. this._blockHashChange--;
  5285. });
  5286. }
  5287. const destination = state.destination;
  5288. this._updateInternalState(destination, state.uid, true);
  5289. if ((0, _ui_utils.isValidRotation)(destination.rotation)) {
  5290. this.linkService.rotation = destination.rotation;
  5291. }
  5292. if (destination.dest) {
  5293. this.linkService.goToDestination(destination.dest);
  5294. } else if (destination.hash) {
  5295. this.linkService.setHash(destination.hash);
  5296. } else if (destination.page) {
  5297. this.linkService.page = destination.page;
  5298. }
  5299. Promise.resolve().then(() => {
  5300. this._popStateInProgress = false;
  5301. });
  5302. }
  5303. _pageHide() {
  5304. if (!this._destination || this._destination.temporary) {
  5305. this._tryPushCurrentPosition();
  5306. }
  5307. }
  5308. _bindEvents() {
  5309. if (this._boundEvents) {
  5310. return;
  5311. }
  5312. this._boundEvents = {
  5313. updateViewarea: this._updateViewarea.bind(this),
  5314. popState: this._popState.bind(this),
  5315. pageHide: this._pageHide.bind(this)
  5316. };
  5317. this.eventBus._on("updateviewarea", this._boundEvents.updateViewarea);
  5318. window.addEventListener("popstate", this._boundEvents.popState);
  5319. window.addEventListener("pagehide", this._boundEvents.pageHide);
  5320. }
  5321. _unbindEvents() {
  5322. if (!this._boundEvents) {
  5323. return;
  5324. }
  5325. this.eventBus._off("updateviewarea", this._boundEvents.updateViewarea);
  5326. window.removeEventListener("popstate", this._boundEvents.popState);
  5327. window.removeEventListener("pagehide", this._boundEvents.pageHide);
  5328. this._boundEvents = null;
  5329. }
  5330. }
  5331. exports.PDFHistory = PDFHistory;
  5332. function isDestHashesEqual(destHash, pushHash) {
  5333. if (typeof destHash !== "string" || typeof pushHash !== "string") {
  5334. return false;
  5335. }
  5336. if (destHash === pushHash) {
  5337. return true;
  5338. }
  5339. const {
  5340. nameddest
  5341. } = (0, _ui_utils.parseQueryString)(destHash);
  5342. if (nameddest === pushHash) {
  5343. return true;
  5344. }
  5345. return false;
  5346. }
  5347. function isDestArraysEqual(firstDest, secondDest) {
  5348. function isEntryEqual(first, second) {
  5349. if (typeof first !== typeof second) {
  5350. return false;
  5351. }
  5352. if (Array.isArray(first) || Array.isArray(second)) {
  5353. return false;
  5354. }
  5355. if (first !== null && typeof first === "object" && second !== null) {
  5356. if (Object.keys(first).length !== Object.keys(second).length) {
  5357. return false;
  5358. }
  5359. for (const key in first) {
  5360. if (!isEntryEqual(first[key], second[key])) {
  5361. return false;
  5362. }
  5363. }
  5364. return true;
  5365. }
  5366. return first === second || Number.isNaN(first) && Number.isNaN(second);
  5367. }
  5368. if (!(Array.isArray(firstDest) && Array.isArray(secondDest))) {
  5369. return false;
  5370. }
  5371. if (firstDest.length !== secondDest.length) {
  5372. return false;
  5373. }
  5374. for (let i = 0, ii = firstDest.length; i < ii; i++) {
  5375. if (!isEntryEqual(firstDest[i], secondDest[i])) {
  5376. return false;
  5377. }
  5378. }
  5379. return true;
  5380. }
  5381. /***/ }),
  5382. /* 18 */
  5383. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  5384. Object.defineProperty(exports, "__esModule", ({
  5385. value: true
  5386. }));
  5387. exports.PDFLayerViewer = void 0;
  5388. var _base_tree_viewer = __webpack_require__(12);
  5389. class PDFLayerViewer extends _base_tree_viewer.BaseTreeViewer {
  5390. constructor(options) {
  5391. super(options);
  5392. this.l10n = options.l10n;
  5393. this.eventBus._on("resetlayers", this._resetLayers.bind(this));
  5394. this.eventBus._on("togglelayerstree", this._toggleAllTreeItems.bind(this));
  5395. }
  5396. reset() {
  5397. super.reset();
  5398. this._optionalContentConfig = null;
  5399. }
  5400. _dispatchEvent(layersCount) {
  5401. this.eventBus.dispatch("layersloaded", {
  5402. source: this,
  5403. layersCount
  5404. });
  5405. }
  5406. _bindLink(element, {
  5407. groupId,
  5408. input
  5409. }) {
  5410. const setVisibility = () => {
  5411. this._optionalContentConfig.setVisibility(groupId, input.checked);
  5412. this.eventBus.dispatch("optionalcontentconfig", {
  5413. source: this,
  5414. promise: Promise.resolve(this._optionalContentConfig)
  5415. });
  5416. };
  5417. element.onclick = evt => {
  5418. if (evt.target === input) {
  5419. setVisibility();
  5420. return true;
  5421. } else if (evt.target !== element) {
  5422. return true;
  5423. }
  5424. input.checked = !input.checked;
  5425. setVisibility();
  5426. return false;
  5427. };
  5428. }
  5429. async _setNestedName(element, {
  5430. name = null
  5431. }) {
  5432. if (typeof name === "string") {
  5433. element.textContent = this._normalizeTextContent(name);
  5434. return;
  5435. }
  5436. element.textContent = await this.l10n.get("additional_layers");
  5437. element.style.fontStyle = "italic";
  5438. }
  5439. _addToggleButton(div, {
  5440. name = null
  5441. }) {
  5442. super._addToggleButton(div, name === null);
  5443. }
  5444. _toggleAllTreeItems() {
  5445. if (!this._optionalContentConfig) {
  5446. return;
  5447. }
  5448. super._toggleAllTreeItems();
  5449. }
  5450. render({
  5451. optionalContentConfig,
  5452. pdfDocument
  5453. }) {
  5454. if (this._optionalContentConfig) {
  5455. this.reset();
  5456. }
  5457. this._optionalContentConfig = optionalContentConfig || null;
  5458. this._pdfDocument = pdfDocument || null;
  5459. const groups = optionalContentConfig?.getOrder();
  5460. if (!groups) {
  5461. this._dispatchEvent(0);
  5462. return;
  5463. }
  5464. const fragment = document.createDocumentFragment(),
  5465. queue = [{
  5466. parent: fragment,
  5467. groups
  5468. }];
  5469. let layersCount = 0,
  5470. hasAnyNesting = false;
  5471. while (queue.length > 0) {
  5472. const levelData = queue.shift();
  5473. for (const groupId of levelData.groups) {
  5474. const div = document.createElement("div");
  5475. div.className = "treeItem";
  5476. const element = document.createElement("a");
  5477. div.appendChild(element);
  5478. if (typeof groupId === "object") {
  5479. hasAnyNesting = true;
  5480. this._addToggleButton(div, groupId);
  5481. this._setNestedName(element, groupId);
  5482. const itemsDiv = document.createElement("div");
  5483. itemsDiv.className = "treeItems";
  5484. div.appendChild(itemsDiv);
  5485. queue.push({
  5486. parent: itemsDiv,
  5487. groups: groupId.order
  5488. });
  5489. } else {
  5490. const group = optionalContentConfig.getGroup(groupId);
  5491. const input = document.createElement("input");
  5492. this._bindLink(element, {
  5493. groupId,
  5494. input
  5495. });
  5496. input.type = "checkbox";
  5497. input.id = groupId;
  5498. input.checked = group.visible;
  5499. const label = document.createElement("label");
  5500. label.setAttribute("for", groupId);
  5501. label.textContent = this._normalizeTextContent(group.name);
  5502. element.appendChild(input);
  5503. element.appendChild(label);
  5504. layersCount++;
  5505. }
  5506. levelData.parent.appendChild(div);
  5507. }
  5508. }
  5509. this._finishRendering(fragment, layersCount, hasAnyNesting);
  5510. }
  5511. async _resetLayers() {
  5512. if (!this._optionalContentConfig) {
  5513. return;
  5514. }
  5515. const optionalContentConfig = await this._pdfDocument.getOptionalContentConfig();
  5516. this.eventBus.dispatch("optionalcontentconfig", {
  5517. source: this,
  5518. promise: Promise.resolve(optionalContentConfig)
  5519. });
  5520. this.render({
  5521. optionalContentConfig,
  5522. pdfDocument: this._pdfDocument
  5523. });
  5524. }
  5525. }
  5526. exports.PDFLayerViewer = PDFLayerViewer;
  5527. /***/ }),
  5528. /* 19 */
  5529. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  5530. Object.defineProperty(exports, "__esModule", ({
  5531. value: true
  5532. }));
  5533. exports.SimpleLinkService = exports.PDFLinkService = void 0;
  5534. var _ui_utils = __webpack_require__(4);
  5535. class PDFLinkService {
  5536. constructor({
  5537. eventBus,
  5538. externalLinkTarget = null,
  5539. externalLinkRel = null,
  5540. externalLinkEnabled = true,
  5541. ignoreDestinationZoom = false
  5542. } = {}) {
  5543. this.eventBus = eventBus;
  5544. this.externalLinkTarget = externalLinkTarget;
  5545. this.externalLinkRel = externalLinkRel;
  5546. this.externalLinkEnabled = externalLinkEnabled;
  5547. this._ignoreDestinationZoom = ignoreDestinationZoom;
  5548. this.baseUrl = null;
  5549. this.pdfDocument = null;
  5550. this.pdfViewer = null;
  5551. this.pdfHistory = null;
  5552. this._pagesRefCache = null;
  5553. }
  5554. setDocument(pdfDocument, baseUrl = null) {
  5555. this.baseUrl = baseUrl;
  5556. this.pdfDocument = pdfDocument;
  5557. this._pagesRefCache = Object.create(null);
  5558. }
  5559. setViewer(pdfViewer) {
  5560. this.pdfViewer = pdfViewer;
  5561. }
  5562. setHistory(pdfHistory) {
  5563. this.pdfHistory = pdfHistory;
  5564. }
  5565. get pagesCount() {
  5566. return this.pdfDocument ? this.pdfDocument.numPages : 0;
  5567. }
  5568. get page() {
  5569. return this.pdfViewer.currentPageNumber;
  5570. }
  5571. set page(value) {
  5572. this.pdfViewer.currentPageNumber = value;
  5573. }
  5574. get rotation() {
  5575. return this.pdfViewer.pagesRotation;
  5576. }
  5577. set rotation(value) {
  5578. this.pdfViewer.pagesRotation = value;
  5579. }
  5580. navigateTo(dest) {
  5581. console.error("Deprecated method: `navigateTo`, use `goToDestination` instead.");
  5582. this.goToDestination(dest);
  5583. }
  5584. _goToDestinationHelper(rawDest, namedDest = null, explicitDest) {
  5585. const destRef = explicitDest[0];
  5586. let pageNumber;
  5587. if (destRef instanceof Object) {
  5588. pageNumber = this._cachedPageNumber(destRef);
  5589. if (pageNumber === null) {
  5590. this.pdfDocument.getPageIndex(destRef).then(pageIndex => {
  5591. this.cachePageRef(pageIndex + 1, destRef);
  5592. this._goToDestinationHelper(rawDest, namedDest, explicitDest);
  5593. }).catch(() => {
  5594. console.error(`PDFLinkService._goToDestinationHelper: "${destRef}" is not ` + `a valid page reference, for dest="${rawDest}".`);
  5595. });
  5596. return;
  5597. }
  5598. } else if (Number.isInteger(destRef)) {
  5599. pageNumber = destRef + 1;
  5600. } else {
  5601. console.error(`PDFLinkService._goToDestinationHelper: "${destRef}" is not ` + `a valid destination reference, for dest="${rawDest}".`);
  5602. return;
  5603. }
  5604. if (!pageNumber || pageNumber < 1 || pageNumber > this.pagesCount) {
  5605. console.error(`PDFLinkService._goToDestinationHelper: "${pageNumber}" is not ` + `a valid page number, for dest="${rawDest}".`);
  5606. return;
  5607. }
  5608. if (this.pdfHistory) {
  5609. this.pdfHistory.pushCurrentPosition();
  5610. this.pdfHistory.push({
  5611. namedDest,
  5612. explicitDest,
  5613. pageNumber
  5614. });
  5615. }
  5616. this.pdfViewer.scrollPageIntoView({
  5617. pageNumber,
  5618. destArray: explicitDest,
  5619. ignoreDestinationZoom: this._ignoreDestinationZoom
  5620. });
  5621. }
  5622. async goToDestination(dest) {
  5623. if (!this.pdfDocument) {
  5624. return;
  5625. }
  5626. let namedDest, explicitDest;
  5627. if (typeof dest === "string") {
  5628. namedDest = dest;
  5629. explicitDest = await this.pdfDocument.getDestination(dest);
  5630. } else {
  5631. namedDest = null;
  5632. explicitDest = await dest;
  5633. }
  5634. if (!Array.isArray(explicitDest)) {
  5635. console.error(`PDFLinkService.goToDestination: "${explicitDest}" is not ` + `a valid destination array, for dest="${dest}".`);
  5636. return;
  5637. }
  5638. this._goToDestinationHelper(dest, namedDest, explicitDest);
  5639. }
  5640. goToPage(val) {
  5641. if (!this.pdfDocument) {
  5642. return;
  5643. }
  5644. const pageNumber = typeof val === "string" && this.pdfViewer.pageLabelToPageNumber(val) || val | 0;
  5645. if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) {
  5646. console.error(`PDFLinkService.goToPage: "${val}" is not a valid page.`);
  5647. return;
  5648. }
  5649. if (this.pdfHistory) {
  5650. this.pdfHistory.pushCurrentPosition();
  5651. this.pdfHistory.pushPage(pageNumber);
  5652. }
  5653. this.pdfViewer.scrollPageIntoView({
  5654. pageNumber
  5655. });
  5656. }
  5657. getDestinationHash(dest) {
  5658. if (typeof dest === "string") {
  5659. if (dest.length > 0) {
  5660. return this.getAnchorUrl("#" + escape(dest));
  5661. }
  5662. } else if (Array.isArray(dest)) {
  5663. const str = JSON.stringify(dest);
  5664. if (str.length > 0) {
  5665. return this.getAnchorUrl("#" + escape(str));
  5666. }
  5667. }
  5668. return this.getAnchorUrl("");
  5669. }
  5670. getAnchorUrl(anchor) {
  5671. return (this.baseUrl || "") + anchor;
  5672. }
  5673. setHash(hash) {
  5674. if (!this.pdfDocument) {
  5675. return;
  5676. }
  5677. let pageNumber, dest;
  5678. if (hash.includes("=")) {
  5679. const params = (0, _ui_utils.parseQueryString)(hash);
  5680. if ("search" in params) {
  5681. this.eventBus.dispatch("findfromurlhash", {
  5682. source: this,
  5683. query: params.search.replace(/"/g, ""),
  5684. phraseSearch: params.phrase === "true"
  5685. });
  5686. }
  5687. if ("page" in params) {
  5688. pageNumber = params.page | 0 || 1;
  5689. }
  5690. if ("zoom" in params) {
  5691. const zoomArgs = params.zoom.split(",");
  5692. const zoomArg = zoomArgs[0];
  5693. const zoomArgNumber = parseFloat(zoomArg);
  5694. if (!zoomArg.includes("Fit")) {
  5695. dest = [null, {
  5696. name: "XYZ"
  5697. }, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null, zoomArgs.length > 2 ? zoomArgs[2] | 0 : null, zoomArgNumber ? zoomArgNumber / 100 : zoomArg];
  5698. } else {
  5699. if (zoomArg === "Fit" || zoomArg === "FitB") {
  5700. dest = [null, {
  5701. name: zoomArg
  5702. }];
  5703. } else if (zoomArg === "FitH" || zoomArg === "FitBH" || zoomArg === "FitV" || zoomArg === "FitBV") {
  5704. dest = [null, {
  5705. name: zoomArg
  5706. }, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null];
  5707. } else if (zoomArg === "FitR") {
  5708. if (zoomArgs.length !== 5) {
  5709. console.error('PDFLinkService.setHash: Not enough parameters for "FitR".');
  5710. } else {
  5711. dest = [null, {
  5712. name: zoomArg
  5713. }, zoomArgs[1] | 0, zoomArgs[2] | 0, zoomArgs[3] | 0, zoomArgs[4] | 0];
  5714. }
  5715. } else {
  5716. console.error(`PDFLinkService.setHash: "${zoomArg}" is not ` + "a valid zoom value.");
  5717. }
  5718. }
  5719. }
  5720. if (dest) {
  5721. this.pdfViewer.scrollPageIntoView({
  5722. pageNumber: pageNumber || this.page,
  5723. destArray: dest,
  5724. allowNegativeOffset: true
  5725. });
  5726. } else if (pageNumber) {
  5727. this.page = pageNumber;
  5728. }
  5729. if ("pagemode" in params) {
  5730. this.eventBus.dispatch("pagemode", {
  5731. source: this,
  5732. mode: params.pagemode
  5733. });
  5734. }
  5735. if ("nameddest" in params) {
  5736. this.goToDestination(params.nameddest);
  5737. }
  5738. } else {
  5739. dest = unescape(hash);
  5740. try {
  5741. dest = JSON.parse(dest);
  5742. if (!Array.isArray(dest)) {
  5743. dest = dest.toString();
  5744. }
  5745. } catch (ex) {}
  5746. if (typeof dest === "string" || isValidExplicitDestination(dest)) {
  5747. this.goToDestination(dest);
  5748. return;
  5749. }
  5750. console.error(`PDFLinkService.setHash: "${unescape(hash)}" is not ` + "a valid destination.");
  5751. }
  5752. }
  5753. executeNamedAction(action) {
  5754. switch (action) {
  5755. case "GoBack":
  5756. if (this.pdfHistory) {
  5757. this.pdfHistory.back();
  5758. }
  5759. break;
  5760. case "GoForward":
  5761. if (this.pdfHistory) {
  5762. this.pdfHistory.forward();
  5763. }
  5764. break;
  5765. case "NextPage":
  5766. this.pdfViewer.nextPage();
  5767. break;
  5768. case "PrevPage":
  5769. this.pdfViewer.previousPage();
  5770. break;
  5771. case "LastPage":
  5772. this.page = this.pagesCount;
  5773. break;
  5774. case "FirstPage":
  5775. this.page = 1;
  5776. break;
  5777. default:
  5778. break;
  5779. }
  5780. this.eventBus.dispatch("namedaction", {
  5781. source: this,
  5782. action
  5783. });
  5784. }
  5785. cachePageRef(pageNum, pageRef) {
  5786. if (!pageRef) {
  5787. return;
  5788. }
  5789. const refStr = pageRef.gen === 0 ? `${pageRef.num}R` : `${pageRef.num}R${pageRef.gen}`;
  5790. this._pagesRefCache[refStr] = pageNum;
  5791. }
  5792. _cachedPageNumber(pageRef) {
  5793. const refStr = pageRef.gen === 0 ? `${pageRef.num}R` : `${pageRef.num}R${pageRef.gen}`;
  5794. return this._pagesRefCache?.[refStr] || null;
  5795. }
  5796. isPageVisible(pageNumber) {
  5797. return this.pdfViewer.isPageVisible(pageNumber);
  5798. }
  5799. isPageCached(pageNumber) {
  5800. return this.pdfViewer.isPageCached(pageNumber);
  5801. }
  5802. }
  5803. exports.PDFLinkService = PDFLinkService;
  5804. function isValidExplicitDestination(dest) {
  5805. if (!Array.isArray(dest)) {
  5806. return false;
  5807. }
  5808. const destLength = dest.length;
  5809. if (destLength < 2) {
  5810. return false;
  5811. }
  5812. const page = dest[0];
  5813. if (!(typeof page === "object" && Number.isInteger(page.num) && Number.isInteger(page.gen)) && !(Number.isInteger(page) && page >= 0)) {
  5814. return false;
  5815. }
  5816. const zoom = dest[1];
  5817. if (!(typeof zoom === "object" && typeof zoom.name === "string")) {
  5818. return false;
  5819. }
  5820. let allowNull = true;
  5821. switch (zoom.name) {
  5822. case "XYZ":
  5823. if (destLength !== 5) {
  5824. return false;
  5825. }
  5826. break;
  5827. case "Fit":
  5828. case "FitB":
  5829. return destLength === 2;
  5830. case "FitH":
  5831. case "FitBH":
  5832. case "FitV":
  5833. case "FitBV":
  5834. if (destLength !== 3) {
  5835. return false;
  5836. }
  5837. break;
  5838. case "FitR":
  5839. if (destLength !== 6) {
  5840. return false;
  5841. }
  5842. allowNull = false;
  5843. break;
  5844. default:
  5845. return false;
  5846. }
  5847. for (let i = 2; i < destLength; i++) {
  5848. const param = dest[i];
  5849. if (!(typeof param === "number" || allowNull && param === null)) {
  5850. return false;
  5851. }
  5852. }
  5853. return true;
  5854. }
  5855. class SimpleLinkService {
  5856. constructor() {
  5857. this.externalLinkTarget = null;
  5858. this.externalLinkRel = null;
  5859. this.externalLinkEnabled = true;
  5860. this._ignoreDestinationZoom = false;
  5861. }
  5862. get pagesCount() {
  5863. return 0;
  5864. }
  5865. get page() {
  5866. return 0;
  5867. }
  5868. set page(value) {}
  5869. get rotation() {
  5870. return 0;
  5871. }
  5872. set rotation(value) {}
  5873. async goToDestination(dest) {}
  5874. goToPage(val) {}
  5875. getDestinationHash(dest) {
  5876. return "#";
  5877. }
  5878. getAnchorUrl(hash) {
  5879. return "#";
  5880. }
  5881. setHash(hash) {}
  5882. executeNamedAction(action) {}
  5883. cachePageRef(pageNum, pageRef) {}
  5884. isPageVisible(pageNumber) {
  5885. return true;
  5886. }
  5887. isPageCached(pageNumber) {
  5888. return true;
  5889. }
  5890. }
  5891. exports.SimpleLinkService = SimpleLinkService;
  5892. /***/ }),
  5893. /* 20 */
  5894. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  5895. Object.defineProperty(exports, "__esModule", ({
  5896. value: true
  5897. }));
  5898. exports.PDFOutlineViewer = void 0;
  5899. var _pdfjsLib = __webpack_require__(5);
  5900. var _base_tree_viewer = __webpack_require__(12);
  5901. var _ui_utils = __webpack_require__(4);
  5902. class PDFOutlineViewer extends _base_tree_viewer.BaseTreeViewer {
  5903. constructor(options) {
  5904. super(options);
  5905. this.linkService = options.linkService;
  5906. this.eventBus._on("toggleoutlinetree", this._toggleAllTreeItems.bind(this));
  5907. this.eventBus._on("currentoutlineitem", this._currentOutlineItem.bind(this));
  5908. this.eventBus._on("pagechanging", evt => {
  5909. this._currentPageNumber = evt.pageNumber;
  5910. });
  5911. this.eventBus._on("pagesloaded", evt => {
  5912. this._isPagesLoaded = !!evt.pagesCount;
  5913. });
  5914. this.eventBus._on("sidebarviewchanged", evt => {
  5915. this._sidebarView = evt.view;
  5916. });
  5917. }
  5918. reset() {
  5919. super.reset();
  5920. this._outline = null;
  5921. this._pageNumberToDestHashCapability = null;
  5922. this._currentPageNumber = 1;
  5923. this._isPagesLoaded = false;
  5924. }
  5925. _dispatchEvent(outlineCount) {
  5926. this.eventBus.dispatch("outlineloaded", {
  5927. source: this,
  5928. outlineCount,
  5929. enableCurrentOutlineItemButton: outlineCount > 0 && !this._pdfDocument?.loadingParams.disableAutoFetch
  5930. });
  5931. }
  5932. _bindLink(element, {
  5933. url,
  5934. newWindow,
  5935. dest
  5936. }) {
  5937. const {
  5938. linkService
  5939. } = this;
  5940. if (url) {
  5941. (0, _pdfjsLib.addLinkAttributes)(element, {
  5942. url,
  5943. target: newWindow ? _pdfjsLib.LinkTarget.BLANK : linkService.externalLinkTarget,
  5944. rel: linkService.externalLinkRel,
  5945. enabled: linkService.externalLinkEnabled
  5946. });
  5947. return;
  5948. }
  5949. element.href = linkService.getDestinationHash(dest);
  5950. element.onclick = evt => {
  5951. this._updateCurrentTreeItem(evt.target.parentNode);
  5952. if (dest) {
  5953. linkService.goToDestination(dest);
  5954. }
  5955. return false;
  5956. };
  5957. }
  5958. _setStyles(element, {
  5959. bold,
  5960. italic
  5961. }) {
  5962. if (bold) {
  5963. element.style.fontWeight = "bold";
  5964. }
  5965. if (italic) {
  5966. element.style.fontStyle = "italic";
  5967. }
  5968. }
  5969. _addToggleButton(div, {
  5970. count,
  5971. items
  5972. }) {
  5973. let hidden = false;
  5974. if (count < 0) {
  5975. let totalCount = items.length;
  5976. if (totalCount > 0) {
  5977. const queue = [...items];
  5978. while (queue.length > 0) {
  5979. const {
  5980. count: nestedCount,
  5981. items: nestedItems
  5982. } = queue.shift();
  5983. if (nestedCount > 0 && nestedItems.length > 0) {
  5984. totalCount += nestedItems.length;
  5985. queue.push(...nestedItems);
  5986. }
  5987. }
  5988. }
  5989. if (Math.abs(count) === totalCount) {
  5990. hidden = true;
  5991. }
  5992. }
  5993. super._addToggleButton(div, hidden);
  5994. }
  5995. _toggleAllTreeItems() {
  5996. if (!this._outline) {
  5997. return;
  5998. }
  5999. super._toggleAllTreeItems();
  6000. }
  6001. render({
  6002. outline,
  6003. pdfDocument
  6004. }) {
  6005. if (this._outline) {
  6006. this.reset();
  6007. }
  6008. this._outline = outline || null;
  6009. this._pdfDocument = pdfDocument || null;
  6010. if (!outline) {
  6011. this._dispatchEvent(0);
  6012. return;
  6013. }
  6014. const fragment = document.createDocumentFragment();
  6015. const queue = [{
  6016. parent: fragment,
  6017. items: outline
  6018. }];
  6019. let outlineCount = 0,
  6020. hasAnyNesting = false;
  6021. while (queue.length > 0) {
  6022. const levelData = queue.shift();
  6023. for (const item of levelData.items) {
  6024. const div = document.createElement("div");
  6025. div.className = "treeItem";
  6026. const element = document.createElement("a");
  6027. this._bindLink(element, item);
  6028. this._setStyles(element, item);
  6029. element.textContent = this._normalizeTextContent(item.title);
  6030. div.appendChild(element);
  6031. if (item.items.length > 0) {
  6032. hasAnyNesting = true;
  6033. this._addToggleButton(div, item);
  6034. const itemsDiv = document.createElement("div");
  6035. itemsDiv.className = "treeItems";
  6036. div.appendChild(itemsDiv);
  6037. queue.push({
  6038. parent: itemsDiv,
  6039. items: item.items
  6040. });
  6041. }
  6042. levelData.parent.appendChild(div);
  6043. outlineCount++;
  6044. }
  6045. }
  6046. this._finishRendering(fragment, outlineCount, hasAnyNesting);
  6047. }
  6048. async _currentOutlineItem() {
  6049. if (!this._isPagesLoaded) {
  6050. throw new Error("_currentOutlineItem: All pages have not been loaded.");
  6051. }
  6052. if (!this._outline || !this._pdfDocument) {
  6053. return;
  6054. }
  6055. const pageNumberToDestHash = await this._getPageNumberToDestHash(this._pdfDocument);
  6056. if (!pageNumberToDestHash) {
  6057. return;
  6058. }
  6059. this._updateCurrentTreeItem(null);
  6060. if (this._sidebarView !== _ui_utils.SidebarView.OUTLINE) {
  6061. return;
  6062. }
  6063. for (let i = this._currentPageNumber; i > 0; i--) {
  6064. const destHash = pageNumberToDestHash.get(i);
  6065. if (!destHash) {
  6066. continue;
  6067. }
  6068. const linkElement = this.container.querySelector(`a[href="${destHash}"]`);
  6069. if (!linkElement) {
  6070. continue;
  6071. }
  6072. this._scrollToCurrentTreeItem(linkElement.parentNode);
  6073. break;
  6074. }
  6075. }
  6076. async _getPageNumberToDestHash(pdfDocument) {
  6077. if (this._pageNumberToDestHashCapability) {
  6078. return this._pageNumberToDestHashCapability.promise;
  6079. }
  6080. this._pageNumberToDestHashCapability = (0, _pdfjsLib.createPromiseCapability)();
  6081. const pageNumberToDestHash = new Map(),
  6082. pageNumberNesting = new Map();
  6083. const queue = [{
  6084. nesting: 0,
  6085. items: this._outline
  6086. }];
  6087. while (queue.length > 0) {
  6088. const levelData = queue.shift(),
  6089. currentNesting = levelData.nesting;
  6090. for (const {
  6091. dest,
  6092. items
  6093. } of levelData.items) {
  6094. let explicitDest, pageNumber;
  6095. if (typeof dest === "string") {
  6096. explicitDest = await pdfDocument.getDestination(dest);
  6097. if (pdfDocument !== this._pdfDocument) {
  6098. return null;
  6099. }
  6100. } else {
  6101. explicitDest = dest;
  6102. }
  6103. if (Array.isArray(explicitDest)) {
  6104. const [destRef] = explicitDest;
  6105. if (destRef instanceof Object) {
  6106. pageNumber = this.linkService._cachedPageNumber(destRef);
  6107. if (!pageNumber) {
  6108. try {
  6109. pageNumber = (await pdfDocument.getPageIndex(destRef)) + 1;
  6110. if (pdfDocument !== this._pdfDocument) {
  6111. return null;
  6112. }
  6113. this.linkService.cachePageRef(pageNumber, destRef);
  6114. } catch (ex) {}
  6115. }
  6116. } else if (Number.isInteger(destRef)) {
  6117. pageNumber = destRef + 1;
  6118. }
  6119. if (Number.isInteger(pageNumber) && (!pageNumberToDestHash.has(pageNumber) || currentNesting > pageNumberNesting.get(pageNumber))) {
  6120. const destHash = this.linkService.getDestinationHash(dest);
  6121. pageNumberToDestHash.set(pageNumber, destHash);
  6122. pageNumberNesting.set(pageNumber, currentNesting);
  6123. }
  6124. }
  6125. if (items.length > 0) {
  6126. queue.push({
  6127. nesting: currentNesting + 1,
  6128. items
  6129. });
  6130. }
  6131. }
  6132. }
  6133. this._pageNumberToDestHashCapability.resolve(pageNumberToDestHash.size > 0 ? pageNumberToDestHash : null);
  6134. return this._pageNumberToDestHashCapability.promise;
  6135. }
  6136. }
  6137. exports.PDFOutlineViewer = PDFOutlineViewer;
  6138. /***/ }),
  6139. /* 21 */
  6140. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6141. Object.defineProperty(exports, "__esModule", ({
  6142. value: true
  6143. }));
  6144. exports.PDFPresentationMode = void 0;
  6145. var _ui_utils = __webpack_require__(4);
  6146. const DELAY_BEFORE_RESETTING_SWITCH_IN_PROGRESS = 1500;
  6147. const DELAY_BEFORE_HIDING_CONTROLS = 3000;
  6148. const ACTIVE_SELECTOR = "pdfPresentationMode";
  6149. const CONTROLS_SELECTOR = "pdfPresentationModeControls";
  6150. const MOUSE_SCROLL_COOLDOWN_TIME = 50;
  6151. const PAGE_SWITCH_THRESHOLD = 0.1;
  6152. const SWIPE_MIN_DISTANCE_THRESHOLD = 50;
  6153. const SWIPE_ANGLE_THRESHOLD = Math.PI / 6;
  6154. class PDFPresentationMode {
  6155. constructor({
  6156. container,
  6157. pdfViewer,
  6158. eventBus
  6159. }) {
  6160. this.container = container;
  6161. this.pdfViewer = pdfViewer;
  6162. this.eventBus = eventBus;
  6163. this.active = false;
  6164. this.args = null;
  6165. this.contextMenuOpen = false;
  6166. this.mouseScrollTimeStamp = 0;
  6167. this.mouseScrollDelta = 0;
  6168. this.touchSwipeState = null;
  6169. }
  6170. request() {
  6171. if (this.switchInProgress || this.active || !this.pdfViewer.pagesCount) {
  6172. return false;
  6173. }
  6174. this._addFullscreenChangeListeners();
  6175. this._setSwitchInProgress();
  6176. this._notifyStateChange();
  6177. if (this.container.requestFullscreen) {
  6178. this.container.requestFullscreen();
  6179. } else if (this.container.mozRequestFullScreen) {
  6180. this.container.mozRequestFullScreen();
  6181. } else if (this.container.webkitRequestFullscreen) {
  6182. this.container.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
  6183. } else {
  6184. return false;
  6185. }
  6186. this.args = {
  6187. page: this.pdfViewer.currentPageNumber,
  6188. previousScale: this.pdfViewer.currentScaleValue
  6189. };
  6190. return true;
  6191. }
  6192. _mouseWheel(evt) {
  6193. if (!this.active) {
  6194. return;
  6195. }
  6196. evt.preventDefault();
  6197. const delta = (0, _ui_utils.normalizeWheelEventDelta)(evt);
  6198. const currentTime = Date.now();
  6199. const storedTime = this.mouseScrollTimeStamp;
  6200. if (currentTime > storedTime && currentTime - storedTime < MOUSE_SCROLL_COOLDOWN_TIME) {
  6201. return;
  6202. }
  6203. if (this.mouseScrollDelta > 0 && delta < 0 || this.mouseScrollDelta < 0 && delta > 0) {
  6204. this._resetMouseScrollState();
  6205. }
  6206. this.mouseScrollDelta += delta;
  6207. if (Math.abs(this.mouseScrollDelta) >= PAGE_SWITCH_THRESHOLD) {
  6208. const totalDelta = this.mouseScrollDelta;
  6209. this._resetMouseScrollState();
  6210. const success = totalDelta > 0 ? this.pdfViewer.previousPage() : this.pdfViewer.nextPage();
  6211. if (success) {
  6212. this.mouseScrollTimeStamp = currentTime;
  6213. }
  6214. }
  6215. }
  6216. get isFullscreen() {
  6217. return !!(document.fullscreenElement || document.mozFullScreen || document.webkitIsFullScreen);
  6218. }
  6219. _notifyStateChange() {
  6220. let state = _ui_utils.PresentationModeState.NORMAL;
  6221. if (this.switchInProgress) {
  6222. state = _ui_utils.PresentationModeState.CHANGING;
  6223. } else if (this.active) {
  6224. state = _ui_utils.PresentationModeState.FULLSCREEN;
  6225. }
  6226. this.eventBus.dispatch("presentationmodechanged", {
  6227. source: this,
  6228. state,
  6229. get active() {
  6230. throw new Error("Deprecated parameter: `active`, please use `state` instead.");
  6231. },
  6232. get switchInProgress() {
  6233. throw new Error("Deprecated parameter: `switchInProgress`, please use `state` instead.");
  6234. }
  6235. });
  6236. }
  6237. _setSwitchInProgress() {
  6238. if (this.switchInProgress) {
  6239. clearTimeout(this.switchInProgress);
  6240. }
  6241. this.switchInProgress = setTimeout(() => {
  6242. this._removeFullscreenChangeListeners();
  6243. delete this.switchInProgress;
  6244. this._notifyStateChange();
  6245. }, DELAY_BEFORE_RESETTING_SWITCH_IN_PROGRESS);
  6246. }
  6247. _resetSwitchInProgress() {
  6248. if (this.switchInProgress) {
  6249. clearTimeout(this.switchInProgress);
  6250. delete this.switchInProgress;
  6251. }
  6252. }
  6253. _enter() {
  6254. this.active = true;
  6255. this._resetSwitchInProgress();
  6256. this._notifyStateChange();
  6257. this.container.classList.add(ACTIVE_SELECTOR);
  6258. setTimeout(() => {
  6259. this.pdfViewer.currentPageNumber = this.args.page;
  6260. this.pdfViewer.currentScaleValue = "page-fit";
  6261. }, 0);
  6262. this._addWindowListeners();
  6263. this._showControls();
  6264. this.contextMenuOpen = false;
  6265. window.getSelection().removeAllRanges();
  6266. }
  6267. _exit() {
  6268. const page = this.pdfViewer.currentPageNumber;
  6269. this.container.classList.remove(ACTIVE_SELECTOR);
  6270. setTimeout(() => {
  6271. this.active = false;
  6272. this._removeFullscreenChangeListeners();
  6273. this._notifyStateChange();
  6274. this.pdfViewer.currentScaleValue = this.args.previousScale;
  6275. this.pdfViewer.currentPageNumber = page;
  6276. this.args = null;
  6277. }, 0);
  6278. this._removeWindowListeners();
  6279. this._hideControls();
  6280. this._resetMouseScrollState();
  6281. this.contextMenuOpen = false;
  6282. }
  6283. _mouseDown(evt) {
  6284. if (this.contextMenuOpen) {
  6285. this.contextMenuOpen = false;
  6286. evt.preventDefault();
  6287. return;
  6288. }
  6289. if (evt.button === 0) {
  6290. const isInternalLink = evt.target.href && evt.target.classList.contains("internalLink");
  6291. if (!isInternalLink) {
  6292. evt.preventDefault();
  6293. if (evt.shiftKey) {
  6294. this.pdfViewer.previousPage();
  6295. } else {
  6296. this.pdfViewer.nextPage();
  6297. }
  6298. }
  6299. }
  6300. }
  6301. _contextMenu() {
  6302. this.contextMenuOpen = true;
  6303. }
  6304. _showControls() {
  6305. if (this.controlsTimeout) {
  6306. clearTimeout(this.controlsTimeout);
  6307. } else {
  6308. this.container.classList.add(CONTROLS_SELECTOR);
  6309. }
  6310. this.controlsTimeout = setTimeout(() => {
  6311. this.container.classList.remove(CONTROLS_SELECTOR);
  6312. delete this.controlsTimeout;
  6313. }, DELAY_BEFORE_HIDING_CONTROLS);
  6314. }
  6315. _hideControls() {
  6316. if (!this.controlsTimeout) {
  6317. return;
  6318. }
  6319. clearTimeout(this.controlsTimeout);
  6320. this.container.classList.remove(CONTROLS_SELECTOR);
  6321. delete this.controlsTimeout;
  6322. }
  6323. _resetMouseScrollState() {
  6324. this.mouseScrollTimeStamp = 0;
  6325. this.mouseScrollDelta = 0;
  6326. }
  6327. _touchSwipe(evt) {
  6328. if (!this.active) {
  6329. return;
  6330. }
  6331. if (evt.touches.length > 1) {
  6332. this.touchSwipeState = null;
  6333. return;
  6334. }
  6335. switch (evt.type) {
  6336. case "touchstart":
  6337. this.touchSwipeState = {
  6338. startX: evt.touches[0].pageX,
  6339. startY: evt.touches[0].pageY,
  6340. endX: evt.touches[0].pageX,
  6341. endY: evt.touches[0].pageY
  6342. };
  6343. break;
  6344. case "touchmove":
  6345. if (this.touchSwipeState === null) {
  6346. return;
  6347. }
  6348. this.touchSwipeState.endX = evt.touches[0].pageX;
  6349. this.touchSwipeState.endY = evt.touches[0].pageY;
  6350. evt.preventDefault();
  6351. break;
  6352. case "touchend":
  6353. if (this.touchSwipeState === null) {
  6354. return;
  6355. }
  6356. let delta = 0;
  6357. const dx = this.touchSwipeState.endX - this.touchSwipeState.startX;
  6358. const dy = this.touchSwipeState.endY - this.touchSwipeState.startY;
  6359. const absAngle = Math.abs(Math.atan2(dy, dx));
  6360. if (Math.abs(dx) > SWIPE_MIN_DISTANCE_THRESHOLD && (absAngle <= SWIPE_ANGLE_THRESHOLD || absAngle >= Math.PI - SWIPE_ANGLE_THRESHOLD)) {
  6361. delta = dx;
  6362. } else if (Math.abs(dy) > SWIPE_MIN_DISTANCE_THRESHOLD && Math.abs(absAngle - Math.PI / 2) <= SWIPE_ANGLE_THRESHOLD) {
  6363. delta = dy;
  6364. }
  6365. if (delta > 0) {
  6366. this.pdfViewer.previousPage();
  6367. } else if (delta < 0) {
  6368. this.pdfViewer.nextPage();
  6369. }
  6370. break;
  6371. }
  6372. }
  6373. _addWindowListeners() {
  6374. this.showControlsBind = this._showControls.bind(this);
  6375. this.mouseDownBind = this._mouseDown.bind(this);
  6376. this.mouseWheelBind = this._mouseWheel.bind(this);
  6377. this.resetMouseScrollStateBind = this._resetMouseScrollState.bind(this);
  6378. this.contextMenuBind = this._contextMenu.bind(this);
  6379. this.touchSwipeBind = this._touchSwipe.bind(this);
  6380. window.addEventListener("mousemove", this.showControlsBind);
  6381. window.addEventListener("mousedown", this.mouseDownBind);
  6382. window.addEventListener("wheel", this.mouseWheelBind, {
  6383. passive: false
  6384. });
  6385. window.addEventListener("keydown", this.resetMouseScrollStateBind);
  6386. window.addEventListener("contextmenu", this.contextMenuBind);
  6387. window.addEventListener("touchstart", this.touchSwipeBind);
  6388. window.addEventListener("touchmove", this.touchSwipeBind);
  6389. window.addEventListener("touchend", this.touchSwipeBind);
  6390. }
  6391. _removeWindowListeners() {
  6392. window.removeEventListener("mousemove", this.showControlsBind);
  6393. window.removeEventListener("mousedown", this.mouseDownBind);
  6394. window.removeEventListener("wheel", this.mouseWheelBind, {
  6395. passive: false
  6396. });
  6397. window.removeEventListener("keydown", this.resetMouseScrollStateBind);
  6398. window.removeEventListener("contextmenu", this.contextMenuBind);
  6399. window.removeEventListener("touchstart", this.touchSwipeBind);
  6400. window.removeEventListener("touchmove", this.touchSwipeBind);
  6401. window.removeEventListener("touchend", this.touchSwipeBind);
  6402. delete this.showControlsBind;
  6403. delete this.mouseDownBind;
  6404. delete this.mouseWheelBind;
  6405. delete this.resetMouseScrollStateBind;
  6406. delete this.contextMenuBind;
  6407. delete this.touchSwipeBind;
  6408. }
  6409. _fullscreenChange() {
  6410. if (this.isFullscreen) {
  6411. this._enter();
  6412. } else {
  6413. this._exit();
  6414. }
  6415. }
  6416. _addFullscreenChangeListeners() {
  6417. this.fullscreenChangeBind = this._fullscreenChange.bind(this);
  6418. window.addEventListener("fullscreenchange", this.fullscreenChangeBind);
  6419. window.addEventListener("mozfullscreenchange", this.fullscreenChangeBind);
  6420. window.addEventListener("webkitfullscreenchange", this.fullscreenChangeBind);
  6421. }
  6422. _removeFullscreenChangeListeners() {
  6423. window.removeEventListener("fullscreenchange", this.fullscreenChangeBind);
  6424. window.removeEventListener("mozfullscreenchange", this.fullscreenChangeBind);
  6425. window.removeEventListener("webkitfullscreenchange", this.fullscreenChangeBind);
  6426. delete this.fullscreenChangeBind;
  6427. }
  6428. }
  6429. exports.PDFPresentationMode = PDFPresentationMode;
  6430. /***/ }),
  6431. /* 22 */
  6432. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6433. Object.defineProperty(exports, "__esModule", ({
  6434. value: true
  6435. }));
  6436. exports.PDFScriptingManager = void 0;
  6437. var _pdfjsLib = __webpack_require__(5);
  6438. var _ui_utils = __webpack_require__(4);
  6439. var _pdf_rendering_queue = __webpack_require__(8);
  6440. class PDFScriptingManager {
  6441. constructor({
  6442. eventBus,
  6443. sandboxBundleSrc = null,
  6444. scriptingFactory = null,
  6445. docPropertiesLookup = null
  6446. }) {
  6447. this._pdfDocument = null;
  6448. this._pdfViewer = null;
  6449. this._closeCapability = null;
  6450. this._destroyCapability = null;
  6451. this._scripting = null;
  6452. this._mouseState = Object.create(null);
  6453. this._pageEventsReady = false;
  6454. this._ready = false;
  6455. this._eventBus = eventBus;
  6456. this._sandboxBundleSrc = sandboxBundleSrc;
  6457. this._scriptingFactory = scriptingFactory;
  6458. this._docPropertiesLookup = docPropertiesLookup;
  6459. }
  6460. setViewer(pdfViewer) {
  6461. this._pdfViewer = pdfViewer;
  6462. }
  6463. async setDocument(pdfDocument) {
  6464. if (this._pdfDocument) {
  6465. await this._destroyScripting();
  6466. }
  6467. this._pdfDocument = pdfDocument;
  6468. if (!pdfDocument) {
  6469. return;
  6470. }
  6471. const [objects, calculationOrder, docActions] = await Promise.all([pdfDocument.getFieldObjects(), pdfDocument.getCalculationOrderIds(), pdfDocument.getJSActions()]);
  6472. if (!objects && !docActions) {
  6473. await this._destroyScripting();
  6474. return;
  6475. }
  6476. if (pdfDocument !== this._pdfDocument) {
  6477. return;
  6478. }
  6479. this._scripting = this._createScripting();
  6480. this._internalEvents.set("updatefromsandbox", event => {
  6481. if (event?.source !== window) {
  6482. return;
  6483. }
  6484. this._updateFromSandbox(event.detail);
  6485. });
  6486. this._internalEvents.set("dispatcheventinsandbox", event => {
  6487. this._scripting?.dispatchEventInSandbox(event.detail);
  6488. });
  6489. this._internalEvents.set("pagechanging", ({
  6490. pageNumber,
  6491. previous
  6492. }) => {
  6493. if (pageNumber === previous) {
  6494. return;
  6495. }
  6496. this._dispatchPageClose(previous);
  6497. this._dispatchPageOpen(pageNumber);
  6498. });
  6499. this._internalEvents.set("pagerendered", ({
  6500. pageNumber
  6501. }) => {
  6502. if (!this._pageOpenPending.has(pageNumber)) {
  6503. return;
  6504. }
  6505. if (pageNumber !== this._pdfViewer.currentPageNumber) {
  6506. return;
  6507. }
  6508. this._dispatchPageOpen(pageNumber);
  6509. });
  6510. this._internalEvents.set("pagesdestroy", async event => {
  6511. await this._dispatchPageClose(this._pdfViewer.currentPageNumber);
  6512. await this._scripting?.dispatchEventInSandbox({
  6513. id: "doc",
  6514. name: "WillClose"
  6515. });
  6516. this._closeCapability?.resolve();
  6517. });
  6518. this._domEvents.set("mousedown", event => {
  6519. this._mouseState.isDown = true;
  6520. });
  6521. this._domEvents.set("mouseup", event => {
  6522. this._mouseState.isDown = false;
  6523. });
  6524. for (const [name, listener] of this._internalEvents) {
  6525. this._eventBus._on(name, listener);
  6526. }
  6527. for (const [name, listener] of this._domEvents) {
  6528. window.addEventListener(name, listener);
  6529. }
  6530. try {
  6531. const docProperties = await this._getDocProperties();
  6532. if (pdfDocument !== this._pdfDocument) {
  6533. return;
  6534. }
  6535. await this._scripting.createSandbox({
  6536. objects,
  6537. calculationOrder,
  6538. appInfo: {
  6539. platform: navigator.platform,
  6540. language: navigator.language
  6541. },
  6542. docInfo: { ...docProperties,
  6543. actions: docActions
  6544. }
  6545. });
  6546. this._eventBus.dispatch("sandboxcreated", {
  6547. source: this
  6548. });
  6549. } catch (error) {
  6550. console.error(`PDFScriptingManager.setDocument: "${error?.message}".`);
  6551. await this._destroyScripting();
  6552. return;
  6553. }
  6554. await this._scripting?.dispatchEventInSandbox({
  6555. id: "doc",
  6556. name: "Open"
  6557. });
  6558. await this._dispatchPageOpen(this._pdfViewer.currentPageNumber, true);
  6559. Promise.resolve().then(() => {
  6560. if (pdfDocument === this._pdfDocument) {
  6561. this._ready = true;
  6562. }
  6563. });
  6564. }
  6565. async dispatchWillSave(detail) {
  6566. return this._scripting?.dispatchEventInSandbox({
  6567. id: "doc",
  6568. name: "WillSave"
  6569. });
  6570. }
  6571. async dispatchDidSave(detail) {
  6572. return this._scripting?.dispatchEventInSandbox({
  6573. id: "doc",
  6574. name: "DidSave"
  6575. });
  6576. }
  6577. async dispatchWillPrint(detail) {
  6578. return this._scripting?.dispatchEventInSandbox({
  6579. id: "doc",
  6580. name: "WillPrint"
  6581. });
  6582. }
  6583. async dispatchDidPrint(detail) {
  6584. return this._scripting?.dispatchEventInSandbox({
  6585. id: "doc",
  6586. name: "DidPrint"
  6587. });
  6588. }
  6589. get mouseState() {
  6590. return this._mouseState;
  6591. }
  6592. get destroyPromise() {
  6593. return this._destroyCapability?.promise || null;
  6594. }
  6595. get ready() {
  6596. return this._ready;
  6597. }
  6598. get _internalEvents() {
  6599. return (0, _pdfjsLib.shadow)(this, "_internalEvents", new Map());
  6600. }
  6601. get _domEvents() {
  6602. return (0, _pdfjsLib.shadow)(this, "_domEvents", new Map());
  6603. }
  6604. get _pageOpenPending() {
  6605. return (0, _pdfjsLib.shadow)(this, "_pageOpenPending", new Set());
  6606. }
  6607. get _visitedPages() {
  6608. return (0, _pdfjsLib.shadow)(this, "_visitedPages", new Map());
  6609. }
  6610. async _updateFromSandbox(detail) {
  6611. const isInPresentationMode = this._pdfViewer.isInPresentationMode || this._pdfViewer.isChangingPresentationMode;
  6612. const {
  6613. id,
  6614. command,
  6615. value
  6616. } = detail;
  6617. if (!id) {
  6618. switch (command) {
  6619. case "clear":
  6620. console.clear();
  6621. break;
  6622. case "error":
  6623. console.error(value);
  6624. break;
  6625. case "layout":
  6626. this._pdfViewer.spreadMode = (0, _ui_utils.apiPageLayoutToSpreadMode)(value);
  6627. break;
  6628. case "page-num":
  6629. this._pdfViewer.currentPageNumber = value + 1;
  6630. break;
  6631. case "print":
  6632. await this._pdfViewer.pagesPromise;
  6633. this._eventBus.dispatch("print", {
  6634. source: this
  6635. });
  6636. break;
  6637. case "println":
  6638. console.log(value);
  6639. break;
  6640. case "zoom":
  6641. if (isInPresentationMode) {
  6642. return;
  6643. }
  6644. this._pdfViewer.currentScaleValue = value;
  6645. break;
  6646. }
  6647. return;
  6648. }
  6649. if (isInPresentationMode) {
  6650. if (detail.focus) {
  6651. return;
  6652. }
  6653. }
  6654. const element = document.getElementById(id);
  6655. if (element) {
  6656. element.dispatchEvent(new CustomEvent("updatefromsandbox", {
  6657. detail
  6658. }));
  6659. } else {
  6660. delete detail.id;
  6661. this._pdfDocument?.annotationStorage.setValue(id, detail);
  6662. }
  6663. }
  6664. async _dispatchPageOpen(pageNumber, initialize = false) {
  6665. const pdfDocument = this._pdfDocument,
  6666. visitedPages = this._visitedPages;
  6667. if (initialize) {
  6668. this._closeCapability = (0, _pdfjsLib.createPromiseCapability)();
  6669. this._pageEventsReady = true;
  6670. }
  6671. if (!this._pageEventsReady) {
  6672. return;
  6673. }
  6674. const pageView = this._pdfViewer.getPageView(pageNumber - 1);
  6675. if (pageView?.renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED) {
  6676. this._pageOpenPending.add(pageNumber);
  6677. return;
  6678. }
  6679. this._pageOpenPending.delete(pageNumber);
  6680. const actionsPromise = (async () => {
  6681. const actions = await (!visitedPages.has(pageNumber) ? pageView.pdfPage?.getJSActions() : null);
  6682. if (pdfDocument !== this._pdfDocument) {
  6683. return;
  6684. }
  6685. await this._scripting?.dispatchEventInSandbox({
  6686. id: "page",
  6687. name: "PageOpen",
  6688. pageNumber,
  6689. actions
  6690. });
  6691. })();
  6692. visitedPages.set(pageNumber, actionsPromise);
  6693. }
  6694. async _dispatchPageClose(pageNumber) {
  6695. const pdfDocument = this._pdfDocument,
  6696. visitedPages = this._visitedPages;
  6697. if (!this._pageEventsReady) {
  6698. return;
  6699. }
  6700. if (this._pageOpenPending.has(pageNumber)) {
  6701. return;
  6702. }
  6703. const actionsPromise = visitedPages.get(pageNumber);
  6704. if (!actionsPromise) {
  6705. return;
  6706. }
  6707. visitedPages.set(pageNumber, null);
  6708. await actionsPromise;
  6709. if (pdfDocument !== this._pdfDocument) {
  6710. return;
  6711. }
  6712. await this._scripting?.dispatchEventInSandbox({
  6713. id: "page",
  6714. name: "PageClose",
  6715. pageNumber
  6716. });
  6717. }
  6718. async _getDocProperties() {
  6719. if (this._docPropertiesLookup) {
  6720. return this._docPropertiesLookup(this._pdfDocument);
  6721. }
  6722. throw new Error("_getDocProperties: Unable to lookup properties.");
  6723. }
  6724. _createScripting() {
  6725. this._destroyCapability = (0, _pdfjsLib.createPromiseCapability)();
  6726. if (this._scripting) {
  6727. throw new Error("_createScripting: Scripting already exists.");
  6728. }
  6729. if (this._scriptingFactory) {
  6730. return this._scriptingFactory.createScripting({
  6731. sandboxBundleSrc: this._sandboxBundleSrc
  6732. });
  6733. }
  6734. throw new Error("_createScripting: Cannot create scripting.");
  6735. }
  6736. async _destroyScripting() {
  6737. if (!this._scripting) {
  6738. this._pdfDocument = null;
  6739. this._destroyCapability?.resolve();
  6740. return;
  6741. }
  6742. if (this._closeCapability) {
  6743. await Promise.race([this._closeCapability.promise, new Promise(resolve => {
  6744. setTimeout(resolve, 1000);
  6745. })]).catch(reason => {});
  6746. this._closeCapability = null;
  6747. }
  6748. this._pdfDocument = null;
  6749. try {
  6750. await this._scripting.destroySandbox();
  6751. } catch (ex) {}
  6752. for (const [name, listener] of this._internalEvents) {
  6753. this._eventBus._off(name, listener);
  6754. }
  6755. this._internalEvents.clear();
  6756. for (const [name, listener] of this._domEvents) {
  6757. window.removeEventListener(name, listener);
  6758. }
  6759. this._domEvents.clear();
  6760. this._pageOpenPending.clear();
  6761. this._visitedPages.clear();
  6762. this._scripting = null;
  6763. delete this._mouseState.isDown;
  6764. this._pageEventsReady = false;
  6765. this._ready = false;
  6766. this._destroyCapability?.resolve();
  6767. }
  6768. }
  6769. exports.PDFScriptingManager = PDFScriptingManager;
  6770. /***/ }),
  6771. /* 23 */
  6772. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6773. Object.defineProperty(exports, "__esModule", ({
  6774. value: true
  6775. }));
  6776. exports.PDFSidebar = void 0;
  6777. var _ui_utils = __webpack_require__(4);
  6778. var _pdf_rendering_queue = __webpack_require__(8);
  6779. const UI_NOTIFICATION_CLASS = "pdfSidebarNotification";
  6780. class PDFSidebar {
  6781. constructor({
  6782. elements,
  6783. pdfViewer,
  6784. pdfThumbnailViewer,
  6785. eventBus,
  6786. l10n
  6787. }) {
  6788. this.isOpen = false;
  6789. this.active = _ui_utils.SidebarView.THUMBS;
  6790. this.isInitialViewSet = false;
  6791. this.onToggled = null;
  6792. this.pdfViewer = pdfViewer;
  6793. this.pdfThumbnailViewer = pdfThumbnailViewer;
  6794. this.outerContainer = elements.outerContainer;
  6795. this.viewerContainer = elements.viewerContainer;
  6796. this.toggleButton = elements.toggleButton;
  6797. this.thumbnailButton = elements.thumbnailButton;
  6798. this.outlineButton = elements.outlineButton;
  6799. this.attachmentsButton = elements.attachmentsButton;
  6800. this.layersButton = elements.layersButton;
  6801. this.thumbnailView = elements.thumbnailView;
  6802. this.outlineView = elements.outlineView;
  6803. this.attachmentsView = elements.attachmentsView;
  6804. this.layersView = elements.layersView;
  6805. this._outlineOptionsContainer = elements.outlineOptionsContainer;
  6806. this._currentOutlineItemButton = elements.currentOutlineItemButton;
  6807. this.eventBus = eventBus;
  6808. this.l10n = l10n;
  6809. this._addEventListeners();
  6810. }
  6811. reset() {
  6812. this.isInitialViewSet = false;
  6813. this._hideUINotification(true);
  6814. this.switchView(_ui_utils.SidebarView.THUMBS);
  6815. this.outlineButton.disabled = false;
  6816. this.attachmentsButton.disabled = false;
  6817. this.layersButton.disabled = false;
  6818. this._currentOutlineItemButton.disabled = true;
  6819. }
  6820. get visibleView() {
  6821. return this.isOpen ? this.active : _ui_utils.SidebarView.NONE;
  6822. }
  6823. get isThumbnailViewVisible() {
  6824. return this.isOpen && this.active === _ui_utils.SidebarView.THUMBS;
  6825. }
  6826. get isOutlineViewVisible() {
  6827. return this.isOpen && this.active === _ui_utils.SidebarView.OUTLINE;
  6828. }
  6829. get isAttachmentsViewVisible() {
  6830. return this.isOpen && this.active === _ui_utils.SidebarView.ATTACHMENTS;
  6831. }
  6832. get isLayersViewVisible() {
  6833. return this.isOpen && this.active === _ui_utils.SidebarView.LAYERS;
  6834. }
  6835. setInitialView(view = _ui_utils.SidebarView.NONE) {
  6836. if (this.isInitialViewSet) {
  6837. return;
  6838. }
  6839. this.isInitialViewSet = true;
  6840. if (view === _ui_utils.SidebarView.NONE || view === _ui_utils.SidebarView.UNKNOWN) {
  6841. this._dispatchEvent();
  6842. return;
  6843. }
  6844. if (!this._switchView(view, true)) {
  6845. this._dispatchEvent();
  6846. }
  6847. }
  6848. switchView(view, forceOpen = false) {
  6849. this._switchView(view, forceOpen);
  6850. }
  6851. _switchView(view, forceOpen = false) {
  6852. const isViewChanged = view !== this.active;
  6853. let shouldForceRendering = false;
  6854. switch (view) {
  6855. case _ui_utils.SidebarView.NONE:
  6856. if (this.isOpen) {
  6857. this.close();
  6858. return true;
  6859. }
  6860. return false;
  6861. case _ui_utils.SidebarView.THUMBS:
  6862. if (this.isOpen && isViewChanged) {
  6863. shouldForceRendering = true;
  6864. }
  6865. break;
  6866. case _ui_utils.SidebarView.OUTLINE:
  6867. if (this.outlineButton.disabled) {
  6868. return false;
  6869. }
  6870. break;
  6871. case _ui_utils.SidebarView.ATTACHMENTS:
  6872. if (this.attachmentsButton.disabled) {
  6873. return false;
  6874. }
  6875. break;
  6876. case _ui_utils.SidebarView.LAYERS:
  6877. if (this.layersButton.disabled) {
  6878. return false;
  6879. }
  6880. break;
  6881. default:
  6882. console.error(`PDFSidebar._switchView: "${view}" is not a valid view.`);
  6883. return false;
  6884. }
  6885. this.active = view;
  6886. this.thumbnailButton.classList.toggle("toggled", view === _ui_utils.SidebarView.THUMBS);
  6887. this.outlineButton.classList.toggle("toggled", view === _ui_utils.SidebarView.OUTLINE);
  6888. this.attachmentsButton.classList.toggle("toggled", view === _ui_utils.SidebarView.ATTACHMENTS);
  6889. this.layersButton.classList.toggle("toggled", view === _ui_utils.SidebarView.LAYERS);
  6890. this.thumbnailView.classList.toggle("hidden", view !== _ui_utils.SidebarView.THUMBS);
  6891. this.outlineView.classList.toggle("hidden", view !== _ui_utils.SidebarView.OUTLINE);
  6892. this.attachmentsView.classList.toggle("hidden", view !== _ui_utils.SidebarView.ATTACHMENTS);
  6893. this.layersView.classList.toggle("hidden", view !== _ui_utils.SidebarView.LAYERS);
  6894. this._outlineOptionsContainer.classList.toggle("hidden", view !== _ui_utils.SidebarView.OUTLINE);
  6895. if (forceOpen && !this.isOpen) {
  6896. this.open();
  6897. return true;
  6898. }
  6899. if (shouldForceRendering) {
  6900. this._updateThumbnailViewer();
  6901. this._forceRendering();
  6902. }
  6903. if (isViewChanged) {
  6904. this._dispatchEvent();
  6905. }
  6906. return isViewChanged;
  6907. }
  6908. open() {
  6909. if (this.isOpen) {
  6910. return;
  6911. }
  6912. this.isOpen = true;
  6913. this.toggleButton.classList.add("toggled");
  6914. this.toggleButton.setAttribute("aria-expanded", "true");
  6915. this.outerContainer.classList.add("sidebarMoving", "sidebarOpen");
  6916. if (this.active === _ui_utils.SidebarView.THUMBS) {
  6917. this._updateThumbnailViewer();
  6918. }
  6919. this._forceRendering();
  6920. this._dispatchEvent();
  6921. this._hideUINotification();
  6922. }
  6923. close() {
  6924. if (!this.isOpen) {
  6925. return;
  6926. }
  6927. this.isOpen = false;
  6928. this.toggleButton.classList.remove("toggled");
  6929. this.toggleButton.setAttribute("aria-expanded", "false");
  6930. this.outerContainer.classList.add("sidebarMoving");
  6931. this.outerContainer.classList.remove("sidebarOpen");
  6932. this._forceRendering();
  6933. this._dispatchEvent();
  6934. }
  6935. toggle() {
  6936. if (this.isOpen) {
  6937. this.close();
  6938. } else {
  6939. this.open();
  6940. }
  6941. }
  6942. _dispatchEvent() {
  6943. this.eventBus.dispatch("sidebarviewchanged", {
  6944. source: this,
  6945. view: this.visibleView
  6946. });
  6947. }
  6948. _forceRendering() {
  6949. if (this.onToggled) {
  6950. this.onToggled();
  6951. } else {
  6952. this.pdfViewer.forceRendering();
  6953. this.pdfThumbnailViewer.forceRendering();
  6954. }
  6955. }
  6956. _updateThumbnailViewer() {
  6957. const {
  6958. pdfViewer,
  6959. pdfThumbnailViewer
  6960. } = this;
  6961. const pagesCount = pdfViewer.pagesCount;
  6962. for (let pageIndex = 0; pageIndex < pagesCount; pageIndex++) {
  6963. const pageView = pdfViewer.getPageView(pageIndex);
  6964. if (pageView?.renderingState === _pdf_rendering_queue.RenderingStates.FINISHED) {
  6965. const thumbnailView = pdfThumbnailViewer.getThumbnail(pageIndex);
  6966. thumbnailView.setImage(pageView);
  6967. }
  6968. }
  6969. pdfThumbnailViewer.scrollThumbnailIntoView(pdfViewer.currentPageNumber);
  6970. }
  6971. _showUINotification() {
  6972. this.l10n.get("toggle_sidebar_notification2.title").then(msg => {
  6973. this.toggleButton.title = msg;
  6974. });
  6975. if (!this.isOpen) {
  6976. this.toggleButton.classList.add(UI_NOTIFICATION_CLASS);
  6977. }
  6978. }
  6979. _hideUINotification(reset = false) {
  6980. if (this.isOpen || reset) {
  6981. this.toggleButton.classList.remove(UI_NOTIFICATION_CLASS);
  6982. }
  6983. if (reset) {
  6984. this.l10n.get("toggle_sidebar.title").then(msg => {
  6985. this.toggleButton.title = msg;
  6986. });
  6987. }
  6988. }
  6989. _addEventListeners() {
  6990. this.viewerContainer.addEventListener("transitionend", evt => {
  6991. if (evt.target === this.viewerContainer) {
  6992. this.outerContainer.classList.remove("sidebarMoving");
  6993. }
  6994. });
  6995. this.toggleButton.addEventListener("click", () => {
  6996. this.toggle();
  6997. });
  6998. this.thumbnailButton.addEventListener("click", () => {
  6999. this.switchView(_ui_utils.SidebarView.THUMBS);
  7000. });
  7001. this.outlineButton.addEventListener("click", () => {
  7002. this.switchView(_ui_utils.SidebarView.OUTLINE);
  7003. });
  7004. this.outlineButton.addEventListener("dblclick", () => {
  7005. this.eventBus.dispatch("toggleoutlinetree", {
  7006. source: this
  7007. });
  7008. });
  7009. this.attachmentsButton.addEventListener("click", () => {
  7010. this.switchView(_ui_utils.SidebarView.ATTACHMENTS);
  7011. });
  7012. this.layersButton.addEventListener("click", () => {
  7013. this.switchView(_ui_utils.SidebarView.LAYERS);
  7014. });
  7015. this.layersButton.addEventListener("dblclick", () => {
  7016. this.eventBus.dispatch("resetlayers", {
  7017. source: this
  7018. });
  7019. });
  7020. this._currentOutlineItemButton.addEventListener("click", () => {
  7021. this.eventBus.dispatch("currentoutlineitem", {
  7022. source: this
  7023. });
  7024. });
  7025. const onTreeLoaded = (count, button, view) => {
  7026. button.disabled = !count;
  7027. if (count) {
  7028. this._showUINotification();
  7029. } else if (this.active === view) {
  7030. this.switchView(_ui_utils.SidebarView.THUMBS);
  7031. }
  7032. };
  7033. this.eventBus._on("outlineloaded", evt => {
  7034. onTreeLoaded(evt.outlineCount, this.outlineButton, _ui_utils.SidebarView.OUTLINE);
  7035. if (evt.enableCurrentOutlineItemButton) {
  7036. this.pdfViewer.pagesPromise.then(() => {
  7037. this._currentOutlineItemButton.disabled = !this.isInitialViewSet;
  7038. });
  7039. }
  7040. });
  7041. this.eventBus._on("attachmentsloaded", evt => {
  7042. onTreeLoaded(evt.attachmentsCount, this.attachmentsButton, _ui_utils.SidebarView.ATTACHMENTS);
  7043. });
  7044. this.eventBus._on("layersloaded", evt => {
  7045. onTreeLoaded(evt.layersCount, this.layersButton, _ui_utils.SidebarView.LAYERS);
  7046. });
  7047. this.eventBus._on("presentationmodechanged", evt => {
  7048. if (evt.state === _ui_utils.PresentationModeState.NORMAL && this.isThumbnailViewVisible) {
  7049. this._updateThumbnailViewer();
  7050. }
  7051. });
  7052. }
  7053. }
  7054. exports.PDFSidebar = PDFSidebar;
  7055. /***/ }),
  7056. /* 24 */
  7057. /***/ ((__unused_webpack_module, exports) => {
  7058. Object.defineProperty(exports, "__esModule", ({
  7059. value: true
  7060. }));
  7061. exports.PDFSidebarResizer = void 0;
  7062. const SIDEBAR_WIDTH_VAR = "--sidebar-width";
  7063. const SIDEBAR_MIN_WIDTH = 200;
  7064. const SIDEBAR_RESIZING_CLASS = "sidebarResizing";
  7065. class PDFSidebarResizer {
  7066. constructor(options, eventBus, l10n) {
  7067. this.isRTL = false;
  7068. this.sidebarOpen = false;
  7069. this.doc = document.documentElement;
  7070. this._width = null;
  7071. this._outerContainerWidth = null;
  7072. this._boundEvents = Object.create(null);
  7073. this.outerContainer = options.outerContainer;
  7074. this.resizer = options.resizer;
  7075. this.eventBus = eventBus;
  7076. l10n.getDirection().then(dir => {
  7077. this.isRTL = dir === "rtl";
  7078. });
  7079. this._addEventListeners();
  7080. }
  7081. get outerContainerWidth() {
  7082. return this._outerContainerWidth || (this._outerContainerWidth = this.outerContainer.clientWidth);
  7083. }
  7084. _updateWidth(width = 0) {
  7085. const maxWidth = Math.floor(this.outerContainerWidth / 2);
  7086. if (width > maxWidth) {
  7087. width = maxWidth;
  7088. }
  7089. if (width < SIDEBAR_MIN_WIDTH) {
  7090. width = SIDEBAR_MIN_WIDTH;
  7091. }
  7092. if (width === this._width) {
  7093. return false;
  7094. }
  7095. this._width = width;
  7096. this.doc.style.setProperty(SIDEBAR_WIDTH_VAR, `${width}px`);
  7097. return true;
  7098. }
  7099. _mouseMove(evt) {
  7100. let width = evt.clientX;
  7101. if (this.isRTL) {
  7102. width = this.outerContainerWidth - width;
  7103. }
  7104. this._updateWidth(width);
  7105. }
  7106. _mouseUp(evt) {
  7107. this.outerContainer.classList.remove(SIDEBAR_RESIZING_CLASS);
  7108. this.eventBus.dispatch("resize", {
  7109. source: this
  7110. });
  7111. const _boundEvents = this._boundEvents;
  7112. window.removeEventListener("mousemove", _boundEvents.mouseMove);
  7113. window.removeEventListener("mouseup", _boundEvents.mouseUp);
  7114. }
  7115. _addEventListeners() {
  7116. const _boundEvents = this._boundEvents;
  7117. _boundEvents.mouseMove = this._mouseMove.bind(this);
  7118. _boundEvents.mouseUp = this._mouseUp.bind(this);
  7119. this.resizer.addEventListener("mousedown", evt => {
  7120. if (evt.button !== 0) {
  7121. return;
  7122. }
  7123. this.outerContainer.classList.add(SIDEBAR_RESIZING_CLASS);
  7124. window.addEventListener("mousemove", _boundEvents.mouseMove);
  7125. window.addEventListener("mouseup", _boundEvents.mouseUp);
  7126. });
  7127. this.eventBus._on("sidebarviewchanged", evt => {
  7128. this.sidebarOpen = !!evt?.view;
  7129. });
  7130. this.eventBus._on("resize", evt => {
  7131. if (evt?.source !== window) {
  7132. return;
  7133. }
  7134. this._outerContainerWidth = null;
  7135. if (!this._width) {
  7136. return;
  7137. }
  7138. if (!this.sidebarOpen) {
  7139. this._updateWidth(this._width);
  7140. return;
  7141. }
  7142. this.outerContainer.classList.add(SIDEBAR_RESIZING_CLASS);
  7143. const updated = this._updateWidth(this._width);
  7144. Promise.resolve().then(() => {
  7145. this.outerContainer.classList.remove(SIDEBAR_RESIZING_CLASS);
  7146. if (updated) {
  7147. this.eventBus.dispatch("resize", {
  7148. source: this
  7149. });
  7150. }
  7151. });
  7152. });
  7153. }
  7154. }
  7155. exports.PDFSidebarResizer = PDFSidebarResizer;
  7156. /***/ }),
  7157. /* 25 */
  7158. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7159. Object.defineProperty(exports, "__esModule", ({
  7160. value: true
  7161. }));
  7162. exports.PDFThumbnailViewer = void 0;
  7163. var _ui_utils = __webpack_require__(4);
  7164. var _pdf_thumbnail_view = __webpack_require__(26);
  7165. var _pdf_rendering_queue = __webpack_require__(8);
  7166. const THUMBNAIL_SCROLL_MARGIN = -19;
  7167. const THUMBNAIL_SELECTED_CLASS = "selected";
  7168. class PDFThumbnailViewer {
  7169. constructor({
  7170. container,
  7171. eventBus,
  7172. linkService,
  7173. renderingQueue,
  7174. l10n
  7175. }) {
  7176. this.container = container;
  7177. this.linkService = linkService;
  7178. this.renderingQueue = renderingQueue;
  7179. this.l10n = l10n;
  7180. this.scroll = (0, _ui_utils.watchScroll)(this.container, this._scrollUpdated.bind(this));
  7181. this._resetView();
  7182. eventBus._on("optionalcontentconfigchanged", () => {
  7183. this._setImageDisabled = true;
  7184. });
  7185. }
  7186. _scrollUpdated() {
  7187. this.renderingQueue.renderHighestPriority();
  7188. }
  7189. getThumbnail(index) {
  7190. return this._thumbnails[index];
  7191. }
  7192. _getVisibleThumbs() {
  7193. return (0, _ui_utils.getVisibleElements)({
  7194. scrollEl: this.container,
  7195. views: this._thumbnails
  7196. });
  7197. }
  7198. scrollThumbnailIntoView(pageNumber) {
  7199. if (!this.pdfDocument) {
  7200. return;
  7201. }
  7202. const thumbnailView = this._thumbnails[pageNumber - 1];
  7203. if (!thumbnailView) {
  7204. console.error('scrollThumbnailIntoView: Invalid "pageNumber" parameter.');
  7205. return;
  7206. }
  7207. if (pageNumber !== this._currentPageNumber) {
  7208. const prevThumbnailView = this._thumbnails[this._currentPageNumber - 1];
  7209. prevThumbnailView.div.classList.remove(THUMBNAIL_SELECTED_CLASS);
  7210. thumbnailView.div.classList.add(THUMBNAIL_SELECTED_CLASS);
  7211. }
  7212. const visibleThumbs = this._getVisibleThumbs();
  7213. const numVisibleThumbs = visibleThumbs.views.length;
  7214. if (numVisibleThumbs > 0) {
  7215. const first = visibleThumbs.first.id;
  7216. const last = numVisibleThumbs > 1 ? visibleThumbs.last.id : first;
  7217. let shouldScroll = false;
  7218. if (pageNumber <= first || pageNumber >= last) {
  7219. shouldScroll = true;
  7220. } else {
  7221. visibleThumbs.views.some(function (view) {
  7222. if (view.id !== pageNumber) {
  7223. return false;
  7224. }
  7225. shouldScroll = view.percent < 100;
  7226. return true;
  7227. });
  7228. }
  7229. if (shouldScroll) {
  7230. (0, _ui_utils.scrollIntoView)(thumbnailView.div, {
  7231. top: THUMBNAIL_SCROLL_MARGIN
  7232. });
  7233. }
  7234. }
  7235. this._currentPageNumber = pageNumber;
  7236. }
  7237. get pagesRotation() {
  7238. return this._pagesRotation;
  7239. }
  7240. set pagesRotation(rotation) {
  7241. if (!(0, _ui_utils.isValidRotation)(rotation)) {
  7242. throw new Error("Invalid thumbnails rotation angle.");
  7243. }
  7244. if (!this.pdfDocument) {
  7245. return;
  7246. }
  7247. if (this._pagesRotation === rotation) {
  7248. return;
  7249. }
  7250. this._pagesRotation = rotation;
  7251. for (let i = 0, ii = this._thumbnails.length; i < ii; i++) {
  7252. this._thumbnails[i].update(rotation);
  7253. }
  7254. }
  7255. cleanup() {
  7256. for (let i = 0, ii = this._thumbnails.length; i < ii; i++) {
  7257. if (this._thumbnails[i] && this._thumbnails[i].renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED) {
  7258. this._thumbnails[i].reset();
  7259. }
  7260. }
  7261. _pdf_thumbnail_view.TempImageFactory.destroyCanvas();
  7262. }
  7263. _resetView() {
  7264. this._thumbnails = [];
  7265. this._currentPageNumber = 1;
  7266. this._pageLabels = null;
  7267. this._pagesRotation = 0;
  7268. this._optionalContentConfigPromise = null;
  7269. this._pagesRequests = new WeakMap();
  7270. this._setImageDisabled = false;
  7271. this.container.textContent = "";
  7272. }
  7273. setDocument(pdfDocument) {
  7274. if (this.pdfDocument) {
  7275. this._cancelRendering();
  7276. this._resetView();
  7277. }
  7278. this.pdfDocument = pdfDocument;
  7279. if (!pdfDocument) {
  7280. return;
  7281. }
  7282. const firstPagePromise = pdfDocument.getPage(1);
  7283. const optionalContentConfigPromise = pdfDocument.getOptionalContentConfig();
  7284. firstPagePromise.then(firstPdfPage => {
  7285. this._optionalContentConfigPromise = optionalContentConfigPromise;
  7286. const pagesCount = pdfDocument.numPages;
  7287. const viewport = firstPdfPage.getViewport({
  7288. scale: 1
  7289. });
  7290. const checkSetImageDisabled = () => {
  7291. return this._setImageDisabled;
  7292. };
  7293. for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) {
  7294. const thumbnail = new _pdf_thumbnail_view.PDFThumbnailView({
  7295. container: this.container,
  7296. id: pageNum,
  7297. defaultViewport: viewport.clone(),
  7298. optionalContentConfigPromise,
  7299. linkService: this.linkService,
  7300. renderingQueue: this.renderingQueue,
  7301. checkSetImageDisabled,
  7302. disableCanvasToImageConversion: false,
  7303. l10n: this.l10n
  7304. });
  7305. this._thumbnails.push(thumbnail);
  7306. }
  7307. const firstThumbnailView = this._thumbnails[0];
  7308. if (firstThumbnailView) {
  7309. firstThumbnailView.setPdfPage(firstPdfPage);
  7310. }
  7311. const thumbnailView = this._thumbnails[this._currentPageNumber - 1];
  7312. thumbnailView.div.classList.add(THUMBNAIL_SELECTED_CLASS);
  7313. }).catch(reason => {
  7314. console.error("Unable to initialize thumbnail viewer", reason);
  7315. });
  7316. }
  7317. _cancelRendering() {
  7318. for (let i = 0, ii = this._thumbnails.length; i < ii; i++) {
  7319. if (this._thumbnails[i]) {
  7320. this._thumbnails[i].cancelRendering();
  7321. }
  7322. }
  7323. }
  7324. setPageLabels(labels) {
  7325. if (!this.pdfDocument) {
  7326. return;
  7327. }
  7328. if (!labels) {
  7329. this._pageLabels = null;
  7330. } else if (!(Array.isArray(labels) && this.pdfDocument.numPages === labels.length)) {
  7331. this._pageLabels = null;
  7332. console.error("PDFThumbnailViewer_setPageLabels: Invalid page labels.");
  7333. } else {
  7334. this._pageLabels = labels;
  7335. }
  7336. for (let i = 0, ii = this._thumbnails.length; i < ii; i++) {
  7337. this._thumbnails[i].setPageLabel(this._pageLabels?.[i] ?? null);
  7338. }
  7339. }
  7340. _ensurePdfPageLoaded(thumbView) {
  7341. if (thumbView.pdfPage) {
  7342. return Promise.resolve(thumbView.pdfPage);
  7343. }
  7344. if (this._pagesRequests.has(thumbView)) {
  7345. return this._pagesRequests.get(thumbView);
  7346. }
  7347. const promise = this.pdfDocument.getPage(thumbView.id).then(pdfPage => {
  7348. if (!thumbView.pdfPage) {
  7349. thumbView.setPdfPage(pdfPage);
  7350. }
  7351. this._pagesRequests.delete(thumbView);
  7352. return pdfPage;
  7353. }).catch(reason => {
  7354. console.error("Unable to get page for thumb view", reason);
  7355. this._pagesRequests.delete(thumbView);
  7356. });
  7357. this._pagesRequests.set(thumbView, promise);
  7358. return promise;
  7359. }
  7360. forceRendering() {
  7361. const visibleThumbs = this._getVisibleThumbs();
  7362. const thumbView = this.renderingQueue.getHighestPriority(visibleThumbs, this._thumbnails, this.scroll.down);
  7363. if (thumbView) {
  7364. this._ensurePdfPageLoaded(thumbView).then(() => {
  7365. this.renderingQueue.renderView(thumbView);
  7366. });
  7367. return true;
  7368. }
  7369. return false;
  7370. }
  7371. }
  7372. exports.PDFThumbnailViewer = PDFThumbnailViewer;
  7373. /***/ }),
  7374. /* 26 */
  7375. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7376. Object.defineProperty(exports, "__esModule", ({
  7377. value: true
  7378. }));
  7379. exports.TempImageFactory = exports.PDFThumbnailView = void 0;
  7380. var _ui_utils = __webpack_require__(4);
  7381. var _pdfjsLib = __webpack_require__(5);
  7382. var _pdf_rendering_queue = __webpack_require__(8);
  7383. const MAX_NUM_SCALING_STEPS = 3;
  7384. const THUMBNAIL_CANVAS_BORDER_WIDTH = 1;
  7385. const THUMBNAIL_WIDTH = 98;
  7386. const TempImageFactory = function TempImageFactoryClosure() {
  7387. let tempCanvasCache = null;
  7388. return {
  7389. getCanvas(width, height) {
  7390. let tempCanvas = tempCanvasCache;
  7391. if (!tempCanvas) {
  7392. tempCanvas = document.createElement("canvas");
  7393. tempCanvasCache = tempCanvas;
  7394. }
  7395. tempCanvas.width = width;
  7396. tempCanvas.height = height;
  7397. tempCanvas.mozOpaque = true;
  7398. const ctx = tempCanvas.getContext("2d", {
  7399. alpha: false
  7400. });
  7401. ctx.save();
  7402. ctx.fillStyle = "rgb(255, 255, 255)";
  7403. ctx.fillRect(0, 0, width, height);
  7404. ctx.restore();
  7405. return tempCanvas;
  7406. },
  7407. destroyCanvas() {
  7408. const tempCanvas = tempCanvasCache;
  7409. if (tempCanvas) {
  7410. tempCanvas.width = 0;
  7411. tempCanvas.height = 0;
  7412. }
  7413. tempCanvasCache = null;
  7414. }
  7415. };
  7416. }();
  7417. exports.TempImageFactory = TempImageFactory;
  7418. class PDFThumbnailView {
  7419. constructor({
  7420. container,
  7421. id,
  7422. defaultViewport,
  7423. optionalContentConfigPromise,
  7424. linkService,
  7425. renderingQueue,
  7426. checkSetImageDisabled,
  7427. disableCanvasToImageConversion = false,
  7428. l10n
  7429. }) {
  7430. this.id = id;
  7431. this.renderingId = "thumbnail" + id;
  7432. this.pageLabel = null;
  7433. this.pdfPage = null;
  7434. this.rotation = 0;
  7435. this.viewport = defaultViewport;
  7436. this.pdfPageRotate = defaultViewport.rotation;
  7437. this._optionalContentConfigPromise = optionalContentConfigPromise || null;
  7438. this.linkService = linkService;
  7439. this.renderingQueue = renderingQueue;
  7440. this.renderTask = null;
  7441. this.renderingState = _pdf_rendering_queue.RenderingStates.INITIAL;
  7442. this.resume = null;
  7443. this._checkSetImageDisabled = checkSetImageDisabled || function () {
  7444. return false;
  7445. };
  7446. this.disableCanvasToImageConversion = disableCanvasToImageConversion;
  7447. this.pageWidth = this.viewport.width;
  7448. this.pageHeight = this.viewport.height;
  7449. this.pageRatio = this.pageWidth / this.pageHeight;
  7450. this.canvasWidth = THUMBNAIL_WIDTH;
  7451. this.canvasHeight = this.canvasWidth / this.pageRatio | 0;
  7452. this.scale = this.canvasWidth / this.pageWidth;
  7453. this.l10n = l10n;
  7454. const anchor = document.createElement("a");
  7455. anchor.href = linkService.getAnchorUrl("#page=" + id);
  7456. this._thumbPageTitle.then(msg => {
  7457. anchor.title = msg;
  7458. });
  7459. anchor.onclick = function () {
  7460. linkService.goToPage(id);
  7461. return false;
  7462. };
  7463. this.anchor = anchor;
  7464. const div = document.createElement("div");
  7465. div.className = "thumbnail";
  7466. div.setAttribute("data-page-number", this.id);
  7467. this.div = div;
  7468. const ring = document.createElement("div");
  7469. ring.className = "thumbnailSelectionRing";
  7470. const borderAdjustment = 2 * THUMBNAIL_CANVAS_BORDER_WIDTH;
  7471. ring.style.width = this.canvasWidth + borderAdjustment + "px";
  7472. ring.style.height = this.canvasHeight + borderAdjustment + "px";
  7473. this.ring = ring;
  7474. div.appendChild(ring);
  7475. anchor.appendChild(div);
  7476. container.appendChild(anchor);
  7477. }
  7478. setPdfPage(pdfPage) {
  7479. this.pdfPage = pdfPage;
  7480. this.pdfPageRotate = pdfPage.rotate;
  7481. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  7482. this.viewport = pdfPage.getViewport({
  7483. scale: 1,
  7484. rotation: totalRotation
  7485. });
  7486. this.reset();
  7487. }
  7488. reset() {
  7489. this.cancelRendering();
  7490. this.renderingState = _pdf_rendering_queue.RenderingStates.INITIAL;
  7491. this.pageWidth = this.viewport.width;
  7492. this.pageHeight = this.viewport.height;
  7493. this.pageRatio = this.pageWidth / this.pageHeight;
  7494. this.canvasHeight = this.canvasWidth / this.pageRatio | 0;
  7495. this.scale = this.canvasWidth / this.pageWidth;
  7496. this.div.removeAttribute("data-loaded");
  7497. const ring = this.ring;
  7498. const childNodes = ring.childNodes;
  7499. for (let i = childNodes.length - 1; i >= 0; i--) {
  7500. ring.removeChild(childNodes[i]);
  7501. }
  7502. const borderAdjustment = 2 * THUMBNAIL_CANVAS_BORDER_WIDTH;
  7503. ring.style.width = this.canvasWidth + borderAdjustment + "px";
  7504. ring.style.height = this.canvasHeight + borderAdjustment + "px";
  7505. if (this.canvas) {
  7506. this.canvas.width = 0;
  7507. this.canvas.height = 0;
  7508. delete this.canvas;
  7509. }
  7510. if (this.image) {
  7511. this.image.removeAttribute("src");
  7512. delete this.image;
  7513. }
  7514. }
  7515. update(rotation) {
  7516. if (typeof rotation !== "undefined") {
  7517. this.rotation = rotation;
  7518. }
  7519. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  7520. this.viewport = this.viewport.clone({
  7521. scale: 1,
  7522. rotation: totalRotation
  7523. });
  7524. this.reset();
  7525. }
  7526. cancelRendering() {
  7527. if (this.renderTask) {
  7528. this.renderTask.cancel();
  7529. this.renderTask = null;
  7530. }
  7531. this.resume = null;
  7532. }
  7533. _getPageDrawContext() {
  7534. const canvas = document.createElement("canvas");
  7535. this.canvas = canvas;
  7536. canvas.mozOpaque = true;
  7537. const ctx = canvas.getContext("2d", {
  7538. alpha: false
  7539. });
  7540. const outputScale = (0, _ui_utils.getOutputScale)(ctx);
  7541. canvas.width = this.canvasWidth * outputScale.sx | 0;
  7542. canvas.height = this.canvasHeight * outputScale.sy | 0;
  7543. canvas.style.width = this.canvasWidth + "px";
  7544. canvas.style.height = this.canvasHeight + "px";
  7545. const transform = outputScale.scaled ? [outputScale.sx, 0, 0, outputScale.sy, 0, 0] : null;
  7546. return [ctx, transform];
  7547. }
  7548. _convertCanvasToImage() {
  7549. if (!this.canvas) {
  7550. return;
  7551. }
  7552. if (this.renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED) {
  7553. return;
  7554. }
  7555. const className = "thumbnailImage";
  7556. if (this.disableCanvasToImageConversion) {
  7557. this.canvas.className = className;
  7558. this._thumbPageCanvas.then(msg => {
  7559. this.canvas.setAttribute("aria-label", msg);
  7560. });
  7561. this.div.setAttribute("data-loaded", true);
  7562. this.ring.appendChild(this.canvas);
  7563. return;
  7564. }
  7565. const image = document.createElement("img");
  7566. image.className = className;
  7567. this._thumbPageCanvas.then(msg => {
  7568. image.setAttribute("aria-label", msg);
  7569. });
  7570. image.style.width = this.canvasWidth + "px";
  7571. image.style.height = this.canvasHeight + "px";
  7572. image.src = this.canvas.toDataURL();
  7573. this.image = image;
  7574. this.div.setAttribute("data-loaded", true);
  7575. this.ring.appendChild(image);
  7576. this.canvas.width = 0;
  7577. this.canvas.height = 0;
  7578. delete this.canvas;
  7579. }
  7580. draw() {
  7581. if (this.renderingState !== _pdf_rendering_queue.RenderingStates.INITIAL) {
  7582. console.error("Must be in new state before drawing");
  7583. return Promise.resolve(undefined);
  7584. }
  7585. const {
  7586. pdfPage
  7587. } = this;
  7588. if (!pdfPage) {
  7589. this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
  7590. return Promise.reject(new Error("pdfPage is not loaded"));
  7591. }
  7592. this.renderingState = _pdf_rendering_queue.RenderingStates.RUNNING;
  7593. const finishRenderTask = async (error = null) => {
  7594. if (renderTask === this.renderTask) {
  7595. this.renderTask = null;
  7596. }
  7597. if (error instanceof _pdfjsLib.RenderingCancelledException) {
  7598. return;
  7599. }
  7600. this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
  7601. this._convertCanvasToImage();
  7602. if (error) {
  7603. throw error;
  7604. }
  7605. };
  7606. const [ctx, transform] = this._getPageDrawContext();
  7607. const drawViewport = this.viewport.clone({
  7608. scale: this.scale
  7609. });
  7610. const renderContinueCallback = cont => {
  7611. if (!this.renderingQueue.isHighestPriority(this)) {
  7612. this.renderingState = _pdf_rendering_queue.RenderingStates.PAUSED;
  7613. this.resume = () => {
  7614. this.renderingState = _pdf_rendering_queue.RenderingStates.RUNNING;
  7615. cont();
  7616. };
  7617. return;
  7618. }
  7619. cont();
  7620. };
  7621. const renderContext = {
  7622. canvasContext: ctx,
  7623. transform,
  7624. viewport: drawViewport,
  7625. optionalContentConfigPromise: this._optionalContentConfigPromise
  7626. };
  7627. const renderTask = this.renderTask = pdfPage.render(renderContext);
  7628. renderTask.onContinue = renderContinueCallback;
  7629. const resultPromise = renderTask.promise.then(function () {
  7630. finishRenderTask(null);
  7631. }, function (error) {
  7632. finishRenderTask(error);
  7633. });
  7634. resultPromise.finally(() => {
  7635. const pageCached = this.linkService.isPageCached(this.id);
  7636. if (pageCached) {
  7637. return;
  7638. }
  7639. this.pdfPage?.cleanup();
  7640. });
  7641. return resultPromise;
  7642. }
  7643. setImage(pageView) {
  7644. if (this._checkSetImageDisabled()) {
  7645. return;
  7646. }
  7647. if (this.renderingState !== _pdf_rendering_queue.RenderingStates.INITIAL) {
  7648. return;
  7649. }
  7650. const img = pageView.canvas;
  7651. if (!img) {
  7652. return;
  7653. }
  7654. if (!this.pdfPage) {
  7655. this.setPdfPage(pageView.pdfPage);
  7656. }
  7657. this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
  7658. const [ctx] = this._getPageDrawContext();
  7659. const canvas = ctx.canvas;
  7660. if (img.width <= 2 * canvas.width) {
  7661. ctx.drawImage(img, 0, 0, img.width, img.height, 0, 0, canvas.width, canvas.height);
  7662. this._convertCanvasToImage();
  7663. return;
  7664. }
  7665. let reducedWidth = canvas.width << MAX_NUM_SCALING_STEPS;
  7666. let reducedHeight = canvas.height << MAX_NUM_SCALING_STEPS;
  7667. const reducedImage = TempImageFactory.getCanvas(reducedWidth, reducedHeight);
  7668. const reducedImageCtx = reducedImage.getContext("2d");
  7669. while (reducedWidth > img.width || reducedHeight > img.height) {
  7670. reducedWidth >>= 1;
  7671. reducedHeight >>= 1;
  7672. }
  7673. reducedImageCtx.drawImage(img, 0, 0, img.width, img.height, 0, 0, reducedWidth, reducedHeight);
  7674. while (reducedWidth > 2 * canvas.width) {
  7675. reducedImageCtx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, reducedWidth >> 1, reducedHeight >> 1);
  7676. reducedWidth >>= 1;
  7677. reducedHeight >>= 1;
  7678. }
  7679. ctx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, canvas.width, canvas.height);
  7680. this._convertCanvasToImage();
  7681. }
  7682. get _thumbPageTitle() {
  7683. return this.l10n.get("thumb_page_title", {
  7684. page: this.pageLabel ?? this.id
  7685. });
  7686. }
  7687. get _thumbPageCanvas() {
  7688. return this.l10n.get("thumb_page_canvas", {
  7689. page: this.pageLabel ?? this.id
  7690. });
  7691. }
  7692. setPageLabel(label) {
  7693. this.pageLabel = typeof label === "string" ? label : null;
  7694. this._thumbPageTitle.then(msg => {
  7695. this.anchor.title = msg;
  7696. });
  7697. if (this.renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED) {
  7698. return;
  7699. }
  7700. this._thumbPageCanvas.then(msg => {
  7701. if (this.image) {
  7702. this.image.setAttribute("aria-label", msg);
  7703. } else if (this.disableCanvasToImageConversion && this.canvas) {
  7704. this.canvas.setAttribute("aria-label", msg);
  7705. }
  7706. });
  7707. }
  7708. }
  7709. exports.PDFThumbnailView = PDFThumbnailView;
  7710. /***/ }),
  7711. /* 27 */
  7712. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7713. Object.defineProperty(exports, "__esModule", ({
  7714. value: true
  7715. }));
  7716. exports.PDFViewer = void 0;
  7717. var _ui_utils = __webpack_require__(4);
  7718. var _base_viewer = __webpack_require__(28);
  7719. var _pdfjsLib = __webpack_require__(5);
  7720. class PDFViewer extends _base_viewer.BaseViewer {
  7721. get _viewerElement() {
  7722. return (0, _pdfjsLib.shadow)(this, "_viewerElement", this.viewer);
  7723. }
  7724. _scrollIntoView({
  7725. pageDiv,
  7726. pageSpot = null,
  7727. pageNumber = null
  7728. }) {
  7729. if (!pageSpot && !this.isInPresentationMode) {
  7730. const left = pageDiv.offsetLeft + pageDiv.clientLeft;
  7731. const right = left + pageDiv.clientWidth;
  7732. const {
  7733. scrollLeft,
  7734. clientWidth
  7735. } = this.container;
  7736. if (this._isScrollModeHorizontal || left < scrollLeft || right > scrollLeft + clientWidth) {
  7737. pageSpot = {
  7738. left: 0,
  7739. top: 0
  7740. };
  7741. }
  7742. }
  7743. super._scrollIntoView({
  7744. pageDiv,
  7745. pageSpot,
  7746. pageNumber
  7747. });
  7748. }
  7749. _getVisiblePages() {
  7750. if (this.isInPresentationMode) {
  7751. return this._getCurrentVisiblePage();
  7752. }
  7753. return super._getVisiblePages();
  7754. }
  7755. _updateHelper(visiblePages) {
  7756. if (this.isInPresentationMode) {
  7757. return;
  7758. }
  7759. let currentId = this._currentPageNumber;
  7760. let stillFullyVisible = false;
  7761. for (const page of visiblePages) {
  7762. if (page.percent < 100) {
  7763. break;
  7764. }
  7765. if (page.id === currentId && this._scrollMode === _ui_utils.ScrollMode.VERTICAL && this._spreadMode === _ui_utils.SpreadMode.NONE) {
  7766. stillFullyVisible = true;
  7767. break;
  7768. }
  7769. }
  7770. if (!stillFullyVisible) {
  7771. currentId = visiblePages[0].id;
  7772. }
  7773. this._setCurrentPageNumber(currentId);
  7774. }
  7775. }
  7776. exports.PDFViewer = PDFViewer;
  7777. /***/ }),
  7778. /* 28 */
  7779. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  7780. Object.defineProperty(exports, "__esModule", ({
  7781. value: true
  7782. }));
  7783. exports.BaseViewer = void 0;
  7784. var _pdfjsLib = __webpack_require__(5);
  7785. var _ui_utils = __webpack_require__(4);
  7786. var _pdf_rendering_queue = __webpack_require__(8);
  7787. var _annotation_layer_builder = __webpack_require__(29);
  7788. var _l10n_utils = __webpack_require__(30);
  7789. var _pdf_page_view = __webpack_require__(31);
  7790. var _pdf_link_service = __webpack_require__(19);
  7791. var _text_layer_builder = __webpack_require__(32);
  7792. var _xfa_layer_builder = __webpack_require__(33);
  7793. const DEFAULT_CACHE_SIZE = 10;
  7794. function PDFPageViewBuffer(size) {
  7795. const data = [];
  7796. this.push = function (view) {
  7797. const i = data.indexOf(view);
  7798. if (i >= 0) {
  7799. data.splice(i, 1);
  7800. }
  7801. data.push(view);
  7802. if (data.length > size) {
  7803. data.shift().destroy();
  7804. }
  7805. };
  7806. this.resize = function (newSize, pagesToKeep) {
  7807. size = newSize;
  7808. if (pagesToKeep) {
  7809. const pageIdsToKeep = new Set();
  7810. for (let i = 0, iMax = pagesToKeep.length; i < iMax; ++i) {
  7811. pageIdsToKeep.add(pagesToKeep[i].id);
  7812. }
  7813. (0, _ui_utils.moveToEndOfArray)(data, function (page) {
  7814. return pageIdsToKeep.has(page.id);
  7815. });
  7816. }
  7817. while (data.length > size) {
  7818. data.shift().destroy();
  7819. }
  7820. };
  7821. this.has = function (view) {
  7822. return data.includes(view);
  7823. };
  7824. }
  7825. function isSameScale(oldScale, newScale) {
  7826. if (newScale === oldScale) {
  7827. return true;
  7828. }
  7829. if (Math.abs(newScale - oldScale) < 1e-15) {
  7830. return true;
  7831. }
  7832. return false;
  7833. }
  7834. class BaseViewer {
  7835. constructor(options) {
  7836. if (this.constructor === BaseViewer) {
  7837. throw new Error("Cannot initialize BaseViewer.");
  7838. }
  7839. const viewerVersion = '2.8.335';
  7840. if (_pdfjsLib.version !== viewerVersion) {
  7841. throw new Error(`The API version "${_pdfjsLib.version}" does not match the Viewer version "${viewerVersion}".`);
  7842. }
  7843. this._name = this.constructor.name;
  7844. this.container = options.container;
  7845. this.viewer = options.viewer || options.container.firstElementChild;
  7846. if (!(this.container?.tagName.toUpperCase() === "DIV" && this.viewer?.tagName.toUpperCase() === "DIV")) {
  7847. throw new Error("Invalid `container` and/or `viewer` option.");
  7848. }
  7849. if (this.container.offsetParent && getComputedStyle(this.container).position !== "absolute") {
  7850. throw new Error("The `container` must be absolutely positioned.");
  7851. }
  7852. this.eventBus = options.eventBus;
  7853. this.linkService = options.linkService || new _pdf_link_service.SimpleLinkService();
  7854. this.downloadManager = options.downloadManager || null;
  7855. this.findController = options.findController || null;
  7856. this._scriptingManager = options.scriptingManager || null;
  7857. this.removePageBorders = options.removePageBorders || false;
  7858. this.textLayerMode = Number.isInteger(options.textLayerMode) ? options.textLayerMode : _ui_utils.TextLayerMode.ENABLE;
  7859. this.imageResourcesPath = options.imageResourcesPath || "";
  7860. this.renderInteractiveForms = options.renderInteractiveForms !== false;
  7861. this.enablePrintAutoRotate = options.enablePrintAutoRotate || false;
  7862. this.renderer = options.renderer || _ui_utils.RendererType.CANVAS;
  7863. this.enableWebGL = options.enableWebGL || false;
  7864. this.useOnlyCssZoom = options.useOnlyCssZoom || false;
  7865. this.maxCanvasPixels = options.maxCanvasPixels;
  7866. this.l10n = options.l10n || _l10n_utils.NullL10n;
  7867. this.enableScripting = options.enableScripting === true && !!this._scriptingManager;
  7868. this.defaultRenderingQueue = !options.renderingQueue;
  7869. if (this.defaultRenderingQueue) {
  7870. this.renderingQueue = new _pdf_rendering_queue.PDFRenderingQueue();
  7871. this.renderingQueue.setViewer(this);
  7872. } else {
  7873. this.renderingQueue = options.renderingQueue;
  7874. }
  7875. this.scroll = (0, _ui_utils.watchScroll)(this.container, this._scrollUpdate.bind(this));
  7876. this.presentationModeState = _ui_utils.PresentationModeState.UNKNOWN;
  7877. this._onBeforeDraw = this._onAfterDraw = null;
  7878. this._resetView();
  7879. if (this.removePageBorders) {
  7880. this.viewer.classList.add("removePageBorders");
  7881. }
  7882. Promise.resolve().then(() => {
  7883. this.eventBus.dispatch("baseviewerinit", {
  7884. source: this
  7885. });
  7886. });
  7887. }
  7888. get pagesCount() {
  7889. return this._pages.length;
  7890. }
  7891. getPageView(index) {
  7892. return this._pages[index];
  7893. }
  7894. get pageViewsReady() {
  7895. if (!this._pagesCapability.settled) {
  7896. return false;
  7897. }
  7898. return this._pages.every(function (pageView) {
  7899. return pageView?.pdfPage;
  7900. });
  7901. }
  7902. get currentPageNumber() {
  7903. return this._currentPageNumber;
  7904. }
  7905. set currentPageNumber(val) {
  7906. if (!Number.isInteger(val)) {
  7907. throw new Error("Invalid page number.");
  7908. }
  7909. if (!this.pdfDocument) {
  7910. return;
  7911. }
  7912. if (!this._setCurrentPageNumber(val, true)) {
  7913. console.error(`${this._name}.currentPageNumber: "${val}" is not a valid page.`);
  7914. }
  7915. }
  7916. _setCurrentPageNumber(val, resetCurrentPageView = false) {
  7917. if (this._currentPageNumber === val) {
  7918. if (resetCurrentPageView) {
  7919. this._resetCurrentPageView();
  7920. }
  7921. return true;
  7922. }
  7923. if (!(0 < val && val <= this.pagesCount)) {
  7924. return false;
  7925. }
  7926. const previous = this._currentPageNumber;
  7927. this._currentPageNumber = val;
  7928. this.eventBus.dispatch("pagechanging", {
  7929. source: this,
  7930. pageNumber: val,
  7931. pageLabel: this._pageLabels?.[val - 1] ?? null,
  7932. previous
  7933. });
  7934. if (resetCurrentPageView) {
  7935. this._resetCurrentPageView();
  7936. }
  7937. return true;
  7938. }
  7939. get currentPageLabel() {
  7940. return this._pageLabels?.[this._currentPageNumber - 1] ?? null;
  7941. }
  7942. set currentPageLabel(val) {
  7943. if (!this.pdfDocument) {
  7944. return;
  7945. }
  7946. let page = val | 0;
  7947. if (this._pageLabels) {
  7948. const i = this._pageLabels.indexOf(val);
  7949. if (i >= 0) {
  7950. page = i + 1;
  7951. }
  7952. }
  7953. if (!this._setCurrentPageNumber(page, true)) {
  7954. console.error(`${this._name}.currentPageLabel: "${val}" is not a valid page.`);
  7955. }
  7956. }
  7957. get currentScale() {
  7958. return this._currentScale !== _ui_utils.UNKNOWN_SCALE ? this._currentScale : _ui_utils.DEFAULT_SCALE;
  7959. }
  7960. set currentScale(val) {
  7961. if (isNaN(val)) {
  7962. throw new Error("Invalid numeric scale.");
  7963. }
  7964. if (!this.pdfDocument) {
  7965. return;
  7966. }
  7967. this._setScale(val, false);
  7968. }
  7969. get currentScaleValue() {
  7970. return this._currentScaleValue;
  7971. }
  7972. set currentScaleValue(val) {
  7973. if (!this.pdfDocument) {
  7974. return;
  7975. }
  7976. this._setScale(val, false);
  7977. }
  7978. get pagesRotation() {
  7979. return this._pagesRotation;
  7980. }
  7981. set pagesRotation(rotation) {
  7982. if (!(0, _ui_utils.isValidRotation)(rotation)) {
  7983. throw new Error("Invalid pages rotation angle.");
  7984. }
  7985. if (!this.pdfDocument) {
  7986. return;
  7987. }
  7988. rotation %= 360;
  7989. if (rotation < 0) {
  7990. rotation += 360;
  7991. }
  7992. if (this._pagesRotation === rotation) {
  7993. return;
  7994. }
  7995. this._pagesRotation = rotation;
  7996. const pageNumber = this._currentPageNumber;
  7997. for (let i = 0, ii = this._pages.length; i < ii; i++) {
  7998. const pageView = this._pages[i];
  7999. pageView.update(pageView.scale, rotation);
  8000. }
  8001. if (this._currentScaleValue) {
  8002. this._setScale(this._currentScaleValue, true);
  8003. }
  8004. this.eventBus.dispatch("rotationchanging", {
  8005. source: this,
  8006. pagesRotation: rotation,
  8007. pageNumber
  8008. });
  8009. if (this.defaultRenderingQueue) {
  8010. this.update();
  8011. }
  8012. }
  8013. get firstPagePromise() {
  8014. return this.pdfDocument ? this._firstPageCapability.promise : null;
  8015. }
  8016. get onePageRendered() {
  8017. return this.pdfDocument ? this._onePageRenderedCapability.promise : null;
  8018. }
  8019. get pagesPromise() {
  8020. return this.pdfDocument ? this._pagesCapability.promise : null;
  8021. }
  8022. get _viewerElement() {
  8023. throw new Error("Not implemented: _viewerElement");
  8024. }
  8025. _onePageRenderedOrForceFetch() {
  8026. if (!this.container.offsetParent || this._getVisiblePages().views.length === 0) {
  8027. return Promise.resolve();
  8028. }
  8029. return this._onePageRenderedCapability.promise;
  8030. }
  8031. setDocument(pdfDocument) {
  8032. if (this.pdfDocument) {
  8033. this.eventBus.dispatch("pagesdestroy", {
  8034. source: this
  8035. });
  8036. this._cancelRendering();
  8037. this._resetView();
  8038. if (this.findController) {
  8039. this.findController.setDocument(null);
  8040. }
  8041. if (this._scriptingManager) {
  8042. this._scriptingManager.setDocument(null);
  8043. }
  8044. }
  8045. this.pdfDocument = pdfDocument;
  8046. if (!pdfDocument) {
  8047. return;
  8048. }
  8049. const isPureXfa = pdfDocument.isPureXfa;
  8050. const pagesCount = pdfDocument.numPages;
  8051. const firstPagePromise = pdfDocument.getPage(1);
  8052. const optionalContentConfigPromise = pdfDocument.getOptionalContentConfig();
  8053. this._pagesCapability.promise.then(() => {
  8054. this.eventBus.dispatch("pagesloaded", {
  8055. source: this,
  8056. pagesCount
  8057. });
  8058. });
  8059. this._onBeforeDraw = evt => {
  8060. const pageView = this._pages[evt.pageNumber - 1];
  8061. if (!pageView) {
  8062. return;
  8063. }
  8064. this._buffer.push(pageView);
  8065. };
  8066. this.eventBus._on("pagerender", this._onBeforeDraw);
  8067. this._onAfterDraw = evt => {
  8068. if (evt.cssTransform || this._onePageRenderedCapability.settled) {
  8069. return;
  8070. }
  8071. this._onePageRenderedCapability.resolve();
  8072. this.eventBus._off("pagerendered", this._onAfterDraw);
  8073. this._onAfterDraw = null;
  8074. };
  8075. this.eventBus._on("pagerendered", this._onAfterDraw);
  8076. firstPagePromise.then(firstPdfPage => {
  8077. this._firstPageCapability.resolve(firstPdfPage);
  8078. this._optionalContentConfigPromise = optionalContentConfigPromise;
  8079. const scale = this.currentScale;
  8080. const viewport = firstPdfPage.getViewport({
  8081. scale: scale * _ui_utils.CSS_UNITS
  8082. });
  8083. const textLayerFactory = this.textLayerMode !== _ui_utils.TextLayerMode.DISABLE ? this : null;
  8084. const xfaLayerFactory = isPureXfa ? this : null;
  8085. for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) {
  8086. const pageView = new _pdf_page_view.PDFPageView({
  8087. container: this._viewerElement,
  8088. eventBus: this.eventBus,
  8089. id: pageNum,
  8090. scale,
  8091. defaultViewport: viewport.clone(),
  8092. optionalContentConfigPromise,
  8093. renderingQueue: this.renderingQueue,
  8094. textLayerFactory,
  8095. textLayerMode: this.textLayerMode,
  8096. annotationLayerFactory: this,
  8097. xfaLayerFactory,
  8098. imageResourcesPath: this.imageResourcesPath,
  8099. renderInteractiveForms: this.renderInteractiveForms,
  8100. renderer: this.renderer,
  8101. enableWebGL: this.enableWebGL,
  8102. useOnlyCssZoom: this.useOnlyCssZoom,
  8103. maxCanvasPixels: this.maxCanvasPixels,
  8104. l10n: this.l10n,
  8105. enableScripting: this.enableScripting
  8106. });
  8107. this._pages.push(pageView);
  8108. }
  8109. const firstPageView = this._pages[0];
  8110. if (firstPageView) {
  8111. firstPageView.setPdfPage(firstPdfPage);
  8112. this.linkService.cachePageRef(1, firstPdfPage.ref);
  8113. }
  8114. if (this._spreadMode !== _ui_utils.SpreadMode.NONE) {
  8115. this._updateSpreadMode();
  8116. }
  8117. this._onePageRenderedOrForceFetch().then(() => {
  8118. if (this.findController) {
  8119. this.findController.setDocument(pdfDocument);
  8120. }
  8121. if (this.enableScripting) {
  8122. this._scriptingManager.setDocument(pdfDocument);
  8123. }
  8124. if (pdfDocument.loadingParams.disableAutoFetch || pagesCount > 7500) {
  8125. this._pagesCapability.resolve();
  8126. return;
  8127. }
  8128. let getPagesLeft = pagesCount - 1;
  8129. if (getPagesLeft <= 0) {
  8130. this._pagesCapability.resolve();
  8131. return;
  8132. }
  8133. for (let pageNum = 2; pageNum <= pagesCount; ++pageNum) {
  8134. pdfDocument.getPage(pageNum).then(pdfPage => {
  8135. const pageView = this._pages[pageNum - 1];
  8136. if (!pageView.pdfPage) {
  8137. pageView.setPdfPage(pdfPage);
  8138. }
  8139. this.linkService.cachePageRef(pageNum, pdfPage.ref);
  8140. if (--getPagesLeft === 0) {
  8141. this._pagesCapability.resolve();
  8142. }
  8143. }, reason => {
  8144. console.error(`Unable to get page ${pageNum} to initialize viewer`, reason);
  8145. if (--getPagesLeft === 0) {
  8146. this._pagesCapability.resolve();
  8147. }
  8148. });
  8149. }
  8150. });
  8151. this.eventBus.dispatch("pagesinit", {
  8152. source: this
  8153. });
  8154. if (this.defaultRenderingQueue) {
  8155. this.update();
  8156. }
  8157. }).catch(reason => {
  8158. console.error("Unable to initialize viewer", reason);
  8159. });
  8160. }
  8161. setPageLabels(labels) {
  8162. if (!this.pdfDocument) {
  8163. return;
  8164. }
  8165. if (!labels) {
  8166. this._pageLabels = null;
  8167. } else if (!(Array.isArray(labels) && this.pdfDocument.numPages === labels.length)) {
  8168. this._pageLabels = null;
  8169. console.error(`${this._name}.setPageLabels: Invalid page labels.`);
  8170. } else {
  8171. this._pageLabels = labels;
  8172. }
  8173. for (let i = 0, ii = this._pages.length; i < ii; i++) {
  8174. this._pages[i].setPageLabel(this._pageLabels?.[i] ?? null);
  8175. }
  8176. }
  8177. _resetView() {
  8178. this._pages = [];
  8179. this._currentPageNumber = 1;
  8180. this._currentScale = _ui_utils.UNKNOWN_SCALE;
  8181. this._currentScaleValue = null;
  8182. this._pageLabels = null;
  8183. this._buffer = new PDFPageViewBuffer(DEFAULT_CACHE_SIZE);
  8184. this._location = null;
  8185. this._pagesRotation = 0;
  8186. this._optionalContentConfigPromise = null;
  8187. this._pagesRequests = new WeakMap();
  8188. this._firstPageCapability = (0, _pdfjsLib.createPromiseCapability)();
  8189. this._onePageRenderedCapability = (0, _pdfjsLib.createPromiseCapability)();
  8190. this._pagesCapability = (0, _pdfjsLib.createPromiseCapability)();
  8191. this._scrollMode = _ui_utils.ScrollMode.VERTICAL;
  8192. this._spreadMode = _ui_utils.SpreadMode.NONE;
  8193. if (this._onBeforeDraw) {
  8194. this.eventBus._off("pagerender", this._onBeforeDraw);
  8195. this._onBeforeDraw = null;
  8196. }
  8197. if (this._onAfterDraw) {
  8198. this.eventBus._off("pagerendered", this._onAfterDraw);
  8199. this._onAfterDraw = null;
  8200. }
  8201. this.viewer.textContent = "";
  8202. this._updateScrollMode();
  8203. }
  8204. _scrollUpdate() {
  8205. if (this.pagesCount === 0) {
  8206. return;
  8207. }
  8208. this.update();
  8209. }
  8210. _scrollIntoView({
  8211. pageDiv,
  8212. pageSpot = null,
  8213. pageNumber = null
  8214. }) {
  8215. (0, _ui_utils.scrollIntoView)(pageDiv, pageSpot);
  8216. }
  8217. _setScaleUpdatePages(newScale, newValue, noScroll = false, preset = false) {
  8218. this._currentScaleValue = newValue.toString();
  8219. if (isSameScale(this._currentScale, newScale)) {
  8220. if (preset) {
  8221. this.eventBus.dispatch("scalechanging", {
  8222. source: this,
  8223. scale: newScale,
  8224. presetValue: newValue
  8225. });
  8226. }
  8227. return;
  8228. }
  8229. for (let i = 0, ii = this._pages.length; i < ii; i++) {
  8230. this._pages[i].update(newScale);
  8231. }
  8232. this._currentScale = newScale;
  8233. if (!noScroll) {
  8234. let page = this._currentPageNumber,
  8235. dest;
  8236. if (this._location && !(this.isInPresentationMode || this.isChangingPresentationMode)) {
  8237. page = this._location.pageNumber;
  8238. dest = [null, {
  8239. name: "XYZ"
  8240. }, this._location.left, this._location.top, null];
  8241. }
  8242. this.scrollPageIntoView({
  8243. pageNumber: page,
  8244. destArray: dest,
  8245. allowNegativeOffset: true
  8246. });
  8247. }
  8248. this.eventBus.dispatch("scalechanging", {
  8249. source: this,
  8250. scale: newScale,
  8251. presetValue: preset ? newValue : undefined
  8252. });
  8253. if (this.defaultRenderingQueue) {
  8254. this.update();
  8255. }
  8256. }
  8257. get _pageWidthScaleFactor() {
  8258. if (this._spreadMode !== _ui_utils.SpreadMode.NONE && this._scrollMode !== _ui_utils.ScrollMode.HORIZONTAL && !this.isInPresentationMode) {
  8259. return 2;
  8260. }
  8261. return 1;
  8262. }
  8263. _setScale(value, noScroll = false) {
  8264. let scale = parseFloat(value);
  8265. if (scale > 0) {
  8266. this._setScaleUpdatePages(scale, value, noScroll, false);
  8267. } else {
  8268. const currentPage = this._pages[this._currentPageNumber - 1];
  8269. if (!currentPage) {
  8270. return;
  8271. }
  8272. const noPadding = this.isInPresentationMode || this.removePageBorders;
  8273. let hPadding = noPadding ? 0 : _ui_utils.SCROLLBAR_PADDING;
  8274. let vPadding = noPadding ? 0 : _ui_utils.VERTICAL_PADDING;
  8275. if (!noPadding && this._isScrollModeHorizontal) {
  8276. [hPadding, vPadding] = [vPadding, hPadding];
  8277. }
  8278. const pageWidthScale = (this.container.clientWidth - hPadding) / currentPage.width * currentPage.scale / this._pageWidthScaleFactor;
  8279. const pageHeightScale = (this.container.clientHeight - vPadding) / currentPage.height * currentPage.scale;
  8280. switch (value) {
  8281. case "page-actual":
  8282. scale = 1;
  8283. break;
  8284. case "page-width":
  8285. scale = pageWidthScale;
  8286. break;
  8287. case "page-height":
  8288. scale = pageHeightScale;
  8289. break;
  8290. case "page-fit":
  8291. scale = Math.min(pageWidthScale, pageHeightScale);
  8292. break;
  8293. case "auto":
  8294. const horizontalScale = (0, _ui_utils.isPortraitOrientation)(currentPage) ? pageWidthScale : Math.min(pageHeightScale, pageWidthScale);
  8295. scale = Math.min(_ui_utils.MAX_AUTO_SCALE, horizontalScale);
  8296. break;
  8297. default:
  8298. console.error(`${this._name}._setScale: "${value}" is an unknown zoom value.`);
  8299. return;
  8300. }
  8301. this._setScaleUpdatePages(scale, value, noScroll, true);
  8302. }
  8303. }
  8304. _resetCurrentPageView() {
  8305. if (this.isInPresentationMode) {
  8306. this._setScale(this._currentScaleValue, true);
  8307. }
  8308. const pageView = this._pages[this._currentPageNumber - 1];
  8309. this._scrollIntoView({
  8310. pageDiv: pageView.div
  8311. });
  8312. }
  8313. pageLabelToPageNumber(label) {
  8314. if (!this._pageLabels) {
  8315. return null;
  8316. }
  8317. const i = this._pageLabels.indexOf(label);
  8318. if (i < 0) {
  8319. return null;
  8320. }
  8321. return i + 1;
  8322. }
  8323. scrollPageIntoView({
  8324. pageNumber,
  8325. destArray = null,
  8326. allowNegativeOffset = false,
  8327. ignoreDestinationZoom = false
  8328. }) {
  8329. if (!this.pdfDocument) {
  8330. return;
  8331. }
  8332. const pageView = Number.isInteger(pageNumber) && this._pages[pageNumber - 1];
  8333. if (!pageView) {
  8334. console.error(`${this._name}.scrollPageIntoView: ` + `"${pageNumber}" is not a valid pageNumber parameter.`);
  8335. return;
  8336. }
  8337. if (this.isInPresentationMode || !destArray) {
  8338. this._setCurrentPageNumber(pageNumber, true);
  8339. return;
  8340. }
  8341. let x = 0,
  8342. y = 0;
  8343. let width = 0,
  8344. height = 0,
  8345. widthScale,
  8346. heightScale;
  8347. const changeOrientation = pageView.rotation % 180 !== 0;
  8348. const pageWidth = (changeOrientation ? pageView.height : pageView.width) / pageView.scale / _ui_utils.CSS_UNITS;
  8349. const pageHeight = (changeOrientation ? pageView.width : pageView.height) / pageView.scale / _ui_utils.CSS_UNITS;
  8350. let scale = 0;
  8351. switch (destArray[1].name) {
  8352. case "XYZ":
  8353. x = destArray[2];
  8354. y = destArray[3];
  8355. scale = destArray[4];
  8356. x = x !== null ? x : 0;
  8357. y = y !== null ? y : pageHeight;
  8358. break;
  8359. case "Fit":
  8360. case "FitB":
  8361. scale = "page-fit";
  8362. break;
  8363. case "FitH":
  8364. case "FitBH":
  8365. y = destArray[2];
  8366. scale = "page-width";
  8367. if (y === null && this._location) {
  8368. x = this._location.left;
  8369. y = this._location.top;
  8370. } else if (typeof y !== "number") {
  8371. y = pageHeight;
  8372. }
  8373. break;
  8374. case "FitV":
  8375. case "FitBV":
  8376. x = destArray[2];
  8377. width = pageWidth;
  8378. height = pageHeight;
  8379. scale = "page-height";
  8380. break;
  8381. case "FitR":
  8382. x = destArray[2];
  8383. y = destArray[3];
  8384. width = destArray[4] - x;
  8385. height = destArray[5] - y;
  8386. const hPadding = this.removePageBorders ? 0 : _ui_utils.SCROLLBAR_PADDING;
  8387. const vPadding = this.removePageBorders ? 0 : _ui_utils.VERTICAL_PADDING;
  8388. widthScale = (this.container.clientWidth - hPadding) / width / _ui_utils.CSS_UNITS;
  8389. heightScale = (this.container.clientHeight - vPadding) / height / _ui_utils.CSS_UNITS;
  8390. scale = Math.min(Math.abs(widthScale), Math.abs(heightScale));
  8391. break;
  8392. default:
  8393. console.error(`${this._name}.scrollPageIntoView: ` + `"${destArray[1].name}" is not a valid destination type.`);
  8394. return;
  8395. }
  8396. if (!ignoreDestinationZoom) {
  8397. if (scale && scale !== this._currentScale) {
  8398. this.currentScaleValue = scale;
  8399. } else if (this._currentScale === _ui_utils.UNKNOWN_SCALE) {
  8400. this.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  8401. }
  8402. }
  8403. if (scale === "page-fit" && !destArray[4]) {
  8404. this._scrollIntoView({
  8405. pageDiv: pageView.div,
  8406. pageNumber
  8407. });
  8408. return;
  8409. }
  8410. const boundingRect = [pageView.viewport.convertToViewportPoint(x, y), pageView.viewport.convertToViewportPoint(x + width, y + height)];
  8411. let left = Math.min(boundingRect[0][0], boundingRect[1][0]);
  8412. let top = Math.min(boundingRect[0][1], boundingRect[1][1]);
  8413. if (!allowNegativeOffset) {
  8414. left = Math.max(left, 0);
  8415. top = Math.max(top, 0);
  8416. }
  8417. this._scrollIntoView({
  8418. pageDiv: pageView.div,
  8419. pageSpot: {
  8420. left,
  8421. top
  8422. },
  8423. pageNumber
  8424. });
  8425. }
  8426. _updateLocation(firstPage) {
  8427. const currentScale = this._currentScale;
  8428. const currentScaleValue = this._currentScaleValue;
  8429. const normalizedScaleValue = parseFloat(currentScaleValue) === currentScale ? Math.round(currentScale * 10000) / 100 : currentScaleValue;
  8430. const pageNumber = firstPage.id;
  8431. let pdfOpenParams = "#page=" + pageNumber;
  8432. pdfOpenParams += "&zoom=" + normalizedScaleValue;
  8433. const currentPageView = this._pages[pageNumber - 1];
  8434. const container = this.container;
  8435. const topLeft = currentPageView.getPagePoint(container.scrollLeft - firstPage.x, container.scrollTop - firstPage.y);
  8436. const intLeft = Math.round(topLeft[0]);
  8437. const intTop = Math.round(topLeft[1]);
  8438. pdfOpenParams += "," + intLeft + "," + intTop;
  8439. this._location = {
  8440. pageNumber,
  8441. scale: normalizedScaleValue,
  8442. top: intTop,
  8443. left: intLeft,
  8444. rotation: this._pagesRotation,
  8445. pdfOpenParams
  8446. };
  8447. }
  8448. _updateHelper(visiblePages) {
  8449. throw new Error("Not implemented: _updateHelper");
  8450. }
  8451. update() {
  8452. const visible = this._getVisiblePages();
  8453. const visiblePages = visible.views,
  8454. numVisiblePages = visiblePages.length;
  8455. if (numVisiblePages === 0) {
  8456. return;
  8457. }
  8458. const newCacheSize = Math.max(DEFAULT_CACHE_SIZE, 2 * numVisiblePages + 1);
  8459. this._buffer.resize(newCacheSize, visiblePages);
  8460. this.renderingQueue.renderHighestPriority(visible);
  8461. this._updateHelper(visiblePages);
  8462. this._updateLocation(visible.first);
  8463. this.eventBus.dispatch("updateviewarea", {
  8464. source: this,
  8465. location: this._location
  8466. });
  8467. }
  8468. containsElement(element) {
  8469. return this.container.contains(element);
  8470. }
  8471. focus() {
  8472. this.container.focus();
  8473. }
  8474. get _isScrollModeHorizontal() {
  8475. return this.isInPresentationMode ? false : this._scrollMode === _ui_utils.ScrollMode.HORIZONTAL;
  8476. }
  8477. get _isContainerRtl() {
  8478. return getComputedStyle(this.container).direction === "rtl";
  8479. }
  8480. get isInPresentationMode() {
  8481. return this.presentationModeState === _ui_utils.PresentationModeState.FULLSCREEN;
  8482. }
  8483. get isChangingPresentationMode() {
  8484. return this.presentationModeState === _ui_utils.PresentationModeState.CHANGING;
  8485. }
  8486. get isHorizontalScrollbarEnabled() {
  8487. return this.isInPresentationMode ? false : this.container.scrollWidth > this.container.clientWidth;
  8488. }
  8489. get isVerticalScrollbarEnabled() {
  8490. return this.isInPresentationMode ? false : this.container.scrollHeight > this.container.clientHeight;
  8491. }
  8492. _getCurrentVisiblePage() {
  8493. if (!this.pagesCount) {
  8494. return {
  8495. views: []
  8496. };
  8497. }
  8498. const pageView = this._pages[this._currentPageNumber - 1];
  8499. const element = pageView.div;
  8500. const view = {
  8501. id: pageView.id,
  8502. x: element.offsetLeft + element.clientLeft,
  8503. y: element.offsetTop + element.clientTop,
  8504. view: pageView
  8505. };
  8506. return {
  8507. first: view,
  8508. last: view,
  8509. views: [view]
  8510. };
  8511. }
  8512. _getVisiblePages() {
  8513. return (0, _ui_utils.getVisibleElements)({
  8514. scrollEl: this.container,
  8515. views: this._pages,
  8516. sortByVisibility: true,
  8517. horizontal: this._isScrollModeHorizontal,
  8518. rtl: this._isScrollModeHorizontal && this._isContainerRtl
  8519. });
  8520. }
  8521. isPageVisible(pageNumber) {
  8522. if (!this.pdfDocument) {
  8523. return false;
  8524. }
  8525. if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) {
  8526. console.error(`${this._name}.isPageVisible: "${pageNumber}" is not a valid page.`);
  8527. return false;
  8528. }
  8529. return this._getVisiblePages().views.some(function (view) {
  8530. return view.id === pageNumber;
  8531. });
  8532. }
  8533. isPageCached(pageNumber) {
  8534. if (!this.pdfDocument || !this._buffer) {
  8535. return false;
  8536. }
  8537. if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) {
  8538. console.error(`${this._name}.isPageCached: "${pageNumber}" is not a valid page.`);
  8539. return false;
  8540. }
  8541. const pageView = this._pages[pageNumber - 1];
  8542. if (!pageView) {
  8543. return false;
  8544. }
  8545. return this._buffer.has(pageView);
  8546. }
  8547. cleanup() {
  8548. for (let i = 0, ii = this._pages.length; i < ii; i++) {
  8549. if (this._pages[i] && this._pages[i].renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED) {
  8550. this._pages[i].reset();
  8551. }
  8552. }
  8553. }
  8554. _cancelRendering() {
  8555. for (let i = 0, ii = this._pages.length; i < ii; i++) {
  8556. if (this._pages[i]) {
  8557. this._pages[i].cancelRendering();
  8558. }
  8559. }
  8560. }
  8561. _ensurePdfPageLoaded(pageView) {
  8562. if (pageView.pdfPage) {
  8563. return Promise.resolve(pageView.pdfPage);
  8564. }
  8565. if (this._pagesRequests.has(pageView)) {
  8566. return this._pagesRequests.get(pageView);
  8567. }
  8568. const promise = this.pdfDocument.getPage(pageView.id).then(pdfPage => {
  8569. if (!pageView.pdfPage) {
  8570. pageView.setPdfPage(pdfPage);
  8571. }
  8572. this._pagesRequests.delete(pageView);
  8573. return pdfPage;
  8574. }).catch(reason => {
  8575. console.error("Unable to get page for page view", reason);
  8576. this._pagesRequests.delete(pageView);
  8577. });
  8578. this._pagesRequests.set(pageView, promise);
  8579. return promise;
  8580. }
  8581. forceRendering(currentlyVisiblePages) {
  8582. const visiblePages = currentlyVisiblePages || this._getVisiblePages();
  8583. const scrollAhead = this._isScrollModeHorizontal ? this.scroll.right : this.scroll.down;
  8584. const pageView = this.renderingQueue.getHighestPriority(visiblePages, this._pages, scrollAhead);
  8585. if (pageView) {
  8586. this._ensurePdfPageLoaded(pageView).then(() => {
  8587. this.renderingQueue.renderView(pageView);
  8588. });
  8589. return true;
  8590. }
  8591. return false;
  8592. }
  8593. createTextLayerBuilder(textLayerDiv, pageIndex, viewport, enhanceTextSelection = false, eventBus) {
  8594. return new _text_layer_builder.TextLayerBuilder({
  8595. textLayerDiv,
  8596. eventBus,
  8597. pageIndex,
  8598. viewport,
  8599. findController: this.isInPresentationMode ? null : this.findController,
  8600. enhanceTextSelection: this.isInPresentationMode ? false : enhanceTextSelection
  8601. });
  8602. }
  8603. createAnnotationLayerBuilder(pageDiv, pdfPage, annotationStorage = null, imageResourcesPath = "", renderInteractiveForms = false, l10n = _l10n_utils.NullL10n, enableScripting = false, hasJSActionsPromise = null, mouseState = null) {
  8604. return new _annotation_layer_builder.AnnotationLayerBuilder({
  8605. pageDiv,
  8606. pdfPage,
  8607. annotationStorage: annotationStorage || this.pdfDocument?.annotationStorage,
  8608. imageResourcesPath,
  8609. renderInteractiveForms,
  8610. linkService: this.linkService,
  8611. downloadManager: this.downloadManager,
  8612. l10n,
  8613. enableScripting,
  8614. hasJSActionsPromise: hasJSActionsPromise || this.pdfDocument?.hasJSActions(),
  8615. mouseState: mouseState || this._scriptingManager?.mouseState
  8616. });
  8617. }
  8618. createXfaLayerBuilder(pageDiv, pdfPage) {
  8619. return new _xfa_layer_builder.XfaLayerBuilder({
  8620. pageDiv,
  8621. pdfPage
  8622. });
  8623. }
  8624. get hasEqualPageSizes() {
  8625. const firstPageView = this._pages[0];
  8626. for (let i = 1, ii = this._pages.length; i < ii; ++i) {
  8627. const pageView = this._pages[i];
  8628. if (pageView.width !== firstPageView.width || pageView.height !== firstPageView.height) {
  8629. return false;
  8630. }
  8631. }
  8632. return true;
  8633. }
  8634. getPagesOverview() {
  8635. return this._pages.map(pageView => {
  8636. const viewport = pageView.pdfPage.getViewport({
  8637. scale: 1
  8638. });
  8639. if (!this.enablePrintAutoRotate || (0, _ui_utils.isPortraitOrientation)(viewport)) {
  8640. return {
  8641. width: viewport.width,
  8642. height: viewport.height,
  8643. rotation: viewport.rotation
  8644. };
  8645. }
  8646. return {
  8647. width: viewport.height,
  8648. height: viewport.width,
  8649. rotation: (viewport.rotation - 90) % 360
  8650. };
  8651. });
  8652. }
  8653. get optionalContentConfigPromise() {
  8654. if (!this.pdfDocument) {
  8655. return Promise.resolve(null);
  8656. }
  8657. if (!this._optionalContentConfigPromise) {
  8658. return this.pdfDocument.getOptionalContentConfig();
  8659. }
  8660. return this._optionalContentConfigPromise;
  8661. }
  8662. set optionalContentConfigPromise(promise) {
  8663. if (!(promise instanceof Promise)) {
  8664. throw new Error(`Invalid optionalContentConfigPromise: ${promise}`);
  8665. }
  8666. if (!this.pdfDocument) {
  8667. return;
  8668. }
  8669. if (!this._optionalContentConfigPromise) {
  8670. return;
  8671. }
  8672. this._optionalContentConfigPromise = promise;
  8673. for (const pageView of this._pages) {
  8674. pageView.update(pageView.scale, pageView.rotation, promise);
  8675. }
  8676. this.update();
  8677. this.eventBus.dispatch("optionalcontentconfigchanged", {
  8678. source: this,
  8679. promise
  8680. });
  8681. }
  8682. get scrollMode() {
  8683. return this._scrollMode;
  8684. }
  8685. set scrollMode(mode) {
  8686. if (this._scrollMode === mode) {
  8687. return;
  8688. }
  8689. if (!(0, _ui_utils.isValidScrollMode)(mode)) {
  8690. throw new Error(`Invalid scroll mode: ${mode}`);
  8691. }
  8692. this._scrollMode = mode;
  8693. this.eventBus.dispatch("scrollmodechanged", {
  8694. source: this,
  8695. mode
  8696. });
  8697. this._updateScrollMode(this._currentPageNumber);
  8698. }
  8699. _updateScrollMode(pageNumber = null) {
  8700. const scrollMode = this._scrollMode,
  8701. viewer = this.viewer;
  8702. viewer.classList.toggle("scrollHorizontal", scrollMode === _ui_utils.ScrollMode.HORIZONTAL);
  8703. viewer.classList.toggle("scrollWrapped", scrollMode === _ui_utils.ScrollMode.WRAPPED);
  8704. if (!this.pdfDocument || !pageNumber) {
  8705. return;
  8706. }
  8707. if (this._currentScaleValue && isNaN(this._currentScaleValue)) {
  8708. this._setScale(this._currentScaleValue, true);
  8709. }
  8710. this._setCurrentPageNumber(pageNumber, true);
  8711. this.update();
  8712. }
  8713. get spreadMode() {
  8714. return this._spreadMode;
  8715. }
  8716. set spreadMode(mode) {
  8717. if (this._spreadMode === mode) {
  8718. return;
  8719. }
  8720. if (!(0, _ui_utils.isValidSpreadMode)(mode)) {
  8721. throw new Error(`Invalid spread mode: ${mode}`);
  8722. }
  8723. this._spreadMode = mode;
  8724. this.eventBus.dispatch("spreadmodechanged", {
  8725. source: this,
  8726. mode
  8727. });
  8728. this._updateSpreadMode(this._currentPageNumber);
  8729. }
  8730. _updateSpreadMode(pageNumber = null) {
  8731. if (!this.pdfDocument) {
  8732. return;
  8733. }
  8734. const viewer = this.viewer,
  8735. pages = this._pages;
  8736. viewer.textContent = "";
  8737. if (this._spreadMode === _ui_utils.SpreadMode.NONE) {
  8738. for (let i = 0, iMax = pages.length; i < iMax; ++i) {
  8739. viewer.appendChild(pages[i].div);
  8740. }
  8741. } else {
  8742. const parity = this._spreadMode - 1;
  8743. let spread = null;
  8744. for (let i = 0, iMax = pages.length; i < iMax; ++i) {
  8745. if (spread === null) {
  8746. spread = document.createElement("div");
  8747. spread.className = "spread";
  8748. viewer.appendChild(spread);
  8749. } else if (i % 2 === parity) {
  8750. spread = spread.cloneNode(false);
  8751. viewer.appendChild(spread);
  8752. }
  8753. spread.appendChild(pages[i].div);
  8754. }
  8755. }
  8756. if (!pageNumber) {
  8757. return;
  8758. }
  8759. if (this._currentScaleValue && isNaN(this._currentScaleValue)) {
  8760. this._setScale(this._currentScaleValue, true);
  8761. }
  8762. this._setCurrentPageNumber(pageNumber, true);
  8763. this.update();
  8764. }
  8765. _getPageAdvance(currentPageNumber, previous = false) {
  8766. if (this.isInPresentationMode) {
  8767. return 1;
  8768. }
  8769. switch (this._scrollMode) {
  8770. case _ui_utils.ScrollMode.WRAPPED:
  8771. {
  8772. const {
  8773. views
  8774. } = this._getVisiblePages(),
  8775. pageLayout = new Map();
  8776. for (const {
  8777. id,
  8778. y,
  8779. percent,
  8780. widthPercent
  8781. } of views) {
  8782. if (percent === 0 || widthPercent < 100) {
  8783. continue;
  8784. }
  8785. let yArray = pageLayout.get(y);
  8786. if (!yArray) {
  8787. pageLayout.set(y, yArray || (yArray = []));
  8788. }
  8789. yArray.push(id);
  8790. }
  8791. for (const yArray of pageLayout.values()) {
  8792. const currentIndex = yArray.indexOf(currentPageNumber);
  8793. if (currentIndex === -1) {
  8794. continue;
  8795. }
  8796. const numPages = yArray.length;
  8797. if (numPages === 1) {
  8798. break;
  8799. }
  8800. if (previous) {
  8801. for (let i = currentIndex - 1, ii = 0; i >= ii; i--) {
  8802. const currentId = yArray[i],
  8803. expectedId = yArray[i + 1] - 1;
  8804. if (currentId < expectedId) {
  8805. return currentPageNumber - expectedId;
  8806. }
  8807. }
  8808. } else {
  8809. for (let i = currentIndex + 1, ii = numPages; i < ii; i++) {
  8810. const currentId = yArray[i],
  8811. expectedId = yArray[i - 1] + 1;
  8812. if (currentId > expectedId) {
  8813. return expectedId - currentPageNumber;
  8814. }
  8815. }
  8816. }
  8817. if (previous) {
  8818. const firstId = yArray[0];
  8819. if (firstId < currentPageNumber) {
  8820. return currentPageNumber - firstId + 1;
  8821. }
  8822. } else {
  8823. const lastId = yArray[numPages - 1];
  8824. if (lastId > currentPageNumber) {
  8825. return lastId - currentPageNumber + 1;
  8826. }
  8827. }
  8828. break;
  8829. }
  8830. break;
  8831. }
  8832. case _ui_utils.ScrollMode.HORIZONTAL:
  8833. {
  8834. break;
  8835. }
  8836. case _ui_utils.ScrollMode.VERTICAL:
  8837. {
  8838. if (this._spreadMode === _ui_utils.SpreadMode.NONE) {
  8839. break;
  8840. }
  8841. const parity = this._spreadMode - 1;
  8842. if (previous && currentPageNumber % 2 !== parity) {
  8843. break;
  8844. } else if (!previous && currentPageNumber % 2 === parity) {
  8845. break;
  8846. }
  8847. const {
  8848. views
  8849. } = this._getVisiblePages(),
  8850. expectedId = previous ? currentPageNumber - 1 : currentPageNumber + 1;
  8851. for (const {
  8852. id,
  8853. percent,
  8854. widthPercent
  8855. } of views) {
  8856. if (id !== expectedId) {
  8857. continue;
  8858. }
  8859. if (percent > 0 && widthPercent === 100) {
  8860. return 2;
  8861. }
  8862. break;
  8863. }
  8864. break;
  8865. }
  8866. }
  8867. return 1;
  8868. }
  8869. nextPage() {
  8870. const currentPageNumber = this._currentPageNumber,
  8871. pagesCount = this.pagesCount;
  8872. if (currentPageNumber >= pagesCount) {
  8873. return false;
  8874. }
  8875. const advance = this._getPageAdvance(currentPageNumber, false) || 1;
  8876. this.currentPageNumber = Math.min(currentPageNumber + advance, pagesCount);
  8877. return true;
  8878. }
  8879. previousPage() {
  8880. const currentPageNumber = this._currentPageNumber;
  8881. if (currentPageNumber <= 1) {
  8882. return false;
  8883. }
  8884. const advance = this._getPageAdvance(currentPageNumber, true) || 1;
  8885. this.currentPageNumber = Math.max(currentPageNumber - advance, 1);
  8886. return true;
  8887. }
  8888. }
  8889. exports.BaseViewer = BaseViewer;
  8890. /***/ }),
  8891. /* 29 */
  8892. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  8893. Object.defineProperty(exports, "__esModule", ({
  8894. value: true
  8895. }));
  8896. exports.DefaultAnnotationLayerFactory = exports.AnnotationLayerBuilder = void 0;
  8897. var _pdfjsLib = __webpack_require__(5);
  8898. var _l10n_utils = __webpack_require__(30);
  8899. var _pdf_link_service = __webpack_require__(19);
  8900. class AnnotationLayerBuilder {
  8901. constructor({
  8902. pageDiv,
  8903. pdfPage,
  8904. linkService,
  8905. downloadManager,
  8906. annotationStorage = null,
  8907. imageResourcesPath = "",
  8908. renderInteractiveForms = true,
  8909. l10n = _l10n_utils.NullL10n,
  8910. enableScripting = false,
  8911. hasJSActionsPromise = null,
  8912. mouseState = null
  8913. }) {
  8914. this.pageDiv = pageDiv;
  8915. this.pdfPage = pdfPage;
  8916. this.linkService = linkService;
  8917. this.downloadManager = downloadManager;
  8918. this.imageResourcesPath = imageResourcesPath;
  8919. this.renderInteractiveForms = renderInteractiveForms;
  8920. this.l10n = l10n;
  8921. this.annotationStorage = annotationStorage;
  8922. this.enableScripting = enableScripting;
  8923. this._hasJSActionsPromise = hasJSActionsPromise;
  8924. this._mouseState = mouseState;
  8925. this.div = null;
  8926. this._cancelled = false;
  8927. }
  8928. render(viewport, intent = "display") {
  8929. return Promise.all([this.pdfPage.getAnnotations({
  8930. intent
  8931. }), this._hasJSActionsPromise]).then(([annotations, hasJSActions = false]) => {
  8932. if (this._cancelled) {
  8933. return;
  8934. }
  8935. if (annotations.length === 0) {
  8936. return;
  8937. }
  8938. const parameters = {
  8939. viewport: viewport.clone({
  8940. dontFlip: true
  8941. }),
  8942. div: this.div,
  8943. annotations,
  8944. page: this.pdfPage,
  8945. imageResourcesPath: this.imageResourcesPath,
  8946. renderInteractiveForms: this.renderInteractiveForms,
  8947. linkService: this.linkService,
  8948. downloadManager: this.downloadManager,
  8949. annotationStorage: this.annotationStorage,
  8950. enableScripting: this.enableScripting,
  8951. hasJSActions,
  8952. mouseState: this._mouseState
  8953. };
  8954. if (this.div) {
  8955. _pdfjsLib.AnnotationLayer.update(parameters);
  8956. } else {
  8957. this.div = document.createElement("div");
  8958. this.div.className = "annotationLayer";
  8959. this.pageDiv.appendChild(this.div);
  8960. parameters.div = this.div;
  8961. _pdfjsLib.AnnotationLayer.render(parameters);
  8962. this.l10n.translate(this.div);
  8963. }
  8964. });
  8965. }
  8966. cancel() {
  8967. this._cancelled = true;
  8968. }
  8969. hide() {
  8970. if (!this.div) {
  8971. return;
  8972. }
  8973. this.div.hidden = true;
  8974. }
  8975. }
  8976. exports.AnnotationLayerBuilder = AnnotationLayerBuilder;
  8977. class DefaultAnnotationLayerFactory {
  8978. createAnnotationLayerBuilder(pageDiv, pdfPage, annotationStorage = null, imageResourcesPath = "", renderInteractiveForms = true, l10n = _l10n_utils.NullL10n, enableScripting = false, hasJSActionsPromise = null, mouseState = null) {
  8979. return new AnnotationLayerBuilder({
  8980. pageDiv,
  8981. pdfPage,
  8982. imageResourcesPath,
  8983. renderInteractiveForms,
  8984. linkService: new _pdf_link_service.SimpleLinkService(),
  8985. l10n,
  8986. annotationStorage,
  8987. enableScripting,
  8988. hasJSActionsPromise,
  8989. mouseState
  8990. });
  8991. }
  8992. }
  8993. exports.DefaultAnnotationLayerFactory = DefaultAnnotationLayerFactory;
  8994. /***/ }),
  8995. /* 30 */
  8996. /***/ ((__unused_webpack_module, exports) => {
  8997. Object.defineProperty(exports, "__esModule", ({
  8998. value: true
  8999. }));
  9000. exports.getL10nFallback = getL10nFallback;
  9001. exports.NullL10n = void 0;
  9002. const DEFAULT_L10N_STRINGS = {
  9003. of_pages: "of {{pagesCount}}",
  9004. page_of_pages: "({{pageNumber}} of {{pagesCount}})",
  9005. document_properties_kb: "{{size_kb}} KB ({{size_b}} bytes)",
  9006. document_properties_mb: "{{size_mb}} MB ({{size_b}} bytes)",
  9007. document_properties_date_string: "{{date}}, {{time}}",
  9008. document_properties_page_size_unit_inches: "in",
  9009. document_properties_page_size_unit_millimeters: "mm",
  9010. document_properties_page_size_orientation_portrait: "portrait",
  9011. document_properties_page_size_orientation_landscape: "landscape",
  9012. document_properties_page_size_name_a3: "A3",
  9013. document_properties_page_size_name_a4: "A4",
  9014. document_properties_page_size_name_letter: "Letter",
  9015. document_properties_page_size_name_legal: "Legal",
  9016. document_properties_page_size_dimension_string: "{{width}} × {{height}} {{unit}} ({{orientation}})",
  9017. document_properties_page_size_dimension_name_string: "{{width}} × {{height}} {{unit}} ({{name}}, {{orientation}})",
  9018. document_properties_linearized_yes: "Yes",
  9019. document_properties_linearized_no: "No",
  9020. print_progress_percent: "{{progress}}%",
  9021. "toggle_sidebar.title": "Toggle Sidebar",
  9022. "toggle_sidebar_notification2.title": "Toggle Sidebar (document contains outline/attachments/layers)",
  9023. additional_layers: "Additional Layers",
  9024. page_landmark: "Page {{page}}",
  9025. thumb_page_title: "Page {{page}}",
  9026. thumb_page_canvas: "Thumbnail of Page {{page}}",
  9027. find_reached_top: "Reached top of document, continued from bottom",
  9028. find_reached_bottom: "Reached end of document, continued from top",
  9029. "find_match_count[one]": "{{current}} of {{total}} match",
  9030. "find_match_count[other]": "{{current}} of {{total}} matches",
  9031. "find_match_count_limit[one]": "More than {{limit}} match",
  9032. "find_match_count_limit[other]": "More than {{limit}} matches",
  9033. find_not_found: "Phrase not found",
  9034. error_version_info: "PDF.js v{{version}} (build: {{build}})",
  9035. error_message: "Message: {{message}}",
  9036. error_stack: "Stack: {{stack}}",
  9037. error_file: "File: {{file}}",
  9038. error_line: "Line: {{line}}",
  9039. rendering_error: "An error occurred while rendering the page.",
  9040. page_scale_width: "Page Width",
  9041. page_scale_fit: "Page Fit",
  9042. page_scale_auto: "Automatic Zoom",
  9043. page_scale_actual: "Actual Size",
  9044. page_scale_percent: "{{scale}}%",
  9045. loading: "Loading…",
  9046. loading_error: "An error occurred while loading the PDF.",
  9047. invalid_file_error: "Invalid or corrupted PDF file.",
  9048. missing_file_error: "Missing PDF file.",
  9049. unexpected_response_error: "Unexpected server response.",
  9050. printing_not_supported: "Warning: Printing is not fully supported by this browser.",
  9051. printing_not_ready: "Warning: The PDF is not fully loaded for printing.",
  9052. web_fonts_disabled: "Web fonts are disabled: unable to use embedded PDF fonts."
  9053. };
  9054. function getL10nFallback(key, args) {
  9055. switch (key) {
  9056. case "find_match_count":
  9057. key = `find_match_count[${args.total === 1 ? "one" : "other"}]`;
  9058. break;
  9059. case "find_match_count_limit":
  9060. key = `find_match_count_limit[${args.limit === 1 ? "one" : "other"}]`;
  9061. break;
  9062. }
  9063. return DEFAULT_L10N_STRINGS[key] || "";
  9064. }
  9065. function formatL10nValue(text, args) {
  9066. if (!args) {
  9067. return text;
  9068. }
  9069. return text.replace(/\{\{\s*(\w+)\s*\}\}/g, (all, name) => {
  9070. return name in args ? args[name] : "{{" + name + "}}";
  9071. });
  9072. }
  9073. const NullL10n = {
  9074. async getLanguage() {
  9075. return "en-us";
  9076. },
  9077. async getDirection() {
  9078. return "ltr";
  9079. },
  9080. async get(key, args = null, fallback = getL10nFallback(key, args)) {
  9081. return formatL10nValue(fallback, args);
  9082. },
  9083. async translate(element) {}
  9084. };
  9085. exports.NullL10n = NullL10n;
  9086. /***/ }),
  9087. /* 31 */
  9088. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  9089. Object.defineProperty(exports, "__esModule", ({
  9090. value: true
  9091. }));
  9092. exports.PDFPageView = void 0;
  9093. var _ui_utils = __webpack_require__(4);
  9094. var _pdfjsLib = __webpack_require__(5);
  9095. var _l10n_utils = __webpack_require__(30);
  9096. var _pdf_rendering_queue = __webpack_require__(8);
  9097. var _viewer_compatibility = __webpack_require__(2);
  9098. const MAX_CANVAS_PIXELS = _viewer_compatibility.viewerCompatibilityParams.maxCanvasPixels || 16777216;
  9099. class PDFPageView {
  9100. constructor(options) {
  9101. const container = options.container;
  9102. const defaultViewport = options.defaultViewport;
  9103. this.id = options.id;
  9104. this.renderingId = "page" + this.id;
  9105. this.pdfPage = null;
  9106. this.pageLabel = null;
  9107. this.rotation = 0;
  9108. this.scale = options.scale || _ui_utils.DEFAULT_SCALE;
  9109. this.viewport = defaultViewport;
  9110. this.pdfPageRotate = defaultViewport.rotation;
  9111. this._optionalContentConfigPromise = options.optionalContentConfigPromise || null;
  9112. this.hasRestrictedScaling = false;
  9113. this.textLayerMode = Number.isInteger(options.textLayerMode) ? options.textLayerMode : _ui_utils.TextLayerMode.ENABLE;
  9114. this.imageResourcesPath = options.imageResourcesPath || "";
  9115. this.renderInteractiveForms = options.renderInteractiveForms !== false;
  9116. this.useOnlyCssZoom = options.useOnlyCssZoom || false;
  9117. this.maxCanvasPixels = options.maxCanvasPixels || MAX_CANVAS_PIXELS;
  9118. this.eventBus = options.eventBus;
  9119. this.renderingQueue = options.renderingQueue;
  9120. this.textLayerFactory = options.textLayerFactory;
  9121. this.annotationLayerFactory = options.annotationLayerFactory;
  9122. this.xfaLayerFactory = options.xfaLayerFactory;
  9123. this.renderer = options.renderer || _ui_utils.RendererType.CANVAS;
  9124. this.enableWebGL = options.enableWebGL || false;
  9125. this.l10n = options.l10n || _l10n_utils.NullL10n;
  9126. this.enableScripting = options.enableScripting === true;
  9127. this.paintTask = null;
  9128. this.paintedViewportMap = new WeakMap();
  9129. this.renderingState = _pdf_rendering_queue.RenderingStates.INITIAL;
  9130. this.resume = null;
  9131. this._renderError = null;
  9132. this.annotationLayer = null;
  9133. this.textLayer = null;
  9134. this.zoomLayer = null;
  9135. this.xfaLayer = null;
  9136. const div = document.createElement("div");
  9137. div.className = "page";
  9138. div.style.width = Math.floor(this.viewport.width) + "px";
  9139. div.style.height = Math.floor(this.viewport.height) + "px";
  9140. div.setAttribute("data-page-number", this.id);
  9141. div.setAttribute("role", "region");
  9142. this.l10n.get("page_landmark", {
  9143. page: this.id
  9144. }).then(msg => {
  9145. div.setAttribute("aria-label", msg);
  9146. });
  9147. this.div = div;
  9148. container.appendChild(div);
  9149. }
  9150. setPdfPage(pdfPage) {
  9151. this.pdfPage = pdfPage;
  9152. this.pdfPageRotate = pdfPage.rotate;
  9153. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  9154. this.viewport = pdfPage.getViewport({
  9155. scale: this.scale * _ui_utils.CSS_UNITS,
  9156. rotation: totalRotation
  9157. });
  9158. this.reset();
  9159. }
  9160. destroy() {
  9161. this.reset();
  9162. if (this.pdfPage) {
  9163. this.pdfPage.cleanup();
  9164. }
  9165. }
  9166. async _renderAnnotationLayer() {
  9167. let error = null;
  9168. try {
  9169. await this.annotationLayer.render(this.viewport, "display");
  9170. } catch (ex) {
  9171. error = ex;
  9172. } finally {
  9173. this.eventBus.dispatch("annotationlayerrendered", {
  9174. source: this,
  9175. pageNumber: this.id,
  9176. error
  9177. });
  9178. }
  9179. }
  9180. async _renderXfaLayer() {
  9181. let error = null;
  9182. try {
  9183. await this.xfaLayer.render(this.viewport, "display");
  9184. } catch (ex) {
  9185. error = ex;
  9186. } finally {
  9187. this.eventBus.dispatch("xfalayerrendered", {
  9188. source: this,
  9189. pageNumber: this.id,
  9190. error
  9191. });
  9192. }
  9193. }
  9194. _resetZoomLayer(removeFromDOM = false) {
  9195. if (!this.zoomLayer) {
  9196. return;
  9197. }
  9198. const zoomLayerCanvas = this.zoomLayer.firstChild;
  9199. this.paintedViewportMap.delete(zoomLayerCanvas);
  9200. zoomLayerCanvas.width = 0;
  9201. zoomLayerCanvas.height = 0;
  9202. if (removeFromDOM) {
  9203. this.zoomLayer.remove();
  9204. }
  9205. this.zoomLayer = null;
  9206. }
  9207. reset(keepZoomLayer = false, keepAnnotations = false) {
  9208. this.cancelRendering(keepAnnotations);
  9209. this.renderingState = _pdf_rendering_queue.RenderingStates.INITIAL;
  9210. const div = this.div;
  9211. div.style.width = Math.floor(this.viewport.width) + "px";
  9212. div.style.height = Math.floor(this.viewport.height) + "px";
  9213. const childNodes = div.childNodes;
  9214. const currentZoomLayerNode = keepZoomLayer && this.zoomLayer || null;
  9215. const currentAnnotationNode = keepAnnotations && this.annotationLayer?.div || null;
  9216. const currentXfaLayerNode = this.xfaLayer?.div || null;
  9217. for (let i = childNodes.length - 1; i >= 0; i--) {
  9218. const node = childNodes[i];
  9219. if (currentZoomLayerNode === node || currentAnnotationNode === node || currentXfaLayerNode === node) {
  9220. continue;
  9221. }
  9222. div.removeChild(node);
  9223. }
  9224. div.removeAttribute("data-loaded");
  9225. if (currentAnnotationNode) {
  9226. this.annotationLayer.hide();
  9227. } else if (this.annotationLayer) {
  9228. this.annotationLayer.cancel();
  9229. this.annotationLayer = null;
  9230. }
  9231. if (!currentZoomLayerNode) {
  9232. if (this.canvas) {
  9233. this.paintedViewportMap.delete(this.canvas);
  9234. this.canvas.width = 0;
  9235. this.canvas.height = 0;
  9236. delete this.canvas;
  9237. }
  9238. this._resetZoomLayer();
  9239. }
  9240. if (this.svg) {
  9241. this.paintedViewportMap.delete(this.svg);
  9242. delete this.svg;
  9243. }
  9244. this.loadingIconDiv = document.createElement("div");
  9245. this.loadingIconDiv.className = "loadingIcon";
  9246. this.loadingIconDiv.setAttribute("role", "img");
  9247. this.l10n.get("loading").then(msg => {
  9248. this.loadingIconDiv?.setAttribute("aria-label", msg);
  9249. });
  9250. div.appendChild(this.loadingIconDiv);
  9251. }
  9252. update(scale, rotation, optionalContentConfigPromise = null) {
  9253. this.scale = scale || this.scale;
  9254. if (typeof rotation !== "undefined") {
  9255. this.rotation = rotation;
  9256. }
  9257. if (optionalContentConfigPromise instanceof Promise) {
  9258. this._optionalContentConfigPromise = optionalContentConfigPromise;
  9259. }
  9260. const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  9261. this.viewport = this.viewport.clone({
  9262. scale: this.scale * _ui_utils.CSS_UNITS,
  9263. rotation: totalRotation
  9264. });
  9265. if (this.svg) {
  9266. this.cssTransform(this.svg, true);
  9267. this.eventBus.dispatch("pagerendered", {
  9268. source: this,
  9269. pageNumber: this.id,
  9270. cssTransform: true,
  9271. timestamp: performance.now(),
  9272. error: this._renderError
  9273. });
  9274. return;
  9275. }
  9276. let isScalingRestricted = false;
  9277. if (this.canvas && this.maxCanvasPixels > 0) {
  9278. const outputScale = this.outputScale;
  9279. if ((Math.floor(this.viewport.width) * outputScale.sx | 0) * (Math.floor(this.viewport.height) * outputScale.sy | 0) > this.maxCanvasPixels) {
  9280. isScalingRestricted = true;
  9281. }
  9282. }
  9283. if (this.canvas) {
  9284. if (this.useOnlyCssZoom || this.hasRestrictedScaling && isScalingRestricted) {
  9285. this.cssTransform(this.canvas, true);
  9286. this.eventBus.dispatch("pagerendered", {
  9287. source: this,
  9288. pageNumber: this.id,
  9289. cssTransform: true,
  9290. timestamp: performance.now(),
  9291. error: this._renderError
  9292. });
  9293. return;
  9294. }
  9295. if (!this.zoomLayer && !this.canvas.hidden) {
  9296. this.zoomLayer = this.canvas.parentNode;
  9297. this.zoomLayer.style.position = "absolute";
  9298. }
  9299. }
  9300. if (this.zoomLayer) {
  9301. this.cssTransform(this.zoomLayer.firstChild);
  9302. }
  9303. this.reset(true, true);
  9304. }
  9305. cancelRendering(keepAnnotations = false) {
  9306. if (this.paintTask) {
  9307. this.paintTask.cancel();
  9308. this.paintTask = null;
  9309. }
  9310. this.resume = null;
  9311. if (this.textLayer) {
  9312. this.textLayer.cancel();
  9313. this.textLayer = null;
  9314. }
  9315. if (!keepAnnotations && this.annotationLayer) {
  9316. this.annotationLayer.cancel();
  9317. this.annotationLayer = null;
  9318. }
  9319. }
  9320. cssTransform(target, redrawAnnotations = false) {
  9321. const width = this.viewport.width;
  9322. const height = this.viewport.height;
  9323. const div = this.div;
  9324. target.style.width = target.parentNode.style.width = div.style.width = Math.floor(width) + "px";
  9325. target.style.height = target.parentNode.style.height = div.style.height = Math.floor(height) + "px";
  9326. const relativeRotation = this.viewport.rotation - this.paintedViewportMap.get(target).rotation;
  9327. const absRotation = Math.abs(relativeRotation);
  9328. let scaleX = 1,
  9329. scaleY = 1;
  9330. if (absRotation === 90 || absRotation === 270) {
  9331. scaleX = height / width;
  9332. scaleY = width / height;
  9333. }
  9334. target.style.transform = `rotate(${relativeRotation}deg) scale(${scaleX}, ${scaleY})`;
  9335. if (this.textLayer) {
  9336. const textLayerViewport = this.textLayer.viewport;
  9337. const textRelativeRotation = this.viewport.rotation - textLayerViewport.rotation;
  9338. const textAbsRotation = Math.abs(textRelativeRotation);
  9339. let scale = width / textLayerViewport.width;
  9340. if (textAbsRotation === 90 || textAbsRotation === 270) {
  9341. scale = width / textLayerViewport.height;
  9342. }
  9343. const textLayerDiv = this.textLayer.textLayerDiv;
  9344. let transX, transY;
  9345. switch (textAbsRotation) {
  9346. case 0:
  9347. transX = transY = 0;
  9348. break;
  9349. case 90:
  9350. transX = 0;
  9351. transY = "-" + textLayerDiv.style.height;
  9352. break;
  9353. case 180:
  9354. transX = "-" + textLayerDiv.style.width;
  9355. transY = "-" + textLayerDiv.style.height;
  9356. break;
  9357. case 270:
  9358. transX = "-" + textLayerDiv.style.width;
  9359. transY = 0;
  9360. break;
  9361. default:
  9362. console.error("Bad rotation value.");
  9363. break;
  9364. }
  9365. textLayerDiv.style.transform = `rotate(${textAbsRotation}deg) ` + `scale(${scale}) ` + `translate(${transX}, ${transY})`;
  9366. textLayerDiv.style.transformOrigin = "0% 0%";
  9367. }
  9368. if (redrawAnnotations && this.annotationLayer) {
  9369. this._renderAnnotationLayer();
  9370. }
  9371. if (this.xfaLayer) {
  9372. this._renderXfaLayer();
  9373. }
  9374. }
  9375. get width() {
  9376. return this.viewport.width;
  9377. }
  9378. get height() {
  9379. return this.viewport.height;
  9380. }
  9381. getPagePoint(x, y) {
  9382. return this.viewport.convertToPdfPoint(x, y);
  9383. }
  9384. draw() {
  9385. if (this.renderingState !== _pdf_rendering_queue.RenderingStates.INITIAL) {
  9386. console.error("Must be in new state before drawing");
  9387. this.reset();
  9388. }
  9389. const {
  9390. div,
  9391. pdfPage
  9392. } = this;
  9393. if (!pdfPage) {
  9394. this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
  9395. if (this.loadingIconDiv) {
  9396. div.removeChild(this.loadingIconDiv);
  9397. delete this.loadingIconDiv;
  9398. }
  9399. return Promise.reject(new Error("pdfPage is not loaded"));
  9400. }
  9401. this.renderingState = _pdf_rendering_queue.RenderingStates.RUNNING;
  9402. const canvasWrapper = document.createElement("div");
  9403. canvasWrapper.style.width = div.style.width;
  9404. canvasWrapper.style.height = div.style.height;
  9405. canvasWrapper.classList.add("canvasWrapper");
  9406. if (this.annotationLayer?.div) {
  9407. div.insertBefore(canvasWrapper, this.annotationLayer.div);
  9408. } else {
  9409. div.appendChild(canvasWrapper);
  9410. }
  9411. let textLayer = null;
  9412. if (this.textLayerMode !== _ui_utils.TextLayerMode.DISABLE && this.textLayerFactory) {
  9413. const textLayerDiv = document.createElement("div");
  9414. textLayerDiv.className = "textLayer";
  9415. textLayerDiv.style.width = canvasWrapper.style.width;
  9416. textLayerDiv.style.height = canvasWrapper.style.height;
  9417. if (this.annotationLayer?.div) {
  9418. div.insertBefore(textLayerDiv, this.annotationLayer.div);
  9419. } else {
  9420. div.appendChild(textLayerDiv);
  9421. }
  9422. textLayer = this.textLayerFactory.createTextLayerBuilder(textLayerDiv, this.id - 1, this.viewport, this.textLayerMode === _ui_utils.TextLayerMode.ENABLE_ENHANCE, this.eventBus);
  9423. }
  9424. this.textLayer = textLayer;
  9425. let renderContinueCallback = null;
  9426. if (this.renderingQueue) {
  9427. renderContinueCallback = cont => {
  9428. if (!this.renderingQueue.isHighestPriority(this)) {
  9429. this.renderingState = _pdf_rendering_queue.RenderingStates.PAUSED;
  9430. this.resume = () => {
  9431. this.renderingState = _pdf_rendering_queue.RenderingStates.RUNNING;
  9432. cont();
  9433. };
  9434. return;
  9435. }
  9436. cont();
  9437. };
  9438. }
  9439. const finishPaintTask = async (error = null) => {
  9440. if (paintTask === this.paintTask) {
  9441. this.paintTask = null;
  9442. }
  9443. if (error instanceof _pdfjsLib.RenderingCancelledException) {
  9444. this._renderError = null;
  9445. return;
  9446. }
  9447. this._renderError = error;
  9448. this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
  9449. if (this.loadingIconDiv) {
  9450. div.removeChild(this.loadingIconDiv);
  9451. delete this.loadingIconDiv;
  9452. }
  9453. this._resetZoomLayer(true);
  9454. this.eventBus.dispatch("pagerendered", {
  9455. source: this,
  9456. pageNumber: this.id,
  9457. cssTransform: false,
  9458. timestamp: performance.now(),
  9459. error: this._renderError
  9460. });
  9461. if (error) {
  9462. throw error;
  9463. }
  9464. };
  9465. const paintTask = this.renderer === _ui_utils.RendererType.SVG ? this.paintOnSvg(canvasWrapper) : this.paintOnCanvas(canvasWrapper);
  9466. paintTask.onRenderContinue = renderContinueCallback;
  9467. this.paintTask = paintTask;
  9468. const resultPromise = paintTask.promise.then(function () {
  9469. return finishPaintTask(null).then(function () {
  9470. if (textLayer) {
  9471. const readableStream = pdfPage.streamTextContent({
  9472. normalizeWhitespace: true
  9473. });
  9474. textLayer.setTextContentStream(readableStream);
  9475. textLayer.render();
  9476. }
  9477. });
  9478. }, function (reason) {
  9479. return finishPaintTask(reason);
  9480. });
  9481. if (this.annotationLayerFactory) {
  9482. if (!this.annotationLayer) {
  9483. this.annotationLayer = this.annotationLayerFactory.createAnnotationLayerBuilder(div, pdfPage, null, this.imageResourcesPath, this.renderInteractiveForms, this.l10n, this.enableScripting, null, null);
  9484. }
  9485. this._renderAnnotationLayer();
  9486. }
  9487. if (this.xfaLayerFactory) {
  9488. if (!this.xfaLayer) {
  9489. this.xfaLayer = this.xfaLayerFactory.createXfaLayerBuilder(div, pdfPage);
  9490. }
  9491. this._renderXfaLayer();
  9492. }
  9493. div.setAttribute("data-loaded", true);
  9494. this.eventBus.dispatch("pagerender", {
  9495. source: this,
  9496. pageNumber: this.id
  9497. });
  9498. return resultPromise;
  9499. }
  9500. paintOnCanvas(canvasWrapper) {
  9501. const renderCapability = (0, _pdfjsLib.createPromiseCapability)();
  9502. const result = {
  9503. promise: renderCapability.promise,
  9504. onRenderContinue(cont) {
  9505. cont();
  9506. },
  9507. cancel() {
  9508. renderTask.cancel();
  9509. }
  9510. };
  9511. const viewport = this.viewport;
  9512. const canvas = document.createElement("canvas");
  9513. canvas.hidden = true;
  9514. let isCanvasHidden = true;
  9515. const showCanvas = function () {
  9516. if (isCanvasHidden) {
  9517. canvas.hidden = false;
  9518. isCanvasHidden = false;
  9519. }
  9520. };
  9521. canvasWrapper.appendChild(canvas);
  9522. this.canvas = canvas;
  9523. canvas.mozOpaque = true;
  9524. const ctx = canvas.getContext("2d", {
  9525. alpha: false
  9526. });
  9527. const outputScale = (0, _ui_utils.getOutputScale)(ctx);
  9528. this.outputScale = outputScale;
  9529. if (this.useOnlyCssZoom) {
  9530. const actualSizeViewport = viewport.clone({
  9531. scale: _ui_utils.CSS_UNITS
  9532. });
  9533. outputScale.sx *= actualSizeViewport.width / viewport.width;
  9534. outputScale.sy *= actualSizeViewport.height / viewport.height;
  9535. outputScale.scaled = true;
  9536. }
  9537. if (this.maxCanvasPixels > 0) {
  9538. const pixelsInViewport = viewport.width * viewport.height;
  9539. const maxScale = Math.sqrt(this.maxCanvasPixels / pixelsInViewport);
  9540. if (outputScale.sx > maxScale || outputScale.sy > maxScale) {
  9541. outputScale.sx = maxScale;
  9542. outputScale.sy = maxScale;
  9543. outputScale.scaled = true;
  9544. this.hasRestrictedScaling = true;
  9545. } else {
  9546. this.hasRestrictedScaling = false;
  9547. }
  9548. }
  9549. const sfx = (0, _ui_utils.approximateFraction)(outputScale.sx);
  9550. const sfy = (0, _ui_utils.approximateFraction)(outputScale.sy);
  9551. canvas.width = (0, _ui_utils.roundToDivide)(viewport.width * outputScale.sx, sfx[0]);
  9552. canvas.height = (0, _ui_utils.roundToDivide)(viewport.height * outputScale.sy, sfy[0]);
  9553. canvas.style.width = (0, _ui_utils.roundToDivide)(viewport.width, sfx[1]) + "px";
  9554. canvas.style.height = (0, _ui_utils.roundToDivide)(viewport.height, sfy[1]) + "px";
  9555. this.paintedViewportMap.set(canvas, viewport);
  9556. const transform = !outputScale.scaled ? null : [outputScale.sx, 0, 0, outputScale.sy, 0, 0];
  9557. const renderContext = {
  9558. canvasContext: ctx,
  9559. transform,
  9560. viewport: this.viewport,
  9561. enableWebGL: this.enableWebGL,
  9562. renderInteractiveForms: this.renderInteractiveForms,
  9563. optionalContentConfigPromise: this._optionalContentConfigPromise
  9564. };
  9565. const renderTask = this.pdfPage.render(renderContext);
  9566. renderTask.onContinue = function (cont) {
  9567. showCanvas();
  9568. if (result.onRenderContinue) {
  9569. result.onRenderContinue(cont);
  9570. } else {
  9571. cont();
  9572. }
  9573. };
  9574. renderTask.promise.then(function () {
  9575. showCanvas();
  9576. renderCapability.resolve(undefined);
  9577. }, function (error) {
  9578. showCanvas();
  9579. renderCapability.reject(error);
  9580. });
  9581. return result;
  9582. }
  9583. paintOnSvg(wrapper) {
  9584. let cancelled = false;
  9585. const ensureNotCancelled = () => {
  9586. if (cancelled) {
  9587. throw new _pdfjsLib.RenderingCancelledException(`Rendering cancelled, page ${this.id}`, "svg");
  9588. }
  9589. };
  9590. const pdfPage = this.pdfPage;
  9591. const actualSizeViewport = this.viewport.clone({
  9592. scale: _ui_utils.CSS_UNITS
  9593. });
  9594. const promise = pdfPage.getOperatorList().then(opList => {
  9595. ensureNotCancelled();
  9596. const svgGfx = new _pdfjsLib.SVGGraphics(pdfPage.commonObjs, pdfPage.objs, _viewer_compatibility.viewerCompatibilityParams.disableCreateObjectURL);
  9597. return svgGfx.getSVG(opList, actualSizeViewport).then(svg => {
  9598. ensureNotCancelled();
  9599. this.svg = svg;
  9600. this.paintedViewportMap.set(svg, actualSizeViewport);
  9601. svg.style.width = wrapper.style.width;
  9602. svg.style.height = wrapper.style.height;
  9603. this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
  9604. wrapper.appendChild(svg);
  9605. });
  9606. });
  9607. return {
  9608. promise,
  9609. onRenderContinue(cont) {
  9610. cont();
  9611. },
  9612. cancel() {
  9613. cancelled = true;
  9614. }
  9615. };
  9616. }
  9617. setPageLabel(label) {
  9618. this.pageLabel = typeof label === "string" ? label : null;
  9619. if (this.pageLabel !== null) {
  9620. this.div.setAttribute("data-page-label", this.pageLabel);
  9621. } else {
  9622. this.div.removeAttribute("data-page-label");
  9623. }
  9624. }
  9625. }
  9626. exports.PDFPageView = PDFPageView;
  9627. /***/ }),
  9628. /* 32 */
  9629. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  9630. Object.defineProperty(exports, "__esModule", ({
  9631. value: true
  9632. }));
  9633. exports.TextLayerBuilder = exports.DefaultTextLayerFactory = void 0;
  9634. var _pdfjsLib = __webpack_require__(5);
  9635. const EXPAND_DIVS_TIMEOUT = 300;
  9636. class TextLayerBuilder {
  9637. constructor({
  9638. textLayerDiv,
  9639. eventBus,
  9640. pageIndex,
  9641. viewport,
  9642. findController = null,
  9643. enhanceTextSelection = false
  9644. }) {
  9645. this.textLayerDiv = textLayerDiv;
  9646. this.eventBus = eventBus;
  9647. this.textContent = null;
  9648. this.textContentItemsStr = [];
  9649. this.textContentStream = null;
  9650. this.renderingDone = false;
  9651. this.pageIdx = pageIndex;
  9652. this.pageNumber = this.pageIdx + 1;
  9653. this.matches = [];
  9654. this.viewport = viewport;
  9655. this.textDivs = [];
  9656. this.findController = findController;
  9657. this.textLayerRenderTask = null;
  9658. this.enhanceTextSelection = enhanceTextSelection;
  9659. this._onUpdateTextLayerMatches = null;
  9660. this._bindMouse();
  9661. }
  9662. _finishRendering() {
  9663. this.renderingDone = true;
  9664. if (!this.enhanceTextSelection) {
  9665. const endOfContent = document.createElement("div");
  9666. endOfContent.className = "endOfContent";
  9667. this.textLayerDiv.appendChild(endOfContent);
  9668. }
  9669. this.eventBus.dispatch("textlayerrendered", {
  9670. source: this,
  9671. pageNumber: this.pageNumber,
  9672. numTextDivs: this.textDivs.length
  9673. });
  9674. }
  9675. render(timeout = 0) {
  9676. if (!(this.textContent || this.textContentStream) || this.renderingDone) {
  9677. return;
  9678. }
  9679. this.cancel();
  9680. this.textDivs = [];
  9681. const textLayerFrag = document.createDocumentFragment();
  9682. this.textLayerRenderTask = (0, _pdfjsLib.renderTextLayer)({
  9683. textContent: this.textContent,
  9684. textContentStream: this.textContentStream,
  9685. container: textLayerFrag,
  9686. viewport: this.viewport,
  9687. textDivs: this.textDivs,
  9688. textContentItemsStr: this.textContentItemsStr,
  9689. timeout,
  9690. enhanceTextSelection: this.enhanceTextSelection
  9691. });
  9692. this.textLayerRenderTask.promise.then(() => {
  9693. this.textLayerDiv.appendChild(textLayerFrag);
  9694. this._finishRendering();
  9695. this._updateMatches();
  9696. }, function (reason) {});
  9697. if (!this._onUpdateTextLayerMatches) {
  9698. this._onUpdateTextLayerMatches = evt => {
  9699. if (evt.pageIndex === this.pageIdx || evt.pageIndex === -1) {
  9700. this._updateMatches();
  9701. }
  9702. };
  9703. this.eventBus._on("updatetextlayermatches", this._onUpdateTextLayerMatches);
  9704. }
  9705. }
  9706. cancel() {
  9707. if (this.textLayerRenderTask) {
  9708. this.textLayerRenderTask.cancel();
  9709. this.textLayerRenderTask = null;
  9710. }
  9711. if (this._onUpdateTextLayerMatches) {
  9712. this.eventBus._off("updatetextlayermatches", this._onUpdateTextLayerMatches);
  9713. this._onUpdateTextLayerMatches = null;
  9714. }
  9715. }
  9716. setTextContentStream(readableStream) {
  9717. this.cancel();
  9718. this.textContentStream = readableStream;
  9719. }
  9720. setTextContent(textContent) {
  9721. this.cancel();
  9722. this.textContent = textContent;
  9723. }
  9724. _convertMatches(matches, matchesLength) {
  9725. if (!matches) {
  9726. return [];
  9727. }
  9728. const {
  9729. textContentItemsStr
  9730. } = this;
  9731. let i = 0,
  9732. iIndex = 0;
  9733. const end = textContentItemsStr.length - 1;
  9734. const result = [];
  9735. for (let m = 0, mm = matches.length; m < mm; m++) {
  9736. let matchIdx = matches[m];
  9737. while (i !== end && matchIdx >= iIndex + textContentItemsStr[i].length) {
  9738. iIndex += textContentItemsStr[i].length;
  9739. i++;
  9740. }
  9741. if (i === textContentItemsStr.length) {
  9742. console.error("Could not find a matching mapping");
  9743. }
  9744. const match = {
  9745. begin: {
  9746. divIdx: i,
  9747. offset: matchIdx - iIndex
  9748. }
  9749. };
  9750. matchIdx += matchesLength[m];
  9751. while (i !== end && matchIdx > iIndex + textContentItemsStr[i].length) {
  9752. iIndex += textContentItemsStr[i].length;
  9753. i++;
  9754. }
  9755. match.end = {
  9756. divIdx: i,
  9757. offset: matchIdx - iIndex
  9758. };
  9759. result.push(match);
  9760. }
  9761. return result;
  9762. }
  9763. _renderMatches(matches) {
  9764. if (matches.length === 0) {
  9765. return;
  9766. }
  9767. const {
  9768. findController,
  9769. pageIdx,
  9770. textContentItemsStr,
  9771. textDivs
  9772. } = this;
  9773. const isSelectedPage = pageIdx === findController.selected.pageIdx;
  9774. const selectedMatchIdx = findController.selected.matchIdx;
  9775. const highlightAll = findController.state.highlightAll;
  9776. let prevEnd = null;
  9777. const infinity = {
  9778. divIdx: -1,
  9779. offset: undefined
  9780. };
  9781. function beginText(begin, className) {
  9782. const divIdx = begin.divIdx;
  9783. textDivs[divIdx].textContent = "";
  9784. appendTextToDiv(divIdx, 0, begin.offset, className);
  9785. }
  9786. function appendTextToDiv(divIdx, fromOffset, toOffset, className) {
  9787. const div = textDivs[divIdx];
  9788. const content = textContentItemsStr[divIdx].substring(fromOffset, toOffset);
  9789. const node = document.createTextNode(content);
  9790. if (className) {
  9791. const span = document.createElement("span");
  9792. span.className = className;
  9793. span.appendChild(node);
  9794. div.appendChild(span);
  9795. return;
  9796. }
  9797. div.appendChild(node);
  9798. }
  9799. let i0 = selectedMatchIdx,
  9800. i1 = i0 + 1;
  9801. if (highlightAll) {
  9802. i0 = 0;
  9803. i1 = matches.length;
  9804. } else if (!isSelectedPage) {
  9805. return;
  9806. }
  9807. for (let i = i0; i < i1; i++) {
  9808. const match = matches[i];
  9809. const begin = match.begin;
  9810. const end = match.end;
  9811. const isSelected = isSelectedPage && i === selectedMatchIdx;
  9812. const highlightSuffix = isSelected ? " selected" : "";
  9813. if (isSelected) {
  9814. findController.scrollMatchIntoView({
  9815. element: textDivs[begin.divIdx],
  9816. pageIndex: pageIdx,
  9817. matchIndex: selectedMatchIdx
  9818. });
  9819. }
  9820. if (!prevEnd || begin.divIdx !== prevEnd.divIdx) {
  9821. if (prevEnd !== null) {
  9822. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset);
  9823. }
  9824. beginText(begin);
  9825. } else {
  9826. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, begin.offset);
  9827. }
  9828. if (begin.divIdx === end.divIdx) {
  9829. appendTextToDiv(begin.divIdx, begin.offset, end.offset, "highlight" + highlightSuffix);
  9830. } else {
  9831. appendTextToDiv(begin.divIdx, begin.offset, infinity.offset, "highlight begin" + highlightSuffix);
  9832. for (let n0 = begin.divIdx + 1, n1 = end.divIdx; n0 < n1; n0++) {
  9833. textDivs[n0].className = "highlight middle" + highlightSuffix;
  9834. }
  9835. beginText(end, "highlight end" + highlightSuffix);
  9836. }
  9837. prevEnd = end;
  9838. }
  9839. if (prevEnd) {
  9840. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset);
  9841. }
  9842. }
  9843. _updateMatches() {
  9844. if (!this.renderingDone) {
  9845. return;
  9846. }
  9847. const {
  9848. findController,
  9849. matches,
  9850. pageIdx,
  9851. textContentItemsStr,
  9852. textDivs
  9853. } = this;
  9854. let clearedUntilDivIdx = -1;
  9855. for (let i = 0, ii = matches.length; i < ii; i++) {
  9856. const match = matches[i];
  9857. const begin = Math.max(clearedUntilDivIdx, match.begin.divIdx);
  9858. for (let n = begin, end = match.end.divIdx; n <= end; n++) {
  9859. const div = textDivs[n];
  9860. div.textContent = textContentItemsStr[n];
  9861. div.className = "";
  9862. }
  9863. clearedUntilDivIdx = match.end.divIdx + 1;
  9864. }
  9865. if (!findController?.highlightMatches) {
  9866. return;
  9867. }
  9868. const pageMatches = findController.pageMatches[pageIdx] || null;
  9869. const pageMatchesLength = findController.pageMatchesLength[pageIdx] || null;
  9870. this.matches = this._convertMatches(pageMatches, pageMatchesLength);
  9871. this._renderMatches(this.matches);
  9872. }
  9873. _bindMouse() {
  9874. const div = this.textLayerDiv;
  9875. let expandDivsTimer = null;
  9876. div.addEventListener("mousedown", evt => {
  9877. if (this.enhanceTextSelection && this.textLayerRenderTask) {
  9878. this.textLayerRenderTask.expandTextDivs(true);
  9879. if (expandDivsTimer) {
  9880. clearTimeout(expandDivsTimer);
  9881. expandDivsTimer = null;
  9882. }
  9883. return;
  9884. }
  9885. const end = div.querySelector(".endOfContent");
  9886. if (!end) {
  9887. return;
  9888. }
  9889. let adjustTop = evt.target !== div;
  9890. adjustTop = adjustTop && window.getComputedStyle(end).getPropertyValue("-moz-user-select") !== "none";
  9891. if (adjustTop) {
  9892. const divBounds = div.getBoundingClientRect();
  9893. const r = Math.max(0, (evt.pageY - divBounds.top) / divBounds.height);
  9894. end.style.top = (r * 100).toFixed(2) + "%";
  9895. }
  9896. end.classList.add("active");
  9897. });
  9898. div.addEventListener("mouseup", () => {
  9899. if (this.enhanceTextSelection && this.textLayerRenderTask) {
  9900. expandDivsTimer = setTimeout(() => {
  9901. if (this.textLayerRenderTask) {
  9902. this.textLayerRenderTask.expandTextDivs(false);
  9903. }
  9904. expandDivsTimer = null;
  9905. }, EXPAND_DIVS_TIMEOUT);
  9906. return;
  9907. }
  9908. const end = div.querySelector(".endOfContent");
  9909. if (!end) {
  9910. return;
  9911. }
  9912. end.style.top = "";
  9913. end.classList.remove("active");
  9914. });
  9915. }
  9916. }
  9917. exports.TextLayerBuilder = TextLayerBuilder;
  9918. class DefaultTextLayerFactory {
  9919. createTextLayerBuilder(textLayerDiv, pageIndex, viewport, enhanceTextSelection = false, eventBus) {
  9920. return new TextLayerBuilder({
  9921. textLayerDiv,
  9922. pageIndex,
  9923. viewport,
  9924. enhanceTextSelection,
  9925. eventBus
  9926. });
  9927. }
  9928. }
  9929. exports.DefaultTextLayerFactory = DefaultTextLayerFactory;
  9930. /***/ }),
  9931. /* 33 */
  9932. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  9933. Object.defineProperty(exports, "__esModule", ({
  9934. value: true
  9935. }));
  9936. exports.XfaLayerBuilder = exports.DefaultXfaLayerFactory = void 0;
  9937. var _pdfjsLib = __webpack_require__(5);
  9938. class XfaLayerBuilder {
  9939. constructor({
  9940. pageDiv,
  9941. pdfPage
  9942. }) {
  9943. this.pageDiv = pageDiv;
  9944. this.pdfPage = pdfPage;
  9945. this.div = null;
  9946. this._cancelled = false;
  9947. }
  9948. render(viewport, intent = "display") {
  9949. return this.pdfPage.getXfa().then(xfa => {
  9950. if (this._cancelled) {
  9951. return;
  9952. }
  9953. const parameters = {
  9954. viewport: viewport.clone({
  9955. dontFlip: true
  9956. }),
  9957. div: this.div,
  9958. xfa,
  9959. page: this.pdfPage
  9960. };
  9961. if (this.div) {
  9962. _pdfjsLib.XfaLayer.update(parameters);
  9963. } else {
  9964. this.div = document.createElement("div");
  9965. this.pageDiv.appendChild(this.div);
  9966. parameters.div = this.div;
  9967. _pdfjsLib.XfaLayer.render(parameters);
  9968. }
  9969. });
  9970. }
  9971. cancel() {
  9972. this._cancelled = true;
  9973. }
  9974. hide() {
  9975. if (!this.div) {
  9976. return;
  9977. }
  9978. this.div.hidden = true;
  9979. }
  9980. }
  9981. exports.XfaLayerBuilder = XfaLayerBuilder;
  9982. class DefaultXfaLayerFactory {
  9983. createXfaLayerBuilder(pageDiv, pdfPage) {
  9984. return new XfaLayerBuilder({
  9985. pageDiv,
  9986. pdfPage
  9987. });
  9988. }
  9989. }
  9990. exports.DefaultXfaLayerFactory = DefaultXfaLayerFactory;
  9991. /***/ }),
  9992. /* 34 */
  9993. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  9994. Object.defineProperty(exports, "__esModule", ({
  9995. value: true
  9996. }));
  9997. exports.SecondaryToolbar = void 0;
  9998. var _ui_utils = __webpack_require__(4);
  9999. var _pdf_cursor_tools = __webpack_require__(6);
  10000. var _pdf_single_page_viewer = __webpack_require__(35);
  10001. class SecondaryToolbar {
  10002. constructor(options, mainContainer, eventBus) {
  10003. this.toolbar = options.toolbar;
  10004. this.toggleButton = options.toggleButton;
  10005. this.toolbarButtonContainer = options.toolbarButtonContainer;
  10006. this.buttons = [{
  10007. element: options.presentationModeButton,
  10008. eventName: "presentationmode",
  10009. close: true
  10010. }, {
  10011. element: options.openFileButton,
  10012. eventName: "openfile",
  10013. close: true
  10014. }, {
  10015. element: options.printButton,
  10016. eventName: "print",
  10017. close: true
  10018. }, {
  10019. element: options.downloadButton,
  10020. eventName: "download",
  10021. close: true
  10022. }, {
  10023. element: options.viewBookmarkButton,
  10024. eventName: null,
  10025. close: true
  10026. }, {
  10027. element: options.firstPageButton,
  10028. eventName: "firstpage",
  10029. close: true
  10030. }, {
  10031. element: options.lastPageButton,
  10032. eventName: "lastpage",
  10033. close: true
  10034. }, {
  10035. element: options.pageRotateCwButton,
  10036. eventName: "rotatecw",
  10037. close: false
  10038. }, {
  10039. element: options.pageRotateCcwButton,
  10040. eventName: "rotateccw",
  10041. close: false
  10042. }, {
  10043. element: options.cursorSelectToolButton,
  10044. eventName: "switchcursortool",
  10045. eventDetails: {
  10046. tool: _pdf_cursor_tools.CursorTool.SELECT
  10047. },
  10048. close: true
  10049. }, {
  10050. element: options.cursorHandToolButton,
  10051. eventName: "switchcursortool",
  10052. eventDetails: {
  10053. tool: _pdf_cursor_tools.CursorTool.HAND
  10054. },
  10055. close: true
  10056. }, {
  10057. element: options.scrollVerticalButton,
  10058. eventName: "switchscrollmode",
  10059. eventDetails: {
  10060. mode: _ui_utils.ScrollMode.VERTICAL
  10061. },
  10062. close: true
  10063. }, {
  10064. element: options.scrollHorizontalButton,
  10065. eventName: "switchscrollmode",
  10066. eventDetails: {
  10067. mode: _ui_utils.ScrollMode.HORIZONTAL
  10068. },
  10069. close: true
  10070. }, {
  10071. element: options.scrollWrappedButton,
  10072. eventName: "switchscrollmode",
  10073. eventDetails: {
  10074. mode: _ui_utils.ScrollMode.WRAPPED
  10075. },
  10076. close: true
  10077. }, {
  10078. element: options.spreadNoneButton,
  10079. eventName: "switchspreadmode",
  10080. eventDetails: {
  10081. mode: _ui_utils.SpreadMode.NONE
  10082. },
  10083. close: true
  10084. }, {
  10085. element: options.spreadOddButton,
  10086. eventName: "switchspreadmode",
  10087. eventDetails: {
  10088. mode: _ui_utils.SpreadMode.ODD
  10089. },
  10090. close: true
  10091. }, {
  10092. element: options.spreadEvenButton,
  10093. eventName: "switchspreadmode",
  10094. eventDetails: {
  10095. mode: _ui_utils.SpreadMode.EVEN
  10096. },
  10097. close: true
  10098. }, {
  10099. element: options.documentPropertiesButton,
  10100. eventName: "documentproperties",
  10101. close: true
  10102. }];
  10103. this.items = {
  10104. firstPage: options.firstPageButton,
  10105. lastPage: options.lastPageButton,
  10106. pageRotateCw: options.pageRotateCwButton,
  10107. pageRotateCcw: options.pageRotateCcwButton
  10108. };
  10109. this.mainContainer = mainContainer;
  10110. this.eventBus = eventBus;
  10111. this.opened = false;
  10112. this.containerHeight = null;
  10113. this.previousContainerHeight = null;
  10114. this.reset();
  10115. this._bindClickListeners();
  10116. this._bindCursorToolsListener(options);
  10117. this._bindScrollModeListener(options);
  10118. this._bindSpreadModeListener(options);
  10119. this.eventBus._on("resize", this._setMaxHeight.bind(this));
  10120. this.eventBus._on("baseviewerinit", evt => {
  10121. if (evt.source instanceof _pdf_single_page_viewer.PDFSinglePageViewer) {
  10122. this.toolbarButtonContainer.classList.add("hiddenScrollModeButtons", "hiddenSpreadModeButtons");
  10123. } else {
  10124. this.toolbarButtonContainer.classList.remove("hiddenScrollModeButtons", "hiddenSpreadModeButtons");
  10125. }
  10126. });
  10127. }
  10128. get isOpen() {
  10129. return this.opened;
  10130. }
  10131. setPageNumber(pageNumber) {
  10132. this.pageNumber = pageNumber;
  10133. this._updateUIState();
  10134. }
  10135. setPagesCount(pagesCount) {
  10136. this.pagesCount = pagesCount;
  10137. this._updateUIState();
  10138. }
  10139. reset() {
  10140. this.pageNumber = 0;
  10141. this.pagesCount = 0;
  10142. this._updateUIState();
  10143. this.eventBus.dispatch("secondarytoolbarreset", {
  10144. source: this
  10145. });
  10146. }
  10147. _updateUIState() {
  10148. this.items.firstPage.disabled = this.pageNumber <= 1;
  10149. this.items.lastPage.disabled = this.pageNumber >= this.pagesCount;
  10150. this.items.pageRotateCw.disabled = this.pagesCount === 0;
  10151. this.items.pageRotateCcw.disabled = this.pagesCount === 0;
  10152. }
  10153. _bindClickListeners() {
  10154. this.toggleButton.addEventListener("click", this.toggle.bind(this));
  10155. for (const {
  10156. element,
  10157. eventName,
  10158. close,
  10159. eventDetails
  10160. } of this.buttons) {
  10161. element.addEventListener("click", evt => {
  10162. if (eventName !== null) {
  10163. const details = {
  10164. source: this
  10165. };
  10166. for (const property in eventDetails) {
  10167. details[property] = eventDetails[property];
  10168. }
  10169. this.eventBus.dispatch(eventName, details);
  10170. }
  10171. if (close) {
  10172. this.close();
  10173. }
  10174. });
  10175. }
  10176. }
  10177. _bindCursorToolsListener(buttons) {
  10178. this.eventBus._on("cursortoolchanged", function ({
  10179. tool
  10180. }) {
  10181. buttons.cursorSelectToolButton.classList.toggle("toggled", tool === _pdf_cursor_tools.CursorTool.SELECT);
  10182. buttons.cursorHandToolButton.classList.toggle("toggled", tool === _pdf_cursor_tools.CursorTool.HAND);
  10183. });
  10184. }
  10185. _bindScrollModeListener(buttons) {
  10186. function scrollModeChanged({
  10187. mode
  10188. }) {
  10189. buttons.scrollVerticalButton.classList.toggle("toggled", mode === _ui_utils.ScrollMode.VERTICAL);
  10190. buttons.scrollHorizontalButton.classList.toggle("toggled", mode === _ui_utils.ScrollMode.HORIZONTAL);
  10191. buttons.scrollWrappedButton.classList.toggle("toggled", mode === _ui_utils.ScrollMode.WRAPPED);
  10192. const isScrollModeHorizontal = mode === _ui_utils.ScrollMode.HORIZONTAL;
  10193. buttons.spreadNoneButton.disabled = isScrollModeHorizontal;
  10194. buttons.spreadOddButton.disabled = isScrollModeHorizontal;
  10195. buttons.spreadEvenButton.disabled = isScrollModeHorizontal;
  10196. }
  10197. this.eventBus._on("scrollmodechanged", scrollModeChanged);
  10198. this.eventBus._on("secondarytoolbarreset", evt => {
  10199. if (evt.source === this) {
  10200. scrollModeChanged({
  10201. mode: _ui_utils.ScrollMode.VERTICAL
  10202. });
  10203. }
  10204. });
  10205. }
  10206. _bindSpreadModeListener(buttons) {
  10207. function spreadModeChanged({
  10208. mode
  10209. }) {
  10210. buttons.spreadNoneButton.classList.toggle("toggled", mode === _ui_utils.SpreadMode.NONE);
  10211. buttons.spreadOddButton.classList.toggle("toggled", mode === _ui_utils.SpreadMode.ODD);
  10212. buttons.spreadEvenButton.classList.toggle("toggled", mode === _ui_utils.SpreadMode.EVEN);
  10213. }
  10214. this.eventBus._on("spreadmodechanged", spreadModeChanged);
  10215. this.eventBus._on("secondarytoolbarreset", evt => {
  10216. if (evt.source === this) {
  10217. spreadModeChanged({
  10218. mode: _ui_utils.SpreadMode.NONE
  10219. });
  10220. }
  10221. });
  10222. }
  10223. open() {
  10224. if (this.opened) {
  10225. return;
  10226. }
  10227. this.opened = true;
  10228. this._setMaxHeight();
  10229. this.toggleButton.classList.add("toggled");
  10230. this.toggleButton.setAttribute("aria-expanded", "true");
  10231. this.toolbar.classList.remove("hidden");
  10232. }
  10233. close() {
  10234. if (!this.opened) {
  10235. return;
  10236. }
  10237. this.opened = false;
  10238. this.toolbar.classList.add("hidden");
  10239. this.toggleButton.classList.remove("toggled");
  10240. this.toggleButton.setAttribute("aria-expanded", "false");
  10241. }
  10242. toggle() {
  10243. if (this.opened) {
  10244. this.close();
  10245. } else {
  10246. this.open();
  10247. }
  10248. }
  10249. _setMaxHeight() {
  10250. if (!this.opened) {
  10251. return;
  10252. }
  10253. this.containerHeight = this.mainContainer.clientHeight;
  10254. if (this.containerHeight === this.previousContainerHeight) {
  10255. return;
  10256. }
  10257. this.toolbarButtonContainer.style.maxHeight = `${this.containerHeight - _ui_utils.SCROLLBAR_PADDING}px`;
  10258. this.previousContainerHeight = this.containerHeight;
  10259. }
  10260. }
  10261. exports.SecondaryToolbar = SecondaryToolbar;
  10262. /***/ }),
  10263. /* 35 */
  10264. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10265. Object.defineProperty(exports, "__esModule", ({
  10266. value: true
  10267. }));
  10268. exports.PDFSinglePageViewer = void 0;
  10269. var _base_viewer = __webpack_require__(28);
  10270. var _pdfjsLib = __webpack_require__(5);
  10271. class PDFSinglePageViewer extends _base_viewer.BaseViewer {
  10272. constructor(options) {
  10273. super(options);
  10274. this.eventBus._on("pagesinit", evt => {
  10275. this._ensurePageViewVisible();
  10276. });
  10277. }
  10278. get _viewerElement() {
  10279. return (0, _pdfjsLib.shadow)(this, "_viewerElement", this._shadowViewer);
  10280. }
  10281. get _pageWidthScaleFactor() {
  10282. return 1;
  10283. }
  10284. _resetView() {
  10285. super._resetView();
  10286. this._previousPageNumber = 1;
  10287. this._shadowViewer = document.createDocumentFragment();
  10288. this._updateScrollDown = null;
  10289. }
  10290. _ensurePageViewVisible() {
  10291. const pageView = this._pages[this._currentPageNumber - 1];
  10292. const previousPageView = this._pages[this._previousPageNumber - 1];
  10293. const viewerNodes = this.viewer.childNodes;
  10294. switch (viewerNodes.length) {
  10295. case 0:
  10296. this.viewer.appendChild(pageView.div);
  10297. break;
  10298. case 1:
  10299. if (viewerNodes[0] !== previousPageView.div) {
  10300. throw new Error("_ensurePageViewVisible: Unexpected previously visible page.");
  10301. }
  10302. if (pageView === previousPageView) {
  10303. break;
  10304. }
  10305. this._shadowViewer.appendChild(previousPageView.div);
  10306. this.viewer.appendChild(pageView.div);
  10307. this.container.scrollTop = 0;
  10308. break;
  10309. default:
  10310. throw new Error("_ensurePageViewVisible: Only one page should be visible at a time.");
  10311. }
  10312. this._previousPageNumber = this._currentPageNumber;
  10313. }
  10314. _scrollUpdate() {
  10315. if (this._updateScrollDown) {
  10316. this._updateScrollDown();
  10317. }
  10318. super._scrollUpdate();
  10319. }
  10320. _scrollIntoView({
  10321. pageDiv,
  10322. pageSpot = null,
  10323. pageNumber = null
  10324. }) {
  10325. if (pageNumber) {
  10326. this._setCurrentPageNumber(pageNumber);
  10327. }
  10328. const scrolledDown = this._currentPageNumber >= this._previousPageNumber;
  10329. this._ensurePageViewVisible();
  10330. this.update();
  10331. super._scrollIntoView({
  10332. pageDiv,
  10333. pageSpot,
  10334. pageNumber
  10335. });
  10336. this._updateScrollDown = () => {
  10337. this.scroll.down = scrolledDown;
  10338. this._updateScrollDown = null;
  10339. };
  10340. }
  10341. _getVisiblePages() {
  10342. return this._getCurrentVisiblePage();
  10343. }
  10344. _updateHelper(visiblePages) {}
  10345. get _isScrollModeHorizontal() {
  10346. return (0, _pdfjsLib.shadow)(this, "_isScrollModeHorizontal", false);
  10347. }
  10348. _updateScrollMode() {}
  10349. _updateSpreadMode() {}
  10350. _getPageAdvance() {
  10351. return 1;
  10352. }
  10353. }
  10354. exports.PDFSinglePageViewer = PDFSinglePageViewer;
  10355. /***/ }),
  10356. /* 36 */
  10357. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10358. Object.defineProperty(exports, "__esModule", ({
  10359. value: true
  10360. }));
  10361. exports.Toolbar = void 0;
  10362. var _ui_utils = __webpack_require__(4);
  10363. const PAGE_NUMBER_LOADING_INDICATOR = "visiblePageIsLoading";
  10364. const SCALE_SELECT_CONTAINER_WIDTH = 140;
  10365. const SCALE_SELECT_WIDTH = 162;
  10366. class Toolbar {
  10367. constructor(options, eventBus, l10n) {
  10368. this.toolbar = options.container;
  10369. this.eventBus = eventBus;
  10370. this.l10n = l10n;
  10371. this.buttons = [{
  10372. element: options.previous,
  10373. eventName: "previouspage"
  10374. }, {
  10375. element: options.next,
  10376. eventName: "nextpage"
  10377. }, {
  10378. element: options.zoomIn,
  10379. eventName: "zoomin"
  10380. }, {
  10381. element: options.zoomOut,
  10382. eventName: "zoomout"
  10383. }, {
  10384. element: options.openFile,
  10385. eventName: "openfile"
  10386. }, {
  10387. element: options.print,
  10388. eventName: "print"
  10389. }, {
  10390. element: options.presentationModeButton,
  10391. eventName: "presentationmode"
  10392. }, {
  10393. element: options.download,
  10394. eventName: "download"
  10395. }, {
  10396. element: options.viewBookmark,
  10397. eventName: null
  10398. }];
  10399. this.items = {
  10400. numPages: options.numPages,
  10401. pageNumber: options.pageNumber,
  10402. scaleSelectContainer: options.scaleSelectContainer,
  10403. scaleSelect: options.scaleSelect,
  10404. customScaleOption: options.customScaleOption,
  10405. previous: options.previous,
  10406. next: options.next,
  10407. zoomIn: options.zoomIn,
  10408. zoomOut: options.zoomOut
  10409. };
  10410. this._wasLocalized = false;
  10411. this.reset();
  10412. this._bindListeners();
  10413. }
  10414. setPageNumber(pageNumber, pageLabel) {
  10415. this.pageNumber = pageNumber;
  10416. this.pageLabel = pageLabel;
  10417. this._updateUIState(false);
  10418. }
  10419. setPagesCount(pagesCount, hasPageLabels) {
  10420. this.pagesCount = pagesCount;
  10421. this.hasPageLabels = hasPageLabels;
  10422. this._updateUIState(true);
  10423. }
  10424. setPageScale(pageScaleValue, pageScale) {
  10425. this.pageScaleValue = (pageScaleValue || pageScale).toString();
  10426. this.pageScale = pageScale;
  10427. this._updateUIState(false);
  10428. }
  10429. reset() {
  10430. this.pageNumber = 0;
  10431. this.pageLabel = null;
  10432. this.hasPageLabels = false;
  10433. this.pagesCount = 0;
  10434. this.pageScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  10435. this.pageScale = _ui_utils.DEFAULT_SCALE;
  10436. this._updateUIState(true);
  10437. this.updateLoadingIndicatorState();
  10438. }
  10439. _bindListeners() {
  10440. const {
  10441. pageNumber,
  10442. scaleSelect
  10443. } = this.items;
  10444. const self = this;
  10445. for (const {
  10446. element,
  10447. eventName
  10448. } of this.buttons) {
  10449. element.addEventListener("click", evt => {
  10450. if (eventName !== null) {
  10451. this.eventBus.dispatch(eventName, {
  10452. source: this
  10453. });
  10454. }
  10455. });
  10456. }
  10457. pageNumber.addEventListener("click", function () {
  10458. this.select();
  10459. });
  10460. pageNumber.addEventListener("change", function () {
  10461. self.eventBus.dispatch("pagenumberchanged", {
  10462. source: self,
  10463. value: this.value
  10464. });
  10465. });
  10466. scaleSelect.addEventListener("change", function () {
  10467. if (this.value === "custom") {
  10468. return;
  10469. }
  10470. self.eventBus.dispatch("scalechanged", {
  10471. source: self,
  10472. value: this.value
  10473. });
  10474. });
  10475. scaleSelect.oncontextmenu = _ui_utils.noContextMenuHandler;
  10476. this.eventBus._on("localized", () => {
  10477. this._wasLocalized = true;
  10478. this._adjustScaleWidth();
  10479. this._updateUIState(true);
  10480. });
  10481. }
  10482. _updateUIState(resetNumPages = false) {
  10483. if (!this._wasLocalized) {
  10484. return;
  10485. }
  10486. const {
  10487. pageNumber,
  10488. pagesCount,
  10489. pageScaleValue,
  10490. pageScale,
  10491. items
  10492. } = this;
  10493. if (resetNumPages) {
  10494. if (this.hasPageLabels) {
  10495. items.pageNumber.type = "text";
  10496. } else {
  10497. items.pageNumber.type = "number";
  10498. this.l10n.get("of_pages", {
  10499. pagesCount
  10500. }).then(msg => {
  10501. items.numPages.textContent = msg;
  10502. });
  10503. }
  10504. items.pageNumber.max = pagesCount;
  10505. }
  10506. if (this.hasPageLabels) {
  10507. items.pageNumber.value = this.pageLabel;
  10508. this.l10n.get("page_of_pages", {
  10509. pageNumber,
  10510. pagesCount
  10511. }).then(msg => {
  10512. items.numPages.textContent = msg;
  10513. });
  10514. } else {
  10515. items.pageNumber.value = pageNumber;
  10516. }
  10517. items.previous.disabled = pageNumber <= 1;
  10518. items.next.disabled = pageNumber >= pagesCount;
  10519. items.zoomOut.disabled = pageScale <= _ui_utils.MIN_SCALE;
  10520. items.zoomIn.disabled = pageScale >= _ui_utils.MAX_SCALE;
  10521. this.l10n.get("page_scale_percent", {
  10522. scale: Math.round(pageScale * 10000) / 100
  10523. }).then(msg => {
  10524. let predefinedValueFound = false;
  10525. for (const option of items.scaleSelect.options) {
  10526. if (option.value !== pageScaleValue) {
  10527. option.selected = false;
  10528. continue;
  10529. }
  10530. option.selected = true;
  10531. predefinedValueFound = true;
  10532. }
  10533. if (!predefinedValueFound) {
  10534. items.customScaleOption.textContent = msg;
  10535. items.customScaleOption.selected = true;
  10536. }
  10537. });
  10538. }
  10539. updateLoadingIndicatorState(loading = false) {
  10540. const pageNumberInput = this.items.pageNumber;
  10541. pageNumberInput.classList.toggle(PAGE_NUMBER_LOADING_INDICATOR, loading);
  10542. }
  10543. async _adjustScaleWidth() {
  10544. const {
  10545. items,
  10546. l10n
  10547. } = this;
  10548. const predefinedValuesPromise = Promise.all([l10n.get("page_scale_auto"), l10n.get("page_scale_actual"), l10n.get("page_scale_fit"), l10n.get("page_scale_width")]);
  10549. let canvas = document.createElement("canvas");
  10550. canvas.mozOpaque = true;
  10551. let ctx = canvas.getContext("2d", {
  10552. alpha: false
  10553. });
  10554. await _ui_utils.animationStarted;
  10555. const {
  10556. fontSize,
  10557. fontFamily
  10558. } = getComputedStyle(items.scaleSelect);
  10559. ctx.font = `${fontSize} ${fontFamily}`;
  10560. let maxWidth = 0;
  10561. for (const predefinedValue of await predefinedValuesPromise) {
  10562. const {
  10563. width
  10564. } = ctx.measureText(predefinedValue);
  10565. if (width > maxWidth) {
  10566. maxWidth = width;
  10567. }
  10568. }
  10569. const overflow = SCALE_SELECT_WIDTH - SCALE_SELECT_CONTAINER_WIDTH;
  10570. maxWidth += 2 * overflow;
  10571. if (maxWidth > SCALE_SELECT_CONTAINER_WIDTH) {
  10572. items.scaleSelect.style.width = `${maxWidth + overflow}px`;
  10573. items.scaleSelectContainer.style.width = `${maxWidth}px`;
  10574. }
  10575. canvas.width = 0;
  10576. canvas.height = 0;
  10577. canvas = ctx = null;
  10578. }
  10579. }
  10580. exports.Toolbar = Toolbar;
  10581. /***/ }),
  10582. /* 37 */
  10583. /***/ ((__unused_webpack_module, exports) => {
  10584. Object.defineProperty(exports, "__esModule", ({
  10585. value: true
  10586. }));
  10587. exports.ViewHistory = void 0;
  10588. const DEFAULT_VIEW_HISTORY_CACHE_SIZE = 20;
  10589. class ViewHistory {
  10590. constructor(fingerprint, cacheSize = DEFAULT_VIEW_HISTORY_CACHE_SIZE) {
  10591. this.fingerprint = fingerprint;
  10592. this.cacheSize = cacheSize;
  10593. this._initializedPromise = this._readFromStorage().then(databaseStr => {
  10594. const database = JSON.parse(databaseStr || "{}");
  10595. let index = -1;
  10596. if (!Array.isArray(database.files)) {
  10597. database.files = [];
  10598. } else {
  10599. while (database.files.length >= this.cacheSize) {
  10600. database.files.shift();
  10601. }
  10602. for (let i = 0, ii = database.files.length; i < ii; i++) {
  10603. const branch = database.files[i];
  10604. if (branch.fingerprint === this.fingerprint) {
  10605. index = i;
  10606. break;
  10607. }
  10608. }
  10609. }
  10610. if (index === -1) {
  10611. index = database.files.push({
  10612. fingerprint: this.fingerprint
  10613. }) - 1;
  10614. }
  10615. this.file = database.files[index];
  10616. this.database = database;
  10617. });
  10618. }
  10619. async _writeToStorage() {
  10620. const databaseStr = JSON.stringify(this.database);
  10621. localStorage.setItem("pdfjs.history", databaseStr);
  10622. }
  10623. async _readFromStorage() {
  10624. return localStorage.getItem("pdfjs.history");
  10625. }
  10626. async set(name, val) {
  10627. await this._initializedPromise;
  10628. this.file[name] = val;
  10629. return this._writeToStorage();
  10630. }
  10631. async setMultiple(properties) {
  10632. await this._initializedPromise;
  10633. for (const name in properties) {
  10634. this.file[name] = properties[name];
  10635. }
  10636. return this._writeToStorage();
  10637. }
  10638. async get(name, defaultValue) {
  10639. await this._initializedPromise;
  10640. const val = this.file[name];
  10641. return val !== undefined ? val : defaultValue;
  10642. }
  10643. async getMultiple(properties) {
  10644. await this._initializedPromise;
  10645. const values = Object.create(null);
  10646. for (const name in properties) {
  10647. const val = this.file[name];
  10648. values[name] = val !== undefined ? val : properties[name];
  10649. }
  10650. return values;
  10651. }
  10652. }
  10653. exports.ViewHistory = ViewHistory;
  10654. /***/ }),
  10655. /* 38 */
  10656. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10657. Object.defineProperty(exports, "__esModule", ({
  10658. value: true
  10659. }));
  10660. exports.GenericCom = void 0;
  10661. var _app = __webpack_require__(3);
  10662. var _preferences = __webpack_require__(39);
  10663. var _download_manager = __webpack_require__(40);
  10664. var _genericl10n = __webpack_require__(41);
  10665. var _generic_scripting = __webpack_require__(43);
  10666. ;
  10667. const GenericCom = {};
  10668. exports.GenericCom = GenericCom;
  10669. class GenericPreferences extends _preferences.BasePreferences {
  10670. async _writeToStorage(prefObj) {
  10671. localStorage.setItem("pdfjs.preferences", JSON.stringify(prefObj));
  10672. }
  10673. async _readFromStorage(prefObj) {
  10674. return JSON.parse(localStorage.getItem("pdfjs.preferences"));
  10675. }
  10676. }
  10677. class GenericExternalServices extends _app.DefaultExternalServices {
  10678. static createDownloadManager(options) {
  10679. return new _download_manager.DownloadManager();
  10680. }
  10681. static createPreferences() {
  10682. return new GenericPreferences();
  10683. }
  10684. static createL10n({
  10685. locale = "en-US"
  10686. }) {
  10687. return new _genericl10n.GenericL10n(locale);
  10688. }
  10689. static createScripting({
  10690. sandboxBundleSrc
  10691. }) {
  10692. return new _generic_scripting.GenericScripting(sandboxBundleSrc);
  10693. }
  10694. }
  10695. _app.PDFViewerApplication.externalServices = GenericExternalServices;
  10696. /***/ }),
  10697. /* 39 */
  10698. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10699. Object.defineProperty(exports, "__esModule", ({
  10700. value: true
  10701. }));
  10702. exports.BasePreferences = void 0;
  10703. var _app_options = __webpack_require__(1);
  10704. class BasePreferences {
  10705. constructor() {
  10706. if (this.constructor === BasePreferences) {
  10707. throw new Error("Cannot initialize BasePreferences.");
  10708. }
  10709. Object.defineProperty(this, "defaults", {
  10710. value: Object.freeze({
  10711. "cursorToolOnLoad": 0,
  10712. "defaultZoomValue": "",
  10713. "disablePageLabels": false,
  10714. "enablePermissions": false,
  10715. "enablePrintAutoRotate": true,
  10716. "enableScripting": true,
  10717. "enableWebGL": false,
  10718. "externalLinkTarget": 0,
  10719. "historyUpdateUrl": false,
  10720. "ignoreDestinationZoom": false,
  10721. "pdfBugEnabled": false,
  10722. "renderer": "canvas",
  10723. "renderInteractiveForms": true,
  10724. "sidebarViewOnLoad": -1,
  10725. "scrollModeOnLoad": -1,
  10726. "spreadModeOnLoad": -1,
  10727. "textLayerMode": 1,
  10728. "useOnlyCssZoom": false,
  10729. "viewerCssTheme": 0,
  10730. "viewOnLoad": 0,
  10731. "disableAutoFetch": false,
  10732. "disableFontFace": false,
  10733. "disableRange": false,
  10734. "disableStream": false
  10735. }),
  10736. writable: false,
  10737. enumerable: true,
  10738. configurable: false
  10739. });
  10740. this.prefs = Object.create(null);
  10741. this._initializedPromise = this._readFromStorage(this.defaults).then(prefs => {
  10742. for (const name in this.defaults) {
  10743. const prefValue = prefs?.[name];
  10744. if (typeof prefValue === typeof this.defaults[name]) {
  10745. this.prefs[name] = prefValue;
  10746. }
  10747. }
  10748. });
  10749. }
  10750. async _writeToStorage(prefObj) {
  10751. throw new Error("Not implemented: _writeToStorage");
  10752. }
  10753. async _readFromStorage(prefObj) {
  10754. throw new Error("Not implemented: _readFromStorage");
  10755. }
  10756. async reset() {
  10757. await this._initializedPromise;
  10758. this.prefs = Object.create(null);
  10759. return this._writeToStorage(this.defaults);
  10760. }
  10761. async set(name, value) {
  10762. await this._initializedPromise;
  10763. const defaultValue = this.defaults[name];
  10764. if (defaultValue === undefined) {
  10765. throw new Error(`Set preference: "${name}" is undefined.`);
  10766. } else if (value === undefined) {
  10767. throw new Error("Set preference: no value is specified.");
  10768. }
  10769. const valueType = typeof value;
  10770. const defaultType = typeof defaultValue;
  10771. if (valueType !== defaultType) {
  10772. if (valueType === "number" && defaultType === "string") {
  10773. value = value.toString();
  10774. } else {
  10775. throw new Error(`Set preference: "${value}" is a ${valueType}, expected a ${defaultType}.`);
  10776. }
  10777. } else {
  10778. if (valueType === "number" && !Number.isInteger(value)) {
  10779. throw new Error(`Set preference: "${value}" must be an integer.`);
  10780. }
  10781. }
  10782. this.prefs[name] = value;
  10783. return this._writeToStorage(this.prefs);
  10784. }
  10785. async get(name) {
  10786. await this._initializedPromise;
  10787. const defaultValue = this.defaults[name],
  10788. prefValue = this.prefs[name];
  10789. if (defaultValue === undefined) {
  10790. throw new Error(`Get preference: "${name}" is undefined.`);
  10791. }
  10792. return prefValue !== undefined ? prefValue : defaultValue;
  10793. }
  10794. async getAll() {
  10795. await this._initializedPromise;
  10796. const obj = Object.create(null);
  10797. for (const name in this.defaults) {
  10798. const prefValue = this.prefs[name];
  10799. obj[name] = prefValue !== undefined ? prefValue : this.defaults[name];
  10800. }
  10801. return obj;
  10802. }
  10803. }
  10804. exports.BasePreferences = BasePreferences;
  10805. /***/ }),
  10806. /* 40 */
  10807. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10808. Object.defineProperty(exports, "__esModule", ({
  10809. value: true
  10810. }));
  10811. exports.DownloadManager = void 0;
  10812. var _pdfjsLib = __webpack_require__(5);
  10813. var _viewer_compatibility = __webpack_require__(2);
  10814. ;
  10815. function download(blobUrl, filename) {
  10816. const a = document.createElement("a");
  10817. if (!a.click) {
  10818. throw new Error('DownloadManager: "a.click()" is not supported.');
  10819. }
  10820. a.href = blobUrl;
  10821. a.target = "_parent";
  10822. if ("download" in a) {
  10823. a.download = filename;
  10824. }
  10825. (document.body || document.documentElement).appendChild(a);
  10826. a.click();
  10827. a.remove();
  10828. }
  10829. class DownloadManager {
  10830. constructor() {
  10831. this._openBlobUrls = new WeakMap();
  10832. }
  10833. downloadUrl(url, filename) {
  10834. if (!(0, _pdfjsLib.createValidAbsoluteUrl)(url, "http://example.com")) {
  10835. return;
  10836. }
  10837. download(url + "#pdfjs.action=download", filename);
  10838. }
  10839. downloadData(data, filename, contentType) {
  10840. const blobUrl = (0, _pdfjsLib.createObjectURL)(data, contentType, _viewer_compatibility.viewerCompatibilityParams.disableCreateObjectURL);
  10841. download(blobUrl, filename);
  10842. }
  10843. openOrDownloadData(element, data, filename) {
  10844. const isPdfData = (0, _pdfjsLib.isPdfFile)(filename);
  10845. const contentType = isPdfData ? "application/pdf" : "";
  10846. if (isPdfData && !_viewer_compatibility.viewerCompatibilityParams.disableCreateObjectURL) {
  10847. let blobUrl = this._openBlobUrls.get(element);
  10848. if (!blobUrl) {
  10849. blobUrl = URL.createObjectURL(new Blob([data], {
  10850. type: contentType
  10851. }));
  10852. this._openBlobUrls.set(element, blobUrl);
  10853. }
  10854. let viewerUrl;
  10855. viewerUrl = "?file=" + encodeURIComponent(blobUrl + "#" + filename);
  10856. try {
  10857. window.open(viewerUrl);
  10858. return true;
  10859. } catch (ex) {
  10860. console.error(`openOrDownloadData: ${ex}`);
  10861. URL.revokeObjectURL(blobUrl);
  10862. this._openBlobUrls.delete(element);
  10863. }
  10864. }
  10865. this.downloadData(data, filename, contentType);
  10866. return false;
  10867. }
  10868. download(blob, url, filename, sourceEventType = "download") {
  10869. if (_viewer_compatibility.viewerCompatibilityParams.disableCreateObjectURL) {
  10870. this.downloadUrl(url, filename);
  10871. return;
  10872. }
  10873. const blobUrl = URL.createObjectURL(blob);
  10874. download(blobUrl, filename);
  10875. }
  10876. }
  10877. exports.DownloadManager = DownloadManager;
  10878. /***/ }),
  10879. /* 41 */
  10880. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10881. Object.defineProperty(exports, "__esModule", ({
  10882. value: true
  10883. }));
  10884. exports.GenericL10n = void 0;
  10885. __webpack_require__(42);
  10886. var _l10n_utils = __webpack_require__(30);
  10887. const webL10n = document.webL10n;
  10888. class GenericL10n {
  10889. constructor(lang) {
  10890. this._lang = lang;
  10891. this._ready = new Promise((resolve, reject) => {
  10892. webL10n.setLanguage(lang, () => {
  10893. resolve(webL10n);
  10894. });
  10895. });
  10896. }
  10897. async getLanguage() {
  10898. const l10n = await this._ready;
  10899. return l10n.getLanguage();
  10900. }
  10901. async getDirection() {
  10902. const l10n = await this._ready;
  10903. return l10n.getDirection();
  10904. }
  10905. async get(key, args = null, fallback = (0, _l10n_utils.getL10nFallback)(key, args)) {
  10906. const l10n = await this._ready;
  10907. return l10n.get(key, args, fallback);
  10908. }
  10909. async translate(element) {
  10910. const l10n = await this._ready;
  10911. return l10n.translate(element);
  10912. }
  10913. }
  10914. exports.GenericL10n = GenericL10n;
  10915. /***/ }),
  10916. /* 42 */
  10917. /***/ (() => {
  10918. document.webL10n = function (window, document, undefined) {
  10919. var gL10nData = {};
  10920. var gTextData = '';
  10921. var gTextProp = 'textContent';
  10922. var gLanguage = '';
  10923. var gMacros = {};
  10924. var gReadyState = 'loading';
  10925. var gAsyncResourceLoading = true;
  10926. function getL10nResourceLinks() {
  10927. return document.querySelectorAll('link[type="application/l10n"]');
  10928. }
  10929. function getL10nDictionary() {
  10930. var script = document.querySelector('script[type="application/l10n"]');
  10931. return script ? JSON.parse(script.innerHTML) : null;
  10932. }
  10933. function getTranslatableChildren(element) {
  10934. return element ? element.querySelectorAll('*[data-l10n-id]') : [];
  10935. }
  10936. function getL10nAttributes(element) {
  10937. if (!element) return {};
  10938. var l10nId = element.getAttribute('data-l10n-id');
  10939. var l10nArgs = element.getAttribute('data-l10n-args');
  10940. var args = {};
  10941. if (l10nArgs) {
  10942. try {
  10943. args = JSON.parse(l10nArgs);
  10944. } catch (e) {
  10945. console.warn('could not parse arguments for #' + l10nId);
  10946. }
  10947. }
  10948. return {
  10949. id: l10nId,
  10950. args: args
  10951. };
  10952. }
  10953. function xhrLoadText(url, onSuccess, onFailure) {
  10954. onSuccess = onSuccess || function _onSuccess(data) {};
  10955. onFailure = onFailure || function _onFailure() {};
  10956. var xhr = new XMLHttpRequest();
  10957. xhr.open('GET', url, gAsyncResourceLoading);
  10958. if (xhr.overrideMimeType) {
  10959. xhr.overrideMimeType('text/plain; charset=utf-8');
  10960. }
  10961. xhr.onreadystatechange = function () {
  10962. if (xhr.readyState == 4) {
  10963. if (xhr.status == 200 || xhr.status === 0) {
  10964. onSuccess(xhr.responseText);
  10965. } else {
  10966. onFailure();
  10967. }
  10968. }
  10969. };
  10970. xhr.onerror = onFailure;
  10971. xhr.ontimeout = onFailure;
  10972. try {
  10973. xhr.send(null);
  10974. } catch (e) {
  10975. onFailure();
  10976. }
  10977. }
  10978. function parseResource(href, lang, successCallback, failureCallback) {
  10979. var baseURL = href.replace(/[^\/]*$/, '') || './';
  10980. function evalString(text) {
  10981. if (text.lastIndexOf('\\') < 0) return text;
  10982. 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, "'");
  10983. }
  10984. function parseProperties(text, parsedPropertiesCallback) {
  10985. var dictionary = {};
  10986. var reBlank = /^\s*|\s*$/;
  10987. var reComment = /^\s*#|^\s*$/;
  10988. var reSection = /^\s*\[(.*)\]\s*$/;
  10989. var reImport = /^\s*@import\s+url\((.*)\)\s*$/i;
  10990. var reSplit = /^([^=\s]*)\s*=\s*(.+)$/;
  10991. function parseRawLines(rawText, extendedSyntax, parsedRawLinesCallback) {
  10992. var entries = rawText.replace(reBlank, '').split(/[\r\n]+/);
  10993. var currentLang = '*';
  10994. var genericLang = lang.split('-', 1)[0];
  10995. var skipLang = false;
  10996. var match = '';
  10997. function nextEntry() {
  10998. while (true) {
  10999. if (!entries.length) {
  11000. parsedRawLinesCallback();
  11001. return;
  11002. }
  11003. var line = entries.shift();
  11004. if (reComment.test(line)) continue;
  11005. if (extendedSyntax) {
  11006. match = reSection.exec(line);
  11007. if (match) {
  11008. currentLang = match[1].toLowerCase();
  11009. skipLang = currentLang !== '*' && currentLang !== lang && currentLang !== genericLang;
  11010. continue;
  11011. } else if (skipLang) {
  11012. continue;
  11013. }
  11014. match = reImport.exec(line);
  11015. if (match) {
  11016. loadImport(baseURL + match[1], nextEntry);
  11017. return;
  11018. }
  11019. }
  11020. var tmp = line.match(reSplit);
  11021. if (tmp && tmp.length == 3) {
  11022. dictionary[tmp[1]] = evalString(tmp[2]);
  11023. }
  11024. }
  11025. }
  11026. nextEntry();
  11027. }
  11028. function loadImport(url, callback) {
  11029. xhrLoadText(url, function (content) {
  11030. parseRawLines(content, false, callback);
  11031. }, function () {
  11032. console.warn(url + ' not found.');
  11033. callback();
  11034. });
  11035. }
  11036. parseRawLines(text, true, function () {
  11037. parsedPropertiesCallback(dictionary);
  11038. });
  11039. }
  11040. xhrLoadText(href, function (response) {
  11041. gTextData += response;
  11042. parseProperties(response, function (data) {
  11043. for (var key in data) {
  11044. var id,
  11045. prop,
  11046. index = key.lastIndexOf('.');
  11047. if (index > 0) {
  11048. id = key.substring(0, index);
  11049. prop = key.substring(index + 1);
  11050. } else {
  11051. id = key;
  11052. prop = gTextProp;
  11053. }
  11054. if (!gL10nData[id]) {
  11055. gL10nData[id] = {};
  11056. }
  11057. gL10nData[id][prop] = data[key];
  11058. }
  11059. if (successCallback) {
  11060. successCallback();
  11061. }
  11062. });
  11063. }, failureCallback);
  11064. }
  11065. function loadLocale(lang, callback) {
  11066. if (lang) {
  11067. lang = lang.toLowerCase();
  11068. }
  11069. callback = callback || function _callback() {};
  11070. clear();
  11071. gLanguage = lang;
  11072. var langLinks = getL10nResourceLinks();
  11073. var langCount = langLinks.length;
  11074. if (langCount === 0) {
  11075. var dict = getL10nDictionary();
  11076. if (dict && dict.locales && dict.default_locale) {
  11077. console.log('using the embedded JSON directory, early way out');
  11078. gL10nData = dict.locales[lang];
  11079. if (!gL10nData) {
  11080. var defaultLocale = dict.default_locale.toLowerCase();
  11081. for (var anyCaseLang in dict.locales) {
  11082. anyCaseLang = anyCaseLang.toLowerCase();
  11083. if (anyCaseLang === lang) {
  11084. gL10nData = dict.locales[lang];
  11085. break;
  11086. } else if (anyCaseLang === defaultLocale) {
  11087. gL10nData = dict.locales[defaultLocale];
  11088. }
  11089. }
  11090. }
  11091. callback();
  11092. } else {
  11093. console.log('no resource to load, early way out');
  11094. }
  11095. gReadyState = 'complete';
  11096. return;
  11097. }
  11098. var onResourceLoaded = null;
  11099. var gResourceCount = 0;
  11100. onResourceLoaded = function () {
  11101. gResourceCount++;
  11102. if (gResourceCount >= langCount) {
  11103. callback();
  11104. gReadyState = 'complete';
  11105. }
  11106. };
  11107. function L10nResourceLink(link) {
  11108. var href = link.href;
  11109. this.load = function (lang, callback) {
  11110. parseResource(href, lang, callback, function () {
  11111. console.warn(href + ' not found.');
  11112. console.warn('"' + lang + '" resource not found');
  11113. gLanguage = '';
  11114. callback();
  11115. });
  11116. };
  11117. }
  11118. for (var i = 0; i < langCount; i++) {
  11119. var resource = new L10nResourceLink(langLinks[i]);
  11120. resource.load(lang, onResourceLoaded);
  11121. }
  11122. }
  11123. function clear() {
  11124. gL10nData = {};
  11125. gTextData = '';
  11126. gLanguage = '';
  11127. }
  11128. function getPluralRules(lang) {
  11129. var locales2rules = {
  11130. 'af': 3,
  11131. 'ak': 4,
  11132. 'am': 4,
  11133. 'ar': 1,
  11134. 'asa': 3,
  11135. 'az': 0,
  11136. 'be': 11,
  11137. 'bem': 3,
  11138. 'bez': 3,
  11139. 'bg': 3,
  11140. 'bh': 4,
  11141. 'bm': 0,
  11142. 'bn': 3,
  11143. 'bo': 0,
  11144. 'br': 20,
  11145. 'brx': 3,
  11146. 'bs': 11,
  11147. 'ca': 3,
  11148. 'cgg': 3,
  11149. 'chr': 3,
  11150. 'cs': 12,
  11151. 'cy': 17,
  11152. 'da': 3,
  11153. 'de': 3,
  11154. 'dv': 3,
  11155. 'dz': 0,
  11156. 'ee': 3,
  11157. 'el': 3,
  11158. 'en': 3,
  11159. 'eo': 3,
  11160. 'es': 3,
  11161. 'et': 3,
  11162. 'eu': 3,
  11163. 'fa': 0,
  11164. 'ff': 5,
  11165. 'fi': 3,
  11166. 'fil': 4,
  11167. 'fo': 3,
  11168. 'fr': 5,
  11169. 'fur': 3,
  11170. 'fy': 3,
  11171. 'ga': 8,
  11172. 'gd': 24,
  11173. 'gl': 3,
  11174. 'gsw': 3,
  11175. 'gu': 3,
  11176. 'guw': 4,
  11177. 'gv': 23,
  11178. 'ha': 3,
  11179. 'haw': 3,
  11180. 'he': 2,
  11181. 'hi': 4,
  11182. 'hr': 11,
  11183. 'hu': 0,
  11184. 'id': 0,
  11185. 'ig': 0,
  11186. 'ii': 0,
  11187. 'is': 3,
  11188. 'it': 3,
  11189. 'iu': 7,
  11190. 'ja': 0,
  11191. 'jmc': 3,
  11192. 'jv': 0,
  11193. 'ka': 0,
  11194. 'kab': 5,
  11195. 'kaj': 3,
  11196. 'kcg': 3,
  11197. 'kde': 0,
  11198. 'kea': 0,
  11199. 'kk': 3,
  11200. 'kl': 3,
  11201. 'km': 0,
  11202. 'kn': 0,
  11203. 'ko': 0,
  11204. 'ksb': 3,
  11205. 'ksh': 21,
  11206. 'ku': 3,
  11207. 'kw': 7,
  11208. 'lag': 18,
  11209. 'lb': 3,
  11210. 'lg': 3,
  11211. 'ln': 4,
  11212. 'lo': 0,
  11213. 'lt': 10,
  11214. 'lv': 6,
  11215. 'mas': 3,
  11216. 'mg': 4,
  11217. 'mk': 16,
  11218. 'ml': 3,
  11219. 'mn': 3,
  11220. 'mo': 9,
  11221. 'mr': 3,
  11222. 'ms': 0,
  11223. 'mt': 15,
  11224. 'my': 0,
  11225. 'nah': 3,
  11226. 'naq': 7,
  11227. 'nb': 3,
  11228. 'nd': 3,
  11229. 'ne': 3,
  11230. 'nl': 3,
  11231. 'nn': 3,
  11232. 'no': 3,
  11233. 'nr': 3,
  11234. 'nso': 4,
  11235. 'ny': 3,
  11236. 'nyn': 3,
  11237. 'om': 3,
  11238. 'or': 3,
  11239. 'pa': 3,
  11240. 'pap': 3,
  11241. 'pl': 13,
  11242. 'ps': 3,
  11243. 'pt': 3,
  11244. 'rm': 3,
  11245. 'ro': 9,
  11246. 'rof': 3,
  11247. 'ru': 11,
  11248. 'rwk': 3,
  11249. 'sah': 0,
  11250. 'saq': 3,
  11251. 'se': 7,
  11252. 'seh': 3,
  11253. 'ses': 0,
  11254. 'sg': 0,
  11255. 'sh': 11,
  11256. 'shi': 19,
  11257. 'sk': 12,
  11258. 'sl': 14,
  11259. 'sma': 7,
  11260. 'smi': 7,
  11261. 'smj': 7,
  11262. 'smn': 7,
  11263. 'sms': 7,
  11264. 'sn': 3,
  11265. 'so': 3,
  11266. 'sq': 3,
  11267. 'sr': 11,
  11268. 'ss': 3,
  11269. 'ssy': 3,
  11270. 'st': 3,
  11271. 'sv': 3,
  11272. 'sw': 3,
  11273. 'syr': 3,
  11274. 'ta': 3,
  11275. 'te': 3,
  11276. 'teo': 3,
  11277. 'th': 0,
  11278. 'ti': 4,
  11279. 'tig': 3,
  11280. 'tk': 3,
  11281. 'tl': 4,
  11282. 'tn': 3,
  11283. 'to': 0,
  11284. 'tr': 0,
  11285. 'ts': 3,
  11286. 'tzm': 22,
  11287. 'uk': 11,
  11288. 'ur': 3,
  11289. 've': 3,
  11290. 'vi': 0,
  11291. 'vun': 3,
  11292. 'wa': 4,
  11293. 'wae': 3,
  11294. 'wo': 0,
  11295. 'xh': 3,
  11296. 'xog': 3,
  11297. 'yo': 0,
  11298. 'zh': 0,
  11299. 'zu': 3
  11300. };
  11301. function isIn(n, list) {
  11302. return list.indexOf(n) !== -1;
  11303. }
  11304. function isBetween(n, start, end) {
  11305. return start <= n && n <= end;
  11306. }
  11307. var pluralRules = {
  11308. '0': function (n) {
  11309. return 'other';
  11310. },
  11311. '1': function (n) {
  11312. if (isBetween(n % 100, 3, 10)) return 'few';
  11313. if (n === 0) return 'zero';
  11314. if (isBetween(n % 100, 11, 99)) return 'many';
  11315. if (n == 2) return 'two';
  11316. if (n == 1) return 'one';
  11317. return 'other';
  11318. },
  11319. '2': function (n) {
  11320. if (n !== 0 && n % 10 === 0) return 'many';
  11321. if (n == 2) return 'two';
  11322. if (n == 1) return 'one';
  11323. return 'other';
  11324. },
  11325. '3': function (n) {
  11326. if (n == 1) return 'one';
  11327. return 'other';
  11328. },
  11329. '4': function (n) {
  11330. if (isBetween(n, 0, 1)) return 'one';
  11331. return 'other';
  11332. },
  11333. '5': function (n) {
  11334. if (isBetween(n, 0, 2) && n != 2) return 'one';
  11335. return 'other';
  11336. },
  11337. '6': function (n) {
  11338. if (n === 0) return 'zero';
  11339. if (n % 10 == 1 && n % 100 != 11) return 'one';
  11340. return 'other';
  11341. },
  11342. '7': function (n) {
  11343. if (n == 2) return 'two';
  11344. if (n == 1) return 'one';
  11345. return 'other';
  11346. },
  11347. '8': function (n) {
  11348. if (isBetween(n, 3, 6)) return 'few';
  11349. if (isBetween(n, 7, 10)) return 'many';
  11350. if (n == 2) return 'two';
  11351. if (n == 1) return 'one';
  11352. return 'other';
  11353. },
  11354. '9': function (n) {
  11355. if (n === 0 || n != 1 && isBetween(n % 100, 1, 19)) return 'few';
  11356. if (n == 1) return 'one';
  11357. return 'other';
  11358. },
  11359. '10': function (n) {
  11360. if (isBetween(n % 10, 2, 9) && !isBetween(n % 100, 11, 19)) return 'few';
  11361. if (n % 10 == 1 && !isBetween(n % 100, 11, 19)) return 'one';
  11362. return 'other';
  11363. },
  11364. '11': function (n) {
  11365. if (isBetween(n % 10, 2, 4) && !isBetween(n % 100, 12, 14)) return 'few';
  11366. if (n % 10 === 0 || isBetween(n % 10, 5, 9) || isBetween(n % 100, 11, 14)) return 'many';
  11367. if (n % 10 == 1 && n % 100 != 11) return 'one';
  11368. return 'other';
  11369. },
  11370. '12': function (n) {
  11371. if (isBetween(n, 2, 4)) return 'few';
  11372. if (n == 1) return 'one';
  11373. return 'other';
  11374. },
  11375. '13': function (n) {
  11376. if (isBetween(n % 10, 2, 4) && !isBetween(n % 100, 12, 14)) return 'few';
  11377. if (n != 1 && isBetween(n % 10, 0, 1) || isBetween(n % 10, 5, 9) || isBetween(n % 100, 12, 14)) return 'many';
  11378. if (n == 1) return 'one';
  11379. return 'other';
  11380. },
  11381. '14': function (n) {
  11382. if (isBetween(n % 100, 3, 4)) return 'few';
  11383. if (n % 100 == 2) return 'two';
  11384. if (n % 100 == 1) return 'one';
  11385. return 'other';
  11386. },
  11387. '15': function (n) {
  11388. if (n === 0 || isBetween(n % 100, 2, 10)) return 'few';
  11389. if (isBetween(n % 100, 11, 19)) return 'many';
  11390. if (n == 1) return 'one';
  11391. return 'other';
  11392. },
  11393. '16': function (n) {
  11394. if (n % 10 == 1 && n != 11) return 'one';
  11395. return 'other';
  11396. },
  11397. '17': function (n) {
  11398. if (n == 3) return 'few';
  11399. if (n === 0) return 'zero';
  11400. if (n == 6) return 'many';
  11401. if (n == 2) return 'two';
  11402. if (n == 1) return 'one';
  11403. return 'other';
  11404. },
  11405. '18': function (n) {
  11406. if (n === 0) return 'zero';
  11407. if (isBetween(n, 0, 2) && n !== 0 && n != 2) return 'one';
  11408. return 'other';
  11409. },
  11410. '19': function (n) {
  11411. if (isBetween(n, 2, 10)) return 'few';
  11412. if (isBetween(n, 0, 1)) return 'one';
  11413. return 'other';
  11414. },
  11415. '20': function (n) {
  11416. 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';
  11417. if (n % 1000000 === 0 && n !== 0) return 'many';
  11418. if (n % 10 == 2 && !isIn(n % 100, [12, 72, 92])) return 'two';
  11419. if (n % 10 == 1 && !isIn(n % 100, [11, 71, 91])) return 'one';
  11420. return 'other';
  11421. },
  11422. '21': function (n) {
  11423. if (n === 0) return 'zero';
  11424. if (n == 1) return 'one';
  11425. return 'other';
  11426. },
  11427. '22': function (n) {
  11428. if (isBetween(n, 0, 1) || isBetween(n, 11, 99)) return 'one';
  11429. return 'other';
  11430. },
  11431. '23': function (n) {
  11432. if (isBetween(n % 10, 1, 2) || n % 20 === 0) return 'one';
  11433. return 'other';
  11434. },
  11435. '24': function (n) {
  11436. if (isBetween(n, 3, 10) || isBetween(n, 13, 19)) return 'few';
  11437. if (isIn(n, [2, 12])) return 'two';
  11438. if (isIn(n, [1, 11])) return 'one';
  11439. return 'other';
  11440. }
  11441. };
  11442. var index = locales2rules[lang.replace(/-.*$/, '')];
  11443. if (!(index in pluralRules)) {
  11444. console.warn('plural form unknown for [' + lang + ']');
  11445. return function () {
  11446. return 'other';
  11447. };
  11448. }
  11449. return pluralRules[index];
  11450. }
  11451. gMacros.plural = function (str, param, key, prop) {
  11452. var n = parseFloat(param);
  11453. if (isNaN(n)) return str;
  11454. if (prop != gTextProp) return str;
  11455. if (!gMacros._pluralRules) {
  11456. gMacros._pluralRules = getPluralRules(gLanguage);
  11457. }
  11458. var index = '[' + gMacros._pluralRules(n) + ']';
  11459. if (n === 0 && key + '[zero]' in gL10nData) {
  11460. str = gL10nData[key + '[zero]'][prop];
  11461. } else if (n == 1 && key + '[one]' in gL10nData) {
  11462. str = gL10nData[key + '[one]'][prop];
  11463. } else if (n == 2 && key + '[two]' in gL10nData) {
  11464. str = gL10nData[key + '[two]'][prop];
  11465. } else if (key + index in gL10nData) {
  11466. str = gL10nData[key + index][prop];
  11467. } else if (key + '[other]' in gL10nData) {
  11468. str = gL10nData[key + '[other]'][prop];
  11469. }
  11470. return str;
  11471. };
  11472. function getL10nData(key, args, fallback) {
  11473. var data = gL10nData[key];
  11474. if (!data) {
  11475. console.warn('#' + key + ' is undefined.');
  11476. if (!fallback) {
  11477. return null;
  11478. }
  11479. data = fallback;
  11480. }
  11481. var rv = {};
  11482. for (var prop in data) {
  11483. var str = data[prop];
  11484. str = substIndexes(str, args, key, prop);
  11485. str = substArguments(str, args, key);
  11486. rv[prop] = str;
  11487. }
  11488. return rv;
  11489. }
  11490. function substIndexes(str, args, key, prop) {
  11491. var reIndex = /\{\[\s*([a-zA-Z]+)\(([a-zA-Z]+)\)\s*\]\}/;
  11492. var reMatch = reIndex.exec(str);
  11493. if (!reMatch || !reMatch.length) return str;
  11494. var macroName = reMatch[1];
  11495. var paramName = reMatch[2];
  11496. var param;
  11497. if (args && paramName in args) {
  11498. param = args[paramName];
  11499. } else if (paramName in gL10nData) {
  11500. param = gL10nData[paramName];
  11501. }
  11502. if (macroName in gMacros) {
  11503. var macro = gMacros[macroName];
  11504. str = macro(str, param, key, prop);
  11505. }
  11506. return str;
  11507. }
  11508. function substArguments(str, args, key) {
  11509. var reArgs = /\{\{\s*(.+?)\s*\}\}/g;
  11510. return str.replace(reArgs, function (matched_text, arg) {
  11511. if (args && arg in args) {
  11512. return args[arg];
  11513. }
  11514. if (arg in gL10nData) {
  11515. return gL10nData[arg];
  11516. }
  11517. console.log('argument {{' + arg + '}} for #' + key + ' is undefined.');
  11518. return matched_text;
  11519. });
  11520. }
  11521. function translateElement(element) {
  11522. var l10n = getL10nAttributes(element);
  11523. if (!l10n.id) return;
  11524. var data = getL10nData(l10n.id, l10n.args);
  11525. if (!data) {
  11526. console.warn('#' + l10n.id + ' is undefined.');
  11527. return;
  11528. }
  11529. if (data[gTextProp]) {
  11530. if (getChildElementCount(element) === 0) {
  11531. element[gTextProp] = data[gTextProp];
  11532. } else {
  11533. var children = element.childNodes;
  11534. var found = false;
  11535. for (var i = 0, l = children.length; i < l; i++) {
  11536. if (children[i].nodeType === 3 && /\S/.test(children[i].nodeValue)) {
  11537. if (found) {
  11538. children[i].nodeValue = '';
  11539. } else {
  11540. children[i].nodeValue = data[gTextProp];
  11541. found = true;
  11542. }
  11543. }
  11544. }
  11545. if (!found) {
  11546. var textNode = document.createTextNode(data[gTextProp]);
  11547. element.insertBefore(textNode, element.firstChild);
  11548. }
  11549. }
  11550. delete data[gTextProp];
  11551. }
  11552. for (var k in data) {
  11553. element[k] = data[k];
  11554. }
  11555. }
  11556. function getChildElementCount(element) {
  11557. if (element.children) {
  11558. return element.children.length;
  11559. }
  11560. if (typeof element.childElementCount !== 'undefined') {
  11561. return element.childElementCount;
  11562. }
  11563. var count = 0;
  11564. for (var i = 0; i < element.childNodes.length; i++) {
  11565. count += element.nodeType === 1 ? 1 : 0;
  11566. }
  11567. return count;
  11568. }
  11569. function translateFragment(element) {
  11570. element = element || document.documentElement;
  11571. var children = getTranslatableChildren(element);
  11572. var elementCount = children.length;
  11573. for (var i = 0; i < elementCount; i++) {
  11574. translateElement(children[i]);
  11575. }
  11576. translateElement(element);
  11577. }
  11578. return {
  11579. get: function (key, args, fallbackString) {
  11580. var index = key.lastIndexOf('.');
  11581. var prop = gTextProp;
  11582. if (index > 0) {
  11583. prop = key.substring(index + 1);
  11584. key = key.substring(0, index);
  11585. }
  11586. var fallback;
  11587. if (fallbackString) {
  11588. fallback = {};
  11589. fallback[prop] = fallbackString;
  11590. }
  11591. var data = getL10nData(key, args, fallback);
  11592. if (data && prop in data) {
  11593. return data[prop];
  11594. }
  11595. return '{{' + key + '}}';
  11596. },
  11597. getData: function () {
  11598. return gL10nData;
  11599. },
  11600. getText: function () {
  11601. return gTextData;
  11602. },
  11603. getLanguage: function () {
  11604. return gLanguage;
  11605. },
  11606. setLanguage: function (lang, callback) {
  11607. loadLocale(lang, function () {
  11608. if (callback) callback();
  11609. });
  11610. },
  11611. getDirection: function () {
  11612. var rtlList = ['ar', 'he', 'fa', 'ps', 'ur'];
  11613. var shortCode = gLanguage.split('-', 1)[0];
  11614. return rtlList.indexOf(shortCode) >= 0 ? 'rtl' : 'ltr';
  11615. },
  11616. translate: translateFragment,
  11617. getReadyState: function () {
  11618. return gReadyState;
  11619. },
  11620. ready: function (callback) {
  11621. if (!callback) {
  11622. return;
  11623. } else if (gReadyState == 'complete' || gReadyState == 'interactive') {
  11624. window.setTimeout(function () {
  11625. callback();
  11626. });
  11627. } else if (document.addEventListener) {
  11628. document.addEventListener('localized', function once() {
  11629. document.removeEventListener('localized', once);
  11630. callback();
  11631. });
  11632. }
  11633. }
  11634. };
  11635. }(window, document);
  11636. /***/ }),
  11637. /* 43 */
  11638. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11639. Object.defineProperty(exports, "__esModule", ({
  11640. value: true
  11641. }));
  11642. exports.docPropertiesLookup = docPropertiesLookup;
  11643. exports.GenericScripting = void 0;
  11644. var _pdfjsLib = __webpack_require__(5);
  11645. async function docPropertiesLookup(pdfDocument) {
  11646. const url = "",
  11647. baseUrl = url.split("#")[0];
  11648. let {
  11649. info,
  11650. metadata,
  11651. contentDispositionFilename,
  11652. contentLength
  11653. } = await pdfDocument.getMetadata();
  11654. if (!contentLength) {
  11655. const {
  11656. length
  11657. } = await pdfDocument.getDownloadInfo();
  11658. contentLength = length;
  11659. }
  11660. return { ...info,
  11661. baseURL: baseUrl,
  11662. filesize: contentLength,
  11663. filename: contentDispositionFilename || (0, _pdfjsLib.getPdfFilenameFromUrl)(url),
  11664. metadata: metadata?.getRaw(),
  11665. authors: metadata?.get("dc:creator"),
  11666. numPages: pdfDocument.numPages,
  11667. URL: url
  11668. };
  11669. }
  11670. class GenericScripting {
  11671. constructor(sandboxBundleSrc) {
  11672. this._ready = (0, _pdfjsLib.loadScript)(sandboxBundleSrc, true).then(() => {
  11673. return window.pdfjsSandbox.QuickJSSandbox();
  11674. });
  11675. }
  11676. async createSandbox(data) {
  11677. const sandbox = await this._ready;
  11678. sandbox.create(data);
  11679. }
  11680. async dispatchEventInSandbox(event) {
  11681. const sandbox = await this._ready;
  11682. sandbox.dispatchEvent(event);
  11683. }
  11684. async destroySandbox() {
  11685. const sandbox = await this._ready;
  11686. sandbox.nukeSandbox();
  11687. }
  11688. }
  11689. exports.GenericScripting = GenericScripting;
  11690. /***/ }),
  11691. /* 44 */
  11692. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  11693. Object.defineProperty(exports, "__esModule", ({
  11694. value: true
  11695. }));
  11696. exports.PDFPrintService = PDFPrintService;
  11697. var _app = __webpack_require__(3);
  11698. var _viewer_compatibility = __webpack_require__(2);
  11699. let activeService = null;
  11700. let overlayManager = null;
  11701. function renderPage(activeServiceOnEntry, pdfDocument, pageNumber, size, printResolution, optionalContentConfigPromise) {
  11702. const scratchCanvas = activeService.scratchCanvas;
  11703. const PRINT_UNITS = printResolution / 72.0;
  11704. scratchCanvas.width = Math.floor(size.width * PRINT_UNITS);
  11705. scratchCanvas.height = Math.floor(size.height * PRINT_UNITS);
  11706. const ctx = scratchCanvas.getContext("2d");
  11707. ctx.save();
  11708. ctx.fillStyle = "rgb(255, 255, 255)";
  11709. ctx.fillRect(0, 0, scratchCanvas.width, scratchCanvas.height);
  11710. ctx.restore();
  11711. return pdfDocument.getPage(pageNumber).then(function (pdfPage) {
  11712. const renderContext = {
  11713. canvasContext: ctx,
  11714. transform: [PRINT_UNITS, 0, 0, PRINT_UNITS, 0, 0],
  11715. viewport: pdfPage.getViewport({
  11716. scale: 1,
  11717. rotation: size.rotation
  11718. }),
  11719. intent: "print",
  11720. annotationStorage: pdfDocument.annotationStorage,
  11721. optionalContentConfigPromise
  11722. };
  11723. return pdfPage.render(renderContext).promise;
  11724. });
  11725. }
  11726. function PDFPrintService(pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise = null, l10n) {
  11727. this.pdfDocument = pdfDocument;
  11728. this.pagesOverview = pagesOverview;
  11729. this.printContainer = printContainer;
  11730. this._printResolution = printResolution || 150;
  11731. this._optionalContentConfigPromise = optionalContentConfigPromise || pdfDocument.getOptionalContentConfig();
  11732. this.l10n = l10n;
  11733. this.currentPage = -1;
  11734. this.scratchCanvas = document.createElement("canvas");
  11735. }
  11736. PDFPrintService.prototype = {
  11737. layout() {
  11738. this.throwIfInactive();
  11739. const body = document.querySelector("body");
  11740. body.setAttribute("data-pdfjsprinting", true);
  11741. const hasEqualPageSizes = this.pagesOverview.every(function (size) {
  11742. return size.width === this.pagesOverview[0].width && size.height === this.pagesOverview[0].height;
  11743. }, this);
  11744. if (!hasEqualPageSizes) {
  11745. console.warn("Not all pages have the same size. The printed " + "result may be incorrect!");
  11746. }
  11747. this.pageStyleSheet = document.createElement("style");
  11748. const pageSize = this.pagesOverview[0];
  11749. this.pageStyleSheet.textContent = "@page { size: " + pageSize.width + "pt " + pageSize.height + "pt;}";
  11750. body.appendChild(this.pageStyleSheet);
  11751. },
  11752. destroy() {
  11753. if (activeService !== this) {
  11754. return;
  11755. }
  11756. this.printContainer.textContent = "";
  11757. const body = document.querySelector("body");
  11758. body.removeAttribute("data-pdfjsprinting");
  11759. if (this.pageStyleSheet) {
  11760. this.pageStyleSheet.remove();
  11761. this.pageStyleSheet = null;
  11762. }
  11763. this.scratchCanvas.width = this.scratchCanvas.height = 0;
  11764. this.scratchCanvas = null;
  11765. activeService = null;
  11766. ensureOverlay().then(function () {
  11767. if (overlayManager.active !== "printServiceOverlay") {
  11768. return;
  11769. }
  11770. overlayManager.close("printServiceOverlay");
  11771. });
  11772. },
  11773. renderPages() {
  11774. const pageCount = this.pagesOverview.length;
  11775. const renderNextPage = (resolve, reject) => {
  11776. this.throwIfInactive();
  11777. if (++this.currentPage >= pageCount) {
  11778. renderProgress(pageCount, pageCount, this.l10n);
  11779. resolve();
  11780. return;
  11781. }
  11782. const index = this.currentPage;
  11783. renderProgress(index, pageCount, this.l10n);
  11784. renderPage(this, this.pdfDocument, index + 1, this.pagesOverview[index], this._printResolution, this._optionalContentConfigPromise).then(this.useRenderedPage.bind(this)).then(function () {
  11785. renderNextPage(resolve, reject);
  11786. }, reject);
  11787. };
  11788. return new Promise(renderNextPage);
  11789. },
  11790. useRenderedPage() {
  11791. this.throwIfInactive();
  11792. const img = document.createElement("img");
  11793. const scratchCanvas = this.scratchCanvas;
  11794. if ("toBlob" in scratchCanvas && !_viewer_compatibility.viewerCompatibilityParams.disableCreateObjectURL) {
  11795. scratchCanvas.toBlob(function (blob) {
  11796. img.src = URL.createObjectURL(blob);
  11797. });
  11798. } else {
  11799. img.src = scratchCanvas.toDataURL();
  11800. }
  11801. const wrapper = document.createElement("div");
  11802. wrapper.appendChild(img);
  11803. this.printContainer.appendChild(wrapper);
  11804. return new Promise(function (resolve, reject) {
  11805. img.onload = resolve;
  11806. img.onerror = reject;
  11807. });
  11808. },
  11809. performPrint() {
  11810. this.throwIfInactive();
  11811. return new Promise(resolve => {
  11812. setTimeout(() => {
  11813. if (!this.active) {
  11814. resolve();
  11815. return;
  11816. }
  11817. print.call(window);
  11818. setTimeout(resolve, 20);
  11819. }, 0);
  11820. });
  11821. },
  11822. get active() {
  11823. return this === activeService;
  11824. },
  11825. throwIfInactive() {
  11826. if (!this.active) {
  11827. throw new Error("This print request was cancelled or completed.");
  11828. }
  11829. }
  11830. };
  11831. const print = window.print;
  11832. window.print = function () {
  11833. if (activeService) {
  11834. console.warn("Ignored window.print() because of a pending print job.");
  11835. return;
  11836. }
  11837. ensureOverlay().then(function () {
  11838. if (activeService) {
  11839. overlayManager.open("printServiceOverlay");
  11840. }
  11841. });
  11842. try {
  11843. dispatchEvent("beforeprint");
  11844. } finally {
  11845. if (!activeService) {
  11846. console.error("Expected print service to be initialized.");
  11847. ensureOverlay().then(function () {
  11848. if (overlayManager.active === "printServiceOverlay") {
  11849. overlayManager.close("printServiceOverlay");
  11850. }
  11851. });
  11852. return;
  11853. }
  11854. const activeServiceOnEntry = activeService;
  11855. activeService.renderPages().then(function () {
  11856. return activeServiceOnEntry.performPrint();
  11857. }).catch(function () {}).then(function () {
  11858. if (activeServiceOnEntry.active) {
  11859. abort();
  11860. }
  11861. });
  11862. }
  11863. };
  11864. function dispatchEvent(eventType) {
  11865. const event = document.createEvent("CustomEvent");
  11866. event.initCustomEvent(eventType, false, false, "custom");
  11867. window.dispatchEvent(event);
  11868. }
  11869. function abort() {
  11870. if (activeService) {
  11871. activeService.destroy();
  11872. dispatchEvent("afterprint");
  11873. }
  11874. }
  11875. function renderProgress(index, total, l10n) {
  11876. const progressContainer = document.getElementById("printServiceOverlay");
  11877. const progress = Math.round(100 * index / total);
  11878. const progressBar = progressContainer.querySelector("progress");
  11879. const progressPerc = progressContainer.querySelector(".relative-progress");
  11880. progressBar.value = progress;
  11881. l10n.get("print_progress_percent", {
  11882. progress
  11883. }).then(msg => {
  11884. progressPerc.textContent = msg;
  11885. });
  11886. }
  11887. window.addEventListener("keydown", function (event) {
  11888. if (event.keyCode === 80 && (event.ctrlKey || event.metaKey) && !event.altKey && (!event.shiftKey || window.chrome || window.opera)) {
  11889. window.print();
  11890. event.preventDefault();
  11891. if (event.stopImmediatePropagation) {
  11892. event.stopImmediatePropagation();
  11893. } else {
  11894. event.stopPropagation();
  11895. }
  11896. }
  11897. }, true);
  11898. if ("onbeforeprint" in window) {
  11899. const stopPropagationIfNeeded = function (event) {
  11900. if (event.detail !== "custom" && event.stopImmediatePropagation) {
  11901. event.stopImmediatePropagation();
  11902. }
  11903. };
  11904. window.addEventListener("beforeprint", stopPropagationIfNeeded);
  11905. window.addEventListener("afterprint", stopPropagationIfNeeded);
  11906. }
  11907. let overlayPromise;
  11908. function ensureOverlay() {
  11909. if (!overlayPromise) {
  11910. overlayManager = _app.PDFViewerApplication.overlayManager;
  11911. if (!overlayManager) {
  11912. throw new Error("The overlay manager has not yet been initialized.");
  11913. }
  11914. overlayPromise = overlayManager.register("printServiceOverlay", document.getElementById("printServiceOverlay"), abort, true);
  11915. document.getElementById("printCancel").onclick = abort;
  11916. }
  11917. return overlayPromise;
  11918. }
  11919. _app.PDFPrintServiceFactory.instance = {
  11920. supportsPrinting: true,
  11921. createPrintService(pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise, l10n) {
  11922. if (activeService) {
  11923. throw new Error("The print service is created and active.");
  11924. }
  11925. activeService = new PDFPrintService(pdfDocument, pagesOverview, printContainer, printResolution, optionalContentConfigPromise, l10n);
  11926. return activeService;
  11927. }
  11928. };
  11929. /***/ })
  11930. /******/ ]);
  11931. /************************************************************************/
  11932. /******/ // The module cache
  11933. /******/ var __webpack_module_cache__ = {};
  11934. /******/
  11935. /******/ // The require function
  11936. /******/ function __webpack_require__(moduleId) {
  11937. /******/ // Check if module is in cache
  11938. /******/ var cachedModule = __webpack_module_cache__[moduleId];
  11939. /******/ if (cachedModule !== undefined) {
  11940. /******/ return cachedModule.exports;
  11941. /******/ }
  11942. /******/ // Create a new module (and put it into the cache)
  11943. /******/ var module = __webpack_module_cache__[moduleId] = {
  11944. /******/ // no module.id needed
  11945. /******/ // no module.loaded needed
  11946. /******/ exports: {}
  11947. /******/ };
  11948. /******/
  11949. /******/ // Execute the module function
  11950. /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
  11951. /******/
  11952. /******/ // Return the exports of the module
  11953. /******/ return module.exports;
  11954. /******/ }
  11955. /******/
  11956. /************************************************************************/
  11957. var __webpack_exports__ = {};
  11958. // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
  11959. (() => {
  11960. var exports = __webpack_exports__;
  11961. Object.defineProperty(exports, "__esModule", ({
  11962. value: true
  11963. }));
  11964. Object.defineProperty(exports, "PDFViewerApplicationOptions", ({
  11965. enumerable: true,
  11966. get: function () {
  11967. return _app_options.AppOptions;
  11968. }
  11969. }));
  11970. Object.defineProperty(exports, "PDFViewerApplication", ({
  11971. enumerable: true,
  11972. get: function () {
  11973. return _app.PDFViewerApplication;
  11974. }
  11975. }));
  11976. var _app_options = __webpack_require__(1);
  11977. var _app = __webpack_require__(3);
  11978. const pdfjsVersion = '2.8.335';
  11979. const pdfjsBuild = '228adbf67';
  11980. window.PDFViewerApplication = _app.PDFViewerApplication;
  11981. window.PDFViewerApplicationOptions = _app_options.AppOptions;
  11982. ;
  11983. ;
  11984. {
  11985. __webpack_require__(38);
  11986. }
  11987. ;
  11988. {
  11989. __webpack_require__(44);
  11990. }
  11991. function getViewerConfiguration() {
  11992. let errorWrapper = null;
  11993. errorWrapper = {
  11994. container: document.getElementById("errorWrapper"),
  11995. errorMessage: document.getElementById("errorMessage"),
  11996. closeButton: document.getElementById("errorClose"),
  11997. errorMoreInfo: document.getElementById("errorMoreInfo"),
  11998. moreInfoButton: document.getElementById("errorShowMore"),
  11999. lessInfoButton: document.getElementById("errorShowLess")
  12000. };
  12001. return {
  12002. appContainer: document.body,
  12003. mainContainer: document.getElementById("viewerContainer"),
  12004. viewerContainer: document.getElementById("viewer"),
  12005. eventBus: null,
  12006. toolbar: {
  12007. container: document.getElementById("toolbarViewer"),
  12008. numPages: document.getElementById("numPages"),
  12009. pageNumber: document.getElementById("pageNumber"),
  12010. scaleSelectContainer: document.getElementById("scaleSelectContainer"),
  12011. scaleSelect: document.getElementById("scaleSelect"),
  12012. customScaleOption: document.getElementById("customScaleOption"),
  12013. previous: document.getElementById("previous"),
  12014. next: document.getElementById("next"),
  12015. zoomIn: document.getElementById("zoomIn"),
  12016. zoomOut: document.getElementById("zoomOut"),
  12017. viewFind: document.getElementById("viewFind"),
  12018. openFile: document.getElementById("openFile"),
  12019. print: document.getElementById("print"),
  12020. presentationModeButton: document.getElementById("presentationMode"),
  12021. download: document.getElementById("download"),
  12022. viewBookmark: document.getElementById("viewBookmark")
  12023. },
  12024. secondaryToolbar: {
  12025. toolbar: document.getElementById("secondaryToolbar"),
  12026. toggleButton: document.getElementById("secondaryToolbarToggle"),
  12027. toolbarButtonContainer: document.getElementById("secondaryToolbarButtonContainer"),
  12028. presentationModeButton: document.getElementById("secondaryPresentationMode"),
  12029. openFileButton: document.getElementById("secondaryOpenFile"),
  12030. printButton: document.getElementById("secondaryPrint"),
  12031. downloadButton: document.getElementById("secondaryDownload"),
  12032. viewBookmarkButton: document.getElementById("secondaryViewBookmark"),
  12033. firstPageButton: document.getElementById("firstPage"),
  12034. lastPageButton: document.getElementById("lastPage"),
  12035. pageRotateCwButton: document.getElementById("pageRotateCw"),
  12036. pageRotateCcwButton: document.getElementById("pageRotateCcw"),
  12037. cursorSelectToolButton: document.getElementById("cursorSelectTool"),
  12038. cursorHandToolButton: document.getElementById("cursorHandTool"),
  12039. scrollVerticalButton: document.getElementById("scrollVertical"),
  12040. scrollHorizontalButton: document.getElementById("scrollHorizontal"),
  12041. scrollWrappedButton: document.getElementById("scrollWrapped"),
  12042. spreadNoneButton: document.getElementById("spreadNone"),
  12043. spreadOddButton: document.getElementById("spreadOdd"),
  12044. spreadEvenButton: document.getElementById("spreadEven"),
  12045. documentPropertiesButton: document.getElementById("documentProperties")
  12046. },
  12047. sidebar: {
  12048. outerContainer: document.getElementById("outerContainer"),
  12049. viewerContainer: document.getElementById("viewerContainer"),
  12050. toggleButton: document.getElementById("sidebarToggle"),
  12051. thumbnailButton: document.getElementById("viewThumbnail"),
  12052. outlineButton: document.getElementById("viewOutline"),
  12053. attachmentsButton: document.getElementById("viewAttachments"),
  12054. layersButton: document.getElementById("viewLayers"),
  12055. thumbnailView: document.getElementById("thumbnailView"),
  12056. outlineView: document.getElementById("outlineView"),
  12057. attachmentsView: document.getElementById("attachmentsView"),
  12058. layersView: document.getElementById("layersView"),
  12059. outlineOptionsContainer: document.getElementById("outlineOptionsContainer"),
  12060. currentOutlineItemButton: document.getElementById("currentOutlineItem")
  12061. },
  12062. sidebarResizer: {
  12063. outerContainer: document.getElementById("outerContainer"),
  12064. resizer: document.getElementById("sidebarResizer")
  12065. },
  12066. findBar: {
  12067. bar: document.getElementById("findbar"),
  12068. toggleButton: document.getElementById("viewFind"),
  12069. findField: document.getElementById("findInput"),
  12070. highlightAllCheckbox: document.getElementById("findHighlightAll"),
  12071. caseSensitiveCheckbox: document.getElementById("findMatchCase"),
  12072. entireWordCheckbox: document.getElementById("findEntireWord"),
  12073. findMsg: document.getElementById("findMsg"),
  12074. findResultsCount: document.getElementById("findResultsCount"),
  12075. findPreviousButton: document.getElementById("findPrevious"),
  12076. findNextButton: document.getElementById("findNext")
  12077. },
  12078. passwordOverlay: {
  12079. overlayName: "passwordOverlay",
  12080. container: document.getElementById("passwordOverlay"),
  12081. label: document.getElementById("passwordText"),
  12082. input: document.getElementById("password"),
  12083. submitButton: document.getElementById("passwordSubmit"),
  12084. cancelButton: document.getElementById("passwordCancel")
  12085. },
  12086. documentProperties: {
  12087. overlayName: "documentPropertiesOverlay",
  12088. container: document.getElementById("documentPropertiesOverlay"),
  12089. closeButton: document.getElementById("documentPropertiesClose"),
  12090. fields: {
  12091. fileName: document.getElementById("fileNameField"),
  12092. fileSize: document.getElementById("fileSizeField"),
  12093. title: document.getElementById("titleField"),
  12094. author: document.getElementById("authorField"),
  12095. subject: document.getElementById("subjectField"),
  12096. keywords: document.getElementById("keywordsField"),
  12097. creationDate: document.getElementById("creationDateField"),
  12098. modificationDate: document.getElementById("modificationDateField"),
  12099. creator: document.getElementById("creatorField"),
  12100. producer: document.getElementById("producerField"),
  12101. version: document.getElementById("versionField"),
  12102. pageCount: document.getElementById("pageCountField"),
  12103. pageSize: document.getElementById("pageSizeField"),
  12104. linearized: document.getElementById("linearizedField")
  12105. }
  12106. },
  12107. errorWrapper,
  12108. printContainer: document.getElementById("printContainer"),
  12109. openFileInputName: "fileInput",
  12110. debuggerScriptPath: "./debugger.js"
  12111. };
  12112. }
  12113. function webViewerLoad() {
  12114. const config = getViewerConfiguration();
  12115. const event = document.createEvent("CustomEvent");
  12116. event.initCustomEvent("webviewerloaded", true, true, {
  12117. source: window
  12118. });
  12119. try {
  12120. parent.document.dispatchEvent(event);
  12121. } catch (ex) {
  12122. console.error(`webviewerloaded: ${ex}`);
  12123. document.dispatchEvent(event);
  12124. }
  12125. _app.PDFViewerApplication.run(config);
  12126. }
  12127. if (document.blockUnblockOnload) {
  12128. document.blockUnblockOnload(true);
  12129. }
  12130. if (document.readyState === "interactive" || document.readyState === "complete") {
  12131. webViewerLoad();
  12132. } else {
  12133. document.addEventListener("DOMContentLoaded", webViewerLoad, true);
  12134. }
  12135. })();
  12136. /******/ })()
  12137. ;
  12138. //# sourceMappingURL=viewer.js.map