splide.esm.js 136 KB

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