splide.esm.js 136 KB

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