splide.cjs.js 122 KB

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