better-scroll.js 275 KB

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