splide.cjs.js 123 KB

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