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