splide.js 124 KB

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