splide.esm.js 135 KB

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