splide.esm.js 132 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753
  1. /*!
  2. * Splide.js
  3. * Version : 2.2.7
  4. * License : MIT
  5. * Copyright: 2020 Naotoshi Fujita
  6. */
  7. (function webpackUniversalModuleDefinition(root, factory) {
  8. if(typeof exports === 'object' && typeof module === 'object')
  9. module.exports = factory();
  10. else if(typeof define === 'function' && define.amd)
  11. define([], factory);
  12. else if(typeof exports === 'object')
  13. exports["Splide"] = factory();
  14. else
  15. root["Splide"] = factory();
  16. })(window, function() {
  17. return /******/ (function(modules) { // webpackBootstrap
  18. /******/ // The module cache
  19. /******/ var installedModules = {};
  20. /******/
  21. /******/ // The require function
  22. /******/ function __webpack_require__(moduleId) {
  23. /******/
  24. /******/ // Check if module is in cache
  25. /******/ if(installedModules[moduleId]) {
  26. /******/ return installedModules[moduleId].exports;
  27. /******/ }
  28. /******/ // Create a new module (and put it into the cache)
  29. /******/ var module = installedModules[moduleId] = {
  30. /******/ i: moduleId,
  31. /******/ l: false,
  32. /******/ exports: {}
  33. /******/ };
  34. /******/
  35. /******/ // Execute the module function
  36. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  37. /******/
  38. /******/ // Flag the module as loaded
  39. /******/ module.l = true;
  40. /******/
  41. /******/ // Return the exports of the module
  42. /******/ return module.exports;
  43. /******/ }
  44. /******/
  45. /******/
  46. /******/ // expose the modules object (__webpack_modules__)
  47. /******/ __webpack_require__.m = modules;
  48. /******/
  49. /******/ // expose the module cache
  50. /******/ __webpack_require__.c = installedModules;
  51. /******/
  52. /******/ // define getter function for harmony exports
  53. /******/ __webpack_require__.d = function(exports, name, getter) {
  54. /******/ if(!__webpack_require__.o(exports, name)) {
  55. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  56. /******/ }
  57. /******/ };
  58. /******/
  59. /******/ // define __esModule on exports
  60. /******/ __webpack_require__.r = function(exports) {
  61. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  62. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  63. /******/ }
  64. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  65. /******/ };
  66. /******/
  67. /******/ // create a fake namespace object
  68. /******/ // mode & 1: value is a module id, require it
  69. /******/ // mode & 2: merge all properties of value into the ns
  70. /******/ // mode & 4: return value when already ns object
  71. /******/ // mode & 8|1: behave like require
  72. /******/ __webpack_require__.t = function(value, mode) {
  73. /******/ if(mode & 1) value = __webpack_require__(value);
  74. /******/ if(mode & 8) return value;
  75. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  76. /******/ var ns = Object.create(null);
  77. /******/ __webpack_require__.r(ns);
  78. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  79. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  80. /******/ return ns;
  81. /******/ };
  82. /******/
  83. /******/ // getDefaultExport function for compatibility with non-harmony modules
  84. /******/ __webpack_require__.n = function(module) {
  85. /******/ var getter = module && module.__esModule ?
  86. /******/ function getDefault() { return module['default']; } :
  87. /******/ function getModuleExports() { return module; };
  88. /******/ __webpack_require__.d(getter, 'a', getter);
  89. /******/ return getter;
  90. /******/ };
  91. /******/
  92. /******/ // Object.prototype.hasOwnProperty.call
  93. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  94. /******/
  95. /******/ // __webpack_public_path__
  96. /******/ __webpack_require__.p = "";
  97. /******/
  98. /******/
  99. /******/ // Load entry module and return exports
  100. /******/ return __webpack_require__(__webpack_require__.s = 0);
  101. /******/ })
  102. /************************************************************************/
  103. /******/ ([
  104. /* 0 */
  105. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  106. "use strict";
  107. // ESM COMPAT FLAG
  108. __webpack_require__.r(__webpack_exports__);
  109. // EXPORTS
  110. __webpack_require__.d(__webpack_exports__, "default", function() { return /* binding */ module_Splide; });
  111. // NAMESPACE OBJECT: ./src/js/constants/states.js
  112. var states_namespaceObject = {};
  113. __webpack_require__.r(states_namespaceObject);
  114. __webpack_require__.d(states_namespaceObject, "CREATED", function() { return CREATED; });
  115. __webpack_require__.d(states_namespaceObject, "MOUNTED", function() { return MOUNTED; });
  116. __webpack_require__.d(states_namespaceObject, "IDLE", function() { return IDLE; });
  117. __webpack_require__.d(states_namespaceObject, "MOVING", function() { return MOVING; });
  118. __webpack_require__.d(states_namespaceObject, "DESTROYED", function() { return DESTROYED; });
  119. // CONCATENATED MODULE: ./src/js/core/event.js
  120. /**
  121. * The function for providing an Event object simply managing events.
  122. *
  123. * @author Naotoshi Fujita
  124. * @copyright Naotoshi Fujita. All rights reserved.
  125. */
  126. /**
  127. * The function for providing an Event object simply managing events.
  128. */
  129. /* harmony default export */ var core_event = (function () {
  130. /**
  131. * Store all event data.
  132. *
  133. * @type {Array}
  134. */
  135. var data = [];
  136. var Event = {
  137. /**
  138. * Subscribe the given event(s).
  139. *
  140. * @param {string} events - An event name. Use space to separate multiple events.
  141. * Also, namespace is accepted by dot, such as 'resize.{namespace}'.
  142. * @param {function} handler - A callback function.
  143. * @param {Element} elm - Optional. Native event will be listened to when this arg is provided.
  144. * @param {Object} options - Optional. Options for addEventListener.
  145. */
  146. on: function on(events, handler, elm, options) {
  147. if (elm === void 0) {
  148. elm = null;
  149. }
  150. if (options === void 0) {
  151. options = {};
  152. }
  153. events.split(' ').forEach(function (event) {
  154. if (elm) {
  155. elm.addEventListener(event, handler, options);
  156. }
  157. data.push({
  158. event: event,
  159. handler: handler,
  160. elm: elm,
  161. options: options
  162. });
  163. });
  164. },
  165. /**
  166. * Unsubscribe the given event(s).
  167. *
  168. * @param {string} events - A event name or names split by space.
  169. * @param {Element} elm - Optional. removeEventListener() will be called when this arg is provided.
  170. */
  171. off: function off(events, elm) {
  172. if (elm === void 0) {
  173. elm = null;
  174. }
  175. events.split(' ').forEach(function (event) {
  176. data = data.filter(function (item) {
  177. if (item && item.event === event && item.elm === elm) {
  178. unsubscribe(item);
  179. return false;
  180. }
  181. return true;
  182. });
  183. });
  184. },
  185. /**
  186. * Emit an event.
  187. * This method is only for custom events.
  188. *
  189. * @param {string} event - An event name.
  190. * @param {*} args - Any number of arguments passed to handlers.
  191. */
  192. emit: function emit(event) {
  193. for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  194. args[_key - 1] = arguments[_key];
  195. }
  196. data.forEach(function (item) {
  197. if (!item.elm && item.event.split('.')[0] === event) {
  198. item.handler.apply(item, args);
  199. }
  200. });
  201. },
  202. /**
  203. * Clear event data.
  204. */
  205. destroy: function destroy() {
  206. data.forEach(unsubscribe);
  207. data = [];
  208. }
  209. };
  210. /**
  211. * Remove the registered event listener.
  212. *
  213. * @param {Object} item - An object containing event data.
  214. */
  215. function unsubscribe(item) {
  216. if (item.elm) {
  217. item.elm.removeEventListener(item.event, item.handler, item.options);
  218. }
  219. }
  220. return Event;
  221. });
  222. // CONCATENATED MODULE: ./src/js/core/state.js
  223. /**
  224. * The function providing a super simple state system.
  225. *
  226. * @author Naotoshi Fujita
  227. * @copyright Naotoshi Fujita. All rights reserved.
  228. */
  229. /**
  230. * The function providing a super simple state system.
  231. *
  232. * @param {string|number} initialState - Provide the initial state value.
  233. */
  234. /* harmony default export */ var state = (function (initialState) {
  235. /**
  236. * Store the current state.
  237. *
  238. * @type {string|number}
  239. */
  240. var curr = initialState;
  241. return {
  242. /**
  243. * Change state.
  244. *
  245. * @param {string|number} state - A new state.
  246. */
  247. set: function set(state) {
  248. curr = state;
  249. },
  250. /**
  251. * Verify if the current state is given one or not.
  252. *
  253. * @param {string|number} state - A state name to be verified.
  254. *
  255. * @return {boolean} - True if the current state is the given one.
  256. */
  257. is: function is(state) {
  258. return state === curr;
  259. }
  260. };
  261. });
  262. // CONCATENATED MODULE: ./src/js/utils/object.js
  263. function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
  264. /**
  265. * Some utility functions related with Object, supporting IE.
  266. *
  267. * @author Naotoshi Fujita
  268. * @copyright Naotoshi Fujita. All rights reserved.
  269. */
  270. /**
  271. * Iterate an object like Array.forEach.
  272. * IE doesn't support forEach of HTMLCollection.
  273. *
  274. * @param {Object} obj - An object.
  275. * @param {function} callback - A function handling each value. Arguments are value, property and index.
  276. */
  277. function each(obj, callback) {
  278. Object.keys(obj).some(function (key, index) {
  279. return callback(obj[key], key, index);
  280. });
  281. }
  282. /**
  283. * Return values of the given object as an array.
  284. * IE doesn't support Object.values.
  285. *
  286. * @param {Object} obj - An object.
  287. *
  288. * @return {Array} - An array containing all values of the given object.
  289. */
  290. function values(obj) {
  291. return Object.keys(obj).map(function (key) {
  292. return obj[key];
  293. });
  294. }
  295. /**
  296. * Check if the given subject is object or not.
  297. *
  298. * @param {*} subject - A subject to be verified.
  299. *
  300. * @return {boolean} - True if object, false otherwise.
  301. */
  302. function isObject(subject) {
  303. return typeof subject === 'object';
  304. }
  305. /**
  306. * Merge two objects deeply.
  307. *
  308. * @param {Object} to - An object where "from" is merged.
  309. * @param {Object} from - An object merged to "to".
  310. *
  311. * @return {Object} - A merged object.
  312. */
  313. function merge(_ref, from) {
  314. var to = _extends({}, _ref);
  315. each(from, function (value, key) {
  316. if (isObject(value)) {
  317. if (!isObject(to[key])) {
  318. to[key] = {};
  319. }
  320. to[key] = merge(to[key], value);
  321. } else {
  322. to[key] = value;
  323. }
  324. });
  325. return to;
  326. }
  327. /**
  328. * Assign all properties "from" to "to" object.
  329. *
  330. * @param {Object} to - An object where properties are assigned.
  331. * @param {Object} from - An object whose properties are assigned to "to".
  332. *
  333. * @return {Object} - An assigned object.
  334. */
  335. function object_assign(to, from) {
  336. to._s = from;
  337. Object.keys(from).forEach(function (key) {
  338. if (!to[key]) {
  339. Object.defineProperty(to, key, Object.getOwnPropertyDescriptor(from, key));
  340. }
  341. });
  342. return to;
  343. }
  344. // CONCATENATED MODULE: ./src/js/utils/utils.js
  345. /**
  346. * A package of some miscellaneous utility functions.
  347. *
  348. * @author Naotoshi Fujita
  349. * @copyright Naotoshi Fujita. All rights reserved.
  350. */
  351. /**
  352. * Convert the given value to array.
  353. *
  354. * @param {*} value - Any value.
  355. *
  356. * @return {*[]} - Array containing the given value.
  357. */
  358. function toArray(value) {
  359. return Array.isArray(value) ? value : [value];
  360. }
  361. /**
  362. * Check if the given value is between min and max.
  363. * Min will be returned when the value is less than min or max will do when greater than max.
  364. *
  365. * @param {number} value - A number to be checked.
  366. * @param {number} m1 - Minimum or maximum number.
  367. * @param {number} m2 - Maximum or minimum number.
  368. *
  369. * @return {number} - A value itself, min or max.
  370. */
  371. function between(value, m1, m2) {
  372. return Math.min(Math.max(value, m1 > m2 ? m2 : m1), m1 > m2 ? m1 : m2);
  373. }
  374. /**
  375. * The sprintf method with minimum functionality.
  376. *
  377. * @param {string} format - The string format.
  378. * @param {string|Array} replacements - Replacements accepting multiple arguments.
  379. *
  380. * @returns {string} - Converted string.
  381. */
  382. function sprintf(format, replacements) {
  383. var i = 0;
  384. return format.replace(/%s/g, function () {
  385. return toArray(replacements)[i++];
  386. });
  387. }
  388. /**
  389. * Append px unit to the given subject if necessary.
  390. *
  391. * @param {number|string} value - A value that may not include an unit.
  392. *
  393. * @return {string} - If the value is string, return itself.
  394. * If number, do value + "px". An empty string, otherwise.
  395. */
  396. function unit(value) {
  397. var type = typeof value;
  398. if (type === 'number' && value > 0) {
  399. return parseFloat(value) + 'px';
  400. }
  401. return type === 'string' ? value : '';
  402. }
  403. /**
  404. * Pad start with 0.
  405. *
  406. * @param {number} number - A number to be filled with 0.
  407. *
  408. * @return {string|number} - Padded number.
  409. */
  410. function pad(number) {
  411. return number < 10 ? '0' + number : number;
  412. }
  413. /**
  414. * Convert the given value to pixel.
  415. *
  416. * @param {Element} root - Root element where a dummy div is appended.
  417. * @param {string|number} value - CSS value to be converted, such as 10rem.
  418. *
  419. * @return {number} - Pixel.
  420. */
  421. function toPixel(root, value) {
  422. if (typeof value === 'string') {
  423. var div = create('div', {});
  424. applyStyle(div, {
  425. position: 'absolute',
  426. width: value
  427. });
  428. append(root, div);
  429. value = div.clientWidth;
  430. dom_remove(div);
  431. }
  432. return value;
  433. }
  434. // CONCATENATED MODULE: ./src/js/utils/dom.js
  435. /**
  436. * Some utility functions related with DOM.
  437. *
  438. * @author Naotoshi Fujita
  439. * @copyright Naotoshi Fujita. All rights reserved.
  440. */
  441. /**
  442. * Find the first element matching the given selector.
  443. * Be aware that all selectors after a space are ignored.
  444. *
  445. * @param {Element|Node} elm - An ancestor element.
  446. * @param {string} selector - DOMString.
  447. *
  448. * @return {Element|null} - A found element or null.
  449. */
  450. function find(elm, selector) {
  451. return elm ? elm.querySelector(selector.split(' ')[0]) : null;
  452. }
  453. /**
  454. * Find a first child having the given tag or class name.
  455. *
  456. * @param {Element} parent - A parent element.
  457. * @param {string} tagOrClassName - A tag or class name.
  458. *
  459. * @return {Element|null} - A found element on success. Null on failure.
  460. */
  461. function child(parent, tagOrClassName) {
  462. if (parent) {
  463. return values(parent.children).filter(function (child) {
  464. return hasClass(child, tagOrClassName.split(' ')[0]) || child.tagName.toLowerCase() === tagOrClassName;
  465. })[0] || null;
  466. }
  467. return null;
  468. }
  469. /**
  470. * Create an element with some optional attributes.
  471. *
  472. * @param {string} tag - A tag name.
  473. * @param {Object} attrs - An object any attribute pairs of name and value.
  474. *
  475. * @return {Element} - A created element.
  476. */
  477. function create(tag, attrs) {
  478. var elm = document.createElement(tag);
  479. each(attrs, function (value, key) {
  480. return setAttribute(elm, key, value);
  481. });
  482. return elm;
  483. }
  484. /**
  485. * Convert HTML string to DOM node.
  486. *
  487. * @param {string} html - HTML string.
  488. *
  489. * @return {Node} - A created node.
  490. */
  491. function domify(html) {
  492. var div = create('div', {});
  493. div.innerHTML = html;
  494. return div.firstChild;
  495. }
  496. /**
  497. * Remove a given element from a DOM tree.
  498. *
  499. * @param {Element|Element[]} elms - Element(s) to be removed.
  500. */
  501. function dom_remove(elms) {
  502. toArray(elms).forEach(function (elm) {
  503. if (elm && elm.parentElement) {
  504. elm.parentElement.removeChild(elm);
  505. }
  506. });
  507. }
  508. /**
  509. * Append a child to a given element.
  510. *
  511. * @param {Element} parent - A parent element.
  512. * @param {Element} child - An element to be appended.
  513. */
  514. function append(parent, child) {
  515. if (parent) {
  516. parent.appendChild(child);
  517. }
  518. }
  519. /**
  520. * Insert an element before the reference element.
  521. *
  522. * @param {Element|Node} ref - A reference element.
  523. * @param {Element} elm - An element to be inserted.
  524. */
  525. function before(elm, ref) {
  526. if (elm && ref && ref.parentElement) {
  527. ref.parentElement.insertBefore(elm, ref);
  528. }
  529. }
  530. /**
  531. * Apply styles to the given element.
  532. *
  533. * @param {Element} elm - An element where styles are applied.
  534. * @param {Object} styles - Object containing styles.
  535. */
  536. function applyStyle(elm, styles) {
  537. if (elm) {
  538. each(styles, function (value, prop) {
  539. if (value !== null) {
  540. elm.style[prop] = value;
  541. }
  542. });
  543. }
  544. }
  545. /**
  546. * Add or remove classes to/from the element.
  547. * This function is for internal usage.
  548. *
  549. * @param {Element} elm - An element where classes are added.
  550. * @param {string|string[]} classes - Class names being added.
  551. * @param {boolean} remove - Whether to remove or add classes.
  552. */
  553. function addOrRemoveClasses(elm, classes, remove) {
  554. if (elm) {
  555. toArray(classes).forEach(function (name) {
  556. if (name) {
  557. elm.classList[remove ? 'remove' : 'add'](name);
  558. }
  559. });
  560. }
  561. }
  562. /**
  563. * Add classes to the element.
  564. *
  565. * @param {Element} elm - An element where classes are added.
  566. * @param {string|string[]} classes - Class names being added.
  567. */
  568. function addClass(elm, classes) {
  569. addOrRemoveClasses(elm, classes, false);
  570. }
  571. /**
  572. * Remove a class from the element.
  573. *
  574. * @param {Element} elm - An element where classes are removed.
  575. * @param {string|string[]} classes - A class name being removed.
  576. */
  577. function removeClass(elm, classes) {
  578. addOrRemoveClasses(elm, classes, true);
  579. }
  580. /**
  581. * Verify if the provided element has the class or not.
  582. *
  583. * @param {Element} elm - An element.
  584. * @param {string} className - A class name.
  585. *
  586. * @return {boolean} - True if the element has the class or false if not.
  587. */
  588. function hasClass(elm, className) {
  589. return !!elm && elm.classList.contains(className);
  590. }
  591. /**
  592. * Set attribute to the given element.
  593. *
  594. * @param {Element} elm - An element where an attribute is assigned.
  595. * @param {string} name - Attribute name.
  596. * @param {string|number|boolean} value - Attribute value.
  597. */
  598. function setAttribute(elm, name, value) {
  599. if (elm) {
  600. elm.setAttribute(name, value);
  601. }
  602. }
  603. /**
  604. * Get attribute from the given element.
  605. *
  606. * @param {Element} elm - An element where an attribute is assigned.
  607. * @param {string} name - Attribute name.
  608. *
  609. * @return {string} - The value of the given attribute if available. An empty string if not.
  610. */
  611. function getAttribute(elm, name) {
  612. return elm ? elm.getAttribute(name) : '';
  613. }
  614. /**
  615. * Remove attribute from the given element.
  616. *
  617. * @param {Element|Element[]} elms - An element where an attribute is removed.
  618. * @param {string|string[]} names - Attribute name.
  619. */
  620. function removeAttribute(elms, names) {
  621. toArray(names).forEach(function (name) {
  622. toArray(elms).forEach(function (elm) {
  623. return elm && elm.removeAttribute(name);
  624. });
  625. });
  626. }
  627. /**
  628. * Trigger the given callback after all images contained by the element are loaded.
  629. *
  630. * @param {Element} elm - Element that may contain images.
  631. * @param {Function} callback - Callback function fired right after all images are loaded.
  632. */
  633. function dom_loaded(elm, callback) {
  634. var images = elm.querySelectorAll('img');
  635. var length = images.length;
  636. if (length) {
  637. var count = 0;
  638. each(images, function (img) {
  639. img.onload = img.onerror = function () {
  640. if (++count === length) {
  641. callback();
  642. }
  643. };
  644. });
  645. } else {
  646. // Trigger the callback immediately if there is no image.
  647. callback();
  648. }
  649. }
  650. // CONCATENATED MODULE: ./src/js/constants/types.js
  651. /**
  652. * Export slider types.
  653. *
  654. * @author Naotoshi Fujita
  655. * @copyright Naotoshi Fujita. All rights reserved.
  656. */
  657. /**
  658. * Normal slider.
  659. *
  660. * @type {string}
  661. */
  662. var SLIDE = 'slide';
  663. /**
  664. * Loop after the last slide and before the first one.
  665. *
  666. * @type {string}
  667. */
  668. var LOOP = 'loop';
  669. /**
  670. * The track doesn't move.
  671. *
  672. * @type {string}
  673. */
  674. var FADE = 'fade';
  675. // CONCATENATED MODULE: ./src/js/transitions/slide/index.js
  676. /**
  677. * The component for general slide effect transition.
  678. *
  679. * @author Naotoshi Fujita
  680. * @copyright Naotoshi Fujita. All rights reserved.
  681. */
  682. /**
  683. * The component for general slide effect transition.
  684. *
  685. * @param {Splide} Splide - A Splide instance.
  686. * @param {Object} Components - An object containing components.
  687. *
  688. * @return {Object} - The component object.
  689. */
  690. /* harmony default export */ var transitions_slide = (function (Splide, Components) {
  691. /**
  692. * Hold the list element.
  693. *
  694. * @type {Element}
  695. */
  696. var list;
  697. /**
  698. * Hold the onEnd callback function.
  699. *
  700. * @type {function}
  701. */
  702. var endCallback;
  703. return {
  704. /**
  705. * Called when the component is mounted.
  706. */
  707. mount: function mount() {
  708. list = Components.Elements.list;
  709. Splide.on('transitionend', function (e) {
  710. if (e.target === list && endCallback) {
  711. endCallback();
  712. }
  713. }, list);
  714. },
  715. /**
  716. * Start transition.
  717. *
  718. * @param {number} destIndex - Destination slide index that might be clone's.
  719. * @param {number} newIndex - New index.
  720. * @param {number} prevIndex - Previous index.
  721. * @param {Object} coord - Destination coordinates.
  722. * @param {function} done - Callback function must be invoked when transition is completed.
  723. */
  724. start: function start(destIndex, newIndex, prevIndex, coord, done) {
  725. var options = Splide.options;
  726. var edgeIndex = Components.Controller.edgeIndex;
  727. var speed = options.speed;
  728. endCallback = done;
  729. if (Splide.is(SLIDE)) {
  730. if (prevIndex === 0 && newIndex >= edgeIndex || prevIndex >= edgeIndex && newIndex === 0) {
  731. speed = options.rewindSpeed || speed;
  732. }
  733. }
  734. applyStyle(list, {
  735. transition: "transform " + speed + "ms " + options.easing,
  736. transform: "translate(" + coord.x + "px," + coord.y + "px)"
  737. });
  738. }
  739. };
  740. });
  741. // CONCATENATED MODULE: ./src/js/transitions/fade/index.js
  742. /**
  743. * The component for fade transition.
  744. *
  745. * @author Naotoshi Fujita
  746. * @copyright Naotoshi Fujita. All rights reserved.
  747. */
  748. /**
  749. * The component for fade transition.
  750. *
  751. * @param {Splide} Splide - A Splide instance.
  752. * @param {Object} Components - An object containing components.
  753. *
  754. * @return {Object} - The component object.
  755. */
  756. /* harmony default export */ var fade = (function (Splide, Components) {
  757. if (Components.Drag) {
  758. Components.Drag.required = false;
  759. }
  760. var Fade = {
  761. /**
  762. * Called when the component is mounted.
  763. * Apply transition style to the first slide.
  764. */
  765. mount: function mount() {
  766. apply(Splide.index);
  767. },
  768. /**
  769. * Start transition.
  770. *
  771. * @param {number} destIndex - Destination slide index that might be clone's.
  772. * @param {number} newIndex - New index.
  773. * @param {number} prevIndex - Previous index.
  774. * @param {Object} coord - Destination coordinates.
  775. * @param {function} done - Callback function must be invoked when transition is completed.
  776. */
  777. start: function start(destIndex, newIndex, prevIndex, coord, done) {
  778. var track = Components.Elements.track;
  779. applyStyle(track, {
  780. height: unit(track.clientHeight)
  781. });
  782. apply(newIndex);
  783. done();
  784. applyStyle(track, {
  785. height: ''
  786. });
  787. }
  788. };
  789. /**
  790. * Apply transition style to the slide specified by the given index.
  791. *
  792. * @param {number} index - A slide index.
  793. */
  794. function apply(index) {
  795. var options = Splide.options;
  796. applyStyle(Components.Elements.slides[index], {
  797. transition: "opacity " + options.speed + "ms " + options.easing
  798. });
  799. }
  800. return Fade;
  801. });
  802. // CONCATENATED MODULE: ./src/js/transitions/index.js
  803. /**
  804. * Export transition components.
  805. *
  806. * @author Naotoshi Fujita
  807. * @copyright Naotoshi Fujita. All rights reserved.
  808. */
  809. // CONCATENATED MODULE: ./src/js/core/composer.js
  810. /**
  811. * Provide a function for composing components.
  812. *
  813. * @author Naotoshi Fujita
  814. * @copyright Naotoshi Fujita. All rights reserved.
  815. */
  816. /**
  817. * Compose components.
  818. *
  819. * @param {Splide} Splide - Splide instance.
  820. * @param {Object} Components - Additional components.
  821. * @param {function} Transition - Change component for transition.
  822. *
  823. * @return {Object} - An object containing all components.
  824. */
  825. function compose(Splide, Components, Transition) {
  826. var components = {};
  827. each(Components, function (Component, name) {
  828. components[name] = Component(Splide, components, name.toLowerCase());
  829. });
  830. if (!Transition) {
  831. Transition = Splide.is(FADE) ? fade : transitions_slide;
  832. }
  833. components.Transition = Transition(Splide, components);
  834. return components;
  835. }
  836. // CONCATENATED MODULE: ./src/js/utils/error.js
  837. /**
  838. * Utility functions for outputting logs.
  839. *
  840. * @author Naotoshi Fujita
  841. * @copyright Naotoshi Fujita. All rights reserved.
  842. */
  843. /**
  844. * Prefix of an error massage.
  845. *
  846. * @type {string}
  847. */
  848. var MESSAGE_PREFIX = '[SPLIDE]';
  849. /**
  850. * Display an error message on the browser console.
  851. *
  852. * @param {string} message - An error message.
  853. */
  854. function error_error(message) {
  855. console.error(MESSAGE_PREFIX + " " + message);
  856. }
  857. /**
  858. * Check existence of the given object and throw an error if it doesn't.
  859. *
  860. * @throws {Error}
  861. *
  862. * @param {*} subject - A subject to be confirmed.
  863. * @param {string} message - An error message.
  864. */
  865. function exist(subject, message) {
  866. if (!subject) {
  867. throw new Error(message);
  868. }
  869. }
  870. // CONCATENATED MODULE: ./src/js/constants/classes.js
  871. /**
  872. * Export class names.
  873. *
  874. * @author Naotoshi Fujita
  875. * @copyright Naotoshi Fujita. All rights reserved.
  876. */
  877. /**
  878. * A root class name.
  879. *
  880. * @type {string}
  881. */
  882. var ROOT = 'splide';
  883. /**
  884. * The definition table of all classes for elements.
  885. * They might be modified by options.
  886. *
  887. * @type {Object}
  888. */
  889. var ELEMENT_CLASSES = {
  890. root: ROOT,
  891. slider: ROOT + "__slider",
  892. track: ROOT + "__track",
  893. list: ROOT + "__list",
  894. slide: ROOT + "__slide",
  895. container: ROOT + "__slide__container",
  896. arrows: ROOT + "__arrows",
  897. arrow: ROOT + "__arrow",
  898. prev: ROOT + "__arrow--prev",
  899. next: ROOT + "__arrow--next",
  900. pagination: ROOT + "__pagination",
  901. page: ROOT + "__pagination__page",
  902. clone: ROOT + "__slide--clone",
  903. progress: ROOT + "__progress",
  904. bar: ROOT + "__progress__bar",
  905. autoplay: ROOT + "__autoplay",
  906. play: ROOT + "__play",
  907. pause: ROOT + "__pause",
  908. spinner: ROOT + "__spinner",
  909. sr: ROOT + "__sr"
  910. };
  911. /**
  912. * Definitions of status classes.
  913. *
  914. * @type {Object}
  915. */
  916. var STATUS_CLASSES = {
  917. active: 'is-active',
  918. visible: 'is-visible',
  919. loading: 'is-loading'
  920. };
  921. // CONCATENATED MODULE: ./src/js/constants/i18n.js
  922. /**
  923. * Export i18n texts as object.
  924. *
  925. * @author Naotoshi Fujita
  926. * @copyright Naotoshi Fujita. All rights reserved.
  927. */
  928. /**
  929. * Texts for i18n.
  930. *
  931. * @type {Object}
  932. */
  933. var I18N = {
  934. prev: 'Previous slide',
  935. next: 'Next slide',
  936. first: 'Go to first slide',
  937. last: 'Go to last slide',
  938. slideX: 'Go to slide %s',
  939. pageX: 'Go to page %s',
  940. play: 'Start autoplay',
  941. pause: 'Pause autoplay'
  942. };
  943. // CONCATENATED MODULE: ./src/js/constants/defaults.js
  944. /**
  945. * Export default options.
  946. *
  947. * @author Naotoshi Fujita
  948. * @copyright Naotoshi Fujita. All rights reserved.
  949. */
  950. var DEFAULTS = {
  951. /**
  952. * Determine a slider type.
  953. * - 'slide': Regular slider.
  954. * - 'loop' : Carousel slider.
  955. * - 'fade' : Change slides with fade transition. perPage, drag options are ignored.
  956. *
  957. * @type {string}
  958. */
  959. type: 'slide',
  960. /**
  961. * Whether to rewind a slider before the first slide or after the last one.
  962. * In "loop" mode, this option is ignored.
  963. *
  964. * @type {boolean}
  965. */
  966. rewind: false,
  967. /**
  968. * Transition speed in milliseconds.
  969. *
  970. * @type {number}
  971. */
  972. speed: 400,
  973. /**
  974. * Transition speed on rewind in milliseconds.
  975. *
  976. * @type {number}
  977. */
  978. rewindSpeed: 0,
  979. /**
  980. * Define slider max width.
  981. *
  982. * @type {number}
  983. */
  984. width: 0,
  985. /**
  986. * Define slider height.
  987. *
  988. * @type {number}
  989. */
  990. height: 0,
  991. /**
  992. * Fix width of slides. CSS format is allowed such as 10em, 80% or 80vw.
  993. * perPage number will be ignored when this option is falsy.
  994. *
  995. * @type {number|string}
  996. */
  997. fixedWidth: 0,
  998. /**
  999. * Fix height of slides. CSS format is allowed such as 10em, 80vh but % unit is not accepted.
  1000. * heightRatio option will be ignored when this option is falsy.
  1001. *
  1002. * @type {number}
  1003. */
  1004. fixedHeight: 0,
  1005. /**
  1006. * Determine height of slides by ratio to a slider width.
  1007. * This will be ignored when the fixedHeight is provided.
  1008. *
  1009. * @type {number}
  1010. */
  1011. heightRatio: 0,
  1012. /**
  1013. * If true, slide width will be determined by the element width itself.
  1014. * - perPage/perMove should be 1.
  1015. * - lazyLoad should be false.
  1016. *
  1017. * @type {boolean}
  1018. */
  1019. autoWidth: false,
  1020. /**
  1021. * Determine how many slides should be displayed per page.
  1022. *
  1023. * @type {number}
  1024. */
  1025. perPage: 1,
  1026. /**
  1027. * Determine how many slides should be moved when a slider goes to next or perv.
  1028. *
  1029. * @type {number}
  1030. */
  1031. perMove: 0,
  1032. /**
  1033. * Start index.
  1034. *
  1035. * @type {number}
  1036. */
  1037. start: 0,
  1038. /**
  1039. * Determine which slide should be focused if there are multiple slides in a page.
  1040. * A string "center" is acceptable for centering slides.
  1041. *
  1042. * @type {boolean|number|string}
  1043. */
  1044. focus: false,
  1045. /**
  1046. * Gap between slides. CSS format is allowed such as 1em.
  1047. *
  1048. * @type {number|string}
  1049. */
  1050. gap: 0,
  1051. /**
  1052. * Set padding-left/right in horizontal mode or padding-top/bottom in vertical one.
  1053. * Give a single value to set a same size for both sides or
  1054. * do an object for different sizes.
  1055. * Also, CSS format is allowed such as 1em.
  1056. *
  1057. * @example
  1058. * - 10: Number
  1059. * - '1em': CSS format.
  1060. * - { left: 0, right: 20 }: Object for different sizes in horizontal mode.
  1061. * - { top: 0, bottom: 20 }: Object for different sizes in vertical mode.
  1062. *
  1063. * @type {number|string|Object}
  1064. */
  1065. padding: 0,
  1066. /**
  1067. * Whether to append arrows.
  1068. *
  1069. * @type {boolean}
  1070. */
  1071. arrows: true,
  1072. /**
  1073. * Change the arrow SVG path like 'm7.61 0.807-2.12...'.
  1074. *
  1075. * @type {string}
  1076. */
  1077. arrowPath: '',
  1078. /**
  1079. * Whether to append pagination(indicator dots) or not.
  1080. *
  1081. * @type {boolean}
  1082. */
  1083. pagination: true,
  1084. /**
  1085. * Activate autoplay.
  1086. *
  1087. * @type {boolean}
  1088. */
  1089. autoplay: false,
  1090. /**
  1091. * Autoplay interval in milliseconds.
  1092. *
  1093. * @type {number}
  1094. */
  1095. interval: 5000,
  1096. /**
  1097. * Whether to stop autoplay when a slider is hovered.
  1098. *
  1099. * @type {boolean}
  1100. */
  1101. pauseOnHover: true,
  1102. /**
  1103. * Whether to stop autoplay when a slider elements are focused.
  1104. * True is recommended for accessibility.
  1105. *
  1106. * @type {boolean}
  1107. */
  1108. pauseOnFocus: true,
  1109. /**
  1110. * Loading images lazily.
  1111. * Image src must be provided by a data-splide-lazy attribute.
  1112. *
  1113. * - false: Do nothing.
  1114. * - 'nearby': Only images around an active slide will be loaded.
  1115. * - 'sequential': All images will be sequentially loaded.
  1116. *
  1117. * @type {boolean|string}
  1118. */
  1119. lazyLoad: false,
  1120. /**
  1121. * This option works only when a lazyLoad option is "nearby".
  1122. * Determine how many pages(not slides) around an active slide should be loaded beforehand.
  1123. *
  1124. * @type {number}
  1125. */
  1126. preloadPages: 1,
  1127. /**
  1128. * Easing for CSS transition. For example, linear, ease or cubic-bezier().
  1129. *
  1130. * @type {string}
  1131. */
  1132. easing: 'cubic-bezier(.42,.65,.27,.99)',
  1133. /**
  1134. * Whether to control a slide via keyboard.
  1135. *
  1136. * @type {boolean}
  1137. */
  1138. keyboard: true,
  1139. /**
  1140. * Whether to allow mouse drag and touch swipe.
  1141. *
  1142. * @type {boolean}
  1143. */
  1144. drag: true,
  1145. /**
  1146. * The angle threshold for drag.
  1147. * The slider starts moving only when the drag angle is less than this threshold.
  1148. *
  1149. * @type {number}
  1150. */
  1151. dragAngleThreshold: 30,
  1152. /**
  1153. * Distance threshold for determining if the action is "flick" or "swipe".
  1154. * When a drag distance is over this value, the action will be treated as "swipe", not "flick".
  1155. *
  1156. * @type {number}
  1157. */
  1158. swipeDistanceThreshold: 150,
  1159. /**
  1160. * Velocity threshold for determining if the action is "flick" or "swipe".
  1161. * Around 0.5 is recommended.
  1162. *
  1163. * @type {number}
  1164. */
  1165. flickVelocityThreshold: .6,
  1166. /**
  1167. * Determine power of flick. The larger number this is, the farther a slider runs by flick.
  1168. * Around 500 is recommended.
  1169. *
  1170. * @type {number}
  1171. */
  1172. flickPower: 600,
  1173. /**
  1174. * Limit a number of pages to move by flick.
  1175. *
  1176. * @type {number}
  1177. */
  1178. flickMaxPages: 1,
  1179. /**
  1180. * Slider direction.
  1181. * - 'ltr': Left to right.
  1182. * - 'rtl': Right to left.
  1183. * - 'ttb': Top to bottom.
  1184. *
  1185. * @type {string}
  1186. */
  1187. direction: 'ltr',
  1188. /**
  1189. * Set img src to background-image of its parent element.
  1190. * Images with various sizes can be displayed as same dimension without cropping work.
  1191. * fixedHeight or heightRatio is required.
  1192. *
  1193. * @type {boolean}
  1194. */
  1195. cover: false,
  1196. /**
  1197. * Whether to enable accessibility(aria and screen reader texts) or not.
  1198. *
  1199. * @type {boolean}
  1200. */
  1201. accessibility: true,
  1202. /**
  1203. * Determine if a slider is navigation for another.
  1204. * Use "sync" API to synchronize two sliders.
  1205. *
  1206. * @type {boolean}
  1207. */
  1208. isNavigation: false,
  1209. /**
  1210. * Whether to trim spaces before the fist slide or after the last one when "focus" is not 0.
  1211. *
  1212. * @type {boolean}
  1213. */
  1214. trimSpace: true,
  1215. /**
  1216. * Slide status is updated after move as default.
  1217. * If true, it will be updated before move.
  1218. *
  1219. * @type {boolean}
  1220. */
  1221. updateOnMove: false,
  1222. /**
  1223. * Breakpoints definitions.
  1224. *
  1225. * @example
  1226. * {
  1227. * '1000': {
  1228. * perPage: 3,
  1229. * gap: 20
  1230. * },
  1231. * '600': {
  1232. * perPage: 1,
  1233. * gap: 5,
  1234. * }
  1235. * }
  1236. *
  1237. * @type {boolean|Object}
  1238. */
  1239. breakpoints: false,
  1240. /**
  1241. * Collection of class names.
  1242. *
  1243. * @see ./classes.js
  1244. *
  1245. * @type {Object}
  1246. */
  1247. classes: ELEMENT_CLASSES,
  1248. /**
  1249. * Collection of i18n texts.
  1250. *
  1251. * @see ./i18n.js
  1252. *
  1253. * @type {Object}
  1254. */
  1255. i18n: I18N
  1256. };
  1257. // CONCATENATED MODULE: ./src/js/constants/states.js
  1258. /**
  1259. * Export state constants.
  1260. *
  1261. * @author Naotoshi Fujita
  1262. * @copyright Naotoshi Fujita. All rights reserved.
  1263. */
  1264. /**
  1265. * Splide has been just created.
  1266. *
  1267. * @type {number}
  1268. */
  1269. var CREATED = 1;
  1270. /**
  1271. * All components have been mounted and initialized.
  1272. *
  1273. * @type {number}
  1274. */
  1275. var MOUNTED = 2;
  1276. /**
  1277. * Splide is ready for transition.
  1278. *
  1279. * @type {number}
  1280. */
  1281. var IDLE = 3;
  1282. /**
  1283. * Splide is moving.
  1284. *
  1285. * @type {number}
  1286. */
  1287. var MOVING = 4;
  1288. /**
  1289. * Splide is moving.
  1290. *
  1291. * @type {number}
  1292. */
  1293. var DESTROYED = 5;
  1294. // CONCATENATED MODULE: ./src/js/splide.js
  1295. 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); } }
  1296. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  1297. /**
  1298. * The main class for applying Splide to an element.
  1299. *
  1300. * @author Naotoshi Fujita
  1301. * @copyright Naotoshi Fujita. All rights reserved.
  1302. */
  1303. /**
  1304. * The main class for applying Splide to an element,
  1305. * providing some APIs to control the behavior.
  1306. */
  1307. var splide_Splide = /*#__PURE__*/function () {
  1308. /**
  1309. * Splide constructor.
  1310. *
  1311. * @throws {Error} When the given root element or selector is invalid.
  1312. *
  1313. * @param {Element|string} root - A selector for a root element or an element itself.
  1314. * @param {Object} options - Optional. Options to change default behaviour.
  1315. * @param {Object} Components - Optional. Components.
  1316. */
  1317. function Splide(root, options, Components) {
  1318. if (options === void 0) {
  1319. options = {};
  1320. }
  1321. if (Components === void 0) {
  1322. Components = {};
  1323. }
  1324. this.root = root instanceof Element ? root : document.querySelector(root);
  1325. exist(this.root, 'An invalid element/selector was given.');
  1326. this.Components = null;
  1327. this.Event = core_event();
  1328. this.State = state(CREATED);
  1329. this.STATES = states_namespaceObject;
  1330. this._o = merge(DEFAULTS, options);
  1331. this._i = 0;
  1332. this._c = Components;
  1333. }
  1334. /**
  1335. * Compose and mount components.
  1336. *
  1337. * @param {Object} Extensions - Optional. Additional components.
  1338. * @param {function} Transition - Optional. Set a custom transition component.
  1339. *
  1340. * @return {Splide|null} - This instance or null if an exception occurred.
  1341. */
  1342. var _proto = Splide.prototype;
  1343. _proto.mount = function mount(Extensions, Transition) {
  1344. var _this = this;
  1345. if (Extensions === void 0) {
  1346. Extensions = {};
  1347. }
  1348. if (Transition === void 0) {
  1349. Transition = null;
  1350. }
  1351. this.Components = this.Components || compose(this, merge(this._c, Extensions), Transition);
  1352. try {
  1353. each(this.Components, function (component, key) {
  1354. var required = component.required;
  1355. if (required === undefined || required) {
  1356. component.mount && component.mount();
  1357. } else {
  1358. delete _this.Components[key];
  1359. }
  1360. });
  1361. } catch (e) {
  1362. error_error(e.message);
  1363. return null;
  1364. }
  1365. this.State.set(MOUNTED);
  1366. each(this.Components, function (component) {
  1367. component.mounted && component.mounted();
  1368. });
  1369. this.emit('mounted');
  1370. this.State.set(IDLE);
  1371. this.emit('ready');
  1372. applyStyle(this.root, {
  1373. visibility: 'visible'
  1374. });
  1375. this.on('move drag', function () {
  1376. return _this.State.set(MOVING);
  1377. }).on('moved dragged', function () {
  1378. return _this.State.set(IDLE);
  1379. });
  1380. return this;
  1381. }
  1382. /**
  1383. * Set sync target.
  1384. *
  1385. * @param {Splide} splide - A Splide instance.
  1386. *
  1387. * @return {Splide} - This instance.
  1388. */
  1389. ;
  1390. _proto.sync = function sync(splide) {
  1391. this.sibling = splide;
  1392. return this;
  1393. }
  1394. /**
  1395. * Register callback fired on the given event(s).
  1396. *
  1397. * @param {string} events - An event name. Use space to separate multiple events.
  1398. * Also, namespace is accepted by dot, such as 'resize.{namespace}'.
  1399. * @param {function} handler - A callback function.
  1400. * @param {Element} elm - Optional. Native event will be listened to when this arg is provided.
  1401. * @param {Object} options - Optional. Options for addEventListener.
  1402. *
  1403. * @return {Splide} - This instance.
  1404. */
  1405. ;
  1406. _proto.on = function on(events, handler, elm, options) {
  1407. if (elm === void 0) {
  1408. elm = null;
  1409. }
  1410. if (options === void 0) {
  1411. options = {};
  1412. }
  1413. this.Event.on(events, handler, elm, options);
  1414. return this;
  1415. }
  1416. /**
  1417. * Unsubscribe the given event.
  1418. *
  1419. * @param {string} events - A event name.
  1420. * @param {Element} elm - Optional. removeEventListener() will be called when this arg is provided.
  1421. *
  1422. * @return {Splide} - This instance.
  1423. */
  1424. ;
  1425. _proto.off = function off(events, elm) {
  1426. if (elm === void 0) {
  1427. elm = null;
  1428. }
  1429. this.Event.off(events, elm);
  1430. return this;
  1431. }
  1432. /**
  1433. * Emit an event.
  1434. *
  1435. * @param {string} event - An event name.
  1436. * @param {*} args - Any number of arguments passed to handlers.
  1437. */
  1438. ;
  1439. _proto.emit = function emit(event) {
  1440. var _this$Event;
  1441. for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  1442. args[_key - 1] = arguments[_key];
  1443. }
  1444. (_this$Event = this.Event).emit.apply(_this$Event, [event].concat(args));
  1445. return this;
  1446. }
  1447. /**
  1448. * Go to the slide specified by the given control.
  1449. *
  1450. * @param {string|number} control - A control pattern.
  1451. * @param {boolean} wait - Optional. Whether to wait for transition.
  1452. */
  1453. ;
  1454. _proto.go = function go(control, wait) {
  1455. if (wait === void 0) {
  1456. wait = true;
  1457. }
  1458. if (this.State.is(IDLE) || this.State.is(MOVING) && !wait) {
  1459. this.Components.Controller.go(control, false);
  1460. }
  1461. return this;
  1462. }
  1463. /**
  1464. * Verify whether the slider type is the given one or not.
  1465. *
  1466. * @param {string} type - A slider type.
  1467. *
  1468. * @return {boolean} - True if the slider type is the provided type or false if not.
  1469. */
  1470. ;
  1471. _proto.is = function is(type) {
  1472. return type === this._o.type;
  1473. }
  1474. /**
  1475. * Insert a slide.
  1476. *
  1477. * @param {Element|string} slide - A slide element to be added.
  1478. * @param {number} index - A slide will be added at the position.
  1479. */
  1480. ;
  1481. _proto.add = function add(slide, index) {
  1482. if (index === void 0) {
  1483. index = -1;
  1484. }
  1485. this.Components.Elements.add(slide, index, this.refresh.bind(this));
  1486. return this;
  1487. }
  1488. /**
  1489. * Remove the slide designated by the index.
  1490. *
  1491. * @param {number} index - A slide index.
  1492. */
  1493. ;
  1494. _proto.remove = function remove(index) {
  1495. this.Components.Elements.remove(index);
  1496. this.refresh();
  1497. return this;
  1498. }
  1499. /**
  1500. * Destroy all Slide objects and clones and recreate them again.
  1501. */
  1502. ;
  1503. _proto.refresh = function refresh() {
  1504. this.emit('refresh').emit('resize');
  1505. return this;
  1506. }
  1507. /**
  1508. * Destroy the Splide.
  1509. * "Completely" boolean is mainly for breakpoints.
  1510. *
  1511. * @param {boolean} completely - Destroy completely.
  1512. */
  1513. ;
  1514. _proto.destroy = function destroy(completely) {
  1515. var _this2 = this;
  1516. if (completely === void 0) {
  1517. completely = true;
  1518. }
  1519. // Postpone destroy because it should be done after mount.
  1520. if (this.State.is(CREATED)) {
  1521. this.on('ready', function () {
  1522. return _this2.destroy(completely);
  1523. });
  1524. return;
  1525. }
  1526. values(this.Components).reverse().forEach(function (component) {
  1527. component.destroy && component.destroy(completely);
  1528. });
  1529. this.emit('destroy', completely); // Destroy all event handlers, including ones for native events.
  1530. this.Event.destroy();
  1531. this.State.set(DESTROYED);
  1532. return this;
  1533. }
  1534. /**
  1535. * Return the current slide index.
  1536. *
  1537. * @return {number} - The current slide index.
  1538. // */
  1539. ;
  1540. _createClass(Splide, [{
  1541. key: "index",
  1542. get: function get() {
  1543. return this._i;
  1544. }
  1545. /**
  1546. * Set the current slide index.
  1547. *
  1548. * @param {number|string} index - A new index.
  1549. */
  1550. ,
  1551. set: function set(index) {
  1552. this._i = parseInt(index);
  1553. }
  1554. /**
  1555. * Return length of slides.
  1556. * This is an alias of Elements.length.
  1557. *
  1558. * @return {number} - A number of slides.
  1559. */
  1560. }, {
  1561. key: "length",
  1562. get: function get() {
  1563. return this.Components.Elements.length;
  1564. }
  1565. /**
  1566. * Return options.
  1567. *
  1568. * @return {Object} - Options object.
  1569. */
  1570. }, {
  1571. key: "options",
  1572. get: function get() {
  1573. return this._o;
  1574. }
  1575. /**
  1576. * Set options with merging the given object to the current one.
  1577. *
  1578. * @param {Object} options - New options.
  1579. */
  1580. ,
  1581. set: function set(options) {
  1582. var created = this.State.is(CREATED);
  1583. if (!created) {
  1584. this.emit('update');
  1585. }
  1586. this._o = merge(this._o, options);
  1587. if (!created) {
  1588. this.emit('updated', this._o);
  1589. }
  1590. }
  1591. /**
  1592. * Return the class list.
  1593. * This is an alias of Splide.options.classList.
  1594. *
  1595. * @return {Object} - An object containing all class list.
  1596. */
  1597. }, {
  1598. key: "classes",
  1599. get: function get() {
  1600. return this._o.classes;
  1601. }
  1602. /**
  1603. * Return the i18n strings.
  1604. * This is an alias of Splide.options.i18n.
  1605. *
  1606. * @return {Object} - An object containing all i18n strings.
  1607. */
  1608. }, {
  1609. key: "i18n",
  1610. get: function get() {
  1611. return this._o.i18n;
  1612. }
  1613. }]);
  1614. return Splide;
  1615. }();
  1616. // CONCATENATED MODULE: ./src/js/components/options/index.js
  1617. /**
  1618. * The component for initializing options.
  1619. *
  1620. * @author Naotoshi Fujita
  1621. * @copyright Naotoshi Fujita. All rights reserved.
  1622. */
  1623. /**
  1624. * The component for initializing options.
  1625. *
  1626. * @param {Splide} Splide - A Splide instance.
  1627. *
  1628. * @return {Object} - The component object.
  1629. */
  1630. /* harmony default export */ var components_options = (function (Splide) {
  1631. /**
  1632. * Retrieve options from the data attribute.
  1633. * Note that IE10 doesn't support dataset property.
  1634. *
  1635. * @type {string}
  1636. */
  1637. var options = getAttribute(Splide.root, 'data-splide');
  1638. if (options) {
  1639. try {
  1640. Splide.options = JSON.parse(options);
  1641. } catch (e) {
  1642. error_error(e.message);
  1643. }
  1644. }
  1645. return {
  1646. /**
  1647. * Called when the component is mounted.
  1648. */
  1649. mount: function mount() {
  1650. if (Splide.State.is(CREATED)) {
  1651. Splide.index = Splide.options.start;
  1652. }
  1653. }
  1654. };
  1655. });
  1656. // CONCATENATED MODULE: ./src/js/constants/directions.js
  1657. /**
  1658. * Export layout modes.
  1659. *
  1660. * @author Naotoshi Fujita
  1661. * @copyright Naotoshi Fujita. All rights reserved.
  1662. */
  1663. /**
  1664. * Enumerate slides from left to right.
  1665. *
  1666. * @type {string}
  1667. */
  1668. var LTR = 'ltr';
  1669. /**
  1670. * Enumerate slides from right to left.
  1671. *
  1672. * @type {string}
  1673. */
  1674. var RTL = 'rtl';
  1675. /**
  1676. * Enumerate slides in a col.
  1677. *
  1678. * @type {string}
  1679. */
  1680. var TTB = 'ttb';
  1681. // CONCATENATED MODULE: ./src/js/components/elements/slide.js
  1682. /**
  1683. * The sub component for handling each slide.
  1684. *
  1685. * @author Naotoshi Fujita
  1686. * @copyright Naotoshi Fujita. All rights reserved.
  1687. */
  1688. /**
  1689. * Events for restoring original styles.
  1690. *
  1691. * @type {string}
  1692. */
  1693. var STYLE_RESTORE_EVENTS = 'update.slide';
  1694. /**
  1695. * The sub component for handling each slide.
  1696. *
  1697. * @param {Splide} Splide - A Splide instance.
  1698. * @param {number} index - An unique slide index.
  1699. * @param {number} realIndex - Clones should pass a real slide index.
  1700. * @param {Element} slide - A slide element.
  1701. *
  1702. * @return {Object} - The sub component object.
  1703. */
  1704. /* harmony default export */ var elements_slide = (function (Splide, index, realIndex, slide) {
  1705. /**
  1706. * Events when the slide status is updated.
  1707. * Append a namespace to remove listeners later.
  1708. *
  1709. * @type {string}
  1710. */
  1711. var STATUS_UPDATE_EVENTS = 'ready.slide updated.slide resize.slide ' + (Splide.options.updateOnMove ? 'move.slide' : 'moved.slide');
  1712. /**
  1713. * Slide sub component object.
  1714. *
  1715. * @type {Object}
  1716. */
  1717. var Slide = {
  1718. /**
  1719. * Slide element.
  1720. *
  1721. * @type {Element}
  1722. */
  1723. slide: slide,
  1724. /**
  1725. * Slide index.
  1726. *
  1727. * @type {number}
  1728. */
  1729. index: index,
  1730. /**
  1731. * Real index for clones.
  1732. *
  1733. * @type {number}
  1734. */
  1735. realIndex: realIndex,
  1736. /**
  1737. * Container element if available.
  1738. *
  1739. * @type {Element|null}
  1740. */
  1741. container: find(slide, "." + Splide.classes.container),
  1742. /**
  1743. * Whether this is a cloned slide or not.
  1744. *
  1745. * @type {boolean}
  1746. */
  1747. isClone: realIndex > -1,
  1748. /**
  1749. * Hold the original styles.
  1750. *
  1751. * @type {string}
  1752. */
  1753. styles: getAttribute(slide, 'style') || '',
  1754. /**
  1755. * Called when the component is mounted.
  1756. */
  1757. mount: function mount() {
  1758. var _this = this;
  1759. if (!this.isClone) {
  1760. slide.id = Splide.root.id + "-slide" + pad(index + 1);
  1761. }
  1762. Splide.on(STATUS_UPDATE_EVENTS, function () {
  1763. return _this.update();
  1764. }).on(STYLE_RESTORE_EVENTS, restoreStyles);
  1765. },
  1766. /**
  1767. * Destroy.
  1768. */
  1769. destroy: function destroy() {
  1770. Splide.off(STATUS_UPDATE_EVENTS).off(STYLE_RESTORE_EVENTS);
  1771. removeClass(slide, values(STATUS_CLASSES));
  1772. restoreStyles();
  1773. },
  1774. /**
  1775. * Update active and visible status.
  1776. */
  1777. update: function update() {
  1778. _update(this.isActive(), false);
  1779. _update(this.isVisible(), true);
  1780. },
  1781. /**
  1782. * Check whether this slide is active or not.
  1783. *
  1784. * @return {boolean} - True if the slide is active or false if not.
  1785. */
  1786. isActive: function isActive() {
  1787. return Splide.index === index;
  1788. },
  1789. /**
  1790. * Check whether this slide is visible in the viewport or not.
  1791. *
  1792. * @return {boolean} - True if the slide is visible or false if not.
  1793. */
  1794. isVisible: function isVisible() {
  1795. var active = this.isActive();
  1796. if (Splide.is(FADE) || active) {
  1797. return active;
  1798. }
  1799. var floor = Math.floor;
  1800. var Components = Splide.Components;
  1801. var Track = Components.Track;
  1802. var Layout = Components.Layout;
  1803. var isVertical = Splide.options.direction === TTB;
  1804. var position = floor((Track.toPosition(index) + Track.offset(index) - Track.position) * Track.sign);
  1805. var edge = floor(position + Layout[isVertical ? 'slideHeight' : 'slideWidth'](index));
  1806. var size = Layout[isVertical ? 'height' : 'width'];
  1807. return 0 <= position && position <= size && 0 <= edge && edge <= size;
  1808. },
  1809. /**
  1810. * Calculate how far this slide is from another slide and
  1811. * return true if the distance is within the given number.
  1812. *
  1813. * @param {number} from - Index of a target slide.
  1814. * @param {number} within - True if the slide is within this number.
  1815. *
  1816. * @return {boolean} - True if the slide is within the number or false otherwise.
  1817. */
  1818. isWithin: function isWithin(from, within) {
  1819. var diff = Math.abs(from - index);
  1820. if (!Splide.is(SLIDE) && !this.isClone) {
  1821. diff = Math.min(diff, Splide.length - diff);
  1822. }
  1823. return diff < within;
  1824. }
  1825. };
  1826. /**
  1827. * Update classes for activity or visibility.
  1828. *
  1829. * @param {boolean} active - Is active/visible or not.
  1830. * @param {boolean} forVisibility - Toggle classes for activity or visibility.
  1831. */
  1832. function _update(active, forVisibility) {
  1833. var type = forVisibility ? 'visible' : 'active';
  1834. var className = STATUS_CLASSES[type];
  1835. if (active) {
  1836. addClass(slide, className);
  1837. Splide.emit("" + type, Slide);
  1838. } else {
  1839. if (hasClass(slide, className)) {
  1840. removeClass(slide, className);
  1841. Splide.emit("" + (forVisibility ? 'hidden' : 'inactive'), Slide);
  1842. }
  1843. }
  1844. }
  1845. /**
  1846. * Restore the original styles.
  1847. */
  1848. function restoreStyles() {
  1849. setAttribute(slide, 'style', Slide.styles);
  1850. }
  1851. return Slide;
  1852. });
  1853. // CONCATENATED MODULE: ./src/js/components/elements/index.js
  1854. /**
  1855. * The component for main elements.
  1856. *
  1857. * @author Naotoshi Fujita
  1858. * @copyright Naotoshi Fujita. All rights reserved.
  1859. */
  1860. /**
  1861. * The property name for UID stored in a window object.
  1862. *
  1863. * @type {string}
  1864. */
  1865. var UID_NAME = 'uid';
  1866. /**
  1867. * The component for main elements.
  1868. *
  1869. * @param {Splide} Splide - A Splide instance.
  1870. * @param {Object} Components - An object containing components.
  1871. *
  1872. * @return {Object} - The component object.
  1873. */
  1874. /* harmony default export */ var components_elements = (function (Splide, Components) {
  1875. /**
  1876. * Hold the root element.
  1877. *
  1878. * @type {Element}
  1879. */
  1880. var root = Splide.root;
  1881. /**
  1882. * Hold the class list.
  1883. *
  1884. * @type {Object}
  1885. */
  1886. var classes = Splide.classes;
  1887. /**
  1888. * Store Slide objects.
  1889. *
  1890. * @type {Array}
  1891. */
  1892. var Slides = [];
  1893. /*
  1894. * Assign unique ID to the root element if it doesn't have the one.
  1895. * Note that IE doesn't support padStart() to fill the uid by 0.
  1896. */
  1897. if (!root.id) {
  1898. window.splide = window.splide || {};
  1899. var uid = window.splide[UID_NAME] || 0;
  1900. window.splide[UID_NAME] = ++uid;
  1901. root.id = "splide" + pad(uid);
  1902. }
  1903. /**
  1904. * Elements component object.
  1905. *
  1906. * @type {Object}
  1907. */
  1908. var Elements = {
  1909. /**
  1910. * Called when the component is mounted.
  1911. * Collect main elements and store them as member properties.
  1912. */
  1913. mount: function mount() {
  1914. var _this = this;
  1915. collect();
  1916. this.init();
  1917. Splide.on('refresh', function () {
  1918. _this.destroy();
  1919. _this.init();
  1920. });
  1921. Splide.on('updated', function () {
  1922. removeClass(root, getClasses());
  1923. addClass(root, getClasses());
  1924. });
  1925. },
  1926. /**
  1927. * Destroy.
  1928. */
  1929. destroy: function destroy() {
  1930. Slides.forEach(function (Slide) {
  1931. Slide.destroy();
  1932. });
  1933. Slides = [];
  1934. removeClass(root, getClasses());
  1935. },
  1936. /**
  1937. * Initialization.
  1938. */
  1939. init: function init() {
  1940. addClass(root, getClasses());
  1941. Elements.slides.forEach(function (slide, index) {
  1942. Elements.register(slide, index, -1);
  1943. });
  1944. },
  1945. /**
  1946. * Register a slide to create a Slide object and handle its behavior.
  1947. *
  1948. * @param {Element} slide - A slide element.
  1949. * @param {number} index - A unique index. This can be negative.
  1950. * @param {number} realIndex - A real index for clones. Set -1 for real slides.
  1951. */
  1952. register: function register(slide, index, realIndex) {
  1953. var SlideObject = elements_slide(Splide, index, realIndex, slide);
  1954. SlideObject.mount();
  1955. Slides.push(SlideObject);
  1956. },
  1957. /**
  1958. * Return the Slide object designated by the index.
  1959. * Note that "find" is not supported by IE.
  1960. *
  1961. * @return {Object|undefined} - A Slide object if available. Undefined if not.
  1962. */
  1963. getSlide: function getSlide(index) {
  1964. return Slides.filter(function (Slide) {
  1965. return Slide.index === index;
  1966. })[0];
  1967. },
  1968. /**
  1969. * Return all Slide objects.
  1970. *
  1971. * @param {boolean} includeClones - Whether to include cloned slides or not.
  1972. *
  1973. * @return {Object[]} - Slide objects.
  1974. */
  1975. getSlides: function getSlides(includeClones) {
  1976. return includeClones ? Slides : Slides.filter(function (Slide) {
  1977. return !Slide.isClone;
  1978. });
  1979. },
  1980. /**
  1981. * Return Slide objects belonging to the given page.
  1982. *
  1983. * @param {number} page - A page number.
  1984. *
  1985. * @return {Object[]} - An array containing Slide objects.
  1986. */
  1987. getSlidesByPage: function getSlidesByPage(page) {
  1988. var idx = Components.Controller.toIndex(page);
  1989. var options = Splide.options;
  1990. var max = options.focus !== false ? 1 : options.perPage;
  1991. return Slides.filter(function (_ref) {
  1992. var index = _ref.index;
  1993. return idx <= index && index < idx + max;
  1994. });
  1995. },
  1996. /**
  1997. * Insert a slide to a slider.
  1998. * Need to refresh Splide after adding a slide.
  1999. *
  2000. * @param {Node|string} slide - A slide element to be added.
  2001. * @param {number} index - A slide will be added at the position.
  2002. * @param {Function} callback - Called right after the slide is added to the DOM tree.
  2003. */
  2004. add: function add(slide, index, callback) {
  2005. if (typeof slide === 'string') {
  2006. slide = domify(slide);
  2007. }
  2008. if (slide instanceof Element) {
  2009. var ref = this.slides[index];
  2010. applyStyle(slide, {
  2011. display: 'none'
  2012. });
  2013. if (ref) {
  2014. before(slide, ref);
  2015. this.slides.splice(index, 0, slide);
  2016. } else {
  2017. append(this.list, slide);
  2018. this.slides.push(slide);
  2019. }
  2020. dom_loaded(slide, function () {
  2021. applyStyle(slide, {
  2022. display: ''
  2023. });
  2024. callback && callback(slide);
  2025. });
  2026. }
  2027. },
  2028. /**
  2029. * Remove a slide from a slider.
  2030. * Need to refresh Splide after removing a slide.
  2031. *
  2032. * @param index - Slide index.
  2033. */
  2034. remove: function remove(index) {
  2035. dom_remove(this.slides.splice(index, 1)[0]);
  2036. },
  2037. /**
  2038. * Trigger the provided callback for each Slide object.
  2039. *
  2040. * @param {Function} callback - A callback function. The first argument will be the Slide object.
  2041. */
  2042. each: function each(callback) {
  2043. Slides.forEach(callback);
  2044. },
  2045. /**
  2046. * Return slides length without clones.
  2047. *
  2048. * @return {number} - Slide length.
  2049. */
  2050. get length() {
  2051. return this.slides.length;
  2052. },
  2053. /**
  2054. * Return "SlideObjects" length including clones.
  2055. *
  2056. * @return {number} - Slide length including clones.
  2057. */
  2058. get total() {
  2059. return Slides.length;
  2060. }
  2061. };
  2062. /**
  2063. * Collect elements.
  2064. */
  2065. function collect() {
  2066. Elements.slider = child(root, classes.slider);
  2067. Elements.track = find(root, "." + classes.track);
  2068. Elements.list = child(Elements.track, classes.list);
  2069. exist(Elements.track && Elements.list, 'Track or list was not found.');
  2070. Elements.slides = values(Elements.list.children);
  2071. var arrows = findParts(classes.arrows);
  2072. Elements.arrows = {
  2073. prev: find(arrows, "." + classes.prev),
  2074. next: find(arrows, "." + classes.next)
  2075. };
  2076. var autoplay = findParts(classes.autoplay);
  2077. Elements.bar = find(findParts(classes.progress), "." + classes.bar);
  2078. Elements.play = find(autoplay, "." + classes.play);
  2079. Elements.pause = find(autoplay, "." + classes.pause);
  2080. Elements.track.id = Elements.track.id || root.id + "-track";
  2081. Elements.list.id = Elements.list.id || root.id + "-list";
  2082. }
  2083. /**
  2084. * Return class names for the root element.
  2085. */
  2086. function getClasses() {
  2087. var rootClass = classes.root;
  2088. var options = Splide.options;
  2089. return [rootClass + "--" + options.type, rootClass + "--" + options.direction, options.drag ? rootClass + "--draggable" : '', options.isNavigation ? rootClass + "--nav" : ''];
  2090. }
  2091. /**
  2092. * Find parts only from children of the root or track.
  2093. *
  2094. * @return {Element|null} - A found element or null.
  2095. */
  2096. function findParts(className) {
  2097. return child(root, className) || child(Elements.slider, className);
  2098. }
  2099. return Elements;
  2100. });
  2101. // CONCATENATED MODULE: ./src/js/components/controller/index.js
  2102. /**
  2103. * The component for controlling the track.
  2104. *
  2105. * @author Naotoshi Fujita
  2106. * @copyright Naotoshi Fujita. All rights reserved.
  2107. */
  2108. var controller_floor = Math.floor;
  2109. /**
  2110. * The component for controlling the track.
  2111. *
  2112. * @param {Splide} Splide - A Splide instance.
  2113. * @param {Object} Components - An object containing components.
  2114. *
  2115. * @return {Object} - The component object.
  2116. */
  2117. /* harmony default export */ var controller = (function (Splide, Components) {
  2118. /**
  2119. * Store current options.
  2120. *
  2121. * @type {Object}
  2122. */
  2123. var options;
  2124. /**
  2125. * True if the slide is LOOP mode.
  2126. *
  2127. * @type {boolean}
  2128. */
  2129. var isLoop;
  2130. /**
  2131. * Controller component object.
  2132. *
  2133. * @type {Object}
  2134. */
  2135. var Controller = {
  2136. /**
  2137. * Called when the component is mounted.
  2138. */
  2139. mount: function mount() {
  2140. options = Splide.options;
  2141. isLoop = Splide.is(LOOP);
  2142. bind();
  2143. },
  2144. /**
  2145. * Make track run by the given control.
  2146. * - "+{i}" : Increment the slide index by i.
  2147. * - "-{i}" : Decrement the slide index by i.
  2148. * - "{i}" : Go to the slide whose index is i.
  2149. * - ">" : Go to next page.
  2150. * - "<" : Go to prev page.
  2151. * - ">{i}" : Go to page i.
  2152. *
  2153. * @param {string|number} control - A control pattern.
  2154. * @param {boolean} silently - Go to the destination without event emission.
  2155. */
  2156. go: function go(control, silently) {
  2157. var destIndex = this.trim(this.parse(control));
  2158. Components.Track.go(destIndex, this.rewind(destIndex), silently);
  2159. },
  2160. /**
  2161. * Parse the given control and return the destination index for the track.
  2162. *
  2163. * @param {string} control - A control target pattern.
  2164. *
  2165. * @return {string|number} - A parsed target.
  2166. */
  2167. parse: function parse(control) {
  2168. var index = Splide.index;
  2169. var matches = String(control).match(/([+\-<>])(\d+)?/);
  2170. var indicator = matches ? matches[1] : '';
  2171. var number = matches ? parseInt(matches[2]) : 0;
  2172. switch (indicator) {
  2173. case '+':
  2174. index += number || 1;
  2175. break;
  2176. case '-':
  2177. index -= number || 1;
  2178. break;
  2179. case '>':
  2180. index = this.toIndex(number > -1 ? number : this.toPage(index) + 1);
  2181. break;
  2182. case '<':
  2183. index = this.toIndex(number > -1 ? number : this.toPage(index) - 1);
  2184. break;
  2185. default:
  2186. index = parseInt(control);
  2187. }
  2188. return index;
  2189. },
  2190. /**
  2191. * Compute index from the given page number.
  2192. *
  2193. * @param {number} page - Page number.
  2194. *
  2195. * @return {number} - A computed page number.
  2196. */
  2197. toIndex: function toIndex(page) {
  2198. if (hasFocus()) {
  2199. return page;
  2200. }
  2201. var length = Splide.length;
  2202. var perPage = options.perPage;
  2203. var index = page * perPage;
  2204. index = index - (this.pageLength * perPage - length) * controller_floor(index / length); // Adjustment for the last page.
  2205. if (length - perPage <= index && index < length) {
  2206. index = length - perPage;
  2207. }
  2208. return index;
  2209. },
  2210. /**
  2211. * Compute page number from the given slide index.
  2212. *
  2213. * @param index - Slide index.
  2214. *
  2215. * @return {number} - A computed page number.
  2216. */
  2217. toPage: function toPage(index) {
  2218. if (hasFocus()) {
  2219. return index;
  2220. }
  2221. var length = Splide.length;
  2222. var perPage = options.perPage; // Make the last "perPage" number of slides belong to the last page.
  2223. if (length - perPage <= index && index < length) {
  2224. return controller_floor((length - 1) / perPage);
  2225. }
  2226. return controller_floor(index / perPage);
  2227. },
  2228. /**
  2229. * Trim the given index according to the current mode.
  2230. * Index being returned could be less than 0 or greater than the length in Loop mode.
  2231. *
  2232. * @param {number} index - An index being trimmed.
  2233. *
  2234. * @return {number} - A trimmed index.
  2235. */
  2236. trim: function trim(index) {
  2237. if (!isLoop) {
  2238. index = options.rewind ? this.rewind(index) : between(index, 0, this.edgeIndex);
  2239. }
  2240. return index;
  2241. },
  2242. /**
  2243. * Rewind the given index if it's out of range.
  2244. *
  2245. * @param {number} index - An index.
  2246. *
  2247. * @return {number} - A rewound index.
  2248. */
  2249. rewind: function rewind(index) {
  2250. var edge = this.edgeIndex;
  2251. if (isLoop) {
  2252. while (index > edge) {
  2253. index -= edge + 1;
  2254. }
  2255. while (index < 0) {
  2256. index += edge + 1;
  2257. }
  2258. } else {
  2259. if (index > edge) {
  2260. index = 0;
  2261. } else if (index < 0) {
  2262. index = edge;
  2263. }
  2264. }
  2265. return index;
  2266. },
  2267. /**
  2268. * Check if the direction is "rtl" or not.
  2269. *
  2270. * @return {boolean} - True if "rtl" or false if not.
  2271. */
  2272. isRtl: function isRtl() {
  2273. return options.direction === RTL;
  2274. },
  2275. /**
  2276. * Return the page length.
  2277. *
  2278. * @return {number} - Max page number.
  2279. */
  2280. get pageLength() {
  2281. var length = Splide.length;
  2282. return hasFocus() ? length : Math.ceil(length / options.perPage);
  2283. },
  2284. /**
  2285. * Return the edge index.
  2286. *
  2287. * @return {number} - Edge index.
  2288. */
  2289. get edgeIndex() {
  2290. var length = Splide.length;
  2291. if (!length) {
  2292. return 0;
  2293. }
  2294. if (hasFocus() || options.isNavigation || isLoop) {
  2295. return length - 1;
  2296. }
  2297. return length - options.perPage;
  2298. },
  2299. /**
  2300. * Return the index of the previous slide.
  2301. *
  2302. * @return {number} - The index of the previous slide if available. -1 otherwise.
  2303. */
  2304. get prevIndex() {
  2305. var prev = Splide.index - 1;
  2306. if (isLoop || options.rewind) {
  2307. prev = this.rewind(prev);
  2308. }
  2309. return prev > -1 ? prev : -1;
  2310. },
  2311. /**
  2312. * Return the index of the next slide.
  2313. *
  2314. * @return {number} - The index of the next slide if available. -1 otherwise.
  2315. */
  2316. get nextIndex() {
  2317. var next = Splide.index + 1;
  2318. if (isLoop || options.rewind) {
  2319. next = this.rewind(next);
  2320. }
  2321. return Splide.index < next && next <= this.edgeIndex || next === 0 ? next : -1;
  2322. }
  2323. };
  2324. /**
  2325. * Listen some events.
  2326. */
  2327. function bind() {
  2328. Splide.on('move', function (newIndex) {
  2329. Splide.index = newIndex;
  2330. }).on('updated refresh', function (newOptions) {
  2331. options = newOptions || options;
  2332. Splide.index = between(Splide.index, 0, Controller.edgeIndex);
  2333. });
  2334. }
  2335. /**
  2336. * Verify if the focus option is available or not.
  2337. *
  2338. * @return {boolean} - True if a slider has the focus option.
  2339. */
  2340. function hasFocus() {
  2341. return options.focus !== false;
  2342. }
  2343. return Controller;
  2344. });
  2345. // CONCATENATED MODULE: ./src/js/components/track/directions/vertical.js
  2346. /**
  2347. * The resolver component for vertical move.
  2348. *
  2349. * @author Naotoshi Fujita
  2350. * @copyright Naotoshi Fujita. All rights reserved.
  2351. */
  2352. /**
  2353. * The resolver component for vertical move.
  2354. *
  2355. * @param {Splide} Splide - A Splide instance.
  2356. * @param {Object} Components - An object containing components.
  2357. *
  2358. * @return {Object} - The resolver object.
  2359. */
  2360. /* harmony default export */ var vertical = (function (Splide, Components) {
  2361. /**
  2362. * Hold the Layout object.
  2363. *
  2364. * @type {Object}
  2365. */
  2366. var Layout;
  2367. return {
  2368. /**
  2369. * Axis of translate.
  2370. *
  2371. * @type {string}
  2372. */
  2373. axis: 'Y',
  2374. /**
  2375. * Sign for the direction.
  2376. *
  2377. * @return {number}
  2378. */
  2379. sign: -1,
  2380. /**
  2381. * Initialization.
  2382. */
  2383. init: function init() {
  2384. Layout = Components.Layout;
  2385. },
  2386. /**
  2387. * Calculate position by index.
  2388. *
  2389. * @param {number} index - Slide index.
  2390. *
  2391. * @return {Object} - Calculated position.
  2392. */
  2393. toPosition: function toPosition(index) {
  2394. return -((index + Components.Clones.length / 2) * (Layout.slideHeight() + Layout.gap) + this.offset());
  2395. },
  2396. /**
  2397. * Calculate the closest slide index from the given position.
  2398. *
  2399. * @return {number} - The closest slide index.
  2400. */
  2401. toIndex: function toIndex(position) {
  2402. var slideHeight = Layout.slideHeight();
  2403. var cloneOffset = (slideHeight + Layout.gap) * Components.Clones.length / 2;
  2404. return Math.round(-(position + cloneOffset + this.offset()) / (slideHeight + Layout.gap));
  2405. },
  2406. /**
  2407. * Trim redundant spaces on the left or right edge if necessary.
  2408. *
  2409. * @param {number} position - Position value to be trimmed.
  2410. *
  2411. * @return {number} - Trimmed position.
  2412. */
  2413. trim: function trim(position) {
  2414. var edge = -(Layout.listHeight - (Layout.height + Layout.gap));
  2415. return between(position, edge, 0);
  2416. },
  2417. /**
  2418. * Return current offset value, considering direction.
  2419. *
  2420. * @return {number} - Offset amount.
  2421. */
  2422. offset: function offset() {
  2423. var focus = Splide.options.focus;
  2424. var slideHeight = Layout.slideHeight();
  2425. if (focus === 'center') {
  2426. return -(Layout.height - slideHeight) / 2;
  2427. }
  2428. return -(parseInt(focus) || 0) * (slideHeight + Layout.gap);
  2429. }
  2430. };
  2431. });
  2432. // CONCATENATED MODULE: ./src/js/components/track/directions/horizontal.js
  2433. /**
  2434. * The resolver component for horizontal move.
  2435. *
  2436. * @author Naotoshi Fujita
  2437. * @copyright Naotoshi Fujita. All rights reserved.
  2438. */
  2439. /**
  2440. * The resolver component for horizontal move.
  2441. *
  2442. * @param {Splide} Splide - A Splide instance.
  2443. * @param {Object} Components - An object containing components.
  2444. *
  2445. * @return {Object} - The resolver object.
  2446. */
  2447. /* harmony default export */ var horizontal = (function (Splide, Components) {
  2448. /**
  2449. * Hold the Layout component.
  2450. *
  2451. * @type {Object}
  2452. */
  2453. var Layout;
  2454. /**
  2455. * Hold the Elements component.
  2456. *
  2457. * @type {Object}
  2458. */
  2459. var Elements;
  2460. return {
  2461. /**
  2462. * Axis of translate.
  2463. *
  2464. * @type {string}
  2465. */
  2466. axis: 'X',
  2467. /**
  2468. * Sign for the direction.
  2469. *
  2470. * @type {number}
  2471. */
  2472. sign: Splide.options.direction === RTL ? 1 : -1,
  2473. /**
  2474. * Initialization.
  2475. */
  2476. init: function init() {
  2477. Layout = Components.Layout;
  2478. Elements = Components.Elements;
  2479. },
  2480. /**
  2481. * Calculate position by index.
  2482. *
  2483. * @param {number} index - Slide index.
  2484. *
  2485. * @return {Object} - Calculated position.
  2486. */
  2487. toPosition: function toPosition(index) {
  2488. return this.sign * (Layout.totalWidth(index - 1) + this.offset(index));
  2489. },
  2490. /**
  2491. * Calculate the closest slide index from the given position.
  2492. *
  2493. * @return {number} - The closest slide position.
  2494. */
  2495. toIndex: function toIndex(position) {
  2496. position *= this.sign;
  2497. if (Splide.is(SLIDE)) {
  2498. position = between(position, Layout.totalWidth(Elements.total), 0);
  2499. }
  2500. var Slides = Elements.getSlides(true);
  2501. for (var i in Slides) {
  2502. var Slide = Slides[i];
  2503. var slideIndex = Slide.index;
  2504. var slidePosition = this.sign * this.toPosition(slideIndex);
  2505. if (slidePosition < position && position <= slidePosition + Layout.slideWidth(slideIndex) + Layout.gap) {
  2506. return slideIndex;
  2507. }
  2508. }
  2509. return 0;
  2510. },
  2511. /**
  2512. * Trim redundant spaces on the left or right edge if necessary.
  2513. *
  2514. * @param {number} position - Position value to be trimmed.
  2515. *
  2516. * @return {number} - Trimmed position.
  2517. */
  2518. trim: function trim(position) {
  2519. var edge = this.sign * (Layout.totalWidth(Elements.total) - (Layout.width + Layout.gap));
  2520. return between(position, edge, 0);
  2521. },
  2522. /**
  2523. * Return current offset value, considering direction.
  2524. *
  2525. * @return {number} - Offset amount.
  2526. */
  2527. offset: function offset(index) {
  2528. var focus = Splide.options.focus;
  2529. var slideWidth = Layout.slideWidth(index);
  2530. if (focus === 'center') {
  2531. return -(Layout.width - slideWidth) / 2;
  2532. }
  2533. return -(parseInt(focus) || 0) * (slideWidth + Layout.gap);
  2534. }
  2535. };
  2536. });
  2537. // CONCATENATED MODULE: ./src/js/components/track/index.js
  2538. /**
  2539. * The component for moving list in the track.
  2540. *
  2541. * @author Naotoshi Fujita
  2542. * @copyright Naotoshi Fujita. All rights reserved.
  2543. */
  2544. /**
  2545. * The component for moving list in the track.
  2546. *
  2547. * @param {Splide} Splide - A Splide instance.
  2548. * @param {Object} Components - An object containing components.
  2549. *
  2550. * @return {Object} - The component object.
  2551. */
  2552. /* harmony default export */ var components_track = (function (Splide, Components) {
  2553. /**
  2554. * Store the list element.
  2555. *
  2556. * @type {Element}
  2557. */
  2558. var list;
  2559. /**
  2560. * Store the current position.
  2561. *
  2562. * @type {number}
  2563. */
  2564. var currPosition = 0;
  2565. /**
  2566. * Whether the current direction is vertical or not.
  2567. *
  2568. * @type {boolean}
  2569. */
  2570. var isVertical = Splide.options.direction === TTB;
  2571. /**
  2572. * Whether the slider type is FADE or not.
  2573. *
  2574. * @type {boolean}
  2575. */
  2576. var isFade = Splide.is(FADE);
  2577. /**
  2578. * Track component object.
  2579. *
  2580. * @type {Object}
  2581. */
  2582. var Track = object_assign({
  2583. /**
  2584. * Called when the component is mounted.
  2585. */
  2586. mount: function mount() {
  2587. list = Components.Elements.list;
  2588. this.init();
  2589. },
  2590. /**
  2591. * Called after the component is mounted.
  2592. * The resize event must be registered after the Layout's one is done.
  2593. */
  2594. mounted: function mounted() {
  2595. var _this = this;
  2596. if (!isFade) {
  2597. Splide.on('mounted resize updated', function () {
  2598. _this.jump(Splide.index);
  2599. });
  2600. }
  2601. },
  2602. /**
  2603. * Go to the given destination index.
  2604. * After arriving there, the track is jump to the new index without animation, mainly for loop mode.
  2605. *
  2606. * @param {number} destIndex - A destination index.
  2607. * This can be negative or greater than slides length for reaching clones.
  2608. * @param {number} newIndex - An actual new index. They are always same in Slide and Rewind mode.
  2609. * @param {boolean} silently - If true, suppress emitting events.
  2610. */
  2611. go: function go(destIndex, newIndex, silently) {
  2612. var _this2 = this;
  2613. var newPosition = getTrimmedPosition(destIndex);
  2614. var prevIndex = Splide.index;
  2615. if (!silently) {
  2616. Splide.emit('move', newIndex, prevIndex, destIndex);
  2617. }
  2618. if (Math.abs(newPosition - currPosition) >= 1 || isFade) {
  2619. Components.Transition.start(destIndex, newIndex, prevIndex, this.toCoord(newPosition), function () {
  2620. _this2.end(destIndex, newIndex, prevIndex, silently);
  2621. });
  2622. } else {
  2623. if (destIndex !== prevIndex && Splide.options.trimSpace === 'move') {
  2624. Components.Controller.go(destIndex + destIndex - prevIndex, silently);
  2625. } else {
  2626. this.end(destIndex, newIndex, prevIndex, silently);
  2627. }
  2628. }
  2629. },
  2630. /**
  2631. * Called whenever slides arrive at a destination.
  2632. *
  2633. * @param {number} destIndex - A destination index.
  2634. * @param {number} newIndex - A new index.
  2635. * @param {number} prevIndex - A previous index.
  2636. * @param {boolean} silently - If true, suppress emitting events.
  2637. */
  2638. end: function end(destIndex, newIndex, prevIndex, silently) {
  2639. applyStyle(list, {
  2640. transition: ''
  2641. });
  2642. if (!isFade) {
  2643. this.jump(newIndex);
  2644. }
  2645. if (!silently) {
  2646. Splide.emit('moved', newIndex, prevIndex, destIndex);
  2647. }
  2648. },
  2649. /**
  2650. * Move the track to the specified index.
  2651. *
  2652. * @param {number} index - A destination index where the track jumps.
  2653. */
  2654. jump: function jump(index) {
  2655. this.translate(getTrimmedPosition(index));
  2656. },
  2657. /**
  2658. * Set position.
  2659. *
  2660. * @param {number} position - A new position value.
  2661. */
  2662. translate: function translate(position) {
  2663. currPosition = position;
  2664. applyStyle(list, {
  2665. transform: "translate" + this.axis + "(" + position + "px)"
  2666. });
  2667. },
  2668. /**
  2669. * Trim redundant spaces on the left or right edge if necessary.
  2670. *
  2671. * @param {number} position - Position value to be trimmed.
  2672. *
  2673. * @return {number} - Trimmed position.
  2674. */
  2675. trim: function trim(position) {
  2676. if (!Splide.options.trimSpace || Splide.is(LOOP)) {
  2677. return position;
  2678. }
  2679. return this._s.trim(position);
  2680. },
  2681. /**
  2682. * Return coordinates object by the given position.
  2683. *
  2684. * @param {number} position - A position value.
  2685. *
  2686. * @return {Object} - A coordinates object.
  2687. */
  2688. toCoord: function toCoord(position) {
  2689. return {
  2690. x: isVertical ? 0 : position,
  2691. y: isVertical ? position : 0
  2692. };
  2693. },
  2694. /**
  2695. * Return current position.
  2696. *
  2697. * @return {number} - Current position.
  2698. */
  2699. get position() {
  2700. return currPosition;
  2701. }
  2702. }, isVertical ? vertical(Splide, Components) : horizontal(Splide, Components));
  2703. /**
  2704. * Convert index to the trimmed position.
  2705. *
  2706. * @return {number} - Trimmed position.
  2707. */
  2708. function getTrimmedPosition(index) {
  2709. return Track.trim(Track.toPosition(index));
  2710. }
  2711. return Track;
  2712. });
  2713. // CONCATENATED MODULE: ./src/js/components/clones/index.js
  2714. /**
  2715. * The component for cloning some slides for "loop" mode of the track.
  2716. *
  2717. * @author Naotoshi Fujita
  2718. * @copyright Naotoshi Fujita. All rights reserved.
  2719. */
  2720. /**
  2721. * The component for cloning some slides for "loop" mode of the track.
  2722. *
  2723. * @param {Splide} Splide - A Splide instance.
  2724. * @param {Object} Components - An object containing components.
  2725. *
  2726. * @return {Object} - The component object.
  2727. */
  2728. /* harmony default export */ var components_clones = (function (Splide, Components) {
  2729. /**
  2730. * Store information of all clones.
  2731. *
  2732. * @type {Array}
  2733. */
  2734. var clones = [];
  2735. /**
  2736. * Keep Elements component.
  2737. *
  2738. * @type {Object}
  2739. */
  2740. var Elements = Components.Elements;
  2741. /**
  2742. * Clones component object.
  2743. *
  2744. * @type {Object}
  2745. */
  2746. var Clones = {
  2747. /**
  2748. * Called when the component is mounted.
  2749. */
  2750. mount: function mount() {
  2751. var _this = this;
  2752. if (Splide.is(LOOP)) {
  2753. generateClones();
  2754. Splide.on('refresh', function () {
  2755. _this.destroy();
  2756. generateClones();
  2757. });
  2758. }
  2759. },
  2760. /**
  2761. * Destroy.
  2762. */
  2763. destroy: function destroy() {
  2764. dom_remove(clones);
  2765. clones = [];
  2766. },
  2767. /**
  2768. * Return all clones.
  2769. *
  2770. * @return {Element[]} - Cloned elements.
  2771. */
  2772. get clones() {
  2773. return clones;
  2774. },
  2775. /**
  2776. * Return clone length.
  2777. *
  2778. * @return {number} - A length of clones.
  2779. */
  2780. get length() {
  2781. return clones.length;
  2782. }
  2783. };
  2784. /**
  2785. * Generate and append clones.
  2786. */
  2787. function generateClones() {
  2788. var length = Elements.length;
  2789. if (!length) {
  2790. return;
  2791. }
  2792. var count = getCloneCount();
  2793. var slides = Elements.slides;
  2794. while (slides.length < count) {
  2795. slides = slides.concat(slides);
  2796. }
  2797. slides.slice(0, count).forEach(function (elm, index) {
  2798. var clone = cloneDeeply(elm);
  2799. append(Elements.list, clone);
  2800. clones.push(clone);
  2801. Elements.register(clone, index + length, index);
  2802. });
  2803. slides.slice(-count).forEach(function (elm, index) {
  2804. var clone = cloneDeeply(elm);
  2805. before(clone, slides[0]);
  2806. clones.push(clone);
  2807. Elements.register(clone, index - count, index);
  2808. });
  2809. }
  2810. /**
  2811. * Return half count of clones to be generated.
  2812. * Clone count is determined by:
  2813. * - Max pages a flick action can move.
  2814. * - Whether the slide length is enough for perPage.
  2815. *
  2816. * @return {number} - Count for clones.
  2817. */
  2818. function getCloneCount() {
  2819. var options = Splide.options;
  2820. if (options.autoWidth) {
  2821. return Elements.length;
  2822. }
  2823. return options.perPage * (options.drag ? options.flickMaxPages + 1 : 1);
  2824. }
  2825. /**
  2826. * Clone deeply the given element.
  2827. *
  2828. * @param {Element} elm - An element being duplicated.
  2829. *
  2830. * @return {Node} - A cloned node(element).
  2831. */
  2832. function cloneDeeply(elm) {
  2833. var clone = elm.cloneNode(true);
  2834. addClass(clone, Splide.classes.clone); // ID should not be duplicated.
  2835. removeAttribute(clone, 'id');
  2836. return clone;
  2837. }
  2838. return Clones;
  2839. });
  2840. // CONCATENATED MODULE: ./src/js/components/layout/directions/horizontal.js
  2841. /**
  2842. * The resolver component for horizontal layout.
  2843. *
  2844. * @author Naotoshi Fujita
  2845. * @copyright Naotoshi Fujita. All rights reserved.
  2846. */
  2847. /**
  2848. * Max width of a slide.
  2849. *
  2850. * @type {number}
  2851. */
  2852. var SLIDE_MAX_WIDTH = 5000;
  2853. /**
  2854. * The resolver component for horizontal layout.
  2855. *
  2856. * @param {Splide} Splide - A Splide instance.
  2857. * @param {Object} Components - An object containing components.
  2858. *
  2859. * @return {Object} - The resolver object.
  2860. */
  2861. /* harmony default export */ var directions_horizontal = (function (Splide, Components) {
  2862. /**
  2863. * Keep the Elements component.
  2864. *
  2865. * @type {string}
  2866. */
  2867. var Elements = Components.Elements;
  2868. /**
  2869. * Keep the root element.
  2870. *
  2871. * @type {Element}
  2872. */
  2873. var root = Splide.root;
  2874. /**
  2875. * Keep the track element.
  2876. *
  2877. * @type {Element}
  2878. */
  2879. var track;
  2880. /**
  2881. * Keep the latest options.
  2882. *
  2883. * @type {Element}
  2884. */
  2885. var options = Splide.options;
  2886. return {
  2887. /**
  2888. * Margin property name.
  2889. *
  2890. * @type {string}
  2891. */
  2892. margin: 'margin' + (options.direction === RTL ? 'Left' : 'Right'),
  2893. /**
  2894. * Always 0 because the height will be determined by inner contents.
  2895. *
  2896. * @type {number}
  2897. */
  2898. height: 0,
  2899. /**
  2900. * Always 0 because the height will be determined by inner contents.
  2901. *
  2902. * @type {number}
  2903. */
  2904. listHeight: 0,
  2905. /**
  2906. * Initialization.
  2907. */
  2908. init: function init() {
  2909. options = Splide.options;
  2910. track = Elements.track;
  2911. this.gap = toPixel(root, options.gap);
  2912. var padding = options.padding;
  2913. var _padding$left = padding.left,
  2914. left = _padding$left === void 0 ? padding : _padding$left,
  2915. _padding$right = padding.right,
  2916. right = _padding$right === void 0 ? padding : _padding$right;
  2917. this.padding = {
  2918. left: toPixel(root, left),
  2919. right: toPixel(root, right)
  2920. };
  2921. applyStyle(track, {
  2922. paddingLeft: unit(left),
  2923. paddingRight: unit(right)
  2924. });
  2925. },
  2926. /**
  2927. * Accumulate slide width including the gap to the designated index.
  2928. *
  2929. * @param {number|undefined} index - If undefined, width of all slides will be accumulated.
  2930. *
  2931. * @return {number} - Accumulated width.
  2932. */
  2933. totalWidth: function totalWidth(index) {
  2934. var _this = this;
  2935. return Elements.getSlides(true).filter(function (Slide) {
  2936. return Slide.index <= index;
  2937. }).reduce(function (accumulator, Slide) {
  2938. return accumulator + _this.slideWidth(Slide.index) + _this.gap;
  2939. }, 0);
  2940. },
  2941. /**
  2942. * Return the slide width in px.
  2943. *
  2944. * @param {number} index - Slide index.
  2945. *
  2946. * @return {number} - The slide width.
  2947. */
  2948. slideWidth: function slideWidth(index) {
  2949. if (options.autoWidth) {
  2950. var Slide = Elements.getSlide(index);
  2951. return Slide ? Slide.slide.offsetWidth : 0;
  2952. }
  2953. var width = options.fixedWidth || (this.width + this.gap) / options.perPage - this.gap;
  2954. return toPixel(root, width);
  2955. },
  2956. /**
  2957. * Return the slide height in px.
  2958. *
  2959. * @return {number} - The slide height.
  2960. */
  2961. slideHeight: function slideHeight() {
  2962. var height = options.height || options.fixedHeight || this.width * options.heightRatio;
  2963. return toPixel(root, height);
  2964. },
  2965. /**
  2966. * Return slider width without padding.
  2967. *
  2968. * @return {number} - Current slider width.
  2969. */
  2970. get width() {
  2971. return track.clientWidth - this.padding.left - this.padding.right;
  2972. },
  2973. /**
  2974. * Return list width.
  2975. *
  2976. * @return {number} - Current list width.
  2977. */
  2978. get listWidth() {
  2979. var total = Elements.total;
  2980. return options.autoWidth ? total * SLIDE_MAX_WIDTH : this.totalWidth(total);
  2981. }
  2982. };
  2983. });
  2984. // CONCATENATED MODULE: ./src/js/components/layout/directions/vertical.js
  2985. /**
  2986. * The resolver component for vertical layout.
  2987. *
  2988. * @author Naotoshi Fujita
  2989. * @copyright Naotoshi Fujita. All rights reserved.
  2990. */
  2991. /**
  2992. * The resolver component for vertical layout.
  2993. *
  2994. * @param {Splide} Splide - A Splide instance.
  2995. * @param {Object} Components - An object containing components.
  2996. *
  2997. * @return {Object} - The resolver object.
  2998. */
  2999. /* harmony default export */ var directions_vertical = (function (Splide, Components) {
  3000. /**
  3001. * Keep the Elements component.
  3002. *
  3003. * @type {string}
  3004. */
  3005. var Elements = Components.Elements;
  3006. /**
  3007. * Keep the root element.
  3008. *
  3009. * @type {Element}
  3010. */
  3011. var root = Splide.root;
  3012. /**
  3013. * Keep the track element.
  3014. *
  3015. * @type {Element}
  3016. */
  3017. var track;
  3018. /**
  3019. * Keep the latest options.
  3020. *
  3021. * @type {Element}
  3022. */
  3023. var options;
  3024. return {
  3025. /**
  3026. * Margin property name.
  3027. *
  3028. * @type {string}
  3029. */
  3030. margin: 'marginBottom',
  3031. /**
  3032. * Init slider styles according to options.
  3033. */
  3034. init: function init() {
  3035. options = Splide.options;
  3036. track = Elements.track;
  3037. this.gap = toPixel(root, options.gap);
  3038. var padding = options.padding;
  3039. var _padding$top = padding.top,
  3040. top = _padding$top === void 0 ? padding : _padding$top,
  3041. _padding$bottom = padding.bottom,
  3042. bottom = _padding$bottom === void 0 ? padding : _padding$bottom;
  3043. this.padding = {
  3044. top: toPixel(root, top),
  3045. bottom: toPixel(root, bottom)
  3046. };
  3047. applyStyle(track, {
  3048. paddingTop: unit(top),
  3049. paddingBottom: unit(bottom)
  3050. });
  3051. },
  3052. /**
  3053. * Return the slide width in px.
  3054. *
  3055. * @return {number} - The slide width.
  3056. */
  3057. slideWidth: function slideWidth() {
  3058. return toPixel(root, options.fixedWidth || this.width);
  3059. },
  3060. /**
  3061. * Return the slide height in px.
  3062. *
  3063. * @return {number} - The slide height.
  3064. */
  3065. slideHeight: function slideHeight() {
  3066. var height = options.fixedHeight || (this.height + this.gap) / options.perPage - this.gap;
  3067. return toPixel(root, height);
  3068. },
  3069. /**
  3070. * Return slider width without padding.
  3071. *
  3072. * @return {number} - Current slider width.
  3073. */
  3074. get width() {
  3075. return track.clientWidth;
  3076. },
  3077. /**
  3078. * Return slide height without padding.
  3079. *
  3080. * @return {number} - Slider height.
  3081. */
  3082. get height() {
  3083. var height = options.height || this.width * options.heightRatio;
  3084. exist(height, '"height" or "heightRatio" is missing.');
  3085. return toPixel(root, height) - this.padding.top - this.padding.bottom;
  3086. },
  3087. /**
  3088. * Return list width.
  3089. *
  3090. * @return {number} - Current list width.
  3091. */
  3092. get listWidth() {
  3093. return this.width;
  3094. },
  3095. /**
  3096. * Return list height.
  3097. *
  3098. * @return {number} - Current list height.
  3099. */
  3100. get listHeight() {
  3101. return (this.slideHeight() + this.gap) * Elements.total;
  3102. }
  3103. };
  3104. });
  3105. // CONCATENATED MODULE: ./src/js/utils/time.js
  3106. /**
  3107. * A package of utility functions related with time.
  3108. *
  3109. * @author Naotoshi Fujita
  3110. * @copyright Naotoshi Fujita. All rights reserved.
  3111. */
  3112. /**
  3113. * Simple throttle function that controls how often the given function is executed.
  3114. *
  3115. * @param {function} func - A function to be throttled.
  3116. * @param {number} wait - Time in millisecond for interval of execution.
  3117. *
  3118. * @return {Function} - A debounced function.
  3119. */
  3120. function throttle(func, wait) {
  3121. var timeout; // Declare function by the "function" keyword to prevent "this" from being inherited.
  3122. return function () {
  3123. if (!timeout) {
  3124. timeout = setTimeout(function () {
  3125. func();
  3126. timeout = null;
  3127. }, wait);
  3128. }
  3129. };
  3130. }
  3131. /**
  3132. * Custom setInterval function that provides progress rate as callback.
  3133. *
  3134. * @param {function} callback - A callback function fired every time the interval time passes.
  3135. * @param {number} interval - Interval duration in milliseconds.
  3136. * @param {function} progress - A callback function fired whenever the progress goes.
  3137. *
  3138. * @return {Object} - An object containing play() and pause() functions.
  3139. */
  3140. function createInterval(callback, interval, progress) {
  3141. var _window = window,
  3142. requestAnimationFrame = _window.requestAnimationFrame;
  3143. var start,
  3144. elapse,
  3145. rate,
  3146. _pause = true;
  3147. var step = function step(timestamp) {
  3148. if (!_pause) {
  3149. if (!start) {
  3150. start = timestamp;
  3151. }
  3152. elapse = timestamp - start;
  3153. rate = elapse / interval;
  3154. if (elapse >= interval) {
  3155. start = 0;
  3156. rate = 1;
  3157. callback();
  3158. }
  3159. if (progress) {
  3160. progress(rate);
  3161. }
  3162. requestAnimationFrame(step);
  3163. }
  3164. };
  3165. return {
  3166. pause: function pause() {
  3167. _pause = true;
  3168. start = 0;
  3169. },
  3170. play: function play() {
  3171. start = 0;
  3172. if (_pause) {
  3173. _pause = false;
  3174. requestAnimationFrame(step);
  3175. }
  3176. }
  3177. };
  3178. }
  3179. // CONCATENATED MODULE: ./src/js/components/layout/index.js
  3180. /**
  3181. * The component for handing slide layouts and their sizes.
  3182. *
  3183. * @author Naotoshi Fujita
  3184. * @copyright Naotoshi Fujita. All rights reserved.
  3185. */
  3186. /**
  3187. * Interval time for throttle.
  3188. *
  3189. * @type {number}
  3190. */
  3191. var THROTTLE = 100;
  3192. /**
  3193. * The component for handing slide layouts and their sizes.
  3194. *
  3195. * @param {Splide} Splide - A Splide instance.
  3196. * @param {Object} Components - An object containing components.
  3197. *
  3198. * @return {Object} - The component object.
  3199. */
  3200. /* harmony default export */ var layout = (function (Splide, Components) {
  3201. /**
  3202. * Keep the Elements component.
  3203. *
  3204. * @type {string}
  3205. */
  3206. var Elements = Components.Elements;
  3207. /**
  3208. * Layout component object.
  3209. *
  3210. * @type {Object}
  3211. */
  3212. var Layout = object_assign({
  3213. /**
  3214. * Called when the component is mounted.
  3215. */
  3216. mount: function mount() {
  3217. bind();
  3218. init();
  3219. },
  3220. /**
  3221. * Destroy.
  3222. */
  3223. destroy: function destroy() {
  3224. removeAttribute([Elements.list, Elements.track], 'style');
  3225. }
  3226. }, Splide.options.direction === TTB ? directions_vertical(Splide, Components) : directions_horizontal(Splide, Components));
  3227. /**
  3228. * Init slider styles according to options.
  3229. */
  3230. function init() {
  3231. Layout.init();
  3232. applyStyle(Splide.root, {
  3233. maxWidth: unit(Splide.options.width)
  3234. });
  3235. Elements.each(function (Slide) {
  3236. Slide.slide.style[Layout.margin] = unit(Layout.gap);
  3237. });
  3238. resize();
  3239. }
  3240. /**
  3241. * Listen the resize native event with throttle.
  3242. * Initialize when the component is mounted or options are updated.
  3243. */
  3244. function bind() {
  3245. Splide.on('resize load', throttle(function () {
  3246. Splide.emit('resize');
  3247. }, THROTTLE), window).on('resize', resize).on('updated refresh', init);
  3248. }
  3249. /**
  3250. * Resize the list and slides including clones.
  3251. */
  3252. function resize() {
  3253. applyStyle(Elements.list, {
  3254. width: unit(Layout.listWidth),
  3255. height: unit(Layout.listHeight)
  3256. });
  3257. applyStyle(Elements.track, {
  3258. height: unit(Layout.height)
  3259. });
  3260. var slideHeight = unit(Layout.slideHeight());
  3261. var width = Layout.width;
  3262. Elements.each(function (Slide) {
  3263. applyStyle(Slide.container, {
  3264. height: slideHeight
  3265. });
  3266. applyStyle(Slide.slide, {
  3267. width: Splide.options.autoWidth ? null : unit(Layout.slideWidth(Slide.index)),
  3268. height: Slide.container ? null : slideHeight
  3269. });
  3270. }); // When the scrollbar is made hidden, the track width is changed but the resize event is not fired.
  3271. if (width !== Layout.width) {
  3272. resize();
  3273. }
  3274. }
  3275. return Layout;
  3276. });
  3277. // CONCATENATED MODULE: ./src/js/components/drag/index.js
  3278. /**
  3279. * The component for supporting mouse drag and swipe.
  3280. *
  3281. * @author Naotoshi Fujita
  3282. * @copyright Naotoshi Fujita. All rights reserved.
  3283. */
  3284. var abs = Math.abs;
  3285. /**
  3286. * Adjust how much the track can be pulled on the first or last page.
  3287. * The larger number this is, the farther the track moves.
  3288. * This should be around 5 - 9.
  3289. *
  3290. * @type {number}
  3291. */
  3292. var FRICTION_REDUCER = 7;
  3293. /**
  3294. * The component supporting mouse drag and swipe.
  3295. *
  3296. * @param {Splide} Splide - A Splide instance.
  3297. * @param {Object} Components - An object containing components.
  3298. *
  3299. * @return {Object} - The component object.
  3300. */
  3301. /* harmony default export */ var drag = (function (Splide, Components) {
  3302. /**
  3303. * Store the Move component.
  3304. *
  3305. * @type {Object}
  3306. */
  3307. var Track = Components.Track;
  3308. /**
  3309. * Store the Controller component.
  3310. *
  3311. * @type {Object}
  3312. */
  3313. var Controller = Components.Controller;
  3314. /**
  3315. * Coordinate of the track on starting drag.
  3316. *
  3317. * @type {Object}
  3318. */
  3319. var startCoord;
  3320. /**
  3321. * Analyzed info on starting drag.
  3322. *
  3323. * @type {Object|null}
  3324. */
  3325. var startInfo;
  3326. /**
  3327. * Analyzed info being updated while dragging/swiping.
  3328. *
  3329. * @type {Object}
  3330. */
  3331. var currentInfo;
  3332. /**
  3333. * Determine whether slides are being dragged or not.
  3334. *
  3335. * @type {boolean}
  3336. */
  3337. var isDragging;
  3338. /**
  3339. * Whether the slider direction is vertical or not.
  3340. *
  3341. * @type {boolean}
  3342. */
  3343. var isVertical = Splide.options.direction === TTB;
  3344. /**
  3345. * Axis for the direction.
  3346. *
  3347. * @type {string}
  3348. */
  3349. var axis = isVertical ? 'y' : 'x';
  3350. /**
  3351. * Drag component object.
  3352. *
  3353. * @type {Object}
  3354. */
  3355. var Drag = {
  3356. /**
  3357. * Mount only when the drag option is true.
  3358. *
  3359. * @type {boolean}
  3360. */
  3361. required: Splide.options.drag,
  3362. /**
  3363. * Whether dragging is disabled or not.
  3364. *
  3365. * @type {boolean}
  3366. */
  3367. disabled: false,
  3368. /**
  3369. * Called when the component is mounted.
  3370. */
  3371. mount: function mount() {
  3372. var list = Components.Elements.list;
  3373. Splide.on('touchstart mousedown', start, list).on('touchmove mousemove', move, list, {
  3374. passive: false
  3375. }).on('touchend touchcancel mouseleave mouseup dragend', end, list).on('mounted refresh', function () {
  3376. // Prevent dragging an image or anchor itself.
  3377. each(list.querySelectorAll('img, a'), function (elm) {
  3378. Splide.off('dragstart', elm).on('dragstart', function (e) {
  3379. e.preventDefault();
  3380. }, elm, {
  3381. passive: false
  3382. });
  3383. });
  3384. });
  3385. }
  3386. };
  3387. /**
  3388. * Called when the track starts to be dragged.
  3389. *
  3390. * @param {TouchEvent|MouseEvent} e - TouchEvent or MouseEvent object.
  3391. */
  3392. function start(e) {
  3393. if (!Drag.disabled && !isDragging && Splide.State.is(IDLE)) {
  3394. startCoord = Track.toCoord(Track.position);
  3395. startInfo = analyze(e, {});
  3396. currentInfo = startInfo;
  3397. }
  3398. }
  3399. /**
  3400. * Called while the track being dragged.
  3401. *
  3402. * @param {TouchEvent|MouseEvent} e - TouchEvent or MouseEvent object.
  3403. */
  3404. function move(e) {
  3405. if (startInfo) {
  3406. currentInfo = analyze(e, startInfo);
  3407. if (isDragging) {
  3408. if (e.cancelable) {
  3409. e.preventDefault();
  3410. }
  3411. var position = startCoord[axis] + currentInfo.offset[axis];
  3412. Track.translate(resist(position));
  3413. } else {
  3414. if (shouldMove(currentInfo)) {
  3415. Splide.emit('drag', startInfo);
  3416. isDragging = true;
  3417. }
  3418. }
  3419. }
  3420. }
  3421. /**
  3422. * Determine whether to start moving the track or not by drag angle.
  3423. *
  3424. * @param {Object} info - An information object.
  3425. *
  3426. * @return {boolean} - True if the track should be moved or false if not.
  3427. */
  3428. function shouldMove(_ref) {
  3429. var offset = _ref.offset;
  3430. if (Splide.State.is(IDLE)) {
  3431. var angle = Math.atan(abs(offset.y) / abs(offset.x)) * 180 / Math.PI;
  3432. if (isVertical) {
  3433. angle = 90 - angle;
  3434. }
  3435. return angle < Splide.options.dragAngleThreshold;
  3436. }
  3437. return false;
  3438. }
  3439. /**
  3440. * Resist dragging the track on the first/last page because there is no more.
  3441. *
  3442. * @param {number} position - A position being applied to the track.
  3443. *
  3444. * @return {Object} - Adjusted position.
  3445. */
  3446. function resist(position) {
  3447. if (!Splide.is(LOOP)) {
  3448. var sign = Track.sign;
  3449. var _start = sign * Track.trim(Track.toPosition(0));
  3450. var _end = sign * Track.trim(Track.toPosition(Controller.edgeIndex));
  3451. position *= sign;
  3452. if (position < _start) {
  3453. position = _start - FRICTION_REDUCER * Math.log(_start - position);
  3454. } else if (position > _end) {
  3455. position = _end + FRICTION_REDUCER * Math.log(position - _end);
  3456. }
  3457. position *= sign;
  3458. }
  3459. return position;
  3460. }
  3461. /**
  3462. * Called when dragging ends.
  3463. */
  3464. function end() {
  3465. startInfo = null;
  3466. if (isDragging) {
  3467. Splide.emit('dragged', currentInfo);
  3468. go(currentInfo);
  3469. isDragging = false;
  3470. }
  3471. }
  3472. /**
  3473. * Go to the slide determined by the analyzed data.
  3474. *
  3475. * @param {Object} info - An info object.
  3476. */
  3477. function go(info) {
  3478. var velocity = info.velocity[axis];
  3479. var absV = abs(velocity);
  3480. if (absV > 0) {
  3481. var Layout = Components.Layout;
  3482. var options = Splide.options;
  3483. var sign = velocity < 0 ? -1 : 1;
  3484. var destination = Track.position;
  3485. if (absV > options.flickVelocityThreshold && abs(info.offset[axis]) < options.swipeDistanceThreshold) {
  3486. destination += sign * Math.min(absV * options.flickPower, Layout.width * (options.flickMaxPages || 1));
  3487. }
  3488. var index = Track.toIndex(destination); // Do not allow the track to go to a previous position.
  3489. if (index === Splide.index) {
  3490. index += sign * Track.sign;
  3491. }
  3492. if (!Splide.is(LOOP)) {
  3493. index = between(index, 0, Controller.edgeIndex);
  3494. }
  3495. Controller.go(index, options.isNavigation);
  3496. }
  3497. }
  3498. /**
  3499. * Analyze the given event object and return important information for handling swipe behavior.
  3500. *
  3501. * @param {Event} e - Touch or Mouse event object.
  3502. * @param {Object} startInfo - Information analyzed on start for calculating difference from the current one.
  3503. *
  3504. * @return {Object} - An object containing analyzed information, such as offset, velocity, etc.
  3505. */
  3506. function analyze(e, startInfo) {
  3507. var timeStamp = e.timeStamp,
  3508. touches = e.touches;
  3509. var _ref2 = touches ? touches[0] : e,
  3510. clientX = _ref2.clientX,
  3511. clientY = _ref2.clientY;
  3512. var _ref3 = startInfo.to || {},
  3513. _ref3$x = _ref3.x,
  3514. fromX = _ref3$x === void 0 ? clientX : _ref3$x,
  3515. _ref3$y = _ref3.y,
  3516. fromY = _ref3$y === void 0 ? clientY : _ref3$y;
  3517. var startTime = startInfo.time || 0;
  3518. var offset = {
  3519. x: clientX - fromX,
  3520. y: clientY - fromY
  3521. };
  3522. var duration = timeStamp - startTime;
  3523. var velocity = {
  3524. x: offset.x / duration,
  3525. y: offset.y / duration
  3526. };
  3527. return {
  3528. to: {
  3529. x: clientX,
  3530. y: clientY
  3531. },
  3532. offset: offset,
  3533. time: timeStamp,
  3534. velocity: velocity
  3535. };
  3536. }
  3537. return Drag;
  3538. });
  3539. // CONCATENATED MODULE: ./src/js/components/click/index.js
  3540. /**
  3541. * The component for handling a click event.
  3542. *
  3543. * @author Naotoshi Fujita
  3544. * @copyright Naotoshi Fujita. All rights reserved.
  3545. */
  3546. /**
  3547. * The component for handling a click event.
  3548. * Click should be disabled during drag/swipe.
  3549. *
  3550. * @param {Splide} Splide - A Splide instance.
  3551. * @param {Object} Components - An object containing components.
  3552. *
  3553. * @return {Object} - The component object.
  3554. */
  3555. /* harmony default export */ var click = (function (Splide, Components) {
  3556. /**
  3557. * Whether click is disabled or not.
  3558. *
  3559. * @type {boolean}
  3560. */
  3561. var disabled = false;
  3562. /**
  3563. * Click component object.
  3564. *
  3565. * @type {Object}
  3566. */
  3567. var Click = {
  3568. /**
  3569. * Mount only when the drag is activated and the slide type is not "fade".
  3570. *
  3571. * @type {boolean}
  3572. */
  3573. required: Splide.options.drag && !Splide.is(FADE),
  3574. /**
  3575. * Called when the component is mounted.
  3576. */
  3577. mount: function mount() {
  3578. Splide.on('click', onClick, Components.Elements.track, {
  3579. capture: true
  3580. }).on('drag', function () {
  3581. disabled = true;
  3582. }).on('moved', function () {
  3583. disabled = false;
  3584. });
  3585. }
  3586. };
  3587. /**
  3588. * Called when a track element is clicked.
  3589. *
  3590. * @param {Event} e - A click event.
  3591. */
  3592. function onClick(e) {
  3593. if (disabled) {
  3594. e.preventDefault();
  3595. e.stopPropagation();
  3596. e.stopImmediatePropagation();
  3597. }
  3598. }
  3599. return Click;
  3600. });
  3601. // CONCATENATED MODULE: ./src/js/components/autoplay/index.js
  3602. /**
  3603. * The component for playing slides automatically.
  3604. *
  3605. * @author Naotoshi Fujita
  3606. * @copyright Naotoshi Fujita. All rights reserved.
  3607. */
  3608. /**
  3609. * Set of pause flags.
  3610. */
  3611. var PAUSE_FLAGS = {
  3612. HOVER: 1,
  3613. FOCUS: 2,
  3614. MANUAL: 3
  3615. };
  3616. /**
  3617. * The component for playing slides automatically.
  3618. *
  3619. * @param {Splide} Splide - A Splide instance.
  3620. * @param {Object} Components - An object containing components.
  3621. * @param {string} name - A component name as a lowercase string.
  3622. *
  3623. * @return {Object} - The component object.
  3624. */
  3625. /* harmony default export */ var components_autoplay = (function (Splide, Components, name) {
  3626. /**
  3627. * Store pause flags.
  3628. *
  3629. * @type {Array}
  3630. */
  3631. var flags = [];
  3632. /**
  3633. * Store an interval object.
  3634. *
  3635. * @type {Object};
  3636. */
  3637. var interval;
  3638. /**
  3639. * Keep the Elements component.
  3640. *
  3641. * @type {string}
  3642. */
  3643. var Elements = Components.Elements;
  3644. /**
  3645. * Autoplay component object.
  3646. *
  3647. * @type {Object}
  3648. */
  3649. var Autoplay = {
  3650. /**
  3651. * Required only when the autoplay option is true.
  3652. *
  3653. * @type {boolean}
  3654. */
  3655. required: Splide.options.autoplay,
  3656. /**
  3657. * Called when the component is mounted.
  3658. * Note that autoplay starts only if there are slides over perPage number.
  3659. */
  3660. mount: function mount() {
  3661. var options = Splide.options;
  3662. if (Elements.slides.length > options.perPage) {
  3663. interval = createInterval(function () {
  3664. Splide.go('>');
  3665. }, options.interval, function (rate) {
  3666. Splide.emit(name + ":playing", rate);
  3667. if (Elements.bar) {
  3668. applyStyle(Elements.bar, {
  3669. width: rate * 100 + "%"
  3670. });
  3671. }
  3672. });
  3673. bind();
  3674. this.play();
  3675. }
  3676. },
  3677. /**
  3678. * Start autoplay.
  3679. *
  3680. * @param {number} flag - A pause flag to be removed.
  3681. */
  3682. play: function play(flag) {
  3683. if (flag === void 0) {
  3684. flag = 0;
  3685. }
  3686. flags = flags.filter(function (f) {
  3687. return f !== flag;
  3688. });
  3689. if (!flags.length) {
  3690. Splide.emit(name + ":play");
  3691. interval.play();
  3692. }
  3693. },
  3694. /**
  3695. * Pause autoplay.
  3696. * Note that Array.includes is not supported by IE.
  3697. *
  3698. * @param {number} flag - A pause flag to be added.
  3699. */
  3700. pause: function pause(flag) {
  3701. if (flag === void 0) {
  3702. flag = 0;
  3703. }
  3704. interval.pause();
  3705. if (flags.indexOf(flag) === -1) {
  3706. flags.push(flag);
  3707. }
  3708. if (flags.length === 1) {
  3709. Splide.emit(name + ":pause");
  3710. }
  3711. }
  3712. };
  3713. /**
  3714. * Listen some events.
  3715. */
  3716. function bind() {
  3717. var options = Splide.options;
  3718. var sibling = Splide.sibling;
  3719. var elms = [Splide.root, sibling ? sibling.root : null];
  3720. if (options.pauseOnHover) {
  3721. switchOn(elms, 'mouseleave', PAUSE_FLAGS.HOVER, true);
  3722. switchOn(elms, 'mouseenter', PAUSE_FLAGS.HOVER, false);
  3723. }
  3724. if (options.pauseOnFocus) {
  3725. switchOn(elms, 'focusout', PAUSE_FLAGS.FOCUS, true);
  3726. switchOn(elms, 'focusin', PAUSE_FLAGS.FOCUS, false);
  3727. }
  3728. Splide.on('click', function () {
  3729. // Need to be removed a focus flag at first.
  3730. Autoplay.play(PAUSE_FLAGS.FOCUS);
  3731. Autoplay.play(PAUSE_FLAGS.MANUAL);
  3732. }, Elements.play).on('move refresh', function () {
  3733. Autoplay.play();
  3734. }) // Rewind the timer.
  3735. .on('destroy', function () {
  3736. Autoplay.pause();
  3737. });
  3738. switchOn([Elements.pause], 'click', PAUSE_FLAGS.MANUAL, false);
  3739. }
  3740. /**
  3741. * Play or pause on the given event.
  3742. *
  3743. * @param {Element[]} elms - Elements.
  3744. * @param {string} event - An event name or names.
  3745. * @param {number} flag - A pause flag defined on the top.
  3746. * @param {boolean} play - Determine whether to play or pause.
  3747. */
  3748. function switchOn(elms, event, flag, play) {
  3749. elms.forEach(function (elm) {
  3750. Splide.on(event, function () {
  3751. Autoplay[play ? 'play' : 'pause'](flag);
  3752. }, elm);
  3753. });
  3754. }
  3755. return Autoplay;
  3756. });
  3757. // CONCATENATED MODULE: ./src/js/components/cover/index.js
  3758. /**
  3759. * The component for change an img element to background image of its wrapper.
  3760. *
  3761. * @author Naotoshi Fujita
  3762. * @copyright Naotoshi Fujita. All rights reserved.
  3763. */
  3764. /**
  3765. * The component for change an img element to background image of its wrapper.
  3766. *
  3767. * @param {Splide} Splide - A Splide instance.
  3768. * @param {Object} Components - An object containing components.
  3769. *
  3770. * @return {Object} - The component object.
  3771. */
  3772. /* harmony default export */ var components_cover = (function (Splide, Components) {
  3773. /**
  3774. * Hold options.
  3775. *
  3776. * @type {Object}
  3777. */
  3778. var options = Splide.options;
  3779. /**
  3780. * Cover component object.
  3781. *
  3782. * @type {Object}
  3783. */
  3784. var Cover = {
  3785. /**
  3786. * Required only when "cover" option is true.
  3787. *
  3788. * @type {boolean}
  3789. */
  3790. required: options.cover,
  3791. /**
  3792. * Called when the component is mounted.
  3793. */
  3794. mount: function mount() {
  3795. Splide.on('lazyload:loaded', function (img) {
  3796. cover(img, false);
  3797. });
  3798. Splide.on('mounted updated refresh', function () {
  3799. return apply(false);
  3800. });
  3801. },
  3802. /**
  3803. * Destroy.
  3804. */
  3805. destroy: function destroy() {
  3806. apply(true);
  3807. }
  3808. };
  3809. /**
  3810. * Apply "cover" to all slides.
  3811. *
  3812. * @param {boolean} uncover - If true, "cover" will be clear.
  3813. */
  3814. function apply(uncover) {
  3815. Components.Elements.each(function (Slide) {
  3816. var img = child(Slide.slide, 'img') || child(Slide.container, 'img');
  3817. if (img && img.src) {
  3818. cover(img, uncover);
  3819. }
  3820. });
  3821. }
  3822. /**
  3823. * Set background image of the parent element, using source of the given image element.
  3824. *
  3825. * @param {Element} img - An image element.
  3826. * @param {boolean} uncover - Reset "cover".
  3827. */
  3828. function cover(img, uncover) {
  3829. applyStyle(img.parentElement, {
  3830. background: uncover ? '' : "center/cover no-repeat url(\"" + img.src + "\")"
  3831. });
  3832. applyStyle(img, {
  3833. display: uncover ? '' : 'none'
  3834. });
  3835. }
  3836. return Cover;
  3837. });
  3838. // CONCATENATED MODULE: ./src/js/components/arrows/path.js
  3839. /**
  3840. * Export vector path for an arrow.
  3841. *
  3842. * @author Naotoshi Fujita
  3843. * @copyright Naotoshi Fujita. All rights reserved.
  3844. */
  3845. /**
  3846. * Namespace definition for SVG element.
  3847. *
  3848. * @type {string}
  3849. */
  3850. var XML_NAME_SPACE = 'http://www.w3.org/2000/svg';
  3851. /**
  3852. * The arrow vector path.
  3853. *
  3854. * @type {number}
  3855. */
  3856. 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';
  3857. /**
  3858. * SVG width and height.
  3859. *
  3860. * @type {number}
  3861. */
  3862. var SIZE = 40;
  3863. // CONCATENATED MODULE: ./src/js/components/arrows/index.js
  3864. /**
  3865. * The component for appending prev/next arrows.
  3866. *
  3867. * @author Naotoshi Fujita
  3868. * @copyright Naotoshi Fujita. All rights reserved.
  3869. */
  3870. /**
  3871. * The component for appending prev/next arrows.
  3872. *
  3873. * @param {Splide} Splide - A Splide instance.
  3874. * @param {Object} Components - An object containing components.
  3875. * @param {string} name - A component name as a lowercase string.
  3876. *
  3877. * @return {Object} - The component object.
  3878. */
  3879. /* harmony default export */ var components_arrows = (function (Splide, Components, name) {
  3880. /**
  3881. * Previous arrow element.
  3882. *
  3883. * @type {Element|undefined}
  3884. */
  3885. var prev;
  3886. /**
  3887. * Next arrow element.
  3888. *
  3889. * @type {Element|undefined}
  3890. */
  3891. var next;
  3892. /**
  3893. * Store the class list.
  3894. *
  3895. * @type {Object}
  3896. */
  3897. var classes = Splide.classes;
  3898. /**
  3899. * Hold the root element.
  3900. *
  3901. * @type {Element}
  3902. */
  3903. var root = Splide.root;
  3904. /**
  3905. * Whether arrows are created programmatically or not.
  3906. *
  3907. * @type {boolean}
  3908. */
  3909. var created;
  3910. /**
  3911. * Hold the Elements component.
  3912. *
  3913. * @type {Object}
  3914. */
  3915. var Elements = Components.Elements;
  3916. /**
  3917. * Arrows component object.
  3918. *
  3919. * @type {Object}
  3920. */
  3921. var Arrows = {
  3922. /**
  3923. * Required when the arrows option is true.
  3924. *
  3925. * @type {boolean}
  3926. */
  3927. required: Splide.options.arrows,
  3928. /**
  3929. * Called when the component is mounted.
  3930. */
  3931. mount: function mount() {
  3932. // Attempt to get arrows from HTML source.
  3933. prev = Elements.arrows.prev;
  3934. next = Elements.arrows.next; // If arrows were not found in HTML, let's generate them.
  3935. if ((!prev || !next) && Splide.options.arrows) {
  3936. prev = createArrow(true);
  3937. next = createArrow(false);
  3938. created = true;
  3939. appendArrows();
  3940. }
  3941. if (prev && next) {
  3942. bind();
  3943. }
  3944. this.arrows = {
  3945. prev: prev,
  3946. next: next
  3947. };
  3948. },
  3949. /**
  3950. * Called after all components are mounted.
  3951. */
  3952. mounted: function mounted() {
  3953. Splide.emit(name + ":mounted", prev, next);
  3954. },
  3955. /**
  3956. * Destroy.
  3957. */
  3958. destroy: function destroy() {
  3959. removeAttribute([prev, next], 'disabled');
  3960. if (created) {
  3961. dom_remove(prev.parentElement);
  3962. }
  3963. }
  3964. };
  3965. /**
  3966. * Listen native and custom events.
  3967. */
  3968. function bind() {
  3969. Splide.on('click', function () {
  3970. return onClick(true);
  3971. }, prev).on('click', function () {
  3972. return onClick(false);
  3973. }, next).on('mounted move updated refresh', updateDisabled);
  3974. }
  3975. /**
  3976. * Called when an arrow is clicked.
  3977. *
  3978. * @param {boolean} prev - If true, the previous arrow is clicked.
  3979. */
  3980. function onClick(prev) {
  3981. var perMove = Splide.options.perMove;
  3982. Splide.go(perMove ? "" + (prev ? '-' : '+') + perMove : prev ? '<' : '>');
  3983. }
  3984. /**
  3985. * Update a disabled attribute.
  3986. */
  3987. function updateDisabled() {
  3988. var _Components$Controlle = Components.Controller,
  3989. prevIndex = _Components$Controlle.prevIndex,
  3990. nextIndex = _Components$Controlle.nextIndex;
  3991. var isEnough = Splide.length > Splide.options.perPage || Splide.is(LOOP);
  3992. prev.disabled = prevIndex < 0 || !isEnough;
  3993. next.disabled = nextIndex < 0 || !isEnough;
  3994. Splide.emit(name + ":updated", prev, next, prevIndex, nextIndex);
  3995. }
  3996. /**
  3997. * Create a wrapper element and append arrows.
  3998. */
  3999. function appendArrows() {
  4000. var wrapper = create('div', {
  4001. "class": classes.arrows
  4002. });
  4003. append(wrapper, prev);
  4004. append(wrapper, next);
  4005. var slider = Elements.slider;
  4006. var parent = Splide.options.arrows === 'slider' && slider ? slider : root;
  4007. before(wrapper, parent.firstElementChild);
  4008. }
  4009. /**
  4010. * Create an arrow element.
  4011. *
  4012. * @param {boolean} prev - Determine to create a prev arrow or next arrow.
  4013. *
  4014. * @return {Element} - A created arrow element.
  4015. */
  4016. function createArrow(prev) {
  4017. var arrow = "<button class=\"" + classes.arrow + " " + (prev ? classes.prev : classes.next) + "\" type=\"button\">" + ("<svg xmlns=\"" + XML_NAME_SPACE + "\"\tviewBox=\"0 0 " + SIZE + " " + SIZE + "\"\twidth=\"" + SIZE + "\"\theight=\"" + SIZE + "\">") + ("<path d=\"" + (Splide.options.arrowPath || PATH) + "\" />");
  4018. return domify(arrow);
  4019. }
  4020. return Arrows;
  4021. });
  4022. // CONCATENATED MODULE: ./src/js/components/pagination/index.js
  4023. /**
  4024. * The component for handling pagination
  4025. *
  4026. * @author Naotoshi Fujita
  4027. * @copyright Naotoshi Fujita. All rights reserved.
  4028. */
  4029. /**
  4030. * The event name for updating some attributes of pagination nodes.
  4031. *
  4032. * @type {string}
  4033. */
  4034. var ATTRIBUTES_UPDATE_EVENT = 'move.page';
  4035. /**
  4036. * The event name for recreating pagination.
  4037. *
  4038. * @type {string}
  4039. */
  4040. var UPDATE_EVENT = 'updated.page refresh.page';
  4041. /**
  4042. * The component for handling pagination
  4043. *
  4044. * @param {Splide} Splide - A Splide instance.
  4045. * @param {Object} Components - An object containing components.
  4046. * @param {string} name - A component name as a lowercase string.
  4047. *
  4048. * @return {Object} - The component object.
  4049. */
  4050. /* harmony default export */ var pagination = (function (Splide, Components, name) {
  4051. /**
  4052. * Store all data for pagination.
  4053. * - list: A list element.
  4054. * - items: An array that contains objects(li, button, index, page).
  4055. *
  4056. * @type {Object}
  4057. */
  4058. var data = {};
  4059. /**
  4060. * Hold the Elements component.
  4061. *
  4062. * @type {Object}
  4063. */
  4064. var Elements = Components.Elements;
  4065. /**
  4066. * Pagination component object.
  4067. *
  4068. * @type {Object}
  4069. */
  4070. var Pagination = {
  4071. /**
  4072. * Required only when the pagination option is true.
  4073. *
  4074. * @type {boolean}
  4075. */
  4076. required: Splide.options.pagination,
  4077. /**
  4078. * Called when the component is mounted.
  4079. */
  4080. mount: function mount() {
  4081. data = createPagination();
  4082. var slider = Elements.slider;
  4083. var parent = Splide.options.pagination === 'slider' && slider ? slider : Splide.root;
  4084. append(parent, data.list);
  4085. bind();
  4086. },
  4087. /**
  4088. * Called after all components are mounted.
  4089. */
  4090. mounted: function mounted() {
  4091. var index = Splide.index;
  4092. Splide.emit(name + ":mounted", data, this.getItem(index));
  4093. update(index, -1);
  4094. },
  4095. /**
  4096. * Destroy the pagination.
  4097. * Be aware that node.remove() is not supported by IE.
  4098. */
  4099. destroy: function destroy() {
  4100. dom_remove(data.list);
  4101. if (data.items) {
  4102. data.items.forEach(function (item) {
  4103. Splide.off('click', item.button);
  4104. });
  4105. }
  4106. Splide.off(ATTRIBUTES_UPDATE_EVENT).off(UPDATE_EVENT);
  4107. data = {};
  4108. },
  4109. /**
  4110. * Return an item by index.
  4111. *
  4112. * @param {number} index - A slide index.
  4113. *
  4114. * @return {Object|undefined} - An item object on success or undefined on failure.
  4115. */
  4116. getItem: function getItem(index) {
  4117. return data.items[Components.Controller.toPage(index)];
  4118. },
  4119. /**
  4120. * Return object containing pagination data.
  4121. *
  4122. * @return {Object} - Pagination data including list and items.
  4123. */
  4124. get data() {
  4125. return data;
  4126. }
  4127. };
  4128. /**
  4129. * Listen some events.
  4130. */
  4131. function bind() {
  4132. Splide.on(ATTRIBUTES_UPDATE_EVENT, update).on(UPDATE_EVENT, function () {
  4133. Pagination.destroy();
  4134. if (Splide.options.pagination) {
  4135. Pagination.mount();
  4136. Pagination.mounted();
  4137. }
  4138. });
  4139. }
  4140. /**
  4141. * Update attributes.
  4142. *
  4143. * @param {number} index - Active index.
  4144. * @param {number} prevIndex - Prev index.
  4145. */
  4146. function update(index, prevIndex) {
  4147. var prev = Pagination.getItem(prevIndex);
  4148. var curr = Pagination.getItem(index);
  4149. var active = STATUS_CLASSES.active;
  4150. if (prev) {
  4151. removeClass(prev.button, active);
  4152. }
  4153. if (curr) {
  4154. addClass(curr.button, active);
  4155. }
  4156. Splide.emit(name + ":updated", data, prev, curr);
  4157. }
  4158. /**
  4159. * Create a wrapper and button elements.
  4160. *
  4161. * @return {Object} - An object contains all data.
  4162. */
  4163. function createPagination() {
  4164. var options = Splide.options;
  4165. var classes = Splide.classes;
  4166. var list = create('ul', {
  4167. "class": classes.pagination
  4168. });
  4169. var items = Elements.getSlides(false).filter(function (Slide) {
  4170. return options.focus !== false || Slide.index % options.perPage === 0;
  4171. }).map(function (Slide, page) {
  4172. var li = create('li', {});
  4173. var button = create('button', {
  4174. "class": classes.page,
  4175. type: 'button'
  4176. });
  4177. append(li, button);
  4178. append(list, li);
  4179. Splide.on('click', function () {
  4180. Splide.go(">" + page);
  4181. }, button);
  4182. return {
  4183. li: li,
  4184. button: button,
  4185. page: page,
  4186. Slides: Elements.getSlidesByPage(page)
  4187. };
  4188. });
  4189. return {
  4190. list: list,
  4191. items: items
  4192. };
  4193. }
  4194. return Pagination;
  4195. });
  4196. // CONCATENATED MODULE: ./src/js/components/lazyload/index.js
  4197. /**
  4198. * The component for loading slider images lazily.
  4199. *
  4200. * @author Naotoshi Fujita
  4201. * @copyright Naotoshi Fujita. All rights reserved.
  4202. */
  4203. /**
  4204. * The name for a data attribute.
  4205. *
  4206. * @type {string}
  4207. */
  4208. var SRC_DATA_NAME = 'data-splide-lazy';
  4209. /**
  4210. * The component for loading slider images lazily.
  4211. *
  4212. * @param {Splide} Splide - A Splide instance.
  4213. * @param {Object} Components - An object containing components.
  4214. * @param {string} name - A component name as a lowercase string.
  4215. *
  4216. * @return {Object} - The component object.
  4217. */
  4218. /* harmony default export */ var lazyload = (function (Splide, Components, name) {
  4219. /**
  4220. * Next index for sequential loading.
  4221. *
  4222. * @type {number}
  4223. */
  4224. var nextIndex;
  4225. /**
  4226. * Store objects containing an img element and a Slide object.
  4227. *
  4228. * @type {Object[]}
  4229. */
  4230. var images;
  4231. /**
  4232. * Store the options.
  4233. *
  4234. * @type {Object}
  4235. */
  4236. var options = Splide.options;
  4237. /**
  4238. * Whether to load images sequentially or not.
  4239. *
  4240. * @type {boolean}
  4241. */
  4242. var isSequential = options.lazyLoad === 'sequential';
  4243. /**
  4244. * Lazyload component object.
  4245. *
  4246. * @type {Object}
  4247. */
  4248. var Lazyload = {
  4249. /**
  4250. * Mount only when the lazyload option is provided.
  4251. *
  4252. * @type {boolean}
  4253. */
  4254. required: options.lazyLoad,
  4255. /**
  4256. * Called when the component is mounted.
  4257. */
  4258. mount: function mount() {
  4259. Splide.on('mounted refresh', function () {
  4260. init();
  4261. Components.Elements.each(function (Slide) {
  4262. each(Slide.slide.querySelectorAll("[" + SRC_DATA_NAME + "]"), function (img) {
  4263. if (!img.src) {
  4264. images.push({
  4265. img: img,
  4266. Slide: Slide
  4267. });
  4268. applyStyle(img, {
  4269. display: 'none'
  4270. });
  4271. }
  4272. });
  4273. });
  4274. if (isSequential) {
  4275. loadNext();
  4276. }
  4277. });
  4278. if (!isSequential) {
  4279. Splide.on("mounted refresh moved." + name, check);
  4280. }
  4281. },
  4282. /**
  4283. * Destroy.
  4284. */
  4285. destroy: init
  4286. };
  4287. /**
  4288. * Initialize parameters.
  4289. */
  4290. function init() {
  4291. images = [];
  4292. nextIndex = 0;
  4293. }
  4294. /**
  4295. * Check how close each image is from the active slide and
  4296. * determine whether to start loading or not, according to the distance.
  4297. *
  4298. * @param {number} index - Current index.
  4299. */
  4300. function check(index) {
  4301. index = isNaN(index) ? Splide.index : index;
  4302. images = images.filter(function (image) {
  4303. if (image.Slide.isWithin(index, options.perPage * (options.preloadPages + 1))) {
  4304. load(image.img, image.Slide);
  4305. return false;
  4306. }
  4307. return true;
  4308. }); // Unbind if all images are loaded.
  4309. if (!images[0]) {
  4310. Splide.off("moved." + name);
  4311. }
  4312. }
  4313. /**
  4314. * Start loading an image.
  4315. * Creating a clone of the image element since setting src attribute directly to it
  4316. * often occurs 'hitch', blocking some other processes of a browser.
  4317. *
  4318. * @param {Element} img - An image element.
  4319. * @param {Object} Slide - A Slide object.
  4320. */
  4321. function load(img, Slide) {
  4322. addClass(Slide.slide, STATUS_CLASSES.loading);
  4323. var spinner = create('span', {
  4324. "class": Splide.classes.spinner
  4325. });
  4326. append(img.parentElement, spinner);
  4327. img.onload = function () {
  4328. loaded(img, spinner, Slide, false);
  4329. };
  4330. img.onerror = function () {
  4331. loaded(img, spinner, Slide, true);
  4332. };
  4333. setAttribute(img, 'src', getAttribute(img, SRC_DATA_NAME));
  4334. }
  4335. /**
  4336. * Start loading a next image in images array.
  4337. */
  4338. function loadNext() {
  4339. if (nextIndex < images.length) {
  4340. var image = images[nextIndex];
  4341. load(image.img, image.Slide);
  4342. }
  4343. nextIndex++;
  4344. }
  4345. /**
  4346. * Called just after the image was loaded or loading was aborted by some error.
  4347. *
  4348. * @param {Element} img - An image element.
  4349. * @param {Element} spinner - A spinner element.
  4350. * @param {Object} Slide - A Slide object.
  4351. * @param {boolean} error - True if the image was loaded successfully or false on error.
  4352. */
  4353. function loaded(img, spinner, Slide, error) {
  4354. removeClass(Slide.slide, STATUS_CLASSES.loading);
  4355. if (!error) {
  4356. dom_remove(spinner);
  4357. applyStyle(img, {
  4358. display: ''
  4359. });
  4360. Splide.emit(name + ":loaded", img).emit('resize');
  4361. }
  4362. if (isSequential) {
  4363. loadNext();
  4364. }
  4365. }
  4366. return Lazyload;
  4367. });
  4368. // CONCATENATED MODULE: ./src/js/components/keyboard/index.js
  4369. /**
  4370. * The component for controlling slides via keyboard.
  4371. *
  4372. * @author Naotoshi Fujita
  4373. * @copyright Naotoshi Fujita. All rights reserved.
  4374. */
  4375. /**
  4376. * Map a key to a slide control.
  4377. *
  4378. * @type {Object}
  4379. */
  4380. var KEY_MAP = {
  4381. ltr: {
  4382. ArrowLeft: '<',
  4383. ArrowRight: '>',
  4384. // For IE.
  4385. Left: '<',
  4386. Right: '>'
  4387. },
  4388. rtl: {
  4389. ArrowLeft: '>',
  4390. ArrowRight: '<',
  4391. // For IE.
  4392. Left: '>',
  4393. Right: '<'
  4394. },
  4395. ttb: {
  4396. ArrowUp: '<',
  4397. ArrowDown: '>',
  4398. // For IE.
  4399. Up: '<',
  4400. Down: '>'
  4401. }
  4402. };
  4403. /**
  4404. * The component for controlling slides via keyboard.
  4405. *
  4406. * @param {Splide} Splide - A Splide instance.
  4407. *
  4408. * @return {Object} - The component object.
  4409. */
  4410. /* harmony default export */ var keyboard = (function (Splide) {
  4411. /**
  4412. * Hold the root element.
  4413. *
  4414. * @type {Element}
  4415. */
  4416. var root = Splide.root;
  4417. return {
  4418. /**
  4419. * Called when the component is mounted.
  4420. */
  4421. mount: function mount() {
  4422. var map = KEY_MAP[Splide.options.direction];
  4423. Splide.on('mounted updated', function () {
  4424. Splide.off('keydown', root);
  4425. if (Splide.options.keyboard) {
  4426. Splide.on('keydown', function (e) {
  4427. if (map[e.key]) {
  4428. Splide.go(map[e.key]);
  4429. }
  4430. }, root);
  4431. }
  4432. });
  4433. }
  4434. };
  4435. });
  4436. // CONCATENATED MODULE: ./src/js/constants/a11y.js
  4437. /**
  4438. * Export aria attribute names.
  4439. *
  4440. * @author Naotoshi Fujita
  4441. * @copyright Naotoshi Fujita. All rights reserved.
  4442. */
  4443. /**
  4444. * Attribute name for aria-current.
  4445. *
  4446. * @type {string}
  4447. */
  4448. var ARIA_CURRENRT = 'aria-current';
  4449. /**
  4450. * Attribute name for aria-control.
  4451. *
  4452. * @type {string}
  4453. */
  4454. var ARIA_CONTROLS = 'aria-controls';
  4455. /**
  4456. * Attribute name for aria-control.
  4457. *
  4458. * @type {string}
  4459. */
  4460. var ARIA_LABEL = 'aria-label';
  4461. /**
  4462. * Attribute name for aria-labelledby.
  4463. *
  4464. * @type {string}
  4465. */
  4466. var ARIA_LABELLEDBY = 'aria-labelledby';
  4467. /**
  4468. * Attribute name for aria-hidden.
  4469. *
  4470. * @type {string}
  4471. */
  4472. var ARIA_HIDDEN = 'aria-hidden';
  4473. /**
  4474. * Attribute name for tab-index.
  4475. *
  4476. * @type {string}
  4477. */
  4478. var TAB_INDEX = 'tabindex';
  4479. // CONCATENATED MODULE: ./src/js/components/a11y/index.js
  4480. /**
  4481. * The component for enhancing accessibility.
  4482. *
  4483. * @author Naotoshi Fujita
  4484. * @copyright Naotoshi Fujita. All rights reserved.
  4485. */
  4486. /**
  4487. * The component for enhancing accessibility.
  4488. *
  4489. * @param {Splide} Splide - A Splide instance.
  4490. * @param {Object} Components - An object containing components.
  4491. *
  4492. * @return {Object} - The component object.
  4493. */
  4494. /* harmony default export */ var a11y = (function (Splide, Components) {
  4495. /**
  4496. * Hold a i18n object.
  4497. *
  4498. * @type {Object}
  4499. */
  4500. var i18n = Splide.i18n;
  4501. /**
  4502. * Hold the Elements component.
  4503. *
  4504. * @type {Object}
  4505. */
  4506. var Elements = Components.Elements;
  4507. /**
  4508. * A11y component object.
  4509. *
  4510. * @type {Object}
  4511. */
  4512. var A11y = {
  4513. /**
  4514. * Required only when the accessibility option is true.
  4515. *
  4516. * @type {boolean}
  4517. */
  4518. required: Splide.options.accessibility,
  4519. /**
  4520. * Called when the component is mounted.
  4521. */
  4522. mount: function mount() {
  4523. Splide.on('visible', function (Slide) {
  4524. updateSlide(Slide.slide, true);
  4525. }).on('hidden', function (Slide) {
  4526. updateSlide(Slide.slide, false);
  4527. }).on('arrows:mounted', initArrows).on('arrows:updated', updateArrows).on('pagination:mounted', initPagination).on('pagination:updated', updatePagination);
  4528. if (Splide.options.isNavigation) {
  4529. Splide.on('navigation:mounted', initNavigation).on('active', function (Slide) {
  4530. updateNavigation(Slide, true);
  4531. }).on('inactive', function (Slide) {
  4532. updateNavigation(Slide, false);
  4533. });
  4534. }
  4535. initAutoplay();
  4536. },
  4537. /**
  4538. * Destroy.
  4539. */
  4540. destroy: function destroy() {
  4541. var arrows = Components.Arrows ? Components.Arrows.arrows : {};
  4542. removeAttribute(Elements.slides.concat([arrows.prev, arrows.next, Elements.play, Elements.pause]), [ARIA_HIDDEN, TAB_INDEX, ARIA_CONTROLS, ARIA_LABEL, ARIA_CURRENRT, 'role']);
  4543. }
  4544. };
  4545. /**
  4546. * Update slide attributes when it gets visible or hidden.
  4547. *
  4548. * @param {Element} slide - A slide element.
  4549. * @param {Boolean} visible - True when the slide gets visible, or false when hidden.
  4550. */
  4551. function updateSlide(slide, visible) {
  4552. setAttribute(slide, ARIA_HIDDEN, !visible);
  4553. setAttribute(slide, TAB_INDEX, visible ? 0 : -1);
  4554. }
  4555. /**
  4556. * Initialize arrows if they are available.
  4557. * Append screen reader elements and add aria-controls attribute.
  4558. *
  4559. * @param {Element} prev - Previous arrow element.
  4560. * @param {Element} next - Next arrow element.
  4561. */
  4562. function initArrows(prev, next) {
  4563. var controls = Elements.track.id;
  4564. setAttribute(prev, ARIA_CONTROLS, controls);
  4565. setAttribute(next, ARIA_CONTROLS, controls);
  4566. }
  4567. /**
  4568. * Update arrow attributes.
  4569. *
  4570. * @param {Element} prev - Previous arrow element.
  4571. * @param {Element} next - Next arrow element.
  4572. * @param {number} prevIndex - Previous slide index or -1 when there is no precede slide.
  4573. * @param {number} nextIndex - Next slide index or -1 when there is no next slide.
  4574. */
  4575. function updateArrows(prev, next, prevIndex, nextIndex) {
  4576. var index = Splide.index;
  4577. var prevLabel = prevIndex > -1 && index < prevIndex ? i18n.last : i18n.prev;
  4578. var nextLabel = nextIndex > -1 && index > nextIndex ? i18n.first : i18n.next;
  4579. setAttribute(prev, ARIA_LABEL, prevLabel);
  4580. setAttribute(next, ARIA_LABEL, nextLabel);
  4581. }
  4582. /**
  4583. * Initialize pagination if it's available.
  4584. * Append a screen reader element and add aria-controls/label attribute to each item.
  4585. *
  4586. * @param {Object} data - Data object containing all items.
  4587. * @param {Object} activeItem - An initial active item.
  4588. */
  4589. function initPagination(data, activeItem) {
  4590. if (activeItem) {
  4591. setAttribute(activeItem.button, ARIA_CURRENRT, true);
  4592. }
  4593. data.items.forEach(function (item) {
  4594. var options = Splide.options;
  4595. var text = options.focus === false && options.perPage > 1 ? i18n.pageX : i18n.slideX;
  4596. var label = sprintf(text, item.page + 1);
  4597. var button = item.button;
  4598. var controls = item.Slides.map(function (Slide) {
  4599. return Slide.slide.id;
  4600. });
  4601. setAttribute(button, ARIA_CONTROLS, controls.join(' '));
  4602. setAttribute(button, ARIA_LABEL, label);
  4603. });
  4604. }
  4605. /**
  4606. * Update pagination attributes.
  4607. *
  4608. * @param {Object} data - Data object containing all items.
  4609. * @param {Element} prev - A previous active element.
  4610. * @param {Element} curr - A current active element.
  4611. */
  4612. function updatePagination(data, prev, curr) {
  4613. if (prev) {
  4614. removeAttribute(prev.button, ARIA_CURRENRT);
  4615. }
  4616. if (curr) {
  4617. setAttribute(curr.button, ARIA_CURRENRT, true);
  4618. }
  4619. }
  4620. /**
  4621. * Initialize autoplay buttons.
  4622. */
  4623. function initAutoplay() {
  4624. ['play', 'pause'].forEach(function (name) {
  4625. var elm = Elements[name];
  4626. if (elm) {
  4627. if (!isButton(elm)) {
  4628. setAttribute(elm, 'role', 'button');
  4629. }
  4630. setAttribute(elm, ARIA_CONTROLS, Elements.track.id);
  4631. setAttribute(elm, ARIA_LABEL, i18n[name]);
  4632. }
  4633. });
  4634. }
  4635. /**
  4636. * Initialize navigation slider.
  4637. * Add button role, aria-label, aria-controls to slide elements and append screen reader text to them.
  4638. *
  4639. * @param {Splide} main - A main Splide instance.
  4640. */
  4641. function initNavigation(main) {
  4642. Elements.each(function (_ref) {
  4643. var slide = _ref.slide,
  4644. realIndex = _ref.realIndex,
  4645. index = _ref.index;
  4646. if (!isButton(slide)) {
  4647. setAttribute(slide, 'role', 'button');
  4648. }
  4649. var slideIndex = realIndex > -1 ? realIndex : index;
  4650. var label = sprintf(i18n.slideX, slideIndex + 1);
  4651. var mainSlide = main.Components.Elements.getSlide(slideIndex);
  4652. setAttribute(slide, ARIA_LABEL, label);
  4653. if (mainSlide) {
  4654. setAttribute(slide, ARIA_CONTROLS, mainSlide.slide.id);
  4655. }
  4656. });
  4657. }
  4658. /**
  4659. * Update navigation attributes.
  4660. *
  4661. * @param {Object} Slide - A target Slide object.
  4662. * @param {boolean} active - True if the slide is active or false if inactive.
  4663. */
  4664. function updateNavigation(_ref2, active) {
  4665. var slide = _ref2.slide;
  4666. if (active) {
  4667. setAttribute(slide, ARIA_CURRENRT, true);
  4668. } else {
  4669. removeAttribute(slide, ARIA_CURRENRT);
  4670. }
  4671. }
  4672. /**
  4673. * Check if the given element is button or not.
  4674. *
  4675. * @param {Element} elm - An element to be checked.
  4676. *
  4677. * @return {boolean} - True if the given element is button.
  4678. */
  4679. function isButton(elm) {
  4680. return elm.tagName.toLowerCase() === 'button';
  4681. }
  4682. return A11y;
  4683. });
  4684. // CONCATENATED MODULE: ./src/js/components/sync/index.js
  4685. /**
  4686. * The component for synchronizing a slider with another.
  4687. *
  4688. * @author Naotoshi Fujita
  4689. * @copyright Naotoshi Fujita. All rights reserved.
  4690. */
  4691. /**
  4692. * The event name for sync.
  4693. *
  4694. * @type {string}
  4695. */
  4696. var SYNC_EVENT = 'move.sync';
  4697. /**
  4698. * The keys for triggering the navigation button.
  4699. *
  4700. * @type {String[]}
  4701. */
  4702. var TRIGGER_KEYS = [' ', 'Enter', 'Spacebar'];
  4703. /**
  4704. * The component for synchronizing a slider with another.
  4705. *
  4706. * @param {Splide} Splide - A Splide instance.
  4707. *
  4708. * @return {Object} - The component object.
  4709. */
  4710. /* harmony default export */ var sync = (function (Splide) {
  4711. /**
  4712. * Keep the sibling Splide instance.
  4713. *
  4714. * @type {Splide}
  4715. */
  4716. var sibling = Splide.sibling;
  4717. /**
  4718. * Whether the sibling slider is navigation or not.
  4719. *
  4720. * @type {Splide|boolean}
  4721. */
  4722. var isNavigation = sibling && sibling.options.isNavigation;
  4723. /**
  4724. * Layout component object.
  4725. *
  4726. * @type {Object}
  4727. */
  4728. var Sync = {
  4729. /**
  4730. * Required only when the sub slider is available.
  4731. *
  4732. * @type {boolean}
  4733. */
  4734. required: !!sibling,
  4735. /**
  4736. * Called when the component is mounted.
  4737. */
  4738. mount: function mount() {
  4739. syncMain();
  4740. syncSibling();
  4741. if (isNavigation) {
  4742. bind();
  4743. }
  4744. },
  4745. /**
  4746. * Called after all components are mounted.
  4747. */
  4748. mounted: function mounted() {
  4749. if (isNavigation) {
  4750. sibling.emit('navigation:mounted', Splide);
  4751. }
  4752. }
  4753. };
  4754. /**
  4755. * Listen the primary slider event to move secondary one.
  4756. * Must unbind a handler at first to avoid infinite loop.
  4757. */
  4758. function syncMain() {
  4759. Splide.on(SYNC_EVENT, function (newIndex, prevIndex, destIndex) {
  4760. sibling.off(SYNC_EVENT).go(sibling.is(LOOP) ? destIndex : newIndex, false);
  4761. syncSibling();
  4762. });
  4763. }
  4764. /**
  4765. * Listen the secondary slider event to move primary one.
  4766. * Must unbind a handler at first to avoid infinite loop.
  4767. */
  4768. function syncSibling() {
  4769. sibling.on(SYNC_EVENT, function (newIndex, prevIndex, destIndex) {
  4770. Splide.off(SYNC_EVENT).go(Splide.is(LOOP) ? destIndex : newIndex, false);
  4771. syncMain();
  4772. });
  4773. }
  4774. /**
  4775. * Listen some events on each slide.
  4776. */
  4777. function bind() {
  4778. sibling.Components.Elements.each(function (_ref) {
  4779. var slide = _ref.slide,
  4780. index = _ref.index;
  4781. /*
  4782. * Listen mouseup and touchend events to handle click.
  4783. */
  4784. Splide.on('mouseup touchend', function (e) {
  4785. // Ignore a middle or right click.
  4786. if (!e.button || e.button === 0) {
  4787. moveSibling(index);
  4788. }
  4789. }, slide);
  4790. /*
  4791. * Subscribe keyup to handle Enter and Space key.
  4792. * Note that Array.includes is not supported by IE.
  4793. */
  4794. Splide.on('keyup', function (e) {
  4795. if (TRIGGER_KEYS.indexOf(e.key) > -1) {
  4796. e.preventDefault();
  4797. moveSibling(index);
  4798. }
  4799. }, slide, {
  4800. passive: false
  4801. });
  4802. });
  4803. }
  4804. /**
  4805. * Move the sibling to the given index.
  4806. * Need to check "IDLE" status because slides can be moving by Drag component.
  4807. *
  4808. * @param {number} index - Target index.
  4809. */
  4810. function moveSibling(index) {
  4811. if (Splide.State.is(IDLE)) {
  4812. sibling.go(index);
  4813. }
  4814. }
  4815. return Sync;
  4816. });
  4817. // CONCATENATED MODULE: ./src/js/components/breakpoints/index.js
  4818. /**
  4819. * The component for updating options according to a current window width.
  4820. *
  4821. * @author Naotoshi Fujita
  4822. * @copyright Naotoshi Fujita. All rights reserved.
  4823. */
  4824. /**
  4825. * Interval time for throttle.
  4826. *
  4827. * @type {number}
  4828. */
  4829. var breakpoints_THROTTLE = 50;
  4830. /**
  4831. * The component for updating options according to a current window width.
  4832. *
  4833. * @param {Splide} Splide - A Splide instance.
  4834. *
  4835. * @return {Object} - The component object.
  4836. */
  4837. /* harmony default export */ var components_breakpoints = (function (Splide) {
  4838. /**
  4839. * Store breakpoints.
  4840. *
  4841. * @type {Object|boolean}
  4842. */
  4843. var breakpoints = Splide.options.breakpoints;
  4844. /**
  4845. * The check function whose frequency of call is reduced.
  4846. *
  4847. * @type {Function}
  4848. */
  4849. var throttledCheck = throttle(check, breakpoints_THROTTLE);
  4850. /**
  4851. * Keep initial options.
  4852. *
  4853. * @type {Object}
  4854. */
  4855. var initialOptions;
  4856. /**
  4857. * An array containing objects of point and MediaQueryList.
  4858. *
  4859. * @type {Object[]}
  4860. */
  4861. var map = [];
  4862. /**
  4863. * Hold the previous breakpoint.
  4864. *
  4865. * @type {number|undefined}
  4866. */
  4867. var prevPoint;
  4868. /**
  4869. * Breakpoints component object.
  4870. *
  4871. * @type {Object}
  4872. */
  4873. var Breakpoints = {
  4874. /**
  4875. * Required only when the breakpoints definition is provided and browser supports matchMedia.
  4876. *
  4877. * @type {boolean}
  4878. */
  4879. required: breakpoints && matchMedia,
  4880. /**
  4881. * Called when the component is mounted.
  4882. */
  4883. mount: function mount() {
  4884. map = Object.keys(breakpoints).sort(function (n, m) {
  4885. return parseInt(n) - parseInt(m);
  4886. }).map(function (point) {
  4887. return {
  4888. point: point,
  4889. mql: matchMedia("(max-width:" + point + "px)")
  4890. };
  4891. });
  4892. /*
  4893. * To keep monitoring resize event after destruction without "completely",
  4894. * use native addEventListener instead of Splide.on.
  4895. */
  4896. this.destroy(true);
  4897. addEventListener('resize', throttledCheck); // Keep initial options to apply them when no breakpoint matches.
  4898. initialOptions = Splide.options;
  4899. check();
  4900. },
  4901. /**
  4902. * Destroy.
  4903. *
  4904. * @param {boolean} completely - Whether to destroy Splide completely.
  4905. */
  4906. destroy: function destroy(completely) {
  4907. if (completely) {
  4908. removeEventListener('resize', throttledCheck);
  4909. }
  4910. }
  4911. };
  4912. /**
  4913. * Check the breakpoint.
  4914. */
  4915. function check() {
  4916. var point = getPoint();
  4917. if (point !== prevPoint) {
  4918. prevPoint = point;
  4919. var State = Splide.State;
  4920. var options = breakpoints[point] || initialOptions;
  4921. var destroy = options.destroy;
  4922. if (destroy) {
  4923. Splide.options = initialOptions;
  4924. Splide.destroy(destroy === 'completely');
  4925. } else {
  4926. if (State.is(DESTROYED)) {
  4927. State.set(CREATED);
  4928. Splide.mount();
  4929. } else {
  4930. Splide.options = options;
  4931. }
  4932. }
  4933. }
  4934. }
  4935. /**
  4936. * Return the breakpoint matching current window width.
  4937. * Note that Array.prototype.find is not supported by IE.
  4938. *
  4939. * @return {number|string} - A breakpoint as number or string. -1 if no point matches.
  4940. */
  4941. function getPoint() {
  4942. var item = map.filter(function (item) {
  4943. return item.mql.matches;
  4944. })[0];
  4945. return item ? item.point : -1;
  4946. }
  4947. return Breakpoints;
  4948. });
  4949. // CONCATENATED MODULE: ./src/js/components/index.js
  4950. /**
  4951. * Export components.
  4952. *
  4953. * @author Naotoshi Fujita
  4954. * @copyright Naotoshi Fujita. All rights reserved.
  4955. */
  4956. var COMPLETE = {
  4957. Options: components_options,
  4958. Breakpoints: components_breakpoints,
  4959. Elements: components_elements,
  4960. Controller: controller,
  4961. Track: components_track,
  4962. Clones: components_clones,
  4963. Layout: layout,
  4964. Drag: drag,
  4965. Click: click,
  4966. Autoplay: components_autoplay,
  4967. Cover: components_cover,
  4968. Arrows: components_arrows,
  4969. Pagination: pagination,
  4970. LazyLoad: lazyload,
  4971. Keyboard: keyboard,
  4972. Sync: sync,
  4973. A11y: a11y
  4974. };
  4975. var LIGHT = {
  4976. Options: components_options,
  4977. Elements: components_elements,
  4978. Controller: controller,
  4979. Track: components_track,
  4980. Clones: components_clones,
  4981. Layout: layout,
  4982. Drag: drag,
  4983. Arrows: components_arrows,
  4984. Pagination: pagination,
  4985. A11y: a11y
  4986. };
  4987. // CONCATENATED MODULE: ./build/module/module.js
  4988. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
  4989. /**
  4990. * Export Splide class for import.
  4991. *
  4992. * @author Naotoshi Fujita
  4993. * @copyright Naotoshi Fujita. All rights reserved.
  4994. */
  4995. /**
  4996. * Export Splide class for import from other projects.
  4997. */
  4998. var module_Splide = /*#__PURE__*/function (_Core) {
  4999. _inheritsLoose(Splide, _Core);
  5000. function Splide(root, options) {
  5001. return _Core.call(this, root, options, COMPLETE) || this;
  5002. }
  5003. return Splide;
  5004. }(splide_Splide);
  5005. /***/ })
  5006. /******/ ]);
  5007. });