splide.js 135 KB

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