splide.js 135 KB

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