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