better-scroll.esm.js 249 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546
  1. /*!
  2. * better-scroll / better-scroll
  3. * (c) 2016-2021 ustbhuangyi
  4. * Released under the MIT License.
  5. */
  6. /*! *****************************************************************************
  7. Copyright (c) Microsoft Corporation.
  8. Permission to use, copy, modify, and/or distribute this software for any
  9. purpose with or without fee is hereby granted.
  10. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
  11. REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  12. AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
  13. INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  14. LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  15. OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  16. PERFORMANCE OF THIS SOFTWARE.
  17. ***************************************************************************** */
  18. /* global Reflect, Promise */
  19. var extendStatics = function(d, b) {
  20. extendStatics = Object.setPrototypeOf ||
  21. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  22. function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
  23. return extendStatics(d, b);
  24. };
  25. function __extends(d, b) {
  26. extendStatics(d, b);
  27. function __() { this.constructor = d; }
  28. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  29. }
  30. var __assign = function() {
  31. __assign = Object.assign || function __assign(t) {
  32. for (var s, i = 1, n = arguments.length; i < n; i++) {
  33. s = arguments[i];
  34. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
  35. }
  36. return t;
  37. };
  38. return __assign.apply(this, arguments);
  39. };
  40. function __awaiter(thisArg, _arguments, P, generator) {
  41. function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
  42. return new (P || (P = Promise))(function (resolve, reject) {
  43. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  44. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  45. function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
  46. step((generator = generator.apply(thisArg, _arguments || [])).next());
  47. });
  48. }
  49. function __generator(thisArg, body) {
  50. var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
  51. return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
  52. function verb(n) { return function (v) { return step([n, v]); }; }
  53. function step(op) {
  54. if (f) throw new TypeError("Generator is already executing.");
  55. while (_) try {
  56. if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
  57. if (y = 0, t) op = [op[0] & 2, t.value];
  58. switch (op[0]) {
  59. case 0: case 1: t = op; break;
  60. case 4: _.label++; return { value: op[1], done: false };
  61. case 5: _.label++; y = op[1]; op = [0]; continue;
  62. case 7: op = _.ops.pop(); _.trys.pop(); continue;
  63. default:
  64. if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
  65. if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
  66. if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
  67. if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
  68. if (t[2]) _.ops.pop();
  69. _.trys.pop(); continue;
  70. }
  71. op = body.call(thisArg, _);
  72. } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
  73. if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
  74. }
  75. }
  76. function __spreadArrays() {
  77. for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
  78. for (var r = Array(s), k = 0, i = 0; i < il; i++)
  79. for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
  80. r[k] = a[j];
  81. return r;
  82. }
  83. var propertiesConfig$7 = [
  84. {
  85. sourceKey: 'scroller.scrollBehaviorX.currentPos',
  86. key: 'x'
  87. },
  88. {
  89. sourceKey: 'scroller.scrollBehaviorY.currentPos',
  90. key: 'y'
  91. },
  92. {
  93. sourceKey: 'scroller.scrollBehaviorX.hasScroll',
  94. key: 'hasHorizontalScroll'
  95. },
  96. {
  97. sourceKey: 'scroller.scrollBehaviorY.hasScroll',
  98. key: 'hasVerticalScroll'
  99. },
  100. {
  101. sourceKey: 'scroller.scrollBehaviorX.contentSize',
  102. key: 'scrollerWidth'
  103. },
  104. {
  105. sourceKey: 'scroller.scrollBehaviorY.contentSize',
  106. key: 'scrollerHeight'
  107. },
  108. {
  109. sourceKey: 'scroller.scrollBehaviorX.maxScrollPos',
  110. key: 'maxScrollX'
  111. },
  112. {
  113. sourceKey: 'scroller.scrollBehaviorY.maxScrollPos',
  114. key: 'maxScrollY'
  115. },
  116. {
  117. sourceKey: 'scroller.scrollBehaviorX.minScrollPos',
  118. key: 'minScrollX'
  119. },
  120. {
  121. sourceKey: 'scroller.scrollBehaviorY.minScrollPos',
  122. key: 'minScrollY'
  123. },
  124. {
  125. sourceKey: 'scroller.scrollBehaviorX.movingDirection',
  126. key: 'movingDirectionX'
  127. },
  128. {
  129. sourceKey: 'scroller.scrollBehaviorY.movingDirection',
  130. key: 'movingDirectionY'
  131. },
  132. {
  133. sourceKey: 'scroller.scrollBehaviorX.direction',
  134. key: 'directionX'
  135. },
  136. {
  137. sourceKey: 'scroller.scrollBehaviorY.direction',
  138. key: 'directionY'
  139. },
  140. {
  141. sourceKey: 'scroller.actions.enabled',
  142. key: 'enabled'
  143. },
  144. {
  145. sourceKey: 'scroller.animater.pending',
  146. key: 'pending'
  147. },
  148. {
  149. sourceKey: 'scroller.animater.stop',
  150. key: 'stop'
  151. },
  152. {
  153. sourceKey: 'scroller.scrollTo',
  154. key: 'scrollTo'
  155. },
  156. {
  157. sourceKey: 'scroller.scrollBy',
  158. key: 'scrollBy'
  159. },
  160. {
  161. sourceKey: 'scroller.scrollToElement',
  162. key: 'scrollToElement'
  163. },
  164. {
  165. sourceKey: 'scroller.resetPosition',
  166. key: 'resetPosition'
  167. }
  168. ];
  169. function warn(msg) {
  170. console.error("[BScroll warn]: " + msg);
  171. }
  172. function assert(condition, msg) {
  173. if (!condition) {
  174. throw new Error('[BScroll] ' + msg);
  175. }
  176. }
  177. // ssr support
  178. var inBrowser = typeof window !== 'undefined';
  179. var ua = inBrowser && navigator.userAgent.toLowerCase();
  180. var isWeChatDevTools = !!(ua && /wechatdevtools/.test(ua));
  181. var isAndroid = ua && ua.indexOf('android') > 0;
  182. /* istanbul ignore next */
  183. var isIOSBadVersion = (function () {
  184. if (typeof ua === 'string') {
  185. var regex = /os (\d\d?_\d(_\d)?)/;
  186. var matches = regex.exec(ua);
  187. if (!matches)
  188. return false;
  189. var parts = matches[1].split('_').map(function (item) {
  190. return parseInt(item, 10);
  191. });
  192. // ios version >= 13.4 issue 982
  193. return !!(parts[0] === 13 && parts[1] >= 4);
  194. }
  195. return false;
  196. })();
  197. /* istanbul ignore next */
  198. var supportsPassive = false;
  199. /* istanbul ignore next */
  200. if (inBrowser) {
  201. var EventName = 'test-passive';
  202. try {
  203. var opts = {};
  204. Object.defineProperty(opts, 'passive', {
  205. get: function () {
  206. supportsPassive = true;
  207. },
  208. }); // https://github.com/facebook/flow/issues/285
  209. window.addEventListener(EventName, function () { }, opts);
  210. }
  211. catch (e) { }
  212. }
  213. function getNow() {
  214. return window.performance &&
  215. window.performance.now &&
  216. window.performance.timing
  217. ? window.performance.now() + window.performance.timing.navigationStart
  218. : +new Date();
  219. }
  220. var extend = function (target, source) {
  221. for (var key in source) {
  222. target[key] = source[key];
  223. }
  224. return target;
  225. };
  226. function isUndef(v) {
  227. return v === undefined || v === null;
  228. }
  229. function getDistance(x, y) {
  230. return Math.sqrt(x * x + y * y);
  231. }
  232. function between(x, min, max) {
  233. if (x < min) {
  234. return min;
  235. }
  236. if (x > max) {
  237. return max;
  238. }
  239. return x;
  240. }
  241. function findIndex(ary, fn) {
  242. if (ary.findIndex) {
  243. return ary.findIndex(fn);
  244. }
  245. var index = -1;
  246. ary.some(function (item, i, ary) {
  247. var ret = fn(item, i, ary);
  248. if (ret) {
  249. index = i;
  250. return ret;
  251. }
  252. });
  253. return index;
  254. }
  255. var elementStyle = (inBrowser &&
  256. document.createElement('div').style);
  257. var vendor = (function () {
  258. /* istanbul ignore if */
  259. if (!inBrowser) {
  260. return false;
  261. }
  262. var transformNames = [
  263. {
  264. key: 'standard',
  265. value: 'transform',
  266. },
  267. {
  268. key: 'webkit',
  269. value: 'webkitTransform',
  270. },
  271. {
  272. key: 'Moz',
  273. value: 'MozTransform',
  274. },
  275. {
  276. key: 'O',
  277. value: 'OTransform',
  278. },
  279. {
  280. key: 'ms',
  281. value: 'msTransform',
  282. },
  283. ];
  284. for (var _i = 0, transformNames_1 = transformNames; _i < transformNames_1.length; _i++) {
  285. var obj = transformNames_1[_i];
  286. if (elementStyle[obj.value] !== undefined) {
  287. return obj.key;
  288. }
  289. }
  290. /* istanbul ignore next */
  291. return false;
  292. })();
  293. /* istanbul ignore next */
  294. function prefixStyle(style) {
  295. if (vendor === false) {
  296. return style;
  297. }
  298. if (vendor === 'standard') {
  299. if (style === 'transitionEnd') {
  300. return 'transitionend';
  301. }
  302. return style;
  303. }
  304. return vendor + style.charAt(0).toUpperCase() + style.substr(1);
  305. }
  306. function getElement(el) {
  307. return (typeof el === 'string'
  308. ? document.querySelector(el)
  309. : el);
  310. }
  311. function addEvent(el, type, fn, capture) {
  312. var useCapture = supportsPassive
  313. ? {
  314. passive: false,
  315. capture: !!capture,
  316. }
  317. : !!capture;
  318. el.addEventListener(type, fn, useCapture);
  319. }
  320. function removeEvent(el, type, fn, capture) {
  321. el.removeEventListener(type, fn, {
  322. capture: !!capture,
  323. });
  324. }
  325. function offset(el) {
  326. var left = 0;
  327. var top = 0;
  328. while (el) {
  329. left -= el.offsetLeft;
  330. top -= el.offsetTop;
  331. el = el.offsetParent;
  332. }
  333. return {
  334. left: left,
  335. top: top,
  336. };
  337. }
  338. function offsetToBody(el) {
  339. var rect = el.getBoundingClientRect();
  340. return {
  341. left: -(rect.left + window.pageXOffset),
  342. top: -(rect.top + window.pageYOffset),
  343. };
  344. }
  345. var cssVendor = vendor && vendor !== 'standard' ? '-' + vendor.toLowerCase() + '-' : '';
  346. var transform = prefixStyle('transform');
  347. var transition = prefixStyle('transition');
  348. var hasPerspective = inBrowser && prefixStyle('perspective') in elementStyle;
  349. // fix issue #361
  350. var hasTouch = inBrowser && ('ontouchstart' in window || isWeChatDevTools);
  351. var hasTransition = inBrowser && transition in elementStyle;
  352. var style = {
  353. transform: transform,
  354. transition: transition,
  355. transitionTimingFunction: prefixStyle('transitionTimingFunction'),
  356. transitionDuration: prefixStyle('transitionDuration'),
  357. transitionDelay: prefixStyle('transitionDelay'),
  358. transformOrigin: prefixStyle('transformOrigin'),
  359. transitionEnd: prefixStyle('transitionEnd'),
  360. transitionProperty: prefixStyle('transitionProperty'),
  361. };
  362. var eventTypeMap = {
  363. touchstart: 1,
  364. touchmove: 1,
  365. touchend: 1,
  366. touchcancel: 1,
  367. mousedown: 2,
  368. mousemove: 2,
  369. mouseup: 2,
  370. };
  371. function getRect(el) {
  372. /* istanbul ignore if */
  373. if (el instanceof window.SVGElement) {
  374. var rect = el.getBoundingClientRect();
  375. return {
  376. top: rect.top,
  377. left: rect.left,
  378. width: rect.width,
  379. height: rect.height,
  380. };
  381. }
  382. else {
  383. return {
  384. top: el.offsetTop,
  385. left: el.offsetLeft,
  386. width: el.offsetWidth,
  387. height: el.offsetHeight,
  388. };
  389. }
  390. }
  391. function preventDefaultExceptionFn(el, exceptions) {
  392. for (var i in exceptions) {
  393. if (exceptions[i].test(el[i])) {
  394. return true;
  395. }
  396. }
  397. return false;
  398. }
  399. var tagExceptionFn = preventDefaultExceptionFn;
  400. function tap(e, eventName) {
  401. var ev = document.createEvent('Event');
  402. ev.initEvent(eventName, true, true);
  403. ev.pageX = e.pageX;
  404. ev.pageY = e.pageY;
  405. e.target.dispatchEvent(ev);
  406. }
  407. function click(e, event) {
  408. if (event === void 0) { event = 'click'; }
  409. var eventSource;
  410. if (e.type === 'mouseup') {
  411. eventSource = e;
  412. }
  413. else if (e.type === 'touchend' || e.type === 'touchcancel') {
  414. eventSource = e.changedTouches[0];
  415. }
  416. var posSrc = {};
  417. if (eventSource) {
  418. posSrc.screenX = eventSource.screenX || 0;
  419. posSrc.screenY = eventSource.screenY || 0;
  420. posSrc.clientX = eventSource.clientX || 0;
  421. posSrc.clientY = eventSource.clientY || 0;
  422. }
  423. var ev;
  424. var bubbles = true;
  425. var cancelable = true;
  426. var ctrlKey = e.ctrlKey, shiftKey = e.shiftKey, altKey = e.altKey, metaKey = e.metaKey;
  427. var pressedKeysMap = {
  428. ctrlKey: ctrlKey,
  429. shiftKey: shiftKey,
  430. altKey: altKey,
  431. metaKey: metaKey,
  432. };
  433. if (typeof MouseEvent !== 'undefined') {
  434. try {
  435. ev = new MouseEvent(event, extend(__assign({ bubbles: bubbles,
  436. cancelable: cancelable }, pressedKeysMap), posSrc));
  437. }
  438. catch (e) {
  439. /* istanbul ignore next */
  440. createEvent();
  441. }
  442. }
  443. else {
  444. createEvent();
  445. }
  446. function createEvent() {
  447. ev = document.createEvent('Event');
  448. ev.initEvent(event, bubbles, cancelable);
  449. extend(ev, posSrc);
  450. }
  451. // forwardedTouchEvent set to true in case of the conflict with fastclick
  452. ev.forwardedTouchEvent = true;
  453. ev._constructed = true;
  454. e.target.dispatchEvent(ev);
  455. }
  456. function dblclick(e) {
  457. click(e, 'dblclick');
  458. }
  459. function prepend(el, target) {
  460. var firstChild = target.firstChild;
  461. if (firstChild) {
  462. before(el, firstChild);
  463. }
  464. else {
  465. target.appendChild(el);
  466. }
  467. }
  468. function before(el, target) {
  469. var parentNode = target.parentNode;
  470. parentNode.insertBefore(el, target);
  471. }
  472. function removeChild(el, child) {
  473. el.removeChild(child);
  474. }
  475. function hasClass(el, className) {
  476. var reg = new RegExp('(^|\\s)' + className + '(\\s|$)');
  477. return reg.test(el.className);
  478. }
  479. function HTMLCollectionToArray(el) {
  480. return Array.prototype.slice.call(el, 0);
  481. }
  482. function getClientSize(el) {
  483. return {
  484. width: el.clientWidth,
  485. height: el.clientHeight,
  486. };
  487. }
  488. var ease = {
  489. // easeOutQuint
  490. swipe: {
  491. style: 'cubic-bezier(0.23, 1, 0.32, 1)',
  492. fn: function (t) {
  493. return 1 + --t * t * t * t * t;
  494. }
  495. },
  496. // easeOutQuard
  497. swipeBounce: {
  498. style: 'cubic-bezier(0.25, 0.46, 0.45, 0.94)',
  499. fn: function (t) {
  500. return t * (2 - t);
  501. }
  502. },
  503. // easeOutQuart
  504. bounce: {
  505. style: 'cubic-bezier(0.165, 0.84, 0.44, 1)',
  506. fn: function (t) {
  507. return 1 - --t * t * t * t;
  508. }
  509. }
  510. };
  511. var DEFAULT_INTERVAL = 1000 / 60;
  512. var windowCompat = inBrowser && window;
  513. /* istanbul ignore next */
  514. function noop$1() { }
  515. var requestAnimationFrame = (function () {
  516. /* istanbul ignore if */
  517. if (!inBrowser) {
  518. return noop$1;
  519. }
  520. return (windowCompat.requestAnimationFrame ||
  521. windowCompat.webkitRequestAnimationFrame ||
  522. windowCompat.mozRequestAnimationFrame ||
  523. windowCompat.oRequestAnimationFrame ||
  524. // if all else fails, use setTimeout
  525. function (callback) {
  526. return window.setTimeout(callback, callback.interval || DEFAULT_INTERVAL); // make interval as precise as possible.
  527. });
  528. })();
  529. var cancelAnimationFrame = (function () {
  530. /* istanbul ignore if */
  531. if (!inBrowser) {
  532. return noop$1;
  533. }
  534. return (windowCompat.cancelAnimationFrame ||
  535. windowCompat.webkitCancelAnimationFrame ||
  536. windowCompat.mozCancelAnimationFrame ||
  537. windowCompat.oCancelAnimationFrame ||
  538. function (id) {
  539. window.clearTimeout(id);
  540. });
  541. })();
  542. /* istanbul ignore next */
  543. var noop = function (val) { };
  544. var sharedPropertyDefinition = {
  545. enumerable: true,
  546. configurable: true,
  547. get: noop,
  548. set: noop,
  549. };
  550. var getProperty = function (obj, key) {
  551. var keys = key.split('.');
  552. for (var i = 0; i < keys.length - 1; i++) {
  553. obj = obj[keys[i]];
  554. if (typeof obj !== 'object' || !obj)
  555. return;
  556. }
  557. var lastKey = keys.pop();
  558. if (typeof obj[lastKey] === 'function') {
  559. return function () {
  560. return obj[lastKey].apply(obj, arguments);
  561. };
  562. }
  563. else {
  564. return obj[lastKey];
  565. }
  566. };
  567. var setProperty = function (obj, key, value) {
  568. var keys = key.split('.');
  569. var temp;
  570. for (var i = 0; i < keys.length - 1; i++) {
  571. temp = keys[i];
  572. if (!obj[temp])
  573. obj[temp] = {};
  574. obj = obj[temp];
  575. }
  576. obj[keys.pop()] = value;
  577. };
  578. function propertiesProxy(target, sourceKey, key) {
  579. sharedPropertyDefinition.get = function proxyGetter() {
  580. return getProperty(this, sourceKey);
  581. };
  582. sharedPropertyDefinition.set = function proxySetter(val) {
  583. setProperty(this, sourceKey, val);
  584. };
  585. Object.defineProperty(target, key, sharedPropertyDefinition);
  586. }
  587. var EventEmitter = /** @class */ (function () {
  588. function EventEmitter(names) {
  589. this.events = {};
  590. this.eventTypes = {};
  591. this.registerType(names);
  592. }
  593. EventEmitter.prototype.on = function (type, fn, context) {
  594. if (context === void 0) { context = this; }
  595. this.hasType(type);
  596. if (!this.events[type]) {
  597. this.events[type] = [];
  598. }
  599. this.events[type].push([fn, context]);
  600. return this;
  601. };
  602. EventEmitter.prototype.once = function (type, fn, context) {
  603. var _this = this;
  604. if (context === void 0) { context = this; }
  605. this.hasType(type);
  606. var magic = function () {
  607. var args = [];
  608. for (var _i = 0; _i < arguments.length; _i++) {
  609. args[_i] = arguments[_i];
  610. }
  611. _this.off(type, magic);
  612. var ret = fn.apply(context, args);
  613. if (ret === true) {
  614. return ret;
  615. }
  616. };
  617. magic.fn = fn;
  618. this.on(type, magic);
  619. return this;
  620. };
  621. EventEmitter.prototype.off = function (type, fn) {
  622. if (!type && !fn) {
  623. this.events = {};
  624. return this;
  625. }
  626. if (type) {
  627. this.hasType(type);
  628. if (!fn) {
  629. this.events[type] = [];
  630. return this;
  631. }
  632. var events = this.events[type];
  633. if (!events) {
  634. return this;
  635. }
  636. var count = events.length;
  637. while (count--) {
  638. if (events[count][0] === fn ||
  639. (events[count][0] && events[count][0].fn === fn)) {
  640. events.splice(count, 1);
  641. }
  642. }
  643. return this;
  644. }
  645. };
  646. EventEmitter.prototype.trigger = function (type) {
  647. var args = [];
  648. for (var _i = 1; _i < arguments.length; _i++) {
  649. args[_i - 1] = arguments[_i];
  650. }
  651. this.hasType(type);
  652. var events = this.events[type];
  653. if (!events) {
  654. return;
  655. }
  656. var len = events.length;
  657. var eventsCopy = __spreadArrays(events);
  658. var ret;
  659. for (var i = 0; i < len; i++) {
  660. var event_1 = eventsCopy[i];
  661. var fn = event_1[0], context = event_1[1];
  662. if (fn) {
  663. ret = fn.apply(context, args);
  664. if (ret === true) {
  665. return ret;
  666. }
  667. }
  668. }
  669. };
  670. EventEmitter.prototype.registerType = function (names) {
  671. var _this = this;
  672. names.forEach(function (type) {
  673. _this.eventTypes[type] = type;
  674. });
  675. };
  676. EventEmitter.prototype.destroy = function () {
  677. this.events = {};
  678. this.eventTypes = {};
  679. };
  680. EventEmitter.prototype.hasType = function (type) {
  681. var types = this.eventTypes;
  682. var isType = types[type] === type;
  683. if (!isType) {
  684. warn("EventEmitter has used unknown event type: \"" + type + "\", should be oneof [" +
  685. ("" + Object.keys(types).map(function (_) { return JSON.stringify(_); })) +
  686. "]");
  687. }
  688. };
  689. return EventEmitter;
  690. }());
  691. var EventRegister = /** @class */ (function () {
  692. function EventRegister(wrapper, events) {
  693. this.wrapper = wrapper;
  694. this.events = events;
  695. this.addDOMEvents();
  696. }
  697. EventRegister.prototype.destroy = function () {
  698. this.removeDOMEvents();
  699. this.events = [];
  700. };
  701. EventRegister.prototype.addDOMEvents = function () {
  702. this.handleDOMEvents(addEvent);
  703. };
  704. EventRegister.prototype.removeDOMEvents = function () {
  705. this.handleDOMEvents(removeEvent);
  706. };
  707. EventRegister.prototype.handleDOMEvents = function (eventOperation) {
  708. var _this = this;
  709. var wrapper = this.wrapper;
  710. this.events.forEach(function (event) {
  711. eventOperation(wrapper, event.name, _this, !!event.capture);
  712. });
  713. };
  714. EventRegister.prototype.handleEvent = function (e) {
  715. var eventType = e.type;
  716. this.events.some(function (event) {
  717. if (event.name === eventType) {
  718. event.handler(e);
  719. return true;
  720. }
  721. return false;
  722. });
  723. };
  724. return EventRegister;
  725. }());
  726. var CustomOptions = /** @class */ (function () {
  727. function CustomOptions() {
  728. }
  729. return CustomOptions;
  730. }());
  731. var OptionsConstructor = /** @class */ (function (_super) {
  732. __extends(OptionsConstructor, _super);
  733. function OptionsConstructor() {
  734. var _this = _super.call(this) || this;
  735. _this.startX = 0;
  736. _this.startY = 0;
  737. _this.scrollX = false;
  738. _this.scrollY = true;
  739. _this.freeScroll = false;
  740. _this.directionLockThreshold = 0;
  741. _this.eventPassthrough = "" /* None */;
  742. _this.click = false;
  743. _this.dblclick = false;
  744. _this.tap = '';
  745. _this.bounce = {
  746. top: true,
  747. bottom: true,
  748. left: true,
  749. right: true,
  750. };
  751. _this.bounceTime = 800;
  752. _this.momentum = true;
  753. _this.momentumLimitTime = 300;
  754. _this.momentumLimitDistance = 15;
  755. _this.swipeTime = 2500;
  756. _this.swipeBounceTime = 500;
  757. _this.deceleration = 0.0015;
  758. _this.flickLimitTime = 200;
  759. _this.flickLimitDistance = 100;
  760. _this.resizePolling = 60;
  761. _this.probeType = 0 /* Default */;
  762. _this.stopPropagation = false;
  763. _this.preventDefault = true;
  764. _this.preventDefaultException = {
  765. tagName: /^(INPUT|TEXTAREA|BUTTON|SELECT|AUDIO)$/,
  766. };
  767. _this.tagException = {
  768. tagName: /^TEXTAREA$/,
  769. };
  770. _this.HWCompositing = true;
  771. _this.useTransition = true;
  772. _this.bindToWrapper = false;
  773. _this.bindToTarget = false;
  774. _this.disableMouse = hasTouch;
  775. _this.disableTouch = !hasTouch;
  776. _this.autoBlur = true;
  777. _this.autoEndDistance = 5;
  778. _this.outOfBoundaryDampingFactor = 1 / 3;
  779. _this.specifiedIndexAsContent = 0;
  780. _this.quadrant = 1 /* First */;
  781. return _this;
  782. }
  783. OptionsConstructor.prototype.merge = function (options) {
  784. if (!options)
  785. return this;
  786. for (var key in options) {
  787. if (key === 'bounce') {
  788. this.bounce = this.resolveBounce(options[key]);
  789. continue;
  790. }
  791. this[key] = options[key];
  792. }
  793. return this;
  794. };
  795. OptionsConstructor.prototype.process = function () {
  796. this.translateZ =
  797. this.HWCompositing && hasPerspective ? ' translateZ(1px)' : '';
  798. this.useTransition = this.useTransition && hasTransition;
  799. this.preventDefault = !this.eventPassthrough && this.preventDefault;
  800. // If you want eventPassthrough I have to lock one of the axes
  801. this.scrollX =
  802. this.eventPassthrough === "horizontal" /* Horizontal */
  803. ? false
  804. : this.scrollX;
  805. this.scrollY =
  806. this.eventPassthrough === "vertical" /* Vertical */ ? false : this.scrollY;
  807. // With eventPassthrough we also need lockDirection mechanism
  808. this.freeScroll = this.freeScroll && !this.eventPassthrough;
  809. // force true when freeScroll is true
  810. this.scrollX = this.freeScroll ? true : this.scrollX;
  811. this.scrollY = this.freeScroll ? true : this.scrollY;
  812. this.directionLockThreshold = this.eventPassthrough
  813. ? 0
  814. : this.directionLockThreshold;
  815. return this;
  816. };
  817. OptionsConstructor.prototype.resolveBounce = function (bounceOptions) {
  818. var DEFAULT_BOUNCE = {
  819. top: true,
  820. right: true,
  821. bottom: true,
  822. left: true,
  823. };
  824. var NEGATED_BOUNCE = {
  825. top: false,
  826. right: false,
  827. bottom: false,
  828. left: false,
  829. };
  830. var ret;
  831. if (typeof bounceOptions === 'object') {
  832. ret = extend(DEFAULT_BOUNCE, bounceOptions);
  833. }
  834. else {
  835. ret = bounceOptions ? DEFAULT_BOUNCE : NEGATED_BOUNCE;
  836. }
  837. return ret;
  838. };
  839. return OptionsConstructor;
  840. }(CustomOptions));
  841. var ActionsHandler = /** @class */ (function () {
  842. function ActionsHandler(wrapper, options) {
  843. this.wrapper = wrapper;
  844. this.options = options;
  845. this.hooks = new EventEmitter([
  846. 'beforeStart',
  847. 'start',
  848. 'move',
  849. 'end',
  850. 'click',
  851. ]);
  852. this.handleDOMEvents();
  853. }
  854. ActionsHandler.prototype.handleDOMEvents = function () {
  855. var _a = this.options, bindToWrapper = _a.bindToWrapper, disableMouse = _a.disableMouse, disableTouch = _a.disableTouch, click = _a.click;
  856. var wrapper = this.wrapper;
  857. var target = bindToWrapper ? wrapper : window;
  858. var wrapperEvents = [];
  859. var targetEvents = [];
  860. var shouldRegisterTouch = !disableTouch;
  861. var shouldRegisterMouse = !disableMouse;
  862. if (click) {
  863. wrapperEvents.push({
  864. name: 'click',
  865. handler: this.click.bind(this),
  866. capture: true,
  867. });
  868. }
  869. if (shouldRegisterTouch) {
  870. wrapperEvents.push({
  871. name: 'touchstart',
  872. handler: this.start.bind(this),
  873. });
  874. targetEvents.push({
  875. name: 'touchmove',
  876. handler: this.move.bind(this),
  877. }, {
  878. name: 'touchend',
  879. handler: this.end.bind(this),
  880. }, {
  881. name: 'touchcancel',
  882. handler: this.end.bind(this),
  883. });
  884. }
  885. if (shouldRegisterMouse) {
  886. wrapperEvents.push({
  887. name: 'mousedown',
  888. handler: this.start.bind(this),
  889. });
  890. targetEvents.push({
  891. name: 'mousemove',
  892. handler: this.move.bind(this),
  893. }, {
  894. name: 'mouseup',
  895. handler: this.end.bind(this),
  896. });
  897. }
  898. this.wrapperEventRegister = new EventRegister(wrapper, wrapperEvents);
  899. this.targetEventRegister = new EventRegister(target, targetEvents);
  900. };
  901. ActionsHandler.prototype.beforeHandler = function (e, type) {
  902. var _a = this.options, preventDefault = _a.preventDefault, stopPropagation = _a.stopPropagation, preventDefaultException = _a.preventDefaultException;
  903. var preventDefaultConditions = {
  904. start: function () {
  905. return (preventDefault &&
  906. !preventDefaultExceptionFn(e.target, preventDefaultException));
  907. },
  908. end: function () {
  909. return (preventDefault &&
  910. !preventDefaultExceptionFn(e.target, preventDefaultException));
  911. },
  912. move: function () {
  913. return preventDefault;
  914. },
  915. };
  916. if (preventDefaultConditions[type]()) {
  917. e.preventDefault();
  918. }
  919. if (stopPropagation) {
  920. e.stopPropagation();
  921. }
  922. };
  923. ActionsHandler.prototype.setInitiated = function (type) {
  924. if (type === void 0) { type = 0; }
  925. this.initiated = type;
  926. };
  927. ActionsHandler.prototype.start = function (e) {
  928. var _eventType = eventTypeMap[e.type];
  929. if (this.initiated && this.initiated !== _eventType) {
  930. return;
  931. }
  932. this.setInitiated(_eventType);
  933. // if textarea or other html tags in options.tagException is manipulated
  934. // do not make bs scroll
  935. if (tagExceptionFn(e.target, this.options.tagException)) {
  936. this.setInitiated();
  937. return;
  938. }
  939. // only allow mouse left button
  940. if (_eventType === 2 /* Mouse */ && e.button !== 0 /* Left */)
  941. return;
  942. if (this.hooks.trigger(this.hooks.eventTypes.beforeStart, e)) {
  943. return;
  944. }
  945. this.beforeHandler(e, 'start');
  946. var point = (e.touches ? e.touches[0] : e);
  947. this.pointX = point.pageX;
  948. this.pointY = point.pageY;
  949. this.hooks.trigger(this.hooks.eventTypes.start, e);
  950. };
  951. ActionsHandler.prototype.move = function (e) {
  952. if (eventTypeMap[e.type] !== this.initiated) {
  953. return;
  954. }
  955. this.beforeHandler(e, 'move');
  956. var point = (e.touches ? e.touches[0] : e);
  957. var deltaX = point.pageX - this.pointX;
  958. var deltaY = point.pageY - this.pointY;
  959. this.pointX = point.pageX;
  960. this.pointY = point.pageY;
  961. if (this.hooks.trigger(this.hooks.eventTypes.move, {
  962. deltaX: deltaX,
  963. deltaY: deltaY,
  964. e: e,
  965. })) {
  966. return;
  967. }
  968. // auto end when out of viewport
  969. var scrollLeft = document.documentElement.scrollLeft ||
  970. window.pageXOffset ||
  971. document.body.scrollLeft;
  972. var scrollTop = document.documentElement.scrollTop ||
  973. window.pageYOffset ||
  974. document.body.scrollTop;
  975. var pX = this.pointX - scrollLeft;
  976. var pY = this.pointY - scrollTop;
  977. var autoEndDistance = this.options.autoEndDistance;
  978. if (pX > document.documentElement.clientWidth - autoEndDistance ||
  979. pY > document.documentElement.clientHeight - autoEndDistance ||
  980. pX < autoEndDistance ||
  981. pY < autoEndDistance) {
  982. this.end(e);
  983. }
  984. };
  985. ActionsHandler.prototype.end = function (e) {
  986. if (eventTypeMap[e.type] !== this.initiated) {
  987. return;
  988. }
  989. this.setInitiated();
  990. this.beforeHandler(e, 'end');
  991. this.hooks.trigger(this.hooks.eventTypes.end, e);
  992. };
  993. ActionsHandler.prototype.click = function (e) {
  994. this.hooks.trigger(this.hooks.eventTypes.click, e);
  995. };
  996. ActionsHandler.prototype.setContent = function (content) {
  997. if (content !== this.wrapper) {
  998. this.wrapper = content;
  999. this.rebindDOMEvents();
  1000. }
  1001. };
  1002. ActionsHandler.prototype.rebindDOMEvents = function () {
  1003. this.wrapperEventRegister.destroy();
  1004. this.targetEventRegister.destroy();
  1005. this.handleDOMEvents();
  1006. };
  1007. ActionsHandler.prototype.destroy = function () {
  1008. this.wrapperEventRegister.destroy();
  1009. this.targetEventRegister.destroy();
  1010. this.hooks.destroy();
  1011. };
  1012. return ActionsHandler;
  1013. }());
  1014. var translaterMetaData = {
  1015. x: ['translateX', 'px'],
  1016. y: ['translateY', 'px'],
  1017. };
  1018. var Translater = /** @class */ (function () {
  1019. function Translater(content) {
  1020. this.setContent(content);
  1021. this.hooks = new EventEmitter(['beforeTranslate', 'translate']);
  1022. }
  1023. Translater.prototype.getComputedPosition = function () {
  1024. var cssStyle = window.getComputedStyle(this.content, null);
  1025. var matrix = cssStyle[style.transform].split(')')[0].split(', ');
  1026. var x = +(matrix[12] || matrix[4]) || 0;
  1027. var y = +(matrix[13] || matrix[5]) || 0;
  1028. return {
  1029. x: x,
  1030. y: y,
  1031. };
  1032. };
  1033. Translater.prototype.translate = function (point) {
  1034. var transformStyle = [];
  1035. Object.keys(point).forEach(function (key) {
  1036. if (!translaterMetaData[key]) {
  1037. return;
  1038. }
  1039. var transformFnName = translaterMetaData[key][0];
  1040. if (transformFnName) {
  1041. var transformFnArgUnit = translaterMetaData[key][1];
  1042. var transformFnArg = point[key];
  1043. transformStyle.push(transformFnName + "(" + transformFnArg + transformFnArgUnit + ")");
  1044. }
  1045. });
  1046. this.hooks.trigger(this.hooks.eventTypes.beforeTranslate, transformStyle, point);
  1047. this.style[style.transform] = transformStyle.join(' ');
  1048. this.hooks.trigger(this.hooks.eventTypes.translate, point);
  1049. };
  1050. Translater.prototype.setContent = function (content) {
  1051. if (this.content !== content) {
  1052. this.content = content;
  1053. this.style = content.style;
  1054. }
  1055. };
  1056. Translater.prototype.destroy = function () {
  1057. this.hooks.destroy();
  1058. };
  1059. return Translater;
  1060. }());
  1061. var Base = /** @class */ (function () {
  1062. function Base(content, translater, options) {
  1063. this.translater = translater;
  1064. this.options = options;
  1065. this.timer = 0;
  1066. this.hooks = new EventEmitter([
  1067. 'move',
  1068. 'end',
  1069. 'beforeForceStop',
  1070. 'forceStop',
  1071. 'callStop',
  1072. 'time',
  1073. 'timeFunction',
  1074. ]);
  1075. this.setContent(content);
  1076. }
  1077. Base.prototype.translate = function (endPoint) {
  1078. this.translater.translate(endPoint);
  1079. };
  1080. Base.prototype.setPending = function (pending) {
  1081. this.pending = pending;
  1082. };
  1083. Base.prototype.setForceStopped = function (forceStopped) {
  1084. this.forceStopped = forceStopped;
  1085. };
  1086. Base.prototype.setCallStop = function (called) {
  1087. this.callStopWhenPending = called;
  1088. };
  1089. Base.prototype.setContent = function (content) {
  1090. if (this.content !== content) {
  1091. this.content = content;
  1092. this.style = content.style;
  1093. this.stop();
  1094. }
  1095. };
  1096. Base.prototype.clearTimer = function () {
  1097. if (this.timer) {
  1098. cancelAnimationFrame(this.timer);
  1099. this.timer = 0;
  1100. }
  1101. };
  1102. Base.prototype.destroy = function () {
  1103. this.hooks.destroy();
  1104. cancelAnimationFrame(this.timer);
  1105. };
  1106. return Base;
  1107. }());
  1108. // iOS 13.6 - 14.x, window.getComputedStyle sometimes will get wrong transform value
  1109. // when bs use transition mode
  1110. // eg: translateY -100px -> -200px, when the last frame which is about to scroll to -200px
  1111. // window.getComputedStyle(this.content) will calculate transformY to be -100px(startPoint)
  1112. // it is weird
  1113. // so we should validate position caculated by 'window.getComputedStyle'
  1114. var isValidPostion = function (startPoint, endPoint, currentPos, prePos) {
  1115. var computeDirection = function (endValue, startValue) {
  1116. var delta = endValue - startValue;
  1117. var direction = delta > 0
  1118. ? -1 /* Negative */
  1119. : delta < 0
  1120. ? 1 /* Positive */
  1121. : 0 /* Default */;
  1122. return direction;
  1123. };
  1124. var directionX = computeDirection(endPoint.x, startPoint.x);
  1125. var directionY = computeDirection(endPoint.y, startPoint.y);
  1126. var deltaX = currentPos.x - prePos.x;
  1127. var deltaY = currentPos.y - prePos.y;
  1128. return directionX * deltaX <= 0 && directionY * deltaY <= 0;
  1129. };
  1130. var Transition = /** @class */ (function (_super) {
  1131. __extends(Transition, _super);
  1132. function Transition() {
  1133. return _super !== null && _super.apply(this, arguments) || this;
  1134. }
  1135. Transition.prototype.startProbe = function (startPoint, endPoint) {
  1136. var _this = this;
  1137. var prePos = startPoint;
  1138. var probe = function () {
  1139. var pos = _this.translater.getComputedPosition();
  1140. if (isValidPostion(startPoint, endPoint, pos, prePos)) {
  1141. _this.hooks.trigger(_this.hooks.eventTypes.move, pos);
  1142. }
  1143. // call bs.stop() should not dispatch end hook again.
  1144. // forceStop hook will do this.
  1145. /* istanbul ignore if */
  1146. if (!_this.pending) {
  1147. if (_this.callStopWhenPending) {
  1148. _this.callStopWhenPending = false;
  1149. }
  1150. else {
  1151. // transition ends should dispatch end hook.
  1152. _this.hooks.trigger(_this.hooks.eventTypes.end, pos);
  1153. }
  1154. }
  1155. prePos = pos;
  1156. if (_this.pending) {
  1157. _this.timer = requestAnimationFrame(probe);
  1158. }
  1159. };
  1160. // when manually call bs.stop(), then bs.scrollTo()
  1161. // we should reset callStopWhenPending to dispatch end hook
  1162. if (this.callStopWhenPending) {
  1163. this.setCallStop(false);
  1164. }
  1165. cancelAnimationFrame(this.timer);
  1166. probe();
  1167. };
  1168. Transition.prototype.transitionTime = function (time) {
  1169. if (time === void 0) { time = 0; }
  1170. this.style[style.transitionDuration] = time + 'ms';
  1171. this.hooks.trigger(this.hooks.eventTypes.time, time);
  1172. };
  1173. Transition.prototype.transitionTimingFunction = function (easing) {
  1174. this.style[style.transitionTimingFunction] = easing;
  1175. this.hooks.trigger(this.hooks.eventTypes.timeFunction, easing);
  1176. };
  1177. Transition.prototype.transitionProperty = function () {
  1178. this.style[style.transitionProperty] = style.transform;
  1179. };
  1180. Transition.prototype.move = function (startPoint, endPoint, time, easingFn) {
  1181. this.setPending(time > 0);
  1182. this.transitionTimingFunction(easingFn);
  1183. this.transitionProperty();
  1184. this.transitionTime(time);
  1185. this.translate(endPoint);
  1186. var isRealtimeProbeType = this.options.probeType === 3 /* Realtime */;
  1187. if (time && isRealtimeProbeType) {
  1188. this.startProbe(startPoint, endPoint);
  1189. }
  1190. // if we change content's transformY in a tick
  1191. // such as: 0 -> 50px -> 0
  1192. // transitionend will not be triggered
  1193. // so we forceupdate by reflow
  1194. if (!time) {
  1195. this._reflow = this.content.offsetHeight;
  1196. if (isRealtimeProbeType) {
  1197. this.hooks.trigger(this.hooks.eventTypes.move, endPoint);
  1198. }
  1199. this.hooks.trigger(this.hooks.eventTypes.end, endPoint);
  1200. }
  1201. };
  1202. Transition.prototype.doStop = function () {
  1203. var pending = this.pending;
  1204. this.setForceStopped(false);
  1205. this.setCallStop(false);
  1206. // still in transition
  1207. if (pending) {
  1208. this.setPending(false);
  1209. cancelAnimationFrame(this.timer);
  1210. var _a = this.translater.getComputedPosition(), x = _a.x, y = _a.y;
  1211. this.transitionTime();
  1212. this.translate({ x: x, y: y });
  1213. this.setForceStopped(true);
  1214. this.setCallStop(true);
  1215. this.hooks.trigger(this.hooks.eventTypes.forceStop, { x: x, y: y });
  1216. }
  1217. return pending;
  1218. };
  1219. Transition.prototype.stop = function () {
  1220. var stopFromTransition = this.doStop();
  1221. if (stopFromTransition) {
  1222. this.hooks.trigger(this.hooks.eventTypes.callStop);
  1223. }
  1224. };
  1225. return Transition;
  1226. }(Base));
  1227. var Animation = /** @class */ (function (_super) {
  1228. __extends(Animation, _super);
  1229. function Animation() {
  1230. return _super !== null && _super.apply(this, arguments) || this;
  1231. }
  1232. Animation.prototype.move = function (startPoint, endPoint, time, easingFn) {
  1233. // time is 0
  1234. if (!time) {
  1235. this.translate(endPoint);
  1236. if (this.options.probeType === 3 /* Realtime */) {
  1237. this.hooks.trigger(this.hooks.eventTypes.move, endPoint);
  1238. }
  1239. this.hooks.trigger(this.hooks.eventTypes.end, endPoint);
  1240. return;
  1241. }
  1242. this.animate(startPoint, endPoint, time, easingFn);
  1243. };
  1244. Animation.prototype.animate = function (startPoint, endPoint, duration, easingFn) {
  1245. var _this = this;
  1246. var startTime = getNow();
  1247. var destTime = startTime + duration;
  1248. var isRealtimeProbeType = this.options.probeType === 3 /* Realtime */;
  1249. var step = function () {
  1250. var now = getNow();
  1251. // js animation end
  1252. if (now >= destTime) {
  1253. _this.translate(endPoint);
  1254. if (isRealtimeProbeType) {
  1255. _this.hooks.trigger(_this.hooks.eventTypes.move, endPoint);
  1256. }
  1257. _this.hooks.trigger(_this.hooks.eventTypes.end, endPoint);
  1258. return;
  1259. }
  1260. now = (now - startTime) / duration;
  1261. var easing = easingFn(now);
  1262. var newPoint = {};
  1263. Object.keys(endPoint).forEach(function (key) {
  1264. var startValue = startPoint[key];
  1265. var endValue = endPoint[key];
  1266. newPoint[key] = (endValue - startValue) * easing + startValue;
  1267. });
  1268. _this.translate(newPoint);
  1269. if (isRealtimeProbeType) {
  1270. _this.hooks.trigger(_this.hooks.eventTypes.move, newPoint);
  1271. }
  1272. if (_this.pending) {
  1273. _this.timer = requestAnimationFrame(step);
  1274. }
  1275. // call bs.stop() should not dispatch end hook again.
  1276. // forceStop hook will do this.
  1277. /* istanbul ignore if */
  1278. if (!_this.pending) {
  1279. if (_this.callStopWhenPending) {
  1280. _this.callStopWhenPending = false;
  1281. }
  1282. else {
  1283. // raf ends should dispatch end hook.
  1284. _this.hooks.trigger(_this.hooks.eventTypes.end, endPoint);
  1285. }
  1286. }
  1287. };
  1288. this.setPending(true);
  1289. // when manually call bs.stop(), then bs.scrollTo()
  1290. // we should reset callStopWhenPending to dispatch end hook
  1291. if (this.callStopWhenPending) {
  1292. this.setCallStop(false);
  1293. }
  1294. cancelAnimationFrame(this.timer);
  1295. step();
  1296. };
  1297. Animation.prototype.doStop = function () {
  1298. var pending = this.pending;
  1299. this.setForceStopped(false);
  1300. this.setCallStop(false);
  1301. // still in requestFrameAnimation
  1302. if (pending) {
  1303. this.setPending(false);
  1304. cancelAnimationFrame(this.timer);
  1305. var pos = this.translater.getComputedPosition();
  1306. this.setForceStopped(true);
  1307. this.setCallStop(true);
  1308. this.hooks.trigger(this.hooks.eventTypes.forceStop, pos);
  1309. }
  1310. return pending;
  1311. };
  1312. Animation.prototype.stop = function () {
  1313. var stopFromAnimation = this.doStop();
  1314. if (stopFromAnimation) {
  1315. this.hooks.trigger(this.hooks.eventTypes.callStop);
  1316. }
  1317. };
  1318. return Animation;
  1319. }(Base));
  1320. function createAnimater(element, translater, options) {
  1321. var useTransition = options.useTransition;
  1322. var animaterOptions = {};
  1323. Object.defineProperty(animaterOptions, 'probeType', {
  1324. enumerable: true,
  1325. configurable: false,
  1326. get: function () {
  1327. return options.probeType;
  1328. },
  1329. });
  1330. if (useTransition) {
  1331. return new Transition(element, translater, animaterOptions);
  1332. }
  1333. else {
  1334. return new Animation(element, translater, animaterOptions);
  1335. }
  1336. }
  1337. var Behavior = /** @class */ (function () {
  1338. function Behavior(wrapper, content, options) {
  1339. this.wrapper = wrapper;
  1340. this.options = options;
  1341. this.hooks = new EventEmitter([
  1342. 'beforeComputeBoundary',
  1343. 'computeBoundary',
  1344. 'momentum',
  1345. 'end',
  1346. 'ignoreHasScroll'
  1347. ]);
  1348. this.refresh(content);
  1349. }
  1350. Behavior.prototype.start = function () {
  1351. this.dist = 0;
  1352. this.setMovingDirection(0 /* Default */);
  1353. this.setDirection(0 /* Default */);
  1354. };
  1355. Behavior.prototype.move = function (delta) {
  1356. delta = this.hasScroll ? delta : 0;
  1357. this.setMovingDirection(delta);
  1358. return this.performDampingAlgorithm(delta, this.options.outOfBoundaryDampingFactor);
  1359. };
  1360. Behavior.prototype.setMovingDirection = function (delta) {
  1361. this.movingDirection =
  1362. delta > 0
  1363. ? -1 /* Negative */
  1364. : delta < 0
  1365. ? 1 /* Positive */
  1366. : 0 /* Default */;
  1367. };
  1368. Behavior.prototype.setDirection = function (delta) {
  1369. this.direction =
  1370. delta > 0
  1371. ? -1 /* Negative */
  1372. : delta < 0
  1373. ? 1 /* Positive */
  1374. : 0 /* Default */;
  1375. };
  1376. Behavior.prototype.performDampingAlgorithm = function (delta, dampingFactor) {
  1377. var newPos = this.currentPos + delta;
  1378. // Slow down or stop if outside of the boundaries
  1379. if (newPos > this.minScrollPos || newPos < this.maxScrollPos) {
  1380. if ((newPos > this.minScrollPos && this.options.bounces[0]) ||
  1381. (newPos < this.maxScrollPos && this.options.bounces[1])) {
  1382. newPos = this.currentPos + delta * dampingFactor;
  1383. }
  1384. else {
  1385. newPos =
  1386. newPos > this.minScrollPos ? this.minScrollPos : this.maxScrollPos;
  1387. }
  1388. }
  1389. return newPos;
  1390. };
  1391. Behavior.prototype.end = function (duration) {
  1392. var momentumInfo = {
  1393. duration: 0
  1394. };
  1395. var absDist = Math.abs(this.currentPos - this.startPos);
  1396. // start momentum animation if needed
  1397. if (this.options.momentum &&
  1398. duration < this.options.momentumLimitTime &&
  1399. absDist > this.options.momentumLimitDistance) {
  1400. var wrapperSize = (this.direction === -1 /* Negative */ && this.options.bounces[0]) ||
  1401. (this.direction === 1 /* Positive */ && this.options.bounces[1])
  1402. ? this.wrapperSize
  1403. : 0;
  1404. momentumInfo = this.hasScroll
  1405. ? this.momentum(this.currentPos, this.startPos, duration, this.maxScrollPos, this.minScrollPos, wrapperSize, this.options)
  1406. : { destination: this.currentPos, duration: 0 };
  1407. }
  1408. else {
  1409. this.hooks.trigger(this.hooks.eventTypes.end, momentumInfo);
  1410. }
  1411. return momentumInfo;
  1412. };
  1413. Behavior.prototype.momentum = function (current, start, time, lowerMargin, upperMargin, wrapperSize, options) {
  1414. if (options === void 0) { options = this.options; }
  1415. var distance = current - start;
  1416. var speed = Math.abs(distance) / time;
  1417. var deceleration = options.deceleration, swipeBounceTime = options.swipeBounceTime, swipeTime = options.swipeTime;
  1418. var duration = Math.min(swipeTime, (speed * 2) / deceleration);
  1419. var momentumData = {
  1420. destination: current + ((speed * speed) / deceleration) * (distance < 0 ? -1 : 1),
  1421. duration: duration,
  1422. rate: 15
  1423. };
  1424. this.hooks.trigger(this.hooks.eventTypes.momentum, momentumData, distance);
  1425. if (momentumData.destination < lowerMargin) {
  1426. momentumData.destination = wrapperSize
  1427. ? Math.max(lowerMargin - wrapperSize / 4, lowerMargin - (wrapperSize / momentumData.rate) * speed)
  1428. : lowerMargin;
  1429. momentumData.duration = swipeBounceTime;
  1430. }
  1431. else if (momentumData.destination > upperMargin) {
  1432. momentumData.destination = wrapperSize
  1433. ? Math.min(upperMargin + wrapperSize / 4, upperMargin + (wrapperSize / momentumData.rate) * speed)
  1434. : upperMargin;
  1435. momentumData.duration = swipeBounceTime;
  1436. }
  1437. momentumData.destination = Math.round(momentumData.destination);
  1438. return momentumData;
  1439. };
  1440. Behavior.prototype.updateDirection = function () {
  1441. var absDist = this.currentPos - this.absStartPos;
  1442. this.setDirection(absDist);
  1443. };
  1444. Behavior.prototype.refresh = function (content) {
  1445. var _a = this.options.rect, size = _a.size, position = _a.position;
  1446. var isWrapperStatic = window.getComputedStyle(this.wrapper, null).position === 'static';
  1447. // Force reflow
  1448. var wrapperRect = getRect(this.wrapper);
  1449. // use client is more fair than offset
  1450. this.wrapperSize = this.wrapper[size === 'width' ? 'clientWidth' : 'clientHeight'];
  1451. this.setContent(content);
  1452. var contentRect = getRect(this.content);
  1453. this.contentSize = contentRect[size];
  1454. this.relativeOffset = contentRect[position];
  1455. /* istanbul ignore if */
  1456. if (isWrapperStatic) {
  1457. this.relativeOffset -= wrapperRect[position];
  1458. }
  1459. this.computeBoundary();
  1460. this.setDirection(0 /* Default */);
  1461. };
  1462. Behavior.prototype.setContent = function (content) {
  1463. if (content !== this.content) {
  1464. this.content = content;
  1465. this.resetState();
  1466. }
  1467. };
  1468. Behavior.prototype.resetState = function () {
  1469. this.currentPos = 0;
  1470. this.startPos = 0;
  1471. this.dist = 0;
  1472. this.setDirection(0 /* Default */);
  1473. this.setMovingDirection(0 /* Default */);
  1474. this.resetStartPos();
  1475. };
  1476. Behavior.prototype.computeBoundary = function () {
  1477. this.hooks.trigger(this.hooks.eventTypes.beforeComputeBoundary);
  1478. var boundary = {
  1479. minScrollPos: 0,
  1480. maxScrollPos: this.wrapperSize - this.contentSize
  1481. };
  1482. if (boundary.maxScrollPos < 0) {
  1483. boundary.maxScrollPos -= this.relativeOffset;
  1484. if (this.options.specifiedIndexAsContent === 0) {
  1485. boundary.minScrollPos = -this.relativeOffset;
  1486. }
  1487. }
  1488. this.hooks.trigger(this.hooks.eventTypes.computeBoundary, boundary);
  1489. this.minScrollPos = boundary.minScrollPos;
  1490. this.maxScrollPos = boundary.maxScrollPos;
  1491. this.hasScroll =
  1492. this.options.scrollable && this.maxScrollPos < this.minScrollPos;
  1493. if (!this.hasScroll && this.minScrollPos < this.maxScrollPos) {
  1494. this.maxScrollPos = this.minScrollPos;
  1495. this.contentSize = this.wrapperSize;
  1496. }
  1497. };
  1498. Behavior.prototype.updatePosition = function (pos) {
  1499. this.currentPos = pos;
  1500. };
  1501. Behavior.prototype.getCurrentPos = function () {
  1502. return this.currentPos;
  1503. };
  1504. Behavior.prototype.checkInBoundary = function () {
  1505. var position = this.adjustPosition(this.currentPos);
  1506. var inBoundary = position === this.getCurrentPos();
  1507. return {
  1508. position: position,
  1509. inBoundary: inBoundary
  1510. };
  1511. };
  1512. // adjust position when out of boundary
  1513. Behavior.prototype.adjustPosition = function (pos) {
  1514. if (!this.hasScroll &&
  1515. !this.hooks.trigger(this.hooks.eventTypes.ignoreHasScroll)) {
  1516. pos = this.minScrollPos;
  1517. }
  1518. else if (pos > this.minScrollPos) {
  1519. pos = this.minScrollPos;
  1520. }
  1521. else if (pos < this.maxScrollPos) {
  1522. pos = this.maxScrollPos;
  1523. }
  1524. return pos;
  1525. };
  1526. Behavior.prototype.updateStartPos = function () {
  1527. this.startPos = this.currentPos;
  1528. };
  1529. Behavior.prototype.updateAbsStartPos = function () {
  1530. this.absStartPos = this.currentPos;
  1531. };
  1532. Behavior.prototype.resetStartPos = function () {
  1533. this.updateStartPos();
  1534. this.updateAbsStartPos();
  1535. };
  1536. Behavior.prototype.getAbsDist = function (delta) {
  1537. this.dist += delta;
  1538. return Math.abs(this.dist);
  1539. };
  1540. Behavior.prototype.destroy = function () {
  1541. this.hooks.destroy();
  1542. };
  1543. return Behavior;
  1544. }());
  1545. var _a, _b, _c, _d;
  1546. var PassthroughHandlers = (_a = {},
  1547. _a["yes" /* Yes */] = function (e) {
  1548. return true;
  1549. },
  1550. _a["no" /* No */] = function (e) {
  1551. e.preventDefault();
  1552. return false;
  1553. },
  1554. _a);
  1555. var DirectionMap = (_b = {},
  1556. _b["horizontal" /* Horizontal */] = (_c = {},
  1557. _c["yes" /* Yes */] = "horizontal" /* Horizontal */,
  1558. _c["no" /* No */] = "vertical" /* Vertical */,
  1559. _c),
  1560. _b["vertical" /* Vertical */] = (_d = {},
  1561. _d["yes" /* Yes */] = "vertical" /* Vertical */,
  1562. _d["no" /* No */] = "horizontal" /* Horizontal */,
  1563. _d),
  1564. _b);
  1565. var DirectionLockAction = /** @class */ (function () {
  1566. function DirectionLockAction(directionLockThreshold, freeScroll, eventPassthrough) {
  1567. this.directionLockThreshold = directionLockThreshold;
  1568. this.freeScroll = freeScroll;
  1569. this.eventPassthrough = eventPassthrough;
  1570. this.reset();
  1571. }
  1572. DirectionLockAction.prototype.reset = function () {
  1573. this.directionLocked = "" /* Default */;
  1574. };
  1575. DirectionLockAction.prototype.checkMovingDirection = function (absDistX, absDistY, e) {
  1576. this.computeDirectionLock(absDistX, absDistY);
  1577. return this.handleEventPassthrough(e);
  1578. };
  1579. DirectionLockAction.prototype.adjustDelta = function (deltaX, deltaY) {
  1580. if (this.directionLocked === "horizontal" /* Horizontal */) {
  1581. deltaY = 0;
  1582. }
  1583. else if (this.directionLocked === "vertical" /* Vertical */) {
  1584. deltaX = 0;
  1585. }
  1586. return {
  1587. deltaX: deltaX,
  1588. deltaY: deltaY
  1589. };
  1590. };
  1591. DirectionLockAction.prototype.computeDirectionLock = function (absDistX, absDistY) {
  1592. // If you are scrolling in one direction, lock it
  1593. if (this.directionLocked === "" /* Default */ && !this.freeScroll) {
  1594. if (absDistX > absDistY + this.directionLockThreshold) {
  1595. this.directionLocked = "horizontal" /* Horizontal */; // lock horizontally
  1596. }
  1597. else if (absDistY >= absDistX + this.directionLockThreshold) {
  1598. this.directionLocked = "vertical" /* Vertical */; // lock vertically
  1599. }
  1600. else {
  1601. this.directionLocked = "none" /* None */; // no lock
  1602. }
  1603. }
  1604. };
  1605. DirectionLockAction.prototype.handleEventPassthrough = function (e) {
  1606. var handleMap = DirectionMap[this.directionLocked];
  1607. if (handleMap) {
  1608. if (this.eventPassthrough === handleMap["yes" /* Yes */]) {
  1609. return PassthroughHandlers["yes" /* Yes */](e);
  1610. }
  1611. else if (this.eventPassthrough === handleMap["no" /* No */]) {
  1612. return PassthroughHandlers["no" /* No */](e);
  1613. }
  1614. }
  1615. return false;
  1616. };
  1617. return DirectionLockAction;
  1618. }());
  1619. var applyQuadrantTransformation = function (deltaX, deltaY, quadrant) {
  1620. if (quadrant === 2 /* Second */) {
  1621. return [deltaY, -deltaX];
  1622. }
  1623. else if (quadrant === 3 /* Third */) {
  1624. return [-deltaX, -deltaY];
  1625. }
  1626. else if (quadrant === 4 /* Forth */) {
  1627. return [-deltaY, deltaX];
  1628. }
  1629. else {
  1630. return [deltaX, deltaY];
  1631. }
  1632. };
  1633. var ScrollerActions = /** @class */ (function () {
  1634. function ScrollerActions(scrollBehaviorX, scrollBehaviorY, actionsHandler, animater, options) {
  1635. this.hooks = new EventEmitter([
  1636. 'start',
  1637. 'beforeMove',
  1638. 'scrollStart',
  1639. 'scroll',
  1640. 'beforeEnd',
  1641. 'end',
  1642. 'scrollEnd',
  1643. 'contentNotMoved',
  1644. 'detectMovingDirection',
  1645. 'coordinateTransformation',
  1646. ]);
  1647. this.scrollBehaviorX = scrollBehaviorX;
  1648. this.scrollBehaviorY = scrollBehaviorY;
  1649. this.actionsHandler = actionsHandler;
  1650. this.animater = animater;
  1651. this.options = options;
  1652. this.directionLockAction = new DirectionLockAction(options.directionLockThreshold, options.freeScroll, options.eventPassthrough);
  1653. this.enabled = true;
  1654. this.bindActionsHandler();
  1655. }
  1656. ScrollerActions.prototype.bindActionsHandler = function () {
  1657. var _this = this;
  1658. // [mouse|touch]start event
  1659. this.actionsHandler.hooks.on(this.actionsHandler.hooks.eventTypes.start, function (e) {
  1660. if (!_this.enabled)
  1661. return true;
  1662. return _this.handleStart(e);
  1663. });
  1664. // [mouse|touch]move event
  1665. this.actionsHandler.hooks.on(this.actionsHandler.hooks.eventTypes.move, function (_a) {
  1666. var deltaX = _a.deltaX, deltaY = _a.deltaY, e = _a.e;
  1667. if (!_this.enabled)
  1668. return true;
  1669. var _b = applyQuadrantTransformation(deltaX, deltaY, _this.options.quadrant), transformateDeltaX = _b[0], transformateDeltaY = _b[1];
  1670. var transformateDeltaData = {
  1671. deltaX: transformateDeltaX,
  1672. deltaY: transformateDeltaY,
  1673. };
  1674. _this.hooks.trigger(_this.hooks.eventTypes.coordinateTransformation, transformateDeltaData);
  1675. return _this.handleMove(transformateDeltaData.deltaX, transformateDeltaData.deltaY, e);
  1676. });
  1677. // [mouse|touch]end event
  1678. this.actionsHandler.hooks.on(this.actionsHandler.hooks.eventTypes.end, function (e) {
  1679. if (!_this.enabled)
  1680. return true;
  1681. return _this.handleEnd(e);
  1682. });
  1683. // click
  1684. this.actionsHandler.hooks.on(this.actionsHandler.hooks.eventTypes.click, function (e) {
  1685. // handle native click event
  1686. if (_this.enabled && !e._constructed) {
  1687. _this.handleClick(e);
  1688. }
  1689. });
  1690. };
  1691. ScrollerActions.prototype.handleStart = function (e) {
  1692. var timestamp = getNow();
  1693. this.fingerMoved = false;
  1694. this.contentMoved = false;
  1695. this.startTime = timestamp;
  1696. this.directionLockAction.reset();
  1697. this.scrollBehaviorX.start();
  1698. this.scrollBehaviorY.start();
  1699. // force stopping last transition or animation
  1700. this.animater.doStop();
  1701. this.scrollBehaviorX.resetStartPos();
  1702. this.scrollBehaviorY.resetStartPos();
  1703. this.hooks.trigger(this.hooks.eventTypes.start, e);
  1704. };
  1705. ScrollerActions.prototype.handleMove = function (deltaX, deltaY, e) {
  1706. if (this.hooks.trigger(this.hooks.eventTypes.beforeMove, e)) {
  1707. return;
  1708. }
  1709. var absDistX = this.scrollBehaviorX.getAbsDist(deltaX);
  1710. var absDistY = this.scrollBehaviorY.getAbsDist(deltaY);
  1711. var timestamp = getNow();
  1712. // We need to move at least momentumLimitDistance pixels
  1713. // for the scrolling to initiate
  1714. if (this.checkMomentum(absDistX, absDistY, timestamp)) {
  1715. return true;
  1716. }
  1717. if (this.directionLockAction.checkMovingDirection(absDistX, absDistY, e)) {
  1718. this.actionsHandler.setInitiated();
  1719. return true;
  1720. }
  1721. var delta = this.directionLockAction.adjustDelta(deltaX, deltaY);
  1722. var prevX = this.scrollBehaviorX.getCurrentPos();
  1723. var newX = this.scrollBehaviorX.move(delta.deltaX);
  1724. var prevY = this.scrollBehaviorY.getCurrentPos();
  1725. var newY = this.scrollBehaviorY.move(delta.deltaY);
  1726. if (this.hooks.trigger(this.hooks.eventTypes.detectMovingDirection)) {
  1727. return;
  1728. }
  1729. if (!this.fingerMoved) {
  1730. this.fingerMoved = true;
  1731. }
  1732. var positionChanged = newX !== prevX || newY !== prevY;
  1733. if (!this.contentMoved && !positionChanged) {
  1734. this.hooks.trigger(this.hooks.eventTypes.contentNotMoved);
  1735. }
  1736. if (!this.contentMoved && positionChanged) {
  1737. this.contentMoved = true;
  1738. this.hooks.trigger(this.hooks.eventTypes.scrollStart);
  1739. }
  1740. if (this.contentMoved && positionChanged) {
  1741. this.animater.translate({
  1742. x: newX,
  1743. y: newY,
  1744. });
  1745. this.dispatchScroll(timestamp);
  1746. }
  1747. };
  1748. ScrollerActions.prototype.dispatchScroll = function (timestamp) {
  1749. // dispatch scroll in interval time
  1750. if (timestamp - this.startTime > this.options.momentumLimitTime) {
  1751. // refresh time and starting position to initiate a momentum
  1752. this.startTime = timestamp;
  1753. this.scrollBehaviorX.updateStartPos();
  1754. this.scrollBehaviorY.updateStartPos();
  1755. if (this.options.probeType === 1 /* Throttle */) {
  1756. this.hooks.trigger(this.hooks.eventTypes.scroll, this.getCurrentPos());
  1757. }
  1758. }
  1759. // dispatch scroll all the time
  1760. if (this.options.probeType > 1 /* Throttle */) {
  1761. this.hooks.trigger(this.hooks.eventTypes.scroll, this.getCurrentPos());
  1762. }
  1763. };
  1764. ScrollerActions.prototype.checkMomentum = function (absDistX, absDistY, timestamp) {
  1765. return (timestamp - this.endTime > this.options.momentumLimitTime &&
  1766. absDistY < this.options.momentumLimitDistance &&
  1767. absDistX < this.options.momentumLimitDistance);
  1768. };
  1769. ScrollerActions.prototype.handleEnd = function (e) {
  1770. if (this.hooks.trigger(this.hooks.eventTypes.beforeEnd, e)) {
  1771. return;
  1772. }
  1773. var currentPos = this.getCurrentPos();
  1774. this.scrollBehaviorX.updateDirection();
  1775. this.scrollBehaviorY.updateDirection();
  1776. if (this.hooks.trigger(this.hooks.eventTypes.end, e, currentPos)) {
  1777. return true;
  1778. }
  1779. currentPos = this.ensureIntegerPos(currentPos);
  1780. this.animater.translate(currentPos);
  1781. this.endTime = getNow();
  1782. var duration = this.endTime - this.startTime;
  1783. this.hooks.trigger(this.hooks.eventTypes.scrollEnd, currentPos, duration);
  1784. };
  1785. ScrollerActions.prototype.ensureIntegerPos = function (currentPos) {
  1786. this.ensuringInteger = true;
  1787. var x = currentPos.x, y = currentPos.y;
  1788. var _a = this.scrollBehaviorX, minScrollPosX = _a.minScrollPos, maxScrollPosX = _a.maxScrollPos;
  1789. var _b = this.scrollBehaviorY, minScrollPosY = _b.minScrollPos, maxScrollPosY = _b.maxScrollPos;
  1790. x = x > 0 ? Math.ceil(x) : Math.floor(x);
  1791. y = y > 0 ? Math.ceil(y) : Math.floor(y);
  1792. x = between(x, maxScrollPosX, minScrollPosX);
  1793. y = between(y, maxScrollPosY, minScrollPosY);
  1794. return { x: x, y: y };
  1795. };
  1796. ScrollerActions.prototype.handleClick = function (e) {
  1797. if (!preventDefaultExceptionFn(e.target, this.options.preventDefaultException)) {
  1798. e.preventDefault();
  1799. e.stopPropagation();
  1800. }
  1801. };
  1802. ScrollerActions.prototype.getCurrentPos = function () {
  1803. return {
  1804. x: this.scrollBehaviorX.getCurrentPos(),
  1805. y: this.scrollBehaviorY.getCurrentPos(),
  1806. };
  1807. };
  1808. ScrollerActions.prototype.refresh = function () {
  1809. this.endTime = 0;
  1810. };
  1811. ScrollerActions.prototype.destroy = function () {
  1812. this.hooks.destroy();
  1813. };
  1814. return ScrollerActions;
  1815. }());
  1816. function createActionsHandlerOptions(bsOptions) {
  1817. var options = [
  1818. 'click',
  1819. 'bindToWrapper',
  1820. 'disableMouse',
  1821. 'disableTouch',
  1822. 'preventDefault',
  1823. 'stopPropagation',
  1824. 'tagException',
  1825. 'preventDefaultException',
  1826. 'autoEndDistance',
  1827. ].reduce(function (prev, cur) {
  1828. prev[cur] = bsOptions[cur];
  1829. return prev;
  1830. }, {});
  1831. return options;
  1832. }
  1833. function createBehaviorOptions(bsOptions, extraProp, bounces, rect) {
  1834. var options = [
  1835. 'momentum',
  1836. 'momentumLimitTime',
  1837. 'momentumLimitDistance',
  1838. 'deceleration',
  1839. 'swipeBounceTime',
  1840. 'swipeTime',
  1841. 'outOfBoundaryDampingFactor',
  1842. 'specifiedIndexAsContent',
  1843. ].reduce(function (prev, cur) {
  1844. prev[cur] = bsOptions[cur];
  1845. return prev;
  1846. }, {});
  1847. // add extra property
  1848. options.scrollable = !!bsOptions[extraProp];
  1849. options.bounces = bounces;
  1850. options.rect = rect;
  1851. return options;
  1852. }
  1853. function bubbling(source, target, events) {
  1854. events.forEach(function (event) {
  1855. var sourceEvent;
  1856. var targetEvent;
  1857. if (typeof event === 'string') {
  1858. sourceEvent = targetEvent = event;
  1859. }
  1860. else {
  1861. sourceEvent = event.source;
  1862. targetEvent = event.target;
  1863. }
  1864. source.on(sourceEvent, function () {
  1865. var args = [];
  1866. for (var _i = 0; _i < arguments.length; _i++) {
  1867. args[_i] = arguments[_i];
  1868. }
  1869. return target.trigger.apply(target, __spreadArrays([targetEvent], args));
  1870. });
  1871. });
  1872. }
  1873. function isSamePoint(startPoint, endPoint) {
  1874. // keys of startPoint and endPoint should be equal
  1875. var keys = Object.keys(startPoint);
  1876. for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) {
  1877. var key = keys_1[_i];
  1878. if (startPoint[key] !== endPoint[key])
  1879. return false;
  1880. }
  1881. return true;
  1882. }
  1883. var MIN_SCROLL_DISTANCE = 1;
  1884. var Scroller = /** @class */ (function () {
  1885. function Scroller(wrapper, content, options) {
  1886. this.wrapper = wrapper;
  1887. this.content = content;
  1888. this.resizeTimeout = 0;
  1889. this.hooks = new EventEmitter([
  1890. 'beforeStart',
  1891. 'beforeMove',
  1892. 'beforeScrollStart',
  1893. 'scrollStart',
  1894. 'scroll',
  1895. 'beforeEnd',
  1896. 'scrollEnd',
  1897. 'resize',
  1898. 'touchEnd',
  1899. 'end',
  1900. 'flick',
  1901. 'scrollCancel',
  1902. 'momentum',
  1903. 'scrollTo',
  1904. 'minDistanceScroll',
  1905. 'scrollToElement',
  1906. 'beforeRefresh',
  1907. ]);
  1908. this.options = options;
  1909. var _a = this.options.bounce, left = _a.left, right = _a.right, top = _a.top, bottom = _a.bottom;
  1910. // direction X
  1911. this.scrollBehaviorX = new Behavior(wrapper, content, createBehaviorOptions(options, 'scrollX', [left, right], {
  1912. size: 'width',
  1913. position: 'left',
  1914. }));
  1915. // direction Y
  1916. this.scrollBehaviorY = new Behavior(wrapper, content, createBehaviorOptions(options, 'scrollY', [top, bottom], {
  1917. size: 'height',
  1918. position: 'top',
  1919. }));
  1920. this.translater = new Translater(this.content);
  1921. this.animater = createAnimater(this.content, this.translater, this.options);
  1922. this.actionsHandler = new ActionsHandler(this.options.bindToTarget ? this.content : wrapper, createActionsHandlerOptions(this.options));
  1923. this.actions = new ScrollerActions(this.scrollBehaviorX, this.scrollBehaviorY, this.actionsHandler, this.animater, this.options);
  1924. var resizeHandler = this.resize.bind(this);
  1925. this.resizeRegister = new EventRegister(window, [
  1926. {
  1927. name: 'orientationchange',
  1928. handler: resizeHandler,
  1929. },
  1930. {
  1931. name: 'resize',
  1932. handler: resizeHandler,
  1933. },
  1934. ]);
  1935. this.registerTransitionEnd();
  1936. this.init();
  1937. }
  1938. Scroller.prototype.init = function () {
  1939. var _this = this;
  1940. this.bindTranslater();
  1941. this.bindAnimater();
  1942. this.bindActions();
  1943. // enable pointer events when scrolling ends
  1944. this.hooks.on(this.hooks.eventTypes.scrollEnd, function () {
  1945. _this.togglePointerEvents(true);
  1946. });
  1947. };
  1948. Scroller.prototype.registerTransitionEnd = function () {
  1949. this.transitionEndRegister = new EventRegister(this.content, [
  1950. {
  1951. name: style.transitionEnd,
  1952. handler: this.transitionEnd.bind(this),
  1953. },
  1954. ]);
  1955. };
  1956. Scroller.prototype.bindTranslater = function () {
  1957. var _this = this;
  1958. var hooks = this.translater.hooks;
  1959. hooks.on(hooks.eventTypes.beforeTranslate, function (transformStyle) {
  1960. if (_this.options.translateZ) {
  1961. transformStyle.push(_this.options.translateZ);
  1962. }
  1963. });
  1964. // disable pointer events when scrolling
  1965. hooks.on(hooks.eventTypes.translate, function (pos) {
  1966. var prevPos = _this.getCurrentPos();
  1967. _this.updatePositions(pos);
  1968. // scrollEnd will dispatch when scroll is force stopping in touchstart handler
  1969. // so in touchend handler, don't toggle pointer-events
  1970. if (_this.actions.ensuringInteger === true) {
  1971. _this.actions.ensuringInteger = false;
  1972. return;
  1973. }
  1974. // a valid translate
  1975. if (pos.x !== prevPos.x || pos.y !== prevPos.y) {
  1976. _this.togglePointerEvents(false);
  1977. }
  1978. });
  1979. };
  1980. Scroller.prototype.bindAnimater = function () {
  1981. var _this = this;
  1982. // reset position
  1983. this.animater.hooks.on(this.animater.hooks.eventTypes.end, function (pos) {
  1984. if (!_this.resetPosition(_this.options.bounceTime)) {
  1985. _this.animater.setPending(false);
  1986. _this.hooks.trigger(_this.hooks.eventTypes.scrollEnd, pos);
  1987. }
  1988. });
  1989. bubbling(this.animater.hooks, this.hooks, [
  1990. {
  1991. source: this.animater.hooks.eventTypes.move,
  1992. target: this.hooks.eventTypes.scroll,
  1993. },
  1994. {
  1995. source: this.animater.hooks.eventTypes.forceStop,
  1996. target: this.hooks.eventTypes.scrollEnd,
  1997. },
  1998. ]);
  1999. };
  2000. Scroller.prototype.bindActions = function () {
  2001. var _this = this;
  2002. var actions = this.actions;
  2003. bubbling(actions.hooks, this.hooks, [
  2004. {
  2005. source: actions.hooks.eventTypes.start,
  2006. target: this.hooks.eventTypes.beforeStart,
  2007. },
  2008. {
  2009. source: actions.hooks.eventTypes.start,
  2010. target: this.hooks.eventTypes.beforeScrollStart,
  2011. },
  2012. {
  2013. source: actions.hooks.eventTypes.beforeMove,
  2014. target: this.hooks.eventTypes.beforeMove,
  2015. },
  2016. {
  2017. source: actions.hooks.eventTypes.scrollStart,
  2018. target: this.hooks.eventTypes.scrollStart,
  2019. },
  2020. {
  2021. source: actions.hooks.eventTypes.scroll,
  2022. target: this.hooks.eventTypes.scroll,
  2023. },
  2024. {
  2025. source: actions.hooks.eventTypes.beforeEnd,
  2026. target: this.hooks.eventTypes.beforeEnd,
  2027. },
  2028. ]);
  2029. actions.hooks.on(actions.hooks.eventTypes.end, function (e, pos) {
  2030. _this.hooks.trigger(_this.hooks.eventTypes.touchEnd, pos);
  2031. if (_this.hooks.trigger(_this.hooks.eventTypes.end, pos)) {
  2032. return true;
  2033. }
  2034. // check if it is a click operation
  2035. if (!actions.fingerMoved) {
  2036. _this.hooks.trigger(_this.hooks.eventTypes.scrollCancel);
  2037. if (_this.checkClick(e)) {
  2038. return true;
  2039. }
  2040. }
  2041. // reset if we are outside of the boundaries
  2042. if (_this.resetPosition(_this.options.bounceTime, ease.bounce)) {
  2043. _this.animater.setForceStopped(false);
  2044. return true;
  2045. }
  2046. });
  2047. actions.hooks.on(actions.hooks.eventTypes.scrollEnd, function (pos, duration) {
  2048. var deltaX = Math.abs(pos.x - _this.scrollBehaviorX.startPos);
  2049. var deltaY = Math.abs(pos.y - _this.scrollBehaviorY.startPos);
  2050. if (_this.checkFlick(duration, deltaX, deltaY)) {
  2051. _this.animater.setForceStopped(false);
  2052. _this.hooks.trigger(_this.hooks.eventTypes.flick);
  2053. return;
  2054. }
  2055. if (_this.momentum(pos, duration)) {
  2056. _this.animater.setForceStopped(false);
  2057. return;
  2058. }
  2059. if (actions.contentMoved) {
  2060. _this.hooks.trigger(_this.hooks.eventTypes.scrollEnd, pos);
  2061. }
  2062. if (_this.animater.forceStopped) {
  2063. _this.animater.setForceStopped(false);
  2064. }
  2065. });
  2066. };
  2067. Scroller.prototype.checkFlick = function (duration, deltaX, deltaY) {
  2068. var flickMinMovingDistance = 1; // distinguish flick from click
  2069. if (this.hooks.events.flick.length > 1 &&
  2070. duration < this.options.flickLimitTime &&
  2071. deltaX < this.options.flickLimitDistance &&
  2072. deltaY < this.options.flickLimitDistance &&
  2073. (deltaY > flickMinMovingDistance || deltaX > flickMinMovingDistance)) {
  2074. return true;
  2075. }
  2076. };
  2077. Scroller.prototype.momentum = function (pos, duration) {
  2078. var meta = {
  2079. time: 0,
  2080. easing: ease.swiper,
  2081. newX: pos.x,
  2082. newY: pos.y,
  2083. };
  2084. // start momentum animation if needed
  2085. var momentumX = this.scrollBehaviorX.end(duration);
  2086. var momentumY = this.scrollBehaviorY.end(duration);
  2087. meta.newX = isUndef(momentumX.destination)
  2088. ? meta.newX
  2089. : momentumX.destination;
  2090. meta.newY = isUndef(momentumY.destination)
  2091. ? meta.newY
  2092. : momentumY.destination;
  2093. meta.time = Math.max(momentumX.duration, momentumY.duration);
  2094. this.hooks.trigger(this.hooks.eventTypes.momentum, meta, this);
  2095. // when x or y changed, do momentum animation now!
  2096. if (meta.newX !== pos.x || meta.newY !== pos.y) {
  2097. // change easing function when scroller goes out of the boundaries
  2098. if (meta.newX > this.scrollBehaviorX.minScrollPos ||
  2099. meta.newX < this.scrollBehaviorX.maxScrollPos ||
  2100. meta.newY > this.scrollBehaviorY.minScrollPos ||
  2101. meta.newY < this.scrollBehaviorY.maxScrollPos) {
  2102. meta.easing = ease.swipeBounce;
  2103. }
  2104. this.scrollTo(meta.newX, meta.newY, meta.time, meta.easing);
  2105. return true;
  2106. }
  2107. };
  2108. Scroller.prototype.checkClick = function (e) {
  2109. var cancelable = {
  2110. preventClick: this.animater.forceStopped,
  2111. };
  2112. // we scrolled less than momentumLimitDistance pixels
  2113. if (this.hooks.trigger(this.hooks.eventTypes.checkClick)) {
  2114. this.animater.setForceStopped(false);
  2115. return true;
  2116. }
  2117. if (!cancelable.preventClick) {
  2118. var _dblclick = this.options.dblclick;
  2119. var dblclickTrigged = false;
  2120. if (_dblclick && this.lastClickTime) {
  2121. var _a = _dblclick.delay, delay = _a === void 0 ? 300 : _a;
  2122. if (getNow() - this.lastClickTime < delay) {
  2123. dblclickTrigged = true;
  2124. dblclick(e);
  2125. }
  2126. }
  2127. if (this.options.tap) {
  2128. tap(e, this.options.tap);
  2129. }
  2130. if (this.options.click &&
  2131. !preventDefaultExceptionFn(e.target, this.options.preventDefaultException)) {
  2132. click(e);
  2133. }
  2134. this.lastClickTime = dblclickTrigged ? null : getNow();
  2135. return true;
  2136. }
  2137. return false;
  2138. };
  2139. Scroller.prototype.resize = function () {
  2140. var _this = this;
  2141. if (!this.actions.enabled) {
  2142. return;
  2143. }
  2144. // fix a scroll problem under Android condition
  2145. /* istanbul ignore if */
  2146. if (isAndroid) {
  2147. this.wrapper.scrollTop = 0;
  2148. }
  2149. clearTimeout(this.resizeTimeout);
  2150. this.resizeTimeout = window.setTimeout(function () {
  2151. _this.hooks.trigger(_this.hooks.eventTypes.resize);
  2152. }, this.options.resizePolling);
  2153. };
  2154. /* istanbul ignore next */
  2155. Scroller.prototype.transitionEnd = function (e) {
  2156. if (e.target !== this.content || !this.animater.pending) {
  2157. return;
  2158. }
  2159. var animater = this.animater;
  2160. animater.transitionTime();
  2161. if (!this.resetPosition(this.options.bounceTime, ease.bounce)) {
  2162. this.animater.setPending(false);
  2163. if (this.options.probeType !== 3 /* Realtime */) {
  2164. this.hooks.trigger(this.hooks.eventTypes.scrollEnd, this.getCurrentPos());
  2165. }
  2166. }
  2167. };
  2168. Scroller.prototype.togglePointerEvents = function (enabled) {
  2169. if (enabled === void 0) { enabled = true; }
  2170. var el = this.content.children.length
  2171. ? this.content.children
  2172. : [this.content];
  2173. var pointerEvents = enabled ? 'auto' : 'none';
  2174. for (var i = 0; i < el.length; i++) {
  2175. var node = el[i];
  2176. // ignore BetterScroll instance's wrapper DOM
  2177. /* istanbul ignore if */
  2178. if (node.isBScrollContainer) {
  2179. continue;
  2180. }
  2181. node.style.pointerEvents = pointerEvents;
  2182. }
  2183. };
  2184. Scroller.prototype.refresh = function (content) {
  2185. var contentChanged = this.setContent(content);
  2186. this.hooks.trigger(this.hooks.eventTypes.beforeRefresh);
  2187. this.scrollBehaviorX.refresh(content);
  2188. this.scrollBehaviorY.refresh(content);
  2189. if (contentChanged) {
  2190. this.translater.setContent(content);
  2191. this.animater.setContent(content);
  2192. this.transitionEndRegister.destroy();
  2193. this.registerTransitionEnd();
  2194. if (this.options.bindToTarget) {
  2195. this.actionsHandler.setContent(content);
  2196. }
  2197. }
  2198. this.actions.refresh();
  2199. this.wrapperOffset = offset(this.wrapper);
  2200. };
  2201. Scroller.prototype.setContent = function (content) {
  2202. var contentChanged = content !== this.content;
  2203. if (contentChanged) {
  2204. this.content = content;
  2205. }
  2206. return contentChanged;
  2207. };
  2208. Scroller.prototype.scrollBy = function (deltaX, deltaY, time, easing) {
  2209. if (time === void 0) { time = 0; }
  2210. var _a = this.getCurrentPos(), x = _a.x, y = _a.y;
  2211. easing = !easing ? ease.bounce : easing;
  2212. deltaX += x;
  2213. deltaY += y;
  2214. this.scrollTo(deltaX, deltaY, time, easing);
  2215. };
  2216. Scroller.prototype.scrollTo = function (x, y, time, easing, extraTransform) {
  2217. if (time === void 0) { time = 0; }
  2218. if (easing === void 0) { easing = ease.bounce; }
  2219. if (extraTransform === void 0) { extraTransform = {
  2220. start: {},
  2221. end: {},
  2222. }; }
  2223. var easingFn = this.options.useTransition ? easing.style : easing.fn;
  2224. var currentPos = this.getCurrentPos();
  2225. var startPoint = __assign({ x: currentPos.x, y: currentPos.y }, extraTransform.start);
  2226. var endPoint = __assign({ x: x,
  2227. y: y }, extraTransform.end);
  2228. this.hooks.trigger(this.hooks.eventTypes.scrollTo, endPoint);
  2229. // it is an useless move
  2230. if (isSamePoint(startPoint, endPoint))
  2231. return;
  2232. var deltaX = Math.abs(endPoint.x - startPoint.x);
  2233. var deltaY = Math.abs(endPoint.y - startPoint.y);
  2234. // considering of browser compatibility for decimal transform value
  2235. // force translating immediately
  2236. if (deltaX < MIN_SCROLL_DISTANCE && deltaY < MIN_SCROLL_DISTANCE) {
  2237. time = 0;
  2238. this.hooks.trigger(this.hooks.eventTypes.minDistanceScroll);
  2239. }
  2240. this.animater.move(startPoint, endPoint, time, easingFn);
  2241. };
  2242. Scroller.prototype.scrollToElement = function (el, time, offsetX, offsetY, easing) {
  2243. var targetEle = getElement(el);
  2244. var pos = offset(targetEle);
  2245. var getOffset = function (offset, size, wrapperSize) {
  2246. if (typeof offset === 'number') {
  2247. return offset;
  2248. }
  2249. // if offsetX/Y are true we center the element to the screen
  2250. return offset ? Math.round(size / 2 - wrapperSize / 2) : 0;
  2251. };
  2252. offsetX = getOffset(offsetX, targetEle.offsetWidth, this.wrapper.offsetWidth);
  2253. offsetY = getOffset(offsetY, targetEle.offsetHeight, this.wrapper.offsetHeight);
  2254. var getPos = function (pos, wrapperPos, offset, scrollBehavior) {
  2255. pos -= wrapperPos;
  2256. pos = scrollBehavior.adjustPosition(pos - offset);
  2257. return pos;
  2258. };
  2259. pos.left = getPos(pos.left, this.wrapperOffset.left, offsetX, this.scrollBehaviorX);
  2260. pos.top = getPos(pos.top, this.wrapperOffset.top, offsetY, this.scrollBehaviorY);
  2261. if (this.hooks.trigger(this.hooks.eventTypes.scrollToElement, targetEle, pos)) {
  2262. return;
  2263. }
  2264. this.scrollTo(pos.left, pos.top, time, easing);
  2265. };
  2266. Scroller.prototype.resetPosition = function (time, easing) {
  2267. if (time === void 0) { time = 0; }
  2268. if (easing === void 0) { easing = ease.bounce; }
  2269. var _a = this.scrollBehaviorX.checkInBoundary(), x = _a.position, xInBoundary = _a.inBoundary;
  2270. var _b = this.scrollBehaviorY.checkInBoundary(), y = _b.position, yInBoundary = _b.inBoundary;
  2271. if (xInBoundary && yInBoundary) {
  2272. return false;
  2273. }
  2274. /* istanbul ignore if */
  2275. if (isIOSBadVersion) {
  2276. // fix ios 13.4 bouncing
  2277. // see it in issues 982
  2278. this.reflow();
  2279. }
  2280. // out of boundary
  2281. this.scrollTo(x, y, time, easing);
  2282. return true;
  2283. };
  2284. /* istanbul ignore next */
  2285. Scroller.prototype.reflow = function () {
  2286. this._reflow = this.content.offsetHeight;
  2287. };
  2288. Scroller.prototype.updatePositions = function (pos) {
  2289. this.scrollBehaviorX.updatePosition(pos.x);
  2290. this.scrollBehaviorY.updatePosition(pos.y);
  2291. };
  2292. Scroller.prototype.getCurrentPos = function () {
  2293. return this.actions.getCurrentPos();
  2294. };
  2295. Scroller.prototype.enable = function () {
  2296. this.actions.enabled = true;
  2297. };
  2298. Scroller.prototype.disable = function () {
  2299. cancelAnimationFrame(this.animater.timer);
  2300. this.actions.enabled = false;
  2301. };
  2302. Scroller.prototype.destroy = function () {
  2303. var _this = this;
  2304. var keys = [
  2305. 'resizeRegister',
  2306. 'transitionEndRegister',
  2307. 'actionsHandler',
  2308. 'actions',
  2309. 'hooks',
  2310. 'animater',
  2311. 'translater',
  2312. 'scrollBehaviorX',
  2313. 'scrollBehaviorY',
  2314. ];
  2315. keys.forEach(function (key) { return _this[key].destroy(); });
  2316. };
  2317. return Scroller;
  2318. }());
  2319. var BScrollConstructor = /** @class */ (function (_super) {
  2320. __extends(BScrollConstructor, _super);
  2321. function BScrollConstructor(el, options) {
  2322. var _this = _super.call(this, [
  2323. 'refresh',
  2324. 'contentChanged',
  2325. 'enable',
  2326. 'disable',
  2327. 'beforeScrollStart',
  2328. 'scrollStart',
  2329. 'scroll',
  2330. 'scrollEnd',
  2331. 'scrollCancel',
  2332. 'touchEnd',
  2333. 'flick',
  2334. 'destroy'
  2335. ]) || this;
  2336. var wrapper = getElement(el);
  2337. if (!wrapper) {
  2338. warn('Can not resolve the wrapper DOM.');
  2339. return _this;
  2340. }
  2341. _this.plugins = {};
  2342. _this.options = new OptionsConstructor().merge(options).process();
  2343. if (!_this.setContent(wrapper).valid) {
  2344. return _this;
  2345. }
  2346. _this.hooks = new EventEmitter([
  2347. 'refresh',
  2348. 'enable',
  2349. 'disable',
  2350. 'destroy',
  2351. 'beforeInitialScrollTo',
  2352. 'contentChanged'
  2353. ]);
  2354. _this.init(wrapper);
  2355. return _this;
  2356. }
  2357. BScrollConstructor.use = function (ctor) {
  2358. var name = ctor.pluginName;
  2359. var installed = BScrollConstructor.plugins.some(function (plugin) { return ctor === plugin.ctor; });
  2360. if (installed)
  2361. return BScrollConstructor;
  2362. if (isUndef(name)) {
  2363. warn("Plugin Class must specify plugin's name in static property by 'pluginName' field.");
  2364. return BScrollConstructor;
  2365. }
  2366. BScrollConstructor.pluginsMap[name] = true;
  2367. BScrollConstructor.plugins.push({
  2368. name: name,
  2369. applyOrder: ctor.applyOrder,
  2370. ctor: ctor
  2371. });
  2372. return BScrollConstructor;
  2373. };
  2374. BScrollConstructor.prototype.setContent = function (wrapper) {
  2375. var contentChanged = false;
  2376. var valid = true;
  2377. var content = wrapper.children[this.options.specifiedIndexAsContent];
  2378. if (!content) {
  2379. warn('The wrapper need at least one child element to be content element to scroll.');
  2380. valid = false;
  2381. }
  2382. else {
  2383. contentChanged = this.content !== content;
  2384. if (contentChanged) {
  2385. this.content = content;
  2386. }
  2387. }
  2388. return {
  2389. valid: valid,
  2390. contentChanged: contentChanged
  2391. };
  2392. };
  2393. BScrollConstructor.prototype.init = function (wrapper) {
  2394. var _this = this;
  2395. this.wrapper = wrapper;
  2396. // mark wrapper to recognize bs instance by DOM attribute
  2397. wrapper.isBScrollContainer = true;
  2398. this.scroller = new Scroller(wrapper, this.content, this.options);
  2399. this.scroller.hooks.on(this.scroller.hooks.eventTypes.resize, function () {
  2400. _this.refresh();
  2401. });
  2402. this.eventBubbling();
  2403. this.handleAutoBlur();
  2404. this.enable();
  2405. this.proxy(propertiesConfig$7);
  2406. this.applyPlugins();
  2407. // maybe boundary has changed, should refresh
  2408. this.refreshWithoutReset(this.content);
  2409. var _a = this.options, startX = _a.startX, startY = _a.startY;
  2410. var position = {
  2411. x: startX,
  2412. y: startY
  2413. };
  2414. // maybe plugins want to control scroll position
  2415. if (this.hooks.trigger(this.hooks.eventTypes.beforeInitialScrollTo, position)) {
  2416. return;
  2417. }
  2418. this.scroller.scrollTo(position.x, position.y);
  2419. };
  2420. BScrollConstructor.prototype.applyPlugins = function () {
  2421. var _this = this;
  2422. var options = this.options;
  2423. BScrollConstructor.plugins
  2424. .sort(function (a, b) {
  2425. var _a;
  2426. var applyOrderMap = (_a = {},
  2427. _a["pre" /* Pre */] = -1,
  2428. _a["post" /* Post */] = 1,
  2429. _a);
  2430. var aOrder = a.applyOrder ? applyOrderMap[a.applyOrder] : 0;
  2431. var bOrder = b.applyOrder ? applyOrderMap[b.applyOrder] : 0;
  2432. return aOrder - bOrder;
  2433. })
  2434. .forEach(function (item) {
  2435. var ctor = item.ctor;
  2436. if (options[item.name] && typeof ctor === 'function') {
  2437. _this.plugins[item.name] = new ctor(_this);
  2438. }
  2439. });
  2440. };
  2441. BScrollConstructor.prototype.handleAutoBlur = function () {
  2442. /* istanbul ignore if */
  2443. if (this.options.autoBlur) {
  2444. this.on(this.eventTypes.beforeScrollStart, function () {
  2445. var activeElement = document.activeElement;
  2446. if (activeElement &&
  2447. (activeElement.tagName === 'INPUT' ||
  2448. activeElement.tagName === 'TEXTAREA')) {
  2449. activeElement.blur();
  2450. }
  2451. });
  2452. }
  2453. };
  2454. BScrollConstructor.prototype.eventBubbling = function () {
  2455. bubbling(this.scroller.hooks, this, [
  2456. this.eventTypes.beforeScrollStart,
  2457. this.eventTypes.scrollStart,
  2458. this.eventTypes.scroll,
  2459. this.eventTypes.scrollEnd,
  2460. this.eventTypes.scrollCancel,
  2461. this.eventTypes.touchEnd,
  2462. this.eventTypes.flick
  2463. ]);
  2464. };
  2465. BScrollConstructor.prototype.refreshWithoutReset = function (content) {
  2466. this.scroller.refresh(content);
  2467. this.hooks.trigger(this.hooks.eventTypes.refresh, content);
  2468. this.trigger(this.eventTypes.refresh, content);
  2469. };
  2470. BScrollConstructor.prototype.proxy = function (propertiesConfig) {
  2471. var _this = this;
  2472. propertiesConfig.forEach(function (_a) {
  2473. var key = _a.key, sourceKey = _a.sourceKey;
  2474. propertiesProxy(_this, sourceKey, key);
  2475. });
  2476. };
  2477. BScrollConstructor.prototype.refresh = function () {
  2478. var _a = this.setContent(this.wrapper), contentChanged = _a.contentChanged, valid = _a.valid;
  2479. if (valid) {
  2480. var content = this.content;
  2481. this.refreshWithoutReset(content);
  2482. if (contentChanged) {
  2483. this.hooks.trigger(this.hooks.eventTypes.contentChanged, content);
  2484. this.trigger(this.eventTypes.contentChanged, content);
  2485. }
  2486. this.scroller.resetPosition();
  2487. }
  2488. };
  2489. BScrollConstructor.prototype.enable = function () {
  2490. this.scroller.enable();
  2491. this.hooks.trigger(this.hooks.eventTypes.enable);
  2492. this.trigger(this.eventTypes.enable);
  2493. };
  2494. BScrollConstructor.prototype.disable = function () {
  2495. this.scroller.disable();
  2496. this.hooks.trigger(this.hooks.eventTypes.disable);
  2497. this.trigger(this.eventTypes.disable);
  2498. };
  2499. BScrollConstructor.prototype.destroy = function () {
  2500. this.hooks.trigger(this.hooks.eventTypes.destroy);
  2501. this.trigger(this.eventTypes.destroy);
  2502. this.scroller.destroy();
  2503. };
  2504. BScrollConstructor.prototype.eventRegister = function (names) {
  2505. this.registerType(names);
  2506. };
  2507. BScrollConstructor.plugins = [];
  2508. BScrollConstructor.pluginsMap = {};
  2509. return BScrollConstructor;
  2510. }(EventEmitter));
  2511. function createBScroll(el, options) {
  2512. var bs = new BScrollConstructor(el, options);
  2513. return bs;
  2514. }
  2515. createBScroll.use = BScrollConstructor.use;
  2516. createBScroll.plugins = BScrollConstructor.plugins;
  2517. createBScroll.pluginsMap = BScrollConstructor.pluginsMap;
  2518. var BScroll = createBScroll;
  2519. var MouseWheel = /** @class */ (function () {
  2520. function MouseWheel(scroll) {
  2521. this.scroll = scroll;
  2522. this.wheelEndTimer = 0;
  2523. this.wheelMoveTimer = 0;
  2524. this.wheelStart = false;
  2525. this.init();
  2526. }
  2527. MouseWheel.prototype.init = function () {
  2528. this.handleBScroll();
  2529. this.handleOptions();
  2530. this.handleHooks();
  2531. this.registerEvent();
  2532. };
  2533. MouseWheel.prototype.handleBScroll = function () {
  2534. this.scroll.registerType([
  2535. 'alterOptions',
  2536. 'mousewheelStart',
  2537. 'mousewheelMove',
  2538. 'mousewheelEnd',
  2539. ]);
  2540. };
  2541. MouseWheel.prototype.handleOptions = function () {
  2542. var userOptions = (this.scroll.options.mouseWheel === true
  2543. ? {}
  2544. : this.scroll.options.mouseWheel);
  2545. var defaultOptions = {
  2546. speed: 20,
  2547. invert: false,
  2548. easeTime: 300,
  2549. discreteTime: 400,
  2550. throttleTime: 0,
  2551. dampingFactor: 0.1,
  2552. };
  2553. this.mouseWheelOpt = extend(defaultOptions, userOptions);
  2554. };
  2555. MouseWheel.prototype.handleHooks = function () {
  2556. this.hooksFn = [];
  2557. this.registerHooks(this.scroll.hooks, 'destroy', this.destroy);
  2558. };
  2559. MouseWheel.prototype.registerEvent = function () {
  2560. this.eventRegister = new EventRegister(this.scroll.scroller.wrapper, [
  2561. {
  2562. name: 'wheel',
  2563. handler: this.wheelHandler.bind(this),
  2564. },
  2565. {
  2566. name: 'mousewheel',
  2567. handler: this.wheelHandler.bind(this),
  2568. },
  2569. {
  2570. name: 'DOMMouseScroll',
  2571. handler: this.wheelHandler.bind(this),
  2572. },
  2573. ]);
  2574. };
  2575. MouseWheel.prototype.registerHooks = function (hooks, name, handler) {
  2576. hooks.on(name, handler, this);
  2577. this.hooksFn.push([hooks, name, handler]);
  2578. };
  2579. MouseWheel.prototype.wheelHandler = function (e) {
  2580. if (!this.scroll.enabled) {
  2581. return;
  2582. }
  2583. this.beforeHandler(e);
  2584. // start
  2585. if (!this.wheelStart) {
  2586. this.wheelStartHandler(e);
  2587. this.wheelStart = true;
  2588. }
  2589. // move
  2590. var delta = this.getWheelDelta(e);
  2591. this.wheelMoveHandler(delta);
  2592. // end
  2593. this.wheelEndDetector(delta);
  2594. };
  2595. MouseWheel.prototype.wheelStartHandler = function (e) {
  2596. this.cleanCache();
  2597. var _a = this.scroll.scroller, scrollBehaviorX = _a.scrollBehaviorX, scrollBehaviorY = _a.scrollBehaviorY;
  2598. scrollBehaviorX.setMovingDirection(0 /* Default */);
  2599. scrollBehaviorY.setMovingDirection(0 /* Default */);
  2600. scrollBehaviorX.setDirection(0 /* Default */);
  2601. scrollBehaviorY.setDirection(0 /* Default */);
  2602. this.scroll.trigger(this.scroll.eventTypes.alterOptions, this.mouseWheelOpt);
  2603. this.scroll.trigger(this.scroll.eventTypes.mousewheelStart);
  2604. };
  2605. MouseWheel.prototype.cleanCache = function () {
  2606. this.deltaCache = [];
  2607. };
  2608. MouseWheel.prototype.wheelMoveHandler = function (delta) {
  2609. var _this = this;
  2610. var _a = this.mouseWheelOpt, throttleTime = _a.throttleTime, dampingFactor = _a.dampingFactor;
  2611. if (throttleTime && this.wheelMoveTimer) {
  2612. this.deltaCache.push(delta);
  2613. }
  2614. else {
  2615. var cachedDelta = this.deltaCache.reduce(function (prev, current) {
  2616. return {
  2617. x: prev.x + current.x,
  2618. y: prev.y + current.y,
  2619. };
  2620. }, { x: 0, y: 0 });
  2621. this.cleanCache();
  2622. var _b = this.scroll.scroller, scrollBehaviorX = _b.scrollBehaviorX, scrollBehaviorY = _b.scrollBehaviorY;
  2623. scrollBehaviorX.setMovingDirection(-delta.directionX);
  2624. scrollBehaviorY.setMovingDirection(-delta.directionY);
  2625. scrollBehaviorX.setDirection(delta.x);
  2626. scrollBehaviorY.setDirection(delta.y);
  2627. // when out of boundary, perform a damping scroll
  2628. var newX = scrollBehaviorX.performDampingAlgorithm(Math.round(delta.x) + cachedDelta.x, dampingFactor);
  2629. var newY = scrollBehaviorY.performDampingAlgorithm(Math.round(delta.y) + cachedDelta.x, dampingFactor);
  2630. if (!this.scroll.trigger(this.scroll.eventTypes.mousewheelMove, {
  2631. x: newX,
  2632. y: newY,
  2633. })) {
  2634. var easeTime = this.getEaseTime();
  2635. if (newX !== this.scroll.x || newY !== this.scroll.y) {
  2636. this.scroll.scrollTo(newX, newY, easeTime);
  2637. }
  2638. }
  2639. if (throttleTime) {
  2640. this.wheelMoveTimer = window.setTimeout(function () {
  2641. _this.wheelMoveTimer = 0;
  2642. }, throttleTime);
  2643. }
  2644. }
  2645. };
  2646. MouseWheel.prototype.wheelEndDetector = function (delta) {
  2647. var _this = this;
  2648. window.clearTimeout(this.wheelEndTimer);
  2649. this.wheelEndTimer = window.setTimeout(function () {
  2650. _this.wheelStart = false;
  2651. window.clearTimeout(_this.wheelMoveTimer);
  2652. _this.wheelMoveTimer = 0;
  2653. _this.scroll.trigger(_this.scroll.eventTypes.mousewheelEnd, delta);
  2654. }, this.mouseWheelOpt.discreteTime);
  2655. };
  2656. MouseWheel.prototype.getWheelDelta = function (e) {
  2657. var _a = this.mouseWheelOpt, speed = _a.speed, invert = _a.invert;
  2658. var wheelDeltaX = 0;
  2659. var wheelDeltaY = 0;
  2660. var direction = invert ? -1 /* Negative */ : 1 /* Positive */;
  2661. switch (true) {
  2662. case 'deltaX' in e:
  2663. if (e.deltaMode === 1) {
  2664. wheelDeltaX = -e.deltaX * speed;
  2665. wheelDeltaY = -e.deltaY * speed;
  2666. }
  2667. else {
  2668. wheelDeltaX = -e.deltaX;
  2669. wheelDeltaY = -e.deltaY;
  2670. }
  2671. break;
  2672. case 'wheelDeltaX' in e:
  2673. wheelDeltaX = (e.wheelDeltaX / 120) * speed;
  2674. wheelDeltaY = (e.wheelDeltaY / 120) * speed;
  2675. break;
  2676. case 'wheelDelta' in e:
  2677. wheelDeltaX = wheelDeltaY = (e.wheelDelta / 120) * speed;
  2678. break;
  2679. case 'detail' in e:
  2680. wheelDeltaX = wheelDeltaY = (-e.detail / 3) * speed;
  2681. break;
  2682. }
  2683. wheelDeltaX *= direction;
  2684. wheelDeltaY *= direction;
  2685. if (!this.scroll.hasVerticalScroll) {
  2686. if (Math.abs(wheelDeltaY) > Math.abs(wheelDeltaX)) {
  2687. wheelDeltaX = wheelDeltaY;
  2688. }
  2689. wheelDeltaY = 0;
  2690. }
  2691. if (!this.scroll.hasHorizontalScroll) {
  2692. wheelDeltaX = 0;
  2693. }
  2694. var directionX = wheelDeltaX > 0
  2695. ? -1 /* Negative */
  2696. : wheelDeltaX < 0
  2697. ? 1 /* Positive */
  2698. : 0 /* Default */;
  2699. var directionY = wheelDeltaY > 0
  2700. ? -1 /* Negative */
  2701. : wheelDeltaY < 0
  2702. ? 1 /* Positive */
  2703. : 0 /* Default */;
  2704. return {
  2705. x: wheelDeltaX,
  2706. y: wheelDeltaY,
  2707. directionX: directionX,
  2708. directionY: directionY,
  2709. };
  2710. };
  2711. MouseWheel.prototype.beforeHandler = function (e) {
  2712. var _a = this.scroll.options, preventDefault = _a.preventDefault, stopPropagation = _a.stopPropagation, preventDefaultException = _a.preventDefaultException;
  2713. if (preventDefault &&
  2714. !preventDefaultExceptionFn(e.target, preventDefaultException)) {
  2715. e.preventDefault();
  2716. }
  2717. if (stopPropagation) {
  2718. e.stopPropagation();
  2719. }
  2720. };
  2721. MouseWheel.prototype.getEaseTime = function () {
  2722. var SAFE_EASETIME = 100;
  2723. var easeTime = this.mouseWheelOpt.easeTime;
  2724. // scrollEnd event will be triggered in every calling of scrollTo when easeTime is too small
  2725. // easeTime needs to be greater than 100
  2726. if (easeTime < SAFE_EASETIME) {
  2727. warn("easeTime should be greater than 100." +
  2728. "If mouseWheel easeTime is too small," +
  2729. "scrollEnd will be triggered many times.");
  2730. }
  2731. return Math.max(easeTime, SAFE_EASETIME);
  2732. };
  2733. MouseWheel.prototype.destroy = function () {
  2734. this.eventRegister.destroy();
  2735. window.clearTimeout(this.wheelEndTimer);
  2736. window.clearTimeout(this.wheelMoveTimer);
  2737. this.hooksFn.forEach(function (item) {
  2738. var hooks = item[0];
  2739. var hooksName = item[1];
  2740. var handlerFn = item[2];
  2741. hooks.off(hooksName, handlerFn);
  2742. });
  2743. };
  2744. MouseWheel.pluginName = 'mouseWheel';
  2745. MouseWheel.applyOrder = "pre" /* Pre */;
  2746. return MouseWheel;
  2747. }());
  2748. var ObserveDOM = /** @class */ (function () {
  2749. function ObserveDOM(scroll) {
  2750. this.scroll = scroll;
  2751. this.stopObserver = false;
  2752. this.init();
  2753. }
  2754. ObserveDOM.prototype.init = function () {
  2755. this.handleMutationObserver();
  2756. this.handleHooks();
  2757. };
  2758. ObserveDOM.prototype.handleMutationObserver = function () {
  2759. var _this = this;
  2760. if (typeof MutationObserver !== 'undefined') {
  2761. var timer_1 = 0;
  2762. this.observer = new MutationObserver(function (mutations) {
  2763. _this.mutationObserverHandler(mutations, timer_1);
  2764. });
  2765. this.startObserve(this.observer);
  2766. }
  2767. else {
  2768. this.checkDOMUpdate();
  2769. }
  2770. };
  2771. ObserveDOM.prototype.handleHooks = function () {
  2772. var _this = this;
  2773. this.hooksFn = [];
  2774. this.registerHooks(this.scroll.hooks, this.scroll.hooks.eventTypes.contentChanged, function () {
  2775. _this.stopObserve();
  2776. // launch a new mutationObserver
  2777. _this.handleMutationObserver();
  2778. });
  2779. this.registerHooks(this.scroll.hooks, this.scroll.hooks.eventTypes.enable, function () {
  2780. if (_this.stopObserver) {
  2781. _this.handleMutationObserver();
  2782. }
  2783. });
  2784. this.registerHooks(this.scroll.hooks, this.scroll.hooks.eventTypes.disable, function () {
  2785. _this.stopObserve();
  2786. });
  2787. this.registerHooks(this.scroll.hooks, this.scroll.hooks.eventTypes.destroy, function () {
  2788. _this.destroy();
  2789. });
  2790. };
  2791. ObserveDOM.prototype.mutationObserverHandler = function (mutations, timer) {
  2792. var _this = this;
  2793. if (this.shouldNotRefresh()) {
  2794. return;
  2795. }
  2796. var immediateRefresh = false;
  2797. var deferredRefresh = false;
  2798. for (var i = 0; i < mutations.length; i++) {
  2799. var mutation = mutations[i];
  2800. if (mutation.type !== 'attributes') {
  2801. immediateRefresh = true;
  2802. break;
  2803. }
  2804. else {
  2805. if (mutation.target !== this.scroll.scroller.content) {
  2806. deferredRefresh = true;
  2807. break;
  2808. }
  2809. }
  2810. }
  2811. if (immediateRefresh) {
  2812. this.scroll.refresh();
  2813. }
  2814. else if (deferredRefresh) {
  2815. // attributes changes too often
  2816. clearTimeout(timer);
  2817. timer = window.setTimeout(function () {
  2818. if (!_this.shouldNotRefresh()) {
  2819. _this.scroll.refresh();
  2820. }
  2821. }, 60);
  2822. }
  2823. };
  2824. ObserveDOM.prototype.startObserve = function (observer) {
  2825. var config = {
  2826. attributes: true,
  2827. childList: true,
  2828. subtree: true,
  2829. };
  2830. observer.observe(this.scroll.scroller.content, config);
  2831. };
  2832. ObserveDOM.prototype.shouldNotRefresh = function () {
  2833. var scroller = this.scroll.scroller;
  2834. var scrollBehaviorX = scroller.scrollBehaviorX, scrollBehaviorY = scroller.scrollBehaviorY;
  2835. var outsideBoundaries = scrollBehaviorX.currentPos > scrollBehaviorX.minScrollPos ||
  2836. scrollBehaviorX.currentPos < scrollBehaviorX.maxScrollPos ||
  2837. scrollBehaviorY.currentPos > scrollBehaviorY.minScrollPos ||
  2838. scrollBehaviorY.currentPos < scrollBehaviorY.maxScrollPos;
  2839. return scroller.animater.pending || outsideBoundaries;
  2840. };
  2841. ObserveDOM.prototype.checkDOMUpdate = function () {
  2842. var _this = this;
  2843. var content = this.scroll.scroller.content;
  2844. var contentRect = getRect(content);
  2845. var oldWidth = contentRect.width;
  2846. var oldHeight = contentRect.height;
  2847. var check = function () {
  2848. if (_this.stopObserver) {
  2849. return;
  2850. }
  2851. contentRect = getRect(content);
  2852. var newWidth = contentRect.width;
  2853. var newHeight = contentRect.height;
  2854. if (oldWidth !== newWidth || oldHeight !== newHeight) {
  2855. _this.scroll.refresh();
  2856. }
  2857. oldWidth = newWidth;
  2858. oldHeight = newHeight;
  2859. next();
  2860. };
  2861. var next = function () {
  2862. setTimeout(function () {
  2863. check();
  2864. }, 1000);
  2865. };
  2866. next();
  2867. };
  2868. ObserveDOM.prototype.registerHooks = function (hooks, name, handler) {
  2869. hooks.on(name, handler, this);
  2870. this.hooksFn.push([hooks, name, handler]);
  2871. };
  2872. ObserveDOM.prototype.stopObserve = function () {
  2873. this.stopObserver = true;
  2874. if (this.observer) {
  2875. this.observer.disconnect();
  2876. }
  2877. };
  2878. ObserveDOM.prototype.destroy = function () {
  2879. this.stopObserve();
  2880. this.hooksFn.forEach(function (item) {
  2881. var hooks = item[0];
  2882. var hooksName = item[1];
  2883. var handlerFn = item[2];
  2884. hooks.off(hooksName, handlerFn);
  2885. });
  2886. this.hooksFn.length = 0;
  2887. };
  2888. ObserveDOM.pluginName = 'observeDOM';
  2889. return ObserveDOM;
  2890. }());
  2891. var sourcePrefix$6 = 'plugins.pullDownRefresh';
  2892. var propertiesMap$6 = [
  2893. {
  2894. key: 'finishPullDown',
  2895. name: 'finishPullDown'
  2896. },
  2897. {
  2898. key: 'openPullDown',
  2899. name: 'openPullDown'
  2900. },
  2901. {
  2902. key: 'closePullDown',
  2903. name: 'closePullDown'
  2904. },
  2905. {
  2906. key: 'autoPullDownRefresh',
  2907. name: 'autoPullDownRefresh'
  2908. }
  2909. ];
  2910. var propertiesConfig$6 = propertiesMap$6.map(function (item) {
  2911. return {
  2912. key: item.key,
  2913. sourceKey: sourcePrefix$6 + "." + item.name
  2914. };
  2915. });
  2916. var PULLING_DOWN_EVENT = 'pullingDown';
  2917. var ENTER_THRESHOLD_EVENT = 'enterThreshold';
  2918. var LEAVE_THRESHOLD_EVENT = 'leaveThreshold';
  2919. var PullDown = /** @class */ (function () {
  2920. function PullDown(scroll) {
  2921. this.scroll = scroll;
  2922. this.pulling = 0 /* DEFAULT */;
  2923. this.thresholdBoundary = 0 /* DEFAULT */;
  2924. this.init();
  2925. }
  2926. PullDown.prototype.setPulling = function (status) {
  2927. this.pulling = status;
  2928. };
  2929. PullDown.prototype.setThresholdBoundary = function (boundary) {
  2930. this.thresholdBoundary = boundary;
  2931. };
  2932. PullDown.prototype.init = function () {
  2933. this.handleBScroll();
  2934. this.handleOptions(this.scroll.options.pullDownRefresh);
  2935. this.handleHooks();
  2936. this.watch();
  2937. };
  2938. PullDown.prototype.handleBScroll = function () {
  2939. this.scroll.registerType([
  2940. PULLING_DOWN_EVENT,
  2941. ENTER_THRESHOLD_EVENT,
  2942. LEAVE_THRESHOLD_EVENT,
  2943. ]);
  2944. this.scroll.proxy(propertiesConfig$6);
  2945. };
  2946. PullDown.prototype.handleOptions = function (userOptions) {
  2947. if (userOptions === void 0) { userOptions = {}; }
  2948. userOptions = (userOptions === true ? {} : userOptions);
  2949. var defaultOptions = {
  2950. threshold: 90,
  2951. stop: 40,
  2952. };
  2953. this.options = extend(defaultOptions, userOptions);
  2954. this.scroll.options.probeType = 3 /* Realtime */;
  2955. };
  2956. PullDown.prototype.handleHooks = function () {
  2957. var _this = this;
  2958. this.hooksFn = [];
  2959. var scroller = this.scroll.scroller;
  2960. var scrollBehaviorY = scroller.scrollBehaviorY;
  2961. this.currentMinScrollY = this.cachedOriginanMinScrollY =
  2962. scrollBehaviorY.minScrollPos;
  2963. this.registerHooks(this.scroll.hooks, this.scroll.hooks.eventTypes.contentChanged, function () {
  2964. _this.finishPullDown();
  2965. });
  2966. this.registerHooks(scrollBehaviorY.hooks, scrollBehaviorY.hooks.eventTypes.computeBoundary, function (boundary) {
  2967. // content is smaller than wrapper
  2968. if (boundary.maxScrollPos > 0) {
  2969. // allow scrolling when content is not full of wrapper
  2970. boundary.maxScrollPos = -1;
  2971. }
  2972. boundary.minScrollPos = _this.currentMinScrollY;
  2973. });
  2974. // integrate with mousewheel
  2975. if (this.hasMouseWheelPlugin()) {
  2976. this.registerHooks(this.scroll, this.scroll.eventTypes.alterOptions, function (mouseWheelOptions) {
  2977. var SANE_DISCRETE_TIME = 300;
  2978. var SANE_EASE_TIME = 350;
  2979. mouseWheelOptions.discreteTime = SANE_DISCRETE_TIME;
  2980. // easeTime > discreteTime ensure goInto checkPullDown function
  2981. mouseWheelOptions.easeTime = SANE_EASE_TIME;
  2982. });
  2983. this.registerHooks(this.scroll, this.scroll.eventTypes.mousewheelEnd, function () {
  2984. // mouseWheel need trigger checkPullDown manually
  2985. scroller.hooks.trigger(scroller.hooks.eventTypes.end);
  2986. });
  2987. }
  2988. };
  2989. PullDown.prototype.registerHooks = function (hooks, name, handler) {
  2990. hooks.on(name, handler, this);
  2991. this.hooksFn.push([hooks, name, handler]);
  2992. };
  2993. PullDown.prototype.hasMouseWheelPlugin = function () {
  2994. return !!this.scroll.eventTypes.alterOptions;
  2995. };
  2996. PullDown.prototype.watch = function () {
  2997. var scroller = this.scroll.scroller;
  2998. this.watching = true;
  2999. this.registerHooks(scroller.hooks, scroller.hooks.eventTypes.end, this.checkPullDown);
  3000. this.registerHooks(this.scroll, this.scroll.eventTypes.scrollStart, this.resetStateBeforeScrollStart);
  3001. this.registerHooks(this.scroll, this.scroll.eventTypes.scroll, this.checkLocationOfThresholdBoundary);
  3002. if (this.hasMouseWheelPlugin()) {
  3003. this.registerHooks(this.scroll, this.scroll.eventTypes.mousewheelStart, this.resetStateBeforeScrollStart);
  3004. }
  3005. };
  3006. PullDown.prototype.resetStateBeforeScrollStart = function () {
  3007. // current fetching pulldownRefresh has ended
  3008. if (!this.isFetchingStatus()) {
  3009. this.setPulling(1 /* MOVING */);
  3010. this.setThresholdBoundary(0 /* DEFAULT */);
  3011. }
  3012. };
  3013. PullDown.prototype.checkLocationOfThresholdBoundary = function () {
  3014. // pulldownRefresh is in the phase of Moving
  3015. if (this.pulling === 1 /* MOVING */) {
  3016. var scroll_1 = this.scroll;
  3017. // enter threshold boundary
  3018. var enteredThresholdBoundary = this.thresholdBoundary !== 1 /* INSIDE */ &&
  3019. this.locateInsideThresholdBoundary();
  3020. // leave threshold boundary
  3021. var leftThresholdBoundary = this.thresholdBoundary !== 2 /* OUTSIDE */ &&
  3022. !this.locateInsideThresholdBoundary();
  3023. if (enteredThresholdBoundary) {
  3024. this.setThresholdBoundary(1 /* INSIDE */);
  3025. scroll_1.trigger(ENTER_THRESHOLD_EVENT);
  3026. }
  3027. if (leftThresholdBoundary) {
  3028. this.setThresholdBoundary(2 /* OUTSIDE */);
  3029. scroll_1.trigger(LEAVE_THRESHOLD_EVENT);
  3030. }
  3031. }
  3032. };
  3033. PullDown.prototype.locateInsideThresholdBoundary = function () {
  3034. return this.scroll.y <= this.options.threshold;
  3035. };
  3036. PullDown.prototype.unwatch = function () {
  3037. var scroll = this.scroll;
  3038. var scroller = scroll.scroller;
  3039. this.watching = false;
  3040. scroller.hooks.off(scroller.hooks.eventTypes.end, this.checkPullDown);
  3041. scroll.off(scroll.eventTypes.scrollStart, this.resetStateBeforeScrollStart);
  3042. scroll.off(scroll.eventTypes.scroll, this.checkLocationOfThresholdBoundary);
  3043. if (this.hasMouseWheelPlugin()) {
  3044. scroll.off(scroll.eventTypes.mousewheelStart, this.resetStateBeforeScrollStart);
  3045. }
  3046. };
  3047. PullDown.prototype.checkPullDown = function () {
  3048. var _a = this.options, threshold = _a.threshold, stop = _a.stop;
  3049. // check if a real pull down action
  3050. if (this.scroll.y < threshold) {
  3051. return false;
  3052. }
  3053. if (this.pulling === 1 /* MOVING */) {
  3054. this.modifyBehaviorYBoundary(stop);
  3055. this.setPulling(2 /* FETCHING */);
  3056. this.scroll.trigger(PULLING_DOWN_EVENT);
  3057. }
  3058. this.scroll.scrollTo(this.scroll.x, stop, this.scroll.options.bounceTime, ease.bounce);
  3059. return this.isFetchingStatus();
  3060. };
  3061. PullDown.prototype.isFetchingStatus = function () {
  3062. return this.pulling === 2 /* FETCHING */;
  3063. };
  3064. PullDown.prototype.modifyBehaviorYBoundary = function (stopDistance) {
  3065. var scrollBehaviorY = this.scroll.scroller.scrollBehaviorY;
  3066. // manually modify minScrollPos for a hang animation
  3067. // to prevent from resetPosition
  3068. this.cachedOriginanMinScrollY = scrollBehaviorY.minScrollPos;
  3069. this.currentMinScrollY = stopDistance;
  3070. scrollBehaviorY.computeBoundary();
  3071. };
  3072. PullDown.prototype.finishPullDown = function () {
  3073. if (this.isFetchingStatus()) {
  3074. var scrollBehaviorY = this.scroll.scroller.scrollBehaviorY;
  3075. // restore minScrollY since the hang animation has ended
  3076. this.currentMinScrollY = this.cachedOriginanMinScrollY;
  3077. scrollBehaviorY.computeBoundary();
  3078. this.setPulling(0 /* DEFAULT */);
  3079. this.scroll.resetPosition(this.scroll.options.bounceTime, ease.bounce);
  3080. }
  3081. };
  3082. // allow 'true' type is compat for beta version implements
  3083. PullDown.prototype.openPullDown = function (config) {
  3084. if (config === void 0) { config = {}; }
  3085. this.handleOptions(config);
  3086. if (!this.watching) {
  3087. this.watch();
  3088. }
  3089. };
  3090. PullDown.prototype.closePullDown = function () {
  3091. this.unwatch();
  3092. };
  3093. PullDown.prototype.autoPullDownRefresh = function () {
  3094. var _a = this.options, threshold = _a.threshold, stop = _a.stop;
  3095. if (this.isFetchingStatus() || !this.watching) {
  3096. return;
  3097. }
  3098. this.modifyBehaviorYBoundary(stop);
  3099. this.scroll.trigger(this.scroll.eventTypes.scrollStart);
  3100. this.scroll.scrollTo(this.scroll.x, threshold);
  3101. this.setPulling(2 /* FETCHING */);
  3102. this.scroll.trigger(PULLING_DOWN_EVENT);
  3103. this.scroll.scrollTo(this.scroll.x, stop, this.scroll.options.bounceTime, ease.bounce);
  3104. };
  3105. PullDown.pluginName = 'pullDownRefresh';
  3106. return PullDown;
  3107. }());
  3108. var sourcePrefix$5 = 'plugins.pullUpLoad';
  3109. var propertiesMap$5 = [
  3110. {
  3111. key: 'finishPullUp',
  3112. name: 'finishPullUp'
  3113. },
  3114. {
  3115. key: 'openPullUp',
  3116. name: 'openPullUp'
  3117. },
  3118. {
  3119. key: 'closePullUp',
  3120. name: 'closePullUp'
  3121. },
  3122. {
  3123. key: 'autoPullUpLoad',
  3124. name: 'autoPullUpLoad'
  3125. }
  3126. ];
  3127. var propertiesConfig$5 = propertiesMap$5.map(function (item) {
  3128. return {
  3129. key: item.key,
  3130. sourceKey: sourcePrefix$5 + "." + item.name
  3131. };
  3132. });
  3133. var PULL_UP_HOOKS_NAME = 'pullingUp';
  3134. var PullUp = /** @class */ (function () {
  3135. function PullUp(scroll) {
  3136. this.scroll = scroll;
  3137. this.pulling = false;
  3138. this.watching = false;
  3139. this.init();
  3140. }
  3141. PullUp.prototype.init = function () {
  3142. this.handleBScroll();
  3143. this.handleOptions(this.scroll.options.pullUpLoad);
  3144. this.handleHooks();
  3145. this.watch();
  3146. };
  3147. PullUp.prototype.handleBScroll = function () {
  3148. this.scroll.registerType([PULL_UP_HOOKS_NAME]);
  3149. this.scroll.proxy(propertiesConfig$5);
  3150. };
  3151. PullUp.prototype.handleOptions = function (userOptions) {
  3152. if (userOptions === void 0) { userOptions = {}; }
  3153. userOptions = (userOptions === true ? {} : userOptions);
  3154. var defaultOptions = {
  3155. threshold: 0,
  3156. };
  3157. this.options = extend(defaultOptions, userOptions);
  3158. this.scroll.options.probeType = 3 /* Realtime */;
  3159. };
  3160. PullUp.prototype.handleHooks = function () {
  3161. var _this = this;
  3162. this.hooksFn = [];
  3163. var scrollBehaviorY = this.scroll.scroller.scrollBehaviorY;
  3164. this.registerHooks(this.scroll.hooks, this.scroll.hooks.eventTypes.contentChanged, function () {
  3165. _this.finishPullUp();
  3166. });
  3167. this.registerHooks(scrollBehaviorY.hooks, scrollBehaviorY.hooks.eventTypes.computeBoundary, function (boundary) {
  3168. // content is smaller than wrapper
  3169. if (boundary.maxScrollPos > 0) {
  3170. // allow scrolling when content is not full of wrapper
  3171. boundary.maxScrollPos = -1;
  3172. }
  3173. });
  3174. };
  3175. PullUp.prototype.registerHooks = function (hooks, name, handler) {
  3176. hooks.on(name, handler, this);
  3177. this.hooksFn.push([hooks, name, handler]);
  3178. };
  3179. PullUp.prototype.watch = function () {
  3180. if (this.watching) {
  3181. return;
  3182. }
  3183. this.watching = true;
  3184. this.registerHooks(this.scroll, this.scroll.eventTypes.scroll, this.checkPullUp);
  3185. };
  3186. PullUp.prototype.unwatch = function () {
  3187. this.watching = false;
  3188. this.scroll.off(this.scroll.eventTypes.scroll, this.checkPullUp);
  3189. };
  3190. PullUp.prototype.checkPullUp = function (pos) {
  3191. var _this = this;
  3192. var threshold = this.options.threshold;
  3193. if (this.scroll.movingDirectionY === 1 /* Positive */ &&
  3194. pos.y <= this.scroll.maxScrollY + threshold) {
  3195. this.pulling = true;
  3196. // must reset pulling after scrollEnd
  3197. this.scroll.once(this.scroll.eventTypes.scrollEnd, function () {
  3198. _this.pulling = false;
  3199. });
  3200. this.unwatch();
  3201. this.scroll.trigger(PULL_UP_HOOKS_NAME);
  3202. }
  3203. };
  3204. PullUp.prototype.finishPullUp = function () {
  3205. var _this = this;
  3206. // reset Direction, fix #936
  3207. this.scroll.scroller.scrollBehaviorY.setMovingDirection(0 /* Default */);
  3208. if (this.pulling) {
  3209. this.scroll.once(this.scroll.eventTypes.scrollEnd, function () {
  3210. _this.watch();
  3211. });
  3212. }
  3213. else {
  3214. this.watch();
  3215. }
  3216. };
  3217. // allow 'true' type is compat for beta version implements
  3218. PullUp.prototype.openPullUp = function (config) {
  3219. if (config === void 0) { config = {}; }
  3220. this.handleOptions(config);
  3221. this.watch();
  3222. };
  3223. PullUp.prototype.closePullUp = function () {
  3224. this.unwatch();
  3225. };
  3226. PullUp.prototype.autoPullUpLoad = function () {
  3227. var threshold = this.options.threshold;
  3228. var scrollBehaviorY = this.scroll.scroller.scrollBehaviorY;
  3229. if (this.pulling || !this.watching) {
  3230. return;
  3231. }
  3232. // simulate a pullUp action
  3233. var NEGATIVE_VALUE = -1;
  3234. var outOfBoundaryPos = scrollBehaviorY.maxScrollPos + threshold + NEGATIVE_VALUE;
  3235. this.scroll.scroller.scrollBehaviorY.setMovingDirection(NEGATIVE_VALUE);
  3236. this.scroll.scrollTo(this.scroll.x, outOfBoundaryPos, this.scroll.options.bounceTime);
  3237. };
  3238. PullUp.pluginName = 'pullUpLoad';
  3239. return PullUp;
  3240. }());
  3241. var EventHandler = /** @class */ (function () {
  3242. function EventHandler(indicator, options) {
  3243. this.indicator = indicator;
  3244. this.options = options;
  3245. this.hooks = new EventEmitter(['touchStart', 'touchMove', 'touchEnd']);
  3246. this.registerEvents();
  3247. }
  3248. EventHandler.prototype.registerEvents = function () {
  3249. var _a = this.options, disableMouse = _a.disableMouse, disableTouch = _a.disableTouch;
  3250. var startEvents = [];
  3251. var moveEvents = [];
  3252. var endEvents = [];
  3253. if (!disableMouse) {
  3254. startEvents.push({
  3255. name: 'mousedown',
  3256. handler: this.start.bind(this),
  3257. });
  3258. moveEvents.push({
  3259. name: 'mousemove',
  3260. handler: this.move.bind(this),
  3261. });
  3262. endEvents.push({
  3263. name: 'mouseup',
  3264. handler: this.end.bind(this),
  3265. });
  3266. }
  3267. if (!disableTouch) {
  3268. startEvents.push({
  3269. name: 'touchstart',
  3270. handler: this.start.bind(this),
  3271. });
  3272. moveEvents.push({
  3273. name: 'touchmove',
  3274. handler: this.move.bind(this),
  3275. });
  3276. endEvents.push({
  3277. name: 'touchend',
  3278. handler: this.end.bind(this),
  3279. }, {
  3280. name: 'touchcancel',
  3281. handler: this.end.bind(this),
  3282. });
  3283. }
  3284. this.startEventRegister = new EventRegister(this.indicator.indicatorEl, startEvents);
  3285. this.moveEventRegister = new EventRegister(window, moveEvents);
  3286. this.endEventRegister = new EventRegister(window, endEvents);
  3287. };
  3288. EventHandler.prototype.BScrollIsDisabled = function () {
  3289. return !this.indicator.scroll.enabled;
  3290. };
  3291. EventHandler.prototype.start = function (e) {
  3292. if (this.BScrollIsDisabled()) {
  3293. return;
  3294. }
  3295. var point = (e.touches ? e.touches[0] : e);
  3296. e.preventDefault();
  3297. e.stopPropagation();
  3298. this.initiated = true;
  3299. this.lastPoint = point[this.indicator.keysMap.point];
  3300. this.hooks.trigger(this.hooks.eventTypes.touchStart);
  3301. };
  3302. EventHandler.prototype.move = function (e) {
  3303. if (!this.initiated) {
  3304. return;
  3305. }
  3306. var point = (e.touches ? e.touches[0] : e);
  3307. var pointPos = point[this.indicator.keysMap.point];
  3308. e.preventDefault();
  3309. e.stopPropagation();
  3310. var delta = pointPos - this.lastPoint;
  3311. this.lastPoint = pointPos;
  3312. this.hooks.trigger(this.hooks.eventTypes.touchMove, delta);
  3313. };
  3314. EventHandler.prototype.end = function (e) {
  3315. if (!this.initiated) {
  3316. return;
  3317. }
  3318. this.initiated = false;
  3319. e.preventDefault();
  3320. e.stopPropagation();
  3321. this.hooks.trigger(this.hooks.eventTypes.touchEnd);
  3322. };
  3323. EventHandler.prototype.destroy = function () {
  3324. this.startEventRegister.destroy();
  3325. this.moveEventRegister.destroy();
  3326. this.endEventRegister.destroy();
  3327. };
  3328. return EventHandler;
  3329. }());
  3330. var Indicator$1 = /** @class */ (function () {
  3331. function Indicator(scroll, options) {
  3332. this.scroll = scroll;
  3333. this.options = options;
  3334. this.hooksFn = [];
  3335. this.wrapper = options.wrapper;
  3336. this.direction = options.direction;
  3337. this.indicatorEl = this.wrapper.children[0];
  3338. this.keysMap = this.getKeysMap();
  3339. this.handleFade();
  3340. this.handleHooks();
  3341. }
  3342. Indicator.prototype.handleFade = function () {
  3343. if (this.options.fade) {
  3344. this.wrapper.style.opacity = '0';
  3345. }
  3346. };
  3347. Indicator.prototype.handleHooks = function () {
  3348. var _this = this;
  3349. var _a = this.options, fade = _a.fade, interactive = _a.interactive, scrollbarTrackClickable = _a.scrollbarTrackClickable;
  3350. var scroll = this.scroll;
  3351. var scrollHooks = scroll.hooks;
  3352. var translaterHooks = scroll.scroller.translater.hooks;
  3353. var animaterHooks = scroll.scroller.animater.hooks;
  3354. this.registerHooks(scrollHooks, scrollHooks.eventTypes.refresh, this.refresh);
  3355. this.registerHooks(translaterHooks, translaterHooks.eventTypes.translate, function (pos) {
  3356. var hasScrollKey = _this.keysMap.hasScroll;
  3357. if (_this.scroll[hasScrollKey]) {
  3358. _this.updatePosition(pos);
  3359. }
  3360. });
  3361. this.registerHooks(animaterHooks, animaterHooks.eventTypes.time, this.transitionTime);
  3362. this.registerHooks(animaterHooks, animaterHooks.eventTypes.timeFunction, this.transitionTimingFunction);
  3363. if (fade) {
  3364. this.registerHooks(scroll, scroll.eventTypes.scrollEnd, function () {
  3365. _this.fade();
  3366. });
  3367. this.registerHooks(scroll, scroll.eventTypes.scrollStart, function () {
  3368. _this.fade(true);
  3369. });
  3370. // for mousewheel event
  3371. if (scroll.eventTypes.mousewheelStart &&
  3372. scroll.eventTypes.mousewheelEnd) {
  3373. this.registerHooks(scroll, scroll.eventTypes.mousewheelStart, function () {
  3374. _this.fade(true);
  3375. });
  3376. this.registerHooks(scroll, scroll.eventTypes.mousewheelMove, function () {
  3377. _this.fade(true);
  3378. });
  3379. this.registerHooks(scroll, scroll.eventTypes.mousewheelEnd, function () {
  3380. _this.fade();
  3381. });
  3382. }
  3383. }
  3384. if (interactive) {
  3385. var _b = this.scroll.options, disableMouse = _b.disableMouse, disableTouch = _b.disableTouch;
  3386. this.eventHandler = new EventHandler(this, {
  3387. disableMouse: disableMouse,
  3388. disableTouch: disableTouch,
  3389. });
  3390. var eventHandlerHooks = this.eventHandler.hooks;
  3391. this.registerHooks(eventHandlerHooks, eventHandlerHooks.eventTypes.touchStart, this.startHandler);
  3392. this.registerHooks(eventHandlerHooks, eventHandlerHooks.eventTypes.touchMove, this.moveHandler);
  3393. this.registerHooks(eventHandlerHooks, eventHandlerHooks.eventTypes.touchEnd, this.endHandler);
  3394. }
  3395. if (scrollbarTrackClickable) {
  3396. this.bindClick();
  3397. }
  3398. };
  3399. Indicator.prototype.registerHooks = function (hooks, name, handler) {
  3400. hooks.on(name, handler, this);
  3401. this.hooksFn.push([hooks, name, handler]);
  3402. };
  3403. Indicator.prototype.bindClick = function () {
  3404. var wrapper = this.wrapper;
  3405. this.clickEventRegister = new EventRegister(wrapper, [
  3406. {
  3407. name: 'click',
  3408. handler: this.handleClick.bind(this),
  3409. },
  3410. ]);
  3411. };
  3412. Indicator.prototype.handleClick = function (e) {
  3413. var newPos = this.calculateclickOffsetPos(e);
  3414. var _a = this.scroll, x = _a.x, y = _a.y;
  3415. x = this.direction === "horizontal" /* Horizontal */ ? newPos : x;
  3416. y = this.direction === "vertical" /* Vertical */ ? newPos : y;
  3417. this.scroll.scrollTo(x, y, this.options.scrollbarTrackOffsetTime);
  3418. };
  3419. Indicator.prototype.calculateclickOffsetPos = function (e) {
  3420. var _a = this.keysMap, poinKey = _a.point, domRectKey = _a.domRect;
  3421. var scrollbarTrackOffsetType = this.options.scrollbarTrackOffsetType;
  3422. var clickPointOffset = e[poinKey] - this.wrapperRect[domRectKey];
  3423. var scrollToWhere = clickPointOffset < this.currentPos ? -1 /* Up */ : 1 /* Down */;
  3424. var delta = 0;
  3425. var currentPos = this.currentPos;
  3426. if (scrollbarTrackOffsetType === "step" /* Step */) {
  3427. delta = this.scrollInfo.baseSize * scrollToWhere;
  3428. }
  3429. else {
  3430. delta = 0;
  3431. currentPos = clickPointOffset;
  3432. }
  3433. return this.newPos(currentPos, delta, this.scrollInfo);
  3434. };
  3435. Indicator.prototype.getKeysMap = function () {
  3436. if (this.direction === "vertical" /* Vertical */) {
  3437. return {
  3438. hasScroll: 'hasVerticalScroll',
  3439. size: 'height',
  3440. wrapperSize: 'clientHeight',
  3441. scrollerSize: 'scrollerHeight',
  3442. maxScrollPos: 'maxScrollY',
  3443. pos: 'y',
  3444. point: 'pageY',
  3445. translateProperty: 'translateY',
  3446. domRect: 'top',
  3447. };
  3448. }
  3449. return {
  3450. hasScroll: 'hasHorizontalScroll',
  3451. size: 'width',
  3452. wrapperSize: 'clientWidth',
  3453. scrollerSize: 'scrollerWidth',
  3454. maxScrollPos: 'maxScrollX',
  3455. pos: 'x',
  3456. point: 'pageX',
  3457. translateProperty: 'translateX',
  3458. domRect: 'left',
  3459. };
  3460. };
  3461. Indicator.prototype.fade = function (visible) {
  3462. var _a = this.options, fadeInTime = _a.fadeInTime, fadeOutTime = _a.fadeOutTime;
  3463. var time = visible ? fadeInTime : fadeOutTime;
  3464. var wrapper = this.wrapper;
  3465. wrapper.style[style.transitionDuration] = time + 'ms';
  3466. wrapper.style.opacity = visible ? '1' : '0';
  3467. };
  3468. Indicator.prototype.refresh = function () {
  3469. var hasScrollKey = this.keysMap.hasScroll;
  3470. var scroll = this.scroll;
  3471. var x = scroll.x, y = scroll.y;
  3472. this.wrapperRect = this.wrapper.getBoundingClientRect();
  3473. if (this.canScroll(scroll[hasScrollKey])) {
  3474. var _a = this.keysMap, wrapperSizeKey = _a.wrapperSize, scrollerSizeKey = _a.scrollerSize, maxScrollPosKey = _a.maxScrollPos;
  3475. this.scrollInfo = this.refreshScrollInfo(this.wrapper[wrapperSizeKey], scroll[scrollerSizeKey], scroll[maxScrollPosKey], this.indicatorEl[wrapperSizeKey]);
  3476. this.updatePosition({
  3477. x: x,
  3478. y: y,
  3479. });
  3480. }
  3481. };
  3482. Indicator.prototype.transitionTime = function (time) {
  3483. if (time === void 0) { time = 0; }
  3484. this.indicatorEl.style[style.transitionDuration] = time + 'ms';
  3485. };
  3486. Indicator.prototype.transitionTimingFunction = function (easing) {
  3487. this.indicatorEl.style[style.transitionTimingFunction] = easing;
  3488. };
  3489. Indicator.prototype.canScroll = function (hasScroll) {
  3490. this.wrapper.style.display = hasScroll ? 'block' : 'none';
  3491. return hasScroll;
  3492. };
  3493. Indicator.prototype.refreshScrollInfo = function (wrapperSize, scrollerSize, maxScrollPos, indicatorElSize) {
  3494. var baseSize = Math.max(Math.round((wrapperSize * wrapperSize) / (scrollerSize || wrapperSize || 1)), this.options.minSize);
  3495. if (this.options.isCustom) {
  3496. baseSize = indicatorElSize;
  3497. }
  3498. var maxIndicatorScrollPos = wrapperSize - baseSize;
  3499. // sizeRatio is negative
  3500. var sizeRatio = maxIndicatorScrollPos / maxScrollPos;
  3501. return {
  3502. baseSize: baseSize,
  3503. maxScrollPos: maxIndicatorScrollPos,
  3504. minScrollPos: 0,
  3505. sizeRatio: sizeRatio,
  3506. };
  3507. };
  3508. Indicator.prototype.updatePosition = function (point) {
  3509. var _a = this.caculatePosAndSize(point, this.scrollInfo), pos = _a.pos, size = _a.size;
  3510. this.refreshStyle(size, pos);
  3511. this.currentPos = pos;
  3512. };
  3513. Indicator.prototype.caculatePosAndSize = function (point, scrollInfo) {
  3514. var posKey = this.keysMap.pos;
  3515. var sizeRatio = scrollInfo.sizeRatio, baseSize = scrollInfo.baseSize, maxScrollPos = scrollInfo.maxScrollPos, minScrollPos = scrollInfo.minScrollPos;
  3516. var minSize = this.options.minSize;
  3517. var pos = Math.round(sizeRatio * point[posKey]);
  3518. var size;
  3519. // when out of boundary, slow down size reduction
  3520. if (pos < minScrollPos) {
  3521. size = Math.max(baseSize + pos * 3, minSize);
  3522. pos = minScrollPos;
  3523. }
  3524. else if (pos > maxScrollPos) {
  3525. size = Math.max(baseSize - (pos - maxScrollPos) * 3, minSize);
  3526. pos = maxScrollPos + baseSize - size;
  3527. }
  3528. else {
  3529. size = baseSize;
  3530. }
  3531. return {
  3532. pos: pos,
  3533. size: size,
  3534. };
  3535. };
  3536. Indicator.prototype.refreshStyle = function (size, pos) {
  3537. var _a = this.keysMap, translatePropertyKey = _a.translateProperty, sizeKey = _a.size;
  3538. var translateZ = this.scroll.options.translateZ;
  3539. this.indicatorEl.style[sizeKey] = size + "px";
  3540. this.indicatorEl.style[style.transform] = translatePropertyKey + "(" + pos + "px)" + translateZ;
  3541. };
  3542. Indicator.prototype.startHandler = function () {
  3543. this.moved = false;
  3544. this.startTime = getNow();
  3545. this.transitionTime();
  3546. this.scroll.scroller.hooks.trigger(this.scroll.scroller.hooks.eventTypes.beforeScrollStart);
  3547. };
  3548. Indicator.prototype.moveHandler = function (delta) {
  3549. if (!this.moved && !this.indicatorNotMoved(delta)) {
  3550. this.moved = true;
  3551. this.scroll.scroller.hooks.trigger(this.scroll.scroller.hooks.eventTypes.scrollStart);
  3552. }
  3553. if (this.moved) {
  3554. var newPos = this.newPos(this.currentPos, delta, this.scrollInfo);
  3555. this.syncBScroll(newPos);
  3556. }
  3557. };
  3558. Indicator.prototype.endHandler = function () {
  3559. if (this.moved) {
  3560. var _a = this.scroll, x = _a.x, y = _a.y;
  3561. this.scroll.scroller.hooks.trigger(this.scroll.scroller.hooks.eventTypes.scrollEnd, {
  3562. x: x,
  3563. y: y,
  3564. });
  3565. }
  3566. };
  3567. Indicator.prototype.indicatorNotMoved = function (delta) {
  3568. var currentPos = this.currentPos;
  3569. var _a = this.scrollInfo, maxScrollPos = _a.maxScrollPos, minScrollPos = _a.minScrollPos;
  3570. var notMoved = (currentPos === minScrollPos && delta <= 0) ||
  3571. (currentPos === maxScrollPos && delta >= 0);
  3572. return notMoved;
  3573. };
  3574. Indicator.prototype.syncBScroll = function (newPos) {
  3575. var timestamp = getNow();
  3576. var _a = this.scroll, x = _a.x, y = _a.y, options = _a.options, scroller = _a.scroller, maxScrollY = _a.maxScrollY, minScrollY = _a.minScrollY, maxScrollX = _a.maxScrollX, minScrollX = _a.minScrollX;
  3577. var probeType = options.probeType, momentumLimitTime = options.momentumLimitTime;
  3578. var position = { x: x, y: y };
  3579. if (this.direction === "vertical" /* Vertical */) {
  3580. position.y = between(newPos, maxScrollY, minScrollY);
  3581. }
  3582. else {
  3583. position.x = between(newPos, maxScrollX, minScrollX);
  3584. }
  3585. scroller.translater.translate(position);
  3586. // dispatch scroll in interval time
  3587. if (timestamp - this.startTime > momentumLimitTime) {
  3588. this.startTime = timestamp;
  3589. if (probeType === 1 /* Throttle */) {
  3590. scroller.hooks.trigger(scroller.hooks.eventTypes.scroll, position);
  3591. }
  3592. }
  3593. // dispatch scroll all the time
  3594. if (probeType > 1 /* Throttle */) {
  3595. scroller.hooks.trigger(scroller.hooks.eventTypes.scroll, position);
  3596. }
  3597. };
  3598. Indicator.prototype.newPos = function (currentPos, delta, scrollInfo) {
  3599. var maxScrollPos = scrollInfo.maxScrollPos, sizeRatio = scrollInfo.sizeRatio, minScrollPos = scrollInfo.minScrollPos;
  3600. var newPos = currentPos + delta;
  3601. newPos = between(newPos, minScrollPos, maxScrollPos);
  3602. return Math.round(newPos / sizeRatio);
  3603. };
  3604. Indicator.prototype.destroy = function () {
  3605. var _a = this.options, interactive = _a.interactive, scrollbarTrackClickable = _a.scrollbarTrackClickable, isCustom = _a.isCustom;
  3606. if (interactive) {
  3607. this.eventHandler.destroy();
  3608. }
  3609. if (scrollbarTrackClickable) {
  3610. this.clickEventRegister.destroy();
  3611. }
  3612. if (!isCustom) {
  3613. this.wrapper.parentNode.removeChild(this.wrapper);
  3614. }
  3615. this.hooksFn.forEach(function (item) {
  3616. var hooks = item[0];
  3617. var hooksName = item[1];
  3618. var handlerFn = item[2];
  3619. hooks.off(hooksName, handlerFn);
  3620. });
  3621. this.hooksFn.length = 0;
  3622. };
  3623. return Indicator;
  3624. }());
  3625. var ScrollBar = /** @class */ (function () {
  3626. function ScrollBar(scroll) {
  3627. this.scroll = scroll;
  3628. this.handleOptions();
  3629. this.createIndicators();
  3630. this.handleHooks();
  3631. }
  3632. ScrollBar.prototype.handleHooks = function () {
  3633. var _this = this;
  3634. var scroll = this.scroll;
  3635. scroll.hooks.on(scroll.hooks.eventTypes.destroy, function () {
  3636. for (var _i = 0, _a = _this.indicators; _i < _a.length; _i++) {
  3637. var indicator = _a[_i];
  3638. indicator.destroy();
  3639. }
  3640. });
  3641. };
  3642. ScrollBar.prototype.handleOptions = function () {
  3643. var userOptions = (this.scroll.options.scrollbar === true
  3644. ? {}
  3645. : this.scroll.options.scrollbar);
  3646. var defaultOptions = {
  3647. fade: true,
  3648. fadeInTime: 250,
  3649. fadeOutTime: 500,
  3650. interactive: false,
  3651. customElements: [],
  3652. minSize: 8,
  3653. scrollbarTrackClickable: false,
  3654. scrollbarTrackOffsetType: "step" /* Step */,
  3655. scrollbarTrackOffsetTime: 300,
  3656. };
  3657. this.options = extend(defaultOptions, userOptions);
  3658. };
  3659. ScrollBar.prototype.createIndicators = function () {
  3660. var indicatorOptions;
  3661. var scroll = this.scroll;
  3662. var indicators = [];
  3663. var scrollDirectionConfigKeys = ['scrollX', 'scrollY'];
  3664. var indicatorDirections = [
  3665. "horizontal" /* Horizontal */,
  3666. "vertical" /* Vertical */,
  3667. ];
  3668. var customScrollbarEls = this.options.customElements;
  3669. for (var i = 0; i < scrollDirectionConfigKeys.length; i++) {
  3670. var key = scrollDirectionConfigKeys[i];
  3671. // wanna scroll in specified direction
  3672. if (scroll.options[key]) {
  3673. var customElement = customScrollbarEls.shift();
  3674. var direction = indicatorDirections[i];
  3675. var isCustom = false;
  3676. var scrollbarWrapper = customElement
  3677. ? customElement
  3678. : this.createScrollbarElement(direction);
  3679. // internal scrollbar
  3680. if (scrollbarWrapper !== customElement) {
  3681. scroll.wrapper.appendChild(scrollbarWrapper);
  3682. }
  3683. else {
  3684. // custom scrollbar passed by users
  3685. isCustom = true;
  3686. }
  3687. indicatorOptions = __assign(__assign({ wrapper: scrollbarWrapper, direction: direction }, this.options), { isCustom: isCustom });
  3688. indicators.push(new Indicator$1(scroll, indicatorOptions));
  3689. }
  3690. }
  3691. this.indicators = indicators;
  3692. };
  3693. ScrollBar.prototype.createScrollbarElement = function (direction, scrollbarTrackClickable) {
  3694. if (scrollbarTrackClickable === void 0) { scrollbarTrackClickable = this.options.scrollbarTrackClickable; }
  3695. var scrollbarWrapperEl = document.createElement('div');
  3696. var scrollbarIndicatorEl = document.createElement('div');
  3697. scrollbarWrapperEl.style.cssText =
  3698. 'position:absolute;z-index:9999;overflow:hidden;';
  3699. scrollbarIndicatorEl.style.cssText =
  3700. 'box-sizing:border-box;position:absolute;background:rgba(0,0,0,0.5);border:1px solid rgba(255,255,255,0.9);border-radius:3px;';
  3701. scrollbarIndicatorEl.className = 'bscroll-indicator';
  3702. if (direction === "horizontal" /* Horizontal */) {
  3703. scrollbarWrapperEl.style.cssText +=
  3704. 'height:7px;left:2px;right:2px;bottom:0;';
  3705. scrollbarIndicatorEl.style.height = '100%';
  3706. scrollbarWrapperEl.className = 'bscroll-horizontal-scrollbar';
  3707. }
  3708. else {
  3709. scrollbarWrapperEl.style.cssText +=
  3710. 'width:7px;bottom:2px;top:2px;right:1px;';
  3711. scrollbarIndicatorEl.style.width = '100%';
  3712. scrollbarWrapperEl.className = 'bscroll-vertical-scrollbar';
  3713. }
  3714. if (!scrollbarTrackClickable) {
  3715. scrollbarWrapperEl.style.cssText += 'pointer-events:none;';
  3716. }
  3717. scrollbarWrapperEl.appendChild(scrollbarIndicatorEl);
  3718. return scrollbarWrapperEl;
  3719. };
  3720. ScrollBar.pluginName = 'scrollbar';
  3721. return ScrollBar;
  3722. }());
  3723. var PagesMatrix = /** @class */ (function () {
  3724. function PagesMatrix(scroll) {
  3725. this.scroll = scroll;
  3726. this.init();
  3727. }
  3728. PagesMatrix.prototype.init = function () {
  3729. var scroller = this.scroll.scroller;
  3730. var scrollBehaviorX = scroller.scrollBehaviorX, scrollBehaviorY = scroller.scrollBehaviorY;
  3731. this.wrapperWidth = scrollBehaviorX.wrapperSize;
  3732. this.wrapperHeight = scrollBehaviorY.wrapperSize;
  3733. this.scrollerHeight = scrollBehaviorY.contentSize;
  3734. this.scrollerWidth = scrollBehaviorX.contentSize;
  3735. this.pages = this.buildPagesMatrix(this.wrapperWidth, this.wrapperHeight);
  3736. this.pageLengthOfX = this.pages ? this.pages.length : 0;
  3737. this.pageLengthOfY = this.pages && this.pages[0] ? this.pages[0].length : 0;
  3738. };
  3739. PagesMatrix.prototype.getPageStats = function (pageX, pageY) {
  3740. return this.pages[pageX][pageY];
  3741. };
  3742. PagesMatrix.prototype.getNearestPageIndex = function (x, y) {
  3743. var pageX = 0;
  3744. var pageY = 0;
  3745. var l = this.pages.length;
  3746. for (; pageX < l - 1; pageX++) {
  3747. if (x >= this.pages[pageX][0].cx) {
  3748. break;
  3749. }
  3750. }
  3751. l = this.pages[pageX].length;
  3752. for (; pageY < l - 1; pageY++) {
  3753. if (y >= this.pages[0][pageY].cy) {
  3754. break;
  3755. }
  3756. }
  3757. return {
  3758. pageX: pageX,
  3759. pageY: pageY,
  3760. };
  3761. };
  3762. // (n x 1) matrix for horizontal scroll or
  3763. // (1 * n) matrix for vertical scroll
  3764. PagesMatrix.prototype.buildPagesMatrix = function (stepX, stepY) {
  3765. var pages = [];
  3766. var x = 0;
  3767. var y;
  3768. var cx;
  3769. var cy;
  3770. var i = 0;
  3771. var l;
  3772. var maxScrollPosX = this.scroll.scroller.scrollBehaviorX.maxScrollPos;
  3773. var maxScrollPosY = this.scroll.scroller.scrollBehaviorY.maxScrollPos;
  3774. cx = Math.round(stepX / 2);
  3775. cy = Math.round(stepY / 2);
  3776. while (x > -this.scrollerWidth) {
  3777. pages[i] = [];
  3778. l = 0;
  3779. y = 0;
  3780. while (y > -this.scrollerHeight) {
  3781. pages[i][l] = {
  3782. x: Math.max(x, maxScrollPosX),
  3783. y: Math.max(y, maxScrollPosY),
  3784. width: stepX,
  3785. height: stepY,
  3786. cx: x - cx,
  3787. cy: y - cy,
  3788. };
  3789. y -= stepY;
  3790. l++;
  3791. }
  3792. x -= stepX;
  3793. i++;
  3794. }
  3795. return pages;
  3796. };
  3797. return PagesMatrix;
  3798. }());
  3799. var BASE_PAGE = {
  3800. pageX: 0,
  3801. pageY: 0,
  3802. x: 0,
  3803. y: 0,
  3804. };
  3805. var SlidePages = /** @class */ (function () {
  3806. function SlidePages(scroll, slideOptions) {
  3807. this.scroll = scroll;
  3808. this.slideOptions = slideOptions;
  3809. this.slideX = false;
  3810. this.slideY = false;
  3811. this.currentPage = extend({}, BASE_PAGE);
  3812. }
  3813. SlidePages.prototype.refresh = function () {
  3814. this.pagesMatrix = new PagesMatrix(this.scroll);
  3815. this.checkSlideLoop();
  3816. this.currentPage = this.getAdjustedCurrentPage();
  3817. };
  3818. SlidePages.prototype.getAdjustedCurrentPage = function () {
  3819. var _a = this.currentPage, pageX = _a.pageX, pageY = _a.pageY;
  3820. // page index should be handled
  3821. // because page counts may reduce
  3822. pageX = Math.min(pageX, this.pagesMatrix.pageLengthOfX - 1);
  3823. pageY = Math.min(pageY, this.pagesMatrix.pageLengthOfY - 1);
  3824. // loop scene should also be respected
  3825. // because clonedNode will cause pageLength increasing
  3826. if (this.loopX) {
  3827. pageX = Math.min(pageX, this.pagesMatrix.pageLengthOfX - 2);
  3828. }
  3829. if (this.loopY) {
  3830. pageY = Math.min(pageY, this.pagesMatrix.pageLengthOfY - 2);
  3831. }
  3832. var _b = this.pagesMatrix.getPageStats(pageX, pageY), x = _b.x, y = _b.y;
  3833. return { pageX: pageX, pageY: pageY, x: x, y: y };
  3834. };
  3835. SlidePages.prototype.setCurrentPage = function (newPage) {
  3836. this.currentPage = newPage;
  3837. };
  3838. SlidePages.prototype.getInternalPage = function (pageX, pageY) {
  3839. if (pageX >= this.pagesMatrix.pageLengthOfX) {
  3840. pageX = this.pagesMatrix.pageLengthOfX - 1;
  3841. }
  3842. else if (pageX < 0) {
  3843. pageX = 0;
  3844. }
  3845. if (pageY >= this.pagesMatrix.pageLengthOfY) {
  3846. pageY = this.pagesMatrix.pageLengthOfY - 1;
  3847. }
  3848. else if (pageY < 0) {
  3849. pageY = 0;
  3850. }
  3851. var _a = this.pagesMatrix.getPageStats(pageX, pageY), x = _a.x, y = _a.y;
  3852. return {
  3853. pageX: pageX,
  3854. pageY: pageY,
  3855. x: x,
  3856. y: y,
  3857. };
  3858. };
  3859. SlidePages.prototype.getInitialPage = function (showFirstPage, firstInitialised) {
  3860. if (showFirstPage === void 0) { showFirstPage = false; }
  3861. if (firstInitialised === void 0) { firstInitialised = false; }
  3862. var _a = this.slideOptions, startPageXIndex = _a.startPageXIndex, startPageYIndex = _a.startPageYIndex;
  3863. var firstPageX = this.loopX ? 1 : 0;
  3864. var firstPageY = this.loopY ? 1 : 0;
  3865. var pageX = showFirstPage ? firstPageX : this.currentPage.pageX;
  3866. var pageY = showFirstPage ? firstPageY : this.currentPage.pageY;
  3867. if (firstInitialised) {
  3868. pageX = this.loopX ? startPageXIndex + 1 : startPageXIndex;
  3869. pageY = this.loopY ? startPageYIndex + 1 : startPageYIndex;
  3870. }
  3871. else {
  3872. pageX = showFirstPage ? firstPageX : this.currentPage.pageX;
  3873. pageY = showFirstPage ? firstPageY : this.currentPage.pageY;
  3874. }
  3875. var _b = this.pagesMatrix.getPageStats(pageX, pageY), x = _b.x, y = _b.y;
  3876. return {
  3877. pageX: pageX,
  3878. pageY: pageY,
  3879. x: x,
  3880. y: y,
  3881. };
  3882. };
  3883. SlidePages.prototype.getExposedPage = function (page) {
  3884. var exposedPage = extend({}, page);
  3885. // only pageX or pageY need fix
  3886. if (this.loopX) {
  3887. exposedPage.pageX = this.fixedPage(exposedPage.pageX, this.pagesMatrix.pageLengthOfX - 2);
  3888. }
  3889. if (this.loopY) {
  3890. exposedPage.pageY = this.fixedPage(exposedPage.pageY, this.pagesMatrix.pageLengthOfY - 2);
  3891. }
  3892. return exposedPage;
  3893. };
  3894. SlidePages.prototype.getExposedPageByPageIndex = function (pageIndexX, pageIndexY) {
  3895. var page = {
  3896. pageX: pageIndexX,
  3897. pageY: pageIndexY,
  3898. };
  3899. if (this.loopX) {
  3900. page.pageX = pageIndexX + 1;
  3901. }
  3902. if (this.loopY) {
  3903. page.pageY = pageIndexY + 1;
  3904. }
  3905. var _a = this.pagesMatrix.getPageStats(page.pageX, page.pageY), x = _a.x, y = _a.y;
  3906. return {
  3907. x: x,
  3908. y: y,
  3909. pageX: pageIndexX,
  3910. pageY: pageIndexY,
  3911. };
  3912. };
  3913. SlidePages.prototype.getWillChangedPage = function (page) {
  3914. page = extend({}, page);
  3915. // Page need fix
  3916. if (this.loopX) {
  3917. page.pageX = this.fixedPage(page.pageX, this.pagesMatrix.pageLengthOfX - 2);
  3918. page.x = this.pagesMatrix.getPageStats(page.pageX + 1, 0).x;
  3919. }
  3920. if (this.loopY) {
  3921. page.pageY = this.fixedPage(page.pageY, this.pagesMatrix.pageLengthOfY - 2);
  3922. page.y = this.pagesMatrix.getPageStats(0, page.pageY + 1).y;
  3923. }
  3924. return page;
  3925. };
  3926. SlidePages.prototype.fixedPage = function (page, realPageLen) {
  3927. var pageIndex = [];
  3928. for (var i = 0; i < realPageLen; i++) {
  3929. pageIndex.push(i);
  3930. }
  3931. pageIndex.unshift(realPageLen - 1);
  3932. pageIndex.push(0);
  3933. return pageIndex[page];
  3934. };
  3935. SlidePages.prototype.getPageStats = function () {
  3936. return this.pagesMatrix.getPageStats(this.currentPage.pageX, this.currentPage.pageY);
  3937. };
  3938. SlidePages.prototype.getValidPageIndex = function (x, y) {
  3939. var lastX = this.pagesMatrix.pageLengthOfX - 1;
  3940. var lastY = this.pagesMatrix.pageLengthOfY - 1;
  3941. var firstX = 0;
  3942. var firstY = 0;
  3943. if (this.loopX) {
  3944. x += 1;
  3945. firstX = firstX + 1;
  3946. lastX = lastX - 1;
  3947. }
  3948. if (this.loopY) {
  3949. y += 1;
  3950. firstY = firstY + 1;
  3951. lastY = lastY - 1;
  3952. }
  3953. x = between(x, firstX, lastX);
  3954. y = between(y, firstY, lastY);
  3955. return {
  3956. pageX: x,
  3957. pageY: y,
  3958. };
  3959. };
  3960. SlidePages.prototype.nextPageIndex = function () {
  3961. return this.getPageIndexByDirection("positive" /* Positive */);
  3962. };
  3963. SlidePages.prototype.prevPageIndex = function () {
  3964. return this.getPageIndexByDirection("negative" /* Negative */);
  3965. };
  3966. SlidePages.prototype.getNearestPage = function (x, y) {
  3967. var pageIndex = this.pagesMatrix.getNearestPageIndex(x, y);
  3968. var pageX = pageIndex.pageX, pageY = pageIndex.pageY;
  3969. var newX = this.pagesMatrix.getPageStats(pageX, 0).x;
  3970. var newY = this.pagesMatrix.getPageStats(0, pageY).y;
  3971. return {
  3972. x: newX,
  3973. y: newY,
  3974. pageX: pageX,
  3975. pageY: pageY,
  3976. };
  3977. };
  3978. SlidePages.prototype.getPageByDirection = function (page, directionX, directionY) {
  3979. var pageX = page.pageX, pageY = page.pageY;
  3980. if (pageX === this.currentPage.pageX) {
  3981. pageX = between(pageX + directionX, 0, this.pagesMatrix.pageLengthOfX - 1);
  3982. }
  3983. if (pageY === this.currentPage.pageY) {
  3984. pageY = between(pageY + directionY, 0, this.pagesMatrix.pageLengthOfY - 1);
  3985. }
  3986. var x = this.pagesMatrix.getPageStats(pageX, 0).x;
  3987. var y = this.pagesMatrix.getPageStats(0, pageY).y;
  3988. return {
  3989. x: x,
  3990. y: y,
  3991. pageX: pageX,
  3992. pageY: pageY,
  3993. };
  3994. };
  3995. SlidePages.prototype.resetLoopPage = function () {
  3996. if (this.loopX) {
  3997. if (this.currentPage.pageX === 0) {
  3998. return {
  3999. pageX: this.pagesMatrix.pageLengthOfX - 2,
  4000. pageY: this.currentPage.pageY,
  4001. };
  4002. }
  4003. if (this.currentPage.pageX === this.pagesMatrix.pageLengthOfX - 1) {
  4004. return {
  4005. pageX: 1,
  4006. pageY: this.currentPage.pageY,
  4007. };
  4008. }
  4009. }
  4010. if (this.loopY) {
  4011. if (this.currentPage.pageY === 0) {
  4012. return {
  4013. pageX: this.currentPage.pageX,
  4014. pageY: this.pagesMatrix.pageLengthOfY - 2,
  4015. };
  4016. }
  4017. if (this.currentPage.pageY === this.pagesMatrix.pageLengthOfY - 1) {
  4018. return {
  4019. pageX: this.currentPage.pageX,
  4020. pageY: 1,
  4021. };
  4022. }
  4023. }
  4024. };
  4025. SlidePages.prototype.getPageIndexByDirection = function (direction) {
  4026. var x = this.currentPage.pageX;
  4027. var y = this.currentPage.pageY;
  4028. if (this.slideX) {
  4029. x = direction === "negative" /* Negative */ ? x - 1 : x + 1;
  4030. }
  4031. if (this.slideY) {
  4032. y = direction === "negative" /* Negative */ ? y - 1 : y + 1;
  4033. }
  4034. return {
  4035. pageX: x,
  4036. pageY: y,
  4037. };
  4038. };
  4039. SlidePages.prototype.checkSlideLoop = function () {
  4040. this.wannaLoop = this.slideOptions.loop;
  4041. if (this.pagesMatrix.pageLengthOfX > 1) {
  4042. this.slideX = true;
  4043. }
  4044. else {
  4045. this.slideX = false;
  4046. }
  4047. if (this.pagesMatrix.pages[0] && this.pagesMatrix.pageLengthOfY > 1) {
  4048. this.slideY = true;
  4049. }
  4050. else {
  4051. this.slideY = false;
  4052. }
  4053. this.loopX = this.wannaLoop && this.slideX;
  4054. this.loopY = this.wannaLoop && this.slideY;
  4055. if (this.slideX && this.slideY) {
  4056. warn('slide does not support two direction at the same time.');
  4057. }
  4058. };
  4059. return SlidePages;
  4060. }());
  4061. var sourcePrefix$4 = 'plugins.slide';
  4062. var propertiesMap$4 = [
  4063. {
  4064. key: 'next',
  4065. name: 'next',
  4066. },
  4067. {
  4068. key: 'prev',
  4069. name: 'prev',
  4070. },
  4071. {
  4072. key: 'goToPage',
  4073. name: 'goToPage',
  4074. },
  4075. {
  4076. key: 'getCurrentPage',
  4077. name: 'getCurrentPage',
  4078. },
  4079. {
  4080. key: 'startPlay',
  4081. name: 'startPlay',
  4082. },
  4083. {
  4084. key: 'pausePlay',
  4085. name: 'pausePlay',
  4086. },
  4087. ];
  4088. var propertiesConfig$4 = propertiesMap$4.map(function (item) {
  4089. return {
  4090. key: item.key,
  4091. sourceKey: sourcePrefix$4 + "." + item.name,
  4092. };
  4093. });
  4094. var samePage = function (p1, p2) {
  4095. return p1.pageX === p2.pageX && p1.pageY === p2.pageY;
  4096. };
  4097. var Slide = /** @class */ (function () {
  4098. function Slide(scroll) {
  4099. this.scroll = scroll;
  4100. this.cachedClonedPageDOM = [];
  4101. this.resetLooping = false;
  4102. this.autoplayTimer = 0;
  4103. if (!this.satisfyInitialization()) {
  4104. return;
  4105. }
  4106. this.init();
  4107. }
  4108. Slide.prototype.satisfyInitialization = function () {
  4109. if (this.scroll.scroller.content.children.length <= 0) {
  4110. warn("slide need at least one slide page to be initialised." +
  4111. "please check your DOM layout.");
  4112. return false;
  4113. }
  4114. return true;
  4115. };
  4116. Slide.prototype.init = function () {
  4117. this.willChangeToPage = extend({}, BASE_PAGE);
  4118. this.handleBScroll();
  4119. this.handleOptions();
  4120. this.handleHooks();
  4121. this.createPages();
  4122. };
  4123. Slide.prototype.createPages = function () {
  4124. this.pages = new SlidePages(this.scroll, this.options);
  4125. };
  4126. Slide.prototype.handleBScroll = function () {
  4127. this.scroll.registerType(['slideWillChange', 'slidePageChanged']);
  4128. this.scroll.proxy(propertiesConfig$4);
  4129. };
  4130. Slide.prototype.handleOptions = function () {
  4131. var userOptions = (this.scroll.options.slide === true
  4132. ? {}
  4133. : this.scroll.options.slide);
  4134. var defaultOptions = {
  4135. loop: true,
  4136. threshold: 0.1,
  4137. speed: 400,
  4138. easing: ease.bounce,
  4139. listenFlick: true,
  4140. autoplay: true,
  4141. interval: 3000,
  4142. startPageXIndex: 0,
  4143. startPageYIndex: 0,
  4144. };
  4145. this.options = extend(defaultOptions, userOptions);
  4146. };
  4147. Slide.prototype.handleLoop = function (prevSlideContent) {
  4148. var loop = this.options.loop;
  4149. var slideContent = this.scroll.scroller.content;
  4150. var currentSlidePagesLength = slideContent.children.length;
  4151. // only should respect loop scene
  4152. if (loop) {
  4153. if (slideContent !== prevSlideContent) {
  4154. this.resetLoopChangedStatus();
  4155. this.removeClonedSlidePage(prevSlideContent);
  4156. currentSlidePagesLength > 1 &&
  4157. this.cloneFirstAndLastSlidePage(slideContent);
  4158. }
  4159. else {
  4160. // many pages reduce to one page
  4161. if (currentSlidePagesLength === 3 && this.initialised) {
  4162. this.removeClonedSlidePage(slideContent);
  4163. this.moreToOnePageInLoop = true;
  4164. this.oneToMorePagesInLoop = false;
  4165. }
  4166. else if (currentSlidePagesLength > 1) {
  4167. // one page increases to many page
  4168. if (this.initialised && this.cachedClonedPageDOM.length === 0) {
  4169. this.oneToMorePagesInLoop = true;
  4170. this.moreToOnePageInLoop = false;
  4171. }
  4172. else {
  4173. this.removeClonedSlidePage(slideContent);
  4174. this.resetLoopChangedStatus();
  4175. }
  4176. this.cloneFirstAndLastSlidePage(slideContent);
  4177. }
  4178. else {
  4179. this.resetLoopChangedStatus();
  4180. }
  4181. }
  4182. }
  4183. };
  4184. Slide.prototype.resetLoopChangedStatus = function () {
  4185. this.moreToOnePageInLoop = false;
  4186. this.oneToMorePagesInLoop = false;
  4187. };
  4188. Slide.prototype.handleHooks = function () {
  4189. var _this = this;
  4190. var scrollHooks = this.scroll.hooks;
  4191. var scrollerHooks = this.scroll.scroller.hooks;
  4192. var listenFlick = this.options.listenFlick;
  4193. this.prevContent = this.scroll.scroller.content;
  4194. this.hooksFn = [];
  4195. // scroll
  4196. this.registerHooks(this.scroll, this.scroll.eventTypes.beforeScrollStart, this.pausePlay);
  4197. this.registerHooks(this.scroll, this.scroll.eventTypes.scrollEnd, this.modifyCurrentPage);
  4198. this.registerHooks(this.scroll, this.scroll.eventTypes.scrollEnd, this.startPlay);
  4199. // for mousewheel event
  4200. if (this.scroll.eventTypes.mousewheelMove) {
  4201. this.registerHooks(this.scroll, this.scroll.eventTypes.mousewheelMove, function () {
  4202. // prevent default action of mousewheelMove
  4203. return true;
  4204. });
  4205. this.registerHooks(this.scroll, this.scroll.eventTypes.mousewheelEnd, function (delta) {
  4206. if (delta.directionX === 1 /* Positive */ ||
  4207. delta.directionY === 1 /* Positive */) {
  4208. _this.next();
  4209. }
  4210. if (delta.directionX === -1 /* Negative */ ||
  4211. delta.directionY === -1 /* Negative */) {
  4212. _this.prev();
  4213. }
  4214. });
  4215. }
  4216. // scrollHooks
  4217. this.registerHooks(scrollHooks, scrollHooks.eventTypes.refresh, this.refreshHandler);
  4218. this.registerHooks(scrollHooks, scrollHooks.eventTypes.destroy, this.destroy);
  4219. // scroller
  4220. this.registerHooks(scrollerHooks, scrollerHooks.eventTypes.beforeRefresh, function () {
  4221. _this.handleLoop(_this.prevContent);
  4222. _this.setSlideInlineStyle();
  4223. });
  4224. this.registerHooks(scrollerHooks, scrollerHooks.eventTypes.momentum, this.modifyScrollMetaHandler);
  4225. this.registerHooks(scrollerHooks, scrollerHooks.eventTypes.scroll, this.scrollHandler);
  4226. // a click operation will clearTimer, so restart a new one
  4227. this.registerHooks(scrollerHooks, scrollerHooks.eventTypes.checkClick, this.startPlay);
  4228. if (listenFlick) {
  4229. this.registerHooks(scrollerHooks, scrollerHooks.eventTypes.flick, this.flickHandler);
  4230. }
  4231. };
  4232. Slide.prototype.startPlay = function () {
  4233. var _this = this;
  4234. var _a = this.options, interval = _a.interval, autoplay = _a.autoplay;
  4235. if (autoplay) {
  4236. clearTimeout(this.autoplayTimer);
  4237. this.autoplayTimer = window.setTimeout(function () {
  4238. _this.next();
  4239. }, interval);
  4240. }
  4241. };
  4242. Slide.prototype.pausePlay = function () {
  4243. if (this.options.autoplay) {
  4244. clearTimeout(this.autoplayTimer);
  4245. }
  4246. };
  4247. Slide.prototype.setSlideInlineStyle = function () {
  4248. var styleConfigurations = [
  4249. {
  4250. direction: 'scrollX',
  4251. sizeType: 'offsetWidth',
  4252. styleType: 'width',
  4253. },
  4254. {
  4255. direction: 'scrollY',
  4256. sizeType: 'offsetHeight',
  4257. styleType: 'height',
  4258. },
  4259. ];
  4260. var _a = this.scroll.scroller, slideContent = _a.content, slideWrapper = _a.wrapper;
  4261. var scrollOptions = this.scroll.options;
  4262. styleConfigurations.forEach(function (_a) {
  4263. var direction = _a.direction, sizeType = _a.sizeType, styleType = _a.styleType;
  4264. // wanna scroll in this direction
  4265. if (scrollOptions[direction]) {
  4266. var size = slideWrapper[sizeType];
  4267. var children = slideContent.children;
  4268. var length_1 = children.length;
  4269. for (var i = 0; i < length_1; i++) {
  4270. var slidePageDOM = children[i];
  4271. slidePageDOM.style[styleType] = size + 'px';
  4272. }
  4273. slideContent.style[styleType] = size * length_1 + 'px';
  4274. }
  4275. });
  4276. };
  4277. Slide.prototype.next = function (time, easing) {
  4278. var _a = this.pages.nextPageIndex(), pageX = _a.pageX, pageY = _a.pageY;
  4279. this.goTo(pageX, pageY, time, easing);
  4280. };
  4281. Slide.prototype.prev = function (time, easing) {
  4282. var _a = this.pages.prevPageIndex(), pageX = _a.pageX, pageY = _a.pageY;
  4283. this.goTo(pageX, pageY, time, easing);
  4284. };
  4285. Slide.prototype.goToPage = function (pageX, pageY, time, easing) {
  4286. var pageIndex = this.pages.getValidPageIndex(pageX, pageY);
  4287. this.goTo(pageIndex.pageX, pageIndex.pageY, time, easing);
  4288. };
  4289. Slide.prototype.getCurrentPage = function () {
  4290. return this.exposedPage || this.pages.getInitialPage(false, true);
  4291. };
  4292. Slide.prototype.setCurrentPage = function (page) {
  4293. this.pages.setCurrentPage(page);
  4294. this.exposedPage = this.pages.getExposedPage(page);
  4295. };
  4296. Slide.prototype.nearestPage = function (x, y) {
  4297. var _a = this.scroll.scroller, scrollBehaviorX = _a.scrollBehaviorX, scrollBehaviorY = _a.scrollBehaviorY;
  4298. var maxScrollPosX = scrollBehaviorX.maxScrollPos, minScrollPosX = scrollBehaviorX.minScrollPos;
  4299. var maxScrollPosY = scrollBehaviorY.maxScrollPos, minScrollPosY = scrollBehaviorY.minScrollPos;
  4300. return this.pages.getNearestPage(between(x, maxScrollPosX, minScrollPosX), between(y, maxScrollPosY, minScrollPosY));
  4301. };
  4302. Slide.prototype.satisfyThreshold = function (x, y) {
  4303. var _a = this.scroll.scroller, scrollBehaviorX = _a.scrollBehaviorX, scrollBehaviorY = _a.scrollBehaviorY;
  4304. var satisfied = true;
  4305. if (Math.abs(x - scrollBehaviorX.absStartPos) <= this.thresholdX &&
  4306. Math.abs(y - scrollBehaviorY.absStartPos) <= this.thresholdY) {
  4307. satisfied = false;
  4308. }
  4309. return satisfied;
  4310. };
  4311. Slide.prototype.refreshHandler = function (content) {
  4312. var _this = this;
  4313. if (!this.satisfyInitialization()) {
  4314. return;
  4315. }
  4316. this.pages.refresh();
  4317. this.computeThreshold();
  4318. var contentChanged = (this.contentChanged = this.prevContent !== content);
  4319. if (contentChanged) {
  4320. this.prevContent = content;
  4321. }
  4322. var initPage = this.pages.getInitialPage(this.oneToMorePagesInLoop || this.moreToOnePageInLoop, contentChanged || !this.initialised);
  4323. if (this.initialised) {
  4324. this.goTo(initPage.pageX, initPage.pageY, 0);
  4325. }
  4326. else {
  4327. this.registerHooks(this.scroll.hooks, this.scroll.hooks.eventTypes.beforeInitialScrollTo, function (position) {
  4328. _this.initialised = true;
  4329. position.x = initPage.x;
  4330. position.y = initPage.y;
  4331. });
  4332. }
  4333. this.startPlay();
  4334. };
  4335. Slide.prototype.computeThreshold = function () {
  4336. var threshold = this.options.threshold;
  4337. // Integer
  4338. if (threshold % 1 === 0) {
  4339. this.thresholdX = threshold;
  4340. this.thresholdY = threshold;
  4341. }
  4342. else {
  4343. // decimal
  4344. var _a = this.pages.getPageStats(), width = _a.width, height = _a.height;
  4345. this.thresholdX = Math.round(width * threshold);
  4346. this.thresholdY = Math.round(height * threshold);
  4347. }
  4348. };
  4349. Slide.prototype.cloneFirstAndLastSlidePage = function (slideContent) {
  4350. var children = slideContent.children;
  4351. var preprendDOM = children[children.length - 1].cloneNode(true);
  4352. var appendDOM = children[0].cloneNode(true);
  4353. prepend(preprendDOM, slideContent);
  4354. slideContent.appendChild(appendDOM);
  4355. this.cachedClonedPageDOM = [preprendDOM, appendDOM];
  4356. };
  4357. Slide.prototype.removeClonedSlidePage = function (slideContent) {
  4358. // maybe slideContent has removed from DOM Tree
  4359. var slidePages = (slideContent && slideContent.children) || [];
  4360. if (slidePages.length) {
  4361. this.cachedClonedPageDOM.forEach(function (el) {
  4362. removeChild(slideContent, el);
  4363. });
  4364. }
  4365. this.cachedClonedPageDOM = [];
  4366. };
  4367. Slide.prototype.modifyCurrentPage = function (point) {
  4368. var _a = this.getCurrentPage(), prevExposedPageX = _a.pageX, prevExposedPageY = _a.pageY;
  4369. var newPage = this.nearestPage(point.x, point.y);
  4370. this.setCurrentPage(newPage);
  4371. /* istanbul ignore if */
  4372. if (this.contentChanged) {
  4373. this.contentChanged = false;
  4374. return true;
  4375. }
  4376. var _b = this.getCurrentPage(), currentExposedPageX = _b.pageX, currentExposedPageY = _b.pageY;
  4377. this.pageWillChangeTo(newPage);
  4378. // loop is true, and one page becomes many pages when call bs.refresh
  4379. if (this.oneToMorePagesInLoop) {
  4380. this.oneToMorePagesInLoop = false;
  4381. return true;
  4382. }
  4383. // loop is true, and many page becomes one page when call bs.refresh
  4384. // if prevPage > 0, dispatch slidePageChanged and scrollEnd events
  4385. /* istanbul ignore if */
  4386. if (this.moreToOnePageInLoop &&
  4387. prevExposedPageX === 0 &&
  4388. prevExposedPageY === 0) {
  4389. this.moreToOnePageInLoop = false;
  4390. return true;
  4391. }
  4392. if (prevExposedPageX !== currentExposedPageX ||
  4393. prevExposedPageY !== currentExposedPageY) {
  4394. // only trust pageX & pageY when loop is true
  4395. var page = this.pages.getExposedPageByPageIndex(currentExposedPageX, currentExposedPageY);
  4396. this.scroll.trigger(this.scroll.eventTypes.slidePageChanged, page);
  4397. }
  4398. // triggered by resetLoop
  4399. if (this.resetLooping) {
  4400. this.resetLooping = false;
  4401. return;
  4402. }
  4403. var changePage = this.pages.resetLoopPage();
  4404. if (changePage) {
  4405. this.resetLooping = true;
  4406. this.goTo(changePage.pageX, changePage.pageY, 0);
  4407. // stop user's scrollEnd
  4408. // since it is a seamless scroll
  4409. return true;
  4410. }
  4411. };
  4412. Slide.prototype.goTo = function (pageX, pageY, time, easing) {
  4413. var newPage = this.pages.getInternalPage(pageX, pageY);
  4414. var scrollEasing = easing || this.options.easing || ease.bounce;
  4415. var x = newPage.x, y = newPage.y;
  4416. var deltaX = x - this.scroll.scroller.scrollBehaviorX.currentPos;
  4417. var deltaY = y - this.scroll.scroller.scrollBehaviorY.currentPos;
  4418. /* istanbul ignore if */
  4419. if (!deltaX && !deltaY) {
  4420. this.scroll.scroller.togglePointerEvents(true);
  4421. return;
  4422. }
  4423. time = time === undefined ? this.getEaseTime(deltaX, deltaY) : time;
  4424. this.scroll.scroller.scrollTo(x, y, time, scrollEasing);
  4425. };
  4426. Slide.prototype.flickHandler = function () {
  4427. var _a = this.scroll.scroller, scrollBehaviorX = _a.scrollBehaviorX, scrollBehaviorY = _a.scrollBehaviorY;
  4428. var currentPosX = scrollBehaviorX.currentPos, startPosX = scrollBehaviorX.startPos, directionX = scrollBehaviorX.direction;
  4429. var currentPosY = scrollBehaviorY.currentPos, startPosY = scrollBehaviorY.startPos, directionY = scrollBehaviorY.direction;
  4430. var _b = this.pages.currentPage, pageX = _b.pageX, pageY = _b.pageY;
  4431. var time = this.getEaseTime(currentPosX - startPosX, currentPosY - startPosY);
  4432. this.goTo(pageX + directionX, pageY + directionY, time);
  4433. };
  4434. Slide.prototype.getEaseTime = function (deltaX, deltaY) {
  4435. return (this.options.speed ||
  4436. Math.max(Math.max(Math.min(Math.abs(deltaX), 1000), Math.min(Math.abs(deltaY), 1000)), 300));
  4437. };
  4438. Slide.prototype.modifyScrollMetaHandler = function (scrollMeta) {
  4439. var _a = this.scroll.scroller, scrollBehaviorX = _a.scrollBehaviorX, scrollBehaviorY = _a.scrollBehaviorY, animater = _a.animater;
  4440. var newX = scrollMeta.newX;
  4441. var newY = scrollMeta.newY;
  4442. var newPage = this.satisfyThreshold(newX, newY) || animater.forceStopped
  4443. ? this.pages.getPageByDirection(this.nearestPage(newX, newY), scrollBehaviorX.direction, scrollBehaviorY.direction)
  4444. : this.pages.currentPage;
  4445. scrollMeta.time = this.getEaseTime(scrollMeta.newX - newPage.x, scrollMeta.newY - newPage.y);
  4446. scrollMeta.newX = newPage.x;
  4447. scrollMeta.newY = newPage.y;
  4448. scrollMeta.easing = this.options.easing || ease.bounce;
  4449. };
  4450. Slide.prototype.scrollHandler = function (_a) {
  4451. var x = _a.x, y = _a.y;
  4452. if (this.satisfyThreshold(x, y)) {
  4453. var newPage = this.nearestPage(x, y);
  4454. this.pageWillChangeTo(newPage);
  4455. }
  4456. };
  4457. Slide.prototype.pageWillChangeTo = function (newPage) {
  4458. var changeToPage = this.pages.getWillChangedPage(newPage);
  4459. if (!samePage(this.willChangeToPage, changeToPage)) {
  4460. this.willChangeToPage = changeToPage;
  4461. this.scroll.trigger(this.scroll.eventTypes.slideWillChange, this.willChangeToPage);
  4462. }
  4463. };
  4464. Slide.prototype.registerHooks = function (hooks, name, handler) {
  4465. hooks.on(name, handler, this);
  4466. this.hooksFn.push([hooks, name, handler]);
  4467. };
  4468. Slide.prototype.destroy = function () {
  4469. var slideContent = this.scroll.scroller.content;
  4470. var _a = this.options, loop = _a.loop, autoplay = _a.autoplay;
  4471. if (loop) {
  4472. this.removeClonedSlidePage(slideContent);
  4473. }
  4474. if (autoplay) {
  4475. clearTimeout(this.autoplayTimer);
  4476. }
  4477. this.hooksFn.forEach(function (item) {
  4478. var hooks = item[0];
  4479. var hooksName = item[1];
  4480. var handlerFn = item[2];
  4481. if (hooks.eventTypes[hooksName]) {
  4482. hooks.off(hooksName, handlerFn);
  4483. }
  4484. });
  4485. this.hooksFn.length = 0;
  4486. };
  4487. Slide.pluginName = 'slide';
  4488. return Slide;
  4489. }());
  4490. var sourcePrefix$3 = 'plugins.wheel';
  4491. var propertiesMap$3 = [
  4492. {
  4493. key: 'wheelTo',
  4494. name: 'wheelTo',
  4495. },
  4496. {
  4497. key: 'getSelectedIndex',
  4498. name: 'getSelectedIndex',
  4499. },
  4500. {
  4501. key: 'restorePosition',
  4502. name: 'restorePosition',
  4503. },
  4504. ];
  4505. var propertiesConfig$3 = propertiesMap$3.map(function (item) {
  4506. return {
  4507. key: item.key,
  4508. sourceKey: sourcePrefix$3 + "." + item.name,
  4509. };
  4510. });
  4511. var WHEEL_INDEX_CHANGED_EVENT_NAME = 'wheelIndexChanged';
  4512. var CONSTANTS = {
  4513. rate: 4
  4514. };
  4515. var Wheel = /** @class */ (function () {
  4516. function Wheel(scroll) {
  4517. this.scroll = scroll;
  4518. this.init();
  4519. }
  4520. Wheel.prototype.init = function () {
  4521. this.handleBScroll();
  4522. this.handleOptions();
  4523. this.handleHooks();
  4524. // init boundary for Wheel
  4525. this.refreshBoundary();
  4526. this.setSelectedIndex(this.options.selectedIndex);
  4527. };
  4528. Wheel.prototype.handleBScroll = function () {
  4529. this.scroll.proxy(propertiesConfig$3);
  4530. this.scroll.registerType([WHEEL_INDEX_CHANGED_EVENT_NAME]);
  4531. };
  4532. Wheel.prototype.handleOptions = function () {
  4533. var userOptions = (this.scroll.options.wheel === true
  4534. ? {}
  4535. : this.scroll.options.wheel);
  4536. var defaultOptions = {
  4537. wheelWrapperClass: 'wheel-scroll',
  4538. wheelItemClass: 'wheel-item',
  4539. rotate: 25,
  4540. adjustTime: 400,
  4541. selectedIndex: 0,
  4542. wheelDisabledItemClass: 'wheel-disabled-item'
  4543. };
  4544. this.options = extend(defaultOptions, userOptions);
  4545. };
  4546. Wheel.prototype.handleHooks = function () {
  4547. var _this = this;
  4548. var scroll = this.scroll;
  4549. var scroller = this.scroll.scroller;
  4550. var actionsHandler = scroller.actionsHandler, scrollBehaviorX = scroller.scrollBehaviorX, scrollBehaviorY = scroller.scrollBehaviorY, animater = scroller.animater;
  4551. var prevContent = scroller.content;
  4552. // BScroll
  4553. scroll.on(scroll.eventTypes.scrollEnd, function (position) {
  4554. var index = _this.findNearestValidWheel(position.y).index;
  4555. if (scroller.animater.forceStopped && !_this.isAdjustingPosition) {
  4556. _this.target = _this.items[index];
  4557. // since stopped from an animation.
  4558. // prevent user's scrollEnd callback triggered twice
  4559. return true;
  4560. }
  4561. else {
  4562. _this.setSelectedIndex(index);
  4563. if (_this.isAdjustingPosition) {
  4564. _this.isAdjustingPosition = false;
  4565. }
  4566. }
  4567. });
  4568. // BScroll.hooks
  4569. this.scroll.hooks.on(this.scroll.hooks.eventTypes.refresh, function (content) {
  4570. if (content !== prevContent) {
  4571. prevContent = content;
  4572. _this.setSelectedIndex(_this.options.selectedIndex, true);
  4573. }
  4574. // rotate all wheel-items
  4575. // because position may not change
  4576. _this.rotateX(_this.scroll.y);
  4577. // check we are stop at a disable item or not
  4578. _this.wheelTo(_this.selectedIndex, 0);
  4579. });
  4580. this.scroll.hooks.on(this.scroll.hooks.eventTypes.beforeInitialScrollTo, function (position) {
  4581. // selectedIndex has higher priority than bs.options.startY
  4582. position.x = 0;
  4583. position.y = -(_this.selectedIndex * _this.itemHeight);
  4584. });
  4585. // Scroller
  4586. scroller.hooks.on(scroller.hooks.eventTypes.checkClick, function () {
  4587. var index = HTMLCollectionToArray(_this.items).indexOf(_this.target);
  4588. if (index === -1)
  4589. return true;
  4590. _this.wheelTo(index, _this.options.adjustTime, ease.swipe);
  4591. return true;
  4592. });
  4593. scroller.hooks.on(scroller.hooks.eventTypes.scrollTo, function (endPoint) {
  4594. endPoint.y = _this.findNearestValidWheel(endPoint.y).y;
  4595. });
  4596. // when content is scrolling
  4597. // click wheel-item DOM repeatedly and crazily will cause scrollEnd not triggered
  4598. // so reset forceStopped
  4599. scroller.hooks.on(scroller.hooks.eventTypes.minDistanceScroll, function () {
  4600. var animater = scroller.animater;
  4601. if (animater.forceStopped === true) {
  4602. animater.forceStopped = false;
  4603. }
  4604. });
  4605. scroller.hooks.on(scroller.hooks.eventTypes.scrollToElement, function (el, pos) {
  4606. if (!hasClass(el, _this.options.wheelItemClass)) {
  4607. return true;
  4608. }
  4609. else {
  4610. pos.top = _this.findNearestValidWheel(pos.top).y;
  4611. }
  4612. });
  4613. // ActionsHandler
  4614. actionsHandler.hooks.on(actionsHandler.hooks.eventTypes.beforeStart, function (e) {
  4615. _this.target = e.target;
  4616. });
  4617. // ScrollBehaviorX
  4618. // Wheel has no x direction now
  4619. scrollBehaviorX.hooks.on(scrollBehaviorX.hooks.eventTypes.computeBoundary, function (boundary) {
  4620. boundary.maxScrollPos = 0;
  4621. boundary.minScrollPos = 0;
  4622. });
  4623. // ScrollBehaviorY
  4624. scrollBehaviorY.hooks.on(scrollBehaviorY.hooks.eventTypes.computeBoundary, function (boundary) {
  4625. _this.items = _this.scroll.scroller.content.children;
  4626. _this.checkWheelAllDisabled();
  4627. _this.itemHeight =
  4628. _this.items.length > 0
  4629. ? scrollBehaviorY.contentSize / _this.items.length
  4630. : 0;
  4631. boundary.maxScrollPos = -_this.itemHeight * (_this.items.length - 1);
  4632. boundary.minScrollPos = 0;
  4633. });
  4634. scrollBehaviorY.hooks.on(scrollBehaviorY.hooks.eventTypes.momentum, function (momentumInfo) {
  4635. momentumInfo.rate = CONSTANTS.rate;
  4636. momentumInfo.destination = _this.findNearestValidWheel(momentumInfo.destination).y;
  4637. });
  4638. scrollBehaviorY.hooks.on(scrollBehaviorY.hooks.eventTypes.end, function (momentumInfo) {
  4639. var validWheel = _this.findNearestValidWheel(scrollBehaviorY.currentPos);
  4640. momentumInfo.destination = validWheel.y;
  4641. momentumInfo.duration = _this.options.adjustTime;
  4642. });
  4643. // Animater
  4644. animater.hooks.on(animater.hooks.eventTypes.time, function (time) {
  4645. _this.transitionDuration(time);
  4646. });
  4647. animater.hooks.on(animater.hooks.eventTypes.timeFunction, function (easing) {
  4648. _this.timeFunction(easing);
  4649. });
  4650. // bs.stop() to make wheel stop at a correct position when pending
  4651. animater.hooks.on(animater.hooks.eventTypes.callStop, function () {
  4652. var index = _this.findNearestValidWheel(_this.scroll.y).index;
  4653. _this.isAdjustingPosition = true;
  4654. _this.wheelTo(index, 0);
  4655. });
  4656. // Translater
  4657. animater.translater.hooks.on(animater.translater.hooks.eventTypes.translate, function (endPoint) {
  4658. _this.rotateX(endPoint.y);
  4659. });
  4660. };
  4661. Wheel.prototype.refreshBoundary = function () {
  4662. var _a = this.scroll.scroller, scrollBehaviorX = _a.scrollBehaviorX, scrollBehaviorY = _a.scrollBehaviorY, content = _a.content;
  4663. scrollBehaviorX.refresh(content);
  4664. scrollBehaviorY.refresh(content);
  4665. };
  4666. Wheel.prototype.setSelectedIndex = function (index, contentChanged) {
  4667. if (contentChanged === void 0) { contentChanged = false; }
  4668. var prevSelectedIndex = this.selectedIndex;
  4669. this.selectedIndex = index;
  4670. // if content DOM changed, should not trigger event
  4671. if (prevSelectedIndex !== index && !contentChanged) {
  4672. this.scroll.trigger(WHEEL_INDEX_CHANGED_EVENT_NAME, index);
  4673. }
  4674. };
  4675. Wheel.prototype.getSelectedIndex = function () {
  4676. return this.selectedIndex;
  4677. };
  4678. Wheel.prototype.wheelTo = function (index, time, ease) {
  4679. if (index === void 0) { index = 0; }
  4680. if (time === void 0) { time = 0; }
  4681. var y = -index * this.itemHeight;
  4682. this.scroll.scrollTo(0, y, time, ease);
  4683. };
  4684. Wheel.prototype.restorePosition = function () {
  4685. // bs is scrolling
  4686. var isPending = this.scroll.pending;
  4687. if (isPending) {
  4688. var selectedIndex = this.getSelectedIndex();
  4689. this.scroll.scroller.animater.clearTimer();
  4690. this.wheelTo(selectedIndex, 0);
  4691. }
  4692. };
  4693. Wheel.prototype.transitionDuration = function (time) {
  4694. for (var i = 0; i < this.items.length; i++) {
  4695. this.items[i].style[style.transitionDuration] =
  4696. time + 'ms';
  4697. }
  4698. };
  4699. Wheel.prototype.timeFunction = function (easing) {
  4700. for (var i = 0; i < this.items.length; i++) {
  4701. this.items[i].style[style.transitionTimingFunction] = easing;
  4702. }
  4703. };
  4704. Wheel.prototype.rotateX = function (y) {
  4705. var _a = this.options.rotate, rotate = _a === void 0 ? 25 : _a;
  4706. for (var i = 0; i < this.items.length; i++) {
  4707. var deg = rotate * (y / this.itemHeight + i);
  4708. // Too small value is invalid in some phones, issue 1026
  4709. var SafeDeg = deg.toFixed(3);
  4710. this.items[i].style[style.transform] = "rotateX(" + SafeDeg + "deg)";
  4711. }
  4712. };
  4713. Wheel.prototype.findNearestValidWheel = function (y) {
  4714. y = y > 0 ? 0 : y < this.scroll.maxScrollY ? this.scroll.maxScrollY : y;
  4715. var currentIndex = Math.abs(Math.round(-y / this.itemHeight));
  4716. var cacheIndex = currentIndex;
  4717. var items = this.items;
  4718. var wheelDisabledItemClassName = this.options
  4719. .wheelDisabledItemClass;
  4720. // implement web native select element
  4721. // first, check whether there is a enable item whose index is smaller than currentIndex
  4722. // then, check whether there is a enable item whose index is bigger than currentIndex
  4723. // otherwise, there are all disabled items, just keep currentIndex unchange
  4724. while (currentIndex >= 0) {
  4725. if (!hasClass(items[currentIndex], wheelDisabledItemClassName)) {
  4726. break;
  4727. }
  4728. currentIndex--;
  4729. }
  4730. if (currentIndex < 0) {
  4731. currentIndex = cacheIndex;
  4732. while (currentIndex <= items.length - 1) {
  4733. if (!hasClass(items[currentIndex], wheelDisabledItemClassName)) {
  4734. break;
  4735. }
  4736. currentIndex++;
  4737. }
  4738. }
  4739. // keep it unchange when all the items are disabled
  4740. if (currentIndex === items.length) {
  4741. currentIndex = cacheIndex;
  4742. }
  4743. // when all the items are disabled, selectedIndex should always be -1
  4744. return {
  4745. index: this.wheelItemsAllDisabled ? -1 : currentIndex,
  4746. y: -currentIndex * this.itemHeight
  4747. };
  4748. };
  4749. Wheel.prototype.checkWheelAllDisabled = function () {
  4750. var wheelDisabledItemClassName = this.options.wheelDisabledItemClass;
  4751. var items = this.items;
  4752. this.wheelItemsAllDisabled = true;
  4753. for (var i = 0; i < items.length; i++) {
  4754. if (!hasClass(items[i], wheelDisabledItemClassName)) {
  4755. this.wheelItemsAllDisabled = false;
  4756. break;
  4757. }
  4758. }
  4759. };
  4760. Wheel.pluginName = 'wheel';
  4761. return Wheel;
  4762. }());
  4763. var sourcePrefix$2 = 'plugins.zoom';
  4764. var propertiesMap$2 = [
  4765. {
  4766. key: 'zoomTo',
  4767. name: 'zoomTo'
  4768. }
  4769. ];
  4770. var propertiesConfig$2 = propertiesMap$2.map(function (item) {
  4771. return {
  4772. key: item.key,
  4773. sourceKey: sourcePrefix$2 + "." + item.name
  4774. };
  4775. });
  4776. var TWO_FINGERS = 2;
  4777. var RAW_SCALE = 1;
  4778. var Zoom = /** @class */ (function () {
  4779. function Zoom(scroll) {
  4780. this.scroll = scroll;
  4781. this.scale = RAW_SCALE;
  4782. this.prevScale = 1;
  4783. this.init();
  4784. }
  4785. Zoom.prototype.init = function () {
  4786. this.handleBScroll();
  4787. this.handleOptions();
  4788. this.handleHooks();
  4789. this.tryInitialZoomTo(this.zoomOpt);
  4790. };
  4791. Zoom.prototype.zoomTo = function (scale, x, y, bounceTime) {
  4792. var _a = this.resolveOrigin(x, y), originX = _a.originX, originY = _a.originY;
  4793. var origin = {
  4794. x: originX,
  4795. y: originY,
  4796. baseScale: this.scale,
  4797. };
  4798. this._doZoomTo(scale, origin, bounceTime, true);
  4799. };
  4800. Zoom.prototype.handleBScroll = function () {
  4801. this.scroll.proxy(propertiesConfig$2);
  4802. this.scroll.registerType([
  4803. 'beforeZoomStart',
  4804. 'zoomStart',
  4805. 'zooming',
  4806. 'zoomEnd',
  4807. ]);
  4808. };
  4809. Zoom.prototype.handleOptions = function () {
  4810. var userOptions = (this.scroll.options.zoom === true
  4811. ? {}
  4812. : this.scroll.options.zoom);
  4813. var defaultOptions = {
  4814. start: 1,
  4815. min: 1,
  4816. max: 4,
  4817. initialOrigin: [0, 0],
  4818. minimalZoomDistance: 5,
  4819. bounceTime: 800,
  4820. };
  4821. this.zoomOpt = extend(defaultOptions, userOptions);
  4822. };
  4823. Zoom.prototype.handleHooks = function () {
  4824. var _this = this;
  4825. var scroll = this.scroll;
  4826. var scroller = this.scroll.scroller;
  4827. this.wrapper = this.scroll.scroller.wrapper;
  4828. this.setTransformOrigin(this.scroll.scroller.content);
  4829. var scrollBehaviorX = scroller.scrollBehaviorX;
  4830. var scrollBehaviorY = scroller.scrollBehaviorY;
  4831. this.hooksFn = [];
  4832. // BScroll
  4833. this.registerHooks(scroll.hooks, scroll.hooks.eventTypes.contentChanged, function (content) {
  4834. _this.setTransformOrigin(content);
  4835. _this.scale = RAW_SCALE;
  4836. _this.tryInitialZoomTo(_this.zoomOpt);
  4837. });
  4838. this.registerHooks(scroll.hooks, scroll.hooks.eventTypes.beforeInitialScrollTo, function () {
  4839. // if perform a zoom action, we should prevent initial scroll when initialised
  4840. if (_this.zoomOpt.start !== RAW_SCALE) {
  4841. return true;
  4842. }
  4843. });
  4844. // enlarge boundary
  4845. this.registerHooks(scrollBehaviorX.hooks, scrollBehaviorX.hooks.eventTypes.beforeComputeBoundary, function () {
  4846. // content may change, don't cache it's size
  4847. var contentSize = getRect(_this.scroll.scroller.content);
  4848. scrollBehaviorX.contentSize = Math.floor(contentSize.width * _this.scale);
  4849. });
  4850. this.registerHooks(scrollBehaviorY.hooks, scrollBehaviorY.hooks.eventTypes.beforeComputeBoundary, function () {
  4851. // content may change, don't cache it's size
  4852. var contentSize = getRect(_this.scroll.scroller.content);
  4853. scrollBehaviorY.contentSize = Math.floor(contentSize.height * _this.scale);
  4854. });
  4855. // touch event
  4856. this.registerHooks(scroller.actions.hooks, scroller.actions.hooks.eventTypes.start, function (e) {
  4857. var numberOfFingers = (e.touches && e.touches.length) || 0;
  4858. _this.fingersOperation(numberOfFingers);
  4859. if (numberOfFingers === TWO_FINGERS) {
  4860. _this.zoomStart(e);
  4861. }
  4862. });
  4863. this.registerHooks(scroller.actions.hooks, scroller.actions.hooks.eventTypes.beforeMove, function (e) {
  4864. var numberOfFingers = (e.touches && e.touches.length) || 0;
  4865. _this.fingersOperation(numberOfFingers);
  4866. if (numberOfFingers === TWO_FINGERS) {
  4867. _this.zoom(e);
  4868. return true;
  4869. }
  4870. });
  4871. this.registerHooks(scroller.actions.hooks, scroller.actions.hooks.eventTypes.beforeEnd, function (e) {
  4872. var numberOfFingers = _this.fingersOperation();
  4873. if (numberOfFingers === TWO_FINGERS) {
  4874. _this.zoomEnd();
  4875. return true;
  4876. }
  4877. });
  4878. this.registerHooks(scroller.translater.hooks, scroller.translater.hooks.eventTypes.beforeTranslate, function (transformStyle, point) {
  4879. var scale = point.scale ? point.scale : _this.prevScale;
  4880. _this.prevScale = scale;
  4881. transformStyle.push("scale(" + scale + ")");
  4882. });
  4883. this.registerHooks(scroller.hooks, scroller.hooks.eventTypes.scrollEnd, function () {
  4884. if (_this.fingersOperation() === TWO_FINGERS) {
  4885. _this.scroll.trigger(_this.scroll.eventTypes.zoomEnd, {
  4886. scale: _this.scale,
  4887. });
  4888. }
  4889. });
  4890. this.registerHooks(this.scroll.hooks, 'destroy', this.destroy);
  4891. };
  4892. Zoom.prototype.setTransformOrigin = function (content) {
  4893. content.style[style.transformOrigin] = '0 0';
  4894. };
  4895. Zoom.prototype.tryInitialZoomTo = function (options) {
  4896. var start = options.start, initialOrigin = options.initialOrigin;
  4897. var _a = this.scroll.scroller, scrollBehaviorX = _a.scrollBehaviorX, scrollBehaviorY = _a.scrollBehaviorY;
  4898. if (start !== RAW_SCALE) {
  4899. // Movable plugin may wanna modify minScrollPos or maxScrollPos
  4900. // so we force Movable to caculate them
  4901. this.resetBoundaries([scrollBehaviorX, scrollBehaviorY]);
  4902. this.zoomTo(start, initialOrigin[0], initialOrigin[1], 0);
  4903. }
  4904. };
  4905. // getter or setter operation
  4906. Zoom.prototype.fingersOperation = function (amounts) {
  4907. if (typeof amounts === 'number') {
  4908. this.numberOfFingers = amounts;
  4909. }
  4910. else {
  4911. return this.numberOfFingers;
  4912. }
  4913. };
  4914. Zoom.prototype._doZoomTo = function (scale, origin, time, useCurrentPos) {
  4915. var _this = this;
  4916. if (time === void 0) { time = this.zoomOpt.bounceTime; }
  4917. if (useCurrentPos === void 0) { useCurrentPos = false; }
  4918. var _a = this.zoomOpt, min = _a.min, max = _a.max;
  4919. var fromScale = this.scale;
  4920. var toScale = between(scale, min, max);
  4921. (function () {
  4922. if (time === 0) {
  4923. _this.scroll.trigger(_this.scroll.eventTypes.zooming, {
  4924. scale: toScale,
  4925. });
  4926. return;
  4927. }
  4928. if (time > 0) {
  4929. var timer_1;
  4930. var startTime_1 = getNow();
  4931. var endTime_1 = startTime_1 + time;
  4932. var scheduler_1 = function () {
  4933. var now = getNow();
  4934. if (now >= endTime_1) {
  4935. _this.scroll.trigger(_this.scroll.eventTypes.zooming, {
  4936. scale: toScale,
  4937. });
  4938. cancelAnimationFrame(timer_1);
  4939. return;
  4940. }
  4941. var ratio = ease.bounce.fn((now - startTime_1) / time);
  4942. var currentScale = ratio * (toScale - fromScale) + fromScale;
  4943. _this.scroll.trigger(_this.scroll.eventTypes.zooming, {
  4944. scale: currentScale,
  4945. });
  4946. timer_1 = requestAnimationFrame(scheduler_1);
  4947. };
  4948. // start scheduler job
  4949. scheduler_1();
  4950. }
  4951. })();
  4952. // suppose you are zooming by two fingers
  4953. this.fingersOperation(2);
  4954. this._zoomTo(toScale, fromScale, origin, time, useCurrentPos);
  4955. };
  4956. Zoom.prototype._zoomTo = function (toScale, fromScale, origin, time, useCurrentPos) {
  4957. if (useCurrentPos === void 0) { useCurrentPos = false; }
  4958. var ratio = toScale / origin.baseScale;
  4959. this.setScale(toScale);
  4960. var scroller = this.scroll.scroller;
  4961. var scrollBehaviorX = scroller.scrollBehaviorX, scrollBehaviorY = scroller.scrollBehaviorY;
  4962. this.resetBoundaries([scrollBehaviorX, scrollBehaviorY]);
  4963. // position is restrained in boundary
  4964. var newX = this.getNewPos(origin.x, ratio, scrollBehaviorX, true, useCurrentPos);
  4965. var newY = this.getNewPos(origin.y, ratio, scrollBehaviorY, true, useCurrentPos);
  4966. if (scrollBehaviorX.currentPos !== Math.round(newX) ||
  4967. scrollBehaviorY.currentPos !== Math.round(newY) ||
  4968. toScale !== fromScale) {
  4969. scroller.scrollTo(newX, newY, time, ease.bounce, {
  4970. start: {
  4971. scale: fromScale,
  4972. },
  4973. end: {
  4974. scale: toScale,
  4975. },
  4976. });
  4977. }
  4978. };
  4979. Zoom.prototype.resolveOrigin = function (x, y) {
  4980. var _a = this.scroll.scroller, scrollBehaviorX = _a.scrollBehaviorX, scrollBehaviorY = _a.scrollBehaviorY;
  4981. var resolveFormula = {
  4982. left: function () {
  4983. return 0;
  4984. },
  4985. top: function () {
  4986. return 0;
  4987. },
  4988. right: function () {
  4989. return scrollBehaviorX.contentSize;
  4990. },
  4991. bottom: function () {
  4992. return scrollBehaviorY.contentSize;
  4993. },
  4994. center: function (index) {
  4995. var baseSize = index === 0
  4996. ? scrollBehaviorX.contentSize
  4997. : scrollBehaviorY.contentSize;
  4998. return baseSize / 2;
  4999. },
  5000. };
  5001. return {
  5002. originX: typeof x === 'number' ? x : resolveFormula[x](0),
  5003. originY: typeof y === 'number' ? y : resolveFormula[y](1),
  5004. };
  5005. };
  5006. Zoom.prototype.zoomStart = function (e) {
  5007. var firstFinger = e.touches[0];
  5008. var secondFinger = e.touches[1];
  5009. this.startDistance = this.getFingerDistance(e);
  5010. this.startScale = this.scale;
  5011. var _a = offsetToBody(this.wrapper), left = _a.left, top = _a.top;
  5012. this.origin = {
  5013. x: Math.abs(firstFinger.pageX + secondFinger.pageX) / 2 +
  5014. left -
  5015. this.scroll.x,
  5016. y: Math.abs(firstFinger.pageY + secondFinger.pageY) / 2 +
  5017. top -
  5018. this.scroll.y,
  5019. baseScale: this.startScale,
  5020. };
  5021. this.scroll.trigger(this.scroll.eventTypes.beforeZoomStart);
  5022. };
  5023. Zoom.prototype.zoom = function (e) {
  5024. var currentDistance = this.getFingerDistance(e);
  5025. // at least minimalZoomDistance pixels for the zoom to initiate
  5026. if (!this.zoomed &&
  5027. Math.abs(currentDistance - this.startDistance) <
  5028. this.zoomOpt.minimalZoomDistance) {
  5029. return;
  5030. }
  5031. // when out of boundary , perform a damping algorithm
  5032. var endScale = this.dampingScale((currentDistance / this.startDistance) * this.startScale);
  5033. var ratio = endScale / this.startScale;
  5034. this.setScale(endScale);
  5035. if (!this.zoomed) {
  5036. this.zoomed = true;
  5037. this.scroll.trigger(this.scroll.eventTypes.zoomStart);
  5038. }
  5039. var scroller = this.scroll.scroller;
  5040. var scrollBehaviorX = scroller.scrollBehaviorX, scrollBehaviorY = scroller.scrollBehaviorY;
  5041. var x = this.getNewPos(this.origin.x, ratio, scrollBehaviorX, false, false);
  5042. var y = this.getNewPos(this.origin.y, ratio, scrollBehaviorY, false, false);
  5043. this.scroll.trigger(this.scroll.eventTypes.zooming, {
  5044. scale: this.scale,
  5045. });
  5046. scroller.translater.translate({ x: x, y: y, scale: endScale });
  5047. };
  5048. Zoom.prototype.zoomEnd = function () {
  5049. if (!this.zoomed)
  5050. return;
  5051. // if out of boundary, do rebound!
  5052. if (this.shouldRebound()) {
  5053. this._doZoomTo(this.scale, this.origin, this.zoomOpt.bounceTime);
  5054. return;
  5055. }
  5056. this.scroll.trigger(this.scroll.eventTypes.zoomEnd, { scale: this.scale });
  5057. };
  5058. Zoom.prototype.getFingerDistance = function (e) {
  5059. var firstFinger = e.touches[0];
  5060. var secondFinger = e.touches[1];
  5061. var deltaX = Math.abs(firstFinger.pageX - secondFinger.pageX);
  5062. var deltaY = Math.abs(firstFinger.pageY - secondFinger.pageY);
  5063. return getDistance(deltaX, deltaY);
  5064. };
  5065. Zoom.prototype.shouldRebound = function () {
  5066. var _a = this.zoomOpt, min = _a.min, max = _a.max;
  5067. var currentScale = this.scale;
  5068. // scale exceeded!
  5069. if (currentScale !== between(currentScale, min, max)) {
  5070. return true;
  5071. }
  5072. var _b = this.scroll.scroller, scrollBehaviorX = _b.scrollBehaviorX, scrollBehaviorY = _b.scrollBehaviorY;
  5073. // enlarge boundaries manually when zoom is end
  5074. this.resetBoundaries([scrollBehaviorX, scrollBehaviorY]);
  5075. var xInBoundary = scrollBehaviorX.checkInBoundary().inBoundary;
  5076. var yInBoundary = scrollBehaviorX.checkInBoundary().inBoundary;
  5077. return !(xInBoundary && yInBoundary);
  5078. };
  5079. Zoom.prototype.dampingScale = function (scale) {
  5080. var _a = this.zoomOpt, min = _a.min, max = _a.max;
  5081. if (scale < min) {
  5082. scale = 0.5 * min * Math.pow(2.0, scale / min);
  5083. }
  5084. else if (scale > max) {
  5085. scale = 2.0 * max * Math.pow(0.5, max / scale);
  5086. }
  5087. return scale;
  5088. };
  5089. Zoom.prototype.setScale = function (scale) {
  5090. this.scale = scale;
  5091. };
  5092. Zoom.prototype.resetBoundaries = function (scrollBehaviorPairs) {
  5093. scrollBehaviorPairs.forEach(function (behavior) { return behavior.computeBoundary(); });
  5094. };
  5095. Zoom.prototype.getNewPos = function (origin, lastScale, scrollBehavior, shouldInBoundary, useCurrentPos) {
  5096. if (useCurrentPos === void 0) { useCurrentPos = false; }
  5097. var newPos = origin -
  5098. origin * lastScale +
  5099. (useCurrentPos ? scrollBehavior.currentPos : scrollBehavior.startPos);
  5100. if (shouldInBoundary) {
  5101. newPos = between(newPos, scrollBehavior.maxScrollPos, scrollBehavior.minScrollPos);
  5102. }
  5103. // maxScrollPos or minScrollPos maybe a negative or positive digital
  5104. return newPos > 0 ? Math.floor(newPos) : Math.ceil(newPos);
  5105. };
  5106. Zoom.prototype.registerHooks = function (hooks, name, handler) {
  5107. hooks.on(name, handler, this);
  5108. this.hooksFn.push([hooks, name, handler]);
  5109. };
  5110. Zoom.prototype.destroy = function () {
  5111. this.hooksFn.forEach(function (item) {
  5112. var hooks = item[0];
  5113. var hooksName = item[1];
  5114. var handlerFn = item[2];
  5115. hooks.off(hooksName, handlerFn);
  5116. });
  5117. this.hooksFn.length = 0;
  5118. };
  5119. Zoom.pluginName = 'zoom';
  5120. return Zoom;
  5121. }());
  5122. var BScrollFamily = /** @class */ (function () {
  5123. function BScrollFamily(scroll) {
  5124. this.ancestors = [];
  5125. this.descendants = [];
  5126. this.hooksManager = [];
  5127. this.analyzed = false;
  5128. this.selfScroll = scroll;
  5129. }
  5130. BScrollFamily.create = function (scroll) {
  5131. return new BScrollFamily(scroll);
  5132. };
  5133. BScrollFamily.prototype.hasAncestors = function (bscrollFamily) {
  5134. var index = findIndex(this.ancestors, function (_a) {
  5135. var item = _a[0];
  5136. return item === bscrollFamily;
  5137. });
  5138. return index > -1;
  5139. };
  5140. BScrollFamily.prototype.hasDescendants = function (bscrollFamily) {
  5141. var index = findIndex(this.descendants, function (_a) {
  5142. var item = _a[0];
  5143. return item === bscrollFamily;
  5144. });
  5145. return index > -1;
  5146. };
  5147. BScrollFamily.prototype.addAncestor = function (bscrollFamily, distance) {
  5148. var ancestors = this.ancestors;
  5149. ancestors.push([bscrollFamily, distance]);
  5150. // by ascend
  5151. ancestors.sort(function (a, b) {
  5152. return a[1] - b[1];
  5153. });
  5154. };
  5155. BScrollFamily.prototype.addDescendant = function (bscrollFamily, distance) {
  5156. var descendants = this.descendants;
  5157. descendants.push([bscrollFamily, distance]);
  5158. // by ascend
  5159. descendants.sort(function (a, b) {
  5160. return a[1] - b[1];
  5161. });
  5162. };
  5163. BScrollFamily.prototype.removeAncestor = function (bscrollFamily) {
  5164. var ancestors = this.ancestors;
  5165. if (ancestors.length) {
  5166. var index = findIndex(this.ancestors, function (_a) {
  5167. var item = _a[0];
  5168. return item === bscrollFamily;
  5169. });
  5170. if (index > -1) {
  5171. return ancestors.splice(index, 1);
  5172. }
  5173. }
  5174. };
  5175. BScrollFamily.prototype.removeDescendant = function (bscrollFamily) {
  5176. var descendants = this.descendants;
  5177. if (descendants.length) {
  5178. var index = findIndex(this.descendants, function (_a) {
  5179. var item = _a[0];
  5180. return item === bscrollFamily;
  5181. });
  5182. if (index > -1) {
  5183. return descendants.splice(index, 1);
  5184. }
  5185. }
  5186. };
  5187. BScrollFamily.prototype.registerHooks = function (hook, eventType, handler) {
  5188. hook.on(eventType, handler);
  5189. this.hooksManager.push([hook, eventType, handler]);
  5190. };
  5191. BScrollFamily.prototype.setAnalyzed = function (flag) {
  5192. if (flag === void 0) { flag = false; }
  5193. this.analyzed = flag;
  5194. };
  5195. BScrollFamily.prototype.purge = function () {
  5196. var _this = this;
  5197. // remove self from graph
  5198. this.ancestors.forEach(function (_a) {
  5199. var bscrollFamily = _a[0];
  5200. bscrollFamily.removeDescendant(_this);
  5201. });
  5202. this.descendants.forEach(function (_a) {
  5203. var bscrollFamily = _a[0];
  5204. bscrollFamily.removeAncestor(_this);
  5205. });
  5206. // remove all hook handlers
  5207. this.hooksManager.forEach(function (_a) {
  5208. var hooks = _a[0], eventType = _a[1], handler = _a[2];
  5209. hooks.off(eventType, handler);
  5210. });
  5211. this.hooksManager = [];
  5212. };
  5213. return BScrollFamily;
  5214. }());
  5215. var sourcePrefix$1 = 'plugins.nestedScroll';
  5216. var propertiesMap$1 = [
  5217. {
  5218. key: 'purgeNestedScroll',
  5219. name: 'purgeNestedScroll',
  5220. },
  5221. ];
  5222. var propertiesConfig$1 = propertiesMap$1.map(function (item) {
  5223. return {
  5224. key: item.key,
  5225. sourceKey: sourcePrefix$1 + "." + item.name,
  5226. };
  5227. });
  5228. var DEFAUL_GROUP_ID = 'INTERNAL_NESTED_SCROLL';
  5229. var forceScrollStopHandler = function (scrolls) {
  5230. scrolls.forEach(function (scroll) {
  5231. if (scroll.pending) {
  5232. scroll.stop();
  5233. scroll.resetPosition();
  5234. }
  5235. });
  5236. };
  5237. var enableScrollHander = function (scrolls) {
  5238. scrolls.forEach(function (scroll) {
  5239. scroll.enable();
  5240. });
  5241. };
  5242. var disableScrollHander = function (scrolls, currentScroll) {
  5243. scrolls.forEach(function (scroll) {
  5244. if (scroll.hasHorizontalScroll === currentScroll.hasHorizontalScroll ||
  5245. scroll.hasVerticalScroll === currentScroll.hasVerticalScroll) {
  5246. scroll.disable();
  5247. }
  5248. });
  5249. };
  5250. var syncTouchstartData = function (scrolls) {
  5251. scrolls.forEach(function (scroll) {
  5252. var _a = scroll.scroller, actions = _a.actions, scrollBehaviorX = _a.scrollBehaviorX, scrollBehaviorY = _a.scrollBehaviorY;
  5253. // prevent click triggering many times
  5254. actions.fingerMoved = true;
  5255. actions.contentMoved = false;
  5256. actions.directionLockAction.reset();
  5257. scrollBehaviorX.start();
  5258. scrollBehaviorY.start();
  5259. scrollBehaviorX.resetStartPos();
  5260. scrollBehaviorY.resetStartPos();
  5261. actions.startTime = +new Date();
  5262. });
  5263. };
  5264. var isOutOfBoundary = function (scroll) {
  5265. var hasHorizontalScroll = scroll.hasHorizontalScroll, hasVerticalScroll = scroll.hasVerticalScroll, x = scroll.x, y = scroll.y, minScrollX = scroll.minScrollX, maxScrollX = scroll.maxScrollX, minScrollY = scroll.minScrollY, maxScrollY = scroll.maxScrollY, movingDirectionX = scroll.movingDirectionX, movingDirectionY = scroll.movingDirectionY;
  5266. var ret = false;
  5267. var outOfLeftBoundary = x >= minScrollX && movingDirectionX === -1 /* Negative */;
  5268. var outOfRightBoundary = x <= maxScrollX && movingDirectionX === 1 /* Positive */;
  5269. var outOfTopBoundary = y >= minScrollY && movingDirectionY === -1 /* Negative */;
  5270. var outOfBottomBoundary = y <= maxScrollY && movingDirectionY === 1 /* Positive */;
  5271. if (hasVerticalScroll) {
  5272. ret = outOfTopBoundary || outOfBottomBoundary;
  5273. }
  5274. else if (hasHorizontalScroll) {
  5275. ret = outOfLeftBoundary || outOfRightBoundary;
  5276. }
  5277. return ret;
  5278. };
  5279. var isResettingPosition = function (scroll) {
  5280. var hasHorizontalScroll = scroll.hasHorizontalScroll, hasVerticalScroll = scroll.hasVerticalScroll, x = scroll.x, y = scroll.y, minScrollX = scroll.minScrollX, maxScrollX = scroll.maxScrollX, minScrollY = scroll.minScrollY, maxScrollY = scroll.maxScrollY;
  5281. var ret = false;
  5282. var outOfLeftBoundary = x > minScrollX;
  5283. var outOfRightBoundary = x < maxScrollX;
  5284. var outOfTopBoundary = y > minScrollY;
  5285. var outOfBottomBoundary = y < maxScrollY;
  5286. if (hasVerticalScroll) {
  5287. ret = outOfTopBoundary || outOfBottomBoundary;
  5288. }
  5289. else if (hasHorizontalScroll) {
  5290. ret = outOfLeftBoundary || outOfRightBoundary;
  5291. }
  5292. return ret;
  5293. };
  5294. var resetPositionHandler = function (scroll) {
  5295. scroll.scroller.reflow();
  5296. scroll.resetPosition(0 /* Immediately */);
  5297. };
  5298. var calculateDistance = function (childNode, parentNode) {
  5299. var distance = 0;
  5300. var parent = childNode.parentNode;
  5301. while (parent && parent !== parentNode) {
  5302. distance++;
  5303. parent = parent.parentNode;
  5304. }
  5305. return distance;
  5306. };
  5307. var NestedScroll = /** @class */ (function () {
  5308. function NestedScroll(scroll) {
  5309. var groupId = this.handleOptions(scroll);
  5310. var instance = NestedScroll.instancesMap[groupId];
  5311. if (!instance) {
  5312. instance = NestedScroll.instancesMap[groupId] = this;
  5313. instance.store = [];
  5314. instance.hooksFn = [];
  5315. }
  5316. instance.init(scroll);
  5317. return instance;
  5318. }
  5319. NestedScroll.getAllNestedScrolls = function () {
  5320. var instancesMap = NestedScroll.instancesMap;
  5321. return Object.keys(instancesMap).map(function (key) { return instancesMap[key]; });
  5322. };
  5323. NestedScroll.purgeAllNestedScrolls = function () {
  5324. var nestedScrolls = NestedScroll.getAllNestedScrolls();
  5325. nestedScrolls.forEach(function (ns) { return ns.purgeNestedScroll(); });
  5326. };
  5327. NestedScroll.prototype.handleOptions = function (scroll) {
  5328. var userOptions = (scroll.options.nestedScroll === true
  5329. ? {}
  5330. : scroll.options.nestedScroll);
  5331. var defaultOptions = {
  5332. groupId: DEFAUL_GROUP_ID,
  5333. };
  5334. this.options = extend(defaultOptions, userOptions);
  5335. var groupIdType = typeof this.options.groupId;
  5336. if (groupIdType !== 'string' && groupIdType !== 'number') {
  5337. warn('groupId must be string or number for NestedScroll plugin');
  5338. }
  5339. return this.options.groupId;
  5340. };
  5341. NestedScroll.prototype.init = function (scroll) {
  5342. scroll.proxy(propertiesConfig$1);
  5343. this.addBScroll(scroll);
  5344. this.buildBScrollGraph();
  5345. this.analyzeBScrollGraph();
  5346. this.ensureEventInvokeSequence();
  5347. this.handleHooks(scroll);
  5348. };
  5349. NestedScroll.prototype.handleHooks = function (scroll) {
  5350. var _this = this;
  5351. this.registerHooks(scroll.hooks, scroll.hooks.eventTypes.destroy, function () {
  5352. _this.deleteScroll(scroll);
  5353. });
  5354. };
  5355. NestedScroll.prototype.deleteScroll = function (scroll) {
  5356. var wrapper = scroll.wrapper;
  5357. wrapper.isBScrollContainer = undefined;
  5358. var store = this.store;
  5359. var hooksFn = this.hooksFn;
  5360. var i = findIndex(store, function (bscrollFamily) {
  5361. return bscrollFamily.selfScroll === scroll;
  5362. });
  5363. if (i > -1) {
  5364. var bscrollFamily = store[i];
  5365. bscrollFamily.purge();
  5366. store.splice(i, 1);
  5367. }
  5368. var k = findIndex(hooksFn, function (_a) {
  5369. var hooks = _a[0];
  5370. return hooks === scroll.hooks;
  5371. });
  5372. if (k > -1) {
  5373. var _a = hooksFn[k], hooks = _a[0], eventType = _a[1], handler = _a[2];
  5374. hooks.off(eventType, handler);
  5375. hooksFn.splice(k, 1);
  5376. }
  5377. };
  5378. NestedScroll.prototype.addBScroll = function (scroll) {
  5379. this.store.push(BScrollFamily.create(scroll));
  5380. };
  5381. NestedScroll.prototype.buildBScrollGraph = function () {
  5382. var store = this.store;
  5383. var bf1;
  5384. var bf2;
  5385. var wrapper1;
  5386. var wrapper2;
  5387. var len = this.store.length;
  5388. // build graph
  5389. for (var i = 0; i < len; i++) {
  5390. bf1 = store[i];
  5391. wrapper1 = bf1.selfScroll.wrapper;
  5392. for (var j = 0; j < len; j++) {
  5393. bf2 = store[j];
  5394. wrapper2 = bf2.selfScroll.wrapper;
  5395. // same bs
  5396. if (bf1 === bf2)
  5397. continue;
  5398. if (!wrapper1.contains(wrapper2))
  5399. continue;
  5400. // bs1 contains bs2
  5401. var distance = calculateDistance(wrapper2, wrapper1);
  5402. if (!bf1.hasDescendants(bf2)) {
  5403. bf1.addDescendant(bf2, distance);
  5404. }
  5405. if (!bf2.hasAncestors(bf1)) {
  5406. bf2.addAncestor(bf1, distance);
  5407. }
  5408. }
  5409. }
  5410. };
  5411. NestedScroll.prototype.analyzeBScrollGraph = function () {
  5412. this.store.forEach(function (bscrollFamily) {
  5413. if (bscrollFamily.analyzed) {
  5414. return;
  5415. }
  5416. var ancestors = bscrollFamily.ancestors, descendants = bscrollFamily.descendants, currentScroll = bscrollFamily.selfScroll;
  5417. var beforeScrollStartHandler = function () {
  5418. // always get the latest scroll
  5419. var ancestorScrolls = ancestors.map(function (_a) {
  5420. var bscrollFamily = _a[0];
  5421. return bscrollFamily.selfScroll;
  5422. });
  5423. var descendantScrolls = descendants.map(function (_a) {
  5424. var bscrollFamily = _a[0];
  5425. return bscrollFamily.selfScroll;
  5426. });
  5427. forceScrollStopHandler(__spreadArrays(ancestorScrolls, descendantScrolls));
  5428. if (isResettingPosition(currentScroll)) {
  5429. resetPositionHandler(currentScroll);
  5430. }
  5431. syncTouchstartData(ancestorScrolls);
  5432. disableScrollHander(ancestorScrolls, currentScroll);
  5433. };
  5434. var touchEndHandler = function () {
  5435. var ancestorScrolls = ancestors.map(function (_a) {
  5436. var bscrollFamily = _a[0];
  5437. return bscrollFamily.selfScroll;
  5438. });
  5439. var descendantScrolls = descendants.map(function (_a) {
  5440. var bscrollFamily = _a[0];
  5441. return bscrollFamily.selfScroll;
  5442. });
  5443. enableScrollHander(__spreadArrays(ancestorScrolls, descendantScrolls));
  5444. };
  5445. bscrollFamily.registerHooks(currentScroll, currentScroll.eventTypes.beforeScrollStart, beforeScrollStartHandler);
  5446. bscrollFamily.registerHooks(currentScroll, currentScroll.eventTypes.touchEnd, touchEndHandler);
  5447. var selfActionsHooks = currentScroll.scroller.actions.hooks;
  5448. bscrollFamily.registerHooks(selfActionsHooks, selfActionsHooks.eventTypes.detectMovingDirection, function () {
  5449. var ancestorScrolls = ancestors.map(function (_a) {
  5450. var bscrollFamily = _a[0];
  5451. return bscrollFamily.selfScroll;
  5452. });
  5453. var parentScroll = ancestorScrolls[0];
  5454. var otherAncestorScrolls = ancestorScrolls.slice(1);
  5455. var contentMoved = currentScroll.scroller.actions.contentMoved;
  5456. var isTopScroll = ancestorScrolls.length === 0;
  5457. if (contentMoved) {
  5458. disableScrollHander(ancestorScrolls, currentScroll);
  5459. }
  5460. else if (!isTopScroll) {
  5461. if (isOutOfBoundary(currentScroll)) {
  5462. disableScrollHander([currentScroll], currentScroll);
  5463. if (parentScroll) {
  5464. enableScrollHander([parentScroll]);
  5465. }
  5466. disableScrollHander(otherAncestorScrolls, currentScroll);
  5467. return true;
  5468. }
  5469. }
  5470. });
  5471. bscrollFamily.setAnalyzed(true);
  5472. });
  5473. };
  5474. // make sure touchmove|touchend invoke from child to parent
  5475. NestedScroll.prototype.ensureEventInvokeSequence = function () {
  5476. var copied = this.store.slice();
  5477. var sequencedScroll = copied.sort(function (a, b) {
  5478. return a.descendants.length - b.descendants.length;
  5479. });
  5480. sequencedScroll.forEach(function (bscrollFamily) {
  5481. var scroll = bscrollFamily.selfScroll;
  5482. scroll.scroller.actionsHandler.rebindDOMEvents();
  5483. });
  5484. };
  5485. NestedScroll.prototype.registerHooks = function (hooks, name, handler) {
  5486. hooks.on(name, handler, this);
  5487. this.hooksFn.push([hooks, name, handler]);
  5488. };
  5489. NestedScroll.prototype.purgeNestedScroll = function () {
  5490. var groupId = this.options.groupId;
  5491. this.store.forEach(function (bscrollFamily) {
  5492. bscrollFamily.purge();
  5493. });
  5494. this.store = [];
  5495. this.hooksFn.forEach(function (_a) {
  5496. var hooks = _a[0], eventType = _a[1], handler = _a[2];
  5497. hooks.off(eventType, handler);
  5498. });
  5499. this.hooksFn = [];
  5500. delete NestedScroll.instancesMap[groupId];
  5501. };
  5502. NestedScroll.pluginName = 'nestedScroll';
  5503. NestedScroll.instancesMap = {};
  5504. return NestedScroll;
  5505. }());
  5506. var PRE_NUM = 10;
  5507. var POST_NUM = 30;
  5508. var IndexCalculator = /** @class */ (function () {
  5509. function IndexCalculator(wrapperHeight, tombstoneHeight) {
  5510. this.wrapperHeight = wrapperHeight;
  5511. this.tombstoneHeight = tombstoneHeight;
  5512. this.lastDirection = 1 /* DOWN */;
  5513. this.lastPos = 0;
  5514. }
  5515. IndexCalculator.prototype.calculate = function (pos, list) {
  5516. var offset = pos - this.lastPos;
  5517. this.lastPos = pos;
  5518. var direction = this.getDirection(offset);
  5519. // important! start index is much more important than end index.
  5520. var start = this.calculateIndex(0, pos, list);
  5521. var end = this.calculateIndex(start, pos + this.wrapperHeight, list);
  5522. if (direction === 1 /* DOWN */) {
  5523. start -= PRE_NUM;
  5524. end += POST_NUM;
  5525. }
  5526. else {
  5527. start -= POST_NUM;
  5528. end += PRE_NUM;
  5529. }
  5530. if (start < 0) {
  5531. start = 0;
  5532. }
  5533. return {
  5534. start: start,
  5535. end: end,
  5536. };
  5537. };
  5538. IndexCalculator.prototype.getDirection = function (offset) {
  5539. var direction;
  5540. if (offset > 0) {
  5541. direction = 1 /* DOWN */;
  5542. }
  5543. else if (offset < 0) {
  5544. direction = 0 /* UP */;
  5545. }
  5546. else {
  5547. return this.lastDirection;
  5548. }
  5549. this.lastDirection = direction;
  5550. return direction;
  5551. };
  5552. IndexCalculator.prototype.calculateIndex = function (start, offset, list) {
  5553. if (offset <= 0) {
  5554. return start;
  5555. }
  5556. var i = start;
  5557. var startPos = list[i] && list[i].pos !== -1 ? list[i].pos : 0;
  5558. var lastPos = startPos;
  5559. var tombstone = 0;
  5560. while (i < list.length && list[i].pos < offset) {
  5561. lastPos = list[i].pos;
  5562. i++;
  5563. }
  5564. if (i === list.length) {
  5565. tombstone = Math.floor((offset - lastPos) / this.tombstoneHeight);
  5566. }
  5567. i += tombstone;
  5568. return i;
  5569. };
  5570. IndexCalculator.prototype.resetState = function () {
  5571. this.lastDirection = 1 /* DOWN */;
  5572. this.lastPos = 0;
  5573. };
  5574. return IndexCalculator;
  5575. }());
  5576. var ListItem = /** @class */ (function () {
  5577. function ListItem() {
  5578. this.data = null;
  5579. this.dom = null;
  5580. this.tombstone = null;
  5581. this.width = 0;
  5582. this.height = 0;
  5583. this.pos = 0;
  5584. }
  5585. return ListItem;
  5586. }());
  5587. var DataManager = /** @class */ (function () {
  5588. function DataManager(list, fetchFn, onFetchFinish) {
  5589. this.fetchFn = fetchFn;
  5590. this.onFetchFinish = onFetchFinish;
  5591. this.loadedNum = 0;
  5592. this.fetching = false;
  5593. this.hasMore = true;
  5594. this.list = list || [];
  5595. }
  5596. DataManager.prototype.update = function (end) {
  5597. return __awaiter(this, void 0, void 0, function () {
  5598. var len;
  5599. return __generator(this, function (_a) {
  5600. if (!this.hasMore) {
  5601. end = Math.min(end, this.list.length);
  5602. }
  5603. // add data placeholder
  5604. if (end > this.list.length) {
  5605. len = end - this.list.length;
  5606. this.addEmptyData(len);
  5607. }
  5608. // tslint:disable-next-line: no-floating-promises
  5609. return [2 /*return*/, this.checkToFetch(end)];
  5610. });
  5611. });
  5612. };
  5613. DataManager.prototype.add = function (data) {
  5614. for (var i = 0; i < data.length; i++) {
  5615. if (!this.list[this.loadedNum]) {
  5616. this.list[this.loadedNum] = { data: data[i] };
  5617. }
  5618. else {
  5619. this.list[this.loadedNum] = __assign(__assign({}, this.list[this.loadedNum]), { data: data[i] });
  5620. }
  5621. this.loadedNum++;
  5622. }
  5623. return this.list;
  5624. };
  5625. DataManager.prototype.addEmptyData = function (len) {
  5626. for (var i = 0; i < len; i++) {
  5627. this.list.push(new ListItem());
  5628. }
  5629. return this.list;
  5630. };
  5631. DataManager.prototype.fetch = function (len) {
  5632. return __awaiter(this, void 0, void 0, function () {
  5633. var data;
  5634. return __generator(this, function (_a) {
  5635. switch (_a.label) {
  5636. case 0:
  5637. if (this.fetching) {
  5638. return [2 /*return*/, []];
  5639. }
  5640. this.fetching = true;
  5641. return [4 /*yield*/, this.fetchFn(len)];
  5642. case 1:
  5643. data = _a.sent();
  5644. this.fetching = false;
  5645. return [2 /*return*/, data];
  5646. }
  5647. });
  5648. });
  5649. };
  5650. DataManager.prototype.checkToFetch = function (end) {
  5651. return __awaiter(this, void 0, void 0, function () {
  5652. var min, newData, currentEnd;
  5653. return __generator(this, function (_a) {
  5654. switch (_a.label) {
  5655. case 0:
  5656. if (!this.hasMore) {
  5657. return [2 /*return*/];
  5658. }
  5659. if (end <= this.loadedNum) {
  5660. return [2 /*return*/];
  5661. }
  5662. min = end - this.loadedNum;
  5663. return [4 /*yield*/, this.fetch(min)];
  5664. case 1:
  5665. newData = _a.sent();
  5666. if (newData instanceof Array && newData.length) {
  5667. this.add(newData);
  5668. currentEnd = this.onFetchFinish(this.list, true);
  5669. return [2 /*return*/, this.checkToFetch(currentEnd)];
  5670. }
  5671. else if (typeof newData === 'boolean' && newData === false) {
  5672. this.hasMore = false;
  5673. this.list.splice(this.loadedNum);
  5674. this.onFetchFinish(this.list, false);
  5675. }
  5676. return [2 /*return*/];
  5677. }
  5678. });
  5679. });
  5680. };
  5681. DataManager.prototype.getList = function () {
  5682. return this.list;
  5683. };
  5684. DataManager.prototype.resetState = function () {
  5685. this.loadedNum = 0;
  5686. this.fetching = false;
  5687. this.hasMore = true;
  5688. this.list = [];
  5689. };
  5690. return DataManager;
  5691. }());
  5692. var Tombstone = /** @class */ (function () {
  5693. function Tombstone(create) {
  5694. this.create = create;
  5695. this.cached = [];
  5696. this.width = 0;
  5697. this.height = 0;
  5698. this.initialed = false;
  5699. this.getSize();
  5700. }
  5701. Tombstone.isTombstone = function (el) {
  5702. if (el && el.classList) {
  5703. return el.classList.contains('tombstone');
  5704. }
  5705. return false;
  5706. };
  5707. Tombstone.prototype.getSize = function () {
  5708. if (!this.initialed) {
  5709. var tombstone = this.create();
  5710. tombstone.style.position = 'absolute';
  5711. document.body.appendChild(tombstone);
  5712. tombstone.style.display = '';
  5713. this.height = tombstone.offsetHeight;
  5714. this.width = tombstone.offsetWidth;
  5715. document.body.removeChild(tombstone);
  5716. this.cached.push(tombstone);
  5717. }
  5718. };
  5719. Tombstone.prototype.getOne = function () {
  5720. var tombstone = this.cached.pop();
  5721. if (tombstone) {
  5722. var tombstoneStyle = tombstone.style;
  5723. tombstoneStyle.display = '';
  5724. tombstoneStyle.opacity = '1';
  5725. tombstoneStyle[style.transform] = '';
  5726. tombstoneStyle[style.transition] = '';
  5727. return tombstone;
  5728. }
  5729. return this.create();
  5730. };
  5731. Tombstone.prototype.recycle = function (tombstones) {
  5732. for (var _i = 0, tombstones_1 = tombstones; _i < tombstones_1.length; _i++) {
  5733. var tombstone = tombstones_1[_i];
  5734. tombstone.style.display = 'none';
  5735. this.cached.push(tombstone);
  5736. }
  5737. return this.cached;
  5738. };
  5739. Tombstone.prototype.recycleOne = function (tombstone) {
  5740. this.cached.push(tombstone);
  5741. return this.cached;
  5742. };
  5743. return Tombstone;
  5744. }());
  5745. var ANIMATION_DURATION_MS = 200;
  5746. var DomManager = /** @class */ (function () {
  5747. function DomManager(content, renderFn, tombstone) {
  5748. this.renderFn = renderFn;
  5749. this.tombstone = tombstone;
  5750. this.unusedDom = [];
  5751. this.timers = [];
  5752. this.setContent(content);
  5753. }
  5754. DomManager.prototype.update = function (list, start, end) {
  5755. if (start >= list.length) {
  5756. start = list.length - 1;
  5757. }
  5758. if (end > list.length) {
  5759. end = list.length;
  5760. }
  5761. this.collectUnusedDom(list, start, end);
  5762. this.createDom(list, start, end);
  5763. this.cacheHeight(list, start, end);
  5764. var _a = this.positionDom(list, start, end), startPos = _a.startPos, startDelta = _a.startDelta, endPos = _a.endPos;
  5765. return {
  5766. start: start,
  5767. startPos: startPos,
  5768. startDelta: startDelta,
  5769. end: end,
  5770. endPos: endPos,
  5771. };
  5772. };
  5773. DomManager.prototype.collectUnusedDom = function (list, start, end) {
  5774. // TODO optimise
  5775. for (var i = 0; i < list.length; i++) {
  5776. if (i === start) {
  5777. i = end - 1;
  5778. continue;
  5779. }
  5780. if (list[i].dom) {
  5781. var dom = list[i].dom;
  5782. if (Tombstone.isTombstone(dom)) {
  5783. this.tombstone.recycleOne(dom);
  5784. dom.style.display = 'none';
  5785. }
  5786. else {
  5787. this.unusedDom.push(dom);
  5788. }
  5789. list[i].dom = null;
  5790. }
  5791. }
  5792. return list;
  5793. };
  5794. DomManager.prototype.createDom = function (list, start, end) {
  5795. for (var i = start; i < end; i++) {
  5796. var dom = list[i].dom;
  5797. var data = list[i].data;
  5798. if (dom) {
  5799. if (Tombstone.isTombstone(dom) && data) {
  5800. list[i].tombstone = dom;
  5801. list[i].dom = null;
  5802. }
  5803. else {
  5804. continue;
  5805. }
  5806. }
  5807. dom = data
  5808. ? this.renderFn(data, this.unusedDom.pop())
  5809. : this.tombstone.getOne();
  5810. dom.style.position = 'absolute';
  5811. list[i].dom = dom;
  5812. list[i].pos = -1;
  5813. this.content.appendChild(dom);
  5814. }
  5815. };
  5816. DomManager.prototype.cacheHeight = function (list, start, end) {
  5817. for (var i = start; i < end; i++) {
  5818. if (list[i].data && !list[i].height) {
  5819. list[i].height = list[i].dom.offsetHeight;
  5820. }
  5821. }
  5822. };
  5823. DomManager.prototype.positionDom = function (list, start, end) {
  5824. var _this = this;
  5825. var tombstoneEles = [];
  5826. var _a = this.getStartPos(list, start, end), startPos = _a.start, startDelta = _a.delta;
  5827. var pos = startPos;
  5828. for (var i = start; i < end; i++) {
  5829. var tombstone = list[i].tombstone;
  5830. if (tombstone) {
  5831. var tombstoneStyle = tombstone.style;
  5832. tombstoneStyle[style.transition] = cssVendor + "transform " + ANIMATION_DURATION_MS + "ms, opacity " + ANIMATION_DURATION_MS + "ms";
  5833. tombstoneStyle[style.transform] = "translateY(" + pos + "px)";
  5834. tombstoneStyle.opacity = '0';
  5835. list[i].tombstone = null;
  5836. tombstoneEles.push(tombstone);
  5837. }
  5838. if (list[i].dom && list[i].pos !== pos) {
  5839. list[i].dom.style[style.transform] = "translateY(" + pos + "px)";
  5840. list[i].pos = pos;
  5841. }
  5842. pos += list[i].height || this.tombstone.height;
  5843. }
  5844. var timerId = window.setTimeout(function () {
  5845. _this.tombstone.recycle(tombstoneEles);
  5846. }, ANIMATION_DURATION_MS);
  5847. this.timers.push(timerId);
  5848. return {
  5849. startPos: startPos,
  5850. startDelta: startDelta,
  5851. endPos: pos,
  5852. };
  5853. };
  5854. DomManager.prototype.getStartPos = function (list, start, end) {
  5855. if (list[start] && list[start].pos !== -1) {
  5856. return {
  5857. start: list[start].pos,
  5858. delta: 0,
  5859. };
  5860. }
  5861. // TODO optimise
  5862. var pos = list[0].pos === -1 ? 0 : list[0].pos;
  5863. for (var i_1 = 0; i_1 < start; i_1++) {
  5864. pos += list[i_1].height || this.tombstone.height;
  5865. }
  5866. var originPos = pos;
  5867. var i;
  5868. for (i = start; i < end; i++) {
  5869. if (!Tombstone.isTombstone(list[i].dom) && list[i].pos !== -1) {
  5870. pos = list[i].pos;
  5871. break;
  5872. }
  5873. }
  5874. var x = i;
  5875. if (x < end) {
  5876. while (x > start) {
  5877. pos -= list[x - 1].height;
  5878. x--;
  5879. }
  5880. }
  5881. var delta = originPos - pos;
  5882. return {
  5883. start: pos,
  5884. delta: delta,
  5885. };
  5886. };
  5887. DomManager.prototype.removeTombstone = function () {
  5888. var tombstones = this.content.querySelectorAll('.tombstone');
  5889. for (var i = tombstones.length - 1; i >= 0; i--) {
  5890. this.content.removeChild(tombstones[i]);
  5891. }
  5892. };
  5893. DomManager.prototype.setContent = function (content) {
  5894. if (content !== this.content) {
  5895. this.content = content;
  5896. }
  5897. };
  5898. DomManager.prototype.destroy = function () {
  5899. this.removeTombstone();
  5900. this.timers.forEach(function (id) {
  5901. clearTimeout(id);
  5902. });
  5903. };
  5904. DomManager.prototype.resetState = function () {
  5905. this.destroy();
  5906. this.timers = [];
  5907. this.unusedDom = [];
  5908. };
  5909. return DomManager;
  5910. }());
  5911. var EXTRA_SCROLL_Y = -2000;
  5912. var InfinityScroll = /** @class */ (function () {
  5913. function InfinityScroll(scroll) {
  5914. this.scroll = scroll;
  5915. this.start = 0;
  5916. this.end = 0;
  5917. this.init();
  5918. }
  5919. InfinityScroll.prototype.init = function () {
  5920. var _this = this;
  5921. this.handleOptions();
  5922. var _a = this.options, fetchFn = _a.fetch, renderFn = _a.render, createTombstoneFn = _a.createTombstone;
  5923. this.tombstone = new Tombstone(createTombstoneFn);
  5924. this.indexCalculator = new IndexCalculator(this.scroll.scroller.scrollBehaviorY.wrapperSize, this.tombstone.height);
  5925. this.domManager = new DomManager(this.scroll.scroller.content, renderFn, this.tombstone);
  5926. this.dataManager = new DataManager([], fetchFn, this.onFetchFinish.bind(this));
  5927. this.scroll.on(this.scroll.eventTypes.destroy, this.destroy, this);
  5928. this.scroll.on(this.scroll.eventTypes.scroll, this.update, this);
  5929. this.scroll.on(this.scroll.eventTypes.contentChanged, function (content) {
  5930. _this.domManager.setContent(content);
  5931. _this.indexCalculator.resetState();
  5932. _this.domManager.resetState();
  5933. _this.dataManager.resetState();
  5934. _this.update({ y: 0 });
  5935. });
  5936. var scrollBehaviorY = this.scroll.scroller.scrollBehaviorY;
  5937. scrollBehaviorY.hooks.on(scrollBehaviorY.hooks.eventTypes.computeBoundary, this.modifyBoundary, this);
  5938. this.update({ y: 0 });
  5939. };
  5940. InfinityScroll.prototype.modifyBoundary = function (boundary) {
  5941. // manually set position to allow scroll
  5942. boundary.maxScrollPos = EXTRA_SCROLL_Y;
  5943. };
  5944. InfinityScroll.prototype.handleOptions = function () {
  5945. // narrow down type to an object
  5946. var infinityOptions = this.scroll.options.infinity;
  5947. if (infinityOptions) {
  5948. if (typeof infinityOptions.fetch !== 'function') {
  5949. warn('Infinity plugin need fetch Function to new data.');
  5950. }
  5951. if (typeof infinityOptions.render !== 'function') {
  5952. warn('Infinity plugin need render Function to render each item.');
  5953. }
  5954. if (typeof infinityOptions.render !== 'function') {
  5955. warn('Infinity plugin need createTombstone Function to create tombstone.');
  5956. }
  5957. this.options = infinityOptions;
  5958. }
  5959. this.scroll.options.probeType = 3 /* Realtime */;
  5960. };
  5961. InfinityScroll.prototype.update = function (pos) {
  5962. var position = Math.round(-pos.y);
  5963. // important! calculate start/end index to render
  5964. var _a = this.indexCalculator.calculate(position, this.dataManager.getList()), start = _a.start, end = _a.end;
  5965. this.start = start;
  5966. this.end = end;
  5967. // tslint:disable-next-line: no-floating-promises
  5968. this.dataManager.update(end);
  5969. this.updateDom(this.dataManager.getList());
  5970. };
  5971. InfinityScroll.prototype.onFetchFinish = function (list, hasMore) {
  5972. var end = this.updateDom(list).end;
  5973. if (!hasMore) {
  5974. this.domManager.removeTombstone();
  5975. this.scroll.scroller.animater.stop();
  5976. this.scroll.resetPosition();
  5977. }
  5978. // tslint:disable-next-line: no-floating-promises
  5979. return end;
  5980. };
  5981. InfinityScroll.prototype.updateDom = function (list) {
  5982. var _a = this.domManager.update(list, this.start, this.end), end = _a.end, startPos = _a.startPos, endPos = _a.endPos, startDelta = _a.startDelta;
  5983. if (startDelta) {
  5984. this.scroll.minScrollY = startDelta;
  5985. }
  5986. if (endPos > this.scroll.maxScrollY) {
  5987. this.scroll.maxScrollY = -(endPos - this.scroll.scroller.scrollBehaviorY.wrapperSize);
  5988. }
  5989. return {
  5990. end: end,
  5991. startPos: startPos,
  5992. endPos: endPos,
  5993. };
  5994. };
  5995. InfinityScroll.prototype.destroy = function () {
  5996. var _a = this.scroll.scroller, content = _a.content, scrollBehaviorY = _a.scrollBehaviorY;
  5997. while (content.firstChild) {
  5998. content.removeChild(content.firstChild);
  5999. }
  6000. this.domManager.destroy();
  6001. this.scroll.off('scroll', this.update);
  6002. this.scroll.off('destroy', this.destroy);
  6003. scrollBehaviorY.hooks.off(scrollBehaviorY.hooks.eventTypes.computeBoundary);
  6004. };
  6005. InfinityScroll.pluginName = 'infinity';
  6006. return InfinityScroll;
  6007. }());
  6008. var sourcePrefix = 'plugins.movable';
  6009. var propertiesMap = [
  6010. {
  6011. key: 'putAt',
  6012. name: 'putAt',
  6013. },
  6014. ];
  6015. var propertiesConfig = propertiesMap.map(function (item) {
  6016. return {
  6017. key: item.key,
  6018. sourceKey: sourcePrefix + "." + item.name,
  6019. };
  6020. });
  6021. var Movable = /** @class */ (function () {
  6022. function Movable(scroll) {
  6023. this.scroll = scroll;
  6024. this.handleBScroll();
  6025. this.handleHooks();
  6026. }
  6027. Movable.prototype.handleBScroll = function () {
  6028. this.scroll.proxy(propertiesConfig);
  6029. };
  6030. Movable.prototype.handleHooks = function () {
  6031. var _this = this;
  6032. this.hooksFn = [];
  6033. var _a = this.scroll.scroller, scrollBehaviorX = _a.scrollBehaviorX, scrollBehaviorY = _a.scrollBehaviorY;
  6034. var computeBoundary = function (boundary, behavior) {
  6035. if (boundary.maxScrollPos > 0) {
  6036. // content is smaller than wrapper
  6037. boundary.minScrollPos = behavior.wrapperSize - behavior.contentSize;
  6038. boundary.maxScrollPos = 0;
  6039. }
  6040. };
  6041. this.registerHooks(scrollBehaviorX.hooks, scrollBehaviorX.hooks.eventTypes.ignoreHasScroll, function () { return true; });
  6042. this.registerHooks(scrollBehaviorX.hooks, scrollBehaviorX.hooks.eventTypes.computeBoundary, function (boundary) {
  6043. computeBoundary(boundary, scrollBehaviorX);
  6044. });
  6045. this.registerHooks(scrollBehaviorY.hooks, scrollBehaviorY.hooks.eventTypes.ignoreHasScroll, function () { return true; });
  6046. this.registerHooks(scrollBehaviorY.hooks, scrollBehaviorY.hooks.eventTypes.computeBoundary, function (boundary) {
  6047. computeBoundary(boundary, scrollBehaviorY);
  6048. });
  6049. this.registerHooks(this.scroll.hooks, this.scroll.hooks.eventTypes.destroy, function () {
  6050. _this.destroy();
  6051. });
  6052. };
  6053. Movable.prototype.putAt = function (x, y, time, easing) {
  6054. if (time === void 0) { time = this.scroll.options.bounceTime; }
  6055. if (easing === void 0) { easing = ease.bounce; }
  6056. var position = this.resolvePostion(x, y);
  6057. this.scroll.scrollTo(position.x, position.y, time, easing);
  6058. };
  6059. Movable.prototype.resolvePostion = function (x, y) {
  6060. var _a = this.scroll.scroller, scrollBehaviorX = _a.scrollBehaviorX, scrollBehaviorY = _a.scrollBehaviorY;
  6061. var resolveFormula = {
  6062. left: function () {
  6063. return 0;
  6064. },
  6065. top: function () {
  6066. return 0;
  6067. },
  6068. right: function () {
  6069. return scrollBehaviorX.minScrollPos;
  6070. },
  6071. bottom: function () {
  6072. return scrollBehaviorY.minScrollPos;
  6073. },
  6074. center: function (index) {
  6075. var baseSize = index === 0
  6076. ? scrollBehaviorX.minScrollPos
  6077. : scrollBehaviorY.minScrollPos;
  6078. return baseSize / 2;
  6079. },
  6080. };
  6081. return {
  6082. x: typeof x === 'number' ? x : resolveFormula[x](0),
  6083. y: typeof y === 'number' ? y : resolveFormula[y](1),
  6084. };
  6085. };
  6086. Movable.prototype.destroy = function () {
  6087. this.hooksFn.forEach(function (item) {
  6088. var hooks = item[0];
  6089. var hooksName = item[1];
  6090. var handlerFn = item[2];
  6091. hooks.off(hooksName, handlerFn);
  6092. });
  6093. this.hooksFn.length = 0;
  6094. };
  6095. Movable.prototype.registerHooks = function (hooks, name, handler) {
  6096. hooks.on(name, handler, this);
  6097. this.hooksFn.push([hooks, name, handler]);
  6098. };
  6099. Movable.pluginName = 'movable';
  6100. Movable.applyOrder = "pre" /* Pre */;
  6101. return Movable;
  6102. }());
  6103. var isImageTag = function (el) {
  6104. return el.tagName.toLowerCase() === 'img';
  6105. };
  6106. var ObserveImage = /** @class */ (function () {
  6107. function ObserveImage(scroll) {
  6108. this.scroll = scroll;
  6109. this.refreshTimer = 0;
  6110. this.init();
  6111. }
  6112. ObserveImage.prototype.init = function () {
  6113. this.handleOptions(this.scroll.options.observeImage);
  6114. this.bindEventsToWrapper();
  6115. };
  6116. ObserveImage.prototype.handleOptions = function (userOptions) {
  6117. if (userOptions === void 0) { userOptions = {}; }
  6118. userOptions = (userOptions === true ? {} : userOptions);
  6119. var defaultOptions = {
  6120. debounceTime: 100,
  6121. };
  6122. this.options = extend(defaultOptions, userOptions);
  6123. };
  6124. ObserveImage.prototype.bindEventsToWrapper = function () {
  6125. var wrapper = this.scroll.scroller.wrapper;
  6126. this.imageLoadEventRegister = new EventRegister(wrapper, [
  6127. {
  6128. name: 'load',
  6129. handler: this.load.bind(this),
  6130. capture: true,
  6131. },
  6132. ]);
  6133. this.imageErrorEventRegister = new EventRegister(wrapper, [
  6134. {
  6135. name: 'error',
  6136. handler: this.load.bind(this),
  6137. capture: true,
  6138. },
  6139. ]);
  6140. };
  6141. ObserveImage.prototype.load = function (e) {
  6142. var _this = this;
  6143. var target = e.target;
  6144. var debounceTime = this.options.debounceTime;
  6145. if (target && isImageTag(target)) {
  6146. if (debounceTime === 0) {
  6147. this.scroll.refresh();
  6148. }
  6149. else {
  6150. clearTimeout(this.refreshTimer);
  6151. this.refreshTimer = window.setTimeout(function () {
  6152. _this.scroll.refresh();
  6153. }, this.options.debounceTime);
  6154. }
  6155. }
  6156. };
  6157. ObserveImage.pluginName = 'observeImage';
  6158. return ObserveImage;
  6159. }());
  6160. var resolveRatioOption = function (ratioConfig) {
  6161. var ret = {
  6162. ratioX: 0,
  6163. ratioY: 0,
  6164. };
  6165. /* istanbul ignore if */
  6166. if (!ratioConfig) {
  6167. return ret;
  6168. }
  6169. if (typeof ratioConfig === 'number') {
  6170. ret.ratioX = ret.ratioY = ratioConfig;
  6171. }
  6172. else if (typeof ratioConfig === 'object' && ratioConfig) {
  6173. ret.ratioX = ratioConfig.x || 0;
  6174. ret.ratioY = ratioConfig.y || 0;
  6175. }
  6176. return ret;
  6177. };
  6178. var handleBubbleAndCancelable = function (e) {
  6179. e.preventDefault();
  6180. e.stopPropagation();
  6181. };
  6182. var Indicator = /** @class */ (function () {
  6183. function Indicator(scroll, options) {
  6184. this.scroll = scroll;
  6185. this.options = options;
  6186. this.currentPos = {
  6187. x: 0,
  6188. y: 0,
  6189. };
  6190. this.hooksFn = [];
  6191. this.handleDOM();
  6192. this.handleHooks();
  6193. this.handleInteractive();
  6194. }
  6195. Indicator.prototype.handleDOM = function () {
  6196. var _a = this.options, relationElement = _a.relationElement, _b = _a.relationElementHandleElementIndex, relationElementHandleElementIndex = _b === void 0 ? 0 : _b;
  6197. this.wrapper = relationElement;
  6198. this.indicatorEl = this.wrapper.children[relationElementHandleElementIndex];
  6199. };
  6200. Indicator.prototype.handleHooks = function () {
  6201. var _this = this;
  6202. var scroll = this.scroll;
  6203. var scrollHooks = scroll.hooks;
  6204. var translaterHooks = scroll.scroller.translater.hooks;
  6205. var animaterHooks = scroll.scroller.animater.hooks;
  6206. this.registerHooks(scrollHooks, scrollHooks.eventTypes.refresh, this.refresh);
  6207. this.registerHooks(translaterHooks, translaterHooks.eventTypes.translate, function (pos) {
  6208. _this.updatePosition(pos);
  6209. });
  6210. this.registerHooks(animaterHooks, animaterHooks.eventTypes.time, this.transitionTime);
  6211. this.registerHooks(animaterHooks, animaterHooks.eventTypes.timeFunction, this.transitionTimingFunction);
  6212. };
  6213. Indicator.prototype.transitionTime = function (time) {
  6214. if (time === void 0) { time = 0; }
  6215. this.indicatorEl.style[style.transitionDuration] = time + 'ms';
  6216. };
  6217. Indicator.prototype.transitionTimingFunction = function (easing) {
  6218. this.indicatorEl.style[style.transitionTimingFunction] = easing;
  6219. };
  6220. Indicator.prototype.handleInteractive = function () {
  6221. if (this.options.interactive !== false) {
  6222. this.registerEvents();
  6223. }
  6224. };
  6225. Indicator.prototype.registerHooks = function (hooks, name, handler) {
  6226. hooks.on(name, handler, this);
  6227. this.hooksFn.push([hooks, name, handler]);
  6228. };
  6229. Indicator.prototype.registerEvents = function () {
  6230. var _a = this.scroll.options, disableMouse = _a.disableMouse, disableTouch = _a.disableTouch;
  6231. var startEvents = [];
  6232. var moveEvents = [];
  6233. var endEvents = [];
  6234. if (!disableMouse) {
  6235. startEvents.push({
  6236. name: 'mousedown',
  6237. handler: this.start.bind(this),
  6238. });
  6239. moveEvents.push({
  6240. name: 'mousemove',
  6241. handler: this.move.bind(this),
  6242. });
  6243. endEvents.push({
  6244. name: 'mouseup',
  6245. handler: this.end.bind(this),
  6246. });
  6247. }
  6248. if (!disableTouch) {
  6249. startEvents.push({
  6250. name: 'touchstart',
  6251. handler: this.start.bind(this),
  6252. });
  6253. moveEvents.push({
  6254. name: 'touchmove',
  6255. handler: this.move.bind(this),
  6256. });
  6257. endEvents.push({
  6258. name: 'touchend',
  6259. handler: this.end.bind(this),
  6260. }, {
  6261. name: 'touchcancel',
  6262. handler: this.end.bind(this),
  6263. });
  6264. }
  6265. this.startEventRegister = new EventRegister(this.indicatorEl, startEvents);
  6266. this.moveEventRegister = new EventRegister(window, moveEvents);
  6267. this.endEventRegister = new EventRegister(window, endEvents);
  6268. };
  6269. Indicator.prototype.refresh = function () {
  6270. var _a = this.scroll, x = _a.x, y = _a.y, hasHorizontalScroll = _a.hasHorizontalScroll, hasVerticalScroll = _a.hasVerticalScroll, maxBScrollX = _a.maxScrollX, maxBScrollY = _a.maxScrollY;
  6271. var _b = resolveRatioOption(this.options.ratio), ratioX = _b.ratioX, ratioY = _b.ratioY;
  6272. var _c = getClientSize(this.wrapper), wrapperWidth = _c.width, wrapperHeight = _c.height;
  6273. var _d = getRect(this.indicatorEl), indicatorWidth = _d.width, indicatorHeight = _d.height;
  6274. if (hasHorizontalScroll) {
  6275. this.maxScrollX = wrapperWidth - indicatorWidth;
  6276. this.translateXSign =
  6277. this.maxScrollX > 0 ? -1 /* Positive */ : 1 /* NotPositive */;
  6278. this.minScrollX = 0;
  6279. // ensure positive
  6280. this.ratioX = ratioX ? ratioX : Math.abs(this.maxScrollX / maxBScrollX);
  6281. }
  6282. if (hasVerticalScroll) {
  6283. this.maxScrollY = wrapperHeight - indicatorHeight;
  6284. this.translateYSign =
  6285. this.maxScrollY > 0 ? -1 /* Positive */ : 1 /* NotPositive */;
  6286. this.minScrollY = 0;
  6287. this.ratioY = ratioY ? ratioY : Math.abs(this.maxScrollY / maxBScrollY);
  6288. }
  6289. this.updatePosition({
  6290. x: x,
  6291. y: y,
  6292. });
  6293. };
  6294. Indicator.prototype.start = function (e) {
  6295. if (this.BScrollIsDisabled()) {
  6296. return;
  6297. }
  6298. var point = (e.touches ? e.touches[0] : e);
  6299. handleBubbleAndCancelable(e);
  6300. this.initiated = true;
  6301. this.moved = false;
  6302. this.lastPointX = point.pageX;
  6303. this.lastPointY = point.pageY;
  6304. this.startTime = getNow();
  6305. this.scroll.scroller.hooks.trigger(this.scroll.scroller.hooks.eventTypes.beforeScrollStart);
  6306. };
  6307. Indicator.prototype.BScrollIsDisabled = function () {
  6308. return !this.scroll.enabled;
  6309. };
  6310. Indicator.prototype.move = function (e) {
  6311. if (!this.initiated) {
  6312. return;
  6313. }
  6314. var point = (e.touches ? e.touches[0] : e);
  6315. var pointX = point.pageX;
  6316. var pointY = point.pageY;
  6317. handleBubbleAndCancelable(e);
  6318. var deltaX = pointX - this.lastPointX;
  6319. var deltaY = pointY - this.lastPointY;
  6320. this.lastPointX = pointX;
  6321. this.lastPointY = pointY;
  6322. if (!this.moved && !this.indicatorNotMoved(deltaX, deltaY)) {
  6323. this.moved = true;
  6324. this.scroll.scroller.hooks.trigger(this.scroll.scroller.hooks.eventTypes.scrollStart);
  6325. }
  6326. if (this.moved) {
  6327. var newPos = this.getBScrollPosByRatio(this.currentPos, deltaX, deltaY);
  6328. this.syncBScroll(newPos);
  6329. }
  6330. };
  6331. Indicator.prototype.end = function (e) {
  6332. if (!this.initiated) {
  6333. return;
  6334. }
  6335. this.initiated = false;
  6336. handleBubbleAndCancelable(e);
  6337. if (this.moved) {
  6338. var _a = this.scroll, x = _a.x, y = _a.y;
  6339. this.scroll.scroller.hooks.trigger(this.scroll.scroller.hooks.eventTypes.scrollEnd, {
  6340. x: x,
  6341. y: y,
  6342. });
  6343. }
  6344. };
  6345. Indicator.prototype.getBScrollPosByRatio = function (currentPos, deltaX, deltaY) {
  6346. var currentX = currentPos.x, currentY = currentPos.y;
  6347. var _a = this.scroll, hasHorizontalScroll = _a.hasHorizontalScroll, hasVerticalScroll = _a.hasVerticalScroll, BScrollMinScrollX = _a.minScrollX, BScrollMaxScrollX = _a.maxScrollX, BScrollMinScrollY = _a.minScrollY, BScrollMaxScrollY = _a.maxScrollY;
  6348. var _b = this.scroll, x = _b.x, y = _b.y;
  6349. if (hasHorizontalScroll) {
  6350. var newPosX = between(currentX + deltaX, Math.min(this.minScrollX, this.maxScrollX), Math.max(this.minScrollX, this.maxScrollX));
  6351. var roundX = Math.round((newPosX / this.ratioX) * this.translateXSign);
  6352. x = between(roundX, BScrollMaxScrollX, BScrollMinScrollX);
  6353. }
  6354. if (hasVerticalScroll) {
  6355. var newPosY = between(currentY + deltaY, Math.min(this.minScrollY, this.maxScrollY), Math.max(this.minScrollY, this.maxScrollY));
  6356. var roundY = Math.round((newPosY / this.ratioY) * this.translateYSign);
  6357. y = between(roundY, BScrollMaxScrollY, BScrollMinScrollY);
  6358. }
  6359. return { x: x, y: y };
  6360. };
  6361. Indicator.prototype.indicatorNotMoved = function (deltaX, deltaY) {
  6362. var _a = this.currentPos, x = _a.x, y = _a.y;
  6363. var xNotMoved = (x === this.minScrollX && deltaX <= 0) ||
  6364. (x === this.maxScrollX && deltaX >= 0);
  6365. var yNotMoved = (y === this.minScrollY && deltaY <= 0) ||
  6366. (y === this.maxScrollY && deltaY >= 0);
  6367. return xNotMoved && yNotMoved;
  6368. };
  6369. Indicator.prototype.syncBScroll = function (newPos) {
  6370. var timestamp = getNow();
  6371. var _a = this.scroll, options = _a.options, scroller = _a.scroller;
  6372. var probeType = options.probeType, momentumLimitTime = options.momentumLimitTime;
  6373. scroller.translater.translate(newPos);
  6374. // dispatch scroll in interval time
  6375. if (timestamp - this.startTime > momentumLimitTime) {
  6376. this.startTime = timestamp;
  6377. if (probeType === 1 /* Throttle */) {
  6378. scroller.hooks.trigger(scroller.hooks.eventTypes.scroll, newPos);
  6379. }
  6380. }
  6381. // dispatch scroll all the time
  6382. if (probeType > 1 /* Throttle */) {
  6383. scroller.hooks.trigger(scroller.hooks.eventTypes.scroll, newPos);
  6384. }
  6385. };
  6386. Indicator.prototype.updatePosition = function (BScrollPos) {
  6387. var newIndicatorPos = this.getIndicatorPosByRatio(BScrollPos);
  6388. this.applyTransformProperty(newIndicatorPos);
  6389. this.currentPos = __assign({}, newIndicatorPos);
  6390. };
  6391. Indicator.prototype.applyTransformProperty = function (pos) {
  6392. var translateZ = this.scroll.options.translateZ;
  6393. var transformProperties = [
  6394. "translateX(" + pos.x + "px)",
  6395. "translateY(" + pos.y + "px)",
  6396. "" + translateZ,
  6397. ];
  6398. this.indicatorEl.style[style.transform] = transformProperties.join(' ');
  6399. };
  6400. Indicator.prototype.getIndicatorPosByRatio = function (BScrollPos) {
  6401. var x = BScrollPos.x, y = BScrollPos.y;
  6402. var _a = this.scroll, hasHorizontalScroll = _a.hasHorizontalScroll, hasVerticalScroll = _a.hasVerticalScroll;
  6403. var position = __assign({}, this.currentPos);
  6404. if (hasHorizontalScroll) {
  6405. var roundX = Math.round(this.ratioX * x * this.translateXSign);
  6406. // maybe maxScrollX is negative
  6407. position.x = between(roundX, Math.min(this.minScrollX, this.maxScrollX), Math.max(this.minScrollX, this.maxScrollX));
  6408. }
  6409. if (hasVerticalScroll) {
  6410. var roundY = Math.round(this.ratioY * y * this.translateYSign);
  6411. // maybe maxScrollY is negative
  6412. position.y = between(roundY, Math.min(this.minScrollY, this.maxScrollY), Math.max(this.minScrollY, this.maxScrollY));
  6413. }
  6414. return position;
  6415. };
  6416. Indicator.prototype.destroy = function () {
  6417. if (this.options.interactive !== false) {
  6418. this.startEventRegister.destroy();
  6419. this.moveEventRegister.destroy();
  6420. this.endEventRegister.destroy();
  6421. }
  6422. this.hooksFn.forEach(function (item) {
  6423. var hooks = item[0];
  6424. var hooksName = item[1];
  6425. var handlerFn = item[2];
  6426. hooks.off(hooksName, handlerFn);
  6427. });
  6428. this.hooksFn.length = 0;
  6429. };
  6430. return Indicator;
  6431. }());
  6432. var Indicators = /** @class */ (function () {
  6433. function Indicators(scroll) {
  6434. this.scroll = scroll;
  6435. this.options = [];
  6436. this.indicators = [];
  6437. this.handleOptions();
  6438. this.handleHooks();
  6439. }
  6440. Indicators.prototype.handleOptions = function () {
  6441. var UserIndicatorsOptions = this.scroll.options.indicators;
  6442. assert(Array.isArray(UserIndicatorsOptions), "'indicators' must be an array.");
  6443. for (var _i = 0, UserIndicatorsOptions_1 = UserIndicatorsOptions; _i < UserIndicatorsOptions_1.length; _i++) {
  6444. var indicatorOptions = UserIndicatorsOptions_1[_i];
  6445. assert(!!indicatorOptions.relationElement, "'relationElement' must be a HTMLElement.");
  6446. this.createIndicators(indicatorOptions);
  6447. }
  6448. };
  6449. Indicators.prototype.createIndicators = function (options) {
  6450. this.indicators.push(new Indicator(this.scroll, options));
  6451. };
  6452. Indicators.prototype.handleHooks = function () {
  6453. var _this = this;
  6454. var scrollHooks = this.scroll.hooks;
  6455. scrollHooks.on(scrollHooks.eventTypes.destroy, function () {
  6456. for (var _i = 0, _a = _this.indicators; _i < _a.length; _i++) {
  6457. var indicator = _a[_i];
  6458. indicator.destroy();
  6459. }
  6460. _this.indicators = [];
  6461. });
  6462. };
  6463. Indicators.pluginName = 'indicators';
  6464. return Indicators;
  6465. }());
  6466. BScroll.use(MouseWheel)
  6467. .use(ObserveDOM)
  6468. .use(PullDown)
  6469. .use(PullUp)
  6470. .use(ScrollBar)
  6471. .use(Slide)
  6472. .use(Wheel)
  6473. .use(Zoom)
  6474. .use(NestedScroll)
  6475. .use(InfinityScroll)
  6476. .use(Movable)
  6477. .use(ObserveImage)
  6478. .use(Indicators);
  6479. export default BScroll;
  6480. export { Behavior, CustomOptions, Indicators, InfinityScroll, MouseWheel, Movable, NestedScroll, ObserveDOM as ObserveDom, ObserveImage, PullDown as PullDownRefresh, PullUp as PullUpLoad, ScrollBar, Slide, Wheel, Zoom, createBScroll };