splide.js 134 KB

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