123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546 |
- /*!
- * better-scroll / better-scroll
- * (c) 2016-2021 ustbhuangyi
- * Released under the MIT License.
- */
- /*! *****************************************************************************
- Copyright (c) Microsoft Corporation.
- Permission to use, copy, modify, and/or distribute this software for any
- purpose with or without fee is hereby granted.
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- PERFORMANCE OF THIS SOFTWARE.
- ***************************************************************************** */
- /* global Reflect, Promise */
- var extendStatics = function(d, b) {
- extendStatics = Object.setPrototypeOf ||
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
- return extendStatics(d, b);
- };
- function __extends(d, b) {
- extendStatics(d, b);
- function __() { this.constructor = d; }
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
- }
- var __assign = function() {
- __assign = Object.assign || function __assign(t) {
- for (var s, i = 1, n = arguments.length; i < n; i++) {
- s = arguments[i];
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
- }
- return t;
- };
- return __assign.apply(this, arguments);
- };
- function __awaiter(thisArg, _arguments, P, generator) {
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
- return new (P || (P = Promise))(function (resolve, reject) {
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
- step((generator = generator.apply(thisArg, _arguments || [])).next());
- });
- }
- function __generator(thisArg, body) {
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
- function verb(n) { return function (v) { return step([n, v]); }; }
- function step(op) {
- if (f) throw new TypeError("Generator is already executing.");
- while (_) try {
- 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;
- if (y = 0, t) op = [op[0] & 2, t.value];
- switch (op[0]) {
- case 0: case 1: t = op; break;
- case 4: _.label++; return { value: op[1], done: false };
- case 5: _.label++; y = op[1]; op = [0]; continue;
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
- default:
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
- if (t[2]) _.ops.pop();
- _.trys.pop(); continue;
- }
- op = body.call(thisArg, _);
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
- }
- }
- function __spreadArrays() {
- for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
- for (var r = Array(s), k = 0, i = 0; i < il; i++)
- for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
- r[k] = a[j];
- return r;
- }
- var propertiesConfig$7 = [
- {
- sourceKey: 'scroller.scrollBehaviorX.currentPos',
- key: 'x'
- },
- {
- sourceKey: 'scroller.scrollBehaviorY.currentPos',
- key: 'y'
- },
- {
- sourceKey: 'scroller.scrollBehaviorX.hasScroll',
- key: 'hasHorizontalScroll'
- },
- {
- sourceKey: 'scroller.scrollBehaviorY.hasScroll',
- key: 'hasVerticalScroll'
- },
- {
- sourceKey: 'scroller.scrollBehaviorX.contentSize',
- key: 'scrollerWidth'
- },
- {
- sourceKey: 'scroller.scrollBehaviorY.contentSize',
- key: 'scrollerHeight'
- },
- {
- sourceKey: 'scroller.scrollBehaviorX.maxScrollPos',
- key: 'maxScrollX'
- },
- {
- sourceKey: 'scroller.scrollBehaviorY.maxScrollPos',
- key: 'maxScrollY'
- },
- {
- sourceKey: 'scroller.scrollBehaviorX.minScrollPos',
- key: 'minScrollX'
- },
- {
- sourceKey: 'scroller.scrollBehaviorY.minScrollPos',
- key: 'minScrollY'
- },
- {
- sourceKey: 'scroller.scrollBehaviorX.movingDirection',
- key: 'movingDirectionX'
- },
- {
- sourceKey: 'scroller.scrollBehaviorY.movingDirection',
- key: 'movingDirectionY'
- },
- {
- sourceKey: 'scroller.scrollBehaviorX.direction',
- key: 'directionX'
- },
- {
- sourceKey: 'scroller.scrollBehaviorY.direction',
- key: 'directionY'
- },
- {
- sourceKey: 'scroller.actions.enabled',
- key: 'enabled'
- },
- {
- sourceKey: 'scroller.animater.pending',
- key: 'pending'
- },
- {
- sourceKey: 'scroller.animater.stop',
- key: 'stop'
- },
- {
- sourceKey: 'scroller.scrollTo',
- key: 'scrollTo'
- },
- {
- sourceKey: 'scroller.scrollBy',
- key: 'scrollBy'
- },
- {
- sourceKey: 'scroller.scrollToElement',
- key: 'scrollToElement'
- },
- {
- sourceKey: 'scroller.resetPosition',
- key: 'resetPosition'
- }
- ];
- function warn(msg) {
- console.error("[BScroll warn]: " + msg);
- }
- function assert(condition, msg) {
- if (!condition) {
- throw new Error('[BScroll] ' + msg);
- }
- }
- // ssr support
- var inBrowser = typeof window !== 'undefined';
- var ua = inBrowser && navigator.userAgent.toLowerCase();
- var isWeChatDevTools = !!(ua && /wechatdevtools/.test(ua));
- var isAndroid = ua && ua.indexOf('android') > 0;
- /* istanbul ignore next */
- var isIOSBadVersion = (function () {
- if (typeof ua === 'string') {
- var regex = /os (\d\d?_\d(_\d)?)/;
- var matches = regex.exec(ua);
- if (!matches)
- return false;
- var parts = matches[1].split('_').map(function (item) {
- return parseInt(item, 10);
- });
- // ios version >= 13.4 issue 982
- return !!(parts[0] === 13 && parts[1] >= 4);
- }
- return false;
- })();
- /* istanbul ignore next */
- var supportsPassive = false;
- /* istanbul ignore next */
- if (inBrowser) {
- var EventName = 'test-passive';
- try {
- var opts = {};
- Object.defineProperty(opts, 'passive', {
- get: function () {
- supportsPassive = true;
- },
- }); // https://github.com/facebook/flow/issues/285
- window.addEventListener(EventName, function () { }, opts);
- }
- catch (e) { }
- }
- function getNow() {
- return window.performance &&
- window.performance.now &&
- window.performance.timing
- ? window.performance.now() + window.performance.timing.navigationStart
- : +new Date();
- }
- var extend = function (target, source) {
- for (var key in source) {
- target[key] = source[key];
- }
- return target;
- };
- function isUndef(v) {
- return v === undefined || v === null;
- }
- function getDistance(x, y) {
- return Math.sqrt(x * x + y * y);
- }
- function between(x, min, max) {
- if (x < min) {
- return min;
- }
- if (x > max) {
- return max;
- }
- return x;
- }
- function findIndex(ary, fn) {
- if (ary.findIndex) {
- return ary.findIndex(fn);
- }
- var index = -1;
- ary.some(function (item, i, ary) {
- var ret = fn(item, i, ary);
- if (ret) {
- index = i;
- return ret;
- }
- });
- return index;
- }
- var elementStyle = (inBrowser &&
- document.createElement('div').style);
- var vendor = (function () {
- /* istanbul ignore if */
- if (!inBrowser) {
- return false;
- }
- var transformNames = [
- {
- key: 'standard',
- value: 'transform',
- },
- {
- key: 'webkit',
- value: 'webkitTransform',
- },
- {
- key: 'Moz',
- value: 'MozTransform',
- },
- {
- key: 'O',
- value: 'OTransform',
- },
- {
- key: 'ms',
- value: 'msTransform',
- },
- ];
- for (var _i = 0, transformNames_1 = transformNames; _i < transformNames_1.length; _i++) {
- var obj = transformNames_1[_i];
- if (elementStyle[obj.value] !== undefined) {
- return obj.key;
- }
- }
- /* istanbul ignore next */
- return false;
- })();
- /* istanbul ignore next */
- function prefixStyle(style) {
- if (vendor === false) {
- return style;
- }
- if (vendor === 'standard') {
- if (style === 'transitionEnd') {
- return 'transitionend';
- }
- return style;
- }
- return vendor + style.charAt(0).toUpperCase() + style.substr(1);
- }
- function getElement(el) {
- return (typeof el === 'string'
- ? document.querySelector(el)
- : el);
- }
- function addEvent(el, type, fn, capture) {
- var useCapture = supportsPassive
- ? {
- passive: false,
- capture: !!capture,
- }
- : !!capture;
- el.addEventListener(type, fn, useCapture);
- }
- function removeEvent(el, type, fn, capture) {
- el.removeEventListener(type, fn, {
- capture: !!capture,
- });
- }
- function offset(el) {
- var left = 0;
- var top = 0;
- while (el) {
- left -= el.offsetLeft;
- top -= el.offsetTop;
- el = el.offsetParent;
- }
- return {
- left: left,
- top: top,
- };
- }
- function offsetToBody(el) {
- var rect = el.getBoundingClientRect();
- return {
- left: -(rect.left + window.pageXOffset),
- top: -(rect.top + window.pageYOffset),
- };
- }
- var cssVendor = vendor && vendor !== 'standard' ? '-' + vendor.toLowerCase() + '-' : '';
- var transform = prefixStyle('transform');
- var transition = prefixStyle('transition');
- var hasPerspective = inBrowser && prefixStyle('perspective') in elementStyle;
- // fix issue #361
- var hasTouch = inBrowser && ('ontouchstart' in window || isWeChatDevTools);
- var hasTransition = inBrowser && transition in elementStyle;
- var style = {
- transform: transform,
- transition: transition,
- transitionTimingFunction: prefixStyle('transitionTimingFunction'),
- transitionDuration: prefixStyle('transitionDuration'),
- transitionDelay: prefixStyle('transitionDelay'),
- transformOrigin: prefixStyle('transformOrigin'),
- transitionEnd: prefixStyle('transitionEnd'),
- transitionProperty: prefixStyle('transitionProperty'),
- };
- var eventTypeMap = {
- touchstart: 1,
- touchmove: 1,
- touchend: 1,
- touchcancel: 1,
- mousedown: 2,
- mousemove: 2,
- mouseup: 2,
- };
- function getRect(el) {
- /* istanbul ignore if */
- if (el instanceof window.SVGElement) {
- var rect = el.getBoundingClientRect();
- return {
- top: rect.top,
- left: rect.left,
- width: rect.width,
- height: rect.height,
- };
- }
- else {
- return {
- top: el.offsetTop,
- left: el.offsetLeft,
- width: el.offsetWidth,
- height: el.offsetHeight,
- };
- }
- }
- function preventDefaultExceptionFn(el, exceptions) {
- for (var i in exceptions) {
- if (exceptions[i].test(el[i])) {
- return true;
- }
- }
- return false;
- }
- var tagExceptionFn = preventDefaultExceptionFn;
- function tap(e, eventName) {
- var ev = document.createEvent('Event');
- ev.initEvent(eventName, true, true);
- ev.pageX = e.pageX;
- ev.pageY = e.pageY;
- e.target.dispatchEvent(ev);
- }
- function click(e, event) {
- if (event === void 0) { event = 'click'; }
- var eventSource;
- if (e.type === 'mouseup') {
- eventSource = e;
- }
- else if (e.type === 'touchend' || e.type === 'touchcancel') {
- eventSource = e.changedTouches[0];
- }
- var posSrc = {};
- if (eventSource) {
- posSrc.screenX = eventSource.screenX || 0;
- posSrc.screenY = eventSource.screenY || 0;
- posSrc.clientX = eventSource.clientX || 0;
- posSrc.clientY = eventSource.clientY || 0;
- }
- var ev;
- var bubbles = true;
- var cancelable = true;
- var ctrlKey = e.ctrlKey, shiftKey = e.shiftKey, altKey = e.altKey, metaKey = e.metaKey;
- var pressedKeysMap = {
- ctrlKey: ctrlKey,
- shiftKey: shiftKey,
- altKey: altKey,
- metaKey: metaKey,
- };
- if (typeof MouseEvent !== 'undefined') {
- try {
- ev = new MouseEvent(event, extend(__assign({ bubbles: bubbles,
- cancelable: cancelable }, pressedKeysMap), posSrc));
- }
- catch (e) {
- /* istanbul ignore next */
- createEvent();
- }
- }
- else {
- createEvent();
- }
- function createEvent() {
- ev = document.createEvent('Event');
- ev.initEvent(event, bubbles, cancelable);
- extend(ev, posSrc);
- }
- // forwardedTouchEvent set to true in case of the conflict with fastclick
- ev.forwardedTouchEvent = true;
- ev._constructed = true;
- e.target.dispatchEvent(ev);
- }
- function dblclick(e) {
- click(e, 'dblclick');
- }
- function prepend(el, target) {
- var firstChild = target.firstChild;
- if (firstChild) {
- before(el, firstChild);
- }
- else {
- target.appendChild(el);
- }
- }
- function before(el, target) {
- var parentNode = target.parentNode;
- parentNode.insertBefore(el, target);
- }
- function removeChild(el, child) {
- el.removeChild(child);
- }
- function hasClass(el, className) {
- var reg = new RegExp('(^|\\s)' + className + '(\\s|$)');
- return reg.test(el.className);
- }
- function HTMLCollectionToArray(el) {
- return Array.prototype.slice.call(el, 0);
- }
- function getClientSize(el) {
- return {
- width: el.clientWidth,
- height: el.clientHeight,
- };
- }
- var ease = {
- // easeOutQuint
- swipe: {
- style: 'cubic-bezier(0.23, 1, 0.32, 1)',
- fn: function (t) {
- return 1 + --t * t * t * t * t;
- }
- },
- // easeOutQuard
- swipeBounce: {
- style: 'cubic-bezier(0.25, 0.46, 0.45, 0.94)',
- fn: function (t) {
- return t * (2 - t);
- }
- },
- // easeOutQuart
- bounce: {
- style: 'cubic-bezier(0.165, 0.84, 0.44, 1)',
- fn: function (t) {
- return 1 - --t * t * t * t;
- }
- }
- };
- var DEFAULT_INTERVAL = 1000 / 60;
- var windowCompat = inBrowser && window;
- /* istanbul ignore next */
- function noop$1() { }
- var requestAnimationFrame = (function () {
- /* istanbul ignore if */
- if (!inBrowser) {
- return noop$1;
- }
- return (windowCompat.requestAnimationFrame ||
- windowCompat.webkitRequestAnimationFrame ||
- windowCompat.mozRequestAnimationFrame ||
- windowCompat.oRequestAnimationFrame ||
- // if all else fails, use setTimeout
- function (callback) {
- return window.setTimeout(callback, callback.interval || DEFAULT_INTERVAL); // make interval as precise as possible.
- });
- })();
- var cancelAnimationFrame = (function () {
- /* istanbul ignore if */
- if (!inBrowser) {
- return noop$1;
- }
- return (windowCompat.cancelAnimationFrame ||
- windowCompat.webkitCancelAnimationFrame ||
- windowCompat.mozCancelAnimationFrame ||
- windowCompat.oCancelAnimationFrame ||
- function (id) {
- window.clearTimeout(id);
- });
- })();
- /* istanbul ignore next */
- var noop = function (val) { };
- var sharedPropertyDefinition = {
- enumerable: true,
- configurable: true,
- get: noop,
- set: noop,
- };
- var getProperty = function (obj, key) {
- var keys = key.split('.');
- for (var i = 0; i < keys.length - 1; i++) {
- obj = obj[keys[i]];
- if (typeof obj !== 'object' || !obj)
- return;
- }
- var lastKey = keys.pop();
- if (typeof obj[lastKey] === 'function') {
- return function () {
- return obj[lastKey].apply(obj, arguments);
- };
- }
- else {
- return obj[lastKey];
- }
- };
- var setProperty = function (obj, key, value) {
- var keys = key.split('.');
- var temp;
- for (var i = 0; i < keys.length - 1; i++) {
- temp = keys[i];
- if (!obj[temp])
- obj[temp] = {};
- obj = obj[temp];
- }
- obj[keys.pop()] = value;
- };
- function propertiesProxy(target, sourceKey, key) {
- sharedPropertyDefinition.get = function proxyGetter() {
- return getProperty(this, sourceKey);
- };
- sharedPropertyDefinition.set = function proxySetter(val) {
- setProperty(this, sourceKey, val);
- };
- Object.defineProperty(target, key, sharedPropertyDefinition);
- }
- var EventEmitter = /** @class */ (function () {
- function EventEmitter(names) {
- this.events = {};
- this.eventTypes = {};
- this.registerType(names);
- }
- EventEmitter.prototype.on = function (type, fn, context) {
- if (context === void 0) { context = this; }
- this.hasType(type);
- if (!this.events[type]) {
- this.events[type] = [];
- }
- this.events[type].push([fn, context]);
- return this;
- };
- EventEmitter.prototype.once = function (type, fn, context) {
- var _this = this;
- if (context === void 0) { context = this; }
- this.hasType(type);
- var magic = function () {
- var args = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- args[_i] = arguments[_i];
- }
- _this.off(type, magic);
- var ret = fn.apply(context, args);
- if (ret === true) {
- return ret;
- }
- };
- magic.fn = fn;
- this.on(type, magic);
- return this;
- };
- EventEmitter.prototype.off = function (type, fn) {
- if (!type && !fn) {
- this.events = {};
- return this;
- }
- if (type) {
- this.hasType(type);
- if (!fn) {
- this.events[type] = [];
- return this;
- }
- var events = this.events[type];
- if (!events) {
- return this;
- }
- var count = events.length;
- while (count--) {
- if (events[count][0] === fn ||
- (events[count][0] && events[count][0].fn === fn)) {
- events.splice(count, 1);
- }
- }
- return this;
- }
- };
- EventEmitter.prototype.trigger = function (type) {
- var args = [];
- for (var _i = 1; _i < arguments.length; _i++) {
- args[_i - 1] = arguments[_i];
- }
- this.hasType(type);
- var events = this.events[type];
- if (!events) {
- return;
- }
- var len = events.length;
- var eventsCopy = __spreadArrays(events);
- var ret;
- for (var i = 0; i < len; i++) {
- var event_1 = eventsCopy[i];
- var fn = event_1[0], context = event_1[1];
- if (fn) {
- ret = fn.apply(context, args);
- if (ret === true) {
- return ret;
- }
- }
- }
- };
- EventEmitter.prototype.registerType = function (names) {
- var _this = this;
- names.forEach(function (type) {
- _this.eventTypes[type] = type;
- });
- };
- EventEmitter.prototype.destroy = function () {
- this.events = {};
- this.eventTypes = {};
- };
- EventEmitter.prototype.hasType = function (type) {
- var types = this.eventTypes;
- var isType = types[type] === type;
- if (!isType) {
- warn("EventEmitter has used unknown event type: \"" + type + "\", should be oneof [" +
- ("" + Object.keys(types).map(function (_) { return JSON.stringify(_); })) +
- "]");
- }
- };
- return EventEmitter;
- }());
- var EventRegister = /** @class */ (function () {
- function EventRegister(wrapper, events) {
- this.wrapper = wrapper;
- this.events = events;
- this.addDOMEvents();
- }
- EventRegister.prototype.destroy = function () {
- this.removeDOMEvents();
- this.events = [];
- };
- EventRegister.prototype.addDOMEvents = function () {
- this.handleDOMEvents(addEvent);
- };
- EventRegister.prototype.removeDOMEvents = function () {
- this.handleDOMEvents(removeEvent);
- };
- EventRegister.prototype.handleDOMEvents = function (eventOperation) {
- var _this = this;
- var wrapper = this.wrapper;
- this.events.forEach(function (event) {
- eventOperation(wrapper, event.name, _this, !!event.capture);
- });
- };
- EventRegister.prototype.handleEvent = function (e) {
- var eventType = e.type;
- this.events.some(function (event) {
- if (event.name === eventType) {
- event.handler(e);
- return true;
- }
- return false;
- });
- };
- return EventRegister;
- }());
- var CustomOptions = /** @class */ (function () {
- function CustomOptions() {
- }
- return CustomOptions;
- }());
- var OptionsConstructor = /** @class */ (function (_super) {
- __extends(OptionsConstructor, _super);
- function OptionsConstructor() {
- var _this = _super.call(this) || this;
- _this.startX = 0;
- _this.startY = 0;
- _this.scrollX = false;
- _this.scrollY = true;
- _this.freeScroll = false;
- _this.directionLockThreshold = 0;
- _this.eventPassthrough = "" /* None */;
- _this.click = false;
- _this.dblclick = false;
- _this.tap = '';
- _this.bounce = {
- top: true,
- bottom: true,
- left: true,
- right: true,
- };
- _this.bounceTime = 800;
- _this.momentum = true;
- _this.momentumLimitTime = 300;
- _this.momentumLimitDistance = 15;
- _this.swipeTime = 2500;
- _this.swipeBounceTime = 500;
- _this.deceleration = 0.0015;
- _this.flickLimitTime = 200;
- _this.flickLimitDistance = 100;
- _this.resizePolling = 60;
- _this.probeType = 0 /* Default */;
- _this.stopPropagation = false;
- _this.preventDefault = true;
- _this.preventDefaultException = {
- tagName: /^(INPUT|TEXTAREA|BUTTON|SELECT|AUDIO)$/,
- };
- _this.tagException = {
- tagName: /^TEXTAREA$/,
- };
- _this.HWCompositing = true;
- _this.useTransition = true;
- _this.bindToWrapper = false;
- _this.bindToTarget = false;
- _this.disableMouse = hasTouch;
- _this.disableTouch = !hasTouch;
- _this.autoBlur = true;
- _this.autoEndDistance = 5;
- _this.outOfBoundaryDampingFactor = 1 / 3;
- _this.specifiedIndexAsContent = 0;
- _this.quadrant = 1 /* First */;
- return _this;
- }
- OptionsConstructor.prototype.merge = function (options) {
- if (!options)
- return this;
- for (var key in options) {
- if (key === 'bounce') {
- this.bounce = this.resolveBounce(options[key]);
- continue;
- }
- this[key] = options[key];
- }
- return this;
- };
- OptionsConstructor.prototype.process = function () {
- this.translateZ =
- this.HWCompositing && hasPerspective ? ' translateZ(1px)' : '';
- this.useTransition = this.useTransition && hasTransition;
- this.preventDefault = !this.eventPassthrough && this.preventDefault;
- // If you want eventPassthrough I have to lock one of the axes
- this.scrollX =
- this.eventPassthrough === "horizontal" /* Horizontal */
- ? false
- : this.scrollX;
- this.scrollY =
- this.eventPassthrough === "vertical" /* Vertical */ ? false : this.scrollY;
- // With eventPassthrough we also need lockDirection mechanism
- this.freeScroll = this.freeScroll && !this.eventPassthrough;
- // force true when freeScroll is true
- this.scrollX = this.freeScroll ? true : this.scrollX;
- this.scrollY = this.freeScroll ? true : this.scrollY;
- this.directionLockThreshold = this.eventPassthrough
- ? 0
- : this.directionLockThreshold;
- return this;
- };
- OptionsConstructor.prototype.resolveBounce = function (bounceOptions) {
- var DEFAULT_BOUNCE = {
- top: true,
- right: true,
- bottom: true,
- left: true,
- };
- var NEGATED_BOUNCE = {
- top: false,
- right: false,
- bottom: false,
- left: false,
- };
- var ret;
- if (typeof bounceOptions === 'object') {
- ret = extend(DEFAULT_BOUNCE, bounceOptions);
- }
- else {
- ret = bounceOptions ? DEFAULT_BOUNCE : NEGATED_BOUNCE;
- }
- return ret;
- };
- return OptionsConstructor;
- }(CustomOptions));
- var ActionsHandler = /** @class */ (function () {
- function ActionsHandler(wrapper, options) {
- this.wrapper = wrapper;
- this.options = options;
- this.hooks = new EventEmitter([
- 'beforeStart',
- 'start',
- 'move',
- 'end',
- 'click',
- ]);
- this.handleDOMEvents();
- }
- ActionsHandler.prototype.handleDOMEvents = function () {
- var _a = this.options, bindToWrapper = _a.bindToWrapper, disableMouse = _a.disableMouse, disableTouch = _a.disableTouch, click = _a.click;
- var wrapper = this.wrapper;
- var target = bindToWrapper ? wrapper : window;
- var wrapperEvents = [];
- var targetEvents = [];
- var shouldRegisterTouch = !disableTouch;
- var shouldRegisterMouse = !disableMouse;
- if (click) {
- wrapperEvents.push({
- name: 'click',
- handler: this.click.bind(this),
- capture: true,
- });
- }
- if (shouldRegisterTouch) {
- wrapperEvents.push({
- name: 'touchstart',
- handler: this.start.bind(this),
- });
- targetEvents.push({
- name: 'touchmove',
- handler: this.move.bind(this),
- }, {
- name: 'touchend',
- handler: this.end.bind(this),
- }, {
- name: 'touchcancel',
- handler: this.end.bind(this),
- });
- }
- if (shouldRegisterMouse) {
- wrapperEvents.push({
- name: 'mousedown',
- handler: this.start.bind(this),
- });
- targetEvents.push({
- name: 'mousemove',
- handler: this.move.bind(this),
- }, {
- name: 'mouseup',
- handler: this.end.bind(this),
- });
- }
- this.wrapperEventRegister = new EventRegister(wrapper, wrapperEvents);
- this.targetEventRegister = new EventRegister(target, targetEvents);
- };
- ActionsHandler.prototype.beforeHandler = function (e, type) {
- var _a = this.options, preventDefault = _a.preventDefault, stopPropagation = _a.stopPropagation, preventDefaultException = _a.preventDefaultException;
- var preventDefaultConditions = {
- start: function () {
- return (preventDefault &&
- !preventDefaultExceptionFn(e.target, preventDefaultException));
- },
- end: function () {
- return (preventDefault &&
- !preventDefaultExceptionFn(e.target, preventDefaultException));
- },
- move: function () {
- return preventDefault;
- },
- };
- if (preventDefaultConditions[type]()) {
- e.preventDefault();
- }
- if (stopPropagation) {
- e.stopPropagation();
- }
- };
- ActionsHandler.prototype.setInitiated = function (type) {
- if (type === void 0) { type = 0; }
- this.initiated = type;
- };
- ActionsHandler.prototype.start = function (e) {
- var _eventType = eventTypeMap[e.type];
- if (this.initiated && this.initiated !== _eventType) {
- return;
- }
- this.setInitiated(_eventType);
- // if textarea or other html tags in options.tagException is manipulated
- // do not make bs scroll
- if (tagExceptionFn(e.target, this.options.tagException)) {
- this.setInitiated();
- return;
- }
- // only allow mouse left button
- if (_eventType === 2 /* Mouse */ && e.button !== 0 /* Left */)
- return;
- if (this.hooks.trigger(this.hooks.eventTypes.beforeStart, e)) {
- return;
- }
- this.beforeHandler(e, 'start');
- var point = (e.touches ? e.touches[0] : e);
- this.pointX = point.pageX;
- this.pointY = point.pageY;
- this.hooks.trigger(this.hooks.eventTypes.start, e);
- };
- ActionsHandler.prototype.move = function (e) {
- if (eventTypeMap[e.type] !== this.initiated) {
- return;
- }
- this.beforeHandler(e, 'move');
- var point = (e.touches ? e.touches[0] : e);
- var deltaX = point.pageX - this.pointX;
- var deltaY = point.pageY - this.pointY;
- this.pointX = point.pageX;
- this.pointY = point.pageY;
- if (this.hooks.trigger(this.hooks.eventTypes.move, {
- deltaX: deltaX,
- deltaY: deltaY,
- e: e,
- })) {
- return;
- }
- // auto end when out of viewport
- var scrollLeft = document.documentElement.scrollLeft ||
- window.pageXOffset ||
- document.body.scrollLeft;
- var scrollTop = document.documentElement.scrollTop ||
- window.pageYOffset ||
- document.body.scrollTop;
- var pX = this.pointX - scrollLeft;
- var pY = this.pointY - scrollTop;
- var autoEndDistance = this.options.autoEndDistance;
- if (pX > document.documentElement.clientWidth - autoEndDistance ||
- pY > document.documentElement.clientHeight - autoEndDistance ||
- pX < autoEndDistance ||
- pY < autoEndDistance) {
- this.end(e);
- }
- };
- ActionsHandler.prototype.end = function (e) {
- if (eventTypeMap[e.type] !== this.initiated) {
- return;
- }
- this.setInitiated();
- this.beforeHandler(e, 'end');
- this.hooks.trigger(this.hooks.eventTypes.end, e);
- };
- ActionsHandler.prototype.click = function (e) {
- this.hooks.trigger(this.hooks.eventTypes.click, e);
- };
- ActionsHandler.prototype.setContent = function (content) {
- if (content !== this.wrapper) {
- this.wrapper = content;
- this.rebindDOMEvents();
- }
- };
- ActionsHandler.prototype.rebindDOMEvents = function () {
- this.wrapperEventRegister.destroy();
- this.targetEventRegister.destroy();
- this.handleDOMEvents();
- };
- ActionsHandler.prototype.destroy = function () {
- this.wrapperEventRegister.destroy();
- this.targetEventRegister.destroy();
- this.hooks.destroy();
- };
- return ActionsHandler;
- }());
- var translaterMetaData = {
- x: ['translateX', 'px'],
- y: ['translateY', 'px'],
- };
- var Translater = /** @class */ (function () {
- function Translater(content) {
- this.setContent(content);
- this.hooks = new EventEmitter(['beforeTranslate', 'translate']);
- }
- Translater.prototype.getComputedPosition = function () {
- var cssStyle = window.getComputedStyle(this.content, null);
- var matrix = cssStyle[style.transform].split(')')[0].split(', ');
- var x = +(matrix[12] || matrix[4]) || 0;
- var y = +(matrix[13] || matrix[5]) || 0;
- return {
- x: x,
- y: y,
- };
- };
- Translater.prototype.translate = function (point) {
- var transformStyle = [];
- Object.keys(point).forEach(function (key) {
- if (!translaterMetaData[key]) {
- return;
- }
- var transformFnName = translaterMetaData[key][0];
- if (transformFnName) {
- var transformFnArgUnit = translaterMetaData[key][1];
- var transformFnArg = point[key];
- transformStyle.push(transformFnName + "(" + transformFnArg + transformFnArgUnit + ")");
- }
- });
- this.hooks.trigger(this.hooks.eventTypes.beforeTranslate, transformStyle, point);
- this.style[style.transform] = transformStyle.join(' ');
- this.hooks.trigger(this.hooks.eventTypes.translate, point);
- };
- Translater.prototype.setContent = function (content) {
- if (this.content !== content) {
- this.content = content;
- this.style = content.style;
- }
- };
- Translater.prototype.destroy = function () {
- this.hooks.destroy();
- };
- return Translater;
- }());
- var Base = /** @class */ (function () {
- function Base(content, translater, options) {
- this.translater = translater;
- this.options = options;
- this.timer = 0;
- this.hooks = new EventEmitter([
- 'move',
- 'end',
- 'beforeForceStop',
- 'forceStop',
- 'callStop',
- 'time',
- 'timeFunction',
- ]);
- this.setContent(content);
- }
- Base.prototype.translate = function (endPoint) {
- this.translater.translate(endPoint);
- };
- Base.prototype.setPending = function (pending) {
- this.pending = pending;
- };
- Base.prototype.setForceStopped = function (forceStopped) {
- this.forceStopped = forceStopped;
- };
- Base.prototype.setCallStop = function (called) {
- this.callStopWhenPending = called;
- };
- Base.prototype.setContent = function (content) {
- if (this.content !== content) {
- this.content = content;
- this.style = content.style;
- this.stop();
- }
- };
- Base.prototype.clearTimer = function () {
- if (this.timer) {
- cancelAnimationFrame(this.timer);
- this.timer = 0;
- }
- };
- Base.prototype.destroy = function () {
- this.hooks.destroy();
- cancelAnimationFrame(this.timer);
- };
- return Base;
- }());
- // iOS 13.6 - 14.x, window.getComputedStyle sometimes will get wrong transform value
- // when bs use transition mode
- // eg: translateY -100px -> -200px, when the last frame which is about to scroll to -200px
- // window.getComputedStyle(this.content) will calculate transformY to be -100px(startPoint)
- // it is weird
- // so we should validate position caculated by 'window.getComputedStyle'
- var isValidPostion = function (startPoint, endPoint, currentPos, prePos) {
- var computeDirection = function (endValue, startValue) {
- var delta = endValue - startValue;
- var direction = delta > 0
- ? -1 /* Negative */
- : delta < 0
- ? 1 /* Positive */
- : 0 /* Default */;
- return direction;
- };
- var directionX = computeDirection(endPoint.x, startPoint.x);
- var directionY = computeDirection(endPoint.y, startPoint.y);
- var deltaX = currentPos.x - prePos.x;
- var deltaY = currentPos.y - prePos.y;
- return directionX * deltaX <= 0 && directionY * deltaY <= 0;
- };
- var Transition = /** @class */ (function (_super) {
- __extends(Transition, _super);
- function Transition() {
- return _super !== null && _super.apply(this, arguments) || this;
- }
- Transition.prototype.startProbe = function (startPoint, endPoint) {
- var _this = this;
- var prePos = startPoint;
- var probe = function () {
- var pos = _this.translater.getComputedPosition();
- if (isValidPostion(startPoint, endPoint, pos, prePos)) {
- _this.hooks.trigger(_this.hooks.eventTypes.move, pos);
- }
- // call bs.stop() should not dispatch end hook again.
- // forceStop hook will do this.
- /* istanbul ignore if */
- if (!_this.pending) {
- if (_this.callStopWhenPending) {
- _this.callStopWhenPending = false;
- }
- else {
- // transition ends should dispatch end hook.
- _this.hooks.trigger(_this.hooks.eventTypes.end, pos);
- }
- }
- prePos = pos;
- if (_this.pending) {
- _this.timer = requestAnimationFrame(probe);
- }
- };
- // when manually call bs.stop(), then bs.scrollTo()
- // we should reset callStopWhenPending to dispatch end hook
- if (this.callStopWhenPending) {
- this.setCallStop(false);
- }
- cancelAnimationFrame(this.timer);
- probe();
- };
- Transition.prototype.transitionTime = function (time) {
- if (time === void 0) { time = 0; }
- this.style[style.transitionDuration] = time + 'ms';
- this.hooks.trigger(this.hooks.eventTypes.time, time);
- };
- Transition.prototype.transitionTimingFunction = function (easing) {
- this.style[style.transitionTimingFunction] = easing;
- this.hooks.trigger(this.hooks.eventTypes.timeFunction, easing);
- };
- Transition.prototype.transitionProperty = function () {
- this.style[style.transitionProperty] = style.transform;
- };
- Transition.prototype.move = function (startPoint, endPoint, time, easingFn) {
- this.setPending(time > 0);
- this.transitionTimingFunction(easingFn);
- this.transitionProperty();
- this.transitionTime(time);
- this.translate(endPoint);
- var isRealtimeProbeType = this.options.probeType === 3 /* Realtime */;
- if (time && isRealtimeProbeType) {
- this.startProbe(startPoint, endPoint);
- }
- // if we change content's transformY in a tick
- // such as: 0 -> 50px -> 0
- // transitionend will not be triggered
- // so we forceupdate by reflow
- if (!time) {
- this._reflow = this.content.offsetHeight;
- if (isRealtimeProbeType) {
- this.hooks.trigger(this.hooks.eventTypes.move, endPoint);
- }
- this.hooks.trigger(this.hooks.eventTypes.end, endPoint);
- }
- };
- Transition.prototype.doStop = function () {
- var pending = this.pending;
- this.setForceStopped(false);
- this.setCallStop(false);
- // still in transition
- if (pending) {
- this.setPending(false);
- cancelAnimationFrame(this.timer);
- var _a = this.translater.getComputedPosition(), x = _a.x, y = _a.y;
- this.transitionTime();
- this.translate({ x: x, y: y });
- this.setForceStopped(true);
- this.setCallStop(true);
- this.hooks.trigger(this.hooks.eventTypes.forceStop, { x: x, y: y });
- }
- return pending;
- };
- Transition.prototype.stop = function () {
- var stopFromTransition = this.doStop();
- if (stopFromTransition) {
- this.hooks.trigger(this.hooks.eventTypes.callStop);
- }
- };
- return Transition;
- }(Base));
- var Animation = /** @class */ (function (_super) {
- __extends(Animation, _super);
- function Animation() {
- return _super !== null && _super.apply(this, arguments) || this;
- }
- Animation.prototype.move = function (startPoint, endPoint, time, easingFn) {
- // time is 0
- if (!time) {
- this.translate(endPoint);
- if (this.options.probeType === 3 /* Realtime */) {
- this.hooks.trigger(this.hooks.eventTypes.move, endPoint);
- }
- this.hooks.trigger(this.hooks.eventTypes.end, endPoint);
- return;
- }
- this.animate(startPoint, endPoint, time, easingFn);
- };
- Animation.prototype.animate = function (startPoint, endPoint, duration, easingFn) {
- var _this = this;
- var startTime = getNow();
- var destTime = startTime + duration;
- var isRealtimeProbeType = this.options.probeType === 3 /* Realtime */;
- var step = function () {
- var now = getNow();
- // js animation end
- if (now >= destTime) {
- _this.translate(endPoint);
- if (isRealtimeProbeType) {
- _this.hooks.trigger(_this.hooks.eventTypes.move, endPoint);
- }
- _this.hooks.trigger(_this.hooks.eventTypes.end, endPoint);
- return;
- }
- now = (now - startTime) / duration;
- var easing = easingFn(now);
- var newPoint = {};
- Object.keys(endPoint).forEach(function (key) {
- var startValue = startPoint[key];
- var endValue = endPoint[key];
- newPoint[key] = (endValue - startValue) * easing + startValue;
- });
- _this.translate(newPoint);
- if (isRealtimeProbeType) {
- _this.hooks.trigger(_this.hooks.eventTypes.move, newPoint);
- }
- if (_this.pending) {
- _this.timer = requestAnimationFrame(step);
- }
- // call bs.stop() should not dispatch end hook again.
- // forceStop hook will do this.
- /* istanbul ignore if */
- if (!_this.pending) {
- if (_this.callStopWhenPending) {
- _this.callStopWhenPending = false;
- }
- else {
- // raf ends should dispatch end hook.
- _this.hooks.trigger(_this.hooks.eventTypes.end, endPoint);
- }
- }
- };
- this.setPending(true);
- // when manually call bs.stop(), then bs.scrollTo()
- // we should reset callStopWhenPending to dispatch end hook
- if (this.callStopWhenPending) {
- this.setCallStop(false);
- }
- cancelAnimationFrame(this.timer);
- step();
- };
- Animation.prototype.doStop = function () {
- var pending = this.pending;
- this.setForceStopped(false);
- this.setCallStop(false);
- // still in requestFrameAnimation
- if (pending) {
- this.setPending(false);
- cancelAnimationFrame(this.timer);
- var pos = this.translater.getComputedPosition();
- this.setForceStopped(true);
- this.setCallStop(true);
- this.hooks.trigger(this.hooks.eventTypes.forceStop, pos);
- }
- return pending;
- };
- Animation.prototype.stop = function () {
- var stopFromAnimation = this.doStop();
- if (stopFromAnimation) {
- this.hooks.trigger(this.hooks.eventTypes.callStop);
- }
- };
- return Animation;
- }(Base));
- function createAnimater(element, translater, options) {
- var useTransition = options.useTransition;
- var animaterOptions = {};
- Object.defineProperty(animaterOptions, 'probeType', {
- enumerable: true,
- configurable: false,
- get: function () {
- return options.probeType;
- },
- });
- if (useTransition) {
- return new Transition(element, translater, animaterOptions);
- }
- else {
- return new Animation(element, translater, animaterOptions);
- }
- }
- var Behavior = /** @class */ (function () {
- function Behavior(wrapper, content, options) {
- this.wrapper = wrapper;
- this.options = options;
- this.hooks = new EventEmitter([
- 'beforeComputeBoundary',
- 'computeBoundary',
- 'momentum',
- 'end',
- 'ignoreHasScroll'
- ]);
- this.refresh(content);
- }
- Behavior.prototype.start = function () {
- this.dist = 0;
- this.setMovingDirection(0 /* Default */);
- this.setDirection(0 /* Default */);
- };
- Behavior.prototype.move = function (delta) {
- delta = this.hasScroll ? delta : 0;
- this.setMovingDirection(delta);
- return this.performDampingAlgorithm(delta, this.options.outOfBoundaryDampingFactor);
- };
- Behavior.prototype.setMovingDirection = function (delta) {
- this.movingDirection =
- delta > 0
- ? -1 /* Negative */
- : delta < 0
- ? 1 /* Positive */
- : 0 /* Default */;
- };
- Behavior.prototype.setDirection = function (delta) {
- this.direction =
- delta > 0
- ? -1 /* Negative */
- : delta < 0
- ? 1 /* Positive */
- : 0 /* Default */;
- };
- Behavior.prototype.performDampingAlgorithm = function (delta, dampingFactor) {
- var newPos = this.currentPos + delta;
- // Slow down or stop if outside of the boundaries
- if (newPos > this.minScrollPos || newPos < this.maxScrollPos) {
- if ((newPos > this.minScrollPos && this.options.bounces[0]) ||
- (newPos < this.maxScrollPos && this.options.bounces[1])) {
- newPos = this.currentPos + delta * dampingFactor;
- }
- else {
- newPos =
- newPos > this.minScrollPos ? this.minScrollPos : this.maxScrollPos;
- }
- }
- return newPos;
- };
- Behavior.prototype.end = function (duration) {
- var momentumInfo = {
- duration: 0
- };
- var absDist = Math.abs(this.currentPos - this.startPos);
- // start momentum animation if needed
- if (this.options.momentum &&
- duration < this.options.momentumLimitTime &&
- absDist > this.options.momentumLimitDistance) {
- var wrapperSize = (this.direction === -1 /* Negative */ && this.options.bounces[0]) ||
- (this.direction === 1 /* Positive */ && this.options.bounces[1])
- ? this.wrapperSize
- : 0;
- momentumInfo = this.hasScroll
- ? this.momentum(this.currentPos, this.startPos, duration, this.maxScrollPos, this.minScrollPos, wrapperSize, this.options)
- : { destination: this.currentPos, duration: 0 };
- }
- else {
- this.hooks.trigger(this.hooks.eventTypes.end, momentumInfo);
- }
- return momentumInfo;
- };
- Behavior.prototype.momentum = function (current, start, time, lowerMargin, upperMargin, wrapperSize, options) {
- if (options === void 0) { options = this.options; }
- var distance = current - start;
- var speed = Math.abs(distance) / time;
- var deceleration = options.deceleration, swipeBounceTime = options.swipeBounceTime, swipeTime = options.swipeTime;
- var duration = Math.min(swipeTime, (speed * 2) / deceleration);
- var momentumData = {
- destination: current + ((speed * speed) / deceleration) * (distance < 0 ? -1 : 1),
- duration: duration,
- rate: 15
- };
- this.hooks.trigger(this.hooks.eventTypes.momentum, momentumData, distance);
- if (momentumData.destination < lowerMargin) {
- momentumData.destination = wrapperSize
- ? Math.max(lowerMargin - wrapperSize / 4, lowerMargin - (wrapperSize / momentumData.rate) * speed)
- : lowerMargin;
- momentumData.duration = swipeBounceTime;
- }
- else if (momentumData.destination > upperMargin) {
- momentumData.destination = wrapperSize
- ? Math.min(upperMargin + wrapperSize / 4, upperMargin + (wrapperSize / momentumData.rate) * speed)
- : upperMargin;
- momentumData.duration = swipeBounceTime;
- }
- momentumData.destination = Math.round(momentumData.destination);
- return momentumData;
- };
- Behavior.prototype.updateDirection = function () {
- var absDist = this.currentPos - this.absStartPos;
- this.setDirection(absDist);
- };
- Behavior.prototype.refresh = function (content) {
- var _a = this.options.rect, size = _a.size, position = _a.position;
- var isWrapperStatic = window.getComputedStyle(this.wrapper, null).position === 'static';
- // Force reflow
- var wrapperRect = getRect(this.wrapper);
- // use client is more fair than offset
- this.wrapperSize = this.wrapper[size === 'width' ? 'clientWidth' : 'clientHeight'];
- this.setContent(content);
- var contentRect = getRect(this.content);
- this.contentSize = contentRect[size];
- this.relativeOffset = contentRect[position];
- /* istanbul ignore if */
- if (isWrapperStatic) {
- this.relativeOffset -= wrapperRect[position];
- }
- this.computeBoundary();
- this.setDirection(0 /* Default */);
- };
- Behavior.prototype.setContent = function (content) {
- if (content !== this.content) {
- this.content = content;
- this.resetState();
- }
- };
- Behavior.prototype.resetState = function () {
- this.currentPos = 0;
- this.startPos = 0;
- this.dist = 0;
- this.setDirection(0 /* Default */);
- this.setMovingDirection(0 /* Default */);
- this.resetStartPos();
- };
- Behavior.prototype.computeBoundary = function () {
- this.hooks.trigger(this.hooks.eventTypes.beforeComputeBoundary);
- var boundary = {
- minScrollPos: 0,
- maxScrollPos: this.wrapperSize - this.contentSize
- };
- if (boundary.maxScrollPos < 0) {
- boundary.maxScrollPos -= this.relativeOffset;
- if (this.options.specifiedIndexAsContent === 0) {
- boundary.minScrollPos = -this.relativeOffset;
- }
- }
- this.hooks.trigger(this.hooks.eventTypes.computeBoundary, boundary);
- this.minScrollPos = boundary.minScrollPos;
- this.maxScrollPos = boundary.maxScrollPos;
- this.hasScroll =
- this.options.scrollable && this.maxScrollPos < this.minScrollPos;
- if (!this.hasScroll && this.minScrollPos < this.maxScrollPos) {
- this.maxScrollPos = this.minScrollPos;
- this.contentSize = this.wrapperSize;
- }
- };
- Behavior.prototype.updatePosition = function (pos) {
- this.currentPos = pos;
- };
- Behavior.prototype.getCurrentPos = function () {
- return this.currentPos;
- };
- Behavior.prototype.checkInBoundary = function () {
- var position = this.adjustPosition(this.currentPos);
- var inBoundary = position === this.getCurrentPos();
- return {
- position: position,
- inBoundary: inBoundary
- };
- };
- // adjust position when out of boundary
- Behavior.prototype.adjustPosition = function (pos) {
- if (!this.hasScroll &&
- !this.hooks.trigger(this.hooks.eventTypes.ignoreHasScroll)) {
- pos = this.minScrollPos;
- }
- else if (pos > this.minScrollPos) {
- pos = this.minScrollPos;
- }
- else if (pos < this.maxScrollPos) {
- pos = this.maxScrollPos;
- }
- return pos;
- };
- Behavior.prototype.updateStartPos = function () {
- this.startPos = this.currentPos;
- };
- Behavior.prototype.updateAbsStartPos = function () {
- this.absStartPos = this.currentPos;
- };
- Behavior.prototype.resetStartPos = function () {
- this.updateStartPos();
- this.updateAbsStartPos();
- };
- Behavior.prototype.getAbsDist = function (delta) {
- this.dist += delta;
- return Math.abs(this.dist);
- };
- Behavior.prototype.destroy = function () {
- this.hooks.destroy();
- };
- return Behavior;
- }());
- var _a, _b, _c, _d;
- var PassthroughHandlers = (_a = {},
- _a["yes" /* Yes */] = function (e) {
- return true;
- },
- _a["no" /* No */] = function (e) {
- e.preventDefault();
- return false;
- },
- _a);
- var DirectionMap = (_b = {},
- _b["horizontal" /* Horizontal */] = (_c = {},
- _c["yes" /* Yes */] = "horizontal" /* Horizontal */,
- _c["no" /* No */] = "vertical" /* Vertical */,
- _c),
- _b["vertical" /* Vertical */] = (_d = {},
- _d["yes" /* Yes */] = "vertical" /* Vertical */,
- _d["no" /* No */] = "horizontal" /* Horizontal */,
- _d),
- _b);
- var DirectionLockAction = /** @class */ (function () {
- function DirectionLockAction(directionLockThreshold, freeScroll, eventPassthrough) {
- this.directionLockThreshold = directionLockThreshold;
- this.freeScroll = freeScroll;
- this.eventPassthrough = eventPassthrough;
- this.reset();
- }
- DirectionLockAction.prototype.reset = function () {
- this.directionLocked = "" /* Default */;
- };
- DirectionLockAction.prototype.checkMovingDirection = function (absDistX, absDistY, e) {
- this.computeDirectionLock(absDistX, absDistY);
- return this.handleEventPassthrough(e);
- };
- DirectionLockAction.prototype.adjustDelta = function (deltaX, deltaY) {
- if (this.directionLocked === "horizontal" /* Horizontal */) {
- deltaY = 0;
- }
- else if (this.directionLocked === "vertical" /* Vertical */) {
- deltaX = 0;
- }
- return {
- deltaX: deltaX,
- deltaY: deltaY
- };
- };
- DirectionLockAction.prototype.computeDirectionLock = function (absDistX, absDistY) {
- // If you are scrolling in one direction, lock it
- if (this.directionLocked === "" /* Default */ && !this.freeScroll) {
- if (absDistX > absDistY + this.directionLockThreshold) {
- this.directionLocked = "horizontal" /* Horizontal */; // lock horizontally
- }
- else if (absDistY >= absDistX + this.directionLockThreshold) {
- this.directionLocked = "vertical" /* Vertical */; // lock vertically
- }
- else {
- this.directionLocked = "none" /* None */; // no lock
- }
- }
- };
- DirectionLockAction.prototype.handleEventPassthrough = function (e) {
- var handleMap = DirectionMap[this.directionLocked];
- if (handleMap) {
- if (this.eventPassthrough === handleMap["yes" /* Yes */]) {
- return PassthroughHandlers["yes" /* Yes */](e);
- }
- else if (this.eventPassthrough === handleMap["no" /* No */]) {
- return PassthroughHandlers["no" /* No */](e);
- }
- }
- return false;
- };
- return DirectionLockAction;
- }());
- var applyQuadrantTransformation = function (deltaX, deltaY, quadrant) {
- if (quadrant === 2 /* Second */) {
- return [deltaY, -deltaX];
- }
- else if (quadrant === 3 /* Third */) {
- return [-deltaX, -deltaY];
- }
- else if (quadrant === 4 /* Forth */) {
- return [-deltaY, deltaX];
- }
- else {
- return [deltaX, deltaY];
- }
- };
- var ScrollerActions = /** @class */ (function () {
- function ScrollerActions(scrollBehaviorX, scrollBehaviorY, actionsHandler, animater, options) {
- this.hooks = new EventEmitter([
- 'start',
- 'beforeMove',
- 'scrollStart',
- 'scroll',
- 'beforeEnd',
- 'end',
- 'scrollEnd',
- 'contentNotMoved',
- 'detectMovingDirection',
- 'coordinateTransformation',
- ]);
- this.scrollBehaviorX = scrollBehaviorX;
- this.scrollBehaviorY = scrollBehaviorY;
- this.actionsHandler = actionsHandler;
- this.animater = animater;
- this.options = options;
- this.directionLockAction = new DirectionLockAction(options.directionLockThreshold, options.freeScroll, options.eventPassthrough);
- this.enabled = true;
- this.bindActionsHandler();
- }
- ScrollerActions.prototype.bindActionsHandler = function () {
- var _this = this;
- // [mouse|touch]start event
- this.actionsHandler.hooks.on(this.actionsHandler.hooks.eventTypes.start, function (e) {
- if (!_this.enabled)
- return true;
- return _this.handleStart(e);
- });
- // [mouse|touch]move event
- this.actionsHandler.hooks.on(this.actionsHandler.hooks.eventTypes.move, function (_a) {
- var deltaX = _a.deltaX, deltaY = _a.deltaY, e = _a.e;
- if (!_this.enabled)
- return true;
- var _b = applyQuadrantTransformation(deltaX, deltaY, _this.options.quadrant), transformateDeltaX = _b[0], transformateDeltaY = _b[1];
- var transformateDeltaData = {
- deltaX: transformateDeltaX,
- deltaY: transformateDeltaY,
- };
- _this.hooks.trigger(_this.hooks.eventTypes.coordinateTransformation, transformateDeltaData);
- return _this.handleMove(transformateDeltaData.deltaX, transformateDeltaData.deltaY, e);
- });
- // [mouse|touch]end event
- this.actionsHandler.hooks.on(this.actionsHandler.hooks.eventTypes.end, function (e) {
- if (!_this.enabled)
- return true;
- return _this.handleEnd(e);
- });
- // click
- this.actionsHandler.hooks.on(this.actionsHandler.hooks.eventTypes.click, function (e) {
- // handle native click event
- if (_this.enabled && !e._constructed) {
- _this.handleClick(e);
- }
- });
- };
- ScrollerActions.prototype.handleStart = function (e) {
- var timestamp = getNow();
- this.fingerMoved = false;
- this.contentMoved = false;
- this.startTime = timestamp;
- this.directionLockAction.reset();
- this.scrollBehaviorX.start();
- this.scrollBehaviorY.start();
- // force stopping last transition or animation
- this.animater.doStop();
- this.scrollBehaviorX.resetStartPos();
- this.scrollBehaviorY.resetStartPos();
- this.hooks.trigger(this.hooks.eventTypes.start, e);
- };
- ScrollerActions.prototype.handleMove = function (deltaX, deltaY, e) {
- if (this.hooks.trigger(this.hooks.eventTypes.beforeMove, e)) {
- return;
- }
- var absDistX = this.scrollBehaviorX.getAbsDist(deltaX);
- var absDistY = this.scrollBehaviorY.getAbsDist(deltaY);
- var timestamp = getNow();
- // We need to move at least momentumLimitDistance pixels
- // for the scrolling to initiate
- if (this.checkMomentum(absDistX, absDistY, timestamp)) {
- return true;
- }
- if (this.directionLockAction.checkMovingDirection(absDistX, absDistY, e)) {
- this.actionsHandler.setInitiated();
- return true;
- }
- var delta = this.directionLockAction.adjustDelta(deltaX, deltaY);
- var prevX = this.scrollBehaviorX.getCurrentPos();
- var newX = this.scrollBehaviorX.move(delta.deltaX);
- var prevY = this.scrollBehaviorY.getCurrentPos();
- var newY = this.scrollBehaviorY.move(delta.deltaY);
- if (this.hooks.trigger(this.hooks.eventTypes.detectMovingDirection)) {
- return;
- }
- if (!this.fingerMoved) {
- this.fingerMoved = true;
- }
- var positionChanged = newX !== prevX || newY !== prevY;
- if (!this.contentMoved && !positionChanged) {
- this.hooks.trigger(this.hooks.eventTypes.contentNotMoved);
- }
- if (!this.contentMoved && positionChanged) {
- this.contentMoved = true;
- this.hooks.trigger(this.hooks.eventTypes.scrollStart);
- }
- if (this.contentMoved && positionChanged) {
- this.animater.translate({
- x: newX,
- y: newY,
- });
- this.dispatchScroll(timestamp);
- }
- };
- ScrollerActions.prototype.dispatchScroll = function (timestamp) {
- // dispatch scroll in interval time
- if (timestamp - this.startTime > this.options.momentumLimitTime) {
- // refresh time and starting position to initiate a momentum
- this.startTime = timestamp;
- this.scrollBehaviorX.updateStartPos();
- this.scrollBehaviorY.updateStartPos();
- if (this.options.probeType === 1 /* Throttle */) {
- this.hooks.trigger(this.hooks.eventTypes.scroll, this.getCurrentPos());
- }
- }
- // dispatch scroll all the time
- if (this.options.probeType > 1 /* Throttle */) {
- this.hooks.trigger(this.hooks.eventTypes.scroll, this.getCurrentPos());
- }
- };
- ScrollerActions.prototype.checkMomentum = function (absDistX, absDistY, timestamp) {
- return (timestamp - this.endTime > this.options.momentumLimitTime &&
- absDistY < this.options.momentumLimitDistance &&
- absDistX < this.options.momentumLimitDistance);
- };
- ScrollerActions.prototype.handleEnd = function (e) {
- if (this.hooks.trigger(this.hooks.eventTypes.beforeEnd, e)) {
- return;
- }
- var currentPos = this.getCurrentPos();
- this.scrollBehaviorX.updateDirection();
- this.scrollBehaviorY.updateDirection();
- if (this.hooks.trigger(this.hooks.eventTypes.end, e, currentPos)) {
- return true;
- }
- currentPos = this.ensureIntegerPos(currentPos);
- this.animater.translate(currentPos);
- this.endTime = getNow();
- var duration = this.endTime - this.startTime;
- this.hooks.trigger(this.hooks.eventTypes.scrollEnd, currentPos, duration);
- };
- ScrollerActions.prototype.ensureIntegerPos = function (currentPos) {
- this.ensuringInteger = true;
- var x = currentPos.x, y = currentPos.y;
- var _a = this.scrollBehaviorX, minScrollPosX = _a.minScrollPos, maxScrollPosX = _a.maxScrollPos;
- var _b = this.scrollBehaviorY, minScrollPosY = _b.minScrollPos, maxScrollPosY = _b.maxScrollPos;
- x = x > 0 ? Math.ceil(x) : Math.floor(x);
- y = y > 0 ? Math.ceil(y) : Math.floor(y);
- x = between(x, maxScrollPosX, minScrollPosX);
- y = between(y, maxScrollPosY, minScrollPosY);
- return { x: x, y: y };
- };
- ScrollerActions.prototype.handleClick = function (e) {
- if (!preventDefaultExceptionFn(e.target, this.options.preventDefaultException)) {
- e.preventDefault();
- e.stopPropagation();
- }
- };
- ScrollerActions.prototype.getCurrentPos = function () {
- return {
- x: this.scrollBehaviorX.getCurrentPos(),
- y: this.scrollBehaviorY.getCurrentPos(),
- };
- };
- ScrollerActions.prototype.refresh = function () {
- this.endTime = 0;
- };
- ScrollerActions.prototype.destroy = function () {
- this.hooks.destroy();
- };
- return ScrollerActions;
- }());
- function createActionsHandlerOptions(bsOptions) {
- var options = [
- 'click',
- 'bindToWrapper',
- 'disableMouse',
- 'disableTouch',
- 'preventDefault',
- 'stopPropagation',
- 'tagException',
- 'preventDefaultException',
- 'autoEndDistance',
- ].reduce(function (prev, cur) {
- prev[cur] = bsOptions[cur];
- return prev;
- }, {});
- return options;
- }
- function createBehaviorOptions(bsOptions, extraProp, bounces, rect) {
- var options = [
- 'momentum',
- 'momentumLimitTime',
- 'momentumLimitDistance',
- 'deceleration',
- 'swipeBounceTime',
- 'swipeTime',
- 'outOfBoundaryDampingFactor',
- 'specifiedIndexAsContent',
- ].reduce(function (prev, cur) {
- prev[cur] = bsOptions[cur];
- return prev;
- }, {});
- // add extra property
- options.scrollable = !!bsOptions[extraProp];
- options.bounces = bounces;
- options.rect = rect;
- return options;
- }
- function bubbling(source, target, events) {
- events.forEach(function (event) {
- var sourceEvent;
- var targetEvent;
- if (typeof event === 'string') {
- sourceEvent = targetEvent = event;
- }
- else {
- sourceEvent = event.source;
- targetEvent = event.target;
- }
- source.on(sourceEvent, function () {
- var args = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- args[_i] = arguments[_i];
- }
- return target.trigger.apply(target, __spreadArrays([targetEvent], args));
- });
- });
- }
- function isSamePoint(startPoint, endPoint) {
- // keys of startPoint and endPoint should be equal
- var keys = Object.keys(startPoint);
- for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) {
- var key = keys_1[_i];
- if (startPoint[key] !== endPoint[key])
- return false;
- }
- return true;
- }
- var MIN_SCROLL_DISTANCE = 1;
- var Scroller = /** @class */ (function () {
- function Scroller(wrapper, content, options) {
- this.wrapper = wrapper;
- this.content = content;
- this.resizeTimeout = 0;
- this.hooks = new EventEmitter([
- 'beforeStart',
- 'beforeMove',
- 'beforeScrollStart',
- 'scrollStart',
- 'scroll',
- 'beforeEnd',
- 'scrollEnd',
- 'resize',
- 'touchEnd',
- 'end',
- 'flick',
- 'scrollCancel',
- 'momentum',
- 'scrollTo',
- 'minDistanceScroll',
- 'scrollToElement',
- 'beforeRefresh',
- ]);
- this.options = options;
- var _a = this.options.bounce, left = _a.left, right = _a.right, top = _a.top, bottom = _a.bottom;
- // direction X
- this.scrollBehaviorX = new Behavior(wrapper, content, createBehaviorOptions(options, 'scrollX', [left, right], {
- size: 'width',
- position: 'left',
- }));
- // direction Y
- this.scrollBehaviorY = new Behavior(wrapper, content, createBehaviorOptions(options, 'scrollY', [top, bottom], {
- size: 'height',
- position: 'top',
- }));
- this.translater = new Translater(this.content);
- this.animater = createAnimater(this.content, this.translater, this.options);
- this.actionsHandler = new ActionsHandler(this.options.bindToTarget ? this.content : wrapper, createActionsHandlerOptions(this.options));
- this.actions = new ScrollerActions(this.scrollBehaviorX, this.scrollBehaviorY, this.actionsHandler, this.animater, this.options);
- var resizeHandler = this.resize.bind(this);
- this.resizeRegister = new EventRegister(window, [
- {
- name: 'orientationchange',
- handler: resizeHandler,
- },
- {
- name: 'resize',
- handler: resizeHandler,
- },
- ]);
- this.registerTransitionEnd();
- this.init();
- }
- Scroller.prototype.init = function () {
- var _this = this;
- this.bindTranslater();
- this.bindAnimater();
- this.bindActions();
- // enable pointer events when scrolling ends
- this.hooks.on(this.hooks.eventTypes.scrollEnd, function () {
- _this.togglePointerEvents(true);
- });
- };
- Scroller.prototype.registerTransitionEnd = function () {
- this.transitionEndRegister = new EventRegister(this.content, [
- {
- name: style.transitionEnd,
- handler: this.transitionEnd.bind(this),
- },
- ]);
- };
- Scroller.prototype.bindTranslater = function () {
- var _this = this;
- var hooks = this.translater.hooks;
- hooks.on(hooks.eventTypes.beforeTranslate, function (transformStyle) {
- if (_this.options.translateZ) {
- transformStyle.push(_this.options.translateZ);
- }
- });
- // disable pointer events when scrolling
- hooks.on(hooks.eventTypes.translate, function (pos) {
- var prevPos = _this.getCurrentPos();
- _this.updatePositions(pos);
- // scrollEnd will dispatch when scroll is force stopping in touchstart handler
- // so in touchend handler, don't toggle pointer-events
- if (_this.actions.ensuringInteger === true) {
- _this.actions.ensuringInteger = false;
- return;
- }
- // a valid translate
- if (pos.x !== prevPos.x || pos.y !== prevPos.y) {
- _this.togglePointerEvents(false);
- }
- });
- };
- Scroller.prototype.bindAnimater = function () {
- var _this = this;
- // reset position
- this.animater.hooks.on(this.animater.hooks.eventTypes.end, function (pos) {
- if (!_this.resetPosition(_this.options.bounceTime)) {
- _this.animater.setPending(false);
- _this.hooks.trigger(_this.hooks.eventTypes.scrollEnd, pos);
- }
- });
- bubbling(this.animater.hooks, this.hooks, [
- {
- source: this.animater.hooks.eventTypes.move,
- target: this.hooks.eventTypes.scroll,
- },
- {
- source: this.animater.hooks.eventTypes.forceStop,
- target: this.hooks.eventTypes.scrollEnd,
- },
- ]);
- };
- Scroller.prototype.bindActions = function () {
- var _this = this;
- var actions = this.actions;
- bubbling(actions.hooks, this.hooks, [
- {
- source: actions.hooks.eventTypes.start,
- target: this.hooks.eventTypes.beforeStart,
- },
- {
- source: actions.hooks.eventTypes.start,
- target: this.hooks.eventTypes.beforeScrollStart,
- },
- {
- source: actions.hooks.eventTypes.beforeMove,
- target: this.hooks.eventTypes.beforeMove,
- },
- {
- source: actions.hooks.eventTypes.scrollStart,
- target: this.hooks.eventTypes.scrollStart,
- },
- {
- source: actions.hooks.eventTypes.scroll,
- target: this.hooks.eventTypes.scroll,
- },
- {
- source: actions.hooks.eventTypes.beforeEnd,
- target: this.hooks.eventTypes.beforeEnd,
- },
- ]);
- actions.hooks.on(actions.hooks.eventTypes.end, function (e, pos) {
- _this.hooks.trigger(_this.hooks.eventTypes.touchEnd, pos);
- if (_this.hooks.trigger(_this.hooks.eventTypes.end, pos)) {
- return true;
- }
- // check if it is a click operation
- if (!actions.fingerMoved) {
- _this.hooks.trigger(_this.hooks.eventTypes.scrollCancel);
- if (_this.checkClick(e)) {
- return true;
- }
- }
- // reset if we are outside of the boundaries
- if (_this.resetPosition(_this.options.bounceTime, ease.bounce)) {
- _this.animater.setForceStopped(false);
- return true;
- }
- });
- actions.hooks.on(actions.hooks.eventTypes.scrollEnd, function (pos, duration) {
- var deltaX = Math.abs(pos.x - _this.scrollBehaviorX.startPos);
- var deltaY = Math.abs(pos.y - _this.scrollBehaviorY.startPos);
- if (_this.checkFlick(duration, deltaX, deltaY)) {
- _this.animater.setForceStopped(false);
- _this.hooks.trigger(_this.hooks.eventTypes.flick);
- return;
- }
- if (_this.momentum(pos, duration)) {
- _this.animater.setForceStopped(false);
- return;
- }
- if (actions.contentMoved) {
- _this.hooks.trigger(_this.hooks.eventTypes.scrollEnd, pos);
- }
- if (_this.animater.forceStopped) {
- _this.animater.setForceStopped(false);
- }
- });
- };
- Scroller.prototype.checkFlick = function (duration, deltaX, deltaY) {
- var flickMinMovingDistance = 1; // distinguish flick from click
- if (this.hooks.events.flick.length > 1 &&
- duration < this.options.flickLimitTime &&
- deltaX < this.options.flickLimitDistance &&
- deltaY < this.options.flickLimitDistance &&
- (deltaY > flickMinMovingDistance || deltaX > flickMinMovingDistance)) {
- return true;
- }
- };
- Scroller.prototype.momentum = function (pos, duration) {
- var meta = {
- time: 0,
- easing: ease.swiper,
- newX: pos.x,
- newY: pos.y,
- };
- // start momentum animation if needed
- var momentumX = this.scrollBehaviorX.end(duration);
- var momentumY = this.scrollBehaviorY.end(duration);
- meta.newX = isUndef(momentumX.destination)
- ? meta.newX
- : momentumX.destination;
- meta.newY = isUndef(momentumY.destination)
- ? meta.newY
- : momentumY.destination;
- meta.time = Math.max(momentumX.duration, momentumY.duration);
- this.hooks.trigger(this.hooks.eventTypes.momentum, meta, this);
- // when x or y changed, do momentum animation now!
- if (meta.newX !== pos.x || meta.newY !== pos.y) {
- // change easing function when scroller goes out of the boundaries
- if (meta.newX > this.scrollBehaviorX.minScrollPos ||
- meta.newX < this.scrollBehaviorX.maxScrollPos ||
- meta.newY > this.scrollBehaviorY.minScrollPos ||
- meta.newY < this.scrollBehaviorY.maxScrollPos) {
- meta.easing = ease.swipeBounce;
- }
- this.scrollTo(meta.newX, meta.newY, meta.time, meta.easing);
- return true;
- }
- };
- Scroller.prototype.checkClick = function (e) {
- var cancelable = {
- preventClick: this.animater.forceStopped,
- };
- // we scrolled less than momentumLimitDistance pixels
- if (this.hooks.trigger(this.hooks.eventTypes.checkClick)) {
- this.animater.setForceStopped(false);
- return true;
- }
- if (!cancelable.preventClick) {
- var _dblclick = this.options.dblclick;
- var dblclickTrigged = false;
- if (_dblclick && this.lastClickTime) {
- var _a = _dblclick.delay, delay = _a === void 0 ? 300 : _a;
- if (getNow() - this.lastClickTime < delay) {
- dblclickTrigged = true;
- dblclick(e);
- }
- }
- if (this.options.tap) {
- tap(e, this.options.tap);
- }
- if (this.options.click &&
- !preventDefaultExceptionFn(e.target, this.options.preventDefaultException)) {
- click(e);
- }
- this.lastClickTime = dblclickTrigged ? null : getNow();
- return true;
- }
- return false;
- };
- Scroller.prototype.resize = function () {
- var _this = this;
- if (!this.actions.enabled) {
- return;
- }
- // fix a scroll problem under Android condition
- /* istanbul ignore if */
- if (isAndroid) {
- this.wrapper.scrollTop = 0;
- }
- clearTimeout(this.resizeTimeout);
- this.resizeTimeout = window.setTimeout(function () {
- _this.hooks.trigger(_this.hooks.eventTypes.resize);
- }, this.options.resizePolling);
- };
- /* istanbul ignore next */
- Scroller.prototype.transitionEnd = function (e) {
- if (e.target !== this.content || !this.animater.pending) {
- return;
- }
- var animater = this.animater;
- animater.transitionTime();
- if (!this.resetPosition(this.options.bounceTime, ease.bounce)) {
- this.animater.setPending(false);
- if (this.options.probeType !== 3 /* Realtime */) {
- this.hooks.trigger(this.hooks.eventTypes.scrollEnd, this.getCurrentPos());
- }
- }
- };
- Scroller.prototype.togglePointerEvents = function (enabled) {
- if (enabled === void 0) { enabled = true; }
- var el = this.content.children.length
- ? this.content.children
- : [this.content];
- var pointerEvents = enabled ? 'auto' : 'none';
- for (var i = 0; i < el.length; i++) {
- var node = el[i];
- // ignore BetterScroll instance's wrapper DOM
- /* istanbul ignore if */
- if (node.isBScrollContainer) {
- continue;
- }
- node.style.pointerEvents = pointerEvents;
- }
- };
- Scroller.prototype.refresh = function (content) {
- var contentChanged = this.setContent(content);
- this.hooks.trigger(this.hooks.eventTypes.beforeRefresh);
- this.scrollBehaviorX.refresh(content);
- this.scrollBehaviorY.refresh(content);
- if (contentChanged) {
- this.translater.setContent(content);
- this.animater.setContent(content);
- this.transitionEndRegister.destroy();
- this.registerTransitionEnd();
- if (this.options.bindToTarget) {
- this.actionsHandler.setContent(content);
- }
- }
- this.actions.refresh();
- this.wrapperOffset = offset(this.wrapper);
- };
- Scroller.prototype.setContent = function (content) {
- var contentChanged = content !== this.content;
- if (contentChanged) {
- this.content = content;
- }
- return contentChanged;
- };
- Scroller.prototype.scrollBy = function (deltaX, deltaY, time, easing) {
- if (time === void 0) { time = 0; }
- var _a = this.getCurrentPos(), x = _a.x, y = _a.y;
- easing = !easing ? ease.bounce : easing;
- deltaX += x;
- deltaY += y;
- this.scrollTo(deltaX, deltaY, time, easing);
- };
- Scroller.prototype.scrollTo = function (x, y, time, easing, extraTransform) {
- if (time === void 0) { time = 0; }
- if (easing === void 0) { easing = ease.bounce; }
- if (extraTransform === void 0) { extraTransform = {
- start: {},
- end: {},
- }; }
- var easingFn = this.options.useTransition ? easing.style : easing.fn;
- var currentPos = this.getCurrentPos();
- var startPoint = __assign({ x: currentPos.x, y: currentPos.y }, extraTransform.start);
- var endPoint = __assign({ x: x,
- y: y }, extraTransform.end);
- this.hooks.trigger(this.hooks.eventTypes.scrollTo, endPoint);
- // it is an useless move
- if (isSamePoint(startPoint, endPoint))
- return;
- var deltaX = Math.abs(endPoint.x - startPoint.x);
- var deltaY = Math.abs(endPoint.y - startPoint.y);
- // considering of browser compatibility for decimal transform value
- // force translating immediately
- if (deltaX < MIN_SCROLL_DISTANCE && deltaY < MIN_SCROLL_DISTANCE) {
- time = 0;
- this.hooks.trigger(this.hooks.eventTypes.minDistanceScroll);
- }
- this.animater.move(startPoint, endPoint, time, easingFn);
- };
- Scroller.prototype.scrollToElement = function (el, time, offsetX, offsetY, easing) {
- var targetEle = getElement(el);
- var pos = offset(targetEle);
- var getOffset = function (offset, size, wrapperSize) {
- if (typeof offset === 'number') {
- return offset;
- }
- // if offsetX/Y are true we center the element to the screen
- return offset ? Math.round(size / 2 - wrapperSize / 2) : 0;
- };
- offsetX = getOffset(offsetX, targetEle.offsetWidth, this.wrapper.offsetWidth);
- offsetY = getOffset(offsetY, targetEle.offsetHeight, this.wrapper.offsetHeight);
- var getPos = function (pos, wrapperPos, offset, scrollBehavior) {
- pos -= wrapperPos;
- pos = scrollBehavior.adjustPosition(pos - offset);
- return pos;
- };
- pos.left = getPos(pos.left, this.wrapperOffset.left, offsetX, this.scrollBehaviorX);
- pos.top = getPos(pos.top, this.wrapperOffset.top, offsetY, this.scrollBehaviorY);
- if (this.hooks.trigger(this.hooks.eventTypes.scrollToElement, targetEle, pos)) {
- return;
- }
- this.scrollTo(pos.left, pos.top, time, easing);
- };
- Scroller.prototype.resetPosition = function (time, easing) {
- if (time === void 0) { time = 0; }
- if (easing === void 0) { easing = ease.bounce; }
- var _a = this.scrollBehaviorX.checkInBoundary(), x = _a.position, xInBoundary = _a.inBoundary;
- var _b = this.scrollBehaviorY.checkInBoundary(), y = _b.position, yInBoundary = _b.inBoundary;
- if (xInBoundary && yInBoundary) {
- return false;
- }
- /* istanbul ignore if */
- if (isIOSBadVersion) {
- // fix ios 13.4 bouncing
- // see it in issues 982
- this.reflow();
- }
- // out of boundary
- this.scrollTo(x, y, time, easing);
- return true;
- };
- /* istanbul ignore next */
- Scroller.prototype.reflow = function () {
- this._reflow = this.content.offsetHeight;
- };
- Scroller.prototype.updatePositions = function (pos) {
- this.scrollBehaviorX.updatePosition(pos.x);
- this.scrollBehaviorY.updatePosition(pos.y);
- };
- Scroller.prototype.getCurrentPos = function () {
- return this.actions.getCurrentPos();
- };
- Scroller.prototype.enable = function () {
- this.actions.enabled = true;
- };
- Scroller.prototype.disable = function () {
- cancelAnimationFrame(this.animater.timer);
- this.actions.enabled = false;
- };
- Scroller.prototype.destroy = function () {
- var _this = this;
- var keys = [
- 'resizeRegister',
- 'transitionEndRegister',
- 'actionsHandler',
- 'actions',
- 'hooks',
- 'animater',
- 'translater',
- 'scrollBehaviorX',
- 'scrollBehaviorY',
- ];
- keys.forEach(function (key) { return _this[key].destroy(); });
- };
- return Scroller;
- }());
- var BScrollConstructor = /** @class */ (function (_super) {
- __extends(BScrollConstructor, _super);
- function BScrollConstructor(el, options) {
- var _this = _super.call(this, [
- 'refresh',
- 'contentChanged',
- 'enable',
- 'disable',
- 'beforeScrollStart',
- 'scrollStart',
- 'scroll',
- 'scrollEnd',
- 'scrollCancel',
- 'touchEnd',
- 'flick',
- 'destroy'
- ]) || this;
- var wrapper = getElement(el);
- if (!wrapper) {
- warn('Can not resolve the wrapper DOM.');
- return _this;
- }
- _this.plugins = {};
- _this.options = new OptionsConstructor().merge(options).process();
- if (!_this.setContent(wrapper).valid) {
- return _this;
- }
- _this.hooks = new EventEmitter([
- 'refresh',
- 'enable',
- 'disable',
- 'destroy',
- 'beforeInitialScrollTo',
- 'contentChanged'
- ]);
- _this.init(wrapper);
- return _this;
- }
- BScrollConstructor.use = function (ctor) {
- var name = ctor.pluginName;
- var installed = BScrollConstructor.plugins.some(function (plugin) { return ctor === plugin.ctor; });
- if (installed)
- return BScrollConstructor;
- if (isUndef(name)) {
- warn("Plugin Class must specify plugin's name in static property by 'pluginName' field.");
- return BScrollConstructor;
- }
- BScrollConstructor.pluginsMap[name] = true;
- BScrollConstructor.plugins.push({
- name: name,
- applyOrder: ctor.applyOrder,
- ctor: ctor
- });
- return BScrollConstructor;
- };
- BScrollConstructor.prototype.setContent = function (wrapper) {
- var contentChanged = false;
- var valid = true;
- var content = wrapper.children[this.options.specifiedIndexAsContent];
- if (!content) {
- warn('The wrapper need at least one child element to be content element to scroll.');
- valid = false;
- }
- else {
- contentChanged = this.content !== content;
- if (contentChanged) {
- this.content = content;
- }
- }
- return {
- valid: valid,
- contentChanged: contentChanged
- };
- };
- BScrollConstructor.prototype.init = function (wrapper) {
- var _this = this;
- this.wrapper = wrapper;
- // mark wrapper to recognize bs instance by DOM attribute
- wrapper.isBScrollContainer = true;
- this.scroller = new Scroller(wrapper, this.content, this.options);
- this.scroller.hooks.on(this.scroller.hooks.eventTypes.resize, function () {
- _this.refresh();
- });
- this.eventBubbling();
- this.handleAutoBlur();
- this.enable();
- this.proxy(propertiesConfig$7);
- this.applyPlugins();
- // maybe boundary has changed, should refresh
- this.refreshWithoutReset(this.content);
- var _a = this.options, startX = _a.startX, startY = _a.startY;
- var position = {
- x: startX,
- y: startY
- };
- // maybe plugins want to control scroll position
- if (this.hooks.trigger(this.hooks.eventTypes.beforeInitialScrollTo, position)) {
- return;
- }
- this.scroller.scrollTo(position.x, position.y);
- };
- BScrollConstructor.prototype.applyPlugins = function () {
- var _this = this;
- var options = this.options;
- BScrollConstructor.plugins
- .sort(function (a, b) {
- var _a;
- var applyOrderMap = (_a = {},
- _a["pre" /* Pre */] = -1,
- _a["post" /* Post */] = 1,
- _a);
- var aOrder = a.applyOrder ? applyOrderMap[a.applyOrder] : 0;
- var bOrder = b.applyOrder ? applyOrderMap[b.applyOrder] : 0;
- return aOrder - bOrder;
- })
- .forEach(function (item) {
- var ctor = item.ctor;
- if (options[item.name] && typeof ctor === 'function') {
- _this.plugins[item.name] = new ctor(_this);
- }
- });
- };
- BScrollConstructor.prototype.handleAutoBlur = function () {
- /* istanbul ignore if */
- if (this.options.autoBlur) {
- this.on(this.eventTypes.beforeScrollStart, function () {
- var activeElement = document.activeElement;
- if (activeElement &&
- (activeElement.tagName === 'INPUT' ||
- activeElement.tagName === 'TEXTAREA')) {
- activeElement.blur();
- }
- });
- }
- };
- BScrollConstructor.prototype.eventBubbling = function () {
- bubbling(this.scroller.hooks, this, [
- this.eventTypes.beforeScrollStart,
- this.eventTypes.scrollStart,
- this.eventTypes.scroll,
- this.eventTypes.scrollEnd,
- this.eventTypes.scrollCancel,
- this.eventTypes.touchEnd,
- this.eventTypes.flick
- ]);
- };
- BScrollConstructor.prototype.refreshWithoutReset = function (content) {
- this.scroller.refresh(content);
- this.hooks.trigger(this.hooks.eventTypes.refresh, content);
- this.trigger(this.eventTypes.refresh, content);
- };
- BScrollConstructor.prototype.proxy = function (propertiesConfig) {
- var _this = this;
- propertiesConfig.forEach(function (_a) {
- var key = _a.key, sourceKey = _a.sourceKey;
- propertiesProxy(_this, sourceKey, key);
- });
- };
- BScrollConstructor.prototype.refresh = function () {
- var _a = this.setContent(this.wrapper), contentChanged = _a.contentChanged, valid = _a.valid;
- if (valid) {
- var content = this.content;
- this.refreshWithoutReset(content);
- if (contentChanged) {
- this.hooks.trigger(this.hooks.eventTypes.contentChanged, content);
- this.trigger(this.eventTypes.contentChanged, content);
- }
- this.scroller.resetPosition();
- }
- };
- BScrollConstructor.prototype.enable = function () {
- this.scroller.enable();
- this.hooks.trigger(this.hooks.eventTypes.enable);
- this.trigger(this.eventTypes.enable);
- };
- BScrollConstructor.prototype.disable = function () {
- this.scroller.disable();
- this.hooks.trigger(this.hooks.eventTypes.disable);
- this.trigger(this.eventTypes.disable);
- };
- BScrollConstructor.prototype.destroy = function () {
- this.hooks.trigger(this.hooks.eventTypes.destroy);
- this.trigger(this.eventTypes.destroy);
- this.scroller.destroy();
- };
- BScrollConstructor.prototype.eventRegister = function (names) {
- this.registerType(names);
- };
- BScrollConstructor.plugins = [];
- BScrollConstructor.pluginsMap = {};
- return BScrollConstructor;
- }(EventEmitter));
- function createBScroll(el, options) {
- var bs = new BScrollConstructor(el, options);
- return bs;
- }
- createBScroll.use = BScrollConstructor.use;
- createBScroll.plugins = BScrollConstructor.plugins;
- createBScroll.pluginsMap = BScrollConstructor.pluginsMap;
- var BScroll = createBScroll;
- var MouseWheel = /** @class */ (function () {
- function MouseWheel(scroll) {
- this.scroll = scroll;
- this.wheelEndTimer = 0;
- this.wheelMoveTimer = 0;
- this.wheelStart = false;
- this.init();
- }
- MouseWheel.prototype.init = function () {
- this.handleBScroll();
- this.handleOptions();
- this.handleHooks();
- this.registerEvent();
- };
- MouseWheel.prototype.handleBScroll = function () {
- this.scroll.registerType([
- 'alterOptions',
- 'mousewheelStart',
- 'mousewheelMove',
- 'mousewheelEnd',
- ]);
- };
- MouseWheel.prototype.handleOptions = function () {
- var userOptions = (this.scroll.options.mouseWheel === true
- ? {}
- : this.scroll.options.mouseWheel);
- var defaultOptions = {
- speed: 20,
- invert: false,
- easeTime: 300,
- discreteTime: 400,
- throttleTime: 0,
- dampingFactor: 0.1,
- };
- this.mouseWheelOpt = extend(defaultOptions, userOptions);
- };
- MouseWheel.prototype.handleHooks = function () {
- this.hooksFn = [];
- this.registerHooks(this.scroll.hooks, 'destroy', this.destroy);
- };
- MouseWheel.prototype.registerEvent = function () {
- this.eventRegister = new EventRegister(this.scroll.scroller.wrapper, [
- {
- name: 'wheel',
- handler: this.wheelHandler.bind(this),
- },
- {
- name: 'mousewheel',
- handler: this.wheelHandler.bind(this),
- },
- {
- name: 'DOMMouseScroll',
- handler: this.wheelHandler.bind(this),
- },
- ]);
- };
- MouseWheel.prototype.registerHooks = function (hooks, name, handler) {
- hooks.on(name, handler, this);
- this.hooksFn.push([hooks, name, handler]);
- };
- MouseWheel.prototype.wheelHandler = function (e) {
- if (!this.scroll.enabled) {
- return;
- }
- this.beforeHandler(e);
- // start
- if (!this.wheelStart) {
- this.wheelStartHandler(e);
- this.wheelStart = true;
- }
- // move
- var delta = this.getWheelDelta(e);
- this.wheelMoveHandler(delta);
- // end
- this.wheelEndDetector(delta);
- };
- MouseWheel.prototype.wheelStartHandler = function (e) {
- this.cleanCache();
- var _a = this.scroll.scroller, scrollBehaviorX = _a.scrollBehaviorX, scrollBehaviorY = _a.scrollBehaviorY;
- scrollBehaviorX.setMovingDirection(0 /* Default */);
- scrollBehaviorY.setMovingDirection(0 /* Default */);
- scrollBehaviorX.setDirection(0 /* Default */);
- scrollBehaviorY.setDirection(0 /* Default */);
- this.scroll.trigger(this.scroll.eventTypes.alterOptions, this.mouseWheelOpt);
- this.scroll.trigger(this.scroll.eventTypes.mousewheelStart);
- };
- MouseWheel.prototype.cleanCache = function () {
- this.deltaCache = [];
- };
- MouseWheel.prototype.wheelMoveHandler = function (delta) {
- var _this = this;
- var _a = this.mouseWheelOpt, throttleTime = _a.throttleTime, dampingFactor = _a.dampingFactor;
- if (throttleTime && this.wheelMoveTimer) {
- this.deltaCache.push(delta);
- }
- else {
- var cachedDelta = this.deltaCache.reduce(function (prev, current) {
- return {
- x: prev.x + current.x,
- y: prev.y + current.y,
- };
- }, { x: 0, y: 0 });
- this.cleanCache();
- var _b = this.scroll.scroller, scrollBehaviorX = _b.scrollBehaviorX, scrollBehaviorY = _b.scrollBehaviorY;
- scrollBehaviorX.setMovingDirection(-delta.directionX);
- scrollBehaviorY.setMovingDirection(-delta.directionY);
- scrollBehaviorX.setDirection(delta.x);
- scrollBehaviorY.setDirection(delta.y);
- // when out of boundary, perform a damping scroll
- var newX = scrollBehaviorX.performDampingAlgorithm(Math.round(delta.x) + cachedDelta.x, dampingFactor);
- var newY = scrollBehaviorY.performDampingAlgorithm(Math.round(delta.y) + cachedDelta.x, dampingFactor);
- if (!this.scroll.trigger(this.scroll.eventTypes.mousewheelMove, {
- x: newX,
- y: newY,
- })) {
- var easeTime = this.getEaseTime();
- if (newX !== this.scroll.x || newY !== this.scroll.y) {
- this.scroll.scrollTo(newX, newY, easeTime);
- }
- }
- if (throttleTime) {
- this.wheelMoveTimer = window.setTimeout(function () {
- _this.wheelMoveTimer = 0;
- }, throttleTime);
- }
- }
- };
- MouseWheel.prototype.wheelEndDetector = function (delta) {
- var _this = this;
- window.clearTimeout(this.wheelEndTimer);
- this.wheelEndTimer = window.setTimeout(function () {
- _this.wheelStart = false;
- window.clearTimeout(_this.wheelMoveTimer);
- _this.wheelMoveTimer = 0;
- _this.scroll.trigger(_this.scroll.eventTypes.mousewheelEnd, delta);
- }, this.mouseWheelOpt.discreteTime);
- };
- MouseWheel.prototype.getWheelDelta = function (e) {
- var _a = this.mouseWheelOpt, speed = _a.speed, invert = _a.invert;
- var wheelDeltaX = 0;
- var wheelDeltaY = 0;
- var direction = invert ? -1 /* Negative */ : 1 /* Positive */;
- switch (true) {
- case 'deltaX' in e:
- if (e.deltaMode === 1) {
- wheelDeltaX = -e.deltaX * speed;
- wheelDeltaY = -e.deltaY * speed;
- }
- else {
- wheelDeltaX = -e.deltaX;
- wheelDeltaY = -e.deltaY;
- }
- break;
- case 'wheelDeltaX' in e:
- wheelDeltaX = (e.wheelDeltaX / 120) * speed;
- wheelDeltaY = (e.wheelDeltaY / 120) * speed;
- break;
- case 'wheelDelta' in e:
- wheelDeltaX = wheelDeltaY = (e.wheelDelta / 120) * speed;
- break;
- case 'detail' in e:
- wheelDeltaX = wheelDeltaY = (-e.detail / 3) * speed;
- break;
- }
- wheelDeltaX *= direction;
- wheelDeltaY *= direction;
- if (!this.scroll.hasVerticalScroll) {
- if (Math.abs(wheelDeltaY) > Math.abs(wheelDeltaX)) {
- wheelDeltaX = wheelDeltaY;
- }
- wheelDeltaY = 0;
- }
- if (!this.scroll.hasHorizontalScroll) {
- wheelDeltaX = 0;
- }
- var directionX = wheelDeltaX > 0
- ? -1 /* Negative */
- : wheelDeltaX < 0
- ? 1 /* Positive */
- : 0 /* Default */;
- var directionY = wheelDeltaY > 0
- ? -1 /* Negative */
- : wheelDeltaY < 0
- ? 1 /* Positive */
- : 0 /* Default */;
- return {
- x: wheelDeltaX,
- y: wheelDeltaY,
- directionX: directionX,
- directionY: directionY,
- };
- };
- MouseWheel.prototype.beforeHandler = function (e) {
- var _a = this.scroll.options, preventDefault = _a.preventDefault, stopPropagation = _a.stopPropagation, preventDefaultException = _a.preventDefaultException;
- if (preventDefault &&
- !preventDefaultExceptionFn(e.target, preventDefaultException)) {
- e.preventDefault();
- }
- if (stopPropagation) {
- e.stopPropagation();
- }
- };
- MouseWheel.prototype.getEaseTime = function () {
- var SAFE_EASETIME = 100;
- var easeTime = this.mouseWheelOpt.easeTime;
- // scrollEnd event will be triggered in every calling of scrollTo when easeTime is too small
- // easeTime needs to be greater than 100
- if (easeTime < SAFE_EASETIME) {
- warn("easeTime should be greater than 100." +
- "If mouseWheel easeTime is too small," +
- "scrollEnd will be triggered many times.");
- }
- return Math.max(easeTime, SAFE_EASETIME);
- };
- MouseWheel.prototype.destroy = function () {
- this.eventRegister.destroy();
- window.clearTimeout(this.wheelEndTimer);
- window.clearTimeout(this.wheelMoveTimer);
- this.hooksFn.forEach(function (item) {
- var hooks = item[0];
- var hooksName = item[1];
- var handlerFn = item[2];
- hooks.off(hooksName, handlerFn);
- });
- };
- MouseWheel.pluginName = 'mouseWheel';
- MouseWheel.applyOrder = "pre" /* Pre */;
- return MouseWheel;
- }());
- var ObserveDOM = /** @class */ (function () {
- function ObserveDOM(scroll) {
- this.scroll = scroll;
- this.stopObserver = false;
- this.init();
- }
- ObserveDOM.prototype.init = function () {
- this.handleMutationObserver();
- this.handleHooks();
- };
- ObserveDOM.prototype.handleMutationObserver = function () {
- var _this = this;
- if (typeof MutationObserver !== 'undefined') {
- var timer_1 = 0;
- this.observer = new MutationObserver(function (mutations) {
- _this.mutationObserverHandler(mutations, timer_1);
- });
- this.startObserve(this.observer);
- }
- else {
- this.checkDOMUpdate();
- }
- };
- ObserveDOM.prototype.handleHooks = function () {
- var _this = this;
- this.hooksFn = [];
- this.registerHooks(this.scroll.hooks, this.scroll.hooks.eventTypes.contentChanged, function () {
- _this.stopObserve();
- // launch a new mutationObserver
- _this.handleMutationObserver();
- });
- this.registerHooks(this.scroll.hooks, this.scroll.hooks.eventTypes.enable, function () {
- if (_this.stopObserver) {
- _this.handleMutationObserver();
- }
- });
- this.registerHooks(this.scroll.hooks, this.scroll.hooks.eventTypes.disable, function () {
- _this.stopObserve();
- });
- this.registerHooks(this.scroll.hooks, this.scroll.hooks.eventTypes.destroy, function () {
- _this.destroy();
- });
- };
- ObserveDOM.prototype.mutationObserverHandler = function (mutations, timer) {
- var _this = this;
- if (this.shouldNotRefresh()) {
- return;
- }
- var immediateRefresh = false;
- var deferredRefresh = false;
- for (var i = 0; i < mutations.length; i++) {
- var mutation = mutations[i];
- if (mutation.type !== 'attributes') {
- immediateRefresh = true;
- break;
- }
- else {
- if (mutation.target !== this.scroll.scroller.content) {
- deferredRefresh = true;
- break;
- }
- }
- }
- if (immediateRefresh) {
- this.scroll.refresh();
- }
- else if (deferredRefresh) {
- // attributes changes too often
- clearTimeout(timer);
- timer = window.setTimeout(function () {
- if (!_this.shouldNotRefresh()) {
- _this.scroll.refresh();
- }
- }, 60);
- }
- };
- ObserveDOM.prototype.startObserve = function (observer) {
- var config = {
- attributes: true,
- childList: true,
- subtree: true,
- };
- observer.observe(this.scroll.scroller.content, config);
- };
- ObserveDOM.prototype.shouldNotRefresh = function () {
- var scroller = this.scroll.scroller;
- var scrollBehaviorX = scroller.scrollBehaviorX, scrollBehaviorY = scroller.scrollBehaviorY;
- var outsideBoundaries = scrollBehaviorX.currentPos > scrollBehaviorX.minScrollPos ||
- scrollBehaviorX.currentPos < scrollBehaviorX.maxScrollPos ||
- scrollBehaviorY.currentPos > scrollBehaviorY.minScrollPos ||
- scrollBehaviorY.currentPos < scrollBehaviorY.maxScrollPos;
- return scroller.animater.pending || outsideBoundaries;
- };
- ObserveDOM.prototype.checkDOMUpdate = function () {
- var _this = this;
- var content = this.scroll.scroller.content;
- var contentRect = getRect(content);
- var oldWidth = contentRect.width;
- var oldHeight = contentRect.height;
- var check = function () {
- if (_this.stopObserver) {
- return;
- }
- contentRect = getRect(content);
- var newWidth = contentRect.width;
- var newHeight = contentRect.height;
- if (oldWidth !== newWidth || oldHeight !== newHeight) {
- _this.scroll.refresh();
- }
- oldWidth = newWidth;
- oldHeight = newHeight;
- next();
- };
- var next = function () {
- setTimeout(function () {
- check();
- }, 1000);
- };
- next();
- };
- ObserveDOM.prototype.registerHooks = function (hooks, name, handler) {
- hooks.on(name, handler, this);
- this.hooksFn.push([hooks, name, handler]);
- };
- ObserveDOM.prototype.stopObserve = function () {
- this.stopObserver = true;
- if (this.observer) {
- this.observer.disconnect();
- }
- };
- ObserveDOM.prototype.destroy = function () {
- this.stopObserve();
- this.hooksFn.forEach(function (item) {
- var hooks = item[0];
- var hooksName = item[1];
- var handlerFn = item[2];
- hooks.off(hooksName, handlerFn);
- });
- this.hooksFn.length = 0;
- };
- ObserveDOM.pluginName = 'observeDOM';
- return ObserveDOM;
- }());
- var sourcePrefix$6 = 'plugins.pullDownRefresh';
- var propertiesMap$6 = [
- {
- key: 'finishPullDown',
- name: 'finishPullDown'
- },
- {
- key: 'openPullDown',
- name: 'openPullDown'
- },
- {
- key: 'closePullDown',
- name: 'closePullDown'
- },
- {
- key: 'autoPullDownRefresh',
- name: 'autoPullDownRefresh'
- }
- ];
- var propertiesConfig$6 = propertiesMap$6.map(function (item) {
- return {
- key: item.key,
- sourceKey: sourcePrefix$6 + "." + item.name
- };
- });
- var PULLING_DOWN_EVENT = 'pullingDown';
- var ENTER_THRESHOLD_EVENT = 'enterThreshold';
- var LEAVE_THRESHOLD_EVENT = 'leaveThreshold';
- var PullDown = /** @class */ (function () {
- function PullDown(scroll) {
- this.scroll = scroll;
- this.pulling = 0 /* DEFAULT */;
- this.thresholdBoundary = 0 /* DEFAULT */;
- this.init();
- }
- PullDown.prototype.setPulling = function (status) {
- this.pulling = status;
- };
- PullDown.prototype.setThresholdBoundary = function (boundary) {
- this.thresholdBoundary = boundary;
- };
- PullDown.prototype.init = function () {
- this.handleBScroll();
- this.handleOptions(this.scroll.options.pullDownRefresh);
- this.handleHooks();
- this.watch();
- };
- PullDown.prototype.handleBScroll = function () {
- this.scroll.registerType([
- PULLING_DOWN_EVENT,
- ENTER_THRESHOLD_EVENT,
- LEAVE_THRESHOLD_EVENT,
- ]);
- this.scroll.proxy(propertiesConfig$6);
- };
- PullDown.prototype.handleOptions = function (userOptions) {
- if (userOptions === void 0) { userOptions = {}; }
- userOptions = (userOptions === true ? {} : userOptions);
- var defaultOptions = {
- threshold: 90,
- stop: 40,
- };
- this.options = extend(defaultOptions, userOptions);
- this.scroll.options.probeType = 3 /* Realtime */;
- };
- PullDown.prototype.handleHooks = function () {
- var _this = this;
- this.hooksFn = [];
- var scroller = this.scroll.scroller;
- var scrollBehaviorY = scroller.scrollBehaviorY;
- this.currentMinScrollY = this.cachedOriginanMinScrollY =
- scrollBehaviorY.minScrollPos;
- this.registerHooks(this.scroll.hooks, this.scroll.hooks.eventTypes.contentChanged, function () {
- _this.finishPullDown();
- });
- this.registerHooks(scrollBehaviorY.hooks, scrollBehaviorY.hooks.eventTypes.computeBoundary, function (boundary) {
- // content is smaller than wrapper
- if (boundary.maxScrollPos > 0) {
- // allow scrolling when content is not full of wrapper
- boundary.maxScrollPos = -1;
- }
- boundary.minScrollPos = _this.currentMinScrollY;
- });
- // integrate with mousewheel
- if (this.hasMouseWheelPlugin()) {
- this.registerHooks(this.scroll, this.scroll.eventTypes.alterOptions, function (mouseWheelOptions) {
- var SANE_DISCRETE_TIME = 300;
- var SANE_EASE_TIME = 350;
- mouseWheelOptions.discreteTime = SANE_DISCRETE_TIME;
- // easeTime > discreteTime ensure goInto checkPullDown function
- mouseWheelOptions.easeTime = SANE_EASE_TIME;
- });
- this.registerHooks(this.scroll, this.scroll.eventTypes.mousewheelEnd, function () {
- // mouseWheel need trigger checkPullDown manually
- scroller.hooks.trigger(scroller.hooks.eventTypes.end);
- });
- }
- };
- PullDown.prototype.registerHooks = function (hooks, name, handler) {
- hooks.on(name, handler, this);
- this.hooksFn.push([hooks, name, handler]);
- };
- PullDown.prototype.hasMouseWheelPlugin = function () {
- return !!this.scroll.eventTypes.alterOptions;
- };
- PullDown.prototype.watch = function () {
- var scroller = this.scroll.scroller;
- this.watching = true;
- this.registerHooks(scroller.hooks, scroller.hooks.eventTypes.end, this.checkPullDown);
- this.registerHooks(this.scroll, this.scroll.eventTypes.scrollStart, this.resetStateBeforeScrollStart);
- this.registerHooks(this.scroll, this.scroll.eventTypes.scroll, this.checkLocationOfThresholdBoundary);
- if (this.hasMouseWheelPlugin()) {
- this.registerHooks(this.scroll, this.scroll.eventTypes.mousewheelStart, this.resetStateBeforeScrollStart);
- }
- };
- PullDown.prototype.resetStateBeforeScrollStart = function () {
- // current fetching pulldownRefresh has ended
- if (!this.isFetchingStatus()) {
- this.setPulling(1 /* MOVING */);
- this.setThresholdBoundary(0 /* DEFAULT */);
- }
- };
- PullDown.prototype.checkLocationOfThresholdBoundary = function () {
- // pulldownRefresh is in the phase of Moving
- if (this.pulling === 1 /* MOVING */) {
- var scroll_1 = this.scroll;
- // enter threshold boundary
- var enteredThresholdBoundary = this.thresholdBoundary !== 1 /* INSIDE */ &&
- this.locateInsideThresholdBoundary();
- // leave threshold boundary
- var leftThresholdBoundary = this.thresholdBoundary !== 2 /* OUTSIDE */ &&
- !this.locateInsideThresholdBoundary();
- if (enteredThresholdBoundary) {
- this.setThresholdBoundary(1 /* INSIDE */);
- scroll_1.trigger(ENTER_THRESHOLD_EVENT);
- }
- if (leftThresholdBoundary) {
- this.setThresholdBoundary(2 /* OUTSIDE */);
- scroll_1.trigger(LEAVE_THRESHOLD_EVENT);
- }
- }
- };
- PullDown.prototype.locateInsideThresholdBoundary = function () {
- return this.scroll.y <= this.options.threshold;
- };
- PullDown.prototype.unwatch = function () {
- var scroll = this.scroll;
- var scroller = scroll.scroller;
- this.watching = false;
- scroller.hooks.off(scroller.hooks.eventTypes.end, this.checkPullDown);
- scroll.off(scroll.eventTypes.scrollStart, this.resetStateBeforeScrollStart);
- scroll.off(scroll.eventTypes.scroll, this.checkLocationOfThresholdBoundary);
- if (this.hasMouseWheelPlugin()) {
- scroll.off(scroll.eventTypes.mousewheelStart, this.resetStateBeforeScrollStart);
- }
- };
- PullDown.prototype.checkPullDown = function () {
- var _a = this.options, threshold = _a.threshold, stop = _a.stop;
- // check if a real pull down action
- if (this.scroll.y < threshold) {
- return false;
- }
- if (this.pulling === 1 /* MOVING */) {
- this.modifyBehaviorYBoundary(stop);
- this.setPulling(2 /* FETCHING */);
- this.scroll.trigger(PULLING_DOWN_EVENT);
- }
- this.scroll.scrollTo(this.scroll.x, stop, this.scroll.options.bounceTime, ease.bounce);
- return this.isFetchingStatus();
- };
- PullDown.prototype.isFetchingStatus = function () {
- return this.pulling === 2 /* FETCHING */;
- };
- PullDown.prototype.modifyBehaviorYBoundary = function (stopDistance) {
- var scrollBehaviorY = this.scroll.scroller.scrollBehaviorY;
- // manually modify minScrollPos for a hang animation
- // to prevent from resetPosition
- this.cachedOriginanMinScrollY = scrollBehaviorY.minScrollPos;
- this.currentMinScrollY = stopDistance;
- scrollBehaviorY.computeBoundary();
- };
- PullDown.prototype.finishPullDown = function () {
- if (this.isFetchingStatus()) {
- var scrollBehaviorY = this.scroll.scroller.scrollBehaviorY;
- // restore minScrollY since the hang animation has ended
- this.currentMinScrollY = this.cachedOriginanMinScrollY;
- scrollBehaviorY.computeBoundary();
- this.setPulling(0 /* DEFAULT */);
- this.scroll.resetPosition(this.scroll.options.bounceTime, ease.bounce);
- }
- };
- // allow 'true' type is compat for beta version implements
- PullDown.prototype.openPullDown = function (config) {
- if (config === void 0) { config = {}; }
- this.handleOptions(config);
- if (!this.watching) {
- this.watch();
- }
- };
- PullDown.prototype.closePullDown = function () {
- this.unwatch();
- };
- PullDown.prototype.autoPullDownRefresh = function () {
- var _a = this.options, threshold = _a.threshold, stop = _a.stop;
- if (this.isFetchingStatus() || !this.watching) {
- return;
- }
- this.modifyBehaviorYBoundary(stop);
- this.scroll.trigger(this.scroll.eventTypes.scrollStart);
- this.scroll.scrollTo(this.scroll.x, threshold);
- this.setPulling(2 /* FETCHING */);
- this.scroll.trigger(PULLING_DOWN_EVENT);
- this.scroll.scrollTo(this.scroll.x, stop, this.scroll.options.bounceTime, ease.bounce);
- };
- PullDown.pluginName = 'pullDownRefresh';
- return PullDown;
- }());
- var sourcePrefix$5 = 'plugins.pullUpLoad';
- var propertiesMap$5 = [
- {
- key: 'finishPullUp',
- name: 'finishPullUp'
- },
- {
- key: 'openPullUp',
- name: 'openPullUp'
- },
- {
- key: 'closePullUp',
- name: 'closePullUp'
- },
- {
- key: 'autoPullUpLoad',
- name: 'autoPullUpLoad'
- }
- ];
- var propertiesConfig$5 = propertiesMap$5.map(function (item) {
- return {
- key: item.key,
- sourceKey: sourcePrefix$5 + "." + item.name
- };
- });
- var PULL_UP_HOOKS_NAME = 'pullingUp';
- var PullUp = /** @class */ (function () {
- function PullUp(scroll) {
- this.scroll = scroll;
- this.pulling = false;
- this.watching = false;
- this.init();
- }
- PullUp.prototype.init = function () {
- this.handleBScroll();
- this.handleOptions(this.scroll.options.pullUpLoad);
- this.handleHooks();
- this.watch();
- };
- PullUp.prototype.handleBScroll = function () {
- this.scroll.registerType([PULL_UP_HOOKS_NAME]);
- this.scroll.proxy(propertiesConfig$5);
- };
- PullUp.prototype.handleOptions = function (userOptions) {
- if (userOptions === void 0) { userOptions = {}; }
- userOptions = (userOptions === true ? {} : userOptions);
- var defaultOptions = {
- threshold: 0,
- };
- this.options = extend(defaultOptions, userOptions);
- this.scroll.options.probeType = 3 /* Realtime */;
- };
- PullUp.prototype.handleHooks = function () {
- var _this = this;
- this.hooksFn = [];
- var scrollBehaviorY = this.scroll.scroller.scrollBehaviorY;
- this.registerHooks(this.scroll.hooks, this.scroll.hooks.eventTypes.contentChanged, function () {
- _this.finishPullUp();
- });
- this.registerHooks(scrollBehaviorY.hooks, scrollBehaviorY.hooks.eventTypes.computeBoundary, function (boundary) {
- // content is smaller than wrapper
- if (boundary.maxScrollPos > 0) {
- // allow scrolling when content is not full of wrapper
- boundary.maxScrollPos = -1;
- }
- });
- };
- PullUp.prototype.registerHooks = function (hooks, name, handler) {
- hooks.on(name, handler, this);
- this.hooksFn.push([hooks, name, handler]);
- };
- PullUp.prototype.watch = function () {
- if (this.watching) {
- return;
- }
- this.watching = true;
- this.registerHooks(this.scroll, this.scroll.eventTypes.scroll, this.checkPullUp);
- };
- PullUp.prototype.unwatch = function () {
- this.watching = false;
- this.scroll.off(this.scroll.eventTypes.scroll, this.checkPullUp);
- };
- PullUp.prototype.checkPullUp = function (pos) {
- var _this = this;
- var threshold = this.options.threshold;
- if (this.scroll.movingDirectionY === 1 /* Positive */ &&
- pos.y <= this.scroll.maxScrollY + threshold) {
- this.pulling = true;
- // must reset pulling after scrollEnd
- this.scroll.once(this.scroll.eventTypes.scrollEnd, function () {
- _this.pulling = false;
- });
- this.unwatch();
- this.scroll.trigger(PULL_UP_HOOKS_NAME);
- }
- };
- PullUp.prototype.finishPullUp = function () {
- var _this = this;
- // reset Direction, fix #936
- this.scroll.scroller.scrollBehaviorY.setMovingDirection(0 /* Default */);
- if (this.pulling) {
- this.scroll.once(this.scroll.eventTypes.scrollEnd, function () {
- _this.watch();
- });
- }
- else {
- this.watch();
- }
- };
- // allow 'true' type is compat for beta version implements
- PullUp.prototype.openPullUp = function (config) {
- if (config === void 0) { config = {}; }
- this.handleOptions(config);
- this.watch();
- };
- PullUp.prototype.closePullUp = function () {
- this.unwatch();
- };
- PullUp.prototype.autoPullUpLoad = function () {
- var threshold = this.options.threshold;
- var scrollBehaviorY = this.scroll.scroller.scrollBehaviorY;
- if (this.pulling || !this.watching) {
- return;
- }
- // simulate a pullUp action
- var NEGATIVE_VALUE = -1;
- var outOfBoundaryPos = scrollBehaviorY.maxScrollPos + threshold + NEGATIVE_VALUE;
- this.scroll.scroller.scrollBehaviorY.setMovingDirection(NEGATIVE_VALUE);
- this.scroll.scrollTo(this.scroll.x, outOfBoundaryPos, this.scroll.options.bounceTime);
- };
- PullUp.pluginName = 'pullUpLoad';
- return PullUp;
- }());
- var EventHandler = /** @class */ (function () {
- function EventHandler(indicator, options) {
- this.indicator = indicator;
- this.options = options;
- this.hooks = new EventEmitter(['touchStart', 'touchMove', 'touchEnd']);
- this.registerEvents();
- }
- EventHandler.prototype.registerEvents = function () {
- var _a = this.options, disableMouse = _a.disableMouse, disableTouch = _a.disableTouch;
- var startEvents = [];
- var moveEvents = [];
- var endEvents = [];
- if (!disableMouse) {
- startEvents.push({
- name: 'mousedown',
- handler: this.start.bind(this),
- });
- moveEvents.push({
- name: 'mousemove',
- handler: this.move.bind(this),
- });
- endEvents.push({
- name: 'mouseup',
- handler: this.end.bind(this),
- });
- }
- if (!disableTouch) {
- startEvents.push({
- name: 'touchstart',
- handler: this.start.bind(this),
- });
- moveEvents.push({
- name: 'touchmove',
- handler: this.move.bind(this),
- });
- endEvents.push({
- name: 'touchend',
- handler: this.end.bind(this),
- }, {
- name: 'touchcancel',
- handler: this.end.bind(this),
- });
- }
- this.startEventRegister = new EventRegister(this.indicator.indicatorEl, startEvents);
- this.moveEventRegister = new EventRegister(window, moveEvents);
- this.endEventRegister = new EventRegister(window, endEvents);
- };
- EventHandler.prototype.BScrollIsDisabled = function () {
- return !this.indicator.scroll.enabled;
- };
- EventHandler.prototype.start = function (e) {
- if (this.BScrollIsDisabled()) {
- return;
- }
- var point = (e.touches ? e.touches[0] : e);
- e.preventDefault();
- e.stopPropagation();
- this.initiated = true;
- this.lastPoint = point[this.indicator.keysMap.point];
- this.hooks.trigger(this.hooks.eventTypes.touchStart);
- };
- EventHandler.prototype.move = function (e) {
- if (!this.initiated) {
- return;
- }
- var point = (e.touches ? e.touches[0] : e);
- var pointPos = point[this.indicator.keysMap.point];
- e.preventDefault();
- e.stopPropagation();
- var delta = pointPos - this.lastPoint;
- this.lastPoint = pointPos;
- this.hooks.trigger(this.hooks.eventTypes.touchMove, delta);
- };
- EventHandler.prototype.end = function (e) {
- if (!this.initiated) {
- return;
- }
- this.initiated = false;
- e.preventDefault();
- e.stopPropagation();
- this.hooks.trigger(this.hooks.eventTypes.touchEnd);
- };
- EventHandler.prototype.destroy = function () {
- this.startEventRegister.destroy();
- this.moveEventRegister.destroy();
- this.endEventRegister.destroy();
- };
- return EventHandler;
- }());
- var Indicator$1 = /** @class */ (function () {
- function Indicator(scroll, options) {
- this.scroll = scroll;
- this.options = options;
- this.hooksFn = [];
- this.wrapper = options.wrapper;
- this.direction = options.direction;
- this.indicatorEl = this.wrapper.children[0];
- this.keysMap = this.getKeysMap();
- this.handleFade();
- this.handleHooks();
- }
- Indicator.prototype.handleFade = function () {
- if (this.options.fade) {
- this.wrapper.style.opacity = '0';
- }
- };
- Indicator.prototype.handleHooks = function () {
- var _this = this;
- var _a = this.options, fade = _a.fade, interactive = _a.interactive, scrollbarTrackClickable = _a.scrollbarTrackClickable;
- var scroll = this.scroll;
- var scrollHooks = scroll.hooks;
- var translaterHooks = scroll.scroller.translater.hooks;
- var animaterHooks = scroll.scroller.animater.hooks;
- this.registerHooks(scrollHooks, scrollHooks.eventTypes.refresh, this.refresh);
- this.registerHooks(translaterHooks, translaterHooks.eventTypes.translate, function (pos) {
- var hasScrollKey = _this.keysMap.hasScroll;
- if (_this.scroll[hasScrollKey]) {
- _this.updatePosition(pos);
- }
- });
- this.registerHooks(animaterHooks, animaterHooks.eventTypes.time, this.transitionTime);
- this.registerHooks(animaterHooks, animaterHooks.eventTypes.timeFunction, this.transitionTimingFunction);
- if (fade) {
- this.registerHooks(scroll, scroll.eventTypes.scrollEnd, function () {
- _this.fade();
- });
- this.registerHooks(scroll, scroll.eventTypes.scrollStart, function () {
- _this.fade(true);
- });
- // for mousewheel event
- if (scroll.eventTypes.mousewheelStart &&
- scroll.eventTypes.mousewheelEnd) {
- this.registerHooks(scroll, scroll.eventTypes.mousewheelStart, function () {
- _this.fade(true);
- });
- this.registerHooks(scroll, scroll.eventTypes.mousewheelMove, function () {
- _this.fade(true);
- });
- this.registerHooks(scroll, scroll.eventTypes.mousewheelEnd, function () {
- _this.fade();
- });
- }
- }
- if (interactive) {
- var _b = this.scroll.options, disableMouse = _b.disableMouse, disableTouch = _b.disableTouch;
- this.eventHandler = new EventHandler(this, {
- disableMouse: disableMouse,
- disableTouch: disableTouch,
- });
- var eventHandlerHooks = this.eventHandler.hooks;
- this.registerHooks(eventHandlerHooks, eventHandlerHooks.eventTypes.touchStart, this.startHandler);
- this.registerHooks(eventHandlerHooks, eventHandlerHooks.eventTypes.touchMove, this.moveHandler);
- this.registerHooks(eventHandlerHooks, eventHandlerHooks.eventTypes.touchEnd, this.endHandler);
- }
- if (scrollbarTrackClickable) {
- this.bindClick();
- }
- };
- Indicator.prototype.registerHooks = function (hooks, name, handler) {
- hooks.on(name, handler, this);
- this.hooksFn.push([hooks, name, handler]);
- };
- Indicator.prototype.bindClick = function () {
- var wrapper = this.wrapper;
- this.clickEventRegister = new EventRegister(wrapper, [
- {
- name: 'click',
- handler: this.handleClick.bind(this),
- },
- ]);
- };
- Indicator.prototype.handleClick = function (e) {
- var newPos = this.calculateclickOffsetPos(e);
- var _a = this.scroll, x = _a.x, y = _a.y;
- x = this.direction === "horizontal" /* Horizontal */ ? newPos : x;
- y = this.direction === "vertical" /* Vertical */ ? newPos : y;
- this.scroll.scrollTo(x, y, this.options.scrollbarTrackOffsetTime);
- };
- Indicator.prototype.calculateclickOffsetPos = function (e) {
- var _a = this.keysMap, poinKey = _a.point, domRectKey = _a.domRect;
- var scrollbarTrackOffsetType = this.options.scrollbarTrackOffsetType;
- var clickPointOffset = e[poinKey] - this.wrapperRect[domRectKey];
- var scrollToWhere = clickPointOffset < this.currentPos ? -1 /* Up */ : 1 /* Down */;
- var delta = 0;
- var currentPos = this.currentPos;
- if (scrollbarTrackOffsetType === "step" /* Step */) {
- delta = this.scrollInfo.baseSize * scrollToWhere;
- }
- else {
- delta = 0;
- currentPos = clickPointOffset;
- }
- return this.newPos(currentPos, delta, this.scrollInfo);
- };
- Indicator.prototype.getKeysMap = function () {
- if (this.direction === "vertical" /* Vertical */) {
- return {
- hasScroll: 'hasVerticalScroll',
- size: 'height',
- wrapperSize: 'clientHeight',
- scrollerSize: 'scrollerHeight',
- maxScrollPos: 'maxScrollY',
- pos: 'y',
- point: 'pageY',
- translateProperty: 'translateY',
- domRect: 'top',
- };
- }
- return {
- hasScroll: 'hasHorizontalScroll',
- size: 'width',
- wrapperSize: 'clientWidth',
- scrollerSize: 'scrollerWidth',
- maxScrollPos: 'maxScrollX',
- pos: 'x',
- point: 'pageX',
- translateProperty: 'translateX',
- domRect: 'left',
- };
- };
- Indicator.prototype.fade = function (visible) {
- var _a = this.options, fadeInTime = _a.fadeInTime, fadeOutTime = _a.fadeOutTime;
- var time = visible ? fadeInTime : fadeOutTime;
- var wrapper = this.wrapper;
- wrapper.style[style.transitionDuration] = time + 'ms';
- wrapper.style.opacity = visible ? '1' : '0';
- };
- Indicator.prototype.refresh = function () {
- var hasScrollKey = this.keysMap.hasScroll;
- var scroll = this.scroll;
- var x = scroll.x, y = scroll.y;
- this.wrapperRect = this.wrapper.getBoundingClientRect();
- if (this.canScroll(scroll[hasScrollKey])) {
- var _a = this.keysMap, wrapperSizeKey = _a.wrapperSize, scrollerSizeKey = _a.scrollerSize, maxScrollPosKey = _a.maxScrollPos;
- this.scrollInfo = this.refreshScrollInfo(this.wrapper[wrapperSizeKey], scroll[scrollerSizeKey], scroll[maxScrollPosKey], this.indicatorEl[wrapperSizeKey]);
- this.updatePosition({
- x: x,
- y: y,
- });
- }
- };
- Indicator.prototype.transitionTime = function (time) {
- if (time === void 0) { time = 0; }
- this.indicatorEl.style[style.transitionDuration] = time + 'ms';
- };
- Indicator.prototype.transitionTimingFunction = function (easing) {
- this.indicatorEl.style[style.transitionTimingFunction] = easing;
- };
- Indicator.prototype.canScroll = function (hasScroll) {
- this.wrapper.style.display = hasScroll ? 'block' : 'none';
- return hasScroll;
- };
- Indicator.prototype.refreshScrollInfo = function (wrapperSize, scrollerSize, maxScrollPos, indicatorElSize) {
- var baseSize = Math.max(Math.round((wrapperSize * wrapperSize) / (scrollerSize || wrapperSize || 1)), this.options.minSize);
- if (this.options.isCustom) {
- baseSize = indicatorElSize;
- }
- var maxIndicatorScrollPos = wrapperSize - baseSize;
- // sizeRatio is negative
- var sizeRatio = maxIndicatorScrollPos / maxScrollPos;
- return {
- baseSize: baseSize,
- maxScrollPos: maxIndicatorScrollPos,
- minScrollPos: 0,
- sizeRatio: sizeRatio,
- };
- };
- Indicator.prototype.updatePosition = function (point) {
- var _a = this.caculatePosAndSize(point, this.scrollInfo), pos = _a.pos, size = _a.size;
- this.refreshStyle(size, pos);
- this.currentPos = pos;
- };
- Indicator.prototype.caculatePosAndSize = function (point, scrollInfo) {
- var posKey = this.keysMap.pos;
- var sizeRatio = scrollInfo.sizeRatio, baseSize = scrollInfo.baseSize, maxScrollPos = scrollInfo.maxScrollPos, minScrollPos = scrollInfo.minScrollPos;
- var minSize = this.options.minSize;
- var pos = Math.round(sizeRatio * point[posKey]);
- var size;
- // when out of boundary, slow down size reduction
- if (pos < minScrollPos) {
- size = Math.max(baseSize + pos * 3, minSize);
- pos = minScrollPos;
- }
- else if (pos > maxScrollPos) {
- size = Math.max(baseSize - (pos - maxScrollPos) * 3, minSize);
- pos = maxScrollPos + baseSize - size;
- }
- else {
- size = baseSize;
- }
- return {
- pos: pos,
- size: size,
- };
- };
- Indicator.prototype.refreshStyle = function (size, pos) {
- var _a = this.keysMap, translatePropertyKey = _a.translateProperty, sizeKey = _a.size;
- var translateZ = this.scroll.options.translateZ;
- this.indicatorEl.style[sizeKey] = size + "px";
- this.indicatorEl.style[style.transform] = translatePropertyKey + "(" + pos + "px)" + translateZ;
- };
- Indicator.prototype.startHandler = function () {
- this.moved = false;
- this.startTime = getNow();
- this.transitionTime();
- this.scroll.scroller.hooks.trigger(this.scroll.scroller.hooks.eventTypes.beforeScrollStart);
- };
- Indicator.prototype.moveHandler = function (delta) {
- if (!this.moved && !this.indicatorNotMoved(delta)) {
- this.moved = true;
- this.scroll.scroller.hooks.trigger(this.scroll.scroller.hooks.eventTypes.scrollStart);
- }
- if (this.moved) {
- var newPos = this.newPos(this.currentPos, delta, this.scrollInfo);
- this.syncBScroll(newPos);
- }
- };
- Indicator.prototype.endHandler = function () {
- if (this.moved) {
- var _a = this.scroll, x = _a.x, y = _a.y;
- this.scroll.scroller.hooks.trigger(this.scroll.scroller.hooks.eventTypes.scrollEnd, {
- x: x,
- y: y,
- });
- }
- };
- Indicator.prototype.indicatorNotMoved = function (delta) {
- var currentPos = this.currentPos;
- var _a = this.scrollInfo, maxScrollPos = _a.maxScrollPos, minScrollPos = _a.minScrollPos;
- var notMoved = (currentPos === minScrollPos && delta <= 0) ||
- (currentPos === maxScrollPos && delta >= 0);
- return notMoved;
- };
- Indicator.prototype.syncBScroll = function (newPos) {
- var timestamp = getNow();
- 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;
- var probeType = options.probeType, momentumLimitTime = options.momentumLimitTime;
- var position = { x: x, y: y };
- if (this.direction === "vertical" /* Vertical */) {
- position.y = between(newPos, maxScrollY, minScrollY);
- }
- else {
- position.x = between(newPos, maxScrollX, minScrollX);
- }
- scroller.translater.translate(position);
- // dispatch scroll in interval time
- if (timestamp - this.startTime > momentumLimitTime) {
- this.startTime = timestamp;
- if (probeType === 1 /* Throttle */) {
- scroller.hooks.trigger(scroller.hooks.eventTypes.scroll, position);
- }
- }
- // dispatch scroll all the time
- if (probeType > 1 /* Throttle */) {
- scroller.hooks.trigger(scroller.hooks.eventTypes.scroll, position);
- }
- };
- Indicator.prototype.newPos = function (currentPos, delta, scrollInfo) {
- var maxScrollPos = scrollInfo.maxScrollPos, sizeRatio = scrollInfo.sizeRatio, minScrollPos = scrollInfo.minScrollPos;
- var newPos = currentPos + delta;
- newPos = between(newPos, minScrollPos, maxScrollPos);
- return Math.round(newPos / sizeRatio);
- };
- Indicator.prototype.destroy = function () {
- var _a = this.options, interactive = _a.interactive, scrollbarTrackClickable = _a.scrollbarTrackClickable, isCustom = _a.isCustom;
- if (interactive) {
- this.eventHandler.destroy();
- }
- if (scrollbarTrackClickable) {
- this.clickEventRegister.destroy();
- }
- if (!isCustom) {
- this.wrapper.parentNode.removeChild(this.wrapper);
- }
- this.hooksFn.forEach(function (item) {
- var hooks = item[0];
- var hooksName = item[1];
- var handlerFn = item[2];
- hooks.off(hooksName, handlerFn);
- });
- this.hooksFn.length = 0;
- };
- return Indicator;
- }());
- var ScrollBar = /** @class */ (function () {
- function ScrollBar(scroll) {
- this.scroll = scroll;
- this.handleOptions();
- this.createIndicators();
- this.handleHooks();
- }
- ScrollBar.prototype.handleHooks = function () {
- var _this = this;
- var scroll = this.scroll;
- scroll.hooks.on(scroll.hooks.eventTypes.destroy, function () {
- for (var _i = 0, _a = _this.indicators; _i < _a.length; _i++) {
- var indicator = _a[_i];
- indicator.destroy();
- }
- });
- };
- ScrollBar.prototype.handleOptions = function () {
- var userOptions = (this.scroll.options.scrollbar === true
- ? {}
- : this.scroll.options.scrollbar);
- var defaultOptions = {
- fade: true,
- fadeInTime: 250,
- fadeOutTime: 500,
- interactive: false,
- customElements: [],
- minSize: 8,
- scrollbarTrackClickable: false,
- scrollbarTrackOffsetType: "step" /* Step */,
- scrollbarTrackOffsetTime: 300,
- };
- this.options = extend(defaultOptions, userOptions);
- };
- ScrollBar.prototype.createIndicators = function () {
- var indicatorOptions;
- var scroll = this.scroll;
- var indicators = [];
- var scrollDirectionConfigKeys = ['scrollX', 'scrollY'];
- var indicatorDirections = [
- "horizontal" /* Horizontal */,
- "vertical" /* Vertical */,
- ];
- var customScrollbarEls = this.options.customElements;
- for (var i = 0; i < scrollDirectionConfigKeys.length; i++) {
- var key = scrollDirectionConfigKeys[i];
- // wanna scroll in specified direction
- if (scroll.options[key]) {
- var customElement = customScrollbarEls.shift();
- var direction = indicatorDirections[i];
- var isCustom = false;
- var scrollbarWrapper = customElement
- ? customElement
- : this.createScrollbarElement(direction);
- // internal scrollbar
- if (scrollbarWrapper !== customElement) {
- scroll.wrapper.appendChild(scrollbarWrapper);
- }
- else {
- // custom scrollbar passed by users
- isCustom = true;
- }
- indicatorOptions = __assign(__assign({ wrapper: scrollbarWrapper, direction: direction }, this.options), { isCustom: isCustom });
- indicators.push(new Indicator$1(scroll, indicatorOptions));
- }
- }
- this.indicators = indicators;
- };
- ScrollBar.prototype.createScrollbarElement = function (direction, scrollbarTrackClickable) {
- if (scrollbarTrackClickable === void 0) { scrollbarTrackClickable = this.options.scrollbarTrackClickable; }
- var scrollbarWrapperEl = document.createElement('div');
- var scrollbarIndicatorEl = document.createElement('div');
- scrollbarWrapperEl.style.cssText =
- 'position:absolute;z-index:9999;overflow:hidden;';
- scrollbarIndicatorEl.style.cssText =
- '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;';
- scrollbarIndicatorEl.className = 'bscroll-indicator';
- if (direction === "horizontal" /* Horizontal */) {
- scrollbarWrapperEl.style.cssText +=
- 'height:7px;left:2px;right:2px;bottom:0;';
- scrollbarIndicatorEl.style.height = '100%';
- scrollbarWrapperEl.className = 'bscroll-horizontal-scrollbar';
- }
- else {
- scrollbarWrapperEl.style.cssText +=
- 'width:7px;bottom:2px;top:2px;right:1px;';
- scrollbarIndicatorEl.style.width = '100%';
- scrollbarWrapperEl.className = 'bscroll-vertical-scrollbar';
- }
- if (!scrollbarTrackClickable) {
- scrollbarWrapperEl.style.cssText += 'pointer-events:none;';
- }
- scrollbarWrapperEl.appendChild(scrollbarIndicatorEl);
- return scrollbarWrapperEl;
- };
- ScrollBar.pluginName = 'scrollbar';
- return ScrollBar;
- }());
- var PagesMatrix = /** @class */ (function () {
- function PagesMatrix(scroll) {
- this.scroll = scroll;
- this.init();
- }
- PagesMatrix.prototype.init = function () {
- var scroller = this.scroll.scroller;
- var scrollBehaviorX = scroller.scrollBehaviorX, scrollBehaviorY = scroller.scrollBehaviorY;
- this.wrapperWidth = scrollBehaviorX.wrapperSize;
- this.wrapperHeight = scrollBehaviorY.wrapperSize;
- this.scrollerHeight = scrollBehaviorY.contentSize;
- this.scrollerWidth = scrollBehaviorX.contentSize;
- this.pages = this.buildPagesMatrix(this.wrapperWidth, this.wrapperHeight);
- this.pageLengthOfX = this.pages ? this.pages.length : 0;
- this.pageLengthOfY = this.pages && this.pages[0] ? this.pages[0].length : 0;
- };
- PagesMatrix.prototype.getPageStats = function (pageX, pageY) {
- return this.pages[pageX][pageY];
- };
- PagesMatrix.prototype.getNearestPageIndex = function (x, y) {
- var pageX = 0;
- var pageY = 0;
- var l = this.pages.length;
- for (; pageX < l - 1; pageX++) {
- if (x >= this.pages[pageX][0].cx) {
- break;
- }
- }
- l = this.pages[pageX].length;
- for (; pageY < l - 1; pageY++) {
- if (y >= this.pages[0][pageY].cy) {
- break;
- }
- }
- return {
- pageX: pageX,
- pageY: pageY,
- };
- };
- // (n x 1) matrix for horizontal scroll or
- // (1 * n) matrix for vertical scroll
- PagesMatrix.prototype.buildPagesMatrix = function (stepX, stepY) {
- var pages = [];
- var x = 0;
- var y;
- var cx;
- var cy;
- var i = 0;
- var l;
- var maxScrollPosX = this.scroll.scroller.scrollBehaviorX.maxScrollPos;
- var maxScrollPosY = this.scroll.scroller.scrollBehaviorY.maxScrollPos;
- cx = Math.round(stepX / 2);
- cy = Math.round(stepY / 2);
- while (x > -this.scrollerWidth) {
- pages[i] = [];
- l = 0;
- y = 0;
- while (y > -this.scrollerHeight) {
- pages[i][l] = {
- x: Math.max(x, maxScrollPosX),
- y: Math.max(y, maxScrollPosY),
- width: stepX,
- height: stepY,
- cx: x - cx,
- cy: y - cy,
- };
- y -= stepY;
- l++;
- }
- x -= stepX;
- i++;
- }
- return pages;
- };
- return PagesMatrix;
- }());
- var BASE_PAGE = {
- pageX: 0,
- pageY: 0,
- x: 0,
- y: 0,
- };
- var SlidePages = /** @class */ (function () {
- function SlidePages(scroll, slideOptions) {
- this.scroll = scroll;
- this.slideOptions = slideOptions;
- this.slideX = false;
- this.slideY = false;
- this.currentPage = extend({}, BASE_PAGE);
- }
- SlidePages.prototype.refresh = function () {
- this.pagesMatrix = new PagesMatrix(this.scroll);
- this.checkSlideLoop();
- this.currentPage = this.getAdjustedCurrentPage();
- };
- SlidePages.prototype.getAdjustedCurrentPage = function () {
- var _a = this.currentPage, pageX = _a.pageX, pageY = _a.pageY;
- // page index should be handled
- // because page counts may reduce
- pageX = Math.min(pageX, this.pagesMatrix.pageLengthOfX - 1);
- pageY = Math.min(pageY, this.pagesMatrix.pageLengthOfY - 1);
- // loop scene should also be respected
- // because clonedNode will cause pageLength increasing
- if (this.loopX) {
- pageX = Math.min(pageX, this.pagesMatrix.pageLengthOfX - 2);
- }
- if (this.loopY) {
- pageY = Math.min(pageY, this.pagesMatrix.pageLengthOfY - 2);
- }
- var _b = this.pagesMatrix.getPageStats(pageX, pageY), x = _b.x, y = _b.y;
- return { pageX: pageX, pageY: pageY, x: x, y: y };
- };
- SlidePages.prototype.setCurrentPage = function (newPage) {
- this.currentPage = newPage;
- };
- SlidePages.prototype.getInternalPage = function (pageX, pageY) {
- if (pageX >= this.pagesMatrix.pageLengthOfX) {
- pageX = this.pagesMatrix.pageLengthOfX - 1;
- }
- else if (pageX < 0) {
- pageX = 0;
- }
- if (pageY >= this.pagesMatrix.pageLengthOfY) {
- pageY = this.pagesMatrix.pageLengthOfY - 1;
- }
- else if (pageY < 0) {
- pageY = 0;
- }
- var _a = this.pagesMatrix.getPageStats(pageX, pageY), x = _a.x, y = _a.y;
- return {
- pageX: pageX,
- pageY: pageY,
- x: x,
- y: y,
- };
- };
- SlidePages.prototype.getInitialPage = function (showFirstPage, firstInitialised) {
- if (showFirstPage === void 0) { showFirstPage = false; }
- if (firstInitialised === void 0) { firstInitialised = false; }
- var _a = this.slideOptions, startPageXIndex = _a.startPageXIndex, startPageYIndex = _a.startPageYIndex;
- var firstPageX = this.loopX ? 1 : 0;
- var firstPageY = this.loopY ? 1 : 0;
- var pageX = showFirstPage ? firstPageX : this.currentPage.pageX;
- var pageY = showFirstPage ? firstPageY : this.currentPage.pageY;
- if (firstInitialised) {
- pageX = this.loopX ? startPageXIndex + 1 : startPageXIndex;
- pageY = this.loopY ? startPageYIndex + 1 : startPageYIndex;
- }
- else {
- pageX = showFirstPage ? firstPageX : this.currentPage.pageX;
- pageY = showFirstPage ? firstPageY : this.currentPage.pageY;
- }
- var _b = this.pagesMatrix.getPageStats(pageX, pageY), x = _b.x, y = _b.y;
- return {
- pageX: pageX,
- pageY: pageY,
- x: x,
- y: y,
- };
- };
- SlidePages.prototype.getExposedPage = function (page) {
- var exposedPage = extend({}, page);
- // only pageX or pageY need fix
- if (this.loopX) {
- exposedPage.pageX = this.fixedPage(exposedPage.pageX, this.pagesMatrix.pageLengthOfX - 2);
- }
- if (this.loopY) {
- exposedPage.pageY = this.fixedPage(exposedPage.pageY, this.pagesMatrix.pageLengthOfY - 2);
- }
- return exposedPage;
- };
- SlidePages.prototype.getExposedPageByPageIndex = function (pageIndexX, pageIndexY) {
- var page = {
- pageX: pageIndexX,
- pageY: pageIndexY,
- };
- if (this.loopX) {
- page.pageX = pageIndexX + 1;
- }
- if (this.loopY) {
- page.pageY = pageIndexY + 1;
- }
- var _a = this.pagesMatrix.getPageStats(page.pageX, page.pageY), x = _a.x, y = _a.y;
- return {
- x: x,
- y: y,
- pageX: pageIndexX,
- pageY: pageIndexY,
- };
- };
- SlidePages.prototype.getWillChangedPage = function (page) {
- page = extend({}, page);
- // Page need fix
- if (this.loopX) {
- page.pageX = this.fixedPage(page.pageX, this.pagesMatrix.pageLengthOfX - 2);
- page.x = this.pagesMatrix.getPageStats(page.pageX + 1, 0).x;
- }
- if (this.loopY) {
- page.pageY = this.fixedPage(page.pageY, this.pagesMatrix.pageLengthOfY - 2);
- page.y = this.pagesMatrix.getPageStats(0, page.pageY + 1).y;
- }
- return page;
- };
- SlidePages.prototype.fixedPage = function (page, realPageLen) {
- var pageIndex = [];
- for (var i = 0; i < realPageLen; i++) {
- pageIndex.push(i);
- }
- pageIndex.unshift(realPageLen - 1);
- pageIndex.push(0);
- return pageIndex[page];
- };
- SlidePages.prototype.getPageStats = function () {
- return this.pagesMatrix.getPageStats(this.currentPage.pageX, this.currentPage.pageY);
- };
- SlidePages.prototype.getValidPageIndex = function (x, y) {
- var lastX = this.pagesMatrix.pageLengthOfX - 1;
- var lastY = this.pagesMatrix.pageLengthOfY - 1;
- var firstX = 0;
- var firstY = 0;
- if (this.loopX) {
- x += 1;
- firstX = firstX + 1;
- lastX = lastX - 1;
- }
- if (this.loopY) {
- y += 1;
- firstY = firstY + 1;
- lastY = lastY - 1;
- }
- x = between(x, firstX, lastX);
- y = between(y, firstY, lastY);
- return {
- pageX: x,
- pageY: y,
- };
- };
- SlidePages.prototype.nextPageIndex = function () {
- return this.getPageIndexByDirection("positive" /* Positive */);
- };
- SlidePages.prototype.prevPageIndex = function () {
- return this.getPageIndexByDirection("negative" /* Negative */);
- };
- SlidePages.prototype.getNearestPage = function (x, y) {
- var pageIndex = this.pagesMatrix.getNearestPageIndex(x, y);
- var pageX = pageIndex.pageX, pageY = pageIndex.pageY;
- var newX = this.pagesMatrix.getPageStats(pageX, 0).x;
- var newY = this.pagesMatrix.getPageStats(0, pageY).y;
- return {
- x: newX,
- y: newY,
- pageX: pageX,
- pageY: pageY,
- };
- };
- SlidePages.prototype.getPageByDirection = function (page, directionX, directionY) {
- var pageX = page.pageX, pageY = page.pageY;
- if (pageX === this.currentPage.pageX) {
- pageX = between(pageX + directionX, 0, this.pagesMatrix.pageLengthOfX - 1);
- }
- if (pageY === this.currentPage.pageY) {
- pageY = between(pageY + directionY, 0, this.pagesMatrix.pageLengthOfY - 1);
- }
- var x = this.pagesMatrix.getPageStats(pageX, 0).x;
- var y = this.pagesMatrix.getPageStats(0, pageY).y;
- return {
- x: x,
- y: y,
- pageX: pageX,
- pageY: pageY,
- };
- };
- SlidePages.prototype.resetLoopPage = function () {
- if (this.loopX) {
- if (this.currentPage.pageX === 0) {
- return {
- pageX: this.pagesMatrix.pageLengthOfX - 2,
- pageY: this.currentPage.pageY,
- };
- }
- if (this.currentPage.pageX === this.pagesMatrix.pageLengthOfX - 1) {
- return {
- pageX: 1,
- pageY: this.currentPage.pageY,
- };
- }
- }
- if (this.loopY) {
- if (this.currentPage.pageY === 0) {
- return {
- pageX: this.currentPage.pageX,
- pageY: this.pagesMatrix.pageLengthOfY - 2,
- };
- }
- if (this.currentPage.pageY === this.pagesMatrix.pageLengthOfY - 1) {
- return {
- pageX: this.currentPage.pageX,
- pageY: 1,
- };
- }
- }
- };
- SlidePages.prototype.getPageIndexByDirection = function (direction) {
- var x = this.currentPage.pageX;
- var y = this.currentPage.pageY;
- if (this.slideX) {
- x = direction === "negative" /* Negative */ ? x - 1 : x + 1;
- }
- if (this.slideY) {
- y = direction === "negative" /* Negative */ ? y - 1 : y + 1;
- }
- return {
- pageX: x,
- pageY: y,
- };
- };
- SlidePages.prototype.checkSlideLoop = function () {
- this.wannaLoop = this.slideOptions.loop;
- if (this.pagesMatrix.pageLengthOfX > 1) {
- this.slideX = true;
- }
- else {
- this.slideX = false;
- }
- if (this.pagesMatrix.pages[0] && this.pagesMatrix.pageLengthOfY > 1) {
- this.slideY = true;
- }
- else {
- this.slideY = false;
- }
- this.loopX = this.wannaLoop && this.slideX;
- this.loopY = this.wannaLoop && this.slideY;
- if (this.slideX && this.slideY) {
- warn('slide does not support two direction at the same time.');
- }
- };
- return SlidePages;
- }());
- var sourcePrefix$4 = 'plugins.slide';
- var propertiesMap$4 = [
- {
- key: 'next',
- name: 'next',
- },
- {
- key: 'prev',
- name: 'prev',
- },
- {
- key: 'goToPage',
- name: 'goToPage',
- },
- {
- key: 'getCurrentPage',
- name: 'getCurrentPage',
- },
- {
- key: 'startPlay',
- name: 'startPlay',
- },
- {
- key: 'pausePlay',
- name: 'pausePlay',
- },
- ];
- var propertiesConfig$4 = propertiesMap$4.map(function (item) {
- return {
- key: item.key,
- sourceKey: sourcePrefix$4 + "." + item.name,
- };
- });
- var samePage = function (p1, p2) {
- return p1.pageX === p2.pageX && p1.pageY === p2.pageY;
- };
- var Slide = /** @class */ (function () {
- function Slide(scroll) {
- this.scroll = scroll;
- this.cachedClonedPageDOM = [];
- this.resetLooping = false;
- this.autoplayTimer = 0;
- if (!this.satisfyInitialization()) {
- return;
- }
- this.init();
- }
- Slide.prototype.satisfyInitialization = function () {
- if (this.scroll.scroller.content.children.length <= 0) {
- warn("slide need at least one slide page to be initialised." +
- "please check your DOM layout.");
- return false;
- }
- return true;
- };
- Slide.prototype.init = function () {
- this.willChangeToPage = extend({}, BASE_PAGE);
- this.handleBScroll();
- this.handleOptions();
- this.handleHooks();
- this.createPages();
- };
- Slide.prototype.createPages = function () {
- this.pages = new SlidePages(this.scroll, this.options);
- };
- Slide.prototype.handleBScroll = function () {
- this.scroll.registerType(['slideWillChange', 'slidePageChanged']);
- this.scroll.proxy(propertiesConfig$4);
- };
- Slide.prototype.handleOptions = function () {
- var userOptions = (this.scroll.options.slide === true
- ? {}
- : this.scroll.options.slide);
- var defaultOptions = {
- loop: true,
- threshold: 0.1,
- speed: 400,
- easing: ease.bounce,
- listenFlick: true,
- autoplay: true,
- interval: 3000,
- startPageXIndex: 0,
- startPageYIndex: 0,
- };
- this.options = extend(defaultOptions, userOptions);
- };
- Slide.prototype.handleLoop = function (prevSlideContent) {
- var loop = this.options.loop;
- var slideContent = this.scroll.scroller.content;
- var currentSlidePagesLength = slideContent.children.length;
- // only should respect loop scene
- if (loop) {
- if (slideContent !== prevSlideContent) {
- this.resetLoopChangedStatus();
- this.removeClonedSlidePage(prevSlideContent);
- currentSlidePagesLength > 1 &&
- this.cloneFirstAndLastSlidePage(slideContent);
- }
- else {
- // many pages reduce to one page
- if (currentSlidePagesLength === 3 && this.initialised) {
- this.removeClonedSlidePage(slideContent);
- this.moreToOnePageInLoop = true;
- this.oneToMorePagesInLoop = false;
- }
- else if (currentSlidePagesLength > 1) {
- // one page increases to many page
- if (this.initialised && this.cachedClonedPageDOM.length === 0) {
- this.oneToMorePagesInLoop = true;
- this.moreToOnePageInLoop = false;
- }
- else {
- this.removeClonedSlidePage(slideContent);
- this.resetLoopChangedStatus();
- }
- this.cloneFirstAndLastSlidePage(slideContent);
- }
- else {
- this.resetLoopChangedStatus();
- }
- }
- }
- };
- Slide.prototype.resetLoopChangedStatus = function () {
- this.moreToOnePageInLoop = false;
- this.oneToMorePagesInLoop = false;
- };
- Slide.prototype.handleHooks = function () {
- var _this = this;
- var scrollHooks = this.scroll.hooks;
- var scrollerHooks = this.scroll.scroller.hooks;
- var listenFlick = this.options.listenFlick;
- this.prevContent = this.scroll.scroller.content;
- this.hooksFn = [];
- // scroll
- this.registerHooks(this.scroll, this.scroll.eventTypes.beforeScrollStart, this.pausePlay);
- this.registerHooks(this.scroll, this.scroll.eventTypes.scrollEnd, this.modifyCurrentPage);
- this.registerHooks(this.scroll, this.scroll.eventTypes.scrollEnd, this.startPlay);
- // for mousewheel event
- if (this.scroll.eventTypes.mousewheelMove) {
- this.registerHooks(this.scroll, this.scroll.eventTypes.mousewheelMove, function () {
- // prevent default action of mousewheelMove
- return true;
- });
- this.registerHooks(this.scroll, this.scroll.eventTypes.mousewheelEnd, function (delta) {
- if (delta.directionX === 1 /* Positive */ ||
- delta.directionY === 1 /* Positive */) {
- _this.next();
- }
- if (delta.directionX === -1 /* Negative */ ||
- delta.directionY === -1 /* Negative */) {
- _this.prev();
- }
- });
- }
- // scrollHooks
- this.registerHooks(scrollHooks, scrollHooks.eventTypes.refresh, this.refreshHandler);
- this.registerHooks(scrollHooks, scrollHooks.eventTypes.destroy, this.destroy);
- // scroller
- this.registerHooks(scrollerHooks, scrollerHooks.eventTypes.beforeRefresh, function () {
- _this.handleLoop(_this.prevContent);
- _this.setSlideInlineStyle();
- });
- this.registerHooks(scrollerHooks, scrollerHooks.eventTypes.momentum, this.modifyScrollMetaHandler);
- this.registerHooks(scrollerHooks, scrollerHooks.eventTypes.scroll, this.scrollHandler);
- // a click operation will clearTimer, so restart a new one
- this.registerHooks(scrollerHooks, scrollerHooks.eventTypes.checkClick, this.startPlay);
- if (listenFlick) {
- this.registerHooks(scrollerHooks, scrollerHooks.eventTypes.flick, this.flickHandler);
- }
- };
- Slide.prototype.startPlay = function () {
- var _this = this;
- var _a = this.options, interval = _a.interval, autoplay = _a.autoplay;
- if (autoplay) {
- clearTimeout(this.autoplayTimer);
- this.autoplayTimer = window.setTimeout(function () {
- _this.next();
- }, interval);
- }
- };
- Slide.prototype.pausePlay = function () {
- if (this.options.autoplay) {
- clearTimeout(this.autoplayTimer);
- }
- };
- Slide.prototype.setSlideInlineStyle = function () {
- var styleConfigurations = [
- {
- direction: 'scrollX',
- sizeType: 'offsetWidth',
- styleType: 'width',
- },
- {
- direction: 'scrollY',
- sizeType: 'offsetHeight',
- styleType: 'height',
- },
- ];
- var _a = this.scroll.scroller, slideContent = _a.content, slideWrapper = _a.wrapper;
- var scrollOptions = this.scroll.options;
- styleConfigurations.forEach(function (_a) {
- var direction = _a.direction, sizeType = _a.sizeType, styleType = _a.styleType;
- // wanna scroll in this direction
- if (scrollOptions[direction]) {
- var size = slideWrapper[sizeType];
- var children = slideContent.children;
- var length_1 = children.length;
- for (var i = 0; i < length_1; i++) {
- var slidePageDOM = children[i];
- slidePageDOM.style[styleType] = size + 'px';
- }
- slideContent.style[styleType] = size * length_1 + 'px';
- }
- });
- };
- Slide.prototype.next = function (time, easing) {
- var _a = this.pages.nextPageIndex(), pageX = _a.pageX, pageY = _a.pageY;
- this.goTo(pageX, pageY, time, easing);
- };
- Slide.prototype.prev = function (time, easing) {
- var _a = this.pages.prevPageIndex(), pageX = _a.pageX, pageY = _a.pageY;
- this.goTo(pageX, pageY, time, easing);
- };
- Slide.prototype.goToPage = function (pageX, pageY, time, easing) {
- var pageIndex = this.pages.getValidPageIndex(pageX, pageY);
- this.goTo(pageIndex.pageX, pageIndex.pageY, time, easing);
- };
- Slide.prototype.getCurrentPage = function () {
- return this.exposedPage || this.pages.getInitialPage(false, true);
- };
- Slide.prototype.setCurrentPage = function (page) {
- this.pages.setCurrentPage(page);
- this.exposedPage = this.pages.getExposedPage(page);
- };
- Slide.prototype.nearestPage = function (x, y) {
- var _a = this.scroll.scroller, scrollBehaviorX = _a.scrollBehaviorX, scrollBehaviorY = _a.scrollBehaviorY;
- var maxScrollPosX = scrollBehaviorX.maxScrollPos, minScrollPosX = scrollBehaviorX.minScrollPos;
- var maxScrollPosY = scrollBehaviorY.maxScrollPos, minScrollPosY = scrollBehaviorY.minScrollPos;
- return this.pages.getNearestPage(between(x, maxScrollPosX, minScrollPosX), between(y, maxScrollPosY, minScrollPosY));
- };
- Slide.prototype.satisfyThreshold = function (x, y) {
- var _a = this.scroll.scroller, scrollBehaviorX = _a.scrollBehaviorX, scrollBehaviorY = _a.scrollBehaviorY;
- var satisfied = true;
- if (Math.abs(x - scrollBehaviorX.absStartPos) <= this.thresholdX &&
- Math.abs(y - scrollBehaviorY.absStartPos) <= this.thresholdY) {
- satisfied = false;
- }
- return satisfied;
- };
- Slide.prototype.refreshHandler = function (content) {
- var _this = this;
- if (!this.satisfyInitialization()) {
- return;
- }
- this.pages.refresh();
- this.computeThreshold();
- var contentChanged = (this.contentChanged = this.prevContent !== content);
- if (contentChanged) {
- this.prevContent = content;
- }
- var initPage = this.pages.getInitialPage(this.oneToMorePagesInLoop || this.moreToOnePageInLoop, contentChanged || !this.initialised);
- if (this.initialised) {
- this.goTo(initPage.pageX, initPage.pageY, 0);
- }
- else {
- this.registerHooks(this.scroll.hooks, this.scroll.hooks.eventTypes.beforeInitialScrollTo, function (position) {
- _this.initialised = true;
- position.x = initPage.x;
- position.y = initPage.y;
- });
- }
- this.startPlay();
- };
- Slide.prototype.computeThreshold = function () {
- var threshold = this.options.threshold;
- // Integer
- if (threshold % 1 === 0) {
- this.thresholdX = threshold;
- this.thresholdY = threshold;
- }
- else {
- // decimal
- var _a = this.pages.getPageStats(), width = _a.width, height = _a.height;
- this.thresholdX = Math.round(width * threshold);
- this.thresholdY = Math.round(height * threshold);
- }
- };
- Slide.prototype.cloneFirstAndLastSlidePage = function (slideContent) {
- var children = slideContent.children;
- var preprendDOM = children[children.length - 1].cloneNode(true);
- var appendDOM = children[0].cloneNode(true);
- prepend(preprendDOM, slideContent);
- slideContent.appendChild(appendDOM);
- this.cachedClonedPageDOM = [preprendDOM, appendDOM];
- };
- Slide.prototype.removeClonedSlidePage = function (slideContent) {
- // maybe slideContent has removed from DOM Tree
- var slidePages = (slideContent && slideContent.children) || [];
- if (slidePages.length) {
- this.cachedClonedPageDOM.forEach(function (el) {
- removeChild(slideContent, el);
- });
- }
- this.cachedClonedPageDOM = [];
- };
- Slide.prototype.modifyCurrentPage = function (point) {
- var _a = this.getCurrentPage(), prevExposedPageX = _a.pageX, prevExposedPageY = _a.pageY;
- var newPage = this.nearestPage(point.x, point.y);
- this.setCurrentPage(newPage);
- /* istanbul ignore if */
- if (this.contentChanged) {
- this.contentChanged = false;
- return true;
- }
- var _b = this.getCurrentPage(), currentExposedPageX = _b.pageX, currentExposedPageY = _b.pageY;
- this.pageWillChangeTo(newPage);
- // loop is true, and one page becomes many pages when call bs.refresh
- if (this.oneToMorePagesInLoop) {
- this.oneToMorePagesInLoop = false;
- return true;
- }
- // loop is true, and many page becomes one page when call bs.refresh
- // if prevPage > 0, dispatch slidePageChanged and scrollEnd events
- /* istanbul ignore if */
- if (this.moreToOnePageInLoop &&
- prevExposedPageX === 0 &&
- prevExposedPageY === 0) {
- this.moreToOnePageInLoop = false;
- return true;
- }
- if (prevExposedPageX !== currentExposedPageX ||
- prevExposedPageY !== currentExposedPageY) {
- // only trust pageX & pageY when loop is true
- var page = this.pages.getExposedPageByPageIndex(currentExposedPageX, currentExposedPageY);
- this.scroll.trigger(this.scroll.eventTypes.slidePageChanged, page);
- }
- // triggered by resetLoop
- if (this.resetLooping) {
- this.resetLooping = false;
- return;
- }
- var changePage = this.pages.resetLoopPage();
- if (changePage) {
- this.resetLooping = true;
- this.goTo(changePage.pageX, changePage.pageY, 0);
- // stop user's scrollEnd
- // since it is a seamless scroll
- return true;
- }
- };
- Slide.prototype.goTo = function (pageX, pageY, time, easing) {
- var newPage = this.pages.getInternalPage(pageX, pageY);
- var scrollEasing = easing || this.options.easing || ease.bounce;
- var x = newPage.x, y = newPage.y;
- var deltaX = x - this.scroll.scroller.scrollBehaviorX.currentPos;
- var deltaY = y - this.scroll.scroller.scrollBehaviorY.currentPos;
- /* istanbul ignore if */
- if (!deltaX && !deltaY) {
- this.scroll.scroller.togglePointerEvents(true);
- return;
- }
- time = time === undefined ? this.getEaseTime(deltaX, deltaY) : time;
- this.scroll.scroller.scrollTo(x, y, time, scrollEasing);
- };
- Slide.prototype.flickHandler = function () {
- var _a = this.scroll.scroller, scrollBehaviorX = _a.scrollBehaviorX, scrollBehaviorY = _a.scrollBehaviorY;
- var currentPosX = scrollBehaviorX.currentPos, startPosX = scrollBehaviorX.startPos, directionX = scrollBehaviorX.direction;
- var currentPosY = scrollBehaviorY.currentPos, startPosY = scrollBehaviorY.startPos, directionY = scrollBehaviorY.direction;
- var _b = this.pages.currentPage, pageX = _b.pageX, pageY = _b.pageY;
- var time = this.getEaseTime(currentPosX - startPosX, currentPosY - startPosY);
- this.goTo(pageX + directionX, pageY + directionY, time);
- };
- Slide.prototype.getEaseTime = function (deltaX, deltaY) {
- return (this.options.speed ||
- Math.max(Math.max(Math.min(Math.abs(deltaX), 1000), Math.min(Math.abs(deltaY), 1000)), 300));
- };
- Slide.prototype.modifyScrollMetaHandler = function (scrollMeta) {
- var _a = this.scroll.scroller, scrollBehaviorX = _a.scrollBehaviorX, scrollBehaviorY = _a.scrollBehaviorY, animater = _a.animater;
- var newX = scrollMeta.newX;
- var newY = scrollMeta.newY;
- var newPage = this.satisfyThreshold(newX, newY) || animater.forceStopped
- ? this.pages.getPageByDirection(this.nearestPage(newX, newY), scrollBehaviorX.direction, scrollBehaviorY.direction)
- : this.pages.currentPage;
- scrollMeta.time = this.getEaseTime(scrollMeta.newX - newPage.x, scrollMeta.newY - newPage.y);
- scrollMeta.newX = newPage.x;
- scrollMeta.newY = newPage.y;
- scrollMeta.easing = this.options.easing || ease.bounce;
- };
- Slide.prototype.scrollHandler = function (_a) {
- var x = _a.x, y = _a.y;
- if (this.satisfyThreshold(x, y)) {
- var newPage = this.nearestPage(x, y);
- this.pageWillChangeTo(newPage);
- }
- };
- Slide.prototype.pageWillChangeTo = function (newPage) {
- var changeToPage = this.pages.getWillChangedPage(newPage);
- if (!samePage(this.willChangeToPage, changeToPage)) {
- this.willChangeToPage = changeToPage;
- this.scroll.trigger(this.scroll.eventTypes.slideWillChange, this.willChangeToPage);
- }
- };
- Slide.prototype.registerHooks = function (hooks, name, handler) {
- hooks.on(name, handler, this);
- this.hooksFn.push([hooks, name, handler]);
- };
- Slide.prototype.destroy = function () {
- var slideContent = this.scroll.scroller.content;
- var _a = this.options, loop = _a.loop, autoplay = _a.autoplay;
- if (loop) {
- this.removeClonedSlidePage(slideContent);
- }
- if (autoplay) {
- clearTimeout(this.autoplayTimer);
- }
- this.hooksFn.forEach(function (item) {
- var hooks = item[0];
- var hooksName = item[1];
- var handlerFn = item[2];
- if (hooks.eventTypes[hooksName]) {
- hooks.off(hooksName, handlerFn);
- }
- });
- this.hooksFn.length = 0;
- };
- Slide.pluginName = 'slide';
- return Slide;
- }());
- var sourcePrefix$3 = 'plugins.wheel';
- var propertiesMap$3 = [
- {
- key: 'wheelTo',
- name: 'wheelTo',
- },
- {
- key: 'getSelectedIndex',
- name: 'getSelectedIndex',
- },
- {
- key: 'restorePosition',
- name: 'restorePosition',
- },
- ];
- var propertiesConfig$3 = propertiesMap$3.map(function (item) {
- return {
- key: item.key,
- sourceKey: sourcePrefix$3 + "." + item.name,
- };
- });
- var WHEEL_INDEX_CHANGED_EVENT_NAME = 'wheelIndexChanged';
- var CONSTANTS = {
- rate: 4
- };
- var Wheel = /** @class */ (function () {
- function Wheel(scroll) {
- this.scroll = scroll;
- this.init();
- }
- Wheel.prototype.init = function () {
- this.handleBScroll();
- this.handleOptions();
- this.handleHooks();
- // init boundary for Wheel
- this.refreshBoundary();
- this.setSelectedIndex(this.options.selectedIndex);
- };
- Wheel.prototype.handleBScroll = function () {
- this.scroll.proxy(propertiesConfig$3);
- this.scroll.registerType([WHEEL_INDEX_CHANGED_EVENT_NAME]);
- };
- Wheel.prototype.handleOptions = function () {
- var userOptions = (this.scroll.options.wheel === true
- ? {}
- : this.scroll.options.wheel);
- var defaultOptions = {
- wheelWrapperClass: 'wheel-scroll',
- wheelItemClass: 'wheel-item',
- rotate: 25,
- adjustTime: 400,
- selectedIndex: 0,
- wheelDisabledItemClass: 'wheel-disabled-item'
- };
- this.options = extend(defaultOptions, userOptions);
- };
- Wheel.prototype.handleHooks = function () {
- var _this = this;
- var scroll = this.scroll;
- var scroller = this.scroll.scroller;
- var actionsHandler = scroller.actionsHandler, scrollBehaviorX = scroller.scrollBehaviorX, scrollBehaviorY = scroller.scrollBehaviorY, animater = scroller.animater;
- var prevContent = scroller.content;
- // BScroll
- scroll.on(scroll.eventTypes.scrollEnd, function (position) {
- var index = _this.findNearestValidWheel(position.y).index;
- if (scroller.animater.forceStopped && !_this.isAdjustingPosition) {
- _this.target = _this.items[index];
- // since stopped from an animation.
- // prevent user's scrollEnd callback triggered twice
- return true;
- }
- else {
- _this.setSelectedIndex(index);
- if (_this.isAdjustingPosition) {
- _this.isAdjustingPosition = false;
- }
- }
- });
- // BScroll.hooks
- this.scroll.hooks.on(this.scroll.hooks.eventTypes.refresh, function (content) {
- if (content !== prevContent) {
- prevContent = content;
- _this.setSelectedIndex(_this.options.selectedIndex, true);
- }
- // rotate all wheel-items
- // because position may not change
- _this.rotateX(_this.scroll.y);
- // check we are stop at a disable item or not
- _this.wheelTo(_this.selectedIndex, 0);
- });
- this.scroll.hooks.on(this.scroll.hooks.eventTypes.beforeInitialScrollTo, function (position) {
- // selectedIndex has higher priority than bs.options.startY
- position.x = 0;
- position.y = -(_this.selectedIndex * _this.itemHeight);
- });
- // Scroller
- scroller.hooks.on(scroller.hooks.eventTypes.checkClick, function () {
- var index = HTMLCollectionToArray(_this.items).indexOf(_this.target);
- if (index === -1)
- return true;
- _this.wheelTo(index, _this.options.adjustTime, ease.swipe);
- return true;
- });
- scroller.hooks.on(scroller.hooks.eventTypes.scrollTo, function (endPoint) {
- endPoint.y = _this.findNearestValidWheel(endPoint.y).y;
- });
- // when content is scrolling
- // click wheel-item DOM repeatedly and crazily will cause scrollEnd not triggered
- // so reset forceStopped
- scroller.hooks.on(scroller.hooks.eventTypes.minDistanceScroll, function () {
- var animater = scroller.animater;
- if (animater.forceStopped === true) {
- animater.forceStopped = false;
- }
- });
- scroller.hooks.on(scroller.hooks.eventTypes.scrollToElement, function (el, pos) {
- if (!hasClass(el, _this.options.wheelItemClass)) {
- return true;
- }
- else {
- pos.top = _this.findNearestValidWheel(pos.top).y;
- }
- });
- // ActionsHandler
- actionsHandler.hooks.on(actionsHandler.hooks.eventTypes.beforeStart, function (e) {
- _this.target = e.target;
- });
- // ScrollBehaviorX
- // Wheel has no x direction now
- scrollBehaviorX.hooks.on(scrollBehaviorX.hooks.eventTypes.computeBoundary, function (boundary) {
- boundary.maxScrollPos = 0;
- boundary.minScrollPos = 0;
- });
- // ScrollBehaviorY
- scrollBehaviorY.hooks.on(scrollBehaviorY.hooks.eventTypes.computeBoundary, function (boundary) {
- _this.items = _this.scroll.scroller.content.children;
- _this.checkWheelAllDisabled();
- _this.itemHeight =
- _this.items.length > 0
- ? scrollBehaviorY.contentSize / _this.items.length
- : 0;
- boundary.maxScrollPos = -_this.itemHeight * (_this.items.length - 1);
- boundary.minScrollPos = 0;
- });
- scrollBehaviorY.hooks.on(scrollBehaviorY.hooks.eventTypes.momentum, function (momentumInfo) {
- momentumInfo.rate = CONSTANTS.rate;
- momentumInfo.destination = _this.findNearestValidWheel(momentumInfo.destination).y;
- });
- scrollBehaviorY.hooks.on(scrollBehaviorY.hooks.eventTypes.end, function (momentumInfo) {
- var validWheel = _this.findNearestValidWheel(scrollBehaviorY.currentPos);
- momentumInfo.destination = validWheel.y;
- momentumInfo.duration = _this.options.adjustTime;
- });
- // Animater
- animater.hooks.on(animater.hooks.eventTypes.time, function (time) {
- _this.transitionDuration(time);
- });
- animater.hooks.on(animater.hooks.eventTypes.timeFunction, function (easing) {
- _this.timeFunction(easing);
- });
- // bs.stop() to make wheel stop at a correct position when pending
- animater.hooks.on(animater.hooks.eventTypes.callStop, function () {
- var index = _this.findNearestValidWheel(_this.scroll.y).index;
- _this.isAdjustingPosition = true;
- _this.wheelTo(index, 0);
- });
- // Translater
- animater.translater.hooks.on(animater.translater.hooks.eventTypes.translate, function (endPoint) {
- _this.rotateX(endPoint.y);
- });
- };
- Wheel.prototype.refreshBoundary = function () {
- var _a = this.scroll.scroller, scrollBehaviorX = _a.scrollBehaviorX, scrollBehaviorY = _a.scrollBehaviorY, content = _a.content;
- scrollBehaviorX.refresh(content);
- scrollBehaviorY.refresh(content);
- };
- Wheel.prototype.setSelectedIndex = function (index, contentChanged) {
- if (contentChanged === void 0) { contentChanged = false; }
- var prevSelectedIndex = this.selectedIndex;
- this.selectedIndex = index;
- // if content DOM changed, should not trigger event
- if (prevSelectedIndex !== index && !contentChanged) {
- this.scroll.trigger(WHEEL_INDEX_CHANGED_EVENT_NAME, index);
- }
- };
- Wheel.prototype.getSelectedIndex = function () {
- return this.selectedIndex;
- };
- Wheel.prototype.wheelTo = function (index, time, ease) {
- if (index === void 0) { index = 0; }
- if (time === void 0) { time = 0; }
- var y = -index * this.itemHeight;
- this.scroll.scrollTo(0, y, time, ease);
- };
- Wheel.prototype.restorePosition = function () {
- // bs is scrolling
- var isPending = this.scroll.pending;
- if (isPending) {
- var selectedIndex = this.getSelectedIndex();
- this.scroll.scroller.animater.clearTimer();
- this.wheelTo(selectedIndex, 0);
- }
- };
- Wheel.prototype.transitionDuration = function (time) {
- for (var i = 0; i < this.items.length; i++) {
- this.items[i].style[style.transitionDuration] =
- time + 'ms';
- }
- };
- Wheel.prototype.timeFunction = function (easing) {
- for (var i = 0; i < this.items.length; i++) {
- this.items[i].style[style.transitionTimingFunction] = easing;
- }
- };
- Wheel.prototype.rotateX = function (y) {
- var _a = this.options.rotate, rotate = _a === void 0 ? 25 : _a;
- for (var i = 0; i < this.items.length; i++) {
- var deg = rotate * (y / this.itemHeight + i);
- // Too small value is invalid in some phones, issue 1026
- var SafeDeg = deg.toFixed(3);
- this.items[i].style[style.transform] = "rotateX(" + SafeDeg + "deg)";
- }
- };
- Wheel.prototype.findNearestValidWheel = function (y) {
- y = y > 0 ? 0 : y < this.scroll.maxScrollY ? this.scroll.maxScrollY : y;
- var currentIndex = Math.abs(Math.round(-y / this.itemHeight));
- var cacheIndex = currentIndex;
- var items = this.items;
- var wheelDisabledItemClassName = this.options
- .wheelDisabledItemClass;
- // implement web native select element
- // first, check whether there is a enable item whose index is smaller than currentIndex
- // then, check whether there is a enable item whose index is bigger than currentIndex
- // otherwise, there are all disabled items, just keep currentIndex unchange
- while (currentIndex >= 0) {
- if (!hasClass(items[currentIndex], wheelDisabledItemClassName)) {
- break;
- }
- currentIndex--;
- }
- if (currentIndex < 0) {
- currentIndex = cacheIndex;
- while (currentIndex <= items.length - 1) {
- if (!hasClass(items[currentIndex], wheelDisabledItemClassName)) {
- break;
- }
- currentIndex++;
- }
- }
- // keep it unchange when all the items are disabled
- if (currentIndex === items.length) {
- currentIndex = cacheIndex;
- }
- // when all the items are disabled, selectedIndex should always be -1
- return {
- index: this.wheelItemsAllDisabled ? -1 : currentIndex,
- y: -currentIndex * this.itemHeight
- };
- };
- Wheel.prototype.checkWheelAllDisabled = function () {
- var wheelDisabledItemClassName = this.options.wheelDisabledItemClass;
- var items = this.items;
- this.wheelItemsAllDisabled = true;
- for (var i = 0; i < items.length; i++) {
- if (!hasClass(items[i], wheelDisabledItemClassName)) {
- this.wheelItemsAllDisabled = false;
- break;
- }
- }
- };
- Wheel.pluginName = 'wheel';
- return Wheel;
- }());
- var sourcePrefix$2 = 'plugins.zoom';
- var propertiesMap$2 = [
- {
- key: 'zoomTo',
- name: 'zoomTo'
- }
- ];
- var propertiesConfig$2 = propertiesMap$2.map(function (item) {
- return {
- key: item.key,
- sourceKey: sourcePrefix$2 + "." + item.name
- };
- });
- var TWO_FINGERS = 2;
- var RAW_SCALE = 1;
- var Zoom = /** @class */ (function () {
- function Zoom(scroll) {
- this.scroll = scroll;
- this.scale = RAW_SCALE;
- this.prevScale = 1;
- this.init();
- }
- Zoom.prototype.init = function () {
- this.handleBScroll();
- this.handleOptions();
- this.handleHooks();
- this.tryInitialZoomTo(this.zoomOpt);
- };
- Zoom.prototype.zoomTo = function (scale, x, y, bounceTime) {
- var _a = this.resolveOrigin(x, y), originX = _a.originX, originY = _a.originY;
- var origin = {
- x: originX,
- y: originY,
- baseScale: this.scale,
- };
- this._doZoomTo(scale, origin, bounceTime, true);
- };
- Zoom.prototype.handleBScroll = function () {
- this.scroll.proxy(propertiesConfig$2);
- this.scroll.registerType([
- 'beforeZoomStart',
- 'zoomStart',
- 'zooming',
- 'zoomEnd',
- ]);
- };
- Zoom.prototype.handleOptions = function () {
- var userOptions = (this.scroll.options.zoom === true
- ? {}
- : this.scroll.options.zoom);
- var defaultOptions = {
- start: 1,
- min: 1,
- max: 4,
- initialOrigin: [0, 0],
- minimalZoomDistance: 5,
- bounceTime: 800,
- };
- this.zoomOpt = extend(defaultOptions, userOptions);
- };
- Zoom.prototype.handleHooks = function () {
- var _this = this;
- var scroll = this.scroll;
- var scroller = this.scroll.scroller;
- this.wrapper = this.scroll.scroller.wrapper;
- this.setTransformOrigin(this.scroll.scroller.content);
- var scrollBehaviorX = scroller.scrollBehaviorX;
- var scrollBehaviorY = scroller.scrollBehaviorY;
- this.hooksFn = [];
- // BScroll
- this.registerHooks(scroll.hooks, scroll.hooks.eventTypes.contentChanged, function (content) {
- _this.setTransformOrigin(content);
- _this.scale = RAW_SCALE;
- _this.tryInitialZoomTo(_this.zoomOpt);
- });
- this.registerHooks(scroll.hooks, scroll.hooks.eventTypes.beforeInitialScrollTo, function () {
- // if perform a zoom action, we should prevent initial scroll when initialised
- if (_this.zoomOpt.start !== RAW_SCALE) {
- return true;
- }
- });
- // enlarge boundary
- this.registerHooks(scrollBehaviorX.hooks, scrollBehaviorX.hooks.eventTypes.beforeComputeBoundary, function () {
- // content may change, don't cache it's size
- var contentSize = getRect(_this.scroll.scroller.content);
- scrollBehaviorX.contentSize = Math.floor(contentSize.width * _this.scale);
- });
- this.registerHooks(scrollBehaviorY.hooks, scrollBehaviorY.hooks.eventTypes.beforeComputeBoundary, function () {
- // content may change, don't cache it's size
- var contentSize = getRect(_this.scroll.scroller.content);
- scrollBehaviorY.contentSize = Math.floor(contentSize.height * _this.scale);
- });
- // touch event
- this.registerHooks(scroller.actions.hooks, scroller.actions.hooks.eventTypes.start, function (e) {
- var numberOfFingers = (e.touches && e.touches.length) || 0;
- _this.fingersOperation(numberOfFingers);
- if (numberOfFingers === TWO_FINGERS) {
- _this.zoomStart(e);
- }
- });
- this.registerHooks(scroller.actions.hooks, scroller.actions.hooks.eventTypes.beforeMove, function (e) {
- var numberOfFingers = (e.touches && e.touches.length) || 0;
- _this.fingersOperation(numberOfFingers);
- if (numberOfFingers === TWO_FINGERS) {
- _this.zoom(e);
- return true;
- }
- });
- this.registerHooks(scroller.actions.hooks, scroller.actions.hooks.eventTypes.beforeEnd, function (e) {
- var numberOfFingers = _this.fingersOperation();
- if (numberOfFingers === TWO_FINGERS) {
- _this.zoomEnd();
- return true;
- }
- });
- this.registerHooks(scroller.translater.hooks, scroller.translater.hooks.eventTypes.beforeTranslate, function (transformStyle, point) {
- var scale = point.scale ? point.scale : _this.prevScale;
- _this.prevScale = scale;
- transformStyle.push("scale(" + scale + ")");
- });
- this.registerHooks(scroller.hooks, scroller.hooks.eventTypes.scrollEnd, function () {
- if (_this.fingersOperation() === TWO_FINGERS) {
- _this.scroll.trigger(_this.scroll.eventTypes.zoomEnd, {
- scale: _this.scale,
- });
- }
- });
- this.registerHooks(this.scroll.hooks, 'destroy', this.destroy);
- };
- Zoom.prototype.setTransformOrigin = function (content) {
- content.style[style.transformOrigin] = '0 0';
- };
- Zoom.prototype.tryInitialZoomTo = function (options) {
- var start = options.start, initialOrigin = options.initialOrigin;
- var _a = this.scroll.scroller, scrollBehaviorX = _a.scrollBehaviorX, scrollBehaviorY = _a.scrollBehaviorY;
- if (start !== RAW_SCALE) {
- // Movable plugin may wanna modify minScrollPos or maxScrollPos
- // so we force Movable to caculate them
- this.resetBoundaries([scrollBehaviorX, scrollBehaviorY]);
- this.zoomTo(start, initialOrigin[0], initialOrigin[1], 0);
- }
- };
- // getter or setter operation
- Zoom.prototype.fingersOperation = function (amounts) {
- if (typeof amounts === 'number') {
- this.numberOfFingers = amounts;
- }
- else {
- return this.numberOfFingers;
- }
- };
- Zoom.prototype._doZoomTo = function (scale, origin, time, useCurrentPos) {
- var _this = this;
- if (time === void 0) { time = this.zoomOpt.bounceTime; }
- if (useCurrentPos === void 0) { useCurrentPos = false; }
- var _a = this.zoomOpt, min = _a.min, max = _a.max;
- var fromScale = this.scale;
- var toScale = between(scale, min, max);
- (function () {
- if (time === 0) {
- _this.scroll.trigger(_this.scroll.eventTypes.zooming, {
- scale: toScale,
- });
- return;
- }
- if (time > 0) {
- var timer_1;
- var startTime_1 = getNow();
- var endTime_1 = startTime_1 + time;
- var scheduler_1 = function () {
- var now = getNow();
- if (now >= endTime_1) {
- _this.scroll.trigger(_this.scroll.eventTypes.zooming, {
- scale: toScale,
- });
- cancelAnimationFrame(timer_1);
- return;
- }
- var ratio = ease.bounce.fn((now - startTime_1) / time);
- var currentScale = ratio * (toScale - fromScale) + fromScale;
- _this.scroll.trigger(_this.scroll.eventTypes.zooming, {
- scale: currentScale,
- });
- timer_1 = requestAnimationFrame(scheduler_1);
- };
- // start scheduler job
- scheduler_1();
- }
- })();
- // suppose you are zooming by two fingers
- this.fingersOperation(2);
- this._zoomTo(toScale, fromScale, origin, time, useCurrentPos);
- };
- Zoom.prototype._zoomTo = function (toScale, fromScale, origin, time, useCurrentPos) {
- if (useCurrentPos === void 0) { useCurrentPos = false; }
- var ratio = toScale / origin.baseScale;
- this.setScale(toScale);
- var scroller = this.scroll.scroller;
- var scrollBehaviorX = scroller.scrollBehaviorX, scrollBehaviorY = scroller.scrollBehaviorY;
- this.resetBoundaries([scrollBehaviorX, scrollBehaviorY]);
- // position is restrained in boundary
- var newX = this.getNewPos(origin.x, ratio, scrollBehaviorX, true, useCurrentPos);
- var newY = this.getNewPos(origin.y, ratio, scrollBehaviorY, true, useCurrentPos);
- if (scrollBehaviorX.currentPos !== Math.round(newX) ||
- scrollBehaviorY.currentPos !== Math.round(newY) ||
- toScale !== fromScale) {
- scroller.scrollTo(newX, newY, time, ease.bounce, {
- start: {
- scale: fromScale,
- },
- end: {
- scale: toScale,
- },
- });
- }
- };
- Zoom.prototype.resolveOrigin = function (x, y) {
- var _a = this.scroll.scroller, scrollBehaviorX = _a.scrollBehaviorX, scrollBehaviorY = _a.scrollBehaviorY;
- var resolveFormula = {
- left: function () {
- return 0;
- },
- top: function () {
- return 0;
- },
- right: function () {
- return scrollBehaviorX.contentSize;
- },
- bottom: function () {
- return scrollBehaviorY.contentSize;
- },
- center: function (index) {
- var baseSize = index === 0
- ? scrollBehaviorX.contentSize
- : scrollBehaviorY.contentSize;
- return baseSize / 2;
- },
- };
- return {
- originX: typeof x === 'number' ? x : resolveFormula[x](0),
- originY: typeof y === 'number' ? y : resolveFormula[y](1),
- };
- };
- Zoom.prototype.zoomStart = function (e) {
- var firstFinger = e.touches[0];
- var secondFinger = e.touches[1];
- this.startDistance = this.getFingerDistance(e);
- this.startScale = this.scale;
- var _a = offsetToBody(this.wrapper), left = _a.left, top = _a.top;
- this.origin = {
- x: Math.abs(firstFinger.pageX + secondFinger.pageX) / 2 +
- left -
- this.scroll.x,
- y: Math.abs(firstFinger.pageY + secondFinger.pageY) / 2 +
- top -
- this.scroll.y,
- baseScale: this.startScale,
- };
- this.scroll.trigger(this.scroll.eventTypes.beforeZoomStart);
- };
- Zoom.prototype.zoom = function (e) {
- var currentDistance = this.getFingerDistance(e);
- // at least minimalZoomDistance pixels for the zoom to initiate
- if (!this.zoomed &&
- Math.abs(currentDistance - this.startDistance) <
- this.zoomOpt.minimalZoomDistance) {
- return;
- }
- // when out of boundary , perform a damping algorithm
- var endScale = this.dampingScale((currentDistance / this.startDistance) * this.startScale);
- var ratio = endScale / this.startScale;
- this.setScale(endScale);
- if (!this.zoomed) {
- this.zoomed = true;
- this.scroll.trigger(this.scroll.eventTypes.zoomStart);
- }
- var scroller = this.scroll.scroller;
- var scrollBehaviorX = scroller.scrollBehaviorX, scrollBehaviorY = scroller.scrollBehaviorY;
- var x = this.getNewPos(this.origin.x, ratio, scrollBehaviorX, false, false);
- var y = this.getNewPos(this.origin.y, ratio, scrollBehaviorY, false, false);
- this.scroll.trigger(this.scroll.eventTypes.zooming, {
- scale: this.scale,
- });
- scroller.translater.translate({ x: x, y: y, scale: endScale });
- };
- Zoom.prototype.zoomEnd = function () {
- if (!this.zoomed)
- return;
- // if out of boundary, do rebound!
- if (this.shouldRebound()) {
- this._doZoomTo(this.scale, this.origin, this.zoomOpt.bounceTime);
- return;
- }
- this.scroll.trigger(this.scroll.eventTypes.zoomEnd, { scale: this.scale });
- };
- Zoom.prototype.getFingerDistance = function (e) {
- var firstFinger = e.touches[0];
- var secondFinger = e.touches[1];
- var deltaX = Math.abs(firstFinger.pageX - secondFinger.pageX);
- var deltaY = Math.abs(firstFinger.pageY - secondFinger.pageY);
- return getDistance(deltaX, deltaY);
- };
- Zoom.prototype.shouldRebound = function () {
- var _a = this.zoomOpt, min = _a.min, max = _a.max;
- var currentScale = this.scale;
- // scale exceeded!
- if (currentScale !== between(currentScale, min, max)) {
- return true;
- }
- var _b = this.scroll.scroller, scrollBehaviorX = _b.scrollBehaviorX, scrollBehaviorY = _b.scrollBehaviorY;
- // enlarge boundaries manually when zoom is end
- this.resetBoundaries([scrollBehaviorX, scrollBehaviorY]);
- var xInBoundary = scrollBehaviorX.checkInBoundary().inBoundary;
- var yInBoundary = scrollBehaviorX.checkInBoundary().inBoundary;
- return !(xInBoundary && yInBoundary);
- };
- Zoom.prototype.dampingScale = function (scale) {
- var _a = this.zoomOpt, min = _a.min, max = _a.max;
- if (scale < min) {
- scale = 0.5 * min * Math.pow(2.0, scale / min);
- }
- else if (scale > max) {
- scale = 2.0 * max * Math.pow(0.5, max / scale);
- }
- return scale;
- };
- Zoom.prototype.setScale = function (scale) {
- this.scale = scale;
- };
- Zoom.prototype.resetBoundaries = function (scrollBehaviorPairs) {
- scrollBehaviorPairs.forEach(function (behavior) { return behavior.computeBoundary(); });
- };
- Zoom.prototype.getNewPos = function (origin, lastScale, scrollBehavior, shouldInBoundary, useCurrentPos) {
- if (useCurrentPos === void 0) { useCurrentPos = false; }
- var newPos = origin -
- origin * lastScale +
- (useCurrentPos ? scrollBehavior.currentPos : scrollBehavior.startPos);
- if (shouldInBoundary) {
- newPos = between(newPos, scrollBehavior.maxScrollPos, scrollBehavior.minScrollPos);
- }
- // maxScrollPos or minScrollPos maybe a negative or positive digital
- return newPos > 0 ? Math.floor(newPos) : Math.ceil(newPos);
- };
- Zoom.prototype.registerHooks = function (hooks, name, handler) {
- hooks.on(name, handler, this);
- this.hooksFn.push([hooks, name, handler]);
- };
- Zoom.prototype.destroy = function () {
- this.hooksFn.forEach(function (item) {
- var hooks = item[0];
- var hooksName = item[1];
- var handlerFn = item[2];
- hooks.off(hooksName, handlerFn);
- });
- this.hooksFn.length = 0;
- };
- Zoom.pluginName = 'zoom';
- return Zoom;
- }());
- var BScrollFamily = /** @class */ (function () {
- function BScrollFamily(scroll) {
- this.ancestors = [];
- this.descendants = [];
- this.hooksManager = [];
- this.analyzed = false;
- this.selfScroll = scroll;
- }
- BScrollFamily.create = function (scroll) {
- return new BScrollFamily(scroll);
- };
- BScrollFamily.prototype.hasAncestors = function (bscrollFamily) {
- var index = findIndex(this.ancestors, function (_a) {
- var item = _a[0];
- return item === bscrollFamily;
- });
- return index > -1;
- };
- BScrollFamily.prototype.hasDescendants = function (bscrollFamily) {
- var index = findIndex(this.descendants, function (_a) {
- var item = _a[0];
- return item === bscrollFamily;
- });
- return index > -1;
- };
- BScrollFamily.prototype.addAncestor = function (bscrollFamily, distance) {
- var ancestors = this.ancestors;
- ancestors.push([bscrollFamily, distance]);
- // by ascend
- ancestors.sort(function (a, b) {
- return a[1] - b[1];
- });
- };
- BScrollFamily.prototype.addDescendant = function (bscrollFamily, distance) {
- var descendants = this.descendants;
- descendants.push([bscrollFamily, distance]);
- // by ascend
- descendants.sort(function (a, b) {
- return a[1] - b[1];
- });
- };
- BScrollFamily.prototype.removeAncestor = function (bscrollFamily) {
- var ancestors = this.ancestors;
- if (ancestors.length) {
- var index = findIndex(this.ancestors, function (_a) {
- var item = _a[0];
- return item === bscrollFamily;
- });
- if (index > -1) {
- return ancestors.splice(index, 1);
- }
- }
- };
- BScrollFamily.prototype.removeDescendant = function (bscrollFamily) {
- var descendants = this.descendants;
- if (descendants.length) {
- var index = findIndex(this.descendants, function (_a) {
- var item = _a[0];
- return item === bscrollFamily;
- });
- if (index > -1) {
- return descendants.splice(index, 1);
- }
- }
- };
- BScrollFamily.prototype.registerHooks = function (hook, eventType, handler) {
- hook.on(eventType, handler);
- this.hooksManager.push([hook, eventType, handler]);
- };
- BScrollFamily.prototype.setAnalyzed = function (flag) {
- if (flag === void 0) { flag = false; }
- this.analyzed = flag;
- };
- BScrollFamily.prototype.purge = function () {
- var _this = this;
- // remove self from graph
- this.ancestors.forEach(function (_a) {
- var bscrollFamily = _a[0];
- bscrollFamily.removeDescendant(_this);
- });
- this.descendants.forEach(function (_a) {
- var bscrollFamily = _a[0];
- bscrollFamily.removeAncestor(_this);
- });
- // remove all hook handlers
- this.hooksManager.forEach(function (_a) {
- var hooks = _a[0], eventType = _a[1], handler = _a[2];
- hooks.off(eventType, handler);
- });
- this.hooksManager = [];
- };
- return BScrollFamily;
- }());
- var sourcePrefix$1 = 'plugins.nestedScroll';
- var propertiesMap$1 = [
- {
- key: 'purgeNestedScroll',
- name: 'purgeNestedScroll',
- },
- ];
- var propertiesConfig$1 = propertiesMap$1.map(function (item) {
- return {
- key: item.key,
- sourceKey: sourcePrefix$1 + "." + item.name,
- };
- });
- var DEFAUL_GROUP_ID = 'INTERNAL_NESTED_SCROLL';
- var forceScrollStopHandler = function (scrolls) {
- scrolls.forEach(function (scroll) {
- if (scroll.pending) {
- scroll.stop();
- scroll.resetPosition();
- }
- });
- };
- var enableScrollHander = function (scrolls) {
- scrolls.forEach(function (scroll) {
- scroll.enable();
- });
- };
- var disableScrollHander = function (scrolls, currentScroll) {
- scrolls.forEach(function (scroll) {
- if (scroll.hasHorizontalScroll === currentScroll.hasHorizontalScroll ||
- scroll.hasVerticalScroll === currentScroll.hasVerticalScroll) {
- scroll.disable();
- }
- });
- };
- var syncTouchstartData = function (scrolls) {
- scrolls.forEach(function (scroll) {
- var _a = scroll.scroller, actions = _a.actions, scrollBehaviorX = _a.scrollBehaviorX, scrollBehaviorY = _a.scrollBehaviorY;
- // prevent click triggering many times
- actions.fingerMoved = true;
- actions.contentMoved = false;
- actions.directionLockAction.reset();
- scrollBehaviorX.start();
- scrollBehaviorY.start();
- scrollBehaviorX.resetStartPos();
- scrollBehaviorY.resetStartPos();
- actions.startTime = +new Date();
- });
- };
- var isOutOfBoundary = function (scroll) {
- 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;
- var ret = false;
- var outOfLeftBoundary = x >= minScrollX && movingDirectionX === -1 /* Negative */;
- var outOfRightBoundary = x <= maxScrollX && movingDirectionX === 1 /* Positive */;
- var outOfTopBoundary = y >= minScrollY && movingDirectionY === -1 /* Negative */;
- var outOfBottomBoundary = y <= maxScrollY && movingDirectionY === 1 /* Positive */;
- if (hasVerticalScroll) {
- ret = outOfTopBoundary || outOfBottomBoundary;
- }
- else if (hasHorizontalScroll) {
- ret = outOfLeftBoundary || outOfRightBoundary;
- }
- return ret;
- };
- var isResettingPosition = function (scroll) {
- 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;
- var ret = false;
- var outOfLeftBoundary = x > minScrollX;
- var outOfRightBoundary = x < maxScrollX;
- var outOfTopBoundary = y > minScrollY;
- var outOfBottomBoundary = y < maxScrollY;
- if (hasVerticalScroll) {
- ret = outOfTopBoundary || outOfBottomBoundary;
- }
- else if (hasHorizontalScroll) {
- ret = outOfLeftBoundary || outOfRightBoundary;
- }
- return ret;
- };
- var resetPositionHandler = function (scroll) {
- scroll.scroller.reflow();
- scroll.resetPosition(0 /* Immediately */);
- };
- var calculateDistance = function (childNode, parentNode) {
- var distance = 0;
- var parent = childNode.parentNode;
- while (parent && parent !== parentNode) {
- distance++;
- parent = parent.parentNode;
- }
- return distance;
- };
- var NestedScroll = /** @class */ (function () {
- function NestedScroll(scroll) {
- var groupId = this.handleOptions(scroll);
- var instance = NestedScroll.instancesMap[groupId];
- if (!instance) {
- instance = NestedScroll.instancesMap[groupId] = this;
- instance.store = [];
- instance.hooksFn = [];
- }
- instance.init(scroll);
- return instance;
- }
- NestedScroll.getAllNestedScrolls = function () {
- var instancesMap = NestedScroll.instancesMap;
- return Object.keys(instancesMap).map(function (key) { return instancesMap[key]; });
- };
- NestedScroll.purgeAllNestedScrolls = function () {
- var nestedScrolls = NestedScroll.getAllNestedScrolls();
- nestedScrolls.forEach(function (ns) { return ns.purgeNestedScroll(); });
- };
- NestedScroll.prototype.handleOptions = function (scroll) {
- var userOptions = (scroll.options.nestedScroll === true
- ? {}
- : scroll.options.nestedScroll);
- var defaultOptions = {
- groupId: DEFAUL_GROUP_ID,
- };
- this.options = extend(defaultOptions, userOptions);
- var groupIdType = typeof this.options.groupId;
- if (groupIdType !== 'string' && groupIdType !== 'number') {
- warn('groupId must be string or number for NestedScroll plugin');
- }
- return this.options.groupId;
- };
- NestedScroll.prototype.init = function (scroll) {
- scroll.proxy(propertiesConfig$1);
- this.addBScroll(scroll);
- this.buildBScrollGraph();
- this.analyzeBScrollGraph();
- this.ensureEventInvokeSequence();
- this.handleHooks(scroll);
- };
- NestedScroll.prototype.handleHooks = function (scroll) {
- var _this = this;
- this.registerHooks(scroll.hooks, scroll.hooks.eventTypes.destroy, function () {
- _this.deleteScroll(scroll);
- });
- };
- NestedScroll.prototype.deleteScroll = function (scroll) {
- var wrapper = scroll.wrapper;
- wrapper.isBScrollContainer = undefined;
- var store = this.store;
- var hooksFn = this.hooksFn;
- var i = findIndex(store, function (bscrollFamily) {
- return bscrollFamily.selfScroll === scroll;
- });
- if (i > -1) {
- var bscrollFamily = store[i];
- bscrollFamily.purge();
- store.splice(i, 1);
- }
- var k = findIndex(hooksFn, function (_a) {
- var hooks = _a[0];
- return hooks === scroll.hooks;
- });
- if (k > -1) {
- var _a = hooksFn[k], hooks = _a[0], eventType = _a[1], handler = _a[2];
- hooks.off(eventType, handler);
- hooksFn.splice(k, 1);
- }
- };
- NestedScroll.prototype.addBScroll = function (scroll) {
- this.store.push(BScrollFamily.create(scroll));
- };
- NestedScroll.prototype.buildBScrollGraph = function () {
- var store = this.store;
- var bf1;
- var bf2;
- var wrapper1;
- var wrapper2;
- var len = this.store.length;
- // build graph
- for (var i = 0; i < len; i++) {
- bf1 = store[i];
- wrapper1 = bf1.selfScroll.wrapper;
- for (var j = 0; j < len; j++) {
- bf2 = store[j];
- wrapper2 = bf2.selfScroll.wrapper;
- // same bs
- if (bf1 === bf2)
- continue;
- if (!wrapper1.contains(wrapper2))
- continue;
- // bs1 contains bs2
- var distance = calculateDistance(wrapper2, wrapper1);
- if (!bf1.hasDescendants(bf2)) {
- bf1.addDescendant(bf2, distance);
- }
- if (!bf2.hasAncestors(bf1)) {
- bf2.addAncestor(bf1, distance);
- }
- }
- }
- };
- NestedScroll.prototype.analyzeBScrollGraph = function () {
- this.store.forEach(function (bscrollFamily) {
- if (bscrollFamily.analyzed) {
- return;
- }
- var ancestors = bscrollFamily.ancestors, descendants = bscrollFamily.descendants, currentScroll = bscrollFamily.selfScroll;
- var beforeScrollStartHandler = function () {
- // always get the latest scroll
- var ancestorScrolls = ancestors.map(function (_a) {
- var bscrollFamily = _a[0];
- return bscrollFamily.selfScroll;
- });
- var descendantScrolls = descendants.map(function (_a) {
- var bscrollFamily = _a[0];
- return bscrollFamily.selfScroll;
- });
- forceScrollStopHandler(__spreadArrays(ancestorScrolls, descendantScrolls));
- if (isResettingPosition(currentScroll)) {
- resetPositionHandler(currentScroll);
- }
- syncTouchstartData(ancestorScrolls);
- disableScrollHander(ancestorScrolls, currentScroll);
- };
- var touchEndHandler = function () {
- var ancestorScrolls = ancestors.map(function (_a) {
- var bscrollFamily = _a[0];
- return bscrollFamily.selfScroll;
- });
- var descendantScrolls = descendants.map(function (_a) {
- var bscrollFamily = _a[0];
- return bscrollFamily.selfScroll;
- });
- enableScrollHander(__spreadArrays(ancestorScrolls, descendantScrolls));
- };
- bscrollFamily.registerHooks(currentScroll, currentScroll.eventTypes.beforeScrollStart, beforeScrollStartHandler);
- bscrollFamily.registerHooks(currentScroll, currentScroll.eventTypes.touchEnd, touchEndHandler);
- var selfActionsHooks = currentScroll.scroller.actions.hooks;
- bscrollFamily.registerHooks(selfActionsHooks, selfActionsHooks.eventTypes.detectMovingDirection, function () {
- var ancestorScrolls = ancestors.map(function (_a) {
- var bscrollFamily = _a[0];
- return bscrollFamily.selfScroll;
- });
- var parentScroll = ancestorScrolls[0];
- var otherAncestorScrolls = ancestorScrolls.slice(1);
- var contentMoved = currentScroll.scroller.actions.contentMoved;
- var isTopScroll = ancestorScrolls.length === 0;
- if (contentMoved) {
- disableScrollHander(ancestorScrolls, currentScroll);
- }
- else if (!isTopScroll) {
- if (isOutOfBoundary(currentScroll)) {
- disableScrollHander([currentScroll], currentScroll);
- if (parentScroll) {
- enableScrollHander([parentScroll]);
- }
- disableScrollHander(otherAncestorScrolls, currentScroll);
- return true;
- }
- }
- });
- bscrollFamily.setAnalyzed(true);
- });
- };
- // make sure touchmove|touchend invoke from child to parent
- NestedScroll.prototype.ensureEventInvokeSequence = function () {
- var copied = this.store.slice();
- var sequencedScroll = copied.sort(function (a, b) {
- return a.descendants.length - b.descendants.length;
- });
- sequencedScroll.forEach(function (bscrollFamily) {
- var scroll = bscrollFamily.selfScroll;
- scroll.scroller.actionsHandler.rebindDOMEvents();
- });
- };
- NestedScroll.prototype.registerHooks = function (hooks, name, handler) {
- hooks.on(name, handler, this);
- this.hooksFn.push([hooks, name, handler]);
- };
- NestedScroll.prototype.purgeNestedScroll = function () {
- var groupId = this.options.groupId;
- this.store.forEach(function (bscrollFamily) {
- bscrollFamily.purge();
- });
- this.store = [];
- this.hooksFn.forEach(function (_a) {
- var hooks = _a[0], eventType = _a[1], handler = _a[2];
- hooks.off(eventType, handler);
- });
- this.hooksFn = [];
- delete NestedScroll.instancesMap[groupId];
- };
- NestedScroll.pluginName = 'nestedScroll';
- NestedScroll.instancesMap = {};
- return NestedScroll;
- }());
- var PRE_NUM = 10;
- var POST_NUM = 30;
- var IndexCalculator = /** @class */ (function () {
- function IndexCalculator(wrapperHeight, tombstoneHeight) {
- this.wrapperHeight = wrapperHeight;
- this.tombstoneHeight = tombstoneHeight;
- this.lastDirection = 1 /* DOWN */;
- this.lastPos = 0;
- }
- IndexCalculator.prototype.calculate = function (pos, list) {
- var offset = pos - this.lastPos;
- this.lastPos = pos;
- var direction = this.getDirection(offset);
- // important! start index is much more important than end index.
- var start = this.calculateIndex(0, pos, list);
- var end = this.calculateIndex(start, pos + this.wrapperHeight, list);
- if (direction === 1 /* DOWN */) {
- start -= PRE_NUM;
- end += POST_NUM;
- }
- else {
- start -= POST_NUM;
- end += PRE_NUM;
- }
- if (start < 0) {
- start = 0;
- }
- return {
- start: start,
- end: end,
- };
- };
- IndexCalculator.prototype.getDirection = function (offset) {
- var direction;
- if (offset > 0) {
- direction = 1 /* DOWN */;
- }
- else if (offset < 0) {
- direction = 0 /* UP */;
- }
- else {
- return this.lastDirection;
- }
- this.lastDirection = direction;
- return direction;
- };
- IndexCalculator.prototype.calculateIndex = function (start, offset, list) {
- if (offset <= 0) {
- return start;
- }
- var i = start;
- var startPos = list[i] && list[i].pos !== -1 ? list[i].pos : 0;
- var lastPos = startPos;
- var tombstone = 0;
- while (i < list.length && list[i].pos < offset) {
- lastPos = list[i].pos;
- i++;
- }
- if (i === list.length) {
- tombstone = Math.floor((offset - lastPos) / this.tombstoneHeight);
- }
- i += tombstone;
- return i;
- };
- IndexCalculator.prototype.resetState = function () {
- this.lastDirection = 1 /* DOWN */;
- this.lastPos = 0;
- };
- return IndexCalculator;
- }());
- var ListItem = /** @class */ (function () {
- function ListItem() {
- this.data = null;
- this.dom = null;
- this.tombstone = null;
- this.width = 0;
- this.height = 0;
- this.pos = 0;
- }
- return ListItem;
- }());
- var DataManager = /** @class */ (function () {
- function DataManager(list, fetchFn, onFetchFinish) {
- this.fetchFn = fetchFn;
- this.onFetchFinish = onFetchFinish;
- this.loadedNum = 0;
- this.fetching = false;
- this.hasMore = true;
- this.list = list || [];
- }
- DataManager.prototype.update = function (end) {
- return __awaiter(this, void 0, void 0, function () {
- var len;
- return __generator(this, function (_a) {
- if (!this.hasMore) {
- end = Math.min(end, this.list.length);
- }
- // add data placeholder
- if (end > this.list.length) {
- len = end - this.list.length;
- this.addEmptyData(len);
- }
- // tslint:disable-next-line: no-floating-promises
- return [2 /*return*/, this.checkToFetch(end)];
- });
- });
- };
- DataManager.prototype.add = function (data) {
- for (var i = 0; i < data.length; i++) {
- if (!this.list[this.loadedNum]) {
- this.list[this.loadedNum] = { data: data[i] };
- }
- else {
- this.list[this.loadedNum] = __assign(__assign({}, this.list[this.loadedNum]), { data: data[i] });
- }
- this.loadedNum++;
- }
- return this.list;
- };
- DataManager.prototype.addEmptyData = function (len) {
- for (var i = 0; i < len; i++) {
- this.list.push(new ListItem());
- }
- return this.list;
- };
- DataManager.prototype.fetch = function (len) {
- return __awaiter(this, void 0, void 0, function () {
- var data;
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0:
- if (this.fetching) {
- return [2 /*return*/, []];
- }
- this.fetching = true;
- return [4 /*yield*/, this.fetchFn(len)];
- case 1:
- data = _a.sent();
- this.fetching = false;
- return [2 /*return*/, data];
- }
- });
- });
- };
- DataManager.prototype.checkToFetch = function (end) {
- return __awaiter(this, void 0, void 0, function () {
- var min, newData, currentEnd;
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0:
- if (!this.hasMore) {
- return [2 /*return*/];
- }
- if (end <= this.loadedNum) {
- return [2 /*return*/];
- }
- min = end - this.loadedNum;
- return [4 /*yield*/, this.fetch(min)];
- case 1:
- newData = _a.sent();
- if (newData instanceof Array && newData.length) {
- this.add(newData);
- currentEnd = this.onFetchFinish(this.list, true);
- return [2 /*return*/, this.checkToFetch(currentEnd)];
- }
- else if (typeof newData === 'boolean' && newData === false) {
- this.hasMore = false;
- this.list.splice(this.loadedNum);
- this.onFetchFinish(this.list, false);
- }
- return [2 /*return*/];
- }
- });
- });
- };
- DataManager.prototype.getList = function () {
- return this.list;
- };
- DataManager.prototype.resetState = function () {
- this.loadedNum = 0;
- this.fetching = false;
- this.hasMore = true;
- this.list = [];
- };
- return DataManager;
- }());
- var Tombstone = /** @class */ (function () {
- function Tombstone(create) {
- this.create = create;
- this.cached = [];
- this.width = 0;
- this.height = 0;
- this.initialed = false;
- this.getSize();
- }
- Tombstone.isTombstone = function (el) {
- if (el && el.classList) {
- return el.classList.contains('tombstone');
- }
- return false;
- };
- Tombstone.prototype.getSize = function () {
- if (!this.initialed) {
- var tombstone = this.create();
- tombstone.style.position = 'absolute';
- document.body.appendChild(tombstone);
- tombstone.style.display = '';
- this.height = tombstone.offsetHeight;
- this.width = tombstone.offsetWidth;
- document.body.removeChild(tombstone);
- this.cached.push(tombstone);
- }
- };
- Tombstone.prototype.getOne = function () {
- var tombstone = this.cached.pop();
- if (tombstone) {
- var tombstoneStyle = tombstone.style;
- tombstoneStyle.display = '';
- tombstoneStyle.opacity = '1';
- tombstoneStyle[style.transform] = '';
- tombstoneStyle[style.transition] = '';
- return tombstone;
- }
- return this.create();
- };
- Tombstone.prototype.recycle = function (tombstones) {
- for (var _i = 0, tombstones_1 = tombstones; _i < tombstones_1.length; _i++) {
- var tombstone = tombstones_1[_i];
- tombstone.style.display = 'none';
- this.cached.push(tombstone);
- }
- return this.cached;
- };
- Tombstone.prototype.recycleOne = function (tombstone) {
- this.cached.push(tombstone);
- return this.cached;
- };
- return Tombstone;
- }());
- var ANIMATION_DURATION_MS = 200;
- var DomManager = /** @class */ (function () {
- function DomManager(content, renderFn, tombstone) {
- this.renderFn = renderFn;
- this.tombstone = tombstone;
- this.unusedDom = [];
- this.timers = [];
- this.setContent(content);
- }
- DomManager.prototype.update = function (list, start, end) {
- if (start >= list.length) {
- start = list.length - 1;
- }
- if (end > list.length) {
- end = list.length;
- }
- this.collectUnusedDom(list, start, end);
- this.createDom(list, start, end);
- this.cacheHeight(list, start, end);
- var _a = this.positionDom(list, start, end), startPos = _a.startPos, startDelta = _a.startDelta, endPos = _a.endPos;
- return {
- start: start,
- startPos: startPos,
- startDelta: startDelta,
- end: end,
- endPos: endPos,
- };
- };
- DomManager.prototype.collectUnusedDom = function (list, start, end) {
- // TODO optimise
- for (var i = 0; i < list.length; i++) {
- if (i === start) {
- i = end - 1;
- continue;
- }
- if (list[i].dom) {
- var dom = list[i].dom;
- if (Tombstone.isTombstone(dom)) {
- this.tombstone.recycleOne(dom);
- dom.style.display = 'none';
- }
- else {
- this.unusedDom.push(dom);
- }
- list[i].dom = null;
- }
- }
- return list;
- };
- DomManager.prototype.createDom = function (list, start, end) {
- for (var i = start; i < end; i++) {
- var dom = list[i].dom;
- var data = list[i].data;
- if (dom) {
- if (Tombstone.isTombstone(dom) && data) {
- list[i].tombstone = dom;
- list[i].dom = null;
- }
- else {
- continue;
- }
- }
- dom = data
- ? this.renderFn(data, this.unusedDom.pop())
- : this.tombstone.getOne();
- dom.style.position = 'absolute';
- list[i].dom = dom;
- list[i].pos = -1;
- this.content.appendChild(dom);
- }
- };
- DomManager.prototype.cacheHeight = function (list, start, end) {
- for (var i = start; i < end; i++) {
- if (list[i].data && !list[i].height) {
- list[i].height = list[i].dom.offsetHeight;
- }
- }
- };
- DomManager.prototype.positionDom = function (list, start, end) {
- var _this = this;
- var tombstoneEles = [];
- var _a = this.getStartPos(list, start, end), startPos = _a.start, startDelta = _a.delta;
- var pos = startPos;
- for (var i = start; i < end; i++) {
- var tombstone = list[i].tombstone;
- if (tombstone) {
- var tombstoneStyle = tombstone.style;
- tombstoneStyle[style.transition] = cssVendor + "transform " + ANIMATION_DURATION_MS + "ms, opacity " + ANIMATION_DURATION_MS + "ms";
- tombstoneStyle[style.transform] = "translateY(" + pos + "px)";
- tombstoneStyle.opacity = '0';
- list[i].tombstone = null;
- tombstoneEles.push(tombstone);
- }
- if (list[i].dom && list[i].pos !== pos) {
- list[i].dom.style[style.transform] = "translateY(" + pos + "px)";
- list[i].pos = pos;
- }
- pos += list[i].height || this.tombstone.height;
- }
- var timerId = window.setTimeout(function () {
- _this.tombstone.recycle(tombstoneEles);
- }, ANIMATION_DURATION_MS);
- this.timers.push(timerId);
- return {
- startPos: startPos,
- startDelta: startDelta,
- endPos: pos,
- };
- };
- DomManager.prototype.getStartPos = function (list, start, end) {
- if (list[start] && list[start].pos !== -1) {
- return {
- start: list[start].pos,
- delta: 0,
- };
- }
- // TODO optimise
- var pos = list[0].pos === -1 ? 0 : list[0].pos;
- for (var i_1 = 0; i_1 < start; i_1++) {
- pos += list[i_1].height || this.tombstone.height;
- }
- var originPos = pos;
- var i;
- for (i = start; i < end; i++) {
- if (!Tombstone.isTombstone(list[i].dom) && list[i].pos !== -1) {
- pos = list[i].pos;
- break;
- }
- }
- var x = i;
- if (x < end) {
- while (x > start) {
- pos -= list[x - 1].height;
- x--;
- }
- }
- var delta = originPos - pos;
- return {
- start: pos,
- delta: delta,
- };
- };
- DomManager.prototype.removeTombstone = function () {
- var tombstones = this.content.querySelectorAll('.tombstone');
- for (var i = tombstones.length - 1; i >= 0; i--) {
- this.content.removeChild(tombstones[i]);
- }
- };
- DomManager.prototype.setContent = function (content) {
- if (content !== this.content) {
- this.content = content;
- }
- };
- DomManager.prototype.destroy = function () {
- this.removeTombstone();
- this.timers.forEach(function (id) {
- clearTimeout(id);
- });
- };
- DomManager.prototype.resetState = function () {
- this.destroy();
- this.timers = [];
- this.unusedDom = [];
- };
- return DomManager;
- }());
- var EXTRA_SCROLL_Y = -2000;
- var InfinityScroll = /** @class */ (function () {
- function InfinityScroll(scroll) {
- this.scroll = scroll;
- this.start = 0;
- this.end = 0;
- this.init();
- }
- InfinityScroll.prototype.init = function () {
- var _this = this;
- this.handleOptions();
- var _a = this.options, fetchFn = _a.fetch, renderFn = _a.render, createTombstoneFn = _a.createTombstone;
- this.tombstone = new Tombstone(createTombstoneFn);
- this.indexCalculator = new IndexCalculator(this.scroll.scroller.scrollBehaviorY.wrapperSize, this.tombstone.height);
- this.domManager = new DomManager(this.scroll.scroller.content, renderFn, this.tombstone);
- this.dataManager = new DataManager([], fetchFn, this.onFetchFinish.bind(this));
- this.scroll.on(this.scroll.eventTypes.destroy, this.destroy, this);
- this.scroll.on(this.scroll.eventTypes.scroll, this.update, this);
- this.scroll.on(this.scroll.eventTypes.contentChanged, function (content) {
- _this.domManager.setContent(content);
- _this.indexCalculator.resetState();
- _this.domManager.resetState();
- _this.dataManager.resetState();
- _this.update({ y: 0 });
- });
- var scrollBehaviorY = this.scroll.scroller.scrollBehaviorY;
- scrollBehaviorY.hooks.on(scrollBehaviorY.hooks.eventTypes.computeBoundary, this.modifyBoundary, this);
- this.update({ y: 0 });
- };
- InfinityScroll.prototype.modifyBoundary = function (boundary) {
- // manually set position to allow scroll
- boundary.maxScrollPos = EXTRA_SCROLL_Y;
- };
- InfinityScroll.prototype.handleOptions = function () {
- // narrow down type to an object
- var infinityOptions = this.scroll.options.infinity;
- if (infinityOptions) {
- if (typeof infinityOptions.fetch !== 'function') {
- warn('Infinity plugin need fetch Function to new data.');
- }
- if (typeof infinityOptions.render !== 'function') {
- warn('Infinity plugin need render Function to render each item.');
- }
- if (typeof infinityOptions.render !== 'function') {
- warn('Infinity plugin need createTombstone Function to create tombstone.');
- }
- this.options = infinityOptions;
- }
- this.scroll.options.probeType = 3 /* Realtime */;
- };
- InfinityScroll.prototype.update = function (pos) {
- var position = Math.round(-pos.y);
- // important! calculate start/end index to render
- var _a = this.indexCalculator.calculate(position, this.dataManager.getList()), start = _a.start, end = _a.end;
- this.start = start;
- this.end = end;
- // tslint:disable-next-line: no-floating-promises
- this.dataManager.update(end);
- this.updateDom(this.dataManager.getList());
- };
- InfinityScroll.prototype.onFetchFinish = function (list, hasMore) {
- var end = this.updateDom(list).end;
- if (!hasMore) {
- this.domManager.removeTombstone();
- this.scroll.scroller.animater.stop();
- this.scroll.resetPosition();
- }
- // tslint:disable-next-line: no-floating-promises
- return end;
- };
- InfinityScroll.prototype.updateDom = function (list) {
- var _a = this.domManager.update(list, this.start, this.end), end = _a.end, startPos = _a.startPos, endPos = _a.endPos, startDelta = _a.startDelta;
- if (startDelta) {
- this.scroll.minScrollY = startDelta;
- }
- if (endPos > this.scroll.maxScrollY) {
- this.scroll.maxScrollY = -(endPos - this.scroll.scroller.scrollBehaviorY.wrapperSize);
- }
- return {
- end: end,
- startPos: startPos,
- endPos: endPos,
- };
- };
- InfinityScroll.prototype.destroy = function () {
- var _a = this.scroll.scroller, content = _a.content, scrollBehaviorY = _a.scrollBehaviorY;
- while (content.firstChild) {
- content.removeChild(content.firstChild);
- }
- this.domManager.destroy();
- this.scroll.off('scroll', this.update);
- this.scroll.off('destroy', this.destroy);
- scrollBehaviorY.hooks.off(scrollBehaviorY.hooks.eventTypes.computeBoundary);
- };
- InfinityScroll.pluginName = 'infinity';
- return InfinityScroll;
- }());
- var sourcePrefix = 'plugins.movable';
- var propertiesMap = [
- {
- key: 'putAt',
- name: 'putAt',
- },
- ];
- var propertiesConfig = propertiesMap.map(function (item) {
- return {
- key: item.key,
- sourceKey: sourcePrefix + "." + item.name,
- };
- });
- var Movable = /** @class */ (function () {
- function Movable(scroll) {
- this.scroll = scroll;
- this.handleBScroll();
- this.handleHooks();
- }
- Movable.prototype.handleBScroll = function () {
- this.scroll.proxy(propertiesConfig);
- };
- Movable.prototype.handleHooks = function () {
- var _this = this;
- this.hooksFn = [];
- var _a = this.scroll.scroller, scrollBehaviorX = _a.scrollBehaviorX, scrollBehaviorY = _a.scrollBehaviorY;
- var computeBoundary = function (boundary, behavior) {
- if (boundary.maxScrollPos > 0) {
- // content is smaller than wrapper
- boundary.minScrollPos = behavior.wrapperSize - behavior.contentSize;
- boundary.maxScrollPos = 0;
- }
- };
- this.registerHooks(scrollBehaviorX.hooks, scrollBehaviorX.hooks.eventTypes.ignoreHasScroll, function () { return true; });
- this.registerHooks(scrollBehaviorX.hooks, scrollBehaviorX.hooks.eventTypes.computeBoundary, function (boundary) {
- computeBoundary(boundary, scrollBehaviorX);
- });
- this.registerHooks(scrollBehaviorY.hooks, scrollBehaviorY.hooks.eventTypes.ignoreHasScroll, function () { return true; });
- this.registerHooks(scrollBehaviorY.hooks, scrollBehaviorY.hooks.eventTypes.computeBoundary, function (boundary) {
- computeBoundary(boundary, scrollBehaviorY);
- });
- this.registerHooks(this.scroll.hooks, this.scroll.hooks.eventTypes.destroy, function () {
- _this.destroy();
- });
- };
- Movable.prototype.putAt = function (x, y, time, easing) {
- if (time === void 0) { time = this.scroll.options.bounceTime; }
- if (easing === void 0) { easing = ease.bounce; }
- var position = this.resolvePostion(x, y);
- this.scroll.scrollTo(position.x, position.y, time, easing);
- };
- Movable.prototype.resolvePostion = function (x, y) {
- var _a = this.scroll.scroller, scrollBehaviorX = _a.scrollBehaviorX, scrollBehaviorY = _a.scrollBehaviorY;
- var resolveFormula = {
- left: function () {
- return 0;
- },
- top: function () {
- return 0;
- },
- right: function () {
- return scrollBehaviorX.minScrollPos;
- },
- bottom: function () {
- return scrollBehaviorY.minScrollPos;
- },
- center: function (index) {
- var baseSize = index === 0
- ? scrollBehaviorX.minScrollPos
- : scrollBehaviorY.minScrollPos;
- return baseSize / 2;
- },
- };
- return {
- x: typeof x === 'number' ? x : resolveFormula[x](0),
- y: typeof y === 'number' ? y : resolveFormula[y](1),
- };
- };
- Movable.prototype.destroy = function () {
- this.hooksFn.forEach(function (item) {
- var hooks = item[0];
- var hooksName = item[1];
- var handlerFn = item[2];
- hooks.off(hooksName, handlerFn);
- });
- this.hooksFn.length = 0;
- };
- Movable.prototype.registerHooks = function (hooks, name, handler) {
- hooks.on(name, handler, this);
- this.hooksFn.push([hooks, name, handler]);
- };
- Movable.pluginName = 'movable';
- Movable.applyOrder = "pre" /* Pre */;
- return Movable;
- }());
- var isImageTag = function (el) {
- return el.tagName.toLowerCase() === 'img';
- };
- var ObserveImage = /** @class */ (function () {
- function ObserveImage(scroll) {
- this.scroll = scroll;
- this.refreshTimer = 0;
- this.init();
- }
- ObserveImage.prototype.init = function () {
- this.handleOptions(this.scroll.options.observeImage);
- this.bindEventsToWrapper();
- };
- ObserveImage.prototype.handleOptions = function (userOptions) {
- if (userOptions === void 0) { userOptions = {}; }
- userOptions = (userOptions === true ? {} : userOptions);
- var defaultOptions = {
- debounceTime: 100,
- };
- this.options = extend(defaultOptions, userOptions);
- };
- ObserveImage.prototype.bindEventsToWrapper = function () {
- var wrapper = this.scroll.scroller.wrapper;
- this.imageLoadEventRegister = new EventRegister(wrapper, [
- {
- name: 'load',
- handler: this.load.bind(this),
- capture: true,
- },
- ]);
- this.imageErrorEventRegister = new EventRegister(wrapper, [
- {
- name: 'error',
- handler: this.load.bind(this),
- capture: true,
- },
- ]);
- };
- ObserveImage.prototype.load = function (e) {
- var _this = this;
- var target = e.target;
- var debounceTime = this.options.debounceTime;
- if (target && isImageTag(target)) {
- if (debounceTime === 0) {
- this.scroll.refresh();
- }
- else {
- clearTimeout(this.refreshTimer);
- this.refreshTimer = window.setTimeout(function () {
- _this.scroll.refresh();
- }, this.options.debounceTime);
- }
- }
- };
- ObserveImage.pluginName = 'observeImage';
- return ObserveImage;
- }());
- var resolveRatioOption = function (ratioConfig) {
- var ret = {
- ratioX: 0,
- ratioY: 0,
- };
- /* istanbul ignore if */
- if (!ratioConfig) {
- return ret;
- }
- if (typeof ratioConfig === 'number') {
- ret.ratioX = ret.ratioY = ratioConfig;
- }
- else if (typeof ratioConfig === 'object' && ratioConfig) {
- ret.ratioX = ratioConfig.x || 0;
- ret.ratioY = ratioConfig.y || 0;
- }
- return ret;
- };
- var handleBubbleAndCancelable = function (e) {
- e.preventDefault();
- e.stopPropagation();
- };
- var Indicator = /** @class */ (function () {
- function Indicator(scroll, options) {
- this.scroll = scroll;
- this.options = options;
- this.currentPos = {
- x: 0,
- y: 0,
- };
- this.hooksFn = [];
- this.handleDOM();
- this.handleHooks();
- this.handleInteractive();
- }
- Indicator.prototype.handleDOM = function () {
- var _a = this.options, relationElement = _a.relationElement, _b = _a.relationElementHandleElementIndex, relationElementHandleElementIndex = _b === void 0 ? 0 : _b;
- this.wrapper = relationElement;
- this.indicatorEl = this.wrapper.children[relationElementHandleElementIndex];
- };
- Indicator.prototype.handleHooks = function () {
- var _this = this;
- var scroll = this.scroll;
- var scrollHooks = scroll.hooks;
- var translaterHooks = scroll.scroller.translater.hooks;
- var animaterHooks = scroll.scroller.animater.hooks;
- this.registerHooks(scrollHooks, scrollHooks.eventTypes.refresh, this.refresh);
- this.registerHooks(translaterHooks, translaterHooks.eventTypes.translate, function (pos) {
- _this.updatePosition(pos);
- });
- this.registerHooks(animaterHooks, animaterHooks.eventTypes.time, this.transitionTime);
- this.registerHooks(animaterHooks, animaterHooks.eventTypes.timeFunction, this.transitionTimingFunction);
- };
- Indicator.prototype.transitionTime = function (time) {
- if (time === void 0) { time = 0; }
- this.indicatorEl.style[style.transitionDuration] = time + 'ms';
- };
- Indicator.prototype.transitionTimingFunction = function (easing) {
- this.indicatorEl.style[style.transitionTimingFunction] = easing;
- };
- Indicator.prototype.handleInteractive = function () {
- if (this.options.interactive !== false) {
- this.registerEvents();
- }
- };
- Indicator.prototype.registerHooks = function (hooks, name, handler) {
- hooks.on(name, handler, this);
- this.hooksFn.push([hooks, name, handler]);
- };
- Indicator.prototype.registerEvents = function () {
- var _a = this.scroll.options, disableMouse = _a.disableMouse, disableTouch = _a.disableTouch;
- var startEvents = [];
- var moveEvents = [];
- var endEvents = [];
- if (!disableMouse) {
- startEvents.push({
- name: 'mousedown',
- handler: this.start.bind(this),
- });
- moveEvents.push({
- name: 'mousemove',
- handler: this.move.bind(this),
- });
- endEvents.push({
- name: 'mouseup',
- handler: this.end.bind(this),
- });
- }
- if (!disableTouch) {
- startEvents.push({
- name: 'touchstart',
- handler: this.start.bind(this),
- });
- moveEvents.push({
- name: 'touchmove',
- handler: this.move.bind(this),
- });
- endEvents.push({
- name: 'touchend',
- handler: this.end.bind(this),
- }, {
- name: 'touchcancel',
- handler: this.end.bind(this),
- });
- }
- this.startEventRegister = new EventRegister(this.indicatorEl, startEvents);
- this.moveEventRegister = new EventRegister(window, moveEvents);
- this.endEventRegister = new EventRegister(window, endEvents);
- };
- Indicator.prototype.refresh = function () {
- var _a = this.scroll, x = _a.x, y = _a.y, hasHorizontalScroll = _a.hasHorizontalScroll, hasVerticalScroll = _a.hasVerticalScroll, maxBScrollX = _a.maxScrollX, maxBScrollY = _a.maxScrollY;
- var _b = resolveRatioOption(this.options.ratio), ratioX = _b.ratioX, ratioY = _b.ratioY;
- var _c = getClientSize(this.wrapper), wrapperWidth = _c.width, wrapperHeight = _c.height;
- var _d = getRect(this.indicatorEl), indicatorWidth = _d.width, indicatorHeight = _d.height;
- if (hasHorizontalScroll) {
- this.maxScrollX = wrapperWidth - indicatorWidth;
- this.translateXSign =
- this.maxScrollX > 0 ? -1 /* Positive */ : 1 /* NotPositive */;
- this.minScrollX = 0;
- // ensure positive
- this.ratioX = ratioX ? ratioX : Math.abs(this.maxScrollX / maxBScrollX);
- }
- if (hasVerticalScroll) {
- this.maxScrollY = wrapperHeight - indicatorHeight;
- this.translateYSign =
- this.maxScrollY > 0 ? -1 /* Positive */ : 1 /* NotPositive */;
- this.minScrollY = 0;
- this.ratioY = ratioY ? ratioY : Math.abs(this.maxScrollY / maxBScrollY);
- }
- this.updatePosition({
- x: x,
- y: y,
- });
- };
- Indicator.prototype.start = function (e) {
- if (this.BScrollIsDisabled()) {
- return;
- }
- var point = (e.touches ? e.touches[0] : e);
- handleBubbleAndCancelable(e);
- this.initiated = true;
- this.moved = false;
- this.lastPointX = point.pageX;
- this.lastPointY = point.pageY;
- this.startTime = getNow();
- this.scroll.scroller.hooks.trigger(this.scroll.scroller.hooks.eventTypes.beforeScrollStart);
- };
- Indicator.prototype.BScrollIsDisabled = function () {
- return !this.scroll.enabled;
- };
- Indicator.prototype.move = function (e) {
- if (!this.initiated) {
- return;
- }
- var point = (e.touches ? e.touches[0] : e);
- var pointX = point.pageX;
- var pointY = point.pageY;
- handleBubbleAndCancelable(e);
- var deltaX = pointX - this.lastPointX;
- var deltaY = pointY - this.lastPointY;
- this.lastPointX = pointX;
- this.lastPointY = pointY;
- if (!this.moved && !this.indicatorNotMoved(deltaX, deltaY)) {
- this.moved = true;
- this.scroll.scroller.hooks.trigger(this.scroll.scroller.hooks.eventTypes.scrollStart);
- }
- if (this.moved) {
- var newPos = this.getBScrollPosByRatio(this.currentPos, deltaX, deltaY);
- this.syncBScroll(newPos);
- }
- };
- Indicator.prototype.end = function (e) {
- if (!this.initiated) {
- return;
- }
- this.initiated = false;
- handleBubbleAndCancelable(e);
- if (this.moved) {
- var _a = this.scroll, x = _a.x, y = _a.y;
- this.scroll.scroller.hooks.trigger(this.scroll.scroller.hooks.eventTypes.scrollEnd, {
- x: x,
- y: y,
- });
- }
- };
- Indicator.prototype.getBScrollPosByRatio = function (currentPos, deltaX, deltaY) {
- var currentX = currentPos.x, currentY = currentPos.y;
- var _a = this.scroll, hasHorizontalScroll = _a.hasHorizontalScroll, hasVerticalScroll = _a.hasVerticalScroll, BScrollMinScrollX = _a.minScrollX, BScrollMaxScrollX = _a.maxScrollX, BScrollMinScrollY = _a.minScrollY, BScrollMaxScrollY = _a.maxScrollY;
- var _b = this.scroll, x = _b.x, y = _b.y;
- if (hasHorizontalScroll) {
- var newPosX = between(currentX + deltaX, Math.min(this.minScrollX, this.maxScrollX), Math.max(this.minScrollX, this.maxScrollX));
- var roundX = Math.round((newPosX / this.ratioX) * this.translateXSign);
- x = between(roundX, BScrollMaxScrollX, BScrollMinScrollX);
- }
- if (hasVerticalScroll) {
- var newPosY = between(currentY + deltaY, Math.min(this.minScrollY, this.maxScrollY), Math.max(this.minScrollY, this.maxScrollY));
- var roundY = Math.round((newPosY / this.ratioY) * this.translateYSign);
- y = between(roundY, BScrollMaxScrollY, BScrollMinScrollY);
- }
- return { x: x, y: y };
- };
- Indicator.prototype.indicatorNotMoved = function (deltaX, deltaY) {
- var _a = this.currentPos, x = _a.x, y = _a.y;
- var xNotMoved = (x === this.minScrollX && deltaX <= 0) ||
- (x === this.maxScrollX && deltaX >= 0);
- var yNotMoved = (y === this.minScrollY && deltaY <= 0) ||
- (y === this.maxScrollY && deltaY >= 0);
- return xNotMoved && yNotMoved;
- };
- Indicator.prototype.syncBScroll = function (newPos) {
- var timestamp = getNow();
- var _a = this.scroll, options = _a.options, scroller = _a.scroller;
- var probeType = options.probeType, momentumLimitTime = options.momentumLimitTime;
- scroller.translater.translate(newPos);
- // dispatch scroll in interval time
- if (timestamp - this.startTime > momentumLimitTime) {
- this.startTime = timestamp;
- if (probeType === 1 /* Throttle */) {
- scroller.hooks.trigger(scroller.hooks.eventTypes.scroll, newPos);
- }
- }
- // dispatch scroll all the time
- if (probeType > 1 /* Throttle */) {
- scroller.hooks.trigger(scroller.hooks.eventTypes.scroll, newPos);
- }
- };
- Indicator.prototype.updatePosition = function (BScrollPos) {
- var newIndicatorPos = this.getIndicatorPosByRatio(BScrollPos);
- this.applyTransformProperty(newIndicatorPos);
- this.currentPos = __assign({}, newIndicatorPos);
- };
- Indicator.prototype.applyTransformProperty = function (pos) {
- var translateZ = this.scroll.options.translateZ;
- var transformProperties = [
- "translateX(" + pos.x + "px)",
- "translateY(" + pos.y + "px)",
- "" + translateZ,
- ];
- this.indicatorEl.style[style.transform] = transformProperties.join(' ');
- };
- Indicator.prototype.getIndicatorPosByRatio = function (BScrollPos) {
- var x = BScrollPos.x, y = BScrollPos.y;
- var _a = this.scroll, hasHorizontalScroll = _a.hasHorizontalScroll, hasVerticalScroll = _a.hasVerticalScroll;
- var position = __assign({}, this.currentPos);
- if (hasHorizontalScroll) {
- var roundX = Math.round(this.ratioX * x * this.translateXSign);
- // maybe maxScrollX is negative
- position.x = between(roundX, Math.min(this.minScrollX, this.maxScrollX), Math.max(this.minScrollX, this.maxScrollX));
- }
- if (hasVerticalScroll) {
- var roundY = Math.round(this.ratioY * y * this.translateYSign);
- // maybe maxScrollY is negative
- position.y = between(roundY, Math.min(this.minScrollY, this.maxScrollY), Math.max(this.minScrollY, this.maxScrollY));
- }
- return position;
- };
- Indicator.prototype.destroy = function () {
- if (this.options.interactive !== false) {
- this.startEventRegister.destroy();
- this.moveEventRegister.destroy();
- this.endEventRegister.destroy();
- }
- this.hooksFn.forEach(function (item) {
- var hooks = item[0];
- var hooksName = item[1];
- var handlerFn = item[2];
- hooks.off(hooksName, handlerFn);
- });
- this.hooksFn.length = 0;
- };
- return Indicator;
- }());
- var Indicators = /** @class */ (function () {
- function Indicators(scroll) {
- this.scroll = scroll;
- this.options = [];
- this.indicators = [];
- this.handleOptions();
- this.handleHooks();
- }
- Indicators.prototype.handleOptions = function () {
- var UserIndicatorsOptions = this.scroll.options.indicators;
- assert(Array.isArray(UserIndicatorsOptions), "'indicators' must be an array.");
- for (var _i = 0, UserIndicatorsOptions_1 = UserIndicatorsOptions; _i < UserIndicatorsOptions_1.length; _i++) {
- var indicatorOptions = UserIndicatorsOptions_1[_i];
- assert(!!indicatorOptions.relationElement, "'relationElement' must be a HTMLElement.");
- this.createIndicators(indicatorOptions);
- }
- };
- Indicators.prototype.createIndicators = function (options) {
- this.indicators.push(new Indicator(this.scroll, options));
- };
- Indicators.prototype.handleHooks = function () {
- var _this = this;
- var scrollHooks = this.scroll.hooks;
- scrollHooks.on(scrollHooks.eventTypes.destroy, function () {
- for (var _i = 0, _a = _this.indicators; _i < _a.length; _i++) {
- var indicator = _a[_i];
- indicator.destroy();
- }
- _this.indicators = [];
- });
- };
- Indicators.pluginName = 'indicators';
- return Indicators;
- }());
- BScroll.use(MouseWheel)
- .use(ObserveDOM)
- .use(PullDown)
- .use(PullUp)
- .use(ScrollBar)
- .use(Slide)
- .use(Wheel)
- .use(Zoom)
- .use(NestedScroll)
- .use(InfinityScroll)
- .use(Movable)
- .use(ObserveImage)
- .use(Indicators);
- export default BScroll;
- export { Behavior, CustomOptions, Indicators, InfinityScroll, MouseWheel, Movable, NestedScroll, ObserveDOM as ObserveDom, ObserveImage, PullDown as PullDownRefresh, PullUp as PullUpLoad, ScrollBar, Slide, Wheel, Zoom, createBScroll };
|