splide.js 122 KB

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