splide.esm.js 134 KB

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