splide.js 135 KB

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