splide.cjs.js 123 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475
  1. /*!
  2. * Splide.js
  3. * Version : 3.0.0
  4. * License : MIT
  5. * Copyright: 2021 Naotoshi Fujita
  6. */
  7. 'use strict';
  8. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  9. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  10. Object.defineProperty(exports, '__esModule', {
  11. value: true
  12. });
  13. /**
  14. * The project code.
  15. *
  16. * @since 3.0.0
  17. */
  18. var PROJECT_CODE = 'splide';
  19. /**
  20. * The data attribute prefix.
  21. *
  22. * @since 3.0.0
  23. */
  24. var DATA_ATTRIBUTE = "data-" + PROJECT_CODE;
  25. /**
  26. * Splide has been just created.
  27. */
  28. var CREATED = 1;
  29. /**
  30. * Splide has mounted components.
  31. */
  32. var MOUNTED = 2;
  33. /**
  34. * Splide is ready.
  35. */
  36. var IDLE = 3;
  37. /**
  38. * Splide is moving.
  39. */
  40. var MOVING = 4;
  41. /**
  42. * Splide has been destroyed.
  43. */
  44. var DESTROYED = 5;
  45. /**
  46. * The collection of all states.
  47. *
  48. * @since 3.0.0
  49. */
  50. var STATES = {
  51. CREATED: CREATED,
  52. MOUNTED: MOUNTED,
  53. IDLE: IDLE,
  54. MOVING: MOVING,
  55. DESTROYED: DESTROYED
  56. };
  57. /**
  58. * Empties the array.
  59. *
  60. * @param array - A array to empty.
  61. */
  62. function empty(array) {
  63. array.length = 0;
  64. }
  65. /**
  66. * Checks if the given subject is an object or not.
  67. *
  68. * @param subject - A subject to check.
  69. *
  70. * @return `true` if the subject is an object, or otherwise `false`.
  71. */
  72. function isObject(subject) {
  73. return !isNull(subject) && typeof subject === 'object';
  74. }
  75. /**
  76. * Checks if the given subject is an array or not.
  77. *
  78. * @param subject - A subject to check.
  79. *
  80. * @return `true` if the subject is an array, or otherwise `false`.
  81. */
  82. function isArray(subject) {
  83. return Array.isArray(subject);
  84. }
  85. /**
  86. * Checks if the given subject is a function or not.
  87. *
  88. * @param subject - A subject to check.
  89. *
  90. * @return `true` if the subject is a function, or otherwise `false`.
  91. */
  92. function isFunction(subject) {
  93. return typeof subject === 'function';
  94. }
  95. /**
  96. * Checks if the given subject is a string or not.
  97. *
  98. * @param subject - A subject to check.
  99. *
  100. * @return `true` if the subject is a string, or otherwise `false`.
  101. */
  102. function isString(subject) {
  103. return typeof subject === 'string';
  104. }
  105. /**
  106. * Checks if the given subject is `undefined` or not.
  107. *
  108. * @param subject - A subject to check.
  109. *
  110. * @return `true` if the subject is `undefined`, or otherwise `false`.
  111. */
  112. function isUndefined(subject) {
  113. return typeof subject === 'undefined';
  114. }
  115. /**
  116. * Checks if the given subject is `null` or not.
  117. *
  118. * @param subject - A subject to check.
  119. *
  120. * @return `true` if the subject is `null`, or otherwise `false`.
  121. */
  122. function isNull(subject) {
  123. return subject === null;
  124. }
  125. /**
  126. * Checks if the given subject is an HTMLElement or not.
  127. *
  128. * @param subject - A subject to check.
  129. *
  130. * @return `true` if the subject is an HTMLElement instance, or otherwise `false`.
  131. */
  132. function isHTMLElement(subject) {
  133. return subject instanceof HTMLElement;
  134. }
  135. /**
  136. * Checks if the given subject is an HTMLButtonElement or not.
  137. *
  138. * @param subject - A subject to check.
  139. *
  140. * @return `true` if the subject is an HTMLButtonElement, or otherwise `false`.
  141. */
  142. function isHTMLButtonElement(subject) {
  143. return subject instanceof HTMLButtonElement;
  144. }
  145. /**
  146. * Push the provided value to an array if the value is not an array.
  147. *
  148. * @param value - A value to push.
  149. *
  150. * @return An array containing the value, or the value itself if it is already an array.
  151. */
  152. function toArray(value) {
  153. return isArray(value) ? value : [value];
  154. }
  155. /**
  156. * The extended `Array#forEach` method that accepts a single value as an argument.
  157. *
  158. * @param values - A value or values to iterate over.
  159. * @param iteratee - An iteratee function.
  160. */
  161. function forEach(values, iteratee) {
  162. toArray(values).forEach(iteratee);
  163. }
  164. /**
  165. * Checks if the array includes the value or not.
  166. * `Array#includes` is not supported by IE.
  167. *
  168. * @param array - An array.
  169. * @param value - A value to search for.
  170. *
  171. * @return `true` if the array includes the value, or otherwise `false`.
  172. */
  173. function includes(array, value) {
  174. return array.indexOf(value) > -1;
  175. }
  176. /**
  177. * Extended `Array#push()` that accepts an item or an array with items.
  178. *
  179. * @param array - An array to push items.
  180. * @param items - An item or items to push.
  181. *
  182. * @return A provided array itself.
  183. */
  184. function push(array, items) {
  185. array.push.apply(array, toArray(items));
  186. return array;
  187. }
  188. var arrayProto = Array.prototype;
  189. /**
  190. * The slice method for an array-like object.
  191. *
  192. * @param arrayLike - An array-like object.
  193. * @param start - Optional. A start index.
  194. * @param end - Optional. A end index.
  195. *
  196. * @return An array with sliced elements.
  197. */
  198. function slice(arrayLike, start, end) {
  199. return arrayProto.slice.call(arrayLike, start, end);
  200. }
  201. /**
  202. * The find method for an array or array-like object, works in IE.
  203. * This method is not performant for a huge array.
  204. *
  205. * @param arrayLike - An array-like object.
  206. * @param predicate - The predicate function to test each element in the object.
  207. *
  208. * @return A found value if available, or otherwise `undefined`.
  209. */
  210. function find(arrayLike, predicate) {
  211. return slice(arrayLike).filter(predicate)[0];
  212. }
  213. /**
  214. * Toggles the provided class or classes by following the `add` boolean.
  215. *
  216. * @param elm - An element whose classes are toggled.
  217. * @param classes - A class or class names.
  218. * @param add - Whether to add or remove a class.
  219. */
  220. function toggleClass(elm, classes, add) {
  221. if (elm) {
  222. forEach(classes, function (name) {
  223. if (name) {
  224. elm.classList[add ? 'add' : 'remove'](name);
  225. }
  226. });
  227. }
  228. }
  229. /**
  230. * Adds classes to the element.
  231. *
  232. * @param elm - An element to add classes to.
  233. * @param classes - Classes to add.
  234. */
  235. function addClass(elm, classes) {
  236. toggleClass(elm, classes, true);
  237. }
  238. /**
  239. * Appends children to the parent element.
  240. *
  241. * @param parent - A parent element.
  242. * @param children - A child or children to append to the parent.
  243. */
  244. function append(parent, children) {
  245. forEach(children, parent.appendChild.bind(parent));
  246. }
  247. /**
  248. * Inserts a node or nodes before the specified reference node.
  249. *
  250. * @param nodes - A node or nodes to insert.
  251. * @param ref - A reference node.
  252. */
  253. function before(nodes, ref) {
  254. forEach(nodes, function (node) {
  255. var parent = ref.parentNode;
  256. if (parent) {
  257. parent.insertBefore(node, ref);
  258. }
  259. });
  260. }
  261. /**
  262. * Checks if the element can be selected by the provided selector or not.
  263. *
  264. * @param elm - An element to check.
  265. * @param selector - A selector to test.
  266. *
  267. * @return `true` if the selector matches the element, or otherwise `false`.
  268. */
  269. function matches(elm, selector) {
  270. return (elm['msMatchesSelector'] || elm.matches).call(elm, selector);
  271. }
  272. /**
  273. * Finds children that has the specified tag or class name.
  274. *
  275. * @param parent - A parent element.
  276. * @param selector - A selector to filter children.
  277. *
  278. * @return An array with filtered children.
  279. */
  280. function children(parent, selector) {
  281. return parent ? slice(parent.children).filter(function (child) {
  282. return matches(child, selector);
  283. }) : [];
  284. }
  285. /**
  286. * Returns a child element that matches the specified tag or class name.
  287. *
  288. * @param parent - A parent element.
  289. * @param selector - A selector to filter children.
  290. *
  291. * @return A matched child element if available, or otherwise `undefined`.
  292. */
  293. function child(parent, selector) {
  294. return selector ? children(parent, selector)[0] : parent.firstElementChild;
  295. }
  296. /**
  297. * Iterates over the provided object by own enumerable keys with calling the iteratee function.
  298. *
  299. * @param object - An object to iterate over.
  300. * @param iteratee - An iteratee function that takes the value and key as arguments.
  301. *
  302. * @return A provided object itself.
  303. */
  304. function forOwn(object, iteratee) {
  305. if (object) {
  306. var keys = Object.keys(object);
  307. for (var i = 0; i < keys.length; i++) {
  308. var key = keys[i];
  309. if (key !== '__proto__') {
  310. if (iteratee(object[key], key) === false) {
  311. break;
  312. }
  313. }
  314. }
  315. }
  316. return object;
  317. }
  318. /**
  319. * Assigns all own enumerable properties of all source objects to the provided object.
  320. * `undefined` in source objects will be skipped.
  321. *
  322. * @param object - An object to assign properties to.
  323. * @param sources - Objects to assign properties from.
  324. *
  325. * @return An object assigned properties of the sources to.
  326. */
  327. function assign(object) {
  328. for (var _len = arguments.length, sources = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  329. sources[_key - 1] = arguments[_key];
  330. }
  331. sources.forEach(function (source) {
  332. forOwn(source, function (value, key) {
  333. object[key] = source[key];
  334. });
  335. });
  336. return object;
  337. }
  338. /**
  339. * Recursively merges source properties to the object.
  340. *
  341. * @param object - An object to merge properties to.
  342. * @param source - A source object to merge properties from.
  343. *
  344. * @return A new object with merged properties.
  345. */
  346. function merge(object, source) {
  347. forOwn(source, function (value, key) {
  348. object[key] = isObject(value) ? merge(isObject(object[key]) ? object[key] : {}, value) : value;
  349. });
  350. return object;
  351. }
  352. /**
  353. * Removes attributes from the element.
  354. *
  355. * @param elm - An element.
  356. * @param attrs - An attribute or attributes to remove.
  357. */
  358. function removeAttribute(elm, attrs) {
  359. if (elm) {
  360. forEach(attrs, function (attr) {
  361. elm.removeAttribute(attr);
  362. });
  363. }
  364. }
  365. function setAttribute(elm, attrs, value) {
  366. if (isObject(attrs)) {
  367. forOwn(attrs, function (value, name) {
  368. setAttribute(elm, name, value);
  369. });
  370. } else {
  371. isNull(value) ? removeAttribute(elm, attrs) : elm.setAttribute(attrs, String(value));
  372. }
  373. }
  374. /**
  375. * Creates a HTML element.
  376. *
  377. * @param tag - A tag name.
  378. * @param attrs - Optional. An object with attributes to apply the created element to, or a string with classes.
  379. * @param parent - Optional. A parent element where the created element is appended.
  380. */
  381. function create(tag, attrs, parent) {
  382. var elm = document.createElement(tag);
  383. if (attrs) {
  384. if (isString(attrs) || isArray(attrs)) {
  385. addClass(elm, attrs);
  386. } else {
  387. setAttribute(elm, attrs);
  388. }
  389. }
  390. if (parent) {
  391. append(parent, elm);
  392. }
  393. return elm;
  394. }
  395. /**
  396. * Applies inline styles to the provided element by an object literal.
  397. *
  398. * @param elms - An element or elements to apply styles to.
  399. * @param styles - An object literal with styles.
  400. */
  401. function style(elms, styles) {
  402. if (isString(styles)) {
  403. return isArray(elms) ? null : getComputedStyle(elms)[styles];
  404. }
  405. forOwn(styles, function (value, key) {
  406. if (!isNull(value)) {
  407. forEach(elms, function (elm) {
  408. if (elm) {
  409. elm.style[key] = "" + value;
  410. }
  411. });
  412. }
  413. });
  414. }
  415. /**
  416. * Sets the `display` CSS value to the element.
  417. *
  418. * @param elm - An element to set a new value to.
  419. * @param display - A new `display` value.
  420. */
  421. function display(elm, display) {
  422. style(elm, {
  423. display: display
  424. });
  425. }
  426. /**
  427. * Returns the specified attribute value.
  428. *
  429. * @param elm - An element.
  430. * @param attr - An attribute to get.
  431. */
  432. function getAttribute(elm, attr) {
  433. return elm.getAttribute(attr);
  434. }
  435. /**
  436. * Checks if the element contains the specified class or not.
  437. *
  438. * @param elm - An element to check.
  439. * @param className - A class name that may be contained by the element.
  440. *
  441. * @return `true` if the element contains the class, or otherwise `false`.
  442. */
  443. function hasClass(elm, className) {
  444. return elm && elm.classList.contains(className);
  445. }
  446. /**
  447. * Parses the provided HTML string and returns the first element.
  448. *
  449. * @param html - An HTML string to parse.
  450. *
  451. * @return An Element on success, or otherwise `undefined`.
  452. */
  453. function parseHtml(html) {
  454. return child(new DOMParser().parseFromString(html, 'text/html').body);
  455. }
  456. /**
  457. * Call the `preventDefault()` of the provided event.
  458. *
  459. * @param e - An Event object.
  460. * @param stopPropagation - Optional. Whether to stop the event propagation or not.
  461. */
  462. function prevent(e, stopPropagation) {
  463. e.preventDefault();
  464. if (stopPropagation) {
  465. e.stopPropagation();
  466. e.stopImmediatePropagation();
  467. }
  468. }
  469. /**
  470. * Returns an element that matches the provided selector.
  471. *
  472. * @param parent - A parent element to start searching from.
  473. * @param selector - A selector to query.
  474. *
  475. * @return A found element or `null`.
  476. */
  477. function query(parent, selector) {
  478. return parent && parent.querySelector(selector);
  479. }
  480. /**
  481. * Returns elements that match the provided selector.
  482. *
  483. * @param parent - A parent element to start searching from.
  484. * @param selector - A selector to query.
  485. *
  486. * @return An array with matched elements.
  487. */
  488. function queryAll(parent, selector) {
  489. return slice(parent.querySelectorAll(selector));
  490. }
  491. /**
  492. * Returns a DOMRect object of the provided element.
  493. *
  494. * @param target - An element.
  495. */
  496. function rect(target) {
  497. return target.getBoundingClientRect();
  498. }
  499. /**
  500. * Removes the provided node from its parent.
  501. *
  502. * @param nodes - A node or nodes to remove.
  503. */
  504. function remove(nodes) {
  505. forEach(nodes, function (node) {
  506. if (node && node.parentNode) {
  507. node.parentNode.removeChild(node);
  508. }
  509. });
  510. }
  511. /**
  512. * Removes classes from the element.
  513. *
  514. * @param elm - An element to remove classes from.
  515. * @param classes - Classes to remove.
  516. */
  517. function removeClass(elm, classes) {
  518. toggleClass(elm, classes, false);
  519. }
  520. /**
  521. * Appends `px` to the provided number.
  522. * If the value is already string, just returns it.
  523. *
  524. * @param value - A value to append `px` to.
  525. *
  526. * @return A string with the CSS unit.
  527. */
  528. function unit(value) {
  529. return isString(value) ? value : value ? value + "px" : '';
  530. }
  531. /**
  532. * Throws an error if the provided condition is falsy.
  533. *
  534. * @param condition - If falsy, an error is thrown.
  535. * @param message - Optional. A message to display.
  536. */
  537. function assert(condition, message) {
  538. if (message === void 0) {
  539. message = '';
  540. }
  541. if (!condition) {
  542. throw new Error("[" + PROJECT_CODE + "] " + message);
  543. }
  544. }
  545. /**
  546. * Invokes the callback on the next tick.
  547. *
  548. * @param callback - A callback function.
  549. */
  550. function nextTick(callback) {
  551. setTimeout(callback);
  552. }
  553. /**
  554. * No operation.
  555. */
  556. var noop = function noop() {}; // eslint-disable-line no-empty-function, @typescript-eslint/no-empty-function
  557. /**
  558. * The arias of `window.requestAnimationFrame()`.
  559. */
  560. function raf(func) {
  561. return requestAnimationFrame(func);
  562. }
  563. /**
  564. * Checks if the subject number is between `minOrMax` and `maxOrMin`.
  565. *
  566. * @param number - A subject number to check.
  567. * @param minOrMax - A min or max number.
  568. * @param maxOrMin - A max or min number.
  569. * @param exclusive - Optional. Whether to exclude `x` or `y`.
  570. */
  571. function between(number, minOrMax, maxOrMin, exclusive) {
  572. var min = Math.min(minOrMax, maxOrMin);
  573. var max = Math.max(minOrMax, maxOrMin);
  574. return exclusive ? min < number && number < max : min <= number && number <= max;
  575. }
  576. var max$1 = Math.max,
  577. min$1 = Math.min;
  578. /**
  579. * Clamps a number.
  580. *
  581. * @param number - A subject number to check.
  582. * @param x - A min or max number.
  583. * @param y - A min or max number.
  584. */
  585. function clamp(number, x, y) {
  586. var minimum = min$1(x, y);
  587. var maximum = max$1(x, y);
  588. return min$1(max$1(minimum, number), maximum);
  589. }
  590. /**
  591. * Returns the sign of the provided number.
  592. *
  593. * @param x - A number.
  594. *
  595. * @return `1` for positive numbers, `-1` for negative numbers, or `0` for `0`.
  596. */
  597. function sign(x) {
  598. return +(x > 0) - +(x < 0);
  599. }
  600. var min = Math.min,
  601. max = Math.max,
  602. floor = Math.floor,
  603. ceil = Math.ceil,
  604. abs = Math.abs,
  605. round = Math.round;
  606. /**
  607. * The component for managing options.
  608. *
  609. * @since 3.0.0
  610. *
  611. * @param Splide - A Splide instance.
  612. * @param Components - A collection of components.
  613. * @param options - Options.
  614. *
  615. * @return An Options component object.
  616. */
  617. function Options(Splide, Components, options) {
  618. /**
  619. * Keeps the initial options to apply when no matched query exists.
  620. */
  621. var initialOptions;
  622. /**
  623. * Stores breakpoints with the MediaQueryList object.
  624. */
  625. var points;
  626. /**
  627. * Holds the current breakpoint.
  628. */
  629. var currPoint;
  630. /**
  631. * Called when the component is constructed.
  632. */
  633. function setup() {
  634. try {
  635. merge(options, JSON.parse(getAttribute(Splide.root, DATA_ATTRIBUTE)));
  636. } catch (e) {
  637. assert(false, e.message);
  638. }
  639. initialOptions = merge({}, options);
  640. }
  641. /**
  642. * Called when the component is mounted.
  643. */
  644. function mount() {
  645. var breakpoints = options.breakpoints;
  646. if (breakpoints) {
  647. points = Object.keys(breakpoints).sort(function (n, m) {
  648. return +n - +m;
  649. }).map(function (point) {
  650. return [point, matchMedia("(" + (options.mediaQuery || 'max') + "-width:" + point + "px)")];
  651. });
  652. addEventListener('resize', observe);
  653. observe();
  654. }
  655. }
  656. /**
  657. * Destroys the component.
  658. *
  659. * @param completely - Will be `true` for complete destruction.
  660. */
  661. function destroy(completely) {
  662. if (completely) {
  663. removeEventListener('resize', observe);
  664. }
  665. }
  666. /**
  667. * Observes breakpoints.
  668. * The `currPoint` may be `undefined`.
  669. */
  670. function observe() {
  671. var item = find(points, function (item) {
  672. return item[1].matches;
  673. }) || [];
  674. if (item[0] !== currPoint) {
  675. onMatch(currPoint = item[0]);
  676. }
  677. }
  678. /**
  679. * Called when the media query matches breakpoints.
  680. *
  681. * @param point - A matched point, or `undefined` that means no breakpoint matches a media query.
  682. */
  683. function onMatch(point) {
  684. var newOptions = options.breakpoints[point] || initialOptions;
  685. if (newOptions.destroy) {
  686. Splide.options = initialOptions;
  687. Splide.destroy(newOptions.destroy === 'completely');
  688. } else {
  689. if (Splide.state.is(DESTROYED)) {
  690. destroy(true);
  691. Splide.mount();
  692. }
  693. Splide.options = newOptions;
  694. }
  695. }
  696. return {
  697. setup: setup,
  698. mount: mount,
  699. destroy: destroy
  700. };
  701. }
  702. /**
  703. * Enumerates slides from left to right.
  704. */
  705. /**
  706. * Enumerates slides from right to left.
  707. */
  708. var RTL = 'rtl';
  709. /**
  710. * Enumerates slides in a col.
  711. */
  712. var TTB = 'ttb';
  713. /**
  714. * The translation map for directions.
  715. *
  716. * @since 3.0.0
  717. */
  718. var ORIENTATION_MAP = {
  719. marginRight: ['marginBottom', 'marginLeft'],
  720. width: ['height'],
  721. autoWidth: ['autoHeight'],
  722. fixedWidth: ['fixedHeight'],
  723. paddingLeft: ['paddingTop', 'paddingRight'],
  724. paddingRight: ['paddingBottom', 'paddingLeft'],
  725. left: ['top', 'right'],
  726. right: ['bottom', 'left'],
  727. x: ['y'],
  728. X: ['Y'],
  729. pageX: ['pageY'],
  730. ArrowLeft: ['ArrowUp', 'ArrowRight'],
  731. ArrowRight: ['ArrowDown', 'ArrowLeft']
  732. };
  733. /**
  734. * The component that absorbs the difference among directions.
  735. *
  736. * @since 3.0.0
  737. *
  738. * @param Splide - A Splide instance.
  739. * @param Components - A collection of components.
  740. * @param options - Options.
  741. *
  742. * @return A Direction component object.
  743. */
  744. function Direction(Splide, Components, options) {
  745. /**
  746. * Resolves the provided property name.
  747. *
  748. * @param prop - A property name to translate.
  749. * @param axisOnly - Optional. If `ture`, returns the same property for LTR and RTL.
  750. */
  751. function resolve(prop, axisOnly) {
  752. var direction = options.direction;
  753. var index = direction === RTL && !axisOnly ? 1 : direction === TTB ? 0 : -1;
  754. return ORIENTATION_MAP[prop][index] || prop;
  755. }
  756. /**
  757. * Orients the value towards the current direction.
  758. *
  759. * @param value - A value to orient.
  760. *
  761. * @return The oriented value.
  762. */
  763. function orient(value) {
  764. return value * (options.direction === RTL ? 1 : -1);
  765. }
  766. return {
  767. resolve: resolve,
  768. orient: orient
  769. };
  770. }
  771. var CLASS_ROOT = PROJECT_CODE;
  772. var CLASS_SLIDER = PROJECT_CODE + "__slider";
  773. var CLASS_TRACK = PROJECT_CODE + "__track";
  774. var CLASS_LIST = PROJECT_CODE + "__list";
  775. var CLASS_SLIDE = PROJECT_CODE + "__slide";
  776. var CLASS_CLONE = CLASS_SLIDE + "--clone";
  777. var CLASS_CONTAINER = CLASS_SLIDE + "__container";
  778. var CLASS_ARROWS = PROJECT_CODE + "__arrows";
  779. var CLASS_ARROW = PROJECT_CODE + "__arrow";
  780. var CLASS_ARROW_PREV = CLASS_ARROW + "--prev";
  781. var CLASS_ARROW_NEXT = CLASS_ARROW + "--next";
  782. var CLASS_PAGINATION = PROJECT_CODE + "__pagination";
  783. var CLASS_PAGINATION_PAGE = CLASS_PAGINATION + "__page";
  784. var CLASS_PROGRESS = PROJECT_CODE + "__progress";
  785. var CLASS_PROGRESS_BAR = CLASS_PROGRESS + "__bar";
  786. var CLASS_AUTOPLAY = PROJECT_CODE + "__autoplay";
  787. var CLASS_PLAY = PROJECT_CODE + "__play";
  788. var CLASS_PAUSE = PROJECT_CODE + "__pause";
  789. var CLASS_SPINNER = PROJECT_CODE + "__spinner";
  790. var CLASS_INITIALIZED = 'is-initialized';
  791. var CLASS_ACTIVE = 'is-active';
  792. var CLASS_PREV = 'is-prev';
  793. var CLASS_NEXT = 'is-next';
  794. var CLASS_VISIBLE = 'is-visible';
  795. var CLASS_LOADING = 'is-loading';
  796. /**
  797. * The array with all status classes.
  798. *
  799. * @since 3.0.0
  800. */
  801. var STATUS_CLASSES = [CLASS_ACTIVE, CLASS_VISIBLE, CLASS_PREV, CLASS_NEXT, CLASS_LOADING];
  802. /**
  803. * The collection of classes for elements that Splide dynamically creates.
  804. *
  805. * @since 3.0.0
  806. */
  807. var CLASSES = {
  808. slide: CLASS_SLIDE,
  809. clone: CLASS_CLONE,
  810. arrows: CLASS_ARROWS,
  811. arrow: CLASS_ARROW,
  812. prev: CLASS_ARROW_PREV,
  813. next: CLASS_ARROW_NEXT,
  814. pagination: CLASS_PAGINATION,
  815. page: CLASS_PAGINATION_PAGE,
  816. spinner: CLASS_SPINNER
  817. };
  818. var EVENT_MOUNTED = 'mounted';
  819. var EVENT_READY = 'ready';
  820. var EVENT_MOVE = 'move';
  821. var EVENT_MOVED = 'moved';
  822. var EVENT_CLICK = 'click';
  823. var EVENT_ACTIVE = 'active';
  824. var EVENT_INACTIVE = 'inactive';
  825. var EVENT_VISIBLE = 'visible';
  826. var EVENT_HIDDEN = 'hidden';
  827. var EVENT_SLIDE_KEYDOWN = 'slide:keydown';
  828. var EVENT_REFRESH = 'refresh';
  829. var EVENT_UPDATED = 'undated';
  830. var EVENT_RESIZE = 'resize';
  831. var EVENT_RESIZED = 'resized';
  832. var EVENT_DRAG = 'drag';
  833. var EVENT_DRAGGING = 'dragging';
  834. var EVENT_DRAGGED = 'dragged';
  835. var EVENT_SCROLL = 'scroll';
  836. var EVENT_SCROLLED = 'scrolled';
  837. var EVENT_DESTROY = 'destroy';
  838. var EVENT_ARROWS_MOUNTED = 'arrows:mounted';
  839. var EVENT_ARROWS_UPDATED = 'arrows:updated';
  840. var EVENT_PAGINATION_MOUNTED = 'pagination:mounted';
  841. var EVENT_PAGINATION_PAGE = 'pagination:page';
  842. var EVENT_PAGINATION_UPDATED = 'pagination:updated';
  843. var EVENT_NAVIGATION_MOUNTED = 'navigation:mounted';
  844. var EVENT_AUTOPLAY_PLAY = 'autoplay:play';
  845. var EVENT_AUTOPLAY_PLAYING = 'autoplay:playing';
  846. var EVENT_AUTOPLAY_PAUSE = 'autoplay:pause';
  847. var EVENT_LAZYLOAD_LOADED = 'lazyload:loaded';
  848. /**
  849. * The constructor to provided a simple event system.
  850. *
  851. * @since 3.0.0
  852. *
  853. * @return An EventBus object.
  854. */
  855. function EventBus() {
  856. /**
  857. * The collection of registered handlers.
  858. */
  859. var handlers = {};
  860. /**
  861. * Registers an event handler.
  862. *
  863. * @param events - An event name or names separated by spaces. Use a dot(.) to add a namespace.
  864. * @param callback - A callback function to register.
  865. * @param key - Optional. An object for an identifier of the handler.
  866. * @param priority - Optional. A priority number for the order in which the callbacks are invoked.
  867. * Lower numbers correspond with earlier execution. The default value is 10.
  868. */
  869. function on(events, callback, key, priority) {
  870. if (priority === void 0) {
  871. priority = 10;
  872. }
  873. forEachEvent(events, function (event, namespace) {
  874. handlers[event] = handlers[event] || [];
  875. push(handlers[event], {
  876. event: event,
  877. callback: callback,
  878. namespace: namespace,
  879. priority: priority,
  880. key: key
  881. }).sort(function (handler1, handler2) {
  882. return handler1.priority - handler2.priority;
  883. });
  884. });
  885. }
  886. /**
  887. * Removes event handlers registered by `on()`.
  888. * If only the event name is provided, all handlers that associate with the event are removed.
  889. * If the event name and namespace are specified, handlers that associate with the event and namespace are removed.
  890. *
  891. * @param events - An event name or names separated by spaces. Use a dot(.) to add a namespace.
  892. * @param key - Optional. An object for an identifier of the handler.
  893. */
  894. function off(events, key) {
  895. forEachEvent(events, function (event, namespace) {
  896. var eventHandlers = handlers[event];
  897. handlers[event] = eventHandlers && eventHandlers.filter(function (handler) {
  898. return handler.key ? handler.key !== key : handler.namespace !== namespace;
  899. });
  900. });
  901. }
  902. /**
  903. * Removes all handlers locked by the specified key.
  904. *
  905. * @param key - A key.
  906. */
  907. function offBy(key) {
  908. forOwn(handlers, function (eventHandlers, event) {
  909. off(event, key);
  910. });
  911. }
  912. /**
  913. * Triggers callback functions.
  914. * This accepts additional arguments and passes them to callbacks.
  915. *
  916. * @param event - An event name.
  917. */
  918. function emit(event) {
  919. var _arguments = arguments;
  920. (handlers[event] || []).forEach(function (handler) {
  921. handler.callback.apply(handler, slice(_arguments, 1));
  922. });
  923. }
  924. /**
  925. * Removes all handlers.
  926. */
  927. function destroy() {
  928. handlers = {};
  929. }
  930. /**
  931. * Parses provided events and iterates over them.
  932. *
  933. * @param events - An event or events.
  934. * @param iteratee - An iteratee function.
  935. */
  936. function forEachEvent(events, iteratee) {
  937. toArray(events).join(' ').split(' ').forEach(function (eventNS) {
  938. var fragments = eventNS.split('.');
  939. iteratee(fragments[0], fragments[1]);
  940. });
  941. }
  942. return {
  943. on: on,
  944. off: off,
  945. offBy: offBy,
  946. emit: emit,
  947. destroy: destroy
  948. };
  949. }
  950. /**
  951. * The function that provides interface for internal and native events.
  952. *
  953. * @since 3.0.0
  954. *
  955. * @param Splide - A Splide instance.
  956. *
  957. * @return A collection of interface functions.
  958. */
  959. function EventInterface(Splide) {
  960. /**
  961. * Holds the event object.
  962. */
  963. var event = Splide.event;
  964. /**
  965. * The key for events.
  966. */
  967. var key = {};
  968. /**
  969. * Stores all handlers that listen to native events.
  970. */
  971. var listeners = [];
  972. /**
  973. * Registers an event handler with an unique key.
  974. * It can only be removed by `off()` method below.
  975. *
  976. * @param events - An event name or names separated by spaces. Use a dot(.) to add a namespace.
  977. * @param callback - A callback function to register.
  978. * @param priority - Optional. A priority number for the order in which the callbacks are invoked.
  979. * Lower numbers correspond with earlier execution. The default value is 10.
  980. */
  981. function on(events, callback, priority) {
  982. event.on(events, callback, key, priority);
  983. }
  984. /**
  985. * Removes event handlers registered by `on()`.
  986. *
  987. * @param events - An event name or names separated by spaces. Use a dot(.) to add a namespace.
  988. */
  989. function off(events) {
  990. event.off(events, key);
  991. }
  992. /**
  993. * Listens to native events.
  994. * Splide#destory() will remove all registered listeners.
  995. *
  996. * @param targets - A target element, the window object or the document object.
  997. * @param events - An event or events to listen to.
  998. * @param callback - A callback function.
  999. * @param options - Optional. The options to pass to the `addEventListener` function.
  1000. */
  1001. function bind(targets, events, callback, options) {
  1002. forEachEvent(targets, events, function (target, event) {
  1003. listeners.push([target, event, callback, options]);
  1004. target.addEventListener(event, callback, options);
  1005. });
  1006. }
  1007. /**
  1008. * Removes the event handler.
  1009. *
  1010. * @param targets - A target element, the window object or the document object.
  1011. * @param events - An event name or names to remove.
  1012. */
  1013. function unbind(targets, events) {
  1014. forEachEvent(targets, events, function (target, event) {
  1015. listeners = listeners.filter(function (listener) {
  1016. if (listener[0] === target && listener[1] === event) {
  1017. target.removeEventListener(event, listener[2], listener[3]);
  1018. return false;
  1019. }
  1020. return true;
  1021. });
  1022. });
  1023. }
  1024. /**
  1025. * Iterates over each target and event.
  1026. *
  1027. * @param targets - A target element, the window object or the document object.
  1028. * @param events - An event name or names.
  1029. * @param iteratee - An iteratee function.
  1030. */
  1031. function forEachEvent(targets, events, iteratee) {
  1032. forEach(targets, function (target) {
  1033. if (target) {
  1034. events.split(' ').forEach(iteratee.bind(null, target));
  1035. }
  1036. });
  1037. }
  1038. /**
  1039. * Removes all listeners.
  1040. */
  1041. function destroy() {
  1042. listeners = listeners.filter(function (data) {
  1043. return unbind(data[0], data[1]);
  1044. });
  1045. event.offBy(key);
  1046. }
  1047. /**
  1048. * Invokes destroy when the slider is destroyed.
  1049. */
  1050. event.on(EVENT_DESTROY, destroy, key);
  1051. return {
  1052. on: on,
  1053. off: off,
  1054. emit: event.emit,
  1055. bind: bind,
  1056. unbind: unbind,
  1057. destroy: destroy
  1058. };
  1059. }
  1060. /**
  1061. * Requests interval like the native `setInterval()` with using `requestAnimationFrame`.
  1062. *
  1063. * @since 3.0.0
  1064. *
  1065. * @param interval - The interval duration in milliseconds.
  1066. * @param onInterval - The callback fired on every interval.
  1067. * @param onUpdate - Optional. Called on every animation frame, taking the progress rate.
  1068. * @param limit - Optional. Limits the number of interval.
  1069. */
  1070. function RequestInterval(interval, onInterval, onUpdate, limit) {
  1071. var now = Date.now;
  1072. /**
  1073. * The time when the interval starts.
  1074. */
  1075. var startTime;
  1076. /**
  1077. * The current progress rate.
  1078. */
  1079. var rate = 0;
  1080. /**
  1081. * The animation frame ID.
  1082. */
  1083. var id;
  1084. /**
  1085. * Indicates whether the interval is currently paused or not.
  1086. */
  1087. var paused = true;
  1088. /**
  1089. * The loop count. This only works when the `limit` argument is provided.
  1090. */
  1091. var count = 0;
  1092. /**
  1093. * The update function called on every animation frame.
  1094. */
  1095. function update() {
  1096. if (!paused) {
  1097. var elapsed = now() - startTime;
  1098. if (elapsed >= interval) {
  1099. rate = 1;
  1100. startTime = now();
  1101. } else {
  1102. rate = elapsed / interval;
  1103. }
  1104. if (onUpdate) {
  1105. onUpdate(rate);
  1106. }
  1107. if (rate === 1) {
  1108. onInterval();
  1109. if (limit && ++count >= limit) {
  1110. pause();
  1111. return;
  1112. }
  1113. }
  1114. raf(update);
  1115. }
  1116. }
  1117. /**
  1118. * Starts the interval.
  1119. *
  1120. * @param resume - Optional. Whether to resume the paused progress or not.
  1121. */
  1122. function start(resume) {
  1123. !resume && cancel();
  1124. startTime = now() - (resume ? rate * interval : 0);
  1125. paused = false;
  1126. raf(update);
  1127. }
  1128. /**
  1129. * Pauses the interval.
  1130. */
  1131. function pause() {
  1132. paused = true;
  1133. }
  1134. /**
  1135. * Rewinds the current progress.
  1136. */
  1137. function rewind() {
  1138. startTime = now();
  1139. rate = 0;
  1140. if (onUpdate) {
  1141. onUpdate(rate);
  1142. }
  1143. }
  1144. /**
  1145. * Cancels the interval.
  1146. */
  1147. function cancel() {
  1148. cancelAnimationFrame(id);
  1149. rate = 0;
  1150. id = 0;
  1151. paused = true;
  1152. }
  1153. /**
  1154. * Checks if the interval is paused or not.
  1155. *
  1156. * @return `true` if the interval is paused, or otherwise `false`.
  1157. */
  1158. function isPaused() {
  1159. return paused;
  1160. }
  1161. return {
  1162. start: start,
  1163. rewind: rewind,
  1164. pause: pause,
  1165. cancel: cancel,
  1166. isPaused: isPaused
  1167. };
  1168. }
  1169. /**
  1170. * The function providing a super simple state system.
  1171. *
  1172. * @param initialState - Specifies the initial state.
  1173. */
  1174. function State(initialState) {
  1175. /**
  1176. * The current state.
  1177. */
  1178. var state = initialState;
  1179. /**
  1180. * Sets a new state.
  1181. *
  1182. * @param value - A new state value.
  1183. */
  1184. function set(value) {
  1185. state = value;
  1186. }
  1187. /**
  1188. * Checks if the current state matches the provided one.
  1189. *
  1190. * @param states - A state to check.
  1191. *
  1192. * @return `true` if the current state is the provided one.
  1193. */
  1194. function is(states) {
  1195. return includes(toArray(states), state);
  1196. }
  1197. return {
  1198. set: set,
  1199. is: is
  1200. };
  1201. }
  1202. /**
  1203. * Returns the throttled function.
  1204. *
  1205. * @param func - A function to throttle.
  1206. * @param duration - Optional. Throttle duration in milliseconds.
  1207. *
  1208. * @return A throttled function.
  1209. */
  1210. function Throttle(func, duration) {
  1211. var interval;
  1212. function throttled() {
  1213. var _arguments2 = arguments,
  1214. _this = this;
  1215. if (!interval) {
  1216. interval = RequestInterval(duration || 0, function () {
  1217. func.apply(_this, _arguments2);
  1218. interval = null;
  1219. }, null, 1);
  1220. interval.start();
  1221. }
  1222. }
  1223. return throttled;
  1224. }
  1225. /**
  1226. * Formats a string.
  1227. *
  1228. * @param string - A string to format.
  1229. * @param replacements - A replacement or replacements.
  1230. *
  1231. * @return A formatted string.
  1232. */
  1233. function format(string, replacements) {
  1234. forEach(replacements, function (replacement) {
  1235. string = string.replace('%s', "" + replacement);
  1236. });
  1237. return string;
  1238. }
  1239. /**
  1240. * Pads the number with 0.
  1241. *
  1242. * @param number - A number to pad.
  1243. *
  1244. * @return string - Padded number.
  1245. */
  1246. function pad(number) {
  1247. return number < 10 ? "0" + number : "" + number;
  1248. }
  1249. /**
  1250. * Stores unique IDs.
  1251. *
  1252. * @since 3.0.0
  1253. */
  1254. var ids = {};
  1255. /**
  1256. * Returns a sequential unique ID as "{ prefix }-{ number }".
  1257. *
  1258. * @param prefix - A prefix for the ID.
  1259. */
  1260. function uniqueId(prefix) {
  1261. return "" + prefix + pad(ids[prefix] = (ids[prefix] || 0) + 1);
  1262. }
  1263. /**
  1264. * The component that collects and handles elements which the slider consists of.
  1265. *
  1266. * @since 3.0.0
  1267. *
  1268. * @param Splide - A Splide instance.
  1269. * @param Components - A collection of components.
  1270. * @param options - Options.
  1271. *
  1272. * @return An Elements component object.
  1273. */
  1274. function Elements(Splide, Components, options) {
  1275. var _EventInterface = EventInterface(Splide),
  1276. on = _EventInterface.on;
  1277. var root = Splide.root;
  1278. var elements = {};
  1279. /**
  1280. * Stores all slide elements.
  1281. */
  1282. var slides = [];
  1283. /**
  1284. * Stores all root classes.
  1285. */
  1286. var classes;
  1287. /**
  1288. * The slider element that may be `undefined`.
  1289. */
  1290. var slider;
  1291. /**
  1292. * The track element.
  1293. */
  1294. var track;
  1295. /**
  1296. * The list element.
  1297. */
  1298. var list;
  1299. /**
  1300. * Called when the component is constructed.
  1301. */
  1302. function setup() {
  1303. collect();
  1304. identify();
  1305. addClass(root, classes = getClasses());
  1306. }
  1307. /**
  1308. * Called when the component is mounted.
  1309. */
  1310. function mount() {
  1311. on(EVENT_REFRESH, refresh);
  1312. on(EVENT_UPDATED, update);
  1313. }
  1314. /**
  1315. * Destroys the component.
  1316. */
  1317. function destroy() {
  1318. empty(slides);
  1319. removeClass(root, classes);
  1320. }
  1321. /**
  1322. * Recollects slide elements.
  1323. */
  1324. function refresh() {
  1325. destroy();
  1326. setup();
  1327. }
  1328. /**
  1329. * Updates the status of elements.
  1330. */
  1331. function update() {
  1332. removeClass(root, classes);
  1333. addClass(root, classes = getClasses());
  1334. }
  1335. /**
  1336. * Collects elements which the slider consists of.
  1337. */
  1338. function collect() {
  1339. slider = child(root, "." + CLASS_SLIDER);
  1340. track = query(root, "." + CLASS_TRACK);
  1341. list = child(track, "." + CLASS_LIST);
  1342. assert(track && list, 'Missing a track/list element.');
  1343. push(slides, children(list, "." + CLASS_SLIDE + ":not(." + CLASS_CLONE + ")"));
  1344. var autoplay = find("." + CLASS_AUTOPLAY);
  1345. var arrows = find("." + CLASS_ARROWS);
  1346. assign(elements, {
  1347. root: root,
  1348. slider: slider,
  1349. track: track,
  1350. list: list,
  1351. slides: slides,
  1352. arrows: arrows,
  1353. prev: query(arrows, "." + CLASS_ARROW_PREV),
  1354. next: query(arrows, "." + CLASS_ARROW_NEXT),
  1355. bar: query(find("." + CLASS_PROGRESS), "." + CLASS_PROGRESS_BAR),
  1356. play: query(autoplay, "." + CLASS_PLAY),
  1357. pause: query(autoplay, "." + CLASS_PAUSE)
  1358. });
  1359. }
  1360. /**
  1361. * Assigns unique IDs to essential elements.
  1362. */
  1363. function identify() {
  1364. var id = root.id || uniqueId(PROJECT_CODE);
  1365. root.id = id;
  1366. track.id = track.id || id + "-track";
  1367. list.id = list.id || id + "-list";
  1368. }
  1369. /**
  1370. * Finds an element only in children of the root or slider element.
  1371. *
  1372. * @return {Element} - A found element or undefined.
  1373. */
  1374. function find(selector) {
  1375. return child(root, selector) || child(slider, selector);
  1376. }
  1377. /**
  1378. * Return an array with classes for the root element.
  1379. *
  1380. * @return An array with classes.
  1381. */
  1382. function getClasses() {
  1383. return [CLASS_ROOT + "--" + options.type, CLASS_ROOT + "--" + options.direction, options.drag && CLASS_ROOT + "--draggable", options.isNavigation && CLASS_ROOT + "--nav", CLASS_ACTIVE];
  1384. }
  1385. return assign(elements, {
  1386. setup: setup,
  1387. mount: mount,
  1388. destroy: destroy
  1389. });
  1390. }
  1391. /**
  1392. * The component for managing styles of the slider.
  1393. *
  1394. * @since 3.0.0
  1395. *
  1396. * @return A Style component object.
  1397. */
  1398. function Style() {
  1399. /**
  1400. * The style element for the slider.
  1401. */
  1402. var style;
  1403. /**
  1404. * The CSSStyleSheet object of the created style element.
  1405. */
  1406. var sheet;
  1407. /**
  1408. * Called when the component is mounted.
  1409. */
  1410. function mount() {
  1411. style = create('style', {}, document.head);
  1412. sheet = style.sheet;
  1413. }
  1414. /**
  1415. * Destroys the component.
  1416. */
  1417. function destroy() {
  1418. remove(style);
  1419. sheet = null;
  1420. }
  1421. /**
  1422. * Registers the style for the selector.
  1423. *
  1424. * @param selector - A selector string.
  1425. * @param prop - A CSS property, accepting the camel case.
  1426. * @param value - A CSS value.
  1427. */
  1428. function rule(selector, prop, value) {
  1429. var _sheet = sheet,
  1430. cssRules = _sheet.cssRules;
  1431. var cssRule = find(cssRules, function (cssRule) {
  1432. return isCSSStyleRule(cssRule) && cssRule.selectorText === selector;
  1433. }) || cssRules[sheet.insertRule(selector + "{}", 0)];
  1434. if (isCSSStyleRule(cssRule)) {
  1435. cssRule.style[prop] = "" + value;
  1436. }
  1437. }
  1438. /**
  1439. * Registers the style by the element or the ID.
  1440. *
  1441. * @param target - A target element or ID.
  1442. * @param prop - A CSS property, accepting the camel case.
  1443. * @param value - A CSS value.
  1444. */
  1445. function ruleBy(target, prop, value) {
  1446. rule("#" + (isHTMLElement(target) ? target.id : target), prop, value);
  1447. }
  1448. /**
  1449. * Checks if the provided rule is a CSSStyleRule instance or not.
  1450. *
  1451. * @param cssRule - An instance to check.
  1452. *
  1453. * @return `true` if the cssRule is an instance of CSSStyleRule, or otherwise `false`.
  1454. */
  1455. function isCSSStyleRule(cssRule) {
  1456. return cssRule instanceof CSSStyleRule;
  1457. }
  1458. return {
  1459. mount: mount,
  1460. destroy: destroy,
  1461. rule: rule,
  1462. ruleBy: ruleBy
  1463. };
  1464. }
  1465. var ROLE = 'role';
  1466. var ARIA_CONTROLS = 'aria-controls';
  1467. var ARIA_CURRENT = 'aria-current';
  1468. var ARIA_LABEL = 'aria-label';
  1469. var ARIA_HIDDEN = 'aria-hidden';
  1470. var TAB_INDEX = 'tabindex';
  1471. var DISABLED = 'disabled';
  1472. /**
  1473. * The array with all attributes.
  1474. *
  1475. * @since 3.0.0
  1476. */
  1477. var ALL_ATTRIBUTES = [ROLE, ARIA_CONTROLS, ARIA_CURRENT, ARIA_LABEL, ARIA_HIDDEN, TAB_INDEX, DISABLED];
  1478. /**
  1479. * The type for the regular slider.
  1480. *
  1481. * @since 3.0.0
  1482. */
  1483. var SLIDE = 'slide';
  1484. /**
  1485. * The type for the carousel slider.
  1486. *
  1487. * @since 3.0.0
  1488. */
  1489. var LOOP = 'loop';
  1490. /**
  1491. * The type for the fade slider that can not have multiple slides in a page.
  1492. *
  1493. * @since 3.0.0
  1494. */
  1495. var FADE = 'fade';
  1496. /**
  1497. * The sub component for managing each slide.
  1498. *
  1499. * @since 3.0.0
  1500. *
  1501. * @param Splide - A Splide instance.
  1502. * @param index - A slide index.
  1503. * @param slideIndex - A slide index for clones. This must be `-1` if the slide is not clone.
  1504. * @param slide - A slide element.
  1505. *
  1506. * @return A Slide sub component.
  1507. */
  1508. function Slide$1(Splide, index, slideIndex, slide) {
  1509. var _EventInterface2 = EventInterface(Splide),
  1510. on = _EventInterface2.on,
  1511. emit = _EventInterface2.emit,
  1512. bind = _EventInterface2.bind,
  1513. destroyEvents = _EventInterface2.destroy;
  1514. var Components = Splide.Components,
  1515. root = Splide.root,
  1516. options = Splide.options;
  1517. var isNavigation = options.isNavigation,
  1518. updateOnMove = options.updateOnMove;
  1519. var resolve = Components.Direction.resolve;
  1520. var isClone = slideIndex > -1;
  1521. var container = child(slide, "." + CLASS_CONTAINER);
  1522. /**
  1523. * Called when the component is mounted.
  1524. */
  1525. function mount() {
  1526. var _this2 = this;
  1527. init();
  1528. bind(slide, 'click keydown', function (e) {
  1529. emit(e.type === 'click' ? EVENT_CLICK : EVENT_SLIDE_KEYDOWN, _this2, e);
  1530. });
  1531. on(EVENT_MOUNTED, onMounted.bind(this));
  1532. }
  1533. /**
  1534. * Called after all components are mounted.
  1535. * Updating the status on mount is too early to notify other components of the active slide.
  1536. */
  1537. function onMounted() {
  1538. var boundUpdate = update.bind(this);
  1539. boundUpdate();
  1540. on([EVENT_MOVED, EVENT_UPDATED, EVENT_RESIZED, EVENT_SCROLLED], boundUpdate);
  1541. if (updateOnMove) {
  1542. on(EVENT_MOVE, onMove.bind(this));
  1543. }
  1544. }
  1545. /**
  1546. * If the `updateOnMove` option is `true`, called when the slider starts moving.
  1547. *
  1548. * @param next - A next index.
  1549. * @param prev - A previous index.
  1550. * @param dest - A destination index.
  1551. */
  1552. function onMove(next, prev, dest) {
  1553. if (dest === index) {
  1554. updateActivity.call(this, true);
  1555. }
  1556. update.call(this);
  1557. }
  1558. /**
  1559. * Initializes the component.
  1560. */
  1561. function init() {
  1562. if (!isClone) {
  1563. slide.id = root.id + "-slide" + pad(index + 1);
  1564. }
  1565. if (isNavigation) {
  1566. if (!isHTMLButtonElement(slide)) {
  1567. setAttribute(slide, ROLE, 'button');
  1568. }
  1569. var idx = isClone ? slideIndex : index;
  1570. var label = format(options.i18n.slideX, idx + 1);
  1571. var controls = Splide.splides.map(function (splide) {
  1572. return splide.root.id;
  1573. }).join(' ');
  1574. setAttribute(slide, ARIA_LABEL, label);
  1575. setAttribute(slide, ARIA_CONTROLS, controls);
  1576. }
  1577. }
  1578. /**
  1579. * Destroys the component.
  1580. */
  1581. function destroy() {
  1582. destroyEvents();
  1583. removeClass(slide, STATUS_CLASSES);
  1584. removeAttribute(slide, ALL_ATTRIBUTES);
  1585. }
  1586. /**
  1587. * Updates attribute and classes of the slide.
  1588. */
  1589. function update() {
  1590. var currIndex = Splide.index;
  1591. updateActivity.call(this, isActive());
  1592. updateVisibility.call(this, isVisible());
  1593. toggleClass(slide, CLASS_PREV, index === currIndex - 1);
  1594. toggleClass(slide, CLASS_NEXT, index === currIndex + 1);
  1595. }
  1596. /**
  1597. * Updates the status related with activity.
  1598. *
  1599. * @param active - Set `true` if the slide is active.
  1600. */
  1601. function updateActivity(active) {
  1602. if (active !== hasClass(slide, CLASS_ACTIVE)) {
  1603. toggleClass(slide, CLASS_ACTIVE, active);
  1604. if (isNavigation) {
  1605. setAttribute(slide, ARIA_CURRENT, active || null);
  1606. }
  1607. emit(active ? EVENT_ACTIVE : EVENT_INACTIVE, this);
  1608. }
  1609. }
  1610. /**
  1611. * Updates the status related with visibility.
  1612. *
  1613. * @param visible - Set `true` if the slide is visible.
  1614. */
  1615. function updateVisibility(visible) {
  1616. setAttribute(slide, ARIA_HIDDEN, !visible || null);
  1617. setAttribute(slide, TAB_INDEX, visible && options.slideFocus ? 0 : null);
  1618. if (visible !== hasClass(slide, CLASS_VISIBLE)) {
  1619. toggleClass(slide, CLASS_VISIBLE, visible);
  1620. emit(visible ? EVENT_VISIBLE : EVENT_HIDDEN, this);
  1621. }
  1622. }
  1623. /**
  1624. * Adds a CSS rule to the slider or the container.
  1625. *
  1626. * @param prop - A property name.
  1627. * @param value - A CSS value to add.
  1628. * @param useContainer - Optional. Determines whether to apply the rule to the container or not.
  1629. */
  1630. function rule(prop, value, useContainer) {
  1631. var selector = "#" + slide.id + (container && useContainer ? " > ." + CLASS_CONTAINER : '');
  1632. Components.Style.rule(selector, prop, value);
  1633. }
  1634. /**
  1635. * Checks if the slide is active or not.
  1636. *
  1637. * @return `true` if the slide is active.
  1638. */
  1639. function isActive() {
  1640. return Splide.index === index;
  1641. }
  1642. /**
  1643. * Checks if the slide is visible or not.
  1644. */
  1645. function isVisible() {
  1646. if (Splide.is(FADE)) {
  1647. return isActive();
  1648. }
  1649. var trackRect = rect(Components.Elements.track);
  1650. var slideRect = rect(slide);
  1651. var left = resolve('left');
  1652. var right = resolve('right');
  1653. return floor(trackRect[left]) <= slideRect[left] && slideRect[right] <= ceil(trackRect[right]);
  1654. }
  1655. /**
  1656. * Calculates how far this slide is from another slide and
  1657. * returns `true` if the distance is within the given number.
  1658. *
  1659. * @param from - An index of a base slide.
  1660. * @param distance - `true` if the slide is within this number.
  1661. *
  1662. * @return `true` if the slide is within the `distance` from the base slide, or otherwise `false`.
  1663. */
  1664. function isWithin(from, distance) {
  1665. var diff = abs(from - index);
  1666. if (!Splide.is(SLIDE) && !isClone) {
  1667. diff = min(diff, Splide.length - diff);
  1668. }
  1669. return diff <= distance;
  1670. }
  1671. return {
  1672. index: index,
  1673. slideIndex: slideIndex,
  1674. slide: slide,
  1675. container: container,
  1676. isClone: isClone,
  1677. mount: mount,
  1678. destroy: destroy,
  1679. rule: rule,
  1680. isWithin: isWithin
  1681. };
  1682. }
  1683. /**
  1684. * The component for managing all slides include clones.
  1685. *
  1686. * @since 3.0.0
  1687. *
  1688. * @param Splide - A Splide instance.
  1689. * @param Components - A collection of components.
  1690. * @param options - Options.
  1691. *
  1692. * @return An Slides component object.
  1693. */
  1694. function Slides(Splide, Components, options) {
  1695. var _EventInterface3 = EventInterface(Splide),
  1696. on = _EventInterface3.on,
  1697. emit = _EventInterface3.emit,
  1698. bind = _EventInterface3.bind;
  1699. var _Components$Elements = Components.Elements,
  1700. slides = _Components$Elements.slides,
  1701. list = _Components$Elements.list;
  1702. /**
  1703. * Stores all SlideComponent objects.
  1704. */
  1705. var Slides = [];
  1706. /**
  1707. * Called when the component is mounted.
  1708. */
  1709. function mount() {
  1710. init();
  1711. on(EVENT_REFRESH, refresh);
  1712. }
  1713. /**
  1714. * Initializes the component.
  1715. */
  1716. function init() {
  1717. slides.forEach(function (slide, index) {
  1718. register(slide, index, -1);
  1719. });
  1720. }
  1721. /**
  1722. * Destroys the component.
  1723. */
  1724. function destroy() {
  1725. forEach$1(function (Slide) {
  1726. Slide.destroy();
  1727. });
  1728. empty(Slides);
  1729. }
  1730. /**
  1731. * Discards all Slide components and regenerates them.
  1732. */
  1733. function refresh() {
  1734. destroy();
  1735. init();
  1736. }
  1737. /**
  1738. * Registers a slide element and creates a Slide object.
  1739. *
  1740. * @param slide - A slide element to register.
  1741. * @param index - A slide index.
  1742. * @param slideIndex - A slide index for clones. This must be `-1` for regular slides.
  1743. */
  1744. function register(slide, index, slideIndex) {
  1745. var object = Slide$1(Splide, index, slideIndex, slide);
  1746. object.mount();
  1747. Slides.push(object);
  1748. }
  1749. /**
  1750. * Returns all Slide objects.
  1751. *
  1752. * @param excludeClones - Optional. Determines whether to exclude clones or not.
  1753. *
  1754. * @return An array with Slide objects.
  1755. */
  1756. function get(excludeClones) {
  1757. return excludeClones ? filter(function (Slide) {
  1758. return !Slide.isClone;
  1759. }) : Slides;
  1760. }
  1761. /**
  1762. * Returns slides in the specified page.
  1763. *
  1764. * @param page - A page index.
  1765. *
  1766. * @return An array with slides that belong to the page.
  1767. */
  1768. function getIn(page) {
  1769. var Controller = Components.Controller;
  1770. var index = Controller.toIndex(page);
  1771. var max = Controller.hasFocus() ? 1 : options.perPage;
  1772. return filter(function (Slide) {
  1773. return between(Slide.index, index, index + max - 1);
  1774. });
  1775. }
  1776. /**
  1777. * Returns a Slide object at the specified index.
  1778. *
  1779. * @param index - A slide index.
  1780. *
  1781. * @return A Slide object if available, or otherwise `undefined`.
  1782. */
  1783. function getAt(index) {
  1784. return filter(index)[0];
  1785. }
  1786. /**
  1787. * Inserts a slide or slides at a specified index.
  1788. *
  1789. * @param items - A slide element, an HTML string or an array with them.
  1790. * @param index - Optional. An index to insert the slide at. If omitted, appends it to the list.
  1791. */
  1792. function add(items, index) {
  1793. forEach(items, function (slide) {
  1794. if (isString(slide)) {
  1795. slide = parseHtml(slide);
  1796. }
  1797. if (isHTMLElement(slide)) {
  1798. var ref = slides[index];
  1799. ref ? before(slide, ref) : append(list, slide);
  1800. addClass(slide, options.classes.slide);
  1801. observeImages(slide, emit.bind(null, EVENT_RESIZE));
  1802. }
  1803. });
  1804. emit(EVENT_REFRESH);
  1805. }
  1806. /**
  1807. * Removes slides that match the matcher
  1808. * that can be an index, an array with indices, a selector, or an iteratee function.
  1809. *
  1810. * @param matcher - An index, an array with indices, a selector string, or an iteratee function.
  1811. */
  1812. function remove$1(matcher) {
  1813. remove(filter(matcher).map(function (Slide) {
  1814. return Slide.slide;
  1815. }));
  1816. emit(EVENT_REFRESH);
  1817. }
  1818. /**
  1819. * Iterates over Slide objects by the iteratee function.
  1820. *
  1821. * @param iteratee - An iteratee function that takes a Slide object, an index and an array with Slides.
  1822. * @param excludeClones - Optional. Determines whether to exclude clones or not.
  1823. */
  1824. function forEach$1(iteratee, excludeClones) {
  1825. get(excludeClones).forEach(iteratee);
  1826. }
  1827. /**
  1828. * Filters Slides by the matcher
  1829. * that can be an index, an array with indices, a selector, or an predicate function.
  1830. *
  1831. * @param matcher - An index, an array with indices, a selector string, or an predicate function.
  1832. *
  1833. * @return An array with SlideComponent objects.
  1834. */
  1835. function filter(matcher) {
  1836. return Slides.filter(isFunction(matcher) ? matcher : function (Slide) {
  1837. return isString(matcher) ? matches(Slide.slide, matcher) : includes(toArray(matcher), Slide.index);
  1838. });
  1839. }
  1840. /**
  1841. * Adds a CSS rule to all slides or containers.
  1842. *
  1843. * @param prop - A property name.
  1844. * @param value - A CSS value to add.
  1845. * @param useContainer - Optional. Determines whether to apply the rule to the container or not.
  1846. */
  1847. function rule(prop, value, useContainer) {
  1848. forEach$1(function (Slide) {
  1849. Slide.rule(prop, value, useContainer);
  1850. });
  1851. }
  1852. /**
  1853. * Invokes the callback after all images in the element are loaded.
  1854. *
  1855. * @param elm - An element that may contain images.
  1856. * @param callback - A callback function.
  1857. */
  1858. function observeImages(elm, callback) {
  1859. var images = queryAll(elm, 'img');
  1860. var length = images.length;
  1861. if (length) {
  1862. images.forEach(function (img) {
  1863. bind(img, 'load error', function () {
  1864. if (! --length) {
  1865. callback();
  1866. }
  1867. });
  1868. });
  1869. } else {
  1870. callback();
  1871. }
  1872. }
  1873. /**
  1874. * Returns the length of slides.
  1875. *
  1876. * @param excludeClones - Optional. Determines whether to exclude clones or not.
  1877. *
  1878. * @return The length of slides.
  1879. */
  1880. function getLength(excludeClones) {
  1881. return excludeClones ? slides.length : Slides.length;
  1882. }
  1883. /**
  1884. * Checks if the number of slides is over than the `perPage` option, including clones.
  1885. *
  1886. * @return `true` if there are enough slides, or otherwise `false`.
  1887. */
  1888. function isEnough() {
  1889. return Slides.length > options.perPage;
  1890. }
  1891. return {
  1892. mount: mount,
  1893. destroy: destroy,
  1894. register: register,
  1895. get: get,
  1896. getIn: getIn,
  1897. getAt: getAt,
  1898. add: add,
  1899. remove: remove$1,
  1900. forEach: forEach$1,
  1901. filter: filter,
  1902. rule: rule,
  1903. getLength: getLength,
  1904. isEnough: isEnough
  1905. };
  1906. }
  1907. /**
  1908. * The component that generates clones for the loop slider.
  1909. *
  1910. * @since 3.0.0
  1911. *
  1912. * @param Splide - A Splide instance.
  1913. * @param Components - A collection of components.
  1914. * @param options - Options.
  1915. *
  1916. * @return A Clones component object.
  1917. */
  1918. function Clones(Splide, Components, options) {
  1919. var _EventInterface4 = EventInterface(Splide),
  1920. on = _EventInterface4.on,
  1921. emit = _EventInterface4.emit;
  1922. var Elements = Components.Elements,
  1923. Slides = Components.Slides;
  1924. var resolve = Components.Direction.resolve;
  1925. var clones = [];
  1926. /**
  1927. * Keeps the current number of clones.
  1928. */
  1929. var cloneCount;
  1930. /**
  1931. * The index used for generating IDs.
  1932. */
  1933. var cloneIndex;
  1934. /**
  1935. * Called when the component is mounted.
  1936. */
  1937. function mount() {
  1938. init();
  1939. on(EVENT_REFRESH, refresh);
  1940. on([EVENT_UPDATED, EVENT_RESIZE], observe);
  1941. }
  1942. /**
  1943. * Removes all clones if available, and generates new clones.
  1944. */
  1945. function init() {
  1946. if (cloneCount = computeCloneCount()) {
  1947. generate(cloneCount);
  1948. }
  1949. }
  1950. /**
  1951. * Destroys clones.
  1952. */
  1953. function destroy() {
  1954. remove(clones);
  1955. empty(clones);
  1956. }
  1957. /**
  1958. * Discards all clones and regenerates them.
  1959. * Must do this before the Elements component collects slide elements.
  1960. */
  1961. function refresh() {
  1962. destroy();
  1963. init();
  1964. }
  1965. /**
  1966. * Observes the required clone count and refreshes the slider if necessary.
  1967. */
  1968. function observe() {
  1969. if (cloneCount !== computeCloneCount()) {
  1970. emit(EVENT_REFRESH);
  1971. }
  1972. }
  1973. /**
  1974. * Generates the specified number of clones.
  1975. *
  1976. * @param count - The number of clones to generate for each side.
  1977. */
  1978. function generate(count) {
  1979. var slides = Slides.get().slice();
  1980. var length = slides.length;
  1981. if (length) {
  1982. cloneIndex = 0;
  1983. while (slides.length < count) {
  1984. push(slides, slides);
  1985. }
  1986. slides.slice(-count).concat(slides.slice(0, count)).forEach(function (Slide, index) {
  1987. var isHead = index < count;
  1988. var clone = cloneDeep(Slide.slide);
  1989. isHead ? before(clone, slides[0].slide) : append(Elements.list, clone);
  1990. push(clones, clone);
  1991. Slides.register(clone, index - count + (isHead ? 0 : length), Slide.index);
  1992. });
  1993. }
  1994. }
  1995. /**
  1996. * Deeply clones the provided element with removing the ID attribute.
  1997. *
  1998. * @param elm - An element to clone.
  1999. *
  2000. * @return A cloned element.
  2001. */
  2002. function cloneDeep(elm) {
  2003. var clone = elm.cloneNode(true);
  2004. addClass(clone, options.classes.clone);
  2005. clone.id = Splide.root.id + "-clone" + pad(++cloneIndex);
  2006. return clone;
  2007. }
  2008. /**
  2009. * Returns the number of elements to generate.
  2010. * This always returns 0 if the slider type is not `'loop'`.
  2011. *
  2012. * @return The number of clones.
  2013. */
  2014. function computeCloneCount() {
  2015. var clones = options.clones;
  2016. if (!Splide.is(LOOP)) {
  2017. clones = 0;
  2018. } else if (!clones) {
  2019. var fixedSize = options[resolve('fixedWidth')];
  2020. var fixedCount = fixedSize && ceil(rect(Elements.track)[resolve('width')] / fixedSize);
  2021. var baseCount = fixedCount || options[resolve('autoWidth')] && Splide.length || options.perPage;
  2022. clones = baseCount * (options.drag ? (options.flickMaxPages || 1) + 1 : 2);
  2023. }
  2024. return clones;
  2025. }
  2026. return {
  2027. mount: mount,
  2028. destroy: destroy
  2029. };
  2030. }
  2031. /**
  2032. * The component that layouts slider components and provides methods for dimensions.
  2033. *
  2034. * @since 3.0.0
  2035. *
  2036. * @param Splide - A Splide instance.
  2037. * @param Components - A collection of components.
  2038. * @param options - Options.
  2039. *
  2040. * @return An Layout component object.
  2041. */
  2042. function Layout(Splide, Components, options) {
  2043. var _EventInterface5 = EventInterface(Splide),
  2044. on = _EventInterface5.on,
  2045. bind = _EventInterface5.bind,
  2046. emit = _EventInterface5.emit;
  2047. var Slides = Components.Slides;
  2048. var ruleBy = Components.Style.ruleBy;
  2049. var resolve = Components.Direction.resolve;
  2050. var _Components$Elements2 = Components.Elements,
  2051. root = _Components$Elements2.root,
  2052. track = _Components$Elements2.track,
  2053. list = _Components$Elements2.list;
  2054. var getAt = Slides.getAt;
  2055. var vertical = options.direction === TTB;
  2056. /**
  2057. * Called when the component is mounted.
  2058. */
  2059. function mount() {
  2060. init();
  2061. bind(window, 'resize load', Throttle(emit.bind(this, EVENT_RESIZE)));
  2062. on([EVENT_UPDATED, EVENT_REFRESH], init);
  2063. on(EVENT_RESIZE, resize);
  2064. }
  2065. /**
  2066. * Initializes the component on `mount` or `updated`.
  2067. * Uses `max-width` for the root to prevent the slider from exceeding the parent element.
  2068. */
  2069. function init() {
  2070. ruleBy(root, 'maxWidth', unit(options.width));
  2071. ruleBy(track, resolve('paddingLeft'), cssPadding(false));
  2072. ruleBy(track, resolve('paddingRight'), cssPadding(true));
  2073. Slides.rule(resolve('marginRight'), unit(options.gap));
  2074. Slides.rule('width', cssSlideWidth());
  2075. setSlidesHeight();
  2076. resize();
  2077. }
  2078. /**
  2079. * Updates dimensions of some elements when the slider is resized.
  2080. */
  2081. function resize() {
  2082. ruleBy(track, 'height', cssTrackHeight());
  2083. options.heightRatio && setSlidesHeight();
  2084. emit(EVENT_RESIZED);
  2085. }
  2086. /**
  2087. * Updates the height of slides or their container elements if available.
  2088. */
  2089. function setSlidesHeight() {
  2090. Slides.rule('height', cssSlideHeight(), true);
  2091. }
  2092. /**
  2093. * Parses the padding option and returns the value for each side.
  2094. * This method returns `paddingTop` or `paddingBottom` for the vertical slider.
  2095. *
  2096. * @param right - Determines whether to get `paddingRight/Bottom` or `paddingLeft/Top`.
  2097. *
  2098. * @return The padding value as a CSS string.
  2099. */
  2100. function cssPadding(right) {
  2101. var padding = options.padding;
  2102. var prop = resolve(right ? 'right' : 'left', true);
  2103. return padding ? unit(padding[prop] || (isObject(padding) ? '0' : padding)) : '';
  2104. }
  2105. /**
  2106. * Returns the height of the track element as a CSS string.
  2107. *
  2108. * @return The height of the track.
  2109. */
  2110. function cssTrackHeight() {
  2111. var height = '';
  2112. if (vertical) {
  2113. height = cssHeight();
  2114. assert(height, '"height" or "heightRatio" is missing.');
  2115. var paddingTop = cssPadding(false);
  2116. var paddingBottom = cssPadding(true);
  2117. if (paddingTop || paddingBottom) {
  2118. height = "calc(" + height;
  2119. height += "" + (paddingTop ? " - " + paddingTop : '') + (paddingBottom ? " - " + paddingBottom : '') + ")";
  2120. }
  2121. }
  2122. return height;
  2123. }
  2124. /**
  2125. * Converts options related with height to a CSS string.
  2126. *
  2127. * @return The height as a CSS string if available, or otherwise an empty string.
  2128. */
  2129. function cssHeight() {
  2130. return unit(options.height || rect(list).width * options.heightRatio);
  2131. }
  2132. /**
  2133. * Returns the width of the slide as a CSS string.
  2134. *
  2135. * @return The width of the slide.
  2136. */
  2137. function cssSlideWidth() {
  2138. return options.autoWidth ? '' : unit(options.fixedWidth) || (vertical ? '' : cssSlideSize());
  2139. }
  2140. /**
  2141. * Returns the height of the slide as a CSS string.
  2142. *
  2143. * @return The height of the slide.
  2144. */
  2145. function cssSlideHeight() {
  2146. return unit(options.fixedHeight) || (vertical ? options.autoHeight ? '' : cssSlideSize() : cssHeight());
  2147. }
  2148. /**
  2149. * Returns the CSS string for slide width or height without gap.
  2150. *
  2151. * @return The CSS string for slide width or height.
  2152. */
  2153. function cssSlideSize() {
  2154. var gap = unit(options.gap);
  2155. return "calc((100%" + (gap && " + " + gap) + ")/" + (options.perPage || 1) + (gap && " - " + gap) + ")";
  2156. }
  2157. /**
  2158. * Returns the list width for the horizontal slider, or the height for the vertical slider.
  2159. *
  2160. * @return The size of the track element in pixel.
  2161. */
  2162. function listSize() {
  2163. return rect(list)[resolve('width')];
  2164. }
  2165. /**
  2166. * Returns the slide width for the horizontal slider, or the height for the vertical slider.
  2167. *
  2168. * @param index - Optional. A slide index.
  2169. * @param withoutGap - Optional. Determines whether to exclude the gap amount or not.
  2170. *
  2171. * @return The size of the specified slide element in pixel.
  2172. */
  2173. function slideSize(index, withoutGap) {
  2174. var Slide = getAt(index || 0);
  2175. return Slide ? rect(Slide.slide)[resolve('width')] + (withoutGap ? 0 : getGap()) : 0;
  2176. }
  2177. /**
  2178. * Returns the total width or height of slides from 0 to the specified index.
  2179. *
  2180. * @param index - A slide index. If omitted, uses the last index.
  2181. * @param withoutGap - Optional. Determines whether to exclude the last gap or not.
  2182. *
  2183. * @return The total width of slides in the horizontal slider, or the height in the vertical one.
  2184. */
  2185. function totalSize(index, withoutGap) {
  2186. var Slide = getAt(index);
  2187. if (Slide) {
  2188. var right = rect(Slide.slide)[resolve('right')];
  2189. var left = rect(list)[resolve('left')];
  2190. return abs(right - left) + (withoutGap ? 0 : getGap());
  2191. }
  2192. return 0;
  2193. }
  2194. /**
  2195. * Returns the slider size without clones.
  2196. *
  2197. * @return The slider size.
  2198. */
  2199. function sliderSize() {
  2200. var firstSlide = getAt(0);
  2201. var lastSlide = getAt(Slides.getLength(true) - 1);
  2202. if (firstSlide && lastSlide) {
  2203. return rect(lastSlide.slide)[resolve('right')] - rect(firstSlide.slide)[resolve('left')];
  2204. }
  2205. return 0;
  2206. }
  2207. /**
  2208. * Returns the gap value.
  2209. *
  2210. *
  2211. * @return The gap value in pixel.
  2212. */
  2213. function getGap() {
  2214. var Slide = getAt(0);
  2215. return Slide ? parseFloat(style(Slide.slide, resolve('marginRight'))) || 0 : 0;
  2216. }
  2217. /**
  2218. * Returns the padding value.
  2219. *
  2220. * @param right - Determines whether to get `paddingRight/Bottom` or `paddingLeft/Top`.
  2221. *
  2222. * @return The padding value in pixel.
  2223. */
  2224. function getPadding(right) {
  2225. return parseFloat(style(track, resolve("padding" + (right ? 'Right' : 'Left'), true))) || 0;
  2226. }
  2227. return {
  2228. mount: mount,
  2229. listSize: listSize,
  2230. slideSize: slideSize,
  2231. sliderSize: sliderSize,
  2232. totalSize: totalSize,
  2233. getPadding: getPadding
  2234. };
  2235. }
  2236. /**
  2237. * The component for moving the slider.
  2238. *
  2239. * @since 3.0.0
  2240. *
  2241. * @param Splide - A Splide instance.
  2242. * @param Components - A collection of components.
  2243. * @param options - Options.
  2244. *
  2245. * @return A Move component object.
  2246. */
  2247. function Move(Splide, Components, options) {
  2248. var _EventInterface6 = EventInterface(Splide),
  2249. on = _EventInterface6.on,
  2250. emit = _EventInterface6.emit;
  2251. var _Components$Layout = Components.Layout,
  2252. slideSize = _Components$Layout.slideSize,
  2253. getPadding = _Components$Layout.getPadding,
  2254. totalSize = _Components$Layout.totalSize,
  2255. listSize = _Components$Layout.listSize,
  2256. sliderSize = _Components$Layout.sliderSize;
  2257. var _Components$Direction = Components.Direction,
  2258. resolve = _Components$Direction.resolve,
  2259. orient = _Components$Direction.orient;
  2260. var _Components$Elements3 = Components.Elements,
  2261. list = _Components$Elements3.list,
  2262. track = _Components$Elements3.track;
  2263. /**
  2264. * Indicates whether the slider is just looping or not.
  2265. */
  2266. var looping;
  2267. /**
  2268. * Indicates whether the component can move the slider or not.
  2269. */
  2270. var waiting;
  2271. /**
  2272. * Keeps the current position.
  2273. */
  2274. var currPosition = 0;
  2275. /**
  2276. * Keeps the rate of position to the slider width.
  2277. */
  2278. var positionRate = 0;
  2279. /**
  2280. * Called when the component is mounted.
  2281. */
  2282. function mount() {
  2283. on([EVENT_RESIZE, EVENT_UPDATED, EVENT_REFRESH], reposition);
  2284. }
  2285. /**
  2286. * Repositions the slider.
  2287. */
  2288. function reposition() {
  2289. if (options.drag !== 'free') {
  2290. jump(Splide.index);
  2291. } else {
  2292. if (!options[resolve('fixedWidth')] && !options[resolve('autoWidth')]) {
  2293. translate(listSize() * positionRate);
  2294. }
  2295. if (isExceededMax(currPosition)) {
  2296. translate(getLimit(true));
  2297. }
  2298. }
  2299. }
  2300. /**
  2301. * Goes to the slide at the specified index with the Transition component.
  2302. *
  2303. * @param dest - A destination index to go to.
  2304. * @param index - A slide index.
  2305. * @param prev - A previous index.
  2306. */
  2307. function move(dest, index, prev) {
  2308. if (!isBusy()) {
  2309. var position = getPosition();
  2310. looping = dest !== index;
  2311. waiting = options.waitForTransition;
  2312. Splide.state.set(MOVING);
  2313. emit(EVENT_MOVE, index, prev, dest);
  2314. Components.Transition.start(dest, function () {
  2315. onMoved(dest, index, prev, position);
  2316. });
  2317. }
  2318. }
  2319. /**
  2320. * Called after the transition ends.
  2321. *
  2322. * @param dest - A destination index to go to.
  2323. * @param index - A slide index.
  2324. * @param prev - A previous index.
  2325. * @param oldPosition - An old position.
  2326. */
  2327. function onMoved(dest, index, prev, oldPosition) {
  2328. if (looping) {
  2329. jump(index);
  2330. looping = false;
  2331. }
  2332. waiting = false;
  2333. Splide.state.set(IDLE);
  2334. emit(EVENT_MOVED, index, prev, dest);
  2335. if (options.trimSpace === 'move' && dest !== prev && oldPosition === getPosition()) {
  2336. Components.Controller.go(dest > prev ? '>' : '<');
  2337. }
  2338. }
  2339. /**
  2340. * Jumps to the slide at the specified index.
  2341. *
  2342. * @param index - An index to jump to.
  2343. */
  2344. function jump(index) {
  2345. translate(toPosition(index, true));
  2346. }
  2347. /**
  2348. * Moves the slider to the specified position.
  2349. *
  2350. * @param position - The destination.
  2351. */
  2352. function translate(position) {
  2353. currPosition = loop(position);
  2354. positionRate = currPosition / listSize();
  2355. Components.Style.ruleBy(list, 'transform', "translate" + resolve('X') + "(" + currPosition + "px)");
  2356. }
  2357. /**
  2358. * Loops the provided position if it exceeds limits.
  2359. *
  2360. * @param position - A position to loop.
  2361. */
  2362. function loop(position) {
  2363. if (!looping && Splide.is(LOOP)) {
  2364. var diff = position - currPosition;
  2365. var exceededMin = isExceededMin(position);
  2366. var exceededMax = isExceededMax(position);
  2367. if (exceededMin && diff > 0 || exceededMax && diff < 0) {
  2368. position += orient(sliderSize() * (exceededMin ? 1 : -1));
  2369. }
  2370. }
  2371. return position;
  2372. }
  2373. /**
  2374. * Cancels transition.
  2375. */
  2376. function cancel() {
  2377. translate(getPosition());
  2378. Components.Transition.cancel();
  2379. }
  2380. /**
  2381. * Returns the closest index to the position.
  2382. *
  2383. * @param position - A position to convert.
  2384. *
  2385. * @return The closest index to the position.
  2386. */
  2387. function toIndex(position) {
  2388. var Slides = Components.Slides.get();
  2389. var index = 0;
  2390. var minDistance = Infinity;
  2391. for (var i = 0; i < Slides.length; i++) {
  2392. var slideIndex = Slides[i].index;
  2393. var distance = abs(toPosition(slideIndex) - position);
  2394. if (distance < minDistance) {
  2395. minDistance = distance;
  2396. index = slideIndex;
  2397. } else {
  2398. break;
  2399. }
  2400. }
  2401. return index;
  2402. }
  2403. /**
  2404. * Converts the slide index to the position.
  2405. *
  2406. * @param index - An index to convert.
  2407. * @param trimming - Optional. Whether to trim edge spaces or not.
  2408. *
  2409. * @return The position corresponding with the index.
  2410. */
  2411. function toPosition(index, trimming) {
  2412. var position = orient(totalSize(index - 1) - offset(index));
  2413. return trimming ? trim(position) : position;
  2414. }
  2415. /**
  2416. * Returns the current position.
  2417. *
  2418. * @return The position of the list element.
  2419. */
  2420. function getPosition() {
  2421. var left = resolve('left');
  2422. return rect(list)[left] - rect(track)[left] + orient(getPadding(false));
  2423. }
  2424. /**
  2425. * Trims spaces on the edge of the slider.
  2426. *
  2427. * @param position - A position to trim.
  2428. *
  2429. * @return A trimmed position.
  2430. */
  2431. function trim(position) {
  2432. if (options.trimSpace && Splide.is(SLIDE)) {
  2433. position = clamp(position, 0, orient(sliderSize() - listSize()));
  2434. }
  2435. return position;
  2436. }
  2437. /**
  2438. * Returns the offset amount.
  2439. *
  2440. * @param index - An index.
  2441. */
  2442. function offset(index) {
  2443. var focus = options.focus;
  2444. if (focus === 'center') {
  2445. return (listSize() - slideSize(index, true)) / 2;
  2446. }
  2447. return (+focus || 0) * slideSize(index);
  2448. }
  2449. /**
  2450. * Returns the limit number that the slider can move to.
  2451. *
  2452. * @param max - Determines whether to return the maximum or minimum limit.
  2453. *
  2454. * @return The border number.
  2455. */
  2456. function getLimit(max) {
  2457. var trimming = !!options.trimSpace;
  2458. return max ? toPosition(Components.Controller.getEnd(), trimming) : toPosition(0, trimming);
  2459. }
  2460. /**
  2461. * Checks if the slider can move now or not.
  2462. *
  2463. * @return `true` if the slider can move, or otherwise `false`.
  2464. */
  2465. function isBusy() {
  2466. return !!(looping || waiting);
  2467. }
  2468. /**
  2469. * Checks if the provided position exceeds the minimum limit or not.
  2470. *
  2471. * @param position - A position to test.
  2472. * @param offset - Optional. Offsets the limit in pixel.
  2473. *
  2474. * @return `true` if the position exceeds the limit, or otherwise `false`.
  2475. */
  2476. function isExceededMin(position, offset) {
  2477. return orient(position) + (offset || 0) < orient(getLimit(false));
  2478. }
  2479. /**
  2480. * Checks if the provided position exceeds the maximum limit or not.
  2481. *
  2482. * @param position - A position to test.
  2483. * @param offset - Optional. Offsets the limit in pixel.
  2484. *
  2485. * @return `true` if the position exceeds the limit, or otherwise `false`.
  2486. */
  2487. function isExceededMax(position, offset) {
  2488. return orient(position) + (offset || 0) > orient(getLimit(true));
  2489. }
  2490. /**
  2491. * Checks if the slider position exceeds borders or not.
  2492. *
  2493. * @return `true` if the position is over borders, or otherwise `false`.
  2494. */
  2495. function isExceeded() {
  2496. return isExceededMin(currPosition) || isExceededMax(currPosition);
  2497. }
  2498. return {
  2499. mount: mount,
  2500. move: move,
  2501. jump: jump,
  2502. translate: translate,
  2503. cancel: cancel,
  2504. toIndex: toIndex,
  2505. toPosition: toPosition,
  2506. getPosition: getPosition,
  2507. getLimit: getLimit,
  2508. isBusy: isBusy,
  2509. isExceededMin: isExceededMin,
  2510. isExceededMax: isExceededMax,
  2511. isExceeded: isExceeded
  2512. };
  2513. }
  2514. /**
  2515. * The component for controlling the slider.
  2516. *
  2517. * @since 3.0.0
  2518. *
  2519. * @param Splide - A Splide instance.
  2520. * @param Components - A collection of components.
  2521. * @param options - Options.
  2522. *
  2523. * @return A Controller component object.
  2524. */
  2525. function Controller(Splide, Components, options) {
  2526. var _EventInterface7 = EventInterface(Splide),
  2527. on = _EventInterface7.on;
  2528. var Move = Components.Move;
  2529. var _Components$Slides = Components.Slides,
  2530. isEnough = _Components$Slides.isEnough,
  2531. getLength = _Components$Slides.getLength;
  2532. var isLoop = Splide.is(LOOP);
  2533. /**
  2534. * The current index.
  2535. */
  2536. var currIndex = options.start || 0;
  2537. /**
  2538. * The previous index.
  2539. */
  2540. var prevIndex = currIndex;
  2541. /**
  2542. * The latest number of slides.
  2543. */
  2544. var slideCount;
  2545. /**
  2546. * The latest `perMove` value.
  2547. */
  2548. var perMove;
  2549. /**
  2550. * The latest `perMove` value.
  2551. */
  2552. var perPage;
  2553. /**
  2554. * Called when the component is mounted.
  2555. */
  2556. function mount() {
  2557. init();
  2558. Move.jump(currIndex);
  2559. on([EVENT_UPDATED, EVENT_REFRESH], init);
  2560. on(EVENT_SCROLLED, function () {
  2561. setIndex(Move.toIndex(Move.getPosition()));
  2562. }, 0);
  2563. }
  2564. /**
  2565. * Initializes the component.
  2566. */
  2567. function init() {
  2568. slideCount = getLength(true);
  2569. perMove = options.perMove;
  2570. perPage = options.perPage;
  2571. }
  2572. /**
  2573. * Moves the slider by the control pattern.
  2574. *
  2575. * @see `Splide#go()`
  2576. *
  2577. * @param control - A control pattern.
  2578. * @param allowSameIndex - Optional. Determines whether to allow to go to the current index or not.
  2579. */
  2580. function go(control, allowSameIndex) {
  2581. var dest = parse(control);
  2582. var index = loop(dest);
  2583. if (index > -1 && !Move.isBusy() && (allowSameIndex || index !== currIndex)) {
  2584. setIndex(index);
  2585. Move.move(dest, index, prevIndex);
  2586. }
  2587. }
  2588. /**
  2589. * Parses the control and returns a slide index.
  2590. *
  2591. * @param control - A control pattern to parse.
  2592. */
  2593. function parse(control) {
  2594. var index = currIndex;
  2595. if (isString(control)) {
  2596. var _ref = control.match(/([+\-<>])(\d+)?/) || [],
  2597. indicator = _ref[1],
  2598. number = _ref[2];
  2599. if (indicator === '+' || indicator === '-') {
  2600. index = computeDestIndex(currIndex + +("" + indicator + (+number || 1)), currIndex, true);
  2601. } else if (indicator === '>') {
  2602. index = number ? toIndex(+number) : getNext(true);
  2603. } else if (indicator === '<') {
  2604. index = getPrev(true);
  2605. }
  2606. } else {
  2607. if (isLoop) {
  2608. index = clamp(control, -perPage, slideCount + perPage - 1);
  2609. } else {
  2610. index = clamp(control, 0, getEnd());
  2611. }
  2612. }
  2613. return index;
  2614. }
  2615. /**
  2616. * Returns a next destination index.
  2617. *
  2618. * @param destination - Optional. Determines whether to get a destination index or a slide one.
  2619. *
  2620. * @return A next index if available, or otherwise `-1`.
  2621. */
  2622. function getNext(destination) {
  2623. return getAdjacent(false, destination);
  2624. }
  2625. /**
  2626. * Returns a previous destination index.
  2627. *
  2628. * @param destination - Optional. Determines whether to get a destination index or a slide one.
  2629. *
  2630. * @return A previous index if available, or otherwise `-1`.
  2631. */
  2632. function getPrev(destination) {
  2633. return getAdjacent(true, destination);
  2634. }
  2635. /**
  2636. * Returns an adjacent destination index.
  2637. *
  2638. * @param prev - Determines whether to return a previous or next index.
  2639. * @param destination - Optional. Determines whether to get a destination index or a slide one.
  2640. *
  2641. * @return An adjacent index if available, or otherwise `-1`.
  2642. */
  2643. function getAdjacent(prev, destination) {
  2644. var dest = computeDestIndex(currIndex + getPerMove() * (prev ? -1 : 1), currIndex);
  2645. return destination ? dest : loop(dest);
  2646. }
  2647. /**
  2648. * Converts the desired destination index to the valid one.
  2649. * - This may return clone indices if the editor is the loop mode,
  2650. * or `-1` if there is no slide to go.
  2651. * - There are still slides where the slider can go if borders are between `from` and `dest`.
  2652. *
  2653. * @param dest - The desired destination.
  2654. * @param from - A base index.
  2655. * @param incremental - Optional. Whether the control is incremental or not.
  2656. *
  2657. * @return A converted destination index, including clones.
  2658. */
  2659. function computeDestIndex(dest, from, incremental) {
  2660. if (isEnough()) {
  2661. var end = getEnd(); // Will overrun:
  2662. if (dest < 0 || dest > end) {
  2663. if (between(0, dest, from, true) || between(end, from, dest, true)) {
  2664. dest = toIndex(toPage(dest));
  2665. } else {
  2666. if (isLoop) {
  2667. dest = perMove ? dest : dest < 0 ? -(slideCount % perPage || perPage) : slideCount;
  2668. } else if (options.rewind) {
  2669. dest = dest < 0 ? end : 0;
  2670. } else {
  2671. dest = -1;
  2672. }
  2673. }
  2674. } else {
  2675. if (!isLoop && !incremental && dest !== from) {
  2676. dest = toIndex(toPage(from) + (dest < from ? -1 : 1));
  2677. }
  2678. }
  2679. } else {
  2680. dest = -1;
  2681. }
  2682. return dest;
  2683. }
  2684. /**
  2685. * Returns the end index where the slider can go.
  2686. * For example, if the slider has 10 slides and the `perPage` option is 3,
  2687. * the slider can go to the slide 8 (the index is 7).
  2688. *
  2689. * @return An end index.
  2690. */
  2691. function getEnd() {
  2692. var end = slideCount - perPage;
  2693. if (hasFocus() || isLoop && perMove) {
  2694. end = slideCount - 1;
  2695. }
  2696. return max(end, 0);
  2697. }
  2698. /**
  2699. * Loops the provided index only in the loop mode.
  2700. *
  2701. * @param index - An index to loop.
  2702. *
  2703. * @return A looped index.
  2704. */
  2705. function loop(index) {
  2706. if (isLoop) {
  2707. return isEnough() ? index % slideCount + (index < 0 ? slideCount : 0) : -1;
  2708. }
  2709. return index;
  2710. }
  2711. /**
  2712. * Converts the page index to the slide index.
  2713. *
  2714. * @param page - A page index to convert.
  2715. *
  2716. * @return A slide index.
  2717. */
  2718. function toIndex(page) {
  2719. return clamp(hasFocus() ? page : perPage * page, 0, getEnd());
  2720. }
  2721. /**
  2722. * Converts the slide index to the page index.
  2723. *
  2724. * @param index - An index to convert.
  2725. */
  2726. function toPage(index) {
  2727. if (!hasFocus()) {
  2728. index = between(index, slideCount - perPage, slideCount - 1) ? slideCount - 1 : index;
  2729. index = floor(index / perPage);
  2730. }
  2731. return index;
  2732. }
  2733. /**
  2734. * Returns the number of slides to move for '>' and '<'.
  2735. *
  2736. * @return The number of slides to move.
  2737. */
  2738. function getPerMove() {
  2739. return perMove || hasFocus() ? 1 : perPage;
  2740. }
  2741. /**
  2742. * Sets a new index and retains old one.
  2743. *
  2744. * @param index - A new index to set.
  2745. */
  2746. function setIndex(index) {
  2747. if (index !== currIndex) {
  2748. prevIndex = currIndex;
  2749. currIndex = index;
  2750. }
  2751. }
  2752. /**
  2753. * Returns the current/previous index slide index.
  2754. *
  2755. * @param prev - Optional. Whether to return previous index or not.
  2756. */
  2757. function getIndex(prev) {
  2758. return prev ? prevIndex : currIndex;
  2759. }
  2760. /**
  2761. * Verifies if the focus option is available or not.
  2762. *
  2763. * @return `true` if the slider has the focus option.
  2764. */
  2765. function hasFocus() {
  2766. return !isUndefined(options.focus) || options.isNavigation;
  2767. }
  2768. return {
  2769. mount: mount,
  2770. go: go,
  2771. getNext: getNext,
  2772. getPrev: getPrev,
  2773. getEnd: getEnd,
  2774. setIndex: setIndex,
  2775. getIndex: getIndex,
  2776. toIndex: toIndex,
  2777. toPage: toPage,
  2778. hasFocus: hasFocus
  2779. };
  2780. }
  2781. /**
  2782. * The namespace for SVG elements.
  2783. */
  2784. var XML_NAME_SPACE = 'http://www.w3.org/2000/svg';
  2785. /**
  2786. * The arrow path.
  2787. */
  2788. var PATH = 'm15.5 0.932-4.3 4.38 14.5 14.6-14.5 14.5 4.3 4.4 14.6-14.6 4.4-4.3-4.4-4.4-14.6-14.6z';
  2789. /**
  2790. * SVG width and height.
  2791. */
  2792. var SIZE = 40;
  2793. /**
  2794. * The component for handling previous and next arrows.
  2795. *
  2796. * @since 3.0.0
  2797. *
  2798. * @param Splide - A Splide instance.
  2799. * @param Components - A collection of components.
  2800. * @param options - Options.
  2801. *
  2802. * @return An Arrows component object.
  2803. */
  2804. function Arrows(Splide, Components, options) {
  2805. var _EventInterface8 = EventInterface(Splide),
  2806. on = _EventInterface8.on,
  2807. bind = _EventInterface8.bind,
  2808. emit = _EventInterface8.emit;
  2809. var classes = options.classes,
  2810. i18n = options.i18n;
  2811. var Elements = Components.Elements,
  2812. Controller = Components.Controller;
  2813. var slider = Elements.slider,
  2814. track = Elements.track;
  2815. /**
  2816. * The wrapper element.
  2817. */
  2818. var wrapper = Elements.arrows;
  2819. /**
  2820. * The previous arrow element.
  2821. */
  2822. var prev = Elements.prev;
  2823. /**
  2824. * The next arrow element.
  2825. */
  2826. var next = Elements.next;
  2827. /**
  2828. * Indicates whether the component creates arrows or retrieved from the DOM.
  2829. */
  2830. var created;
  2831. /**
  2832. * An object with previous and next arrows.
  2833. */
  2834. var arrows = {};
  2835. /**
  2836. * Called when the component is mounted.
  2837. */
  2838. function mount() {
  2839. init();
  2840. on(EVENT_UPDATED, init);
  2841. }
  2842. /**
  2843. * Initializes the component.
  2844. */
  2845. function init() {
  2846. if (options.arrows) {
  2847. if (!prev || !next) {
  2848. createArrows();
  2849. }
  2850. }
  2851. if (prev && next) {
  2852. if (!arrows.prev) {
  2853. setAttribute(prev, ARIA_CONTROLS, track.id);
  2854. setAttribute(next, ARIA_CONTROLS, track.id);
  2855. arrows.prev = prev;
  2856. arrows.next = next;
  2857. listen();
  2858. emit(EVENT_ARROWS_MOUNTED, prev, next);
  2859. } else {
  2860. display(wrapper, options.arrows === false ? 'none' : '');
  2861. }
  2862. }
  2863. }
  2864. /**
  2865. * Destroys the component.
  2866. */
  2867. function destroy() {
  2868. if (created) {
  2869. remove(wrapper);
  2870. } else {
  2871. removeAttribute(prev, ALL_ATTRIBUTES);
  2872. removeAttribute(next, ALL_ATTRIBUTES);
  2873. }
  2874. }
  2875. /**
  2876. * Listens to some events.
  2877. */
  2878. function listen() {
  2879. var go = Controller.go;
  2880. on([EVENT_MOUNTED, EVENT_MOVE, EVENT_UPDATED, EVENT_REFRESH, EVENT_SCROLLED], update);
  2881. bind(next, 'click', function () {
  2882. go('>');
  2883. });
  2884. bind(prev, 'click', function () {
  2885. go('<');
  2886. });
  2887. }
  2888. /**
  2889. * Create arrows and append them to the slider.
  2890. */
  2891. function createArrows() {
  2892. var parent = options.arrows === 'slider' && slider ? slider : Splide.root;
  2893. wrapper = create('div', classes.arrows);
  2894. prev = createArrow(true);
  2895. next = createArrow(false);
  2896. created = true;
  2897. append(wrapper, [prev, next]);
  2898. before(wrapper, child(parent));
  2899. }
  2900. /**
  2901. * Creates an arrow button.
  2902. *
  2903. * @param prev - Determines whether to create a previous or next arrow.
  2904. *
  2905. * @return A created button element.
  2906. */
  2907. function createArrow(prev) {
  2908. var arrow = "<button class=\"" + classes.arrow + " " + (prev ? classes.prev : classes.next) + "\" type=\"button\">" + ("<svg xmlns=\"" + XML_NAME_SPACE + "\" viewBox=\"0 0 " + SIZE + " " + SIZE + "\" width=\"" + SIZE + "\" height=\"" + SIZE + "\">") + ("<path d=\"" + (options.arrowPath || PATH) + "\" />");
  2909. return parseHtml(arrow);
  2910. }
  2911. /**
  2912. * Updates status of arrows, such as `disabled` and `aria-label`.
  2913. */
  2914. function update() {
  2915. var index = Splide.index;
  2916. var prevIndex = Controller.getPrev();
  2917. var nextIndex = Controller.getNext();
  2918. var prevLabel = prevIndex > -1 && index < prevIndex ? i18n.last : i18n.prev;
  2919. var nextLabel = nextIndex > -1 && index > nextIndex ? i18n.first : i18n.next;
  2920. prev.disabled = prevIndex < 0;
  2921. next.disabled = nextIndex < 0;
  2922. setAttribute(prev, ARIA_LABEL, prevLabel);
  2923. setAttribute(next, ARIA_LABEL, nextLabel);
  2924. emit(EVENT_ARROWS_UPDATED, prev, next, prevIndex, nextIndex);
  2925. }
  2926. return {
  2927. arrows: arrows,
  2928. mount: mount,
  2929. destroy: destroy
  2930. };
  2931. }
  2932. /**
  2933. * The component for auto playing sliders.
  2934. *
  2935. * @since 3.0.0
  2936. *
  2937. * @param Splide - A Splide instance.
  2938. * @param Components - A collection of components.
  2939. * @param options - Options.
  2940. *
  2941. * @return An Autoplay component object.
  2942. */
  2943. function Autoplay(Splide, Components, options) {
  2944. var _EventInterface9 = EventInterface(Splide),
  2945. on = _EventInterface9.on,
  2946. bind = _EventInterface9.bind,
  2947. emit = _EventInterface9.emit;
  2948. var _Components$Elements4 = Components.Elements,
  2949. root = _Components$Elements4.root,
  2950. track = _Components$Elements4.track,
  2951. bar = _Components$Elements4.bar,
  2952. playButton = _Components$Elements4.play,
  2953. pauseButton = _Components$Elements4.pause;
  2954. var interval = RequestInterval(options.interval, Splide.go.bind(Splide, '>'), update);
  2955. var isPaused = interval.isPaused;
  2956. /**
  2957. * Indicates whether the slider is hovered or not.
  2958. */
  2959. var hovered;
  2960. /**
  2961. * Indicates whether one of slider elements has focus or not.
  2962. */
  2963. var focused;
  2964. /**
  2965. * Turns into `true` when autoplay is manually paused.
  2966. */
  2967. var paused;
  2968. /**
  2969. * Called when the component is mounted.
  2970. */
  2971. function mount() {
  2972. var autoplay = options.autoplay;
  2973. if (autoplay) {
  2974. initButton(true);
  2975. initButton(false);
  2976. listen();
  2977. if (autoplay !== 'pause') {
  2978. play();
  2979. }
  2980. }
  2981. }
  2982. /**
  2983. * Initializes a play/pause button.
  2984. *
  2985. * @param forPause - Determines whether to initialize a pause or play button.
  2986. */
  2987. function initButton(forPause) {
  2988. var button = forPause ? pauseButton : playButton;
  2989. if (button) {
  2990. if (!isHTMLButtonElement(button)) {
  2991. setAttribute(button, ROLE, 'button');
  2992. }
  2993. setAttribute(button, ARIA_CONTROLS, track.id);
  2994. setAttribute(button, ARIA_LABEL, options.i18n[forPause ? 'pause' : 'play']);
  2995. bind(button, 'click', forPause ? pause : play);
  2996. }
  2997. }
  2998. /**
  2999. * Listens to some events.
  3000. */
  3001. function listen() {
  3002. if (options.pauseOnHover) {
  3003. bind(root, 'mouseenter mouseleave', function (e) {
  3004. hovered = e.type === 'mouseenter';
  3005. autoToggle();
  3006. });
  3007. }
  3008. if (options.pauseOnFocus) {
  3009. bind(root, 'focusin focusout', function (e) {
  3010. focused = e.type === 'focusin';
  3011. autoToggle();
  3012. });
  3013. }
  3014. on([EVENT_MOVE, EVENT_SCROLL, EVENT_REFRESH], interval.rewind);
  3015. }
  3016. /**
  3017. * Starts autoplay and clears all flags.
  3018. */
  3019. function play() {
  3020. if (isPaused() && Components.Slides.isEnough()) {
  3021. interval.start(!options.resetProgress);
  3022. focused = false;
  3023. hovered = false;
  3024. emit(EVENT_AUTOPLAY_PLAY);
  3025. }
  3026. }
  3027. /**
  3028. * Pauses autoplay.
  3029. *
  3030. * @param manual - If `true`, autoplay keeps paused until `play()` is explicitly called.
  3031. */
  3032. function pause(manual) {
  3033. if (manual === void 0) {
  3034. manual = true;
  3035. }
  3036. if (!isPaused()) {
  3037. interval.pause();
  3038. emit(EVENT_AUTOPLAY_PAUSE);
  3039. }
  3040. paused = manual;
  3041. }
  3042. /**
  3043. * Toggles play/pause according to current flags.
  3044. * If autoplay is manually paused, this will do nothing.
  3045. */
  3046. function autoToggle() {
  3047. if (!paused) {
  3048. if (!hovered && !focused) {
  3049. play();
  3050. } else {
  3051. pause(false);
  3052. }
  3053. }
  3054. }
  3055. /**
  3056. * Called on every animation frame when auto playing.
  3057. *
  3058. * @param rate - The progress rate between 0 to 1.
  3059. */
  3060. function update(rate) {
  3061. emit(EVENT_AUTOPLAY_PLAYING, rate);
  3062. if (bar) {
  3063. style(bar, {
  3064. width: rate * 100 + "%"
  3065. });
  3066. }
  3067. }
  3068. return {
  3069. mount: mount,
  3070. destroy: interval.cancel,
  3071. play: play,
  3072. pause: pause,
  3073. isPaused: isPaused
  3074. };
  3075. }
  3076. /**
  3077. * The component for setting the image as the slide background.
  3078. *
  3079. * @since 3.0.0
  3080. *
  3081. * @param Splide - A Splide instance.
  3082. * @param Components - A collection of components.
  3083. * @param options - Options.
  3084. *
  3085. * @return A Cover component object.
  3086. */
  3087. function Cover(Splide, Components, options) {
  3088. var _EventInterface10 = EventInterface(Splide),
  3089. on = _EventInterface10.on;
  3090. /**
  3091. * Called when the component is mounted.
  3092. */
  3093. function mount() {
  3094. if (options.cover) {
  3095. on(EVENT_LAZYLOAD_LOADED, function (img, Slide) {
  3096. toggle(true, img, Slide);
  3097. });
  3098. on([EVENT_MOUNTED, EVENT_UPDATED, EVENT_REFRESH], apply.bind(null, true));
  3099. }
  3100. }
  3101. /**
  3102. * Destroys the component.
  3103. */
  3104. function destroy() {
  3105. apply(false);
  3106. }
  3107. /**
  3108. * Sets/removes the background image to/from all slides.
  3109. *
  3110. * @param cover - If `false`, removes the background image.
  3111. */
  3112. function apply(cover) {
  3113. Components.Slides.forEach(function (Slide) {
  3114. var img = child(Slide.container || Slide.slide, 'img');
  3115. if (img && img.src) {
  3116. toggle(cover, img, Slide);
  3117. }
  3118. });
  3119. }
  3120. /**
  3121. * Sets/removes the background image to/from the parent element.
  3122. *
  3123. * @param cover - If `false`, removes the background image.
  3124. * @param img - A target image element.
  3125. * @param Slide - A SlideComponent object where the image belongs.
  3126. */
  3127. function toggle(cover, img, Slide) {
  3128. Slide.rule('background', cover ? "center/cover no-repeat url(\"" + img.src + "\")" : '', true);
  3129. display(img, cover ? 'none' : '');
  3130. }
  3131. return {
  3132. mount: mount,
  3133. destroy: destroy
  3134. };
  3135. }
  3136. /**
  3137. * Triggers the bounce effect when the diff becomes less than this value.
  3138. *
  3139. * @since 3.0.0
  3140. */
  3141. var BOUNCE_DIFF_THRESHOLD = 10;
  3142. /**
  3143. * The duration of the bounce effect.
  3144. *
  3145. * @since 3.0.0
  3146. */
  3147. var BOUNCE_DURATION = 600;
  3148. /**
  3149. * The friction factor.
  3150. *
  3151. * @since 3.0.0
  3152. */
  3153. var FRICTION_FACTOR = 0.6;
  3154. /**
  3155. * The velocity to calculate the scroll duration.
  3156. *
  3157. * @since 3.0.0
  3158. */
  3159. var BASE_VELOCITY = 1.2;
  3160. /**
  3161. * The minimum duration of scroll.
  3162. *
  3163. * @since 3.0.0
  3164. */
  3165. var MIN_DURATION = 800;
  3166. /**
  3167. * The component for scrolling the slider.
  3168. *
  3169. * @since 3.0.0
  3170. *
  3171. * @param Splide - A Splide instance.
  3172. * @param Components - A collection of components.
  3173. * @param options - Options.
  3174. *
  3175. * @return A Scroll component object.
  3176. */
  3177. function Scroll(Splide, Components, options) {
  3178. var _EventInterface11 = EventInterface(Splide),
  3179. on = _EventInterface11.on,
  3180. emit = _EventInterface11.emit;
  3181. var Move = Components.Move;
  3182. var getPosition = Move.getPosition,
  3183. getLimit = Move.getLimit;
  3184. /**
  3185. * Retains the active RequestInterval object.
  3186. */
  3187. var interval;
  3188. /**
  3189. * Called when the component is mounted.
  3190. */
  3191. function mount() {
  3192. on(EVENT_MOVE, clear);
  3193. on([EVENT_UPDATED, EVENT_REFRESH], cancel);
  3194. }
  3195. /**
  3196. * Scrolls the slider to the provided destination.
  3197. *
  3198. * @param destination - The destination to scroll to.
  3199. * @param duration - Optional. The scroll duration. If omitted, calculates it by the distance.
  3200. * @param suppressConstraint - Optional. Whether to suppress constraint process when the slider exceeds bounds.
  3201. */
  3202. function scroll(destination, duration, suppressConstraint) {
  3203. var start = getPosition();
  3204. var friction = 1;
  3205. duration = duration || computeDuration(abs(destination - start));
  3206. clear();
  3207. interval = RequestInterval(duration, onScrolled, function (rate) {
  3208. var position = getPosition();
  3209. var target = start + (destination - start) * easing(rate);
  3210. var diff = (target - getPosition()) * friction;
  3211. Move.translate(position + diff);
  3212. if (Splide.is(SLIDE) && !suppressConstraint && Move.isExceeded()) {
  3213. friction *= FRICTION_FACTOR;
  3214. if (abs(diff) < BOUNCE_DIFF_THRESHOLD) {
  3215. bounce(Move.isExceededMin(getPosition()));
  3216. }
  3217. }
  3218. }, 1);
  3219. emit(EVENT_SCROLL);
  3220. interval.start();
  3221. }
  3222. /**
  3223. * Triggers the bounce effect when the slider reaches bounds.
  3224. *
  3225. * @param backwards - The direction the slider is going towards.
  3226. */
  3227. function bounce(backwards) {
  3228. scroll(getLimit(!backwards), BOUNCE_DURATION, true);
  3229. }
  3230. /**
  3231. * Called when scroll ends or is canceled.
  3232. */
  3233. function onScrolled() {
  3234. emit(EVENT_SCROLLED);
  3235. }
  3236. /**
  3237. * Computes the scroll duration by the distance and the base velocity.
  3238. *
  3239. * @param distance - Distance in pixel.
  3240. *
  3241. * @return The duration for scroll.
  3242. */
  3243. function computeDuration(distance) {
  3244. return max(distance / BASE_VELOCITY, MIN_DURATION);
  3245. }
  3246. /**
  3247. * Clears the active interval.
  3248. */
  3249. function clear() {
  3250. if (interval) {
  3251. interval.cancel();
  3252. }
  3253. }
  3254. /**
  3255. * Cancels the active interval and emits the `scrolled` event.
  3256. */
  3257. function cancel() {
  3258. if (interval && !interval.isPaused()) {
  3259. clear();
  3260. onScrolled();
  3261. }
  3262. }
  3263. /**
  3264. * The easing function.
  3265. *
  3266. * @param t - A value to ease.
  3267. *
  3268. * @return An eased value.
  3269. */
  3270. function easing(t) {
  3271. var easingFunc = options.easingFunc;
  3272. return easingFunc ? easingFunc(t) : 1 - Math.pow(1 - t, 4);
  3273. }
  3274. return {
  3275. mount: mount,
  3276. destroy: clear,
  3277. scroll: scroll,
  3278. cancel: cancel
  3279. };
  3280. }
  3281. /**
  3282. * The power of the friction.
  3283. *
  3284. * @since 3.0.0
  3285. */
  3286. var FRICTION = 5;
  3287. /**
  3288. * If the user stops dragging for this duration with keeping the pointer down, updates the base coord and time.
  3289. *
  3290. * @since 3.0.0
  3291. */
  3292. var SAMPLING_INTERVAL = 50;
  3293. /**
  3294. * Start events for dragging.
  3295. *
  3296. * @since 3.0.0
  3297. */
  3298. var POINTER_DOWN_EVENTS = 'touchstart mousedown';
  3299. /**
  3300. * Update events for dragging.
  3301. *
  3302. * @since 3.0.0
  3303. */
  3304. var POINTER_MOVE_EVENTS = 'touchmove mousemove';
  3305. /**
  3306. * End events for dragging.
  3307. *
  3308. * @since 3.0.0
  3309. */
  3310. var POINTER_UP_EVENTS = 'touchend touchcancel mouseup mouseleave';
  3311. /**
  3312. * The component for dragging the slider.
  3313. *
  3314. * @since 3.0.0
  3315. *
  3316. * @param Splide - A Splide instance.
  3317. * @param Components - A collection of components.
  3318. * @param options - Options.
  3319. *
  3320. * @return A Drag component object.
  3321. */
  3322. function Drag(Splide, Components, options) {
  3323. var _EventInterface12 = EventInterface(Splide),
  3324. emit = _EventInterface12.emit,
  3325. bind = _EventInterface12.bind,
  3326. unbind = _EventInterface12.unbind;
  3327. var track = Components.Elements.track;
  3328. var _Components$Direction2 = Components.Direction,
  3329. resolve = _Components$Direction2.resolve,
  3330. orient = _Components$Direction2.orient;
  3331. var listSize = Components.Layout.listSize;
  3332. var _Components$Controlle = Components.Controller,
  3333. go = _Components$Controlle.go,
  3334. getEnd = _Components$Controlle.getEnd;
  3335. var Move = Components.Move,
  3336. Scroll = Components.Scroll;
  3337. var translate = Move.translate,
  3338. toIndex = Move.toIndex,
  3339. getPosition = Move.getPosition,
  3340. isExceeded = Move.isExceeded;
  3341. var isSlide = Splide.is(SLIDE);
  3342. var isFade = Splide.is(FADE);
  3343. var isFree = options.drag === 'free';
  3344. /**
  3345. * The coord where a pointer becomes active.
  3346. */
  3347. var startCoord;
  3348. /**
  3349. * Keeps the last time when the component detects dragging.
  3350. */
  3351. var lastTime;
  3352. /**
  3353. * The base slider position where the diff of coords is applied.
  3354. */
  3355. var basePosition;
  3356. /**
  3357. * The base coord to calculate the diff of coords.
  3358. */
  3359. var baseCoord;
  3360. /**
  3361. * The base time when the base position and the base coord are saved.
  3362. */
  3363. var baseTime;
  3364. /**
  3365. * Keeps the last TouchEvent/MouseEvent object.
  3366. */
  3367. var lastEvent;
  3368. /**
  3369. * Indicates whether the user is dragging the slider or not.
  3370. */
  3371. var moving;
  3372. /**
  3373. * Indicates whether the user drags the slider by the mouse or not.
  3374. */
  3375. var isMouse;
  3376. /**
  3377. * The target element to attach listeners.
  3378. */
  3379. var target;
  3380. /**
  3381. * Indicates whether the slider exceeds borders or not.
  3382. */
  3383. var exceeded;
  3384. /**
  3385. * Called when the component is mounted.
  3386. */
  3387. function mount() {
  3388. if (options.drag) {
  3389. bind(track, POINTER_DOWN_EVENTS, onPointerDown);
  3390. }
  3391. }
  3392. /**
  3393. * Called when the user clicks or touches the slider.
  3394. *
  3395. * @param e - A TouchEvent or MouseEvent object
  3396. */
  3397. function onPointerDown(e) {
  3398. isMouse = e.type === 'mousedown';
  3399. target = isMouse ? window : track;
  3400. if (!(isMouse && e.button)) {
  3401. if (!Move.isBusy()) {
  3402. bind(target, POINTER_MOVE_EVENTS, onPointerMove);
  3403. bind(target, POINTER_UP_EVENTS, onPointerUp);
  3404. Move.cancel();
  3405. Scroll.cancel();
  3406. startCoord = getCoord(e);
  3407. } else {
  3408. prevent(e);
  3409. }
  3410. }
  3411. }
  3412. /**
  3413. * Called while the user moves the pointer on the slider.
  3414. *
  3415. * @param e - A TouchEvent or MouseEvent object
  3416. */
  3417. function onPointerMove(e) {
  3418. if (e.cancelable) {
  3419. var _min = options.dragMinThreshold || 15;
  3420. if (isMouse || abs(getCoord(e) - startCoord) > _min) {
  3421. moving = true;
  3422. onDrag();
  3423. }
  3424. if (moving) {
  3425. onDragging(e);
  3426. prevent(e, true);
  3427. }
  3428. } else {
  3429. onPointerUp(e);
  3430. }
  3431. }
  3432. /**
  3433. * Called when the user releases pointing devices.
  3434. * Be aware that the TouchEvent object provided by the `touchend` does not contain `Touch` objects,
  3435. * which means the last touch position is not available.
  3436. *
  3437. * @param e - A TouchEvent or MouseEvent object
  3438. */
  3439. function onPointerUp(e) {
  3440. unbind(target, POINTER_MOVE_EVENTS + " " + POINTER_UP_EVENTS);
  3441. moving = false;
  3442. if (lastEvent) {
  3443. onDragged(e);
  3444. lastEvent = null;
  3445. }
  3446. }
  3447. /**
  3448. * Called when the user starts dragging the slider.
  3449. */
  3450. function onDrag() {
  3451. bind(track, 'click', function (e) {
  3452. unbind(track, 'click');
  3453. prevent(e, true);
  3454. }, {
  3455. capture: true
  3456. });
  3457. emit(EVENT_DRAG);
  3458. }
  3459. /**
  3460. * Called while the user is dragging the slider.
  3461. *
  3462. * @param e - A TouchEvent or MouseEvent object
  3463. */
  3464. function onDragging(e) {
  3465. var timeStamp = e.timeStamp;
  3466. var expired = !lastTime || timeStamp - lastTime > SAMPLING_INTERVAL;
  3467. if (expired || isExceeded() !== exceeded) {
  3468. basePosition = getPosition();
  3469. baseCoord = getCoord(e);
  3470. baseTime = timeStamp;
  3471. }
  3472. exceeded = isExceeded();
  3473. lastTime = timeStamp;
  3474. lastEvent = e;
  3475. if (!isFade) {
  3476. translate(basePosition + constrain(getCoord(e) - baseCoord));
  3477. }
  3478. emit(EVENT_DRAGGING);
  3479. }
  3480. /**
  3481. * Called when the user finishes dragging.
  3482. *
  3483. * @param e - A TouchEvent or MouseEvent object
  3484. */
  3485. function onDragged(e) {
  3486. var velocity = computeVelocity(e);
  3487. if (isFade) {
  3488. go(Splide.index + orient(sign(velocity)));
  3489. } else {
  3490. var destination = computeDestination(velocity);
  3491. if (isFree) {
  3492. Scroll.scroll(destination);
  3493. } else {
  3494. go(computeIndex(destination), true);
  3495. }
  3496. }
  3497. lastTime = 0;
  3498. emit(EVENT_DRAGGED);
  3499. }
  3500. /**
  3501. * Computes the drag velocity.
  3502. *
  3503. * @param e - A TouchEvent or MouseEvent object
  3504. *
  3505. * @return The drag velocity.
  3506. */
  3507. function computeVelocity(e) {
  3508. if (Splide.is(LOOP) || !isExceeded()) {
  3509. var diffCoord = getCoord(lastEvent) - baseCoord;
  3510. var diffTime = lastEvent.timeStamp - baseTime;
  3511. var isFlick = e.timeStamp - lastTime < SAMPLING_INTERVAL;
  3512. if (diffTime && isFlick) {
  3513. return diffCoord / diffTime;
  3514. }
  3515. }
  3516. return 0;
  3517. }
  3518. /**
  3519. * Computes the destination by the velocity and the `flickPower` option.
  3520. *
  3521. * @param velocity - The drag velocity.
  3522. *
  3523. * @return The destination.
  3524. */
  3525. function computeDestination(velocity) {
  3526. var flickPower = options.flickPower || 600;
  3527. return getPosition() + sign(velocity) * min(abs(velocity) * flickPower, isFree ? Infinity : listSize() * (options.flickMaxPages || 1));
  3528. }
  3529. /**
  3530. * Converts the destination to the slide index.
  3531. *
  3532. * @param destination - The target destination.
  3533. *
  3534. * @return The destination index.
  3535. */
  3536. function computeIndex(destination) {
  3537. var dest = toIndex(destination);
  3538. return isSlide ? clamp(dest, 0, getEnd()) : dest;
  3539. }
  3540. /**
  3541. * Returns the `pageX` and `pageY` coordinates provided by the event.
  3542. * Be aware that IE does not support both TouchEvent and MouseEvent constructors.
  3543. *
  3544. * @param e - A TouchEvent or MouseEvent object.
  3545. *
  3546. * @return A pageX or pageY coordinate.
  3547. */
  3548. function getCoord(e) {
  3549. return (isMouse ? e : e.touches[0])[resolve('pageX')];
  3550. }
  3551. /**
  3552. * Reduces the distance to move by the predefined friction.
  3553. * This does nothing when the slider type is not `slide`, or the position is inside borders.
  3554. *
  3555. * @param diff - Diff to constrain.
  3556. *
  3557. * @return The constrained diff.
  3558. */
  3559. function constrain(diff) {
  3560. return diff / (exceeded && isSlide ? FRICTION : 1);
  3561. }
  3562. return {
  3563. mount: mount
  3564. };
  3565. }
  3566. /**
  3567. * The collection of arrow keys of IE.
  3568. *
  3569. * @since 3.0.0
  3570. */
  3571. var IE_ARROW_KEYS = ['Left', 'Right', 'Up', 'Down'];
  3572. /**
  3573. * The component for controlling the slider by keyboards.
  3574. *
  3575. * @since 3.0.0
  3576. *
  3577. * @param Splide - A Splide instance.
  3578. * @param Components - A collection of components.
  3579. * @param options - Options.
  3580. *
  3581. * @return A Keyboard component object.
  3582. */
  3583. function Keyboard(Splide, Components, options) {
  3584. var _EventInterface13 = EventInterface(Splide),
  3585. on = _EventInterface13.on,
  3586. bind = _EventInterface13.bind,
  3587. unbind = _EventInterface13.unbind;
  3588. var root = Components.Elements.root;
  3589. var resolve = Components.Direction.resolve;
  3590. /**
  3591. * The target element of the keyboard event.
  3592. */
  3593. var target;
  3594. /**
  3595. * Called when the component is mounted.
  3596. */
  3597. function mount() {
  3598. init();
  3599. on(EVENT_UPDATED, function () {
  3600. destroy();
  3601. init();
  3602. });
  3603. }
  3604. /**
  3605. * Initializes the component.
  3606. */
  3607. function init() {
  3608. var _options$keyboard = options.keyboard,
  3609. keyboard = _options$keyboard === void 0 ? 'global' : _options$keyboard;
  3610. if (keyboard) {
  3611. if (keyboard === 'focused') {
  3612. target = root;
  3613. setAttribute(root, TAB_INDEX, 0);
  3614. } else {
  3615. target = window;
  3616. }
  3617. bind(target, 'keydown', function (e) {
  3618. var key = normalize(e.key);
  3619. if (key === resolve('ArrowLeft')) {
  3620. Splide.go('<');
  3621. } else if (key === resolve('ArrowRight')) {
  3622. Splide.go('>');
  3623. }
  3624. });
  3625. }
  3626. }
  3627. /**
  3628. * Destroys the component.
  3629. */
  3630. function destroy() {
  3631. if (target) {
  3632. unbind(target, 'keydown');
  3633. if (isHTMLElement(target)) {
  3634. removeAttribute(target, TAB_INDEX);
  3635. }
  3636. }
  3637. }
  3638. /**
  3639. * Absorbs the difference of key names among browsers.
  3640. *
  3641. * @param key - A key to normalize.
  3642. *
  3643. * @return A normalized key.
  3644. */
  3645. function normalize(key) {
  3646. return includes(IE_ARROW_KEYS, key) ? "Arrow" + key : key;
  3647. }
  3648. return {
  3649. mount: mount,
  3650. destroy: destroy
  3651. };
  3652. }
  3653. /**
  3654. * The data attribute for the src value.
  3655. *
  3656. * @since 3.0.0
  3657. */
  3658. var SRC_DATA_ATTRIBUTE = DATA_ATTRIBUTE + "-lazy";
  3659. /**
  3660. * The data attribute for the srcset value.
  3661. *
  3662. * @since 3.0.0
  3663. */
  3664. var SRCSET_DATA_ATTRIBUTE = SRC_DATA_ATTRIBUTE + "-srcset";
  3665. /**
  3666. * The selector string for images to load.
  3667. *
  3668. * @since 3.0.0
  3669. */
  3670. var IMAGE_SELECTOR = "[" + SRC_DATA_ATTRIBUTE + "], [" + SRCSET_DATA_ATTRIBUTE + "]";
  3671. /**
  3672. * The component for lazily loading images.
  3673. *
  3674. * @since 3.0.0
  3675. *
  3676. * @param Splide - A Splide instance.
  3677. * @param Components - A collection of components.
  3678. * @param options - Options.
  3679. *
  3680. * @return An LazyLoad component object.
  3681. */
  3682. function LazyLoad(Splide, Components, options) {
  3683. var _EventInterface14 = EventInterface(Splide),
  3684. on = _EventInterface14.on,
  3685. off = _EventInterface14.off,
  3686. bind = _EventInterface14.bind,
  3687. emit = _EventInterface14.emit;
  3688. var isSequential = options.lazyLoad === 'sequential';
  3689. /**
  3690. * Stores data of images.
  3691. */
  3692. var images = [];
  3693. /**
  3694. * The current index of images.
  3695. */
  3696. var index = 0;
  3697. /**
  3698. * Called when the component is mounted.
  3699. */
  3700. function mount() {
  3701. if (options.lazyLoad) {
  3702. on([EVENT_MOUNTED, EVENT_REFRESH], function () {
  3703. destroy();
  3704. init();
  3705. });
  3706. if (!isSequential) {
  3707. on([EVENT_MOUNTED, EVENT_REFRESH, EVENT_MOVED], observe);
  3708. }
  3709. }
  3710. }
  3711. /**
  3712. * Finds images that contain specific data attributes.
  3713. */
  3714. function init() {
  3715. Components.Slides.forEach(function (Slide) {
  3716. queryAll(Slide.slide, IMAGE_SELECTOR).forEach(function (img) {
  3717. var src = getAttribute(img, SRC_DATA_ATTRIBUTE);
  3718. var srcset = getAttribute(img, SRCSET_DATA_ATTRIBUTE);
  3719. if (src !== img.src || srcset !== img.srcset) {
  3720. var spinner = create('span', options.classes.spinner, img.parentElement);
  3721. setAttribute(spinner, ROLE, 'presentation');
  3722. images.push({
  3723. img: img,
  3724. Slide: Slide,
  3725. src: src,
  3726. srcset: srcset,
  3727. spinner: spinner
  3728. });
  3729. display(img, 'none');
  3730. }
  3731. });
  3732. });
  3733. if (isSequential) {
  3734. loadNext();
  3735. }
  3736. }
  3737. /**
  3738. * Destroys the component.
  3739. */
  3740. function destroy() {
  3741. index = 0;
  3742. images = [];
  3743. }
  3744. /**
  3745. * Checks how close each image is from the active slide, and determines whether to start loading or not.
  3746. * The last `+1` is for the current page.
  3747. */
  3748. function observe() {
  3749. images = images.filter(function (data) {
  3750. if (data.Slide.isWithin(Splide.index, options.perPage * ((options.preloadPages || 1) + 1))) {
  3751. return load(data);
  3752. }
  3753. return true;
  3754. });
  3755. if (!images.length) {
  3756. off(EVENT_MOVED);
  3757. }
  3758. }
  3759. /**
  3760. * Starts loading the image in the data.
  3761. *
  3762. * @param data - A LazyLoadImagesData object.
  3763. */
  3764. function load(data) {
  3765. var img = data.img;
  3766. addClass(data.Slide.slide, CLASS_LOADING);
  3767. bind(img, 'load error', function (e) {
  3768. onLoad(data, e.type === 'error');
  3769. });
  3770. ['src', 'srcset'].forEach(function (name) {
  3771. if (data[name]) {
  3772. setAttribute(img, name, data[name]);
  3773. removeAttribute(img, name === 'src' ? SRC_DATA_ATTRIBUTE : SRCSET_DATA_ATTRIBUTE);
  3774. }
  3775. });
  3776. }
  3777. /**
  3778. * Called when the image is loaded or any error occurs.
  3779. *
  3780. * @param data - A LazyLoadImagesData object.
  3781. * @param error - `true` if this method is called on error.
  3782. */
  3783. function onLoad(data, error) {
  3784. var Slide = data.Slide;
  3785. removeClass(Slide.slide, CLASS_LOADING);
  3786. if (!error) {
  3787. remove(data.spinner);
  3788. display(data.img, '');
  3789. emit(EVENT_LAZYLOAD_LOADED, data.img, Slide);
  3790. emit(EVENT_RESIZE);
  3791. }
  3792. if (isSequential) {
  3793. loadNext();
  3794. }
  3795. }
  3796. /**
  3797. * Starts loading a next image.
  3798. */
  3799. function loadNext() {
  3800. if (index < images.length) {
  3801. load(images[index++]);
  3802. }
  3803. }
  3804. return {
  3805. mount: mount,
  3806. destroy: destroy
  3807. };
  3808. }
  3809. /**
  3810. * The component for handling previous and next arrows.
  3811. *
  3812. * @since 3.0.0
  3813. *
  3814. * @param Splide - A Splide instance.
  3815. * @param Components - A collection of components.
  3816. * @param options - Options.
  3817. *
  3818. * @return A Arrows component object.
  3819. */
  3820. function Pagination(Splide, Components, options) {
  3821. var _EventInterface15 = EventInterface(Splide),
  3822. on = _EventInterface15.on,
  3823. emit = _EventInterface15.emit,
  3824. bind = _EventInterface15.bind,
  3825. unbind = _EventInterface15.unbind;
  3826. var Slides = Components.Slides;
  3827. var _Components$Controlle2 = Components.Controller,
  3828. go = _Components$Controlle2.go,
  3829. toPage = _Components$Controlle2.toPage,
  3830. hasFocus = _Components$Controlle2.hasFocus,
  3831. getIndex = _Components$Controlle2.getIndex;
  3832. /**
  3833. * Stores all pagination items.
  3834. */
  3835. var items = [];
  3836. /**
  3837. * The pagination element.
  3838. */
  3839. var list;
  3840. /**
  3841. * Called when the component is mounted.
  3842. */
  3843. function mount() {
  3844. init();
  3845. on([EVENT_UPDATED, EVENT_REFRESH], init);
  3846. on([EVENT_MOVE, EVENT_SCROLLED], update);
  3847. }
  3848. /**
  3849. * Initializes the pagination.
  3850. */
  3851. function init() {
  3852. destroy();
  3853. if (options.pagination && Slides.isEnough()) {
  3854. createPagination();
  3855. emit(EVENT_PAGINATION_MOUNTED, {
  3856. list: list,
  3857. items: items
  3858. }, getAt(Splide.index));
  3859. update();
  3860. }
  3861. }
  3862. /**
  3863. * Destroys the component.
  3864. */
  3865. function destroy() {
  3866. if (list) {
  3867. remove(list);
  3868. items.forEach(function (item) {
  3869. unbind(item.button, 'click');
  3870. });
  3871. empty(items);
  3872. list = null;
  3873. }
  3874. }
  3875. /**
  3876. * Creates the pagination element and appends it to the slider.
  3877. */
  3878. function createPagination() {
  3879. var length = Splide.length;
  3880. var classes = options.classes,
  3881. i18n = options.i18n,
  3882. perPage = options.perPage;
  3883. var _Components$Elements5 = Components.Elements,
  3884. slider = _Components$Elements5.slider,
  3885. root = _Components$Elements5.root;
  3886. var parent = options.pagination === 'slider' && slider ? slider : root;
  3887. var max = hasFocus() ? length : ceil(length / perPage);
  3888. list = create('ul', classes.pagination, parent);
  3889. var _loop = function _loop(i) {
  3890. var li = create('li', null, list);
  3891. var button = create('button', {
  3892. class: classes.page,
  3893. type: 'button'
  3894. }, li);
  3895. var controls = Slides.getIn(i).map(function (Slide) {
  3896. return Slide.slide.id;
  3897. });
  3898. var text = !hasFocus() && perPage > 1 ? i18n.pageX : i18n.slideX;
  3899. bind(button, 'click', function () {
  3900. go(">" + i);
  3901. });
  3902. setAttribute(button, ARIA_CONTROLS, controls.join(' '));
  3903. setAttribute(button, ARIA_LABEL, format(text, i + 1));
  3904. emit(EVENT_PAGINATION_PAGE, list, li, button, i);
  3905. items.push({
  3906. li: li,
  3907. button: button,
  3908. page: i
  3909. });
  3910. };
  3911. for (var i = 0; i < max; i++) {
  3912. _loop(i);
  3913. }
  3914. }
  3915. /**
  3916. * Returns the pagination item at the specified index.
  3917. *
  3918. * @param index - An index.
  3919. *
  3920. * @return A pagination item object if available, or otherwise `undefined`.
  3921. */
  3922. function getAt(index) {
  3923. return items[toPage(index)];
  3924. }
  3925. /**
  3926. * Updates the pagination status.
  3927. */
  3928. function update() {
  3929. var prev = getAt(getIndex(true));
  3930. var curr = getAt(getIndex());
  3931. if (prev) {
  3932. removeClass(prev.button, CLASS_ACTIVE);
  3933. removeAttribute(prev.button, ARIA_CURRENT);
  3934. }
  3935. if (curr) {
  3936. addClass(curr.button, CLASS_ACTIVE);
  3937. setAttribute(curr.button, ARIA_CURRENT, true);
  3938. }
  3939. emit(EVENT_PAGINATION_UPDATED, {
  3940. list: list,
  3941. items: items
  3942. }, prev, curr);
  3943. }
  3944. return {
  3945. items: items,
  3946. mount: mount,
  3947. destroy: destroy,
  3948. getAt: getAt
  3949. };
  3950. }
  3951. /**
  3952. * The keys for triggering the navigation slide.
  3953. *
  3954. * @since 3.0.0
  3955. */
  3956. var TRIGGER_KEYS = [' ', 'Enter', 'Spacebar'];
  3957. /**
  3958. * The component for syncing multiple sliders.
  3959. *
  3960. * @since 3.0.0
  3961. *
  3962. * @param Splide - A Splide instance.
  3963. * @param Components - A collection of components.
  3964. * @param options - Options.
  3965. *
  3966. * @return A Sync component object.
  3967. */
  3968. function Sync(Splide, Components, options) {
  3969. var splides = Splide.splides;
  3970. /**
  3971. * Called when the component is mounted.
  3972. */
  3973. function mount() {
  3974. if (options.isNavigation) {
  3975. navigate();
  3976. } else {
  3977. sync();
  3978. }
  3979. }
  3980. /**
  3981. * Syncs the current index among all slides.
  3982. * The `processed` array prevents recursive call of handlers.
  3983. */
  3984. function sync() {
  3985. var processed = [];
  3986. splides.concat(Splide).forEach(function (splide, index, instances) {
  3987. EventInterface(splide).on(EVENT_MOVE, function (index, prev, dest) {
  3988. instances.forEach(function (instance) {
  3989. if (instance !== splide && !includes(processed, splide)) {
  3990. processed.push(instance);
  3991. instance.go(instance.is(LOOP) ? dest : index);
  3992. }
  3993. });
  3994. empty(processed);
  3995. });
  3996. });
  3997. }
  3998. /**
  3999. * Makes slides clickable and moves the slider to the index of clicked slide.
  4000. */
  4001. function navigate() {
  4002. var _EventInterface16 = EventInterface(Splide),
  4003. on = _EventInterface16.on,
  4004. emit = _EventInterface16.emit;
  4005. on(EVENT_CLICK, function (Slide) {
  4006. Splide.go(Slide.index);
  4007. });
  4008. on(EVENT_SLIDE_KEYDOWN, function (Slide, e) {
  4009. if (includes(TRIGGER_KEYS, e.key)) {
  4010. Splide.go(Slide.index);
  4011. prevent(e);
  4012. }
  4013. });
  4014. emit(EVENT_NAVIGATION_MOUNTED, Splide.splides);
  4015. }
  4016. return {
  4017. mount: mount
  4018. };
  4019. }
  4020. /**
  4021. * The component for observing the mouse wheel and moving the slider.
  4022. *
  4023. * @since 3.0.0
  4024. *
  4025. * @param Splide - A Splide instance.
  4026. * @param Components - A collection of components.
  4027. * @param options - Options.
  4028. *
  4029. * @return A Wheel component object.
  4030. */
  4031. function Wheel(Splide, Components, options) {
  4032. var _EventInterface17 = EventInterface(Splide),
  4033. bind = _EventInterface17.bind;
  4034. /**
  4035. * Called when the component is mounted.
  4036. */
  4037. function mount() {
  4038. if (options.wheel) {
  4039. bind(Components.Elements.track, 'wheel', onWheel);
  4040. }
  4041. }
  4042. /**
  4043. * Called when the user rotates the mouse wheel.
  4044. *
  4045. * @param e - A WheelEvent object.
  4046. */
  4047. function onWheel(e) {
  4048. var deltaY = e.deltaY;
  4049. if (deltaY) {
  4050. Splide.go(deltaY < 0 ? '<' : '>');
  4051. prevent(e);
  4052. }
  4053. }
  4054. return {
  4055. mount: mount
  4056. };
  4057. }
  4058. var ComponentConstructors = /*#__PURE__*/Object.freeze({
  4059. __proto__: null,
  4060. Options: Options,
  4061. Direction: Direction,
  4062. Elements: Elements,
  4063. Style: Style,
  4064. Slides: Slides,
  4065. Clones: Clones,
  4066. Layout: Layout,
  4067. Move: Move,
  4068. Controller: Controller,
  4069. Arrows: Arrows,
  4070. Autoplay: Autoplay,
  4071. Cover: Cover,
  4072. Scroll: Scroll,
  4073. Drag: Drag,
  4074. Keyboard: Keyboard,
  4075. LazyLoad: LazyLoad,
  4076. Pagination: Pagination,
  4077. Sync: Sync,
  4078. Wheel: Wheel
  4079. });
  4080. /**
  4081. * The collection of i18n strings.
  4082. *
  4083. * @since 3.0.0
  4084. */
  4085. var I18N = {
  4086. prev: 'Previous slide',
  4087. next: 'Next slide',
  4088. first: 'Go to first slide',
  4089. last: 'Go to last slide',
  4090. slideX: 'Go to slide %s',
  4091. pageX: 'Go to page %s',
  4092. play: 'Start autoplay',
  4093. pause: 'Pause autoplay'
  4094. };
  4095. /**
  4096. * The collection of default options.
  4097. * Note that this collection does not contain all options.
  4098. *
  4099. * @since 3.0.0
  4100. */
  4101. var DEFAULTS = {
  4102. type: 'slide',
  4103. speed: 400,
  4104. waitForTransition: true,
  4105. perPage: 1,
  4106. arrows: true,
  4107. pagination: true,
  4108. interval: 5000,
  4109. pauseOnHover: true,
  4110. pauseOnFocus: true,
  4111. resetProgress: true,
  4112. easing: 'cubic-bezier(.42,.65,.27,.99)',
  4113. drag: true,
  4114. direction: 'ltr',
  4115. slideFocus: true,
  4116. trimSpace: true,
  4117. classes: CLASSES,
  4118. i18n: I18N
  4119. };
  4120. /**
  4121. * The component for the fade transition.
  4122. *
  4123. * @since 3.0.0
  4124. *
  4125. * @param Splide - A Splide instance.
  4126. * @param Components - A collection of components.
  4127. * @param options - Options.
  4128. *
  4129. * @return A Transition component object.
  4130. */
  4131. function Fade(Splide, Components, options) {
  4132. var _EventInterface18 = EventInterface(Splide),
  4133. on = _EventInterface18.on;
  4134. var ruleBy = Components.Style.ruleBy;
  4135. /**
  4136. * Called when the component is mounted.
  4137. * The nextTick disables the initial fade transition of the first slide.
  4138. */
  4139. function mount() {
  4140. on([EVENT_MOUNTED, EVENT_REFRESH], function () {
  4141. nextTick(function () {
  4142. Components.Slides.forEach(function (Slide) {
  4143. ruleBy(Slide.slide, 'transition', "opacity " + options.speed + "ms " + options.easing);
  4144. });
  4145. });
  4146. });
  4147. }
  4148. /**
  4149. * Starts the transition.
  4150. * Explicitly sets the track height to avoid it will collapse in Safari.
  4151. *
  4152. * @param index - A destination index.
  4153. * @param done - The callback function that must be called after the transition ends.
  4154. */
  4155. function start(index, done) {
  4156. var track = Components.Elements.track;
  4157. ruleBy(track, 'height', unit(rect(track).height));
  4158. nextTick(function () {
  4159. done();
  4160. ruleBy(track, 'height', '');
  4161. });
  4162. }
  4163. return {
  4164. mount: mount,
  4165. start: start,
  4166. cancel: noop
  4167. };
  4168. }
  4169. /**
  4170. * The component for the slide transition.
  4171. *
  4172. * @since 3.0.0
  4173. *
  4174. * @param Splide - A Splide instance.
  4175. * @param Components - A collection of components.
  4176. * @param options - Options.
  4177. *
  4178. * @return A Transition component object.
  4179. */
  4180. function Slide(Splide, Components, options) {
  4181. var _EventInterface19 = EventInterface(Splide),
  4182. bind = _EventInterface19.bind;
  4183. var Move = Components.Move,
  4184. Controller = Components.Controller;
  4185. var list = Components.Elements.list;
  4186. /**
  4187. * Holds the `done` callback function.
  4188. */
  4189. var endCallback;
  4190. /**
  4191. * Called when the component is mounted.
  4192. */
  4193. function mount() {
  4194. bind(list, 'transitionend', function (e) {
  4195. if (e.target === list && endCallback) {
  4196. cancel();
  4197. endCallback();
  4198. }
  4199. });
  4200. }
  4201. /**
  4202. * Starts the transition.
  4203. * The Move component calls this method just before the slider moves.
  4204. *
  4205. * @param index - A destination index.
  4206. * @param done - The callback function that must be called after the transition ends.
  4207. */
  4208. function start(index, done) {
  4209. var destination = Move.toPosition(index, true);
  4210. var position = Move.getPosition();
  4211. var speed = getSpeed(index);
  4212. if (abs(destination - position) >= 1 && speed >= 1) {
  4213. apply("transform " + speed + "ms " + options.easing);
  4214. Move.translate(destination);
  4215. endCallback = done;
  4216. } else {
  4217. Move.jump(index);
  4218. done();
  4219. }
  4220. }
  4221. /**
  4222. * Cancels the transition.
  4223. */
  4224. function cancel() {
  4225. apply('');
  4226. }
  4227. /**
  4228. * Returns the transition speed.
  4229. *
  4230. * @param index - A destination index.
  4231. */
  4232. function getSpeed(index) {
  4233. var rewindSpeed = options.rewindSpeed;
  4234. if (Splide.is(SLIDE) && rewindSpeed) {
  4235. var prev = Controller.getIndex(true);
  4236. var end = Controller.getEnd();
  4237. if (prev === 0 && index >= end || prev >= end && index === 0) {
  4238. return rewindSpeed;
  4239. }
  4240. }
  4241. return options.speed;
  4242. }
  4243. /**
  4244. * Applies the transition CSS property to the list element.
  4245. *
  4246. * @param transition - A transition CSS value.
  4247. */
  4248. function apply(transition) {
  4249. Components.Style.ruleBy(list, 'transition', transition);
  4250. }
  4251. return {
  4252. mount: mount,
  4253. start: start,
  4254. cancel: cancel
  4255. };
  4256. }
  4257. /**
  4258. * The frontend class for the Splide slider.
  4259. *
  4260. * @since 3.0.0
  4261. */
  4262. var Splide = /*#__PURE__*/function () {
  4263. /**
  4264. * The Splide constructor.
  4265. *
  4266. * @param target - The selector for the target element, or the element itself.
  4267. * @param options - Optional. An object with options.
  4268. */
  4269. function Splide(target, options) {
  4270. /**
  4271. * The EventBusObject object.
  4272. */
  4273. this.event = EventBus();
  4274. /**
  4275. * The collection of all component objects.
  4276. */
  4277. this.Components = {};
  4278. /**
  4279. * The StateObject object.
  4280. */
  4281. this.state = State(CREATED);
  4282. /**
  4283. * Splide instances to sync with.
  4284. */
  4285. this.splides = [];
  4286. /**
  4287. * The collection of options.
  4288. */
  4289. this.opts = {};
  4290. /**
  4291. * The collection of extensions.
  4292. */
  4293. this.Extensions = {};
  4294. var root = isString(target) ? query(document, target) : target;
  4295. assert(root, root + " is invalid.");
  4296. this.root = root;
  4297. merge(DEFAULTS, Splide.defaults);
  4298. merge(merge(this.opts, DEFAULTS), options || {});
  4299. }
  4300. /**
  4301. * Initializes the instance.
  4302. *
  4303. * @param Extensions - Optional. An object with extensions.
  4304. * @param Transition - Optional. A Transition component.
  4305. *
  4306. * @return `this`
  4307. */
  4308. var _proto = Splide.prototype;
  4309. _proto.mount = function mount(Extensions, Transition) {
  4310. var _this3 = this;
  4311. this.state.set(CREATED);
  4312. this.Transition = Transition || this.Transition || (this.is(FADE) ? Fade : Slide);
  4313. this.Extensions = Extensions || this.Extensions;
  4314. var Constructors = assign({}, ComponentConstructors, this.Extensions, {
  4315. Transition: this.Transition
  4316. });
  4317. var Components = this.Components;
  4318. forOwn(Constructors, function (Component, key) {
  4319. var component = Component(_this3, _this3.Components, _this3.opts);
  4320. Components[key] = component;
  4321. component.setup && component.setup();
  4322. });
  4323. forOwn(Components, function (component) {
  4324. component.mount && component.mount();
  4325. });
  4326. forOwn(Components, function (component) {
  4327. component.mounted && component.mounted();
  4328. });
  4329. this.emit(EVENT_MOUNTED);
  4330. addClass(this.root, CLASS_INITIALIZED);
  4331. this.state.set(IDLE);
  4332. this.emit(EVENT_READY);
  4333. return this;
  4334. }
  4335. /**
  4336. * Syncs the slider with the provided one.
  4337. * This method must be called before the `mount()`.
  4338. *
  4339. * @example
  4340. * ```ts
  4341. * var primary = new Splide();
  4342. * var secondary = new Splide();
  4343. *
  4344. * primary.sync( secondary );
  4345. * primary.mount();
  4346. * secondary.mount();
  4347. * ```
  4348. *
  4349. * @param splide - A Splide instance to sync with.
  4350. *
  4351. * @return `this`
  4352. */
  4353. ;
  4354. _proto.sync = function sync(splide) {
  4355. this.splides.push(splide);
  4356. splide.splides.push(this);
  4357. return this;
  4358. }
  4359. /**
  4360. * Moves the slider with the following control pattern.
  4361. *
  4362. * | Pattern | Description |
  4363. * |---|---|
  4364. * | `i` | Goes to the slide `i` |
  4365. * | `'+${i}'` | Increments the slide index by `i` |
  4366. * | `'-${i}'` | Decrements the slide index by `i` |
  4367. * | `'>'` | Goes to the next page |
  4368. * | `'<'` | Goes to the previous page |
  4369. * | `>${i}` | Goes to the page `i` |
  4370. *
  4371. * In most cases, `'>'` and `'<'` notations are enough to control the slider
  4372. * because they respect `perPage` and `perMove` options.
  4373. *
  4374. * @example
  4375. * ```ts
  4376. * var splide = new Splide();
  4377. *
  4378. * // Goes to the slide 1:
  4379. * splide.go( 1 );
  4380. *
  4381. * // Increments the index:
  4382. * splide.go( '+2' );
  4383. *
  4384. * // Goes to the next page:
  4385. * splide.go( '>' );
  4386. *
  4387. * // Goes to the page 2:
  4388. * splide.go( '>2' );
  4389. * ```
  4390. *
  4391. * @param control
  4392. */
  4393. ;
  4394. _proto.go = function go(control) {
  4395. this.Components.Controller.go(control);
  4396. }
  4397. /**
  4398. * Registers an event handler.
  4399. *
  4400. * @example
  4401. * ```ts
  4402. * var splide = new Splide();
  4403. *
  4404. * // Listens to a single event:
  4405. * splide.on( 'move', function() {} );
  4406. *
  4407. * // Listens to multiple events:
  4408. * splide.on( 'move resize', function() {} );
  4409. *
  4410. * // Appends a namespace:
  4411. * splide.on( 'move.myNamespace resize.myNamespace', function() {} );
  4412. * ```
  4413. *
  4414. * @param events - An event name or names separated by spaces. Use a dot(.) to append a namespace.
  4415. * @param callback - A callback function.
  4416. *
  4417. * @return `this`
  4418. */
  4419. ;
  4420. _proto.on = function on(events, callback) {
  4421. this.event.on(events, callback);
  4422. return this;
  4423. }
  4424. /**
  4425. * Removes the registered all handlers for the specified event or events.
  4426. * If you want to only remove a particular handler, use namespace to identify it.
  4427. *
  4428. * @example
  4429. * ```ts
  4430. * var splide = new Splide();
  4431. *
  4432. * // Removes all handlers assigned to "move":
  4433. * splide.off( 'move' );
  4434. *
  4435. * // Only removes handlers that belong to the specified namespace:
  4436. * splide.off( 'move.myNamespace' );
  4437. * ```
  4438. *
  4439. * @param events - An event name or names separated by spaces. Use a dot(.) to append a namespace.
  4440. *
  4441. * @return `this`
  4442. */
  4443. ;
  4444. _proto.off = function off(events) {
  4445. this.event.off(events);
  4446. return this;
  4447. }
  4448. /**
  4449. * Emits an event and triggers registered handlers.
  4450. *
  4451. * @param event - An event name to emit.
  4452. * @param args - Optional. Any number of arguments to pass to handlers.
  4453. *
  4454. * @return `this`
  4455. */
  4456. ;
  4457. _proto.emit = function emit(event) {
  4458. var _this$event;
  4459. for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
  4460. args[_key2 - 1] = arguments[_key2];
  4461. }
  4462. (_this$event = this.event).emit.apply(_this$event, [event].concat(args));
  4463. return this;
  4464. }
  4465. /**
  4466. * Inserts a slide at the specified position.
  4467. *
  4468. * @example
  4469. * ```ts
  4470. * var splide = new Splide();
  4471. * splide.mount();
  4472. *
  4473. * // Adds the slide by the HTML:
  4474. * splide.add( '<li></li> );
  4475. *
  4476. * // or adds the element:
  4477. * splide.add( document.createElement( 'li' ) );
  4478. * ```
  4479. *
  4480. * @param slides - A slide element, an HTML string that represents a slide, or an array with them.
  4481. * @param index - Optional. An index to insert a slide at.
  4482. *
  4483. * @return `this`
  4484. */
  4485. ;
  4486. _proto.add = function add(slides, index) {
  4487. this.Components.Slides.add(slides, index);
  4488. return this;
  4489. }
  4490. /**
  4491. * Removes slides that match the matcher
  4492. * that can be an index, an array with indices, a selector, or an iteratee function.
  4493. *
  4494. * @param matcher - An index, an array with indices, a selector string, or an iteratee function.
  4495. */
  4496. ;
  4497. _proto.remove = function remove(matcher) {
  4498. this.Components.Slides.remove(matcher);
  4499. return this;
  4500. }
  4501. /**
  4502. * Checks the slider type.
  4503. *
  4504. * @param type - A type to test.
  4505. *
  4506. * @return `true` if the type matches the current one, or otherwise `false`.
  4507. */
  4508. ;
  4509. _proto.is = function is(type) {
  4510. return this.opts.type === type;
  4511. }
  4512. /**
  4513. * Refreshes the slider.
  4514. *
  4515. * @return `this`
  4516. */
  4517. ;
  4518. _proto.refresh = function refresh() {
  4519. this.emit(EVENT_REFRESH);
  4520. return this;
  4521. }
  4522. /**
  4523. * Destroys the slider.
  4524. *
  4525. * @param completely - Optional. If `true`, Splide will not remount the slider by breakpoints.
  4526. *
  4527. * @return `this`
  4528. */
  4529. ;
  4530. _proto.destroy = function destroy(completely) {
  4531. var event = this.event,
  4532. state = this.state;
  4533. if (state.is(CREATED)) {
  4534. // Postpones destruction requested before the slider becomes ready.
  4535. event.on(EVENT_READY, this.destroy.bind(this, completely), this);
  4536. } else {
  4537. forOwn(this.Components, function (component) {
  4538. component.destroy && component.destroy(completely);
  4539. });
  4540. event.emit(EVENT_DESTROY);
  4541. event.destroy();
  4542. empty(this.splides);
  4543. state.set(DESTROYED);
  4544. }
  4545. return this;
  4546. }
  4547. /**
  4548. * Returns options.
  4549. *
  4550. * @return An object with the latest options.
  4551. */
  4552. ;
  4553. _createClass(Splide, [{
  4554. key: "options",
  4555. get: function get() {
  4556. return this.opts;
  4557. }
  4558. /**
  4559. * Merges options to the current options and emits `updated` event.
  4560. *
  4561. * @param options - An object with new options.
  4562. */
  4563. ,
  4564. set: function set(options) {
  4565. var opts = this.opts;
  4566. merge(opts, options);
  4567. if (!this.state.is(CREATED)) {
  4568. this.emit(EVENT_UPDATED, opts);
  4569. }
  4570. }
  4571. /**
  4572. * Returns the number of slides without clones.
  4573. *
  4574. * @return The number of slides.
  4575. */
  4576. }, {
  4577. key: "length",
  4578. get: function get() {
  4579. return this.Components.Slides.getLength(true);
  4580. }
  4581. /**
  4582. * Returns the active slide index.
  4583. *
  4584. * @return The active slide index.
  4585. */
  4586. }, {
  4587. key: "index",
  4588. get: function get() {
  4589. return this.Components.Controller.getIndex();
  4590. }
  4591. }]);
  4592. return Splide;
  4593. }();
  4594. /**
  4595. * Changes the default options for all Splide instances.
  4596. */
  4597. Splide.defaults = {};
  4598. /**
  4599. * The collection of state numbers.
  4600. */
  4601. Splide.STATES = STATES;
  4602. exports.CLASSES = CLASSES;
  4603. exports.CLASS_ACTIVE = CLASS_ACTIVE;
  4604. exports.CLASS_ARROW = CLASS_ARROW;
  4605. exports.CLASS_ARROWS = CLASS_ARROWS;
  4606. exports.CLASS_ARROW_NEXT = CLASS_ARROW_NEXT;
  4607. exports.CLASS_ARROW_PREV = CLASS_ARROW_PREV;
  4608. exports.CLASS_AUTOPLAY = CLASS_AUTOPLAY;
  4609. exports.CLASS_CLONE = CLASS_CLONE;
  4610. exports.CLASS_CONTAINER = CLASS_CONTAINER;
  4611. exports.CLASS_INITIALIZED = CLASS_INITIALIZED;
  4612. exports.CLASS_LIST = CLASS_LIST;
  4613. exports.CLASS_LOADING = CLASS_LOADING;
  4614. exports.CLASS_NEXT = CLASS_NEXT;
  4615. exports.CLASS_PAGINATION = CLASS_PAGINATION;
  4616. exports.CLASS_PAGINATION_PAGE = CLASS_PAGINATION_PAGE;
  4617. exports.CLASS_PAUSE = CLASS_PAUSE;
  4618. exports.CLASS_PLAY = CLASS_PLAY;
  4619. exports.CLASS_PREV = CLASS_PREV;
  4620. exports.CLASS_PROGRESS = CLASS_PROGRESS;
  4621. exports.CLASS_PROGRESS_BAR = CLASS_PROGRESS_BAR;
  4622. exports.CLASS_ROOT = CLASS_ROOT;
  4623. exports.CLASS_SLIDE = CLASS_SLIDE;
  4624. exports.CLASS_SLIDER = CLASS_SLIDER;
  4625. exports.CLASS_SPINNER = CLASS_SPINNER;
  4626. exports.CLASS_TRACK = CLASS_TRACK;
  4627. exports.CLASS_VISIBLE = CLASS_VISIBLE;
  4628. exports.EVENT_ACTIVE = EVENT_ACTIVE;
  4629. exports.EVENT_ARROWS_MOUNTED = EVENT_ARROWS_MOUNTED;
  4630. exports.EVENT_ARROWS_UPDATED = EVENT_ARROWS_UPDATED;
  4631. exports.EVENT_AUTOPLAY_PAUSE = EVENT_AUTOPLAY_PAUSE;
  4632. exports.EVENT_AUTOPLAY_PLAY = EVENT_AUTOPLAY_PLAY;
  4633. exports.EVENT_AUTOPLAY_PLAYING = EVENT_AUTOPLAY_PLAYING;
  4634. exports.EVENT_CLICK = EVENT_CLICK;
  4635. exports.EVENT_DESTROY = EVENT_DESTROY;
  4636. exports.EVENT_DRAG = EVENT_DRAG;
  4637. exports.EVENT_DRAGGED = EVENT_DRAGGED;
  4638. exports.EVENT_DRAGGING = EVENT_DRAGGING;
  4639. exports.EVENT_HIDDEN = EVENT_HIDDEN;
  4640. exports.EVENT_INACTIVE = EVENT_INACTIVE;
  4641. exports.EVENT_LAZYLOAD_LOADED = EVENT_LAZYLOAD_LOADED;
  4642. exports.EVENT_MOUNTED = EVENT_MOUNTED;
  4643. exports.EVENT_MOVE = EVENT_MOVE;
  4644. exports.EVENT_MOVED = EVENT_MOVED;
  4645. exports.EVENT_NAVIGATION_MOUNTED = EVENT_NAVIGATION_MOUNTED;
  4646. exports.EVENT_PAGINATION_MOUNTED = EVENT_PAGINATION_MOUNTED;
  4647. exports.EVENT_PAGINATION_PAGE = EVENT_PAGINATION_PAGE;
  4648. exports.EVENT_PAGINATION_UPDATED = EVENT_PAGINATION_UPDATED;
  4649. exports.EVENT_READY = EVENT_READY;
  4650. exports.EVENT_REFRESH = EVENT_REFRESH;
  4651. exports.EVENT_RESIZE = EVENT_RESIZE;
  4652. exports.EVENT_RESIZED = EVENT_RESIZED;
  4653. exports.EVENT_SCROLL = EVENT_SCROLL;
  4654. exports.EVENT_SCROLLED = EVENT_SCROLLED;
  4655. exports.EVENT_SLIDE_KEYDOWN = EVENT_SLIDE_KEYDOWN;
  4656. exports.EVENT_UPDATED = EVENT_UPDATED;
  4657. exports.EVENT_VISIBLE = EVENT_VISIBLE;
  4658. exports.EventBus = EventBus;
  4659. exports.EventInterface = EventInterface;
  4660. exports.RequestInterval = RequestInterval;
  4661. exports.STATUS_CLASSES = STATUS_CLASSES;
  4662. exports.Splide = Splide;
  4663. exports.State = State;
  4664. exports.Throttle = Throttle;
  4665. exports['default'] = Splide;