splide.esm.js 134 KB

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