splide.js 134 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859
  1. /*!
  2. * Splide.js
  3. * Version : 2.4.20
  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:before').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 resized.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 ceil = Math.ceil;
  1837. var trackRect = getRect(Splide.Components.Elements.track);
  1838. var slideRect = getRect(slide);
  1839. if (Splide.options.direction === TTB) {
  1840. return trackRect.top <= slideRect.top && slideRect.bottom <= ceil(trackRect.bottom);
  1841. }
  1842. return trackRect.left <= slideRect.left && slideRect.right <= ceil(trackRect.right);
  1843. },
  1844. /**
  1845. * Calculate how far this slide is from another slide and
  1846. * return true if the distance is within the given number.
  1847. *
  1848. * @param {number} from - Index of a target slide.
  1849. * @param {number} within - True if the slide is within this number.
  1850. *
  1851. * @return {boolean} - True if the slide is within the number or false otherwise.
  1852. */
  1853. isWithin: function isWithin(from, within) {
  1854. var diff = Math.abs(from - index);
  1855. if (!Splide.is(SLIDE) && !this.isClone) {
  1856. diff = Math.min(diff, Splide.length - diff);
  1857. }
  1858. return diff < within;
  1859. }
  1860. };
  1861. /**
  1862. * Update classes for activity or visibility.
  1863. *
  1864. * @param {boolean} active - Is active/visible or not.
  1865. * @param {boolean} forVisibility - Toggle classes for activity or visibility.
  1866. */
  1867. function _update(active, forVisibility) {
  1868. var type = forVisibility ? 'visible' : 'active';
  1869. var className = STATUS_CLASSES[type];
  1870. if (active) {
  1871. addClass(slide, className);
  1872. Splide.emit("" + type, Slide);
  1873. } else {
  1874. if (hasClass(slide, className)) {
  1875. removeClass(slide, className);
  1876. Splide.emit("" + (forVisibility ? 'hidden' : 'inactive'), Slide);
  1877. }
  1878. }
  1879. }
  1880. /**
  1881. * Restore the original styles.
  1882. */
  1883. function restoreStyles() {
  1884. setAttribute(slide, 'style', Slide.styles);
  1885. }
  1886. return Slide;
  1887. });
  1888. // CONCATENATED MODULE: ./src/js/components/elements/index.js
  1889. /**
  1890. * The component for main elements.
  1891. *
  1892. * @author Naotoshi Fujita
  1893. * @copyright Naotoshi Fujita. All rights reserved.
  1894. */
  1895. ;
  1896. /**
  1897. * The property name for UID stored in a window object.
  1898. *
  1899. * @type {string}
  1900. */
  1901. var UID_NAME = 'uid';
  1902. /**
  1903. * The component for main elements.
  1904. *
  1905. * @param {Splide} Splide - A Splide instance.
  1906. * @param {Object} Components - An object containing components.
  1907. *
  1908. * @return {Object} - The component object.
  1909. */
  1910. /* harmony default export */ const components_elements = (function (Splide, Components) {
  1911. /**
  1912. * Hold the root element.
  1913. *
  1914. * @type {Element}
  1915. */
  1916. var root = Splide.root;
  1917. /**
  1918. * Hold the class list.
  1919. *
  1920. * @type {Object}
  1921. */
  1922. var classes = Splide.classes;
  1923. /**
  1924. * Store Slide objects.
  1925. *
  1926. * @type {Array}
  1927. */
  1928. var Slides = [];
  1929. /*
  1930. * Assign unique ID to the root element if it doesn't have the one.
  1931. * Note that IE doesn't support padStart() to fill the uid by 0.
  1932. */
  1933. if (!root.id) {
  1934. window.splide = window.splide || {};
  1935. var uid = window.splide[UID_NAME] || 0;
  1936. window.splide[UID_NAME] = ++uid;
  1937. root.id = "splide" + pad(uid);
  1938. }
  1939. /**
  1940. * Elements component object.
  1941. *
  1942. * @type {Object}
  1943. */
  1944. var Elements = {
  1945. /**
  1946. * Called when the component is mounted.
  1947. * Collect main elements and store them as member properties.
  1948. */
  1949. mount: function mount() {
  1950. var _this = this;
  1951. this.init();
  1952. Splide.on('refresh', function () {
  1953. _this.destroy();
  1954. _this.init();
  1955. }).on('updated', function () {
  1956. removeClass(root, getClasses());
  1957. addClass(root, getClasses());
  1958. });
  1959. },
  1960. /**
  1961. * Destroy.
  1962. */
  1963. destroy: function destroy() {
  1964. Slides.forEach(function (Slide) {
  1965. Slide.destroy();
  1966. });
  1967. Slides = [];
  1968. removeClass(root, getClasses());
  1969. },
  1970. /**
  1971. * Initialization.
  1972. */
  1973. init: function init() {
  1974. var _this2 = this;
  1975. collect();
  1976. addClass(root, getClasses());
  1977. this.slides.forEach(function (slide, index) {
  1978. _this2.register(slide, index, -1);
  1979. });
  1980. },
  1981. /**
  1982. * Register a slide to create a Slide object and handle its behavior.
  1983. *
  1984. * @param {Element} slide - A slide element.
  1985. * @param {number} index - A unique index. This can be negative.
  1986. * @param {number} realIndex - A real index for clones. Set -1 for real slides.
  1987. */
  1988. register: function register(slide, index, realIndex) {
  1989. var SlideObject = elements_slide(Splide, index, realIndex, slide);
  1990. SlideObject.mount();
  1991. Slides.push(SlideObject);
  1992. },
  1993. /**
  1994. * Return the Slide object designated by the index.
  1995. * Note that "find" is not supported by IE.
  1996. *
  1997. * @return {Object|undefined} - A Slide object if available. Undefined if not.
  1998. */
  1999. getSlide: function getSlide(index) {
  2000. return Slides.filter(function (Slide) {
  2001. return Slide.index === index;
  2002. })[0];
  2003. },
  2004. /**
  2005. * Return all Slide objects.
  2006. *
  2007. * @param {boolean} includeClones - Whether to include cloned slides or not.
  2008. *
  2009. * @return {Object[]} - Slide objects.
  2010. */
  2011. getSlides: function getSlides(includeClones) {
  2012. return includeClones ? Slides : Slides.filter(function (Slide) {
  2013. return !Slide.isClone;
  2014. });
  2015. },
  2016. /**
  2017. * Return Slide objects belonging to the given page.
  2018. *
  2019. * @param {number} page - A page number.
  2020. *
  2021. * @return {Object[]} - An array containing Slide objects.
  2022. */
  2023. getSlidesByPage: function getSlidesByPage(page) {
  2024. var idx = Components.Controller.toIndex(page);
  2025. var options = Splide.options;
  2026. var max = options.focus !== false ? 1 : options.perPage;
  2027. return Slides.filter(function (_ref) {
  2028. var index = _ref.index;
  2029. return idx <= index && index < idx + max;
  2030. });
  2031. },
  2032. /**
  2033. * Insert a slide to a slider.
  2034. * Need to refresh Splide after adding a slide.
  2035. *
  2036. * @param {Node|string} slide - A slide element to be added.
  2037. * @param {number} index - A slide will be added at the position.
  2038. * @param {Function} callback - Called right after the slide is added to the DOM tree.
  2039. */
  2040. add: function add(slide, index, callback) {
  2041. if (typeof slide === 'string') {
  2042. slide = domify(slide);
  2043. }
  2044. if (slide instanceof Element) {
  2045. var ref = this.slides[index]; // This will be removed in mount() of a Slide component.
  2046. applyStyle(slide, {
  2047. display: 'none'
  2048. });
  2049. if (ref) {
  2050. before(slide, ref);
  2051. this.slides.splice(index, 0, slide);
  2052. } else {
  2053. append(this.list, slide);
  2054. this.slides.push(slide);
  2055. }
  2056. loaded(slide, function () {
  2057. callback && callback(slide);
  2058. });
  2059. }
  2060. },
  2061. /**
  2062. * Remove a slide from a slider.
  2063. * Need to refresh Splide after removing a slide.
  2064. *
  2065. * @param index - Slide index.
  2066. */
  2067. remove: function remove(index) {
  2068. dom_remove(this.slides.splice(index, 1)[0]);
  2069. },
  2070. /**
  2071. * Trigger the provided callback for each Slide object.
  2072. *
  2073. * @param {Function} callback - A callback function. The first argument will be the Slide object.
  2074. */
  2075. each: function each(callback) {
  2076. Slides.forEach(callback);
  2077. },
  2078. /**
  2079. * Return slides length without clones.
  2080. *
  2081. * @return {number} - Slide length.
  2082. */
  2083. get length() {
  2084. return this.slides.length;
  2085. },
  2086. /**
  2087. * Return "SlideObjects" length including clones.
  2088. *
  2089. * @return {number} - Slide length including clones.
  2090. */
  2091. get total() {
  2092. return Slides.length;
  2093. }
  2094. };
  2095. /**
  2096. * Collect elements.
  2097. */
  2098. function collect() {
  2099. Elements.slider = child(root, classes.slider);
  2100. Elements.track = find(root, "." + classes.track);
  2101. Elements.list = child(Elements.track, classes.list);
  2102. exist(Elements.track && Elements.list, 'Track or list was not found.');
  2103. Elements.slides = children(Elements.list, classes.slide);
  2104. var arrows = findParts(classes.arrows);
  2105. Elements.arrows = {
  2106. prev: find(arrows, "." + classes.prev),
  2107. next: find(arrows, "." + classes.next)
  2108. };
  2109. var autoplay = findParts(classes.autoplay);
  2110. Elements.bar = find(findParts(classes.progress), "." + classes.bar);
  2111. Elements.play = find(autoplay, "." + classes.play);
  2112. Elements.pause = find(autoplay, "." + classes.pause);
  2113. Elements.track.id = Elements.track.id || root.id + "-track";
  2114. Elements.list.id = Elements.list.id || root.id + "-list";
  2115. }
  2116. /**
  2117. * Return class names for the root element.
  2118. */
  2119. function getClasses() {
  2120. var rootClass = classes.root;
  2121. var options = Splide.options;
  2122. return [rootClass + "--" + options.type, rootClass + "--" + options.direction, options.drag ? rootClass + "--draggable" : '', options.isNavigation ? rootClass + "--nav" : '', STATUS_CLASSES.active];
  2123. }
  2124. /**
  2125. * Find parts only from children of the root or track.
  2126. *
  2127. * @return {Element} - A found element or undefined.
  2128. */
  2129. function findParts(className) {
  2130. return child(root, className) || child(Elements.slider, className);
  2131. }
  2132. return Elements;
  2133. });
  2134. // CONCATENATED MODULE: ./src/js/components/controller/index.js
  2135. /**
  2136. * The component for controlling the track.
  2137. *
  2138. * @author Naotoshi Fujita
  2139. * @copyright Naotoshi Fujita. All rights reserved.
  2140. */
  2141. ;
  2142. var floor = Math.floor;
  2143. /**
  2144. * The component for controlling the track.
  2145. *
  2146. * @param {Splide} Splide - A Splide instance.
  2147. * @param {Object} Components - An object containing components.
  2148. *
  2149. * @return {Object} - The component object.
  2150. */
  2151. /* harmony default export */ const controller = (function (Splide, Components) {
  2152. /**
  2153. * Store current options.
  2154. *
  2155. * @type {Object}
  2156. */
  2157. var options;
  2158. /**
  2159. * True if the slide is LOOP mode.
  2160. *
  2161. * @type {boolean}
  2162. */
  2163. var isLoop;
  2164. /**
  2165. * Controller component object.
  2166. *
  2167. * @type {Object}
  2168. */
  2169. var Controller = {
  2170. /**
  2171. * Called when the component is mounted.
  2172. */
  2173. mount: function mount() {
  2174. options = Splide.options;
  2175. isLoop = Splide.is(LOOP);
  2176. bind();
  2177. },
  2178. /**
  2179. * Make track run by the given control.
  2180. * - "+{i}" : Increment the slide index by i.
  2181. * - "-{i}" : Decrement the slide index by i.
  2182. * - "{i}" : Go to the slide whose index is i.
  2183. * - ">" : Go to next page.
  2184. * - "<" : Go to prev page.
  2185. * - ">{i}" : Go to page i.
  2186. *
  2187. * @param {string|number} control - A control pattern.
  2188. * @param {boolean} silently - Go to the destination without event emission.
  2189. */
  2190. go: function go(control, silently) {
  2191. var destIndex = this.trim(this.parse(control));
  2192. Components.Track.go(destIndex, this.rewind(destIndex), silently);
  2193. },
  2194. /**
  2195. * Parse the given control and return the destination index for the track.
  2196. *
  2197. * @param {string} control - A control target pattern.
  2198. *
  2199. * @return {number} - A parsed target.
  2200. */
  2201. parse: function parse(control) {
  2202. var index = Splide.index;
  2203. var matches = String(control).match(/([+\-<>]+)(\d+)?/);
  2204. var indicator = matches ? matches[1] : '';
  2205. var number = matches ? parseInt(matches[2]) : 0;
  2206. switch (indicator) {
  2207. case '+':
  2208. index += number || 1;
  2209. break;
  2210. case '-':
  2211. index -= number || 1;
  2212. break;
  2213. case '>':
  2214. case '<':
  2215. index = parsePage(number, index, indicator === '<');
  2216. break;
  2217. default:
  2218. index = parseInt(control);
  2219. }
  2220. return index;
  2221. },
  2222. /**
  2223. * Compute index from the given page number.
  2224. *
  2225. * @param {number} page - Page number.
  2226. *
  2227. * @return {number} - A computed page number.
  2228. */
  2229. toIndex: function toIndex(page) {
  2230. if (hasFocus()) {
  2231. return page;
  2232. }
  2233. var length = Splide.length;
  2234. var perPage = options.perPage;
  2235. var index = page * perPage;
  2236. index = index - (this.pageLength * perPage - length) * floor(index / length); // Adjustment for the last page.
  2237. if (length - perPage <= index && index < length) {
  2238. index = length - perPage;
  2239. }
  2240. return index;
  2241. },
  2242. /**
  2243. * Compute page number from the given slide index.
  2244. *
  2245. * @param {number} index - Slide index.
  2246. *
  2247. * @return {number} - A computed page number.
  2248. */
  2249. toPage: function toPage(index) {
  2250. if (hasFocus()) {
  2251. return index;
  2252. }
  2253. var length = Splide.length;
  2254. var perPage = options.perPage; // Make the last "perPage" number of slides belong to the last page.
  2255. if (length - perPage <= index && index < length) {
  2256. return floor((length - 1) / perPage);
  2257. }
  2258. return floor(index / perPage);
  2259. },
  2260. /**
  2261. * Trim the given index according to the current mode.
  2262. * Index being returned could be less than 0 or greater than the length in Loop mode.
  2263. *
  2264. * @param {number} index - An index being trimmed.
  2265. *
  2266. * @return {number} - A trimmed index.
  2267. */
  2268. trim: function trim(index) {
  2269. if (!isLoop) {
  2270. index = options.rewind ? this.rewind(index) : between(index, 0, this.edgeIndex);
  2271. }
  2272. return index;
  2273. },
  2274. /**
  2275. * Rewind the given index if it's out of range.
  2276. *
  2277. * @param {number} index - An index.
  2278. *
  2279. * @return {number} - A rewound index.
  2280. */
  2281. rewind: function rewind(index) {
  2282. var edge = this.edgeIndex;
  2283. if (isLoop) {
  2284. while (index > edge) {
  2285. index -= edge + 1;
  2286. }
  2287. while (index < 0) {
  2288. index += edge + 1;
  2289. }
  2290. } else {
  2291. if (index > edge) {
  2292. index = 0;
  2293. } else if (index < 0) {
  2294. index = edge;
  2295. }
  2296. }
  2297. return index;
  2298. },
  2299. /**
  2300. * Check if the direction is "rtl" or not.
  2301. *
  2302. * @return {boolean} - True if "rtl" or false if not.
  2303. */
  2304. isRtl: function isRtl() {
  2305. return options.direction === RTL;
  2306. },
  2307. /**
  2308. * Return the page length.
  2309. *
  2310. * @return {number} - Max page number.
  2311. */
  2312. get pageLength() {
  2313. var length = Splide.length;
  2314. return hasFocus() ? length : Math.ceil(length / options.perPage);
  2315. },
  2316. /**
  2317. * Return the edge index.
  2318. *
  2319. * @return {number} - Edge index.
  2320. */
  2321. get edgeIndex() {
  2322. var length = Splide.length;
  2323. if (!length) {
  2324. return 0;
  2325. }
  2326. if (hasFocus() || options.isNavigation || isLoop) {
  2327. return length - 1;
  2328. }
  2329. return length - options.perPage;
  2330. },
  2331. /**
  2332. * Return the index of the previous slide.
  2333. *
  2334. * @return {number} - The index of the previous slide if available. -1 otherwise.
  2335. */
  2336. get prevIndex() {
  2337. var prev = Splide.index - 1;
  2338. if (isLoop || options.rewind) {
  2339. prev = this.rewind(prev);
  2340. }
  2341. return prev > -1 ? prev : -1;
  2342. },
  2343. /**
  2344. * Return the index of the next slide.
  2345. *
  2346. * @return {number} - The index of the next slide if available. -1 otherwise.
  2347. */
  2348. get nextIndex() {
  2349. var next = Splide.index + 1;
  2350. if (isLoop || options.rewind) {
  2351. next = this.rewind(next);
  2352. }
  2353. return Splide.index < next && next <= this.edgeIndex || next === 0 ? next : -1;
  2354. }
  2355. };
  2356. /**
  2357. * Listen to some events.
  2358. */
  2359. function bind() {
  2360. Splide.on('move', function (newIndex) {
  2361. Splide.index = newIndex;
  2362. }).on('updated refresh', function (newOptions) {
  2363. options = newOptions || options;
  2364. Splide.index = between(Splide.index, 0, Controller.edgeIndex);
  2365. });
  2366. }
  2367. /**
  2368. * Verify if the focus option is available or not.
  2369. *
  2370. * @return {boolean} - True if a slider has the focus option.
  2371. */
  2372. function hasFocus() {
  2373. return options.focus !== false;
  2374. }
  2375. /**
  2376. * Return the next or previous page index computed by the page number and current index.
  2377. *
  2378. * @param {number} number - Specify the page number.
  2379. * @param {number} index - Current index.
  2380. * @param {boolean} prev - Prev or next.
  2381. *
  2382. * @return {number} - Slide index.
  2383. */
  2384. function parsePage(number, index, prev) {
  2385. if (number > -1) {
  2386. return Controller.toIndex(number);
  2387. }
  2388. var perMove = options.perMove;
  2389. var sign = prev ? -1 : 1;
  2390. if (perMove) {
  2391. return index + perMove * sign;
  2392. }
  2393. return Controller.toIndex(Controller.toPage(index) + sign);
  2394. }
  2395. return Controller;
  2396. });
  2397. // CONCATENATED MODULE: ./src/js/components/track/index.js
  2398. /**
  2399. * The component for moving list in the track.
  2400. *
  2401. * @author Naotoshi Fujita
  2402. * @copyright Naotoshi Fujita. All rights reserved.
  2403. */
  2404. ;
  2405. var abs = Math.abs;
  2406. /**
  2407. * The component for moving list in the track.
  2408. *
  2409. * @param {Splide} Splide - A Splide instance.
  2410. * @param {Object} Components - An object containing components.
  2411. *
  2412. * @return {Object} - The component object.
  2413. */
  2414. /* harmony default export */ const track = (function (Splide, Components) {
  2415. /**
  2416. * Hold the Layout component.
  2417. *
  2418. * @type {Object}
  2419. */
  2420. var Layout;
  2421. /**
  2422. * Hold the Layout component.
  2423. *
  2424. * @type {Object}
  2425. */
  2426. var Elements;
  2427. /**
  2428. * Store the list element.
  2429. *
  2430. * @type {Element}
  2431. */
  2432. var list;
  2433. /**
  2434. * Whether the current direction is vertical or not.
  2435. *
  2436. * @type {boolean}
  2437. */
  2438. var isVertical = Splide.options.direction === TTB;
  2439. /**
  2440. * Whether the slider type is FADE or not.
  2441. *
  2442. * @type {boolean}
  2443. */
  2444. var isFade = Splide.is(FADE);
  2445. /**
  2446. * Whether the slider direction is RTL or not.
  2447. *
  2448. * @type {boolean}
  2449. */
  2450. var isRTL = Splide.options.direction === RTL;
  2451. /**
  2452. * This will be true while transitioning from the last index to the first one.
  2453. *
  2454. * @type {boolean}
  2455. */
  2456. var isLoopPending = false;
  2457. /**
  2458. * Sign for the direction. Only RTL mode uses the positive sign.
  2459. *
  2460. * @type {number}
  2461. */
  2462. var sign = isRTL ? 1 : -1;
  2463. /**
  2464. * Track component object.
  2465. *
  2466. * @type {Object}
  2467. */
  2468. var Track = {
  2469. /**
  2470. * Make public the sign defined locally.
  2471. *
  2472. * @type {number}
  2473. */
  2474. sign: sign,
  2475. /**
  2476. * Called when the component is mounted.
  2477. */
  2478. mount: function mount() {
  2479. Elements = Components.Elements;
  2480. Layout = Components.Layout;
  2481. list = Elements.list;
  2482. },
  2483. /**
  2484. * Called after the component is mounted.
  2485. * The resize event must be registered after the Layout's one is done.
  2486. */
  2487. mounted: function mounted() {
  2488. var _this = this;
  2489. if (!isFade) {
  2490. this.jump(0);
  2491. Splide.on('mounted resize updated', function () {
  2492. _this.jump(Splide.index);
  2493. });
  2494. }
  2495. },
  2496. /**
  2497. * Go to the given destination index.
  2498. * After arriving there, the track is jump to the new index without animation, mainly for loop mode.
  2499. *
  2500. * @param {number} destIndex - A destination index.
  2501. * This can be negative or greater than slides length for reaching clones.
  2502. * @param {number} newIndex - An actual new index. They are always same in Slide and Rewind mode.
  2503. * @param {boolean} silently - If true, suppress emitting events.
  2504. */
  2505. go: function go(destIndex, newIndex, silently) {
  2506. var newPosition = getTrimmedPosition(destIndex);
  2507. var prevIndex = Splide.index; // Prevent any actions while transitioning from the last index to the first one for jump.
  2508. if (Splide.State.is(MOVING) && isLoopPending) {
  2509. return;
  2510. }
  2511. isLoopPending = destIndex !== newIndex;
  2512. if (!silently) {
  2513. Splide.emit('move', newIndex, prevIndex, destIndex);
  2514. }
  2515. if (Math.abs(newPosition - this.position) >= 1 || isFade) {
  2516. Components.Transition.start(destIndex, newIndex, prevIndex, this.toCoord(newPosition), function () {
  2517. onTransitionEnd(destIndex, newIndex, prevIndex, silently);
  2518. });
  2519. } else {
  2520. if (destIndex !== prevIndex && Splide.options.trimSpace === 'move') {
  2521. Components.Controller.go(destIndex + destIndex - prevIndex, silently);
  2522. } else {
  2523. onTransitionEnd(destIndex, newIndex, prevIndex, silently);
  2524. }
  2525. }
  2526. },
  2527. /**
  2528. * Move the track to the specified index.
  2529. *
  2530. * @param {number} index - A destination index where the track jumps.
  2531. */
  2532. jump: function jump(index) {
  2533. this.translate(getTrimmedPosition(index));
  2534. },
  2535. /**
  2536. * Set the list position by CSS translate property.
  2537. *
  2538. * @param {number} position - A new position value.
  2539. */
  2540. translate: function translate(position) {
  2541. applyStyle(list, {
  2542. transform: "translate" + (isVertical ? 'Y' : 'X') + "(" + position + "px)"
  2543. });
  2544. },
  2545. /**
  2546. * Cancel the transition and set the list position.
  2547. * Also, loop the slider if necessary.
  2548. */
  2549. cancel: function cancel() {
  2550. if (Splide.is(LOOP)) {
  2551. this.shift();
  2552. } else {
  2553. // Ensure the current position.
  2554. this.translate(this.position);
  2555. }
  2556. applyStyle(list, {
  2557. transition: ''
  2558. });
  2559. },
  2560. /**
  2561. * Shift the slider if it exceeds borders on the edge.
  2562. */
  2563. shift: function shift() {
  2564. var position = abs(this.position);
  2565. var left = abs(this.toPosition(0));
  2566. var right = abs(this.toPosition(Splide.length));
  2567. var innerSize = right - left;
  2568. if (position < left) {
  2569. position += innerSize;
  2570. } else if (position > right) {
  2571. position -= innerSize;
  2572. }
  2573. this.translate(sign * position);
  2574. },
  2575. /**
  2576. * Trim redundant spaces on the left or right edge if necessary.
  2577. *
  2578. * @param {number} position - Position value to be trimmed.
  2579. *
  2580. * @return {number} - Trimmed position.
  2581. */
  2582. trim: function trim(position) {
  2583. if (!Splide.options.trimSpace || Splide.is(LOOP)) {
  2584. return position;
  2585. }
  2586. var edge = sign * (Layout.totalSize() - Layout.size - Layout.gap);
  2587. return between(position, edge, 0);
  2588. },
  2589. /**
  2590. * Calculate the closest slide index from the given position.
  2591. *
  2592. * @param {number} position - A position converted to an slide index.
  2593. *
  2594. * @return {number} - The closest slide index.
  2595. */
  2596. toIndex: function toIndex(position) {
  2597. var _this2 = this;
  2598. var index = 0;
  2599. var minDistance = Infinity;
  2600. Elements.getSlides(true).forEach(function (Slide) {
  2601. var slideIndex = Slide.index;
  2602. var distance = abs(_this2.toPosition(slideIndex) - position);
  2603. if (distance < minDistance) {
  2604. minDistance = distance;
  2605. index = slideIndex;
  2606. }
  2607. });
  2608. return index;
  2609. },
  2610. /**
  2611. * Return coordinates object by the given position.
  2612. *
  2613. * @param {number} position - A position value.
  2614. *
  2615. * @return {Object} - A coordinates object.
  2616. */
  2617. toCoord: function toCoord(position) {
  2618. return {
  2619. x: isVertical ? 0 : position,
  2620. y: isVertical ? position : 0
  2621. };
  2622. },
  2623. /**
  2624. * Calculate the track position by a slide index.
  2625. *
  2626. * @param {number} index - Slide index.
  2627. *
  2628. * @return {Object} - Calculated position.
  2629. */
  2630. toPosition: function toPosition(index) {
  2631. var position = Layout.totalSize(index) - Layout.slideSize(index) - Layout.gap;
  2632. return sign * (position + this.offset(index));
  2633. },
  2634. /**
  2635. * Return the current offset value, considering direction.
  2636. *
  2637. * @return {number} - Offset amount.
  2638. */
  2639. offset: function offset(index) {
  2640. var focus = Splide.options.focus;
  2641. var slideSize = Layout.slideSize(index);
  2642. if (focus === 'center') {
  2643. return -(Layout.size - slideSize) / 2;
  2644. }
  2645. return -(parseInt(focus) || 0) * (slideSize + Layout.gap);
  2646. },
  2647. /**
  2648. * Return the current position.
  2649. * This returns the correct position even while transitioning by CSS.
  2650. *
  2651. * @return {number} - Current position.
  2652. */
  2653. get position() {
  2654. var prop = isVertical ? 'top' : isRTL ? 'right' : 'left';
  2655. return getRect(list)[prop] - (getRect(Elements.track)[prop] - Layout.padding[prop] * sign);
  2656. }
  2657. };
  2658. /**
  2659. * Called whenever slides arrive at a destination.
  2660. *
  2661. * @param {number} destIndex - A destination index.
  2662. * @param {number} newIndex - A new index.
  2663. * @param {number} prevIndex - A previous index.
  2664. * @param {boolean} silently - If true, suppress emitting events.
  2665. */
  2666. function onTransitionEnd(destIndex, newIndex, prevIndex, silently) {
  2667. applyStyle(list, {
  2668. transition: ''
  2669. });
  2670. isLoopPending = false;
  2671. if (!isFade) {
  2672. Track.jump(newIndex);
  2673. }
  2674. if (!silently) {
  2675. Splide.emit('moved', newIndex, prevIndex, destIndex);
  2676. }
  2677. }
  2678. /**
  2679. * Convert index to the trimmed position.
  2680. *
  2681. * @return {number} - Trimmed position.
  2682. */
  2683. function getTrimmedPosition(index) {
  2684. return Track.trim(Track.toPosition(index));
  2685. }
  2686. return Track;
  2687. });
  2688. // CONCATENATED MODULE: ./src/js/components/clones/index.js
  2689. /**
  2690. * The component for cloning some slides for "loop" mode of the track.
  2691. *
  2692. * @author Naotoshi Fujita
  2693. * @copyright Naotoshi Fujita. All rights reserved.
  2694. */
  2695. ;
  2696. /**
  2697. * The component for cloning some slides for "loop" mode of the track.
  2698. *
  2699. * @param {Splide} Splide - A Splide instance.
  2700. * @param {Object} Components - An object containing components.
  2701. *
  2702. * @return {Object} - The component object.
  2703. */
  2704. /* harmony default export */ const clones = (function (Splide, Components) {
  2705. /**
  2706. * Store information of all clones.
  2707. *
  2708. * @type {Array}
  2709. */
  2710. var clones = [];
  2711. /**
  2712. * Store the current clone count on one side.
  2713. *
  2714. * @type {number}
  2715. */
  2716. var cloneCount = 0;
  2717. /**
  2718. * Keep Elements component.
  2719. *
  2720. * @type {Object}
  2721. */
  2722. var Elements = Components.Elements;
  2723. /**
  2724. * Clones component object.
  2725. *
  2726. * @type {Object}
  2727. */
  2728. var Clones = {
  2729. /**
  2730. * Called when the component is mounted.
  2731. */
  2732. mount: function mount() {
  2733. var _this = this;
  2734. if (Splide.is(LOOP)) {
  2735. init();
  2736. Splide.on('refresh:before', function () {
  2737. _this.destroy();
  2738. }).on('refresh', init).on('resize', function () {
  2739. if (cloneCount !== getCloneCount()) {
  2740. // Destroy before refresh not to collect clones by the Elements component.
  2741. _this.destroy();
  2742. Splide.refresh();
  2743. }
  2744. });
  2745. }
  2746. },
  2747. /**
  2748. * Destroy.
  2749. */
  2750. destroy: function destroy() {
  2751. dom_remove(clones);
  2752. clones = [];
  2753. },
  2754. /**
  2755. * Return all clones.
  2756. *
  2757. * @return {Element[]} - Cloned elements.
  2758. */
  2759. get clones() {
  2760. return clones;
  2761. },
  2762. /**
  2763. * Return clone length.
  2764. *
  2765. * @return {number} - A length of clones.
  2766. */
  2767. get length() {
  2768. return clones.length;
  2769. }
  2770. };
  2771. /**
  2772. * Initialization.
  2773. */
  2774. function init() {
  2775. Clones.destroy();
  2776. cloneCount = getCloneCount();
  2777. generateClones(cloneCount);
  2778. }
  2779. /**
  2780. * Generate and append/prepend clones.
  2781. *
  2782. * @param {number} count - The half number of clones.
  2783. */
  2784. function generateClones(count) {
  2785. var length = Elements.length,
  2786. register = Elements.register;
  2787. if (length) {
  2788. var slides = Elements.slides;
  2789. while (slides.length < count) {
  2790. slides = slides.concat(slides);
  2791. } // Clones after the last element.
  2792. slides.slice(0, count).forEach(function (elm, index) {
  2793. var clone = cloneDeeply(elm);
  2794. append(Elements.list, clone);
  2795. clones.push(clone);
  2796. register(clone, index + length, index % length);
  2797. }); // Clones before the first element.
  2798. slides.slice(-count).forEach(function (elm, index) {
  2799. var clone = cloneDeeply(elm);
  2800. before(clone, slides[0]);
  2801. clones.push(clone);
  2802. register(clone, index - count, (length + index - count % length) % length);
  2803. });
  2804. }
  2805. }
  2806. /**
  2807. * Return half count of clones to be generated.
  2808. * Clone count is determined by:
  2809. * - "clones" value in the options.
  2810. * - Number of slides that can be placed in a view in "fixed" mode.
  2811. * - Max pages a flick action can move.
  2812. * - Whether the slide length is enough for perPage.
  2813. *
  2814. * @return {number} - Count for clones.
  2815. */
  2816. function getCloneCount() {
  2817. var options = Splide.options;
  2818. if (options.clones) {
  2819. return options.clones;
  2820. } // Use the slide length in autoWidth mode because the number cannot be calculated.
  2821. var baseCount = options.autoWidth || options.autoHeight ? Elements.length : options.perPage;
  2822. var dimension = options.direction === TTB ? 'Height' : 'Width';
  2823. var fixedSize = toPixel(Splide.root, options["fixed" + dimension]);
  2824. if (fixedSize) {
  2825. // Roughly calculate the count. This needs not to be strict.
  2826. baseCount = Math.ceil(Elements.track["client" + dimension] / fixedSize);
  2827. }
  2828. return baseCount * (options.drag ? options.flickMaxPages + 1 : 1);
  2829. }
  2830. /**
  2831. * Clone deeply the given element.
  2832. *
  2833. * @param {Element} elm - An element being duplicated.
  2834. *
  2835. * @return {Node} - A cloned node(element).
  2836. */
  2837. function cloneDeeply(elm) {
  2838. var clone = elm.cloneNode(true);
  2839. addClass(clone, Splide.classes.clone); // ID should not be duplicated.
  2840. removeAttribute(clone, 'id');
  2841. return clone;
  2842. }
  2843. return Clones;
  2844. });
  2845. // CONCATENATED MODULE: ./src/js/components/layout/directions/horizontal.js
  2846. /**
  2847. * The resolver component for horizontal layout.
  2848. *
  2849. * @author Naotoshi Fujita
  2850. * @copyright Naotoshi Fujita. All rights reserved.
  2851. */
  2852. ;
  2853. /**
  2854. * The resolver component for horizontal layout.
  2855. *
  2856. * @param {Splide} Splide - A Splide instance.
  2857. * @param {Object} Components - An object containing components.
  2858. *
  2859. * @return {Object} - The resolver object.
  2860. */
  2861. /* harmony default export */ const horizontal = (function (Splide, Components) {
  2862. /**
  2863. * Keep the Elements component.
  2864. *
  2865. * @type {string}
  2866. */
  2867. var Elements = Components.Elements;
  2868. /**
  2869. * Keep the root element.
  2870. *
  2871. * @type {Element}
  2872. */
  2873. var root = Splide.root;
  2874. /**
  2875. * Keep the track element.
  2876. *
  2877. * @type {Element}
  2878. */
  2879. var track;
  2880. /**
  2881. * Keep the latest options.
  2882. *
  2883. * @type {Element}
  2884. */
  2885. var options = Splide.options;
  2886. return {
  2887. /**
  2888. * Margin property name.
  2889. *
  2890. * @type {string}
  2891. */
  2892. margin: 'margin' + (options.direction === RTL ? 'Left' : 'Right'),
  2893. /**
  2894. * Always 0 because the height will be determined by inner contents.
  2895. *
  2896. * @type {number}
  2897. */
  2898. height: 0,
  2899. /**
  2900. * Initialization.
  2901. */
  2902. init: function init() {
  2903. this.resize();
  2904. },
  2905. /**
  2906. * Resize gap and padding.
  2907. * This must be called on init.
  2908. */
  2909. resize: function resize() {
  2910. options = Splide.options;
  2911. track = Elements.track;
  2912. this.gap = toPixel(root, options.gap);
  2913. var padding = options.padding;
  2914. var left = toPixel(root, padding.left || padding);
  2915. var right = toPixel(root, padding.right || padding);
  2916. this.padding = {
  2917. left: left,
  2918. right: right
  2919. };
  2920. applyStyle(track, {
  2921. paddingLeft: unit(left),
  2922. paddingRight: unit(right)
  2923. });
  2924. },
  2925. /**
  2926. * Return total width from the left of the list to the right of the slide specified by the provided index.
  2927. *
  2928. * @param {number} index - Optional. A slide index. If undefined, total width of the slider will be returned.
  2929. *
  2930. * @return {number} - Total width to the right side of the specified slide, or 0 for an invalid index.
  2931. */
  2932. totalWidth: function totalWidth(index) {
  2933. if (index === void 0) {
  2934. index = Splide.length - 1;
  2935. }
  2936. var Slide = Elements.getSlide(index);
  2937. var width = 0;
  2938. if (Slide) {
  2939. var slideRect = getRect(Slide.slide);
  2940. var listRect = getRect(Elements.list);
  2941. if (options.direction === RTL) {
  2942. width = listRect.right - slideRect.left;
  2943. } else {
  2944. width = slideRect.right - listRect.left;
  2945. }
  2946. width += this.gap;
  2947. }
  2948. return width;
  2949. },
  2950. /**
  2951. * Return the slide width in px.
  2952. *
  2953. * @param {number} index - Slide index.
  2954. *
  2955. * @return {number} - The slide width.
  2956. */
  2957. slideWidth: function slideWidth(index) {
  2958. if (options.autoWidth) {
  2959. var Slide = Elements.getSlide(index);
  2960. return Slide ? Slide.slide.offsetWidth : 0;
  2961. }
  2962. var width = options.fixedWidth || (this.width + this.gap) / options.perPage - this.gap;
  2963. return toPixel(root, width);
  2964. },
  2965. /**
  2966. * Return the slide height in px.
  2967. *
  2968. * @return {number} - The slide height.
  2969. */
  2970. slideHeight: function slideHeight() {
  2971. var height = options.height || options.fixedHeight || this.width * options.heightRatio;
  2972. return toPixel(root, height);
  2973. },
  2974. /**
  2975. * Return slider width without padding.
  2976. *
  2977. * @return {number} - Current slider width.
  2978. */
  2979. get width() {
  2980. return track.clientWidth - this.padding.left - this.padding.right;
  2981. }
  2982. };
  2983. });
  2984. // CONCATENATED MODULE: ./src/js/components/layout/directions/vertical.js
  2985. /**
  2986. * The resolver component for vertical layout.
  2987. *
  2988. * @author Naotoshi Fujita
  2989. * @copyright Naotoshi Fujita. All rights reserved.
  2990. */
  2991. ;
  2992. /**
  2993. * The resolver component for vertical layout.
  2994. *
  2995. * @param {Splide} Splide - A Splide instance.
  2996. * @param {Object} Components - An object containing components.
  2997. *
  2998. * @return {Object} - The resolver object.
  2999. */
  3000. /* harmony default export */ const vertical = (function (Splide, Components) {
  3001. /**
  3002. * Keep the Elements component.
  3003. *
  3004. * @type {string}
  3005. */
  3006. var Elements = Components.Elements;
  3007. /**
  3008. * Keep the root element.
  3009. *
  3010. * @type {Element}
  3011. */
  3012. var root = Splide.root;
  3013. /**
  3014. * Keep the track element.
  3015. *
  3016. * @type {Element}
  3017. */
  3018. var track;
  3019. /**
  3020. * Keep the latest options.
  3021. *
  3022. * @type {Element}
  3023. */
  3024. var options;
  3025. return {
  3026. /**
  3027. * Margin property name.
  3028. *
  3029. * @type {string}
  3030. */
  3031. margin: 'marginBottom',
  3032. /**
  3033. * Initialization.
  3034. */
  3035. init: function init() {
  3036. this.resize();
  3037. },
  3038. /**
  3039. * Resize gap and padding.
  3040. * This must be called on init.
  3041. */
  3042. resize: function resize() {
  3043. options = Splide.options;
  3044. track = Elements.track;
  3045. this.gap = toPixel(root, options.gap);
  3046. var padding = options.padding;
  3047. var top = toPixel(root, padding.top || padding);
  3048. var bottom = toPixel(root, padding.bottom || padding);
  3049. this.padding = {
  3050. top: top,
  3051. bottom: bottom
  3052. };
  3053. applyStyle(track, {
  3054. paddingTop: unit(top),
  3055. paddingBottom: unit(bottom)
  3056. });
  3057. },
  3058. /**
  3059. * Return total height from the top of the list to the bottom of the slide specified by the provided index.
  3060. *
  3061. * @param {number} index - Optional. A slide index. If undefined, total height of the slider will be returned.
  3062. *
  3063. * @return {number} - Total height to the bottom of the specified slide, or 0 for an invalid index.
  3064. */
  3065. totalHeight: function totalHeight(index) {
  3066. if (index === void 0) {
  3067. index = Splide.length - 1;
  3068. }
  3069. var Slide = Elements.getSlide(index);
  3070. if (Slide) {
  3071. return getRect(Slide.slide).bottom - getRect(Elements.list).top + this.gap;
  3072. }
  3073. return 0;
  3074. },
  3075. /**
  3076. * Return the slide width in px.
  3077. *
  3078. * @return {number} - The slide width.
  3079. */
  3080. slideWidth: function slideWidth() {
  3081. return toPixel(root, options.fixedWidth || this.width);
  3082. },
  3083. /**
  3084. * Return the slide height in px.
  3085. *
  3086. * @param {number} index - Slide index.
  3087. *
  3088. * @return {number} - The slide height.
  3089. */
  3090. slideHeight: function slideHeight(index) {
  3091. if (options.autoHeight) {
  3092. var Slide = Elements.getSlide(index);
  3093. return Slide ? Slide.slide.offsetHeight : 0;
  3094. }
  3095. var height = options.fixedHeight || (this.height + this.gap) / options.perPage - this.gap;
  3096. return toPixel(root, height);
  3097. },
  3098. /**
  3099. * Return slider width without padding.
  3100. *
  3101. * @return {number} - Current slider width.
  3102. */
  3103. get width() {
  3104. return track.clientWidth;
  3105. },
  3106. /**
  3107. * Return slide height without padding.
  3108. *
  3109. * @return {number} - Slider height.
  3110. */
  3111. get height() {
  3112. var height = options.height || this.width * options.heightRatio;
  3113. exist(height, '"height" or "heightRatio" is missing.');
  3114. return toPixel(root, height) - this.padding.top - this.padding.bottom;
  3115. }
  3116. };
  3117. });
  3118. // CONCATENATED MODULE: ./src/js/utils/time.js
  3119. /**
  3120. * A package of utility functions related with time.
  3121. *
  3122. * @author Naotoshi Fujita
  3123. * @copyright Naotoshi Fujita. All rights reserved.
  3124. */
  3125. /**
  3126. * Simple throttle function that controls how often the given function is executed.
  3127. *
  3128. * @param {function} func - A function to be throttled.
  3129. * @param {number} wait - Time in millisecond for interval of execution.
  3130. *
  3131. * @return {Function} - A debounced function.
  3132. */
  3133. function throttle(func, wait) {
  3134. var timeout; // Declare function by the "function" keyword to prevent "this" from being inherited.
  3135. return function () {
  3136. if (!timeout) {
  3137. timeout = setTimeout(function () {
  3138. func();
  3139. timeout = null;
  3140. }, wait);
  3141. }
  3142. };
  3143. }
  3144. /**
  3145. * Custom setInterval function that provides progress rate as callback.
  3146. *
  3147. * @param {function} callback - A callback function fired every time the interval time passes.
  3148. * @param {number} interval - Interval duration in milliseconds.
  3149. * @param {function} progress - A callback function fired whenever the progress goes.
  3150. *
  3151. * @return {Object} - An object containing play() and pause() functions.
  3152. */
  3153. function createInterval(callback, interval, progress) {
  3154. var _window = window,
  3155. requestAnimationFrame = _window.requestAnimationFrame;
  3156. var start,
  3157. elapse,
  3158. rate,
  3159. _pause = true;
  3160. var step = function step(timestamp) {
  3161. if (!_pause) {
  3162. if (!start) {
  3163. start = timestamp;
  3164. if (rate && rate < 1) {
  3165. start -= rate * interval;
  3166. }
  3167. }
  3168. elapse = timestamp - start;
  3169. rate = elapse / interval;
  3170. if (elapse >= interval) {
  3171. start = 0;
  3172. rate = 1;
  3173. callback();
  3174. }
  3175. if (progress) {
  3176. progress(rate);
  3177. }
  3178. requestAnimationFrame(step);
  3179. }
  3180. };
  3181. return {
  3182. pause: function pause() {
  3183. _pause = true;
  3184. start = 0;
  3185. },
  3186. play: function play(reset) {
  3187. start = 0;
  3188. if (reset) {
  3189. rate = 0;
  3190. }
  3191. if (_pause) {
  3192. _pause = false;
  3193. requestAnimationFrame(step);
  3194. }
  3195. }
  3196. };
  3197. }
  3198. // CONCATENATED MODULE: ./src/js/components/layout/index.js
  3199. /**
  3200. * The component for handing slide layouts and their sizes.
  3201. *
  3202. * @author Naotoshi Fujita
  3203. * @copyright Naotoshi Fujita. All rights reserved.
  3204. */
  3205. ;
  3206. /**
  3207. * The component for handing slide layouts and their sizes.
  3208. *
  3209. * @param {Splide} Splide - A Splide instance.
  3210. * @param {Object} Components - An object containing components.
  3211. *
  3212. * @return {Object} - The component object.
  3213. */
  3214. /* harmony default export */ const layout = (function (Splide, Components) {
  3215. /**
  3216. * Keep the Elements component.
  3217. *
  3218. * @type {string}
  3219. */
  3220. var Elements = Components.Elements;
  3221. /**
  3222. * Whether the slider is vertical or not.
  3223. *
  3224. * @type {boolean}
  3225. */
  3226. var isVertical = Splide.options.direction === TTB;
  3227. /**
  3228. * Layout component object.
  3229. *
  3230. * @type {Object}
  3231. */
  3232. var Layout = object_assign({
  3233. /**
  3234. * Called when the component is mounted.
  3235. */
  3236. mount: function mount() {
  3237. bind();
  3238. init(); // The word "size" means width for a horizontal slider and height for a vertical slider.
  3239. this.totalSize = isVertical ? this.totalHeight : this.totalWidth;
  3240. this.slideSize = isVertical ? this.slideHeight : this.slideWidth;
  3241. },
  3242. /**
  3243. * Destroy the component.
  3244. */
  3245. destroy: function destroy() {
  3246. removeAttribute([Elements.list, Elements.track], 'style');
  3247. },
  3248. /**
  3249. * Return the slider height on the vertical mode or width on the horizontal mode.
  3250. *
  3251. * @return {number}
  3252. */
  3253. get size() {
  3254. return isVertical ? this.height : this.width;
  3255. }
  3256. }, isVertical ? vertical(Splide, Components) : horizontal(Splide, Components));
  3257. /**
  3258. * Init slider styles according to options.
  3259. */
  3260. function init() {
  3261. Layout.init();
  3262. applyStyle(Splide.root, {
  3263. maxWidth: unit(Splide.options.width)
  3264. });
  3265. Elements.each(function (Slide) {
  3266. Slide.slide.style[Layout.margin] = unit(Layout.gap);
  3267. });
  3268. resize();
  3269. }
  3270. /**
  3271. * Listen the resize native event with throttle.
  3272. * Initialize when the component is mounted or options are updated.
  3273. */
  3274. function bind() {
  3275. Splide.on('resize load', throttle(function () {
  3276. Splide.emit('resize');
  3277. }, Splide.options.throttle), window).on('resize', resize).on('updated refresh', init);
  3278. }
  3279. /**
  3280. * Resize the track and slide elements.
  3281. */
  3282. function resize() {
  3283. var options = Splide.options;
  3284. Layout.resize();
  3285. applyStyle(Elements.track, {
  3286. height: unit(Layout.height)
  3287. });
  3288. var slideHeight = options.autoHeight ? null : unit(Layout.slideHeight());
  3289. Elements.each(function (Slide) {
  3290. applyStyle(Slide.container, {
  3291. height: slideHeight
  3292. });
  3293. applyStyle(Slide.slide, {
  3294. width: options.autoWidth ? null : unit(Layout.slideWidth(Slide.index)),
  3295. height: Slide.container ? null : slideHeight
  3296. });
  3297. });
  3298. Splide.emit('resized');
  3299. }
  3300. return Layout;
  3301. });
  3302. // CONCATENATED MODULE: ./src/js/components/drag/index.js
  3303. /**
  3304. * The component for supporting mouse drag and swipe.
  3305. *
  3306. * @author Naotoshi Fujita
  3307. * @copyright Naotoshi Fujita. All rights reserved.
  3308. */
  3309. ;
  3310. var drag_abs = Math.abs;
  3311. /**
  3312. * If the absolute velocity is greater thant this value,
  3313. * a slider always goes to a different slide after drag, not allowed to stay on a current slide.
  3314. */
  3315. var MIN_VELOCITY = 0.1;
  3316. /**
  3317. * Adjust how much the track can be pulled on the first or last page.
  3318. * The larger number this is, the farther the track moves.
  3319. * This should be around 5 - 9.
  3320. *
  3321. * @type {number}
  3322. */
  3323. var FRICTION_REDUCER = 7;
  3324. /**
  3325. * The component supporting mouse drag and swipe.
  3326. *
  3327. * @param {Splide} Splide - A Splide instance.
  3328. * @param {Object} Components - An object containing components.
  3329. *
  3330. * @return {Object} - The component object.
  3331. */
  3332. /* harmony default export */ const drag = (function (Splide, Components) {
  3333. /**
  3334. * Store the Move component.
  3335. *
  3336. * @type {Object}
  3337. */
  3338. var Track = Components.Track;
  3339. /**
  3340. * Store the Controller component.
  3341. *
  3342. * @type {Object}
  3343. */
  3344. var Controller = Components.Controller;
  3345. /**
  3346. * Coordinate of the track on starting drag.
  3347. *
  3348. * @type {Object}
  3349. */
  3350. var startCoord;
  3351. /**
  3352. * Analyzed info on starting drag.
  3353. *
  3354. * @type {Object|null}
  3355. */
  3356. var startInfo;
  3357. /**
  3358. * Analyzed info being updated while dragging/swiping.
  3359. *
  3360. * @type {Object}
  3361. */
  3362. var currentInfo;
  3363. /**
  3364. * Determine whether slides are being dragged or not.
  3365. *
  3366. * @type {boolean}
  3367. */
  3368. var isDragging;
  3369. /**
  3370. * Whether the slider direction is vertical or not.
  3371. *
  3372. * @type {boolean}
  3373. */
  3374. var isVertical = Splide.options.direction === TTB;
  3375. /**
  3376. * Axis for the direction.
  3377. *
  3378. * @type {string}
  3379. */
  3380. var axis = isVertical ? 'y' : 'x';
  3381. /**
  3382. * Drag component object.
  3383. *
  3384. * @type {Object}
  3385. */
  3386. var Drag = {
  3387. /**
  3388. * Whether dragging is disabled or not.
  3389. *
  3390. * @type {boolean}
  3391. */
  3392. disabled: false,
  3393. /**
  3394. * Called when the component is mounted.
  3395. */
  3396. mount: function mount() {
  3397. var _this = this;
  3398. var Elements = Components.Elements;
  3399. var track = Elements.track;
  3400. Splide.on('touchstart mousedown', start, track).on('touchmove mousemove', move, track, {
  3401. passive: false
  3402. }).on('touchend touchcancel mouseleave mouseup dragend', end, track).on('mounted refresh', function () {
  3403. // Prevent dragging an image or anchor itself.
  3404. each(Elements.list.querySelectorAll('img, a'), function (elm) {
  3405. Splide.off('dragstart', elm).on('dragstart', function (e) {
  3406. e.preventDefault();
  3407. }, elm, {
  3408. passive: false
  3409. });
  3410. });
  3411. }).on('mounted updated', function () {
  3412. _this.disabled = !Splide.options.drag;
  3413. });
  3414. }
  3415. };
  3416. /**
  3417. * Called when the track starts to be dragged.
  3418. *
  3419. * @param {TouchEvent|MouseEvent} e - TouchEvent or MouseEvent object.
  3420. */
  3421. function start(e) {
  3422. if (!Drag.disabled && !isDragging) {
  3423. // These prams are used to evaluate whether the slider should start moving.
  3424. init(e);
  3425. }
  3426. }
  3427. /**
  3428. * Initialize parameters.
  3429. *
  3430. * @param {TouchEvent|MouseEvent} e - TouchEvent or MouseEvent object.
  3431. */
  3432. function init(e) {
  3433. startCoord = Track.toCoord(Track.position);
  3434. startInfo = analyze(e, {});
  3435. currentInfo = startInfo;
  3436. }
  3437. /**
  3438. * Called while the track being dragged.
  3439. *
  3440. * @param {TouchEvent|MouseEvent} e - TouchEvent or MouseEvent object.
  3441. */
  3442. function move(e) {
  3443. if (startInfo) {
  3444. currentInfo = analyze(e, startInfo);
  3445. if (isDragging) {
  3446. if (e.cancelable) {
  3447. e.preventDefault();
  3448. }
  3449. if (!Splide.is(FADE)) {
  3450. var position = startCoord[axis] + currentInfo.offset[axis];
  3451. Track.translate(resist(position));
  3452. }
  3453. } else {
  3454. if (shouldMove(currentInfo)) {
  3455. Splide.emit('drag', startInfo);
  3456. isDragging = true;
  3457. Track.cancel(); // These params are actual drag data.
  3458. init(e);
  3459. }
  3460. }
  3461. }
  3462. }
  3463. /**
  3464. * Determine whether to start moving the track or not by drag angle.
  3465. *
  3466. * @param {Object} info - An information object.
  3467. *
  3468. * @return {boolean} - True if the track should be moved or false if not.
  3469. */
  3470. function shouldMove(_ref) {
  3471. var offset = _ref.offset;
  3472. if (Splide.State.is(MOVING) && Splide.options.waitForTransition) {
  3473. return false;
  3474. }
  3475. var angle = Math.atan(drag_abs(offset.y) / drag_abs(offset.x)) * 180 / Math.PI;
  3476. if (isVertical) {
  3477. angle = 90 - angle;
  3478. }
  3479. return angle < Splide.options.dragAngleThreshold;
  3480. }
  3481. /**
  3482. * Resist dragging the track on the first/last page because there is no more.
  3483. *
  3484. * @param {number} position - A position being applied to the track.
  3485. *
  3486. * @return {Object} - Adjusted position.
  3487. */
  3488. function resist(position) {
  3489. if (Splide.is(SLIDE)) {
  3490. var sign = Track.sign;
  3491. var _start = sign * Track.trim(Track.toPosition(0));
  3492. var _end = sign * Track.trim(Track.toPosition(Controller.edgeIndex));
  3493. position *= sign;
  3494. if (position < _start) {
  3495. position = _start - FRICTION_REDUCER * Math.log(_start - position);
  3496. } else if (position > _end) {
  3497. position = _end + FRICTION_REDUCER * Math.log(position - _end);
  3498. }
  3499. position *= sign;
  3500. }
  3501. return position;
  3502. }
  3503. /**
  3504. * Called when dragging ends.
  3505. */
  3506. function end() {
  3507. startInfo = null;
  3508. if (isDragging) {
  3509. Splide.emit('dragged', currentInfo);
  3510. go(currentInfo);
  3511. isDragging = false;
  3512. }
  3513. }
  3514. /**
  3515. * Go to the slide determined by the analyzed data.
  3516. *
  3517. * @param {Object} info - An info object.
  3518. */
  3519. function go(info) {
  3520. var velocity = info.velocity[axis];
  3521. var absV = drag_abs(velocity);
  3522. if (absV > 0) {
  3523. var options = Splide.options;
  3524. var index = Splide.index;
  3525. var sign = velocity < 0 ? -1 : 1;
  3526. var destIndex = index;
  3527. if (!Splide.is(FADE)) {
  3528. var destination = Track.position;
  3529. if (absV > options.flickVelocityThreshold && drag_abs(info.offset[axis]) < options.swipeDistanceThreshold) {
  3530. destination += sign * Math.min(absV * options.flickPower, Components.Layout.size * (options.flickMaxPages || 1));
  3531. }
  3532. destIndex = Track.toIndex(destination);
  3533. }
  3534. /*
  3535. * Do not allow the track to go to a previous position if there is enough velocity.
  3536. * Always use the adjacent index for the fade mode.
  3537. */
  3538. if (destIndex === index && absV > MIN_VELOCITY) {
  3539. destIndex = index + sign * Track.sign;
  3540. }
  3541. if (Splide.is(SLIDE)) {
  3542. destIndex = between(destIndex, 0, Controller.edgeIndex);
  3543. }
  3544. Controller.go(destIndex, options.isNavigation);
  3545. }
  3546. }
  3547. /**
  3548. * Analyze the given event object and return important information for handling swipe behavior.
  3549. *
  3550. * @param {Event} e - Touch or Mouse event object.
  3551. * @param {Object} startInfo - Information analyzed on start for calculating difference from the current one.
  3552. *
  3553. * @return {Object} - An object containing analyzed information, such as offset, velocity, etc.
  3554. */
  3555. function analyze(e, startInfo) {
  3556. var timeStamp = e.timeStamp,
  3557. touches = e.touches;
  3558. var _ref2 = touches ? touches[0] : e,
  3559. clientX = _ref2.clientX,
  3560. clientY = _ref2.clientY;
  3561. var _ref3 = startInfo.to || {},
  3562. _ref3$x = _ref3.x,
  3563. fromX = _ref3$x === void 0 ? clientX : _ref3$x,
  3564. _ref3$y = _ref3.y,
  3565. fromY = _ref3$y === void 0 ? clientY : _ref3$y;
  3566. var startTime = startInfo.time || 0;
  3567. var offset = {
  3568. x: clientX - fromX,
  3569. y: clientY - fromY
  3570. };
  3571. var duration = timeStamp - startTime;
  3572. var velocity = {
  3573. x: offset.x / duration,
  3574. y: offset.y / duration
  3575. };
  3576. return {
  3577. to: {
  3578. x: clientX,
  3579. y: clientY
  3580. },
  3581. offset: offset,
  3582. time: timeStamp,
  3583. velocity: velocity
  3584. };
  3585. }
  3586. return Drag;
  3587. });
  3588. // CONCATENATED MODULE: ./src/js/components/click/index.js
  3589. /**
  3590. * The component for handling a click event.
  3591. *
  3592. * @author Naotoshi Fujita
  3593. * @copyright Naotoshi Fujita. All rights reserved.
  3594. */
  3595. /**
  3596. * The component for handling a click event.
  3597. * Click should be disabled during drag/swipe.
  3598. *
  3599. * @param {Splide} Splide - A Splide instance.
  3600. * @param {Object} Components - An object containing components.
  3601. *
  3602. * @return {Object} - The component object.
  3603. */
  3604. /* harmony default export */ const click = (function (Splide, Components) {
  3605. /**
  3606. * Whether click is disabled or not.
  3607. *
  3608. * @type {boolean}
  3609. */
  3610. var disabled = false;
  3611. /**
  3612. * Click component object.
  3613. *
  3614. * @type {Object}
  3615. */
  3616. var Click = {
  3617. /**
  3618. * Mount only when the drag is activated and the slide type is not "fade".
  3619. *
  3620. * @type {boolean}
  3621. */
  3622. required: Splide.options.drag,
  3623. /**
  3624. * Called when the component is mounted.
  3625. */
  3626. mount: function mount() {
  3627. Splide.on('click', onClick, Components.Elements.track, {
  3628. capture: true
  3629. }).on('drag', function () {
  3630. disabled = true;
  3631. }).on('dragged', function () {
  3632. // Make sure the flag is released after the click event is fired.
  3633. setTimeout(function () {
  3634. disabled = false;
  3635. });
  3636. });
  3637. }
  3638. };
  3639. /**
  3640. * Called when a track element is clicked.
  3641. *
  3642. * @param {Event} e - A click event.
  3643. */
  3644. function onClick(e) {
  3645. if (disabled) {
  3646. e.preventDefault();
  3647. e.stopPropagation();
  3648. e.stopImmediatePropagation();
  3649. }
  3650. }
  3651. return Click;
  3652. });
  3653. // CONCATENATED MODULE: ./src/js/components/autoplay/index.js
  3654. /**
  3655. * The component for playing slides automatically.
  3656. *
  3657. * @author Naotoshi Fujita
  3658. * @copyright Naotoshi Fujita. All rights reserved.
  3659. */
  3660. ;
  3661. /**
  3662. * Set of pause flags.
  3663. */
  3664. var PAUSE_FLAGS = {
  3665. HOVER: 1,
  3666. FOCUS: 2,
  3667. MANUAL: 3
  3668. };
  3669. /**
  3670. * The component for playing slides automatically.
  3671. *
  3672. * @param {Splide} Splide - A Splide instance.
  3673. * @param {Object} Components - An object containing components.
  3674. * @param {string} name - A component name as a lowercase string.
  3675. *
  3676. * @return {Object} - The component object.
  3677. */
  3678. /* harmony default export */ const autoplay = (function (Splide, Components, name) {
  3679. /**
  3680. * Store pause flags.
  3681. *
  3682. * @type {Array}
  3683. */
  3684. var flags = [];
  3685. /**
  3686. * Store an interval object.
  3687. *
  3688. * @type {Object};
  3689. */
  3690. var interval;
  3691. /**
  3692. * Keep the Elements component.
  3693. *
  3694. * @type {string}
  3695. */
  3696. var Elements = Components.Elements;
  3697. /**
  3698. * Autoplay component object.
  3699. *
  3700. * @type {Object}
  3701. */
  3702. var Autoplay = {
  3703. /**
  3704. * Required only when the autoplay option is true.
  3705. *
  3706. * @type {boolean}
  3707. */
  3708. required: Splide.options.autoplay,
  3709. /**
  3710. * Called when the component is mounted.
  3711. * Note that autoplay starts only if there are slides over perPage number.
  3712. */
  3713. mount: function mount() {
  3714. var options = Splide.options;
  3715. if (Elements.slides.length > options.perPage) {
  3716. interval = createInterval(function () {
  3717. Splide.go('>');
  3718. }, options.interval, function (rate) {
  3719. Splide.emit(name + ":playing", rate);
  3720. if (Elements.bar) {
  3721. applyStyle(Elements.bar, {
  3722. width: rate * 100 + "%"
  3723. });
  3724. }
  3725. });
  3726. bind();
  3727. this.play();
  3728. }
  3729. },
  3730. /**
  3731. * Start autoplay.
  3732. *
  3733. * @param {number} flag - A pause flag to be removed.
  3734. */
  3735. play: function play(flag) {
  3736. if (flag === void 0) {
  3737. flag = 0;
  3738. }
  3739. flags = flags.filter(function (f) {
  3740. return f !== flag;
  3741. });
  3742. if (!flags.length) {
  3743. Splide.emit(name + ":play");
  3744. interval.play(Splide.options.resetProgress);
  3745. }
  3746. },
  3747. /**
  3748. * Pause autoplay.
  3749. * Note that Array.includes is not supported by IE.
  3750. *
  3751. * @param {number} flag - A pause flag to be added.
  3752. */
  3753. pause: function pause(flag) {
  3754. if (flag === void 0) {
  3755. flag = 0;
  3756. }
  3757. interval.pause();
  3758. if (flags.indexOf(flag) === -1) {
  3759. flags.push(flag);
  3760. }
  3761. if (flags.length === 1) {
  3762. Splide.emit(name + ":pause");
  3763. }
  3764. }
  3765. };
  3766. /**
  3767. * Listen some events.
  3768. */
  3769. function bind() {
  3770. var options = Splide.options;
  3771. var sibling = Splide.sibling;
  3772. var elms = [Splide.root, sibling ? sibling.root : null];
  3773. if (options.pauseOnHover) {
  3774. switchOn(elms, 'mouseleave', PAUSE_FLAGS.HOVER, true);
  3775. switchOn(elms, 'mouseenter', PAUSE_FLAGS.HOVER, false);
  3776. }
  3777. if (options.pauseOnFocus) {
  3778. switchOn(elms, 'focusout', PAUSE_FLAGS.FOCUS, true);
  3779. switchOn(elms, 'focusin', PAUSE_FLAGS.FOCUS, false);
  3780. }
  3781. if (Elements.play) {
  3782. Splide.on('click', function () {
  3783. // Need to be removed a focus flag at first.
  3784. Autoplay.play(PAUSE_FLAGS.FOCUS);
  3785. Autoplay.play(PAUSE_FLAGS.MANUAL);
  3786. }, Elements.play);
  3787. }
  3788. if (Elements.pause) {
  3789. switchOn([Elements.pause], 'click', PAUSE_FLAGS.MANUAL, false);
  3790. }
  3791. Splide.on('move refresh', function () {
  3792. Autoplay.play();
  3793. }) // Rewind the timer.
  3794. .on('destroy', function () {
  3795. Autoplay.pause();
  3796. });
  3797. }
  3798. /**
  3799. * Play or pause on the given event.
  3800. *
  3801. * @param {Element[]} elms - Elements.
  3802. * @param {string} event - An event name or names.
  3803. * @param {number} flag - A pause flag defined on the top.
  3804. * @param {boolean} play - Determine whether to play or pause.
  3805. */
  3806. function switchOn(elms, event, flag, play) {
  3807. elms.forEach(function (elm) {
  3808. Splide.on(event, function () {
  3809. Autoplay[play ? 'play' : 'pause'](flag);
  3810. }, elm);
  3811. });
  3812. }
  3813. return Autoplay;
  3814. });
  3815. // CONCATENATED MODULE: ./src/js/components/cover/index.js
  3816. /**
  3817. * The component for change an img element to background image of its wrapper.
  3818. *
  3819. * @author Naotoshi Fujita
  3820. * @copyright Naotoshi Fujita. All rights reserved.
  3821. */
  3822. ;
  3823. /**
  3824. * The component for change an img element to background image of its wrapper.
  3825. *
  3826. * @param {Splide} Splide - A Splide instance.
  3827. * @param {Object} Components - An object containing components.
  3828. *
  3829. * @return {Object} - The component object.
  3830. */
  3831. /* harmony default export */ const cover = (function (Splide, Components) {
  3832. /**
  3833. * Hold options.
  3834. *
  3835. * @type {Object}
  3836. */
  3837. var options = Splide.options;
  3838. /**
  3839. * Cover component object.
  3840. *
  3841. * @type {Object}
  3842. */
  3843. var Cover = {
  3844. /**
  3845. * Required only when "cover" option is true.
  3846. *
  3847. * @type {boolean}
  3848. */
  3849. required: options.cover,
  3850. /**
  3851. * Called when the component is mounted.
  3852. */
  3853. mount: function mount() {
  3854. Splide.on('lazyload:loaded', function (img) {
  3855. cover(img, false);
  3856. });
  3857. Splide.on('mounted updated refresh', function () {
  3858. return apply(false);
  3859. });
  3860. },
  3861. /**
  3862. * Destroy.
  3863. */
  3864. destroy: function destroy() {
  3865. apply(true);
  3866. }
  3867. };
  3868. /**
  3869. * Apply "cover" to all slides.
  3870. *
  3871. * @param {boolean} uncover - If true, "cover" will be clear.
  3872. */
  3873. function apply(uncover) {
  3874. Components.Elements.each(function (Slide) {
  3875. var img = child(Slide.slide, 'IMG') || child(Slide.container, 'IMG');
  3876. if (img && img.src) {
  3877. cover(img, uncover);
  3878. }
  3879. });
  3880. }
  3881. /**
  3882. * Set background image of the parent element, using source of the given image element.
  3883. *
  3884. * @param {Element} img - An image element.
  3885. * @param {boolean} uncover - Reset "cover".
  3886. */
  3887. function cover(img, uncover) {
  3888. applyStyle(img.parentElement, {
  3889. background: uncover ? '' : "center/cover no-repeat url(\"" + img.src + "\")"
  3890. });
  3891. applyStyle(img, {
  3892. display: uncover ? '' : 'none'
  3893. });
  3894. }
  3895. return Cover;
  3896. });
  3897. // CONCATENATED MODULE: ./src/js/components/arrows/path.js
  3898. /**
  3899. * Export vector path for an arrow.
  3900. *
  3901. * @author Naotoshi Fujita
  3902. * @copyright Naotoshi Fujita. All rights reserved.
  3903. */
  3904. /**
  3905. * Namespace definition for SVG element.
  3906. *
  3907. * @type {string}
  3908. */
  3909. var XML_NAME_SPACE = 'http://www.w3.org/2000/svg';
  3910. /**
  3911. * The arrow vector path.
  3912. *
  3913. * @type {number}
  3914. */
  3915. 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';
  3916. /**
  3917. * SVG width and height.
  3918. *
  3919. * @type {number}
  3920. */
  3921. var SIZE = 40;
  3922. // CONCATENATED MODULE: ./src/js/components/arrows/index.js
  3923. /**
  3924. * The component for appending prev/next arrows.
  3925. *
  3926. * @author Naotoshi Fujita
  3927. * @copyright Naotoshi Fujita. All rights reserved.
  3928. */
  3929. ;
  3930. /**
  3931. * The component for appending prev/next arrows.
  3932. *
  3933. * @param {Splide} Splide - A Splide instance.
  3934. * @param {Object} Components - An object containing components.
  3935. * @param {string} name - A component name as a lowercase string.
  3936. *
  3937. * @return {Object} - The component object.
  3938. */
  3939. /* harmony default export */ const arrows = (function (Splide, Components, name) {
  3940. /**
  3941. * Previous arrow element.
  3942. *
  3943. * @type {Element|undefined}
  3944. */
  3945. var prev;
  3946. /**
  3947. * Next arrow element.
  3948. *
  3949. * @type {Element|undefined}
  3950. */
  3951. var next;
  3952. /**
  3953. * Store the class list.
  3954. *
  3955. * @type {Object}
  3956. */
  3957. var classes = Splide.classes;
  3958. /**
  3959. * Hold the root element.
  3960. *
  3961. * @type {Element}
  3962. */
  3963. var root = Splide.root;
  3964. /**
  3965. * Whether arrows are created programmatically or not.
  3966. *
  3967. * @type {boolean}
  3968. */
  3969. var created;
  3970. /**
  3971. * Hold the Elements component.
  3972. *
  3973. * @type {Object}
  3974. */
  3975. var Elements = Components.Elements;
  3976. /**
  3977. * Arrows component object.
  3978. *
  3979. * @type {Object}
  3980. */
  3981. var Arrows = {
  3982. /**
  3983. * Required when the arrows option is true.
  3984. *
  3985. * @type {boolean}
  3986. */
  3987. required: Splide.options.arrows,
  3988. /**
  3989. * Called when the component is mounted.
  3990. */
  3991. mount: function mount() {
  3992. // Attempt to get arrows from HTML source.
  3993. prev = Elements.arrows.prev;
  3994. next = Elements.arrows.next; // If arrows were not found in HTML, let's generate them.
  3995. if ((!prev || !next) && Splide.options.arrows) {
  3996. prev = createArrow(true);
  3997. next = createArrow(false);
  3998. created = true;
  3999. appendArrows();
  4000. }
  4001. if (prev && next) {
  4002. bind();
  4003. }
  4004. this.arrows = {
  4005. prev: prev,
  4006. next: next
  4007. };
  4008. },
  4009. /**
  4010. * Called after all components are mounted.
  4011. */
  4012. mounted: function mounted() {
  4013. Splide.emit(name + ":mounted", prev, next);
  4014. },
  4015. /**
  4016. * Destroy.
  4017. */
  4018. destroy: function destroy() {
  4019. removeAttribute([prev, next], 'disabled');
  4020. if (created) {
  4021. dom_remove(prev.parentElement);
  4022. }
  4023. }
  4024. };
  4025. /**
  4026. * Listen to native and custom events.
  4027. */
  4028. function bind() {
  4029. Splide.on('click', function () {
  4030. Splide.go('<');
  4031. }, prev).on('click', function () {
  4032. Splide.go('>');
  4033. }, next).on('mounted move updated refresh', updateDisabled);
  4034. }
  4035. /**
  4036. * Update a disabled attribute.
  4037. */
  4038. function updateDisabled() {
  4039. var _Components$Controlle = Components.Controller,
  4040. prevIndex = _Components$Controlle.prevIndex,
  4041. nextIndex = _Components$Controlle.nextIndex;
  4042. var isEnough = Splide.length > Splide.options.perPage || Splide.is(LOOP);
  4043. prev.disabled = prevIndex < 0 || !isEnough;
  4044. next.disabled = nextIndex < 0 || !isEnough;
  4045. Splide.emit(name + ":updated", prev, next, prevIndex, nextIndex);
  4046. }
  4047. /**
  4048. * Create a wrapper element and append arrows.
  4049. */
  4050. function appendArrows() {
  4051. var wrapper = create('div', {
  4052. "class": classes.arrows
  4053. });
  4054. append(wrapper, prev);
  4055. append(wrapper, next);
  4056. var slider = Elements.slider;
  4057. var parent = Splide.options.arrows === 'slider' && slider ? slider : root;
  4058. before(wrapper, parent.firstElementChild);
  4059. }
  4060. /**
  4061. * Create an arrow element.
  4062. *
  4063. * @param {boolean} prev - Determine to create a prev arrow or next arrow.
  4064. *
  4065. * @return {Element} - A created arrow element.
  4066. */
  4067. function createArrow(prev) {
  4068. 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) + "\" />");
  4069. return domify(arrow);
  4070. }
  4071. return Arrows;
  4072. });
  4073. // CONCATENATED MODULE: ./src/js/components/pagination/index.js
  4074. /**
  4075. * The component for handling pagination
  4076. *
  4077. * @author Naotoshi Fujita
  4078. * @copyright Naotoshi Fujita. All rights reserved.
  4079. */
  4080. ;
  4081. /**
  4082. * The event name for updating some attributes of pagination nodes.
  4083. *
  4084. * @type {string}
  4085. */
  4086. var ATTRIBUTES_UPDATE_EVENT = 'move.page';
  4087. /**
  4088. * The event name for recreating pagination.
  4089. *
  4090. * @type {string}
  4091. */
  4092. var UPDATE_EVENT = 'updated.page refresh.page';
  4093. /**
  4094. * The component for handling pagination
  4095. *
  4096. * @param {Splide} Splide - A Splide instance.
  4097. * @param {Object} Components - An object containing components.
  4098. * @param {string} name - A component name as a lowercase string.
  4099. *
  4100. * @return {Object} - The component object.
  4101. */
  4102. /* harmony default export */ const pagination = (function (Splide, Components, name) {
  4103. /**
  4104. * Store all data for pagination.
  4105. * - list: A list element.
  4106. * - items: An array that contains objects(li, button, index, page).
  4107. *
  4108. * @type {Object}
  4109. */
  4110. var data = {};
  4111. /**
  4112. * Hold the Elements component.
  4113. *
  4114. * @type {Object}
  4115. */
  4116. var Elements = Components.Elements;
  4117. /**
  4118. * Pagination component object.
  4119. *
  4120. * @type {Object}
  4121. */
  4122. var Pagination = {
  4123. /**
  4124. * Called when the component is mounted.
  4125. */
  4126. mount: function mount() {
  4127. var pagination = Splide.options.pagination;
  4128. if (pagination) {
  4129. data = createPagination();
  4130. var slider = Elements.slider;
  4131. var parent = pagination === 'slider' && slider ? slider : Splide.root;
  4132. append(parent, data.list);
  4133. Splide.on(ATTRIBUTES_UPDATE_EVENT, updateAttributes);
  4134. }
  4135. Splide.off(UPDATE_EVENT).on(UPDATE_EVENT, function () {
  4136. Pagination.destroy();
  4137. if (Splide.options.pagination) {
  4138. Pagination.mount();
  4139. Pagination.mounted();
  4140. }
  4141. });
  4142. },
  4143. /**
  4144. * Called after all components are mounted.
  4145. */
  4146. mounted: function mounted() {
  4147. if (Splide.options.pagination) {
  4148. var index = Splide.index;
  4149. Splide.emit(name + ":mounted", data, this.getItem(index));
  4150. updateAttributes(index, -1);
  4151. }
  4152. },
  4153. /**
  4154. * Destroy the pagination.
  4155. * Be aware that node.remove() is not supported by IE.
  4156. */
  4157. destroy: function destroy() {
  4158. dom_remove(data.list);
  4159. if (data.items) {
  4160. data.items.forEach(function (item) {
  4161. Splide.off('click', item.button);
  4162. });
  4163. } // Do not remove UPDATE_EVENT to recreate pagination if needed.
  4164. Splide.off(ATTRIBUTES_UPDATE_EVENT);
  4165. data = {};
  4166. },
  4167. /**
  4168. * Return an item by index.
  4169. *
  4170. * @param {number} index - A slide index.
  4171. *
  4172. * @return {Object|undefined} - An item object on success or undefined on failure.
  4173. */
  4174. getItem: function getItem(index) {
  4175. return data.items[Components.Controller.toPage(index)];
  4176. },
  4177. /**
  4178. * Return object containing pagination data.
  4179. *
  4180. * @return {Object} - Pagination data including list and items.
  4181. */
  4182. get data() {
  4183. return data;
  4184. }
  4185. };
  4186. /**
  4187. * Update attributes.
  4188. *
  4189. * @param {number} index - Active index.
  4190. * @param {number} prevIndex - Prev index.
  4191. */
  4192. function updateAttributes(index, prevIndex) {
  4193. var prev = Pagination.getItem(prevIndex);
  4194. var curr = Pagination.getItem(index);
  4195. var active = STATUS_CLASSES.active;
  4196. if (prev) {
  4197. removeClass(prev.button, active);
  4198. }
  4199. if (curr) {
  4200. addClass(curr.button, active);
  4201. }
  4202. Splide.emit(name + ":updated", data, prev, curr);
  4203. }
  4204. /**
  4205. * Create a wrapper and button elements.
  4206. *
  4207. * @return {Object} - An object contains all data.
  4208. */
  4209. function createPagination() {
  4210. var options = Splide.options;
  4211. var classes = Splide.classes;
  4212. var list = create('ul', {
  4213. "class": classes.pagination
  4214. });
  4215. var items = Elements.getSlides(false).filter(function (Slide) {
  4216. return options.focus !== false || Slide.index % options.perPage === 0;
  4217. }).map(function (Slide, page) {
  4218. var li = create('li', {});
  4219. var button = create('button', {
  4220. "class": classes.page,
  4221. type: 'button'
  4222. });
  4223. append(li, button);
  4224. append(list, li);
  4225. Splide.on('click', function () {
  4226. Splide.go(">" + page);
  4227. }, button);
  4228. return {
  4229. li: li,
  4230. button: button,
  4231. page: page,
  4232. Slides: Elements.getSlidesByPage(page)
  4233. };
  4234. });
  4235. return {
  4236. list: list,
  4237. items: items
  4238. };
  4239. }
  4240. return Pagination;
  4241. });
  4242. // CONCATENATED MODULE: ./src/js/components/lazyload/index.js
  4243. /**
  4244. * The component for loading slider images lazily.
  4245. *
  4246. * @author Naotoshi Fujita
  4247. * @copyright Naotoshi Fujita. All rights reserved.
  4248. */
  4249. ;
  4250. /**
  4251. * The name for a data attribute of src.
  4252. *
  4253. * @type {string}
  4254. */
  4255. var SRC_DATA_NAME = 'data-splide-lazy';
  4256. /**
  4257. * The name for a data attribute of srcset.
  4258. *
  4259. * @type {string}
  4260. */
  4261. var SRCSET_DATA_NAME = 'data-splide-lazy-srcset';
  4262. /**
  4263. * The component for loading slider images lazily.
  4264. *
  4265. * @param {Splide} Splide - A Splide instance.
  4266. * @param {Object} Components - An object containing components.
  4267. * @param {string} name - A component name as a lowercase string.
  4268. *
  4269. * @return {Object} - The component object.
  4270. */
  4271. /* harmony default export */ const lazyload = (function (Splide, Components, name) {
  4272. /**
  4273. * Next index for sequential loading.
  4274. *
  4275. * @type {number}
  4276. */
  4277. var nextIndex;
  4278. /**
  4279. * Store objects containing an img element and a Slide object.
  4280. *
  4281. * @type {Object[]}
  4282. */
  4283. var images;
  4284. /**
  4285. * Store the options.
  4286. *
  4287. * @type {Object}
  4288. */
  4289. var options = Splide.options;
  4290. /**
  4291. * Whether to load images sequentially or not.
  4292. *
  4293. * @type {boolean}
  4294. */
  4295. var isSequential = options.lazyLoad === 'sequential';
  4296. /**
  4297. * Lazyload component object.
  4298. *
  4299. * @type {Object}
  4300. */
  4301. var Lazyload = {
  4302. /**
  4303. * Mount only when the lazyload option is provided.
  4304. *
  4305. * @type {boolean}
  4306. */
  4307. required: options.lazyLoad,
  4308. /**
  4309. * Called when the component is mounted.
  4310. */
  4311. mount: function mount() {
  4312. Splide.on('mounted refresh', function () {
  4313. init();
  4314. Components.Elements.each(function (Slide) {
  4315. each(Slide.slide.querySelectorAll("[" + SRC_DATA_NAME + "], [" + SRCSET_DATA_NAME + "]"), function (img) {
  4316. if (!img.src && !img.srcset) {
  4317. images.push({
  4318. img: img,
  4319. Slide: Slide
  4320. });
  4321. applyStyle(img, {
  4322. display: 'none'
  4323. });
  4324. }
  4325. });
  4326. });
  4327. if (isSequential) {
  4328. loadNext();
  4329. }
  4330. });
  4331. if (!isSequential) {
  4332. Splide.on("mounted refresh moved." + name, check);
  4333. }
  4334. },
  4335. /**
  4336. * Destroy.
  4337. */
  4338. destroy: init
  4339. };
  4340. /**
  4341. * Initialize parameters.
  4342. */
  4343. function init() {
  4344. images = [];
  4345. nextIndex = 0;
  4346. }
  4347. /**
  4348. * Check how close each image is from the active slide and
  4349. * determine whether to start loading or not, according to the distance.
  4350. *
  4351. * @param {number} index - Current index.
  4352. */
  4353. function check(index) {
  4354. index = isNaN(index) ? Splide.index : index;
  4355. images = images.filter(function (image) {
  4356. if (image.Slide.isWithin(index, options.perPage * (options.preloadPages + 1))) {
  4357. load(image.img, image.Slide);
  4358. return false;
  4359. }
  4360. return true;
  4361. }); // Unbind if all images are loaded.
  4362. if (!images[0]) {
  4363. Splide.off("moved." + name);
  4364. }
  4365. }
  4366. /**
  4367. * Start loading an image.
  4368. * Creating a clone of the image element since setting src attribute directly to it
  4369. * often occurs 'hitch', blocking some other processes of a browser.
  4370. *
  4371. * @param {Element} img - An image element.
  4372. * @param {Object} Slide - A Slide object.
  4373. */
  4374. function load(img, Slide) {
  4375. addClass(Slide.slide, STATUS_CLASSES.loading);
  4376. var spinner = create('span', {
  4377. "class": Splide.classes.spinner
  4378. });
  4379. append(img.parentElement, spinner);
  4380. img.onload = function () {
  4381. loaded(img, spinner, Slide, false);
  4382. };
  4383. img.onerror = function () {
  4384. loaded(img, spinner, Slide, true);
  4385. };
  4386. setAttribute(img, 'srcset', getAttribute(img, SRCSET_DATA_NAME) || '');
  4387. setAttribute(img, 'src', getAttribute(img, SRC_DATA_NAME) || '');
  4388. }
  4389. /**
  4390. * Start loading a next image in images array.
  4391. */
  4392. function loadNext() {
  4393. if (nextIndex < images.length) {
  4394. var image = images[nextIndex];
  4395. load(image.img, image.Slide);
  4396. }
  4397. nextIndex++;
  4398. }
  4399. /**
  4400. * Called just after the image was loaded or loading was aborted by some error.
  4401. *
  4402. * @param {Element} img - An image element.
  4403. * @param {Element} spinner - A spinner element.
  4404. * @param {Object} Slide - A Slide object.
  4405. * @param {boolean} error - True if the image was loaded successfully or false on error.
  4406. */
  4407. function loaded(img, spinner, Slide, error) {
  4408. removeClass(Slide.slide, STATUS_CLASSES.loading);
  4409. if (!error) {
  4410. dom_remove(spinner);
  4411. applyStyle(img, {
  4412. display: ''
  4413. });
  4414. Splide.emit(name + ":loaded", img).emit('resize');
  4415. }
  4416. if (isSequential) {
  4417. loadNext();
  4418. }
  4419. }
  4420. return Lazyload;
  4421. });
  4422. // CONCATENATED MODULE: ./src/js/constants/a11y.js
  4423. /**
  4424. * Export aria attribute names.
  4425. *
  4426. * @author Naotoshi Fujita
  4427. * @copyright Naotoshi Fujita. All rights reserved.
  4428. */
  4429. /**
  4430. * Attribute name for aria-current.
  4431. *
  4432. * @type {string}
  4433. */
  4434. var ARIA_CURRENRT = 'aria-current';
  4435. /**
  4436. * Attribute name for aria-control.
  4437. *
  4438. * @type {string}
  4439. */
  4440. var ARIA_CONTROLS = 'aria-controls';
  4441. /**
  4442. * Attribute name for aria-control.
  4443. *
  4444. * @type {string}
  4445. */
  4446. var ARIA_LABEL = 'aria-label';
  4447. /**
  4448. * Attribute name for aria-labelledby.
  4449. *
  4450. * @type {string}
  4451. */
  4452. var ARIA_LABELLEDBY = 'aria-labelledby';
  4453. /**
  4454. * Attribute name for aria-hidden.
  4455. *
  4456. * @type {string}
  4457. */
  4458. var ARIA_HIDDEN = 'aria-hidden';
  4459. /**
  4460. * Attribute name for tab-index.
  4461. *
  4462. * @type {string}
  4463. */
  4464. var TAB_INDEX = 'tabindex';
  4465. // CONCATENATED MODULE: ./src/js/components/keyboard/index.js
  4466. /**
  4467. * The component for controlling slides via keyboard.
  4468. *
  4469. * @author Naotoshi Fujita
  4470. * @copyright Naotoshi Fujita. All rights reserved.
  4471. */
  4472. ;
  4473. /**
  4474. * Map a key to a slide control.
  4475. *
  4476. * @type {Object}
  4477. */
  4478. var KEY_MAP = {
  4479. ltr: {
  4480. ArrowLeft: '<',
  4481. ArrowRight: '>',
  4482. // For IE.
  4483. Left: '<',
  4484. Right: '>'
  4485. },
  4486. rtl: {
  4487. ArrowLeft: '>',
  4488. ArrowRight: '<',
  4489. // For IE.
  4490. Left: '>',
  4491. Right: '<'
  4492. },
  4493. ttb: {
  4494. ArrowUp: '<',
  4495. ArrowDown: '>',
  4496. // For IE.
  4497. Up: '<',
  4498. Down: '>'
  4499. }
  4500. };
  4501. /**
  4502. * The component for controlling slides via keyboard.
  4503. *
  4504. * @param {Splide} Splide - A Splide instance.
  4505. *
  4506. * @return {Object} - The component object.
  4507. */
  4508. /* harmony default export */ const keyboard = (function (Splide) {
  4509. /**
  4510. * Hold the target element.
  4511. *
  4512. * @type {Element|Document|undefined}
  4513. */
  4514. var target;
  4515. return {
  4516. /**
  4517. * Called when the component is mounted.
  4518. */
  4519. mount: function mount() {
  4520. Splide.on('mounted updated', function () {
  4521. var options = Splide.options;
  4522. var root = Splide.root;
  4523. var map = KEY_MAP[options.direction];
  4524. var keyboard = options.keyboard;
  4525. if (target) {
  4526. Splide.off('keydown', target);
  4527. removeAttribute(root, TAB_INDEX);
  4528. }
  4529. if (keyboard) {
  4530. if (keyboard === 'focused') {
  4531. target = root;
  4532. setAttribute(root, TAB_INDEX, 0);
  4533. } else {
  4534. target = document;
  4535. }
  4536. Splide.on('keydown', function (e) {
  4537. if (map[e.key]) {
  4538. Splide.go(map[e.key]);
  4539. }
  4540. }, target);
  4541. }
  4542. });
  4543. }
  4544. };
  4545. });
  4546. // CONCATENATED MODULE: ./src/js/components/a11y/index.js
  4547. /**
  4548. * The component for enhancing accessibility.
  4549. *
  4550. * @author Naotoshi Fujita
  4551. * @copyright Naotoshi Fujita. All rights reserved.
  4552. */
  4553. ;
  4554. /**
  4555. * The component for enhancing accessibility.
  4556. *
  4557. * @param {Splide} Splide - A Splide instance.
  4558. * @param {Object} Components - An object containing components.
  4559. *
  4560. * @return {Object} - The component object.
  4561. */
  4562. /* harmony default export */ const a11y = (function (Splide, Components) {
  4563. /**
  4564. * Hold a i18n object.
  4565. *
  4566. * @type {Object}
  4567. */
  4568. var i18n = Splide.i18n;
  4569. /**
  4570. * Hold the Elements component.
  4571. *
  4572. * @type {Object}
  4573. */
  4574. var Elements = Components.Elements;
  4575. /**
  4576. * All attributes related with A11y.
  4577. *
  4578. * @type {string[]}
  4579. */
  4580. var allAttributes = [ARIA_HIDDEN, TAB_INDEX, ARIA_CONTROLS, ARIA_LABEL, ARIA_CURRENRT, 'role'];
  4581. /**
  4582. * A11y component object.
  4583. *
  4584. * @type {Object}
  4585. */
  4586. var A11y = {
  4587. /**
  4588. * Required only when the accessibility option is true.
  4589. *
  4590. * @type {boolean}
  4591. */
  4592. required: Splide.options.accessibility,
  4593. /**
  4594. * Called when the component is mounted.
  4595. */
  4596. mount: function mount() {
  4597. Splide.on('visible', function (Slide) {
  4598. updateSlide(Slide.slide, true);
  4599. }).on('hidden', function (Slide) {
  4600. updateSlide(Slide.slide, false);
  4601. }).on('arrows:mounted', initArrows).on('arrows:updated', updateArrows).on('pagination:mounted', initPagination).on('pagination:updated', updatePagination).on('refresh', function () {
  4602. removeAttribute(Components.Clones.clones, allAttributes);
  4603. });
  4604. if (Splide.options.isNavigation) {
  4605. Splide.on('navigation:mounted navigation:updated', initNavigation).on('active', function (Slide) {
  4606. updateNavigation(Slide, true);
  4607. }).on('inactive', function (Slide) {
  4608. updateNavigation(Slide, false);
  4609. });
  4610. }
  4611. initAutoplay();
  4612. },
  4613. /**
  4614. * Destroy.
  4615. */
  4616. destroy: function destroy() {
  4617. var Arrows = Components.Arrows;
  4618. var arrows = Arrows ? Arrows.arrows : {};
  4619. removeAttribute(Elements.slides.concat([arrows.prev, arrows.next, Elements.play, Elements.pause]), allAttributes);
  4620. }
  4621. };
  4622. /**
  4623. * Update slide attributes when it gets visible or hidden.
  4624. *
  4625. * @param {Element} slide - A slide element.
  4626. * @param {Boolean} visible - True when the slide gets visible, or false when hidden.
  4627. */
  4628. function updateSlide(slide, visible) {
  4629. setAttribute(slide, ARIA_HIDDEN, !visible);
  4630. if (Splide.options.slideFocus) {
  4631. setAttribute(slide, TAB_INDEX, visible ? 0 : -1);
  4632. }
  4633. }
  4634. /**
  4635. * Initialize arrows if they are available.
  4636. * Append screen reader elements and add aria-controls attribute.
  4637. *
  4638. * @param {Element} prev - Previous arrow element.
  4639. * @param {Element} next - Next arrow element.
  4640. */
  4641. function initArrows(prev, next) {
  4642. var controls = Elements.track.id;
  4643. setAttribute(prev, ARIA_CONTROLS, controls);
  4644. setAttribute(next, ARIA_CONTROLS, controls);
  4645. }
  4646. /**
  4647. * Update arrow attributes.
  4648. *
  4649. * @param {Element} prev - Previous arrow element.
  4650. * @param {Element} next - Next arrow element.
  4651. * @param {number} prevIndex - Previous slide index or -1 when there is no precede slide.
  4652. * @param {number} nextIndex - Next slide index or -1 when there is no next slide.
  4653. */
  4654. function updateArrows(prev, next, prevIndex, nextIndex) {
  4655. var index = Splide.index;
  4656. var prevLabel = prevIndex > -1 && index < prevIndex ? i18n.last : i18n.prev;
  4657. var nextLabel = nextIndex > -1 && index > nextIndex ? i18n.first : i18n.next;
  4658. setAttribute(prev, ARIA_LABEL, prevLabel);
  4659. setAttribute(next, ARIA_LABEL, nextLabel);
  4660. }
  4661. /**
  4662. * Initialize pagination if it's available.
  4663. * Append a screen reader element and add aria-controls/label attribute to each item.
  4664. *
  4665. * @param {Object} data - Data object containing all items.
  4666. * @param {Object} activeItem - An initial active item.
  4667. */
  4668. function initPagination(data, activeItem) {
  4669. if (activeItem) {
  4670. setAttribute(activeItem.button, ARIA_CURRENRT, true);
  4671. }
  4672. data.items.forEach(function (item) {
  4673. var options = Splide.options;
  4674. var text = options.focus === false && options.perPage > 1 ? i18n.pageX : i18n.slideX;
  4675. var label = sprintf(text, item.page + 1);
  4676. var button = item.button;
  4677. var controls = item.Slides.map(function (Slide) {
  4678. return Slide.slide.id;
  4679. });
  4680. setAttribute(button, ARIA_CONTROLS, controls.join(' '));
  4681. setAttribute(button, ARIA_LABEL, label);
  4682. });
  4683. }
  4684. /**
  4685. * Update pagination attributes.
  4686. *
  4687. * @param {Object} data - Data object containing all items.
  4688. * @param {Element} prev - A previous active element.
  4689. * @param {Element} curr - A current active element.
  4690. */
  4691. function updatePagination(data, prev, curr) {
  4692. if (prev) {
  4693. removeAttribute(prev.button, ARIA_CURRENRT);
  4694. }
  4695. if (curr) {
  4696. setAttribute(curr.button, ARIA_CURRENRT, true);
  4697. }
  4698. }
  4699. /**
  4700. * Initialize autoplay buttons.
  4701. */
  4702. function initAutoplay() {
  4703. ['play', 'pause'].forEach(function (name) {
  4704. var elm = Elements[name];
  4705. if (elm) {
  4706. if (!isButton(elm)) {
  4707. setAttribute(elm, 'role', 'button');
  4708. }
  4709. setAttribute(elm, ARIA_CONTROLS, Elements.track.id);
  4710. setAttribute(elm, ARIA_LABEL, i18n[name]);
  4711. }
  4712. });
  4713. }
  4714. /**
  4715. * Initialize navigation slider.
  4716. * Add button role, aria-label, aria-controls to slide elements and append screen reader text to them.
  4717. *
  4718. * @param {Splide} main - A main Splide instance.
  4719. */
  4720. function initNavigation(main) {
  4721. Elements.each(function (Slide) {
  4722. var slide = Slide.slide;
  4723. var realIndex = Slide.realIndex;
  4724. if (!isButton(slide)) {
  4725. setAttribute(slide, 'role', 'button');
  4726. }
  4727. var slideIndex = realIndex > -1 ? realIndex : Slide.index;
  4728. var label = sprintf(i18n.slideX, slideIndex + 1);
  4729. var mainSlide = main.Components.Elements.getSlide(slideIndex);
  4730. setAttribute(slide, ARIA_LABEL, label);
  4731. if (mainSlide) {
  4732. setAttribute(slide, ARIA_CONTROLS, mainSlide.slide.id);
  4733. }
  4734. });
  4735. }
  4736. /**
  4737. * Update navigation attributes.
  4738. *
  4739. * @param {Object} Slide - A target Slide object.
  4740. * @param {boolean} active - True if the slide is active or false if inactive.
  4741. */
  4742. function updateNavigation(_ref, active) {
  4743. var slide = _ref.slide;
  4744. if (active) {
  4745. setAttribute(slide, ARIA_CURRENRT, true);
  4746. } else {
  4747. removeAttribute(slide, ARIA_CURRENRT);
  4748. }
  4749. }
  4750. /**
  4751. * Check if the given element is button or not.
  4752. *
  4753. * @param {Element} elm - An element to be checked.
  4754. *
  4755. * @return {boolean} - True if the given element is button.
  4756. */
  4757. function isButton(elm) {
  4758. return elm.tagName === 'BUTTON';
  4759. }
  4760. return A11y;
  4761. });
  4762. // CONCATENATED MODULE: ./src/js/components/sync/index.js
  4763. /**
  4764. * The component for synchronizing a slider with another.
  4765. *
  4766. * @author Naotoshi Fujita
  4767. * @copyright Naotoshi Fujita. All rights reserved.
  4768. */
  4769. ;
  4770. /**
  4771. * The event name for sync.
  4772. *
  4773. * @type {string}
  4774. */
  4775. var SYNC_EVENT = 'move.sync';
  4776. /**
  4777. * The event names for click navigation.
  4778. * @type {string}
  4779. */
  4780. var CLICK_EVENTS = 'mouseup touchend';
  4781. /**
  4782. * The keys for triggering the navigation button.
  4783. *
  4784. * @type {String[]}
  4785. */
  4786. var TRIGGER_KEYS = [' ', 'Enter', 'Spacebar'];
  4787. /**
  4788. * The component for synchronizing a slider with another.
  4789. *
  4790. * @param {Splide} Splide - A Splide instance.
  4791. *
  4792. * @return {Object} - The component object.
  4793. */
  4794. /* harmony default export */ const sync = (function (Splide) {
  4795. /**
  4796. * Keep the sibling Splide instance.
  4797. *
  4798. * @type {Splide}
  4799. */
  4800. var sibling = Splide.sibling;
  4801. /**
  4802. * Whether the sibling slider is navigation or not.
  4803. *
  4804. * @type {Splide|boolean}
  4805. */
  4806. var isNavigation = sibling && sibling.options.isNavigation;
  4807. /**
  4808. * Layout component object.
  4809. *
  4810. * @type {Object}
  4811. */
  4812. var Sync = {
  4813. /**
  4814. * Required only when the sub slider is available.
  4815. *
  4816. * @type {boolean}
  4817. */
  4818. required: !!sibling,
  4819. /**
  4820. * Called when the component is mounted.
  4821. */
  4822. mount: function mount() {
  4823. syncMain();
  4824. syncSibling();
  4825. if (isNavigation) {
  4826. bind();
  4827. Splide.on('refresh', function () {
  4828. setTimeout(function () {
  4829. bind();
  4830. sibling.emit('navigation:updated', Splide);
  4831. });
  4832. });
  4833. }
  4834. },
  4835. /**
  4836. * Called after all components are mounted.
  4837. */
  4838. mounted: function mounted() {
  4839. if (isNavigation) {
  4840. sibling.emit('navigation:mounted', Splide);
  4841. }
  4842. }
  4843. };
  4844. /**
  4845. * Listen the primary slider event to move secondary one.
  4846. * Must unbind a handler at first to avoid infinite loop.
  4847. */
  4848. function syncMain() {
  4849. Splide.on(SYNC_EVENT, function (newIndex, prevIndex, destIndex) {
  4850. sibling.off(SYNC_EVENT).go(sibling.is(LOOP) ? destIndex : newIndex, false);
  4851. syncSibling();
  4852. });
  4853. }
  4854. /**
  4855. * Listen the secondary slider event to move primary one.
  4856. * Must unbind a handler at first to avoid infinite loop.
  4857. */
  4858. function syncSibling() {
  4859. sibling.on(SYNC_EVENT, function (newIndex, prevIndex, destIndex) {
  4860. Splide.off(SYNC_EVENT).go(Splide.is(LOOP) ? destIndex : newIndex, false);
  4861. syncMain();
  4862. });
  4863. }
  4864. /**
  4865. * Listen some events on each slide.
  4866. */
  4867. function bind() {
  4868. sibling.Components.Elements.each(function (_ref) {
  4869. var slide = _ref.slide,
  4870. index = _ref.index;
  4871. /*
  4872. * Listen mouseup and touchend events to handle click.
  4873. */
  4874. Splide.off(CLICK_EVENTS, slide).on(CLICK_EVENTS, function (e) {
  4875. // Ignore a middle or right click.
  4876. if (!e.button || e.button === 0) {
  4877. moveSibling(index);
  4878. }
  4879. }, slide);
  4880. /*
  4881. * Subscribe keyup to handle Enter and Space key.
  4882. * Note that Array.includes is not supported by IE.
  4883. */
  4884. Splide.off('keyup', slide).on('keyup', function (e) {
  4885. if (TRIGGER_KEYS.indexOf(e.key) > -1) {
  4886. e.preventDefault();
  4887. moveSibling(index);
  4888. }
  4889. }, slide, {
  4890. passive: false
  4891. });
  4892. });
  4893. }
  4894. /**
  4895. * Move the sibling to the given index.
  4896. * Need to check "IDLE" status because slides can be moving by Drag component.
  4897. *
  4898. * @param {number} index - Target index.
  4899. */
  4900. function moveSibling(index) {
  4901. if (Splide.State.is(IDLE)) {
  4902. sibling.go(index);
  4903. }
  4904. }
  4905. return Sync;
  4906. });
  4907. // CONCATENATED MODULE: ./src/js/components/breakpoints/index.js
  4908. /**
  4909. * The component for updating options according to a current window width.
  4910. *
  4911. * @author Naotoshi Fujita
  4912. * @copyright Naotoshi Fujita. All rights reserved.
  4913. */
  4914. ;
  4915. /**
  4916. * Interval time for throttle.
  4917. *
  4918. * @type {number}
  4919. */
  4920. var THROTTLE = 50;
  4921. /**
  4922. * The component for updating options according to a current window width.
  4923. *
  4924. * @param {Splide} Splide - A Splide instance.
  4925. *
  4926. * @return {Object} - The component object.
  4927. */
  4928. /* harmony default export */ const breakpoints = (function (Splide) {
  4929. /**
  4930. * Store breakpoints.
  4931. *
  4932. * @type {Object|boolean}
  4933. */
  4934. var breakpoints = Splide.options.breakpoints;
  4935. /**
  4936. * The check function whose frequency of call is reduced.
  4937. *
  4938. * @type {Function}
  4939. */
  4940. var throttledCheck = throttle(check, THROTTLE);
  4941. /**
  4942. * Keep initial options.
  4943. *
  4944. * @type {Object}
  4945. */
  4946. var initialOptions;
  4947. /**
  4948. * An array containing objects of point and MediaQueryList.
  4949. *
  4950. * @type {Object[]}
  4951. */
  4952. var map = [];
  4953. /**
  4954. * Hold the previous breakpoint.
  4955. *
  4956. * @type {number|undefined}
  4957. */
  4958. var prevPoint;
  4959. /**
  4960. * Breakpoints component object.
  4961. *
  4962. * @type {Object}
  4963. */
  4964. var Breakpoints = {
  4965. /**
  4966. * Required only when the breakpoints definition is provided and browser supports matchMedia.
  4967. *
  4968. * @type {boolean}
  4969. */
  4970. required: breakpoints && matchMedia,
  4971. /**
  4972. * Called when the component is mounted.
  4973. */
  4974. mount: function mount() {
  4975. map = Object.keys(breakpoints).sort(function (n, m) {
  4976. return +n - +m;
  4977. }).map(function (point) {
  4978. return {
  4979. point: point,
  4980. mql: matchMedia("(max-width:" + point + "px)")
  4981. };
  4982. });
  4983. /*
  4984. * To keep monitoring resize event after destruction without "completely",
  4985. * use native addEventListener instead of Splide.on.
  4986. */
  4987. this.destroy(true);
  4988. addEventListener('resize', throttledCheck); // Keep initial options to apply them when no breakpoint matches.
  4989. initialOptions = Splide.options;
  4990. check();
  4991. },
  4992. /**
  4993. * Destroy.
  4994. *
  4995. * @param {boolean} completely - Whether to destroy Splide completely.
  4996. */
  4997. destroy: function destroy(completely) {
  4998. if (completely) {
  4999. removeEventListener('resize', throttledCheck);
  5000. }
  5001. }
  5002. };
  5003. /**
  5004. * Check the breakpoint.
  5005. */
  5006. function check() {
  5007. var point = getPoint();
  5008. if (point !== prevPoint) {
  5009. prevPoint = point;
  5010. var State = Splide.State;
  5011. var options = breakpoints[point] || initialOptions;
  5012. var destroy = options.destroy;
  5013. if (destroy) {
  5014. Splide.options = initialOptions;
  5015. Splide.destroy(destroy === 'completely');
  5016. } else {
  5017. if (State.is(DESTROYED)) {
  5018. Splide.mount();
  5019. }
  5020. Splide.options = options;
  5021. }
  5022. }
  5023. }
  5024. /**
  5025. * Return the breakpoint matching current window width.
  5026. * Note that Array.prototype.find is not supported by IE.
  5027. *
  5028. * @return {number|string} - A breakpoint as number or string. -1 if no point matches.
  5029. */
  5030. function getPoint() {
  5031. var item = map.filter(function (item) {
  5032. return item.mql.matches;
  5033. })[0];
  5034. return item ? item.point : -1;
  5035. }
  5036. return Breakpoints;
  5037. });
  5038. // CONCATENATED MODULE: ./src/js/components/index.js
  5039. /**
  5040. * Export components.
  5041. *
  5042. * @author Naotoshi Fujita
  5043. * @copyright Naotoshi Fujita. All rights reserved.
  5044. */
  5045. ;
  5046. var COMPLETE = {
  5047. Options: options,
  5048. Breakpoints: breakpoints,
  5049. Controller: controller,
  5050. Elements: components_elements,
  5051. Track: track,
  5052. Clones: clones,
  5053. Layout: layout,
  5054. Drag: drag,
  5055. Click: click,
  5056. Autoplay: autoplay,
  5057. Cover: cover,
  5058. Arrows: arrows,
  5059. Pagination: pagination,
  5060. LazyLoad: lazyload,
  5061. Keyboard: keyboard,
  5062. Sync: sync,
  5063. A11y: a11y
  5064. };
  5065. var LIGHT = {
  5066. Options: options,
  5067. Controller: controller,
  5068. Elements: components_elements,
  5069. Track: track,
  5070. Clones: clones,
  5071. Layout: layout,
  5072. Drag: drag,
  5073. Click: click,
  5074. Arrows: arrows,
  5075. Pagination: pagination,
  5076. A11y: a11y
  5077. };
  5078. // CONCATENATED MODULE: ./build/complete/complete.js
  5079. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
  5080. /**
  5081. * Export "Splide" class for frontend with full components.
  5082. *
  5083. * @author Naotoshi Fujita
  5084. * @copyright Naotoshi Fujita. All rights reserved.
  5085. */
  5086. /**
  5087. * Export Splide with all components.
  5088. */
  5089. var complete_Splide = /*#__PURE__*/function (_Core) {
  5090. _inheritsLoose(Splide, _Core);
  5091. function Splide(root, options) {
  5092. return _Core.call(this, root, options, COMPLETE) || this;
  5093. }
  5094. return Splide;
  5095. }(Splide); // Register the class as a global variable for non-ES6 environment.
  5096. window.Splide = complete_Splide;
  5097. /******/ })()
  5098. ;