splide.js 125 KB

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