splide.esm.js 135 KB

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