splide.esm.js 136 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903
  1. /*!
  2. * Splide.js
  3. * Version : 2.4.15
  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').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 resize.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 trackRect = getRect(Splide.Components.Elements.track);
  1822. var slideRect = getRect(slide);
  1823. if (Splide.options.direction === TTB) {
  1824. return trackRect.top <= slideRect.top && slideRect.bottom <= trackRect.bottom;
  1825. }
  1826. return trackRect.left <= slideRect.left && slideRect.right <= trackRect.right;
  1827. },
  1828. /**
  1829. * Calculate how far this slide is from another slide and
  1830. * return true if the distance is within the given number.
  1831. *
  1832. * @param {number} from - Index of a target slide.
  1833. * @param {number} within - True if the slide is within this number.
  1834. *
  1835. * @return {boolean} - True if the slide is within the number or false otherwise.
  1836. */
  1837. isWithin: function isWithin(from, within) {
  1838. var diff = Math.abs(from - index);
  1839. if (!Splide.is(SLIDE) && !this.isClone) {
  1840. diff = Math.min(diff, Splide.length - diff);
  1841. }
  1842. return diff < within;
  1843. }
  1844. };
  1845. /**
  1846. * Update classes for activity or visibility.
  1847. *
  1848. * @param {boolean} active - Is active/visible or not.
  1849. * @param {boolean} forVisibility - Toggle classes for activity or visibility.
  1850. */
  1851. function _update(active, forVisibility) {
  1852. var type = forVisibility ? 'visible' : 'active';
  1853. var className = STATUS_CLASSES[type];
  1854. if (active) {
  1855. addClass(slide, className);
  1856. Splide.emit("" + type, Slide);
  1857. } else {
  1858. if (hasClass(slide, className)) {
  1859. removeClass(slide, className);
  1860. Splide.emit("" + (forVisibility ? 'hidden' : 'inactive'), Slide);
  1861. }
  1862. }
  1863. }
  1864. /**
  1865. * Restore the original styles.
  1866. */
  1867. function restoreStyles() {
  1868. setAttribute(slide, 'style', Slide.styles);
  1869. }
  1870. return Slide;
  1871. });
  1872. // CONCATENATED MODULE: ./src/js/components/elements/index.js
  1873. /**
  1874. * The component for main elements.
  1875. *
  1876. * @author Naotoshi Fujita
  1877. * @copyright Naotoshi Fujita. All rights reserved.
  1878. */
  1879. ;
  1880. /**
  1881. * The property name for UID stored in a window object.
  1882. *
  1883. * @type {string}
  1884. */
  1885. var UID_NAME = 'uid';
  1886. /**
  1887. * The component for main elements.
  1888. *
  1889. * @param {Splide} Splide - A Splide instance.
  1890. * @param {Object} Components - An object containing components.
  1891. *
  1892. * @return {Object} - The component object.
  1893. */
  1894. /* harmony default export */ const components_elements = (function (Splide, Components) {
  1895. /**
  1896. * Hold the root element.
  1897. *
  1898. * @type {Element}
  1899. */
  1900. var root = Splide.root;
  1901. /**
  1902. * Hold the class list.
  1903. *
  1904. * @type {Object}
  1905. */
  1906. var classes = Splide.classes;
  1907. /**
  1908. * Store Slide objects.
  1909. *
  1910. * @type {Array}
  1911. */
  1912. var Slides = [];
  1913. /*
  1914. * Assign unique ID to the root element if it doesn't have the one.
  1915. * Note that IE doesn't support padStart() to fill the uid by 0.
  1916. */
  1917. if (!root.id) {
  1918. window.splide = window.splide || {};
  1919. var uid = window.splide[UID_NAME] || 0;
  1920. window.splide[UID_NAME] = ++uid;
  1921. root.id = "splide" + pad(uid);
  1922. }
  1923. /**
  1924. * Elements component object.
  1925. *
  1926. * @type {Object}
  1927. */
  1928. var Elements = {
  1929. /**
  1930. * Called when the component is mounted.
  1931. * Collect main elements and store them as member properties.
  1932. */
  1933. mount: function mount() {
  1934. var _this = this;
  1935. this.init();
  1936. Splide.on('refresh', function () {
  1937. _this.destroy();
  1938. _this.init();
  1939. }).on('updated', function () {
  1940. removeClass(root, getClasses());
  1941. addClass(root, getClasses());
  1942. });
  1943. },
  1944. /**
  1945. * Destroy.
  1946. */
  1947. destroy: function destroy() {
  1948. Slides.forEach(function (Slide) {
  1949. Slide.destroy();
  1950. });
  1951. Slides = [];
  1952. removeClass(root, getClasses());
  1953. },
  1954. /**
  1955. * Initialization.
  1956. */
  1957. init: function init() {
  1958. var _this2 = this;
  1959. collect();
  1960. addClass(root, getClasses());
  1961. this.slides.forEach(function (slide, index) {
  1962. _this2.register(slide, index, -1);
  1963. });
  1964. },
  1965. /**
  1966. * Register a slide to create a Slide object and handle its behavior.
  1967. *
  1968. * @param {Element} slide - A slide element.
  1969. * @param {number} index - A unique index. This can be negative.
  1970. * @param {number} realIndex - A real index for clones. Set -1 for real slides.
  1971. */
  1972. register: function register(slide, index, realIndex) {
  1973. var SlideObject = elements_slide(Splide, index, realIndex, slide);
  1974. SlideObject.mount();
  1975. Slides.push(SlideObject);
  1976. },
  1977. /**
  1978. * Return the Slide object designated by the index.
  1979. * Note that "find" is not supported by IE.
  1980. *
  1981. * @return {Object|undefined} - A Slide object if available. Undefined if not.
  1982. */
  1983. getSlide: function getSlide(index) {
  1984. return Slides.filter(function (Slide) {
  1985. return Slide.index === index;
  1986. })[0];
  1987. },
  1988. /**
  1989. * Return all Slide objects.
  1990. *
  1991. * @param {boolean} includeClones - Whether to include cloned slides or not.
  1992. *
  1993. * @return {Object[]} - Slide objects.
  1994. */
  1995. getSlides: function getSlides(includeClones) {
  1996. return includeClones ? Slides : Slides.filter(function (Slide) {
  1997. return !Slide.isClone;
  1998. });
  1999. },
  2000. /**
  2001. * Return Slide objects belonging to the given page.
  2002. *
  2003. * @param {number} page - A page number.
  2004. *
  2005. * @return {Object[]} - An array containing Slide objects.
  2006. */
  2007. getSlidesByPage: function getSlidesByPage(page) {
  2008. var idx = Components.Controller.toIndex(page);
  2009. var options = Splide.options;
  2010. var max = options.focus !== false ? 1 : options.perPage;
  2011. return Slides.filter(function (_ref) {
  2012. var index = _ref.index;
  2013. return idx <= index && index < idx + max;
  2014. });
  2015. },
  2016. /**
  2017. * Insert a slide to a slider.
  2018. * Need to refresh Splide after adding a slide.
  2019. *
  2020. * @param {Node|string} slide - A slide element to be added.
  2021. * @param {number} index - A slide will be added at the position.
  2022. * @param {Function} callback - Called right after the slide is added to the DOM tree.
  2023. */
  2024. add: function add(slide, index, callback) {
  2025. if (typeof slide === 'string') {
  2026. slide = domify(slide);
  2027. }
  2028. if (slide instanceof Element) {
  2029. var ref = this.slides[index]; // This will be removed in mount() of a Slide component.
  2030. applyStyle(slide, {
  2031. display: 'none'
  2032. });
  2033. if (ref) {
  2034. before(slide, ref);
  2035. this.slides.splice(index, 0, slide);
  2036. } else {
  2037. append(this.list, slide);
  2038. this.slides.push(slide);
  2039. }
  2040. loaded(slide, function () {
  2041. callback && callback(slide);
  2042. });
  2043. }
  2044. },
  2045. /**
  2046. * Remove a slide from a slider.
  2047. * Need to refresh Splide after removing a slide.
  2048. *
  2049. * @param index - Slide index.
  2050. */
  2051. remove: function remove(index) {
  2052. dom_remove(this.slides.splice(index, 1)[0]);
  2053. },
  2054. /**
  2055. * Trigger the provided callback for each Slide object.
  2056. *
  2057. * @param {Function} callback - A callback function. The first argument will be the Slide object.
  2058. */
  2059. each: function each(callback) {
  2060. Slides.forEach(callback);
  2061. },
  2062. /**
  2063. * Return slides length without clones.
  2064. *
  2065. * @return {number} - Slide length.
  2066. */
  2067. get length() {
  2068. return this.slides.length;
  2069. },
  2070. /**
  2071. * Return "SlideObjects" length including clones.
  2072. *
  2073. * @return {number} - Slide length including clones.
  2074. */
  2075. get total() {
  2076. return Slides.length;
  2077. }
  2078. };
  2079. /**
  2080. * Collect elements.
  2081. */
  2082. function collect() {
  2083. Elements.slider = child(root, classes.slider);
  2084. Elements.track = find(root, "." + classes.track);
  2085. Elements.list = child(Elements.track, classes.list);
  2086. exist(Elements.track && Elements.list, 'Track or list was not found.');
  2087. Elements.slides = children(Elements.list, classes.slide);
  2088. var arrows = findParts(classes.arrows);
  2089. Elements.arrows = {
  2090. prev: find(arrows, "." + classes.prev),
  2091. next: find(arrows, "." + classes.next)
  2092. };
  2093. var autoplay = findParts(classes.autoplay);
  2094. Elements.bar = find(findParts(classes.progress), "." + classes.bar);
  2095. Elements.play = find(autoplay, "." + classes.play);
  2096. Elements.pause = find(autoplay, "." + classes.pause);
  2097. Elements.track.id = Elements.track.id || root.id + "-track";
  2098. Elements.list.id = Elements.list.id || root.id + "-list";
  2099. }
  2100. /**
  2101. * Return class names for the root element.
  2102. */
  2103. function getClasses() {
  2104. var rootClass = classes.root;
  2105. var options = Splide.options;
  2106. return [rootClass + "--" + options.type, rootClass + "--" + options.direction, options.drag ? rootClass + "--draggable" : '', options.isNavigation ? rootClass + "--nav" : '', STATUS_CLASSES.active];
  2107. }
  2108. /**
  2109. * Find parts only from children of the root or track.
  2110. *
  2111. * @return {Element} - A found element or undefined.
  2112. */
  2113. function findParts(className) {
  2114. return child(root, className) || child(Elements.slider, className);
  2115. }
  2116. return Elements;
  2117. });
  2118. // CONCATENATED MODULE: ./src/js/components/controller/index.js
  2119. /**
  2120. * The component for controlling the track.
  2121. *
  2122. * @author Naotoshi Fujita
  2123. * @copyright Naotoshi Fujita. All rights reserved.
  2124. */
  2125. ;
  2126. var floor = Math.floor;
  2127. /**
  2128. * The component for controlling the track.
  2129. *
  2130. * @param {Splide} Splide - A Splide instance.
  2131. * @param {Object} Components - An object containing components.
  2132. *
  2133. * @return {Object} - The component object.
  2134. */
  2135. /* harmony default export */ const controller = (function (Splide, Components) {
  2136. /**
  2137. * Store current options.
  2138. *
  2139. * @type {Object}
  2140. */
  2141. var options;
  2142. /**
  2143. * True if the slide is LOOP mode.
  2144. *
  2145. * @type {boolean}
  2146. */
  2147. var isLoop;
  2148. /**
  2149. * Controller component object.
  2150. *
  2151. * @type {Object}
  2152. */
  2153. var Controller = {
  2154. /**
  2155. * Called when the component is mounted.
  2156. */
  2157. mount: function mount() {
  2158. options = Splide.options;
  2159. isLoop = Splide.is(LOOP);
  2160. bind();
  2161. },
  2162. /**
  2163. * Make track run by the given control.
  2164. * - "+{i}" : Increment the slide index by i.
  2165. * - "-{i}" : Decrement the slide index by i.
  2166. * - "{i}" : Go to the slide whose index is i.
  2167. * - ">" : Go to next page.
  2168. * - "<" : Go to prev page.
  2169. * - ">{i}" : Go to page i.
  2170. *
  2171. * @param {string|number} control - A control pattern.
  2172. * @param {boolean} silently - Go to the destination without event emission.
  2173. */
  2174. go: function go(control, silently) {
  2175. var destIndex = this.trim(this.parse(control));
  2176. Components.Track.go(destIndex, this.rewind(destIndex), silently);
  2177. },
  2178. /**
  2179. * Parse the given control and return the destination index for the track.
  2180. *
  2181. * @param {string} control - A control target pattern.
  2182. *
  2183. * @return {number} - A parsed target.
  2184. */
  2185. parse: function parse(control) {
  2186. var index = Splide.index;
  2187. var matches = String(control).match(/([+\-<>]+)(\d+)?/);
  2188. var indicator = matches ? matches[1] : '';
  2189. var number = matches ? parseInt(matches[2]) : 0;
  2190. switch (indicator) {
  2191. case '+':
  2192. index += number || 1;
  2193. break;
  2194. case '-':
  2195. index -= number || 1;
  2196. break;
  2197. case '>':
  2198. case '<':
  2199. index = parsePage(number, index, indicator === '<');
  2200. break;
  2201. default:
  2202. index = parseInt(control);
  2203. }
  2204. return index;
  2205. },
  2206. /**
  2207. * Compute index from the given page number.
  2208. *
  2209. * @param {number} page - Page number.
  2210. *
  2211. * @return {number} - A computed page number.
  2212. */
  2213. toIndex: function toIndex(page) {
  2214. if (hasFocus()) {
  2215. return page;
  2216. }
  2217. var length = Splide.length;
  2218. var perPage = options.perPage;
  2219. var index = page * perPage;
  2220. index = index - (this.pageLength * perPage - length) * floor(index / length); // Adjustment for the last page.
  2221. if (length - perPage <= index && index < length) {
  2222. index = length - perPage;
  2223. }
  2224. return index;
  2225. },
  2226. /**
  2227. * Compute page number from the given slide index.
  2228. *
  2229. * @param {number} index - Slide index.
  2230. *
  2231. * @return {number} - A computed page number.
  2232. */
  2233. toPage: function toPage(index) {
  2234. if (hasFocus()) {
  2235. return index;
  2236. }
  2237. var length = Splide.length;
  2238. var perPage = options.perPage; // Make the last "perPage" number of slides belong to the last page.
  2239. if (length - perPage <= index && index < length) {
  2240. return floor((length - 1) / perPage);
  2241. }
  2242. return floor(index / perPage);
  2243. },
  2244. /**
  2245. * Trim the given index according to the current mode.
  2246. * Index being returned could be less than 0 or greater than the length in Loop mode.
  2247. *
  2248. * @param {number} index - An index being trimmed.
  2249. *
  2250. * @return {number} - A trimmed index.
  2251. */
  2252. trim: function trim(index) {
  2253. if (!isLoop) {
  2254. index = options.rewind ? this.rewind(index) : between(index, 0, this.edgeIndex);
  2255. }
  2256. return index;
  2257. },
  2258. /**
  2259. * Rewind the given index if it's out of range.
  2260. *
  2261. * @param {number} index - An index.
  2262. *
  2263. * @return {number} - A rewound index.
  2264. */
  2265. rewind: function rewind(index) {
  2266. var edge = this.edgeIndex;
  2267. if (isLoop) {
  2268. while (index > edge) {
  2269. index -= edge + 1;
  2270. }
  2271. while (index < 0) {
  2272. index += edge + 1;
  2273. }
  2274. } else {
  2275. if (index > edge) {
  2276. index = 0;
  2277. } else if (index < 0) {
  2278. index = edge;
  2279. }
  2280. }
  2281. return index;
  2282. },
  2283. /**
  2284. * Check if the direction is "rtl" or not.
  2285. *
  2286. * @return {boolean} - True if "rtl" or false if not.
  2287. */
  2288. isRtl: function isRtl() {
  2289. return options.direction === RTL;
  2290. },
  2291. /**
  2292. * Return the page length.
  2293. *
  2294. * @return {number} - Max page number.
  2295. */
  2296. get pageLength() {
  2297. var length = Splide.length;
  2298. return hasFocus() ? length : Math.ceil(length / options.perPage);
  2299. },
  2300. /**
  2301. * Return the edge index.
  2302. *
  2303. * @return {number} - Edge index.
  2304. */
  2305. get edgeIndex() {
  2306. var length = Splide.length;
  2307. if (!length) {
  2308. return 0;
  2309. }
  2310. if (hasFocus() || options.isNavigation || isLoop) {
  2311. return length - 1;
  2312. }
  2313. return length - options.perPage;
  2314. },
  2315. /**
  2316. * Return the index of the previous slide.
  2317. *
  2318. * @return {number} - The index of the previous slide if available. -1 otherwise.
  2319. */
  2320. get prevIndex() {
  2321. var prev = Splide.index - 1;
  2322. if (isLoop || options.rewind) {
  2323. prev = this.rewind(prev);
  2324. }
  2325. return prev > -1 ? prev : -1;
  2326. },
  2327. /**
  2328. * Return the index of the next slide.
  2329. *
  2330. * @return {number} - The index of the next slide if available. -1 otherwise.
  2331. */
  2332. get nextIndex() {
  2333. var next = Splide.index + 1;
  2334. if (isLoop || options.rewind) {
  2335. next = this.rewind(next);
  2336. }
  2337. return Splide.index < next && next <= this.edgeIndex || next === 0 ? next : -1;
  2338. }
  2339. };
  2340. /**
  2341. * Listen to some events.
  2342. */
  2343. function bind() {
  2344. Splide.on('move', function (newIndex) {
  2345. Splide.index = newIndex;
  2346. }).on('updated refresh', function (newOptions) {
  2347. options = newOptions || options;
  2348. Splide.index = between(Splide.index, 0, Controller.edgeIndex);
  2349. });
  2350. }
  2351. /**
  2352. * Verify if the focus option is available or not.
  2353. *
  2354. * @return {boolean} - True if a slider has the focus option.
  2355. */
  2356. function hasFocus() {
  2357. return options.focus !== false;
  2358. }
  2359. /**
  2360. * Return the next or previous page index computed by the page number and current index.
  2361. *
  2362. * @param {number} number - Specify the page number.
  2363. * @param {number} index - Current index.
  2364. * @param {boolean} prev - Prev or next.
  2365. *
  2366. * @return {number} - Slide index.
  2367. */
  2368. function parsePage(number, index, prev) {
  2369. if (number > -1) {
  2370. return Controller.toIndex(number);
  2371. }
  2372. var perMove = options.perMove;
  2373. var sign = prev ? -1 : 1;
  2374. if (perMove) {
  2375. return index + perMove * sign;
  2376. }
  2377. return Controller.toIndex(Controller.toPage(index) + sign);
  2378. }
  2379. return Controller;
  2380. });
  2381. // CONCATENATED MODULE: ./src/js/components/track/index.js
  2382. /**
  2383. * The component for moving list in the track.
  2384. *
  2385. * @author Naotoshi Fujita
  2386. * @copyright Naotoshi Fujita. All rights reserved.
  2387. */
  2388. ;
  2389. var abs = Math.abs;
  2390. /**
  2391. * The component for moving list in the track.
  2392. *
  2393. * @param {Splide} Splide - A Splide instance.
  2394. * @param {Object} Components - An object containing components.
  2395. *
  2396. * @return {Object} - The component object.
  2397. */
  2398. /* harmony default export */ const track = (function (Splide, Components) {
  2399. /**
  2400. * Hold the Layout component.
  2401. *
  2402. * @type {Object}
  2403. */
  2404. var Layout;
  2405. /**
  2406. * Hold the Layout component.
  2407. *
  2408. * @type {Object}
  2409. */
  2410. var Elements;
  2411. /**
  2412. * Store the list element.
  2413. *
  2414. * @type {Element}
  2415. */
  2416. var list;
  2417. /**
  2418. * Whether the current direction is vertical or not.
  2419. *
  2420. * @type {boolean}
  2421. */
  2422. var isVertical = Splide.options.direction === TTB;
  2423. /**
  2424. * Whether the slider type is FADE or not.
  2425. *
  2426. * @type {boolean}
  2427. */
  2428. var isFade = Splide.is(FADE);
  2429. /**
  2430. * Whether the slider direction is RTL or not.
  2431. *
  2432. * @type {boolean}
  2433. */
  2434. var isRTL = Splide.options.direction === RTL;
  2435. /**
  2436. * This will be true while transitioning from the last index to the first one.
  2437. *
  2438. * @type {boolean}
  2439. */
  2440. var isLoopPending = false;
  2441. /**
  2442. * Sign for the direction. Only RTL mode uses the positive sign.
  2443. *
  2444. * @type {number}
  2445. */
  2446. var sign = isRTL ? 1 : -1;
  2447. /**
  2448. * Track component object.
  2449. *
  2450. * @type {Object}
  2451. */
  2452. var Track = {
  2453. /**
  2454. * Make public the sign defined locally.
  2455. *
  2456. * @type {number}
  2457. */
  2458. sign: sign,
  2459. /**
  2460. * Called when the component is mounted.
  2461. */
  2462. mount: function mount() {
  2463. Elements = Components.Elements;
  2464. Layout = Components.Layout;
  2465. list = Elements.list;
  2466. },
  2467. /**
  2468. * Called after the component is mounted.
  2469. * The resize event must be registered after the Layout's one is done.
  2470. */
  2471. mounted: function mounted() {
  2472. var _this = this;
  2473. if (!isFade) {
  2474. this.jump(0);
  2475. Splide.on('mounted resize updated', function () {
  2476. _this.jump(Splide.index);
  2477. });
  2478. }
  2479. },
  2480. /**
  2481. * Go to the given destination index.
  2482. * After arriving there, the track is jump to the new index without animation, mainly for loop mode.
  2483. *
  2484. * @param {number} destIndex - A destination index.
  2485. * This can be negative or greater than slides length for reaching clones.
  2486. * @param {number} newIndex - An actual new index. They are always same in Slide and Rewind mode.
  2487. * @param {boolean} silently - If true, suppress emitting events.
  2488. */
  2489. go: function go(destIndex, newIndex, silently) {
  2490. var newPosition = getTrimmedPosition(destIndex);
  2491. var prevIndex = Splide.index; // Prevent any actions while transitioning from the last index to the first one for jump.
  2492. if (Splide.State.is(MOVING) && isLoopPending) {
  2493. return;
  2494. }
  2495. isLoopPending = destIndex !== newIndex;
  2496. if (!silently) {
  2497. Splide.emit('move', newIndex, prevIndex, destIndex);
  2498. }
  2499. if (Math.abs(newPosition - this.position) >= 1 || isFade) {
  2500. Components.Transition.start(destIndex, newIndex, prevIndex, this.toCoord(newPosition), function () {
  2501. onTransitionEnd(destIndex, newIndex, prevIndex, silently);
  2502. });
  2503. } else {
  2504. if (destIndex !== prevIndex && Splide.options.trimSpace === 'move') {
  2505. Components.Controller.go(destIndex + destIndex - prevIndex, silently);
  2506. } else {
  2507. onTransitionEnd(destIndex, newIndex, prevIndex, silently);
  2508. }
  2509. }
  2510. },
  2511. /**
  2512. * Move the track to the specified index.
  2513. *
  2514. * @param {number} index - A destination index where the track jumps.
  2515. */
  2516. jump: function jump(index) {
  2517. this.translate(getTrimmedPosition(index));
  2518. },
  2519. /**
  2520. * Set the list position by CSS translate property.
  2521. *
  2522. * @param {number} position - A new position value.
  2523. */
  2524. translate: function translate(position) {
  2525. applyStyle(list, {
  2526. transform: "translate" + (isVertical ? 'Y' : 'X') + "(" + position + "px)"
  2527. });
  2528. },
  2529. /**
  2530. * Cancel the transition and set the list position.
  2531. * Also, loop the slider if necessary.
  2532. */
  2533. cancel: function cancel() {
  2534. if (Splide.is(LOOP)) {
  2535. this.shift();
  2536. } else {
  2537. // Ensure the current position.
  2538. this.translate(this.position);
  2539. }
  2540. applyStyle(list, {
  2541. transition: ''
  2542. });
  2543. },
  2544. /**
  2545. * Shift the slider if it exceeds borders on the edge.
  2546. */
  2547. shift: function shift() {
  2548. var position = abs(this.position);
  2549. var left = abs(this.toPosition(0));
  2550. var right = abs(this.toPosition(Splide.length));
  2551. var innerSize = right - left;
  2552. if (position < left) {
  2553. position += innerSize;
  2554. } else if (position > right) {
  2555. position -= innerSize;
  2556. }
  2557. this.translate(sign * position);
  2558. },
  2559. /**
  2560. * Trim redundant spaces on the left or right edge if necessary.
  2561. *
  2562. * @param {number} position - Position value to be trimmed.
  2563. *
  2564. * @return {number} - Trimmed position.
  2565. */
  2566. trim: function trim(position) {
  2567. if (!Splide.options.trimSpace || Splide.is(LOOP)) {
  2568. return position;
  2569. }
  2570. var edge = sign * (Layout.totalSize() - Layout.size - Layout.gap);
  2571. return between(position, edge, 0);
  2572. },
  2573. /**
  2574. * Calculate the closest slide index from the given position.
  2575. *
  2576. * @param {number} position - A position converted to an slide index.
  2577. *
  2578. * @return {number} - The closest slide index.
  2579. */
  2580. toIndex: function toIndex(position) {
  2581. var _this2 = this;
  2582. var index = 0;
  2583. var minDistance = Infinity;
  2584. Elements.getSlides(true).forEach(function (Slide) {
  2585. var slideIndex = Slide.index;
  2586. var distance = abs(_this2.toPosition(slideIndex) - position);
  2587. if (distance < minDistance) {
  2588. minDistance = distance;
  2589. index = slideIndex;
  2590. }
  2591. });
  2592. return index;
  2593. },
  2594. /**
  2595. * Return coordinates object by the given position.
  2596. *
  2597. * @param {number} position - A position value.
  2598. *
  2599. * @return {Object} - A coordinates object.
  2600. */
  2601. toCoord: function toCoord(position) {
  2602. return {
  2603. x: isVertical ? 0 : position,
  2604. y: isVertical ? position : 0
  2605. };
  2606. },
  2607. /**
  2608. * Calculate the track position by a slide index.
  2609. *
  2610. * @param {number} index - Slide index.
  2611. *
  2612. * @return {Object} - Calculated position.
  2613. */
  2614. toPosition: function toPosition(index) {
  2615. var position = Layout.totalSize(index) - Layout.slideSize(index) - Layout.gap;
  2616. return sign * (position + this.offset(index));
  2617. },
  2618. /**
  2619. * Return the current offset value, considering direction.
  2620. *
  2621. * @return {number} - Offset amount.
  2622. */
  2623. offset: function offset(index) {
  2624. var focus = Splide.options.focus;
  2625. var slideSize = Layout.slideSize(index);
  2626. if (focus === 'center') {
  2627. return -(Layout.size - slideSize) / 2;
  2628. }
  2629. return -(parseInt(focus) || 0) * (slideSize + Layout.gap);
  2630. },
  2631. /**
  2632. * Return the current position.
  2633. * This returns the correct position even while transitioning by CSS.
  2634. *
  2635. * @return {number} - Current position.
  2636. */
  2637. get position() {
  2638. var prop = isVertical ? 'top' : isRTL ? 'right' : 'left';
  2639. return getRect(list)[prop] - (getRect(Elements.track)[prop] - Layout.padding[prop] * sign);
  2640. }
  2641. };
  2642. /**
  2643. * Called whenever slides arrive at a destination.
  2644. *
  2645. * @param {number} destIndex - A destination index.
  2646. * @param {number} newIndex - A new index.
  2647. * @param {number} prevIndex - A previous index.
  2648. * @param {boolean} silently - If true, suppress emitting events.
  2649. */
  2650. function onTransitionEnd(destIndex, newIndex, prevIndex, silently) {
  2651. applyStyle(list, {
  2652. transition: ''
  2653. });
  2654. isLoopPending = false;
  2655. if (!isFade) {
  2656. Track.jump(newIndex);
  2657. }
  2658. if (!silently) {
  2659. Splide.emit('moved', newIndex, prevIndex, destIndex);
  2660. }
  2661. }
  2662. /**
  2663. * Convert index to the trimmed position.
  2664. *
  2665. * @return {number} - Trimmed position.
  2666. */
  2667. function getTrimmedPosition(index) {
  2668. return Track.trim(Track.toPosition(index));
  2669. }
  2670. return Track;
  2671. });
  2672. // CONCATENATED MODULE: ./src/js/components/clones/index.js
  2673. /**
  2674. * The component for cloning some slides for "loop" mode of the track.
  2675. *
  2676. * @author Naotoshi Fujita
  2677. * @copyright Naotoshi Fujita. All rights reserved.
  2678. */
  2679. ;
  2680. /**
  2681. * The component for cloning some slides for "loop" mode of the track.
  2682. *
  2683. * @param {Splide} Splide - A Splide instance.
  2684. * @param {Object} Components - An object containing components.
  2685. *
  2686. * @return {Object} - The component object.
  2687. */
  2688. /* harmony default export */ const clones = (function (Splide, Components) {
  2689. /**
  2690. * Store information of all clones.
  2691. *
  2692. * @type {Array}
  2693. */
  2694. var clones = [];
  2695. /**
  2696. * Store the current clone count on one side.
  2697. *
  2698. * @type {number}
  2699. */
  2700. var cloneCount = 0;
  2701. /**
  2702. * Keep Elements component.
  2703. *
  2704. * @type {Object}
  2705. */
  2706. var Elements = Components.Elements;
  2707. /**
  2708. * Clones component object.
  2709. *
  2710. * @type {Object}
  2711. */
  2712. var Clones = {
  2713. /**
  2714. * Called when the component is mounted.
  2715. */
  2716. mount: function mount() {
  2717. var _this = this;
  2718. if (Splide.is(LOOP)) {
  2719. init();
  2720. Splide.on('refresh', init).on('resize', function () {
  2721. if (cloneCount !== getCloneCount()) {
  2722. // Destroy before refresh not to collect clones by the Elements component.
  2723. _this.destroy();
  2724. Splide.refresh();
  2725. }
  2726. });
  2727. }
  2728. },
  2729. /**
  2730. * Destroy.
  2731. */
  2732. destroy: function destroy() {
  2733. dom_remove(clones);
  2734. clones = [];
  2735. },
  2736. /**
  2737. * Return all clones.
  2738. *
  2739. * @return {Element[]} - Cloned elements.
  2740. */
  2741. get clones() {
  2742. return clones;
  2743. },
  2744. /**
  2745. * Return clone length.
  2746. *
  2747. * @return {number} - A length of clones.
  2748. */
  2749. get length() {
  2750. return clones.length;
  2751. }
  2752. };
  2753. /**
  2754. * Initialization.
  2755. */
  2756. function init() {
  2757. Clones.destroy();
  2758. cloneCount = getCloneCount();
  2759. generateClones(cloneCount);
  2760. }
  2761. /**
  2762. * Generate and append/prepend clones.
  2763. *
  2764. * @param {number} count - The half number of clones.
  2765. */
  2766. function generateClones(count) {
  2767. var length = Elements.length,
  2768. register = Elements.register;
  2769. if (length) {
  2770. var slides = Elements.slides;
  2771. while (slides.length < count) {
  2772. slides = slides.concat(slides);
  2773. } // Clones after the last element.
  2774. slides.slice(0, count).forEach(function (elm, index) {
  2775. var clone = cloneDeeply(elm);
  2776. append(Elements.list, clone);
  2777. clones.push(clone);
  2778. register(clone, index + length, index % length);
  2779. }); // Clones before the first element.
  2780. slides.slice(-count).forEach(function (elm, index) {
  2781. var clone = cloneDeeply(elm);
  2782. before(clone, slides[0]);
  2783. clones.push(clone);
  2784. register(clone, index - count, (length + index - count % length) % length);
  2785. });
  2786. }
  2787. }
  2788. /**
  2789. * Return half count of clones to be generated.
  2790. * Clone count is determined by:
  2791. * - "clones" value in the options.
  2792. * - Number of slides that can be placed in a view in "fixed" mode.
  2793. * - Max pages a flick action can move.
  2794. * - Whether the slide length is enough for perPage.
  2795. *
  2796. * @return {number} - Count for clones.
  2797. */
  2798. function getCloneCount() {
  2799. var options = Splide.options;
  2800. if (options.clones) {
  2801. return options.clones;
  2802. } // Use the slide length in autoWidth mode because the number cannot be calculated.
  2803. var baseCount = options.autoWidth || options.autoHeight ? Elements.length : options.perPage;
  2804. var dimension = options.direction === TTB ? 'Height' : 'Width';
  2805. var fixedSize = toPixel(Splide.root, options["fixed" + dimension]);
  2806. if (fixedSize) {
  2807. // Roughly calculate the count. This needs not to be strict.
  2808. baseCount = Math.ceil(Elements.track["client" + dimension] / fixedSize);
  2809. }
  2810. return baseCount * (options.drag ? options.flickMaxPages + 1 : 1);
  2811. }
  2812. /**
  2813. * Clone deeply the given element.
  2814. *
  2815. * @param {Element} elm - An element being duplicated.
  2816. *
  2817. * @return {Node} - A cloned node(element).
  2818. */
  2819. function cloneDeeply(elm) {
  2820. var clone = elm.cloneNode(true);
  2821. addClass(clone, Splide.classes.clone); // ID should not be duplicated.
  2822. removeAttribute(clone, 'id');
  2823. return clone;
  2824. }
  2825. return Clones;
  2826. });
  2827. // CONCATENATED MODULE: ./src/js/components/layout/directions/horizontal.js
  2828. /**
  2829. * The resolver component for horizontal layout.
  2830. *
  2831. * @author Naotoshi Fujita
  2832. * @copyright Naotoshi Fujita. All rights reserved.
  2833. */
  2834. ;
  2835. /**
  2836. * The resolver component for horizontal layout.
  2837. *
  2838. * @param {Splide} Splide - A Splide instance.
  2839. * @param {Object} Components - An object containing components.
  2840. *
  2841. * @return {Object} - The resolver object.
  2842. */
  2843. /* harmony default export */ const horizontal = (function (Splide, Components) {
  2844. /**
  2845. * Keep the Elements component.
  2846. *
  2847. * @type {string}
  2848. */
  2849. var Elements = Components.Elements;
  2850. /**
  2851. * Keep the root element.
  2852. *
  2853. * @type {Element}
  2854. */
  2855. var root = Splide.root;
  2856. /**
  2857. * Keep the track element.
  2858. *
  2859. * @type {Element}
  2860. */
  2861. var track;
  2862. /**
  2863. * Keep the latest options.
  2864. *
  2865. * @type {Element}
  2866. */
  2867. var options = Splide.options;
  2868. return {
  2869. /**
  2870. * Margin property name.
  2871. *
  2872. * @type {string}
  2873. */
  2874. margin: 'margin' + (options.direction === RTL ? 'Left' : 'Right'),
  2875. /**
  2876. * Always 0 because the height will be determined by inner contents.
  2877. *
  2878. * @type {number}
  2879. */
  2880. height: 0,
  2881. /**
  2882. * Initialization.
  2883. */
  2884. init: function init() {
  2885. this.resize();
  2886. },
  2887. /**
  2888. * Resize gap and padding.
  2889. * This must be called on init.
  2890. */
  2891. resize: function resize() {
  2892. options = Splide.options;
  2893. track = Elements.track;
  2894. this.gap = toPixel(root, options.gap);
  2895. var padding = options.padding;
  2896. var left = toPixel(root, padding.left || padding);
  2897. var right = toPixel(root, padding.right || padding);
  2898. this.padding = {
  2899. left: left,
  2900. right: right
  2901. };
  2902. applyStyle(track, {
  2903. paddingLeft: unit(left),
  2904. paddingRight: unit(right)
  2905. });
  2906. },
  2907. /**
  2908. * Return total width from the left of the list to the right of the slide specified by the provided index.
  2909. *
  2910. * @param {number} index - Optional. A slide index. If undefined, total width of the slider will be returned.
  2911. *
  2912. * @return {number} - Total width to the right side of the specified slide, or 0 for an invalid index.
  2913. */
  2914. totalWidth: function totalWidth(index) {
  2915. if (index === void 0) {
  2916. index = Splide.length - 1;
  2917. }
  2918. var Slide = Elements.getSlide(index);
  2919. var width = 0;
  2920. if (Slide) {
  2921. var slideRect = getRect(Slide.slide);
  2922. var listRect = getRect(Elements.list);
  2923. if (options.direction === RTL) {
  2924. width = listRect.right - slideRect.left;
  2925. } else {
  2926. width = slideRect.right - listRect.left;
  2927. }
  2928. width += this.gap;
  2929. }
  2930. return width;
  2931. },
  2932. /**
  2933. * Return the slide width in px.
  2934. *
  2935. * @param {number} index - Slide index.
  2936. *
  2937. * @return {number} - The slide width.
  2938. */
  2939. slideWidth: function slideWidth(index) {
  2940. if (options.autoWidth) {
  2941. var Slide = Elements.getSlide(index);
  2942. return Slide ? Slide.slide.offsetWidth : 0;
  2943. }
  2944. var width = options.fixedWidth || (this.width + this.gap) / options.perPage - this.gap;
  2945. return toPixel(root, width);
  2946. },
  2947. /**
  2948. * Return the slide height in px.
  2949. *
  2950. * @return {number} - The slide height.
  2951. */
  2952. slideHeight: function slideHeight() {
  2953. var height = options.height || options.fixedHeight || this.width * options.heightRatio;
  2954. return toPixel(root, height);
  2955. },
  2956. /**
  2957. * Return slider width without padding.
  2958. *
  2959. * @return {number} - Current slider width.
  2960. */
  2961. get width() {
  2962. return track.clientWidth - this.padding.left - this.padding.right;
  2963. }
  2964. };
  2965. });
  2966. // CONCATENATED MODULE: ./src/js/components/layout/directions/vertical.js
  2967. /**
  2968. * The resolver component for vertical layout.
  2969. *
  2970. * @author Naotoshi Fujita
  2971. * @copyright Naotoshi Fujita. All rights reserved.
  2972. */
  2973. ;
  2974. /**
  2975. * The resolver component for vertical layout.
  2976. *
  2977. * @param {Splide} Splide - A Splide instance.
  2978. * @param {Object} Components - An object containing components.
  2979. *
  2980. * @return {Object} - The resolver object.
  2981. */
  2982. /* harmony default export */ const vertical = (function (Splide, Components) {
  2983. /**
  2984. * Keep the Elements component.
  2985. *
  2986. * @type {string}
  2987. */
  2988. var Elements = Components.Elements;
  2989. /**
  2990. * Keep the root element.
  2991. *
  2992. * @type {Element}
  2993. */
  2994. var root = Splide.root;
  2995. /**
  2996. * Keep the track element.
  2997. *
  2998. * @type {Element}
  2999. */
  3000. var track;
  3001. /**
  3002. * Keep the latest options.
  3003. *
  3004. * @type {Element}
  3005. */
  3006. var options;
  3007. return {
  3008. /**
  3009. * Margin property name.
  3010. *
  3011. * @type {string}
  3012. */
  3013. margin: 'marginBottom',
  3014. /**
  3015. * Initialization.
  3016. */
  3017. init: function init() {
  3018. this.resize();
  3019. },
  3020. /**
  3021. * Resize gap and padding.
  3022. * This must be called on init.
  3023. */
  3024. resize: function resize() {
  3025. options = Splide.options;
  3026. track = Elements.track;
  3027. this.gap = toPixel(root, options.gap);
  3028. var padding = options.padding;
  3029. var top = toPixel(root, padding.top || padding);
  3030. var bottom = toPixel(root, padding.bottom || padding);
  3031. this.padding = {
  3032. top: top,
  3033. bottom: bottom
  3034. };
  3035. applyStyle(track, {
  3036. paddingTop: unit(top),
  3037. paddingBottom: unit(bottom)
  3038. });
  3039. },
  3040. /**
  3041. * Return total height from the top of the list to the bottom of the slide specified by the provided index.
  3042. *
  3043. * @param {number} index - Optional. A slide index. If undefined, total height of the slider will be returned.
  3044. *
  3045. * @return {number} - Total height to the bottom of the specified slide, or 0 for an invalid index.
  3046. */
  3047. totalHeight: function totalHeight(index) {
  3048. if (index === void 0) {
  3049. index = Splide.length - 1;
  3050. }
  3051. var Slide = Elements.getSlide(index);
  3052. if (Slide) {
  3053. return getRect(Slide.slide).bottom - getRect(Elements.list).top + this.gap;
  3054. }
  3055. return 0;
  3056. },
  3057. /**
  3058. * Return the slide width in px.
  3059. *
  3060. * @return {number} - The slide width.
  3061. */
  3062. slideWidth: function slideWidth() {
  3063. return toPixel(root, options.fixedWidth || this.width);
  3064. },
  3065. /**
  3066. * Return the slide height in px.
  3067. *
  3068. * @param {number} index - Slide index.
  3069. *
  3070. * @return {number} - The slide height.
  3071. */
  3072. slideHeight: function slideHeight(index) {
  3073. if (options.autoHeight) {
  3074. var Slide = Elements.getSlide(index);
  3075. return Slide ? Slide.slide.offsetHeight : 0;
  3076. }
  3077. var height = options.fixedHeight || (this.height + this.gap) / options.perPage - this.gap;
  3078. return toPixel(root, height);
  3079. },
  3080. /**
  3081. * Return slider width without padding.
  3082. *
  3083. * @return {number} - Current slider width.
  3084. */
  3085. get width() {
  3086. return track.clientWidth;
  3087. },
  3088. /**
  3089. * Return slide height without padding.
  3090. *
  3091. * @return {number} - Slider height.
  3092. */
  3093. get height() {
  3094. var height = options.height || this.width * options.heightRatio;
  3095. exist(height, '"height" or "heightRatio" is missing.');
  3096. return toPixel(root, height) - this.padding.top - this.padding.bottom;
  3097. }
  3098. };
  3099. });
  3100. // CONCATENATED MODULE: ./src/js/utils/time.js
  3101. /**
  3102. * A package of utility functions related with time.
  3103. *
  3104. * @author Naotoshi Fujita
  3105. * @copyright Naotoshi Fujita. All rights reserved.
  3106. */
  3107. /**
  3108. * Simple throttle function that controls how often the given function is executed.
  3109. *
  3110. * @param {function} func - A function to be throttled.
  3111. * @param {number} wait - Time in millisecond for interval of execution.
  3112. *
  3113. * @return {Function} - A debounced function.
  3114. */
  3115. function throttle(func, wait) {
  3116. var timeout; // Declare function by the "function" keyword to prevent "this" from being inherited.
  3117. return function () {
  3118. if (!timeout) {
  3119. timeout = setTimeout(function () {
  3120. func();
  3121. timeout = null;
  3122. }, wait);
  3123. }
  3124. };
  3125. }
  3126. /**
  3127. * Custom setInterval function that provides progress rate as callback.
  3128. *
  3129. * @param {function} callback - A callback function fired every time the interval time passes.
  3130. * @param {number} interval - Interval duration in milliseconds.
  3131. * @param {function} progress - A callback function fired whenever the progress goes.
  3132. *
  3133. * @return {Object} - An object containing play() and pause() functions.
  3134. */
  3135. function createInterval(callback, interval, progress) {
  3136. var _window = window,
  3137. requestAnimationFrame = _window.requestAnimationFrame;
  3138. var start,
  3139. elapse,
  3140. rate,
  3141. _pause = true;
  3142. var step = function step(timestamp) {
  3143. if (!_pause) {
  3144. if (!start) {
  3145. start = timestamp;
  3146. if (rate && rate < 1) {
  3147. start -= rate * interval;
  3148. }
  3149. }
  3150. elapse = timestamp - start;
  3151. rate = elapse / interval;
  3152. if (elapse >= interval) {
  3153. start = 0;
  3154. rate = 1;
  3155. callback();
  3156. }
  3157. if (progress) {
  3158. progress(rate);
  3159. }
  3160. requestAnimationFrame(step);
  3161. }
  3162. };
  3163. return {
  3164. pause: function pause() {
  3165. _pause = true;
  3166. start = 0;
  3167. },
  3168. play: function play(reset) {
  3169. start = 0;
  3170. if (_pause) {
  3171. _pause = false;
  3172. if (reset) {
  3173. rate = 0;
  3174. }
  3175. requestAnimationFrame(step);
  3176. }
  3177. }
  3178. };
  3179. }
  3180. // CONCATENATED MODULE: ./src/js/components/layout/index.js
  3181. /**
  3182. * The component for handing slide layouts and their sizes.
  3183. *
  3184. * @author Naotoshi Fujita
  3185. * @copyright Naotoshi Fujita. All rights reserved.
  3186. */
  3187. ;
  3188. /**
  3189. * The component for handing slide layouts and their sizes.
  3190. *
  3191. * @param {Splide} Splide - A Splide instance.
  3192. * @param {Object} Components - An object containing components.
  3193. *
  3194. * @return {Object} - The component object.
  3195. */
  3196. /* harmony default export */ const layout = (function (Splide, Components) {
  3197. /**
  3198. * Keep the Elements component.
  3199. *
  3200. * @type {string}
  3201. */
  3202. var Elements = Components.Elements;
  3203. /**
  3204. * Whether the slider is vertical or not.
  3205. *
  3206. * @type {boolean}
  3207. */
  3208. var isVertical = Splide.options.direction === TTB;
  3209. /**
  3210. * Layout component object.
  3211. *
  3212. * @type {Object}
  3213. */
  3214. var Layout = object_assign({
  3215. /**
  3216. * Called when the component is mounted.
  3217. */
  3218. mount: function mount() {
  3219. bind();
  3220. init(); // The word "size" means width for a horizontal slider and height for a vertical slider.
  3221. this.totalSize = isVertical ? this.totalHeight : this.totalWidth;
  3222. this.slideSize = isVertical ? this.slideHeight : this.slideWidth;
  3223. },
  3224. /**
  3225. * Destroy the component.
  3226. */
  3227. destroy: function destroy() {
  3228. removeAttribute([Elements.list, Elements.track], 'style');
  3229. },
  3230. /**
  3231. * Return the slider height on the vertical mode or width on the horizontal mode.
  3232. *
  3233. * @return {number}
  3234. */
  3235. get size() {
  3236. return isVertical ? this.height : this.width;
  3237. }
  3238. }, isVertical ? vertical(Splide, Components) : horizontal(Splide, Components));
  3239. /**
  3240. * Init slider styles according to options.
  3241. */
  3242. function init() {
  3243. Layout.init();
  3244. applyStyle(Splide.root, {
  3245. maxWidth: unit(Splide.options.width)
  3246. });
  3247. Elements.each(function (Slide) {
  3248. Slide.slide.style[Layout.margin] = unit(Layout.gap);
  3249. });
  3250. resize();
  3251. }
  3252. /**
  3253. * Listen the resize native event with throttle.
  3254. * Initialize when the component is mounted or options are updated.
  3255. */
  3256. function bind() {
  3257. Splide.on('resize load', throttle(function () {
  3258. Splide.emit('resize');
  3259. }, Splide.options.throttle), window).on('resize', resize).on('updated refresh', init);
  3260. }
  3261. /**
  3262. * Resize the track and slide elements.
  3263. */
  3264. function resize() {
  3265. var options = Splide.options;
  3266. Layout.resize();
  3267. applyStyle(Elements.track, {
  3268. height: unit(Layout.height)
  3269. });
  3270. var slideHeight = options.autoHeight ? null : unit(Layout.slideHeight());
  3271. Elements.each(function (Slide) {
  3272. applyStyle(Slide.container, {
  3273. height: slideHeight
  3274. });
  3275. applyStyle(Slide.slide, {
  3276. width: options.autoWidth ? null : unit(Layout.slideWidth(Slide.index)),
  3277. height: Slide.container ? null : slideHeight
  3278. });
  3279. });
  3280. }
  3281. return Layout;
  3282. });
  3283. // CONCATENATED MODULE: ./src/js/components/drag/index.js
  3284. /**
  3285. * The component for supporting mouse drag and swipe.
  3286. *
  3287. * @author Naotoshi Fujita
  3288. * @copyright Naotoshi Fujita. All rights reserved.
  3289. */
  3290. ;
  3291. var drag_abs = Math.abs;
  3292. /**
  3293. * If the absolute velocity is greater thant this value,
  3294. * a slider always goes to a different slide after drag, not allowed to stay on a current slide.
  3295. */
  3296. var MIN_VELOCITY = 0.1;
  3297. /**
  3298. * Adjust how much the track can be pulled on the first or last page.
  3299. * The larger number this is, the farther the track moves.
  3300. * This should be around 5 - 9.
  3301. *
  3302. * @type {number}
  3303. */
  3304. var FRICTION_REDUCER = 7;
  3305. /**
  3306. * The component supporting mouse drag and swipe.
  3307. *
  3308. * @param {Splide} Splide - A Splide instance.
  3309. * @param {Object} Components - An object containing components.
  3310. *
  3311. * @return {Object} - The component object.
  3312. */
  3313. /* harmony default export */ const drag = (function (Splide, Components) {
  3314. /**
  3315. * Store the Move component.
  3316. *
  3317. * @type {Object}
  3318. */
  3319. var Track = Components.Track;
  3320. /**
  3321. * Store the Controller component.
  3322. *
  3323. * @type {Object}
  3324. */
  3325. var Controller = Components.Controller;
  3326. /**
  3327. * Coordinate of the track on starting drag.
  3328. *
  3329. * @type {Object}
  3330. */
  3331. var startCoord;
  3332. /**
  3333. * Analyzed info on starting drag.
  3334. *
  3335. * @type {Object|null}
  3336. */
  3337. var startInfo;
  3338. /**
  3339. * Analyzed info being updated while dragging/swiping.
  3340. *
  3341. * @type {Object}
  3342. */
  3343. var currentInfo;
  3344. /**
  3345. * Determine whether slides are being dragged or not.
  3346. *
  3347. * @type {boolean}
  3348. */
  3349. var isDragging;
  3350. /**
  3351. * Whether the slider direction is vertical or not.
  3352. *
  3353. * @type {boolean}
  3354. */
  3355. var isVertical = Splide.options.direction === TTB;
  3356. /**
  3357. * Axis for the direction.
  3358. *
  3359. * @type {string}
  3360. */
  3361. var axis = isVertical ? 'y' : 'x';
  3362. /**
  3363. * Drag component object.
  3364. *
  3365. * @type {Object}
  3366. */
  3367. var Drag = {
  3368. /**
  3369. * Whether dragging is disabled or not.
  3370. *
  3371. * @type {boolean}
  3372. */
  3373. disabled: false,
  3374. /**
  3375. * Called when the component is mounted.
  3376. */
  3377. mount: function mount() {
  3378. var _this = this;
  3379. var Elements = Components.Elements;
  3380. var track = Elements.track;
  3381. Splide.on('touchstart mousedown', start, track).on('touchmove mousemove', move, track, {
  3382. passive: false
  3383. }).on('touchend touchcancel mouseleave mouseup dragend', end, track).on('mounted refresh', function () {
  3384. // Prevent dragging an image or anchor itself.
  3385. each(Elements.list.querySelectorAll('img, a'), function (elm) {
  3386. Splide.off('dragstart', elm).on('dragstart', function (e) {
  3387. e.preventDefault();
  3388. }, elm, {
  3389. passive: false
  3390. });
  3391. });
  3392. }).on('mounted updated', function () {
  3393. _this.disabled = !Splide.options.drag;
  3394. });
  3395. }
  3396. };
  3397. /**
  3398. * Called when the track starts to be dragged.
  3399. *
  3400. * @param {TouchEvent|MouseEvent} e - TouchEvent or MouseEvent object.
  3401. */
  3402. function start(e) {
  3403. if (!Drag.disabled && !isDragging) {
  3404. // These prams are used to evaluate whether the slider should start moving.
  3405. init(e);
  3406. }
  3407. }
  3408. /**
  3409. * Initialize parameters.
  3410. *
  3411. * @param {TouchEvent|MouseEvent} e - TouchEvent or MouseEvent object.
  3412. */
  3413. function init(e) {
  3414. startCoord = Track.toCoord(Track.position);
  3415. startInfo = analyze(e, {});
  3416. currentInfo = startInfo;
  3417. }
  3418. /**
  3419. * Called while the track being dragged.
  3420. *
  3421. * @param {TouchEvent|MouseEvent} e - TouchEvent or MouseEvent object.
  3422. */
  3423. function move(e) {
  3424. if (startInfo) {
  3425. currentInfo = analyze(e, startInfo);
  3426. if (isDragging) {
  3427. if (e.cancelable) {
  3428. e.preventDefault();
  3429. }
  3430. if (!Splide.is(FADE)) {
  3431. var position = startCoord[axis] + currentInfo.offset[axis];
  3432. Track.translate(resist(position));
  3433. }
  3434. } else {
  3435. if (shouldMove(currentInfo)) {
  3436. Splide.emit('drag', startInfo);
  3437. isDragging = true;
  3438. Track.cancel(); // These params are actual drag data.
  3439. init(e);
  3440. }
  3441. }
  3442. }
  3443. }
  3444. /**
  3445. * Determine whether to start moving the track or not by drag angle.
  3446. *
  3447. * @param {Object} info - An information object.
  3448. *
  3449. * @return {boolean} - True if the track should be moved or false if not.
  3450. */
  3451. function shouldMove(_ref) {
  3452. var offset = _ref.offset;
  3453. if (Splide.State.is(MOVING) && Splide.options.waitForTransition) {
  3454. return false;
  3455. }
  3456. var angle = Math.atan(drag_abs(offset.y) / drag_abs(offset.x)) * 180 / Math.PI;
  3457. if (isVertical) {
  3458. angle = 90 - angle;
  3459. }
  3460. return angle < Splide.options.dragAngleThreshold;
  3461. }
  3462. /**
  3463. * Resist dragging the track on the first/last page because there is no more.
  3464. *
  3465. * @param {number} position - A position being applied to the track.
  3466. *
  3467. * @return {Object} - Adjusted position.
  3468. */
  3469. function resist(position) {
  3470. if (Splide.is(SLIDE)) {
  3471. var sign = Track.sign;
  3472. var _start = sign * Track.trim(Track.toPosition(0));
  3473. var _end = sign * Track.trim(Track.toPosition(Controller.edgeIndex));
  3474. position *= sign;
  3475. if (position < _start) {
  3476. position = _start - FRICTION_REDUCER * Math.log(_start - position);
  3477. } else if (position > _end) {
  3478. position = _end + FRICTION_REDUCER * Math.log(position - _end);
  3479. }
  3480. position *= sign;
  3481. }
  3482. return position;
  3483. }
  3484. /**
  3485. * Called when dragging ends.
  3486. */
  3487. function end() {
  3488. startInfo = null;
  3489. if (isDragging) {
  3490. Splide.emit('dragged', currentInfo);
  3491. go(currentInfo);
  3492. isDragging = false;
  3493. }
  3494. }
  3495. /**
  3496. * Go to the slide determined by the analyzed data.
  3497. *
  3498. * @param {Object} info - An info object.
  3499. */
  3500. function go(info) {
  3501. var velocity = info.velocity[axis];
  3502. var absV = drag_abs(velocity);
  3503. if (absV > 0) {
  3504. var options = Splide.options;
  3505. var index = Splide.index;
  3506. var sign = velocity < 0 ? -1 : 1;
  3507. var destIndex = index;
  3508. if (!Splide.is(FADE)) {
  3509. var destination = Track.position;
  3510. if (absV > options.flickVelocityThreshold && drag_abs(info.offset[axis]) < options.swipeDistanceThreshold) {
  3511. destination += sign * Math.min(absV * options.flickPower, Components.Layout.size * (options.flickMaxPages || 1));
  3512. }
  3513. destIndex = Track.toIndex(destination);
  3514. }
  3515. /*
  3516. * Do not allow the track to go to a previous position if there is enough velocity.
  3517. * Always use the adjacent index for the fade mode.
  3518. */
  3519. if (destIndex === index && absV > MIN_VELOCITY) {
  3520. destIndex = index + sign * Track.sign;
  3521. }
  3522. if (Splide.is(SLIDE)) {
  3523. destIndex = between(destIndex, 0, Controller.edgeIndex);
  3524. }
  3525. Controller.go(destIndex, options.isNavigation);
  3526. }
  3527. }
  3528. /**
  3529. * Analyze the given event object and return important information for handling swipe behavior.
  3530. *
  3531. * @param {Event} e - Touch or Mouse event object.
  3532. * @param {Object} startInfo - Information analyzed on start for calculating difference from the current one.
  3533. *
  3534. * @return {Object} - An object containing analyzed information, such as offset, velocity, etc.
  3535. */
  3536. function analyze(e, startInfo) {
  3537. var timeStamp = e.timeStamp,
  3538. touches = e.touches;
  3539. var _ref2 = touches ? touches[0] : e,
  3540. clientX = _ref2.clientX,
  3541. clientY = _ref2.clientY;
  3542. var _ref3 = startInfo.to || {},
  3543. _ref3$x = _ref3.x,
  3544. fromX = _ref3$x === void 0 ? clientX : _ref3$x,
  3545. _ref3$y = _ref3.y,
  3546. fromY = _ref3$y === void 0 ? clientY : _ref3$y;
  3547. var startTime = startInfo.time || 0;
  3548. var offset = {
  3549. x: clientX - fromX,
  3550. y: clientY - fromY
  3551. };
  3552. var duration = timeStamp - startTime;
  3553. var velocity = {
  3554. x: offset.x / duration,
  3555. y: offset.y / duration
  3556. };
  3557. return {
  3558. to: {
  3559. x: clientX,
  3560. y: clientY
  3561. },
  3562. offset: offset,
  3563. time: timeStamp,
  3564. velocity: velocity
  3565. };
  3566. }
  3567. return Drag;
  3568. });
  3569. // CONCATENATED MODULE: ./src/js/components/click/index.js
  3570. /**
  3571. * The component for handling a click event.
  3572. *
  3573. * @author Naotoshi Fujita
  3574. * @copyright Naotoshi Fujita. All rights reserved.
  3575. */
  3576. /**
  3577. * The component for handling a click event.
  3578. * Click should be disabled during drag/swipe.
  3579. *
  3580. * @param {Splide} Splide - A Splide instance.
  3581. * @param {Object} Components - An object containing components.
  3582. *
  3583. * @return {Object} - The component object.
  3584. */
  3585. /* harmony default export */ const click = (function (Splide, Components) {
  3586. /**
  3587. * Whether click is disabled or not.
  3588. *
  3589. * @type {boolean}
  3590. */
  3591. var disabled = false;
  3592. /**
  3593. * Click component object.
  3594. *
  3595. * @type {Object}
  3596. */
  3597. var Click = {
  3598. /**
  3599. * Mount only when the drag is activated and the slide type is not "fade".
  3600. *
  3601. * @type {boolean}
  3602. */
  3603. required: Splide.options.drag,
  3604. /**
  3605. * Called when the component is mounted.
  3606. */
  3607. mount: function mount() {
  3608. Splide.on('click', onClick, Components.Elements.track, {
  3609. capture: true
  3610. }).on('drag', function () {
  3611. disabled = true;
  3612. }).on('dragged', function () {
  3613. disabled = false;
  3614. });
  3615. }
  3616. };
  3617. /**
  3618. * Called when a track element is clicked.
  3619. *
  3620. * @param {Event} e - A click event.
  3621. */
  3622. function onClick(e) {
  3623. if (disabled) {
  3624. e.preventDefault();
  3625. e.stopPropagation();
  3626. e.stopImmediatePropagation();
  3627. }
  3628. }
  3629. return Click;
  3630. });
  3631. // CONCATENATED MODULE: ./src/js/components/autoplay/index.js
  3632. /**
  3633. * The component for playing slides automatically.
  3634. *
  3635. * @author Naotoshi Fujita
  3636. * @copyright Naotoshi Fujita. All rights reserved.
  3637. */
  3638. ;
  3639. /**
  3640. * Set of pause flags.
  3641. */
  3642. var PAUSE_FLAGS = {
  3643. HOVER: 1,
  3644. FOCUS: 2,
  3645. MANUAL: 3
  3646. };
  3647. /**
  3648. * The component for playing slides automatically.
  3649. *
  3650. * @param {Splide} Splide - A Splide instance.
  3651. * @param {Object} Components - An object containing components.
  3652. * @param {string} name - A component name as a lowercase string.
  3653. *
  3654. * @return {Object} - The component object.
  3655. */
  3656. /* harmony default export */ const autoplay = (function (Splide, Components, name) {
  3657. /**
  3658. * Store pause flags.
  3659. *
  3660. * @type {Array}
  3661. */
  3662. var flags = [];
  3663. /**
  3664. * Store an interval object.
  3665. *
  3666. * @type {Object};
  3667. */
  3668. var interval;
  3669. /**
  3670. * Keep the Elements component.
  3671. *
  3672. * @type {string}
  3673. */
  3674. var Elements = Components.Elements;
  3675. /**
  3676. * Autoplay component object.
  3677. *
  3678. * @type {Object}
  3679. */
  3680. var Autoplay = {
  3681. /**
  3682. * Required only when the autoplay option is true.
  3683. *
  3684. * @type {boolean}
  3685. */
  3686. required: Splide.options.autoplay,
  3687. /**
  3688. * Called when the component is mounted.
  3689. * Note that autoplay starts only if there are slides over perPage number.
  3690. */
  3691. mount: function mount() {
  3692. var options = Splide.options;
  3693. if (Elements.slides.length > options.perPage) {
  3694. interval = createInterval(function () {
  3695. Splide.go('>');
  3696. }, options.interval, function (rate) {
  3697. Splide.emit(name + ":playing", rate);
  3698. if (Elements.bar) {
  3699. applyStyle(Elements.bar, {
  3700. width: rate * 100 + "%"
  3701. });
  3702. }
  3703. });
  3704. bind();
  3705. this.play();
  3706. }
  3707. },
  3708. /**
  3709. * Start autoplay.
  3710. *
  3711. * @param {number} flag - A pause flag to be removed.
  3712. */
  3713. play: function play(flag) {
  3714. if (flag === void 0) {
  3715. flag = 0;
  3716. }
  3717. flags = flags.filter(function (f) {
  3718. return f !== flag;
  3719. });
  3720. if (!flags.length) {
  3721. Splide.emit(name + ":play");
  3722. interval.play(Splide.options.resetProgress);
  3723. }
  3724. },
  3725. /**
  3726. * Pause autoplay.
  3727. * Note that Array.includes is not supported by IE.
  3728. *
  3729. * @param {number} flag - A pause flag to be added.
  3730. */
  3731. pause: function pause(flag) {
  3732. if (flag === void 0) {
  3733. flag = 0;
  3734. }
  3735. interval.pause();
  3736. if (flags.indexOf(flag) === -1) {
  3737. flags.push(flag);
  3738. }
  3739. if (flags.length === 1) {
  3740. Splide.emit(name + ":pause");
  3741. }
  3742. }
  3743. };
  3744. /**
  3745. * Listen some events.
  3746. */
  3747. function bind() {
  3748. var options = Splide.options;
  3749. var sibling = Splide.sibling;
  3750. var elms = [Splide.root, sibling ? sibling.root : null];
  3751. if (options.pauseOnHover) {
  3752. switchOn(elms, 'mouseleave', PAUSE_FLAGS.HOVER, true);
  3753. switchOn(elms, 'mouseenter', PAUSE_FLAGS.HOVER, false);
  3754. }
  3755. if (options.pauseOnFocus) {
  3756. switchOn(elms, 'focusout', PAUSE_FLAGS.FOCUS, true);
  3757. switchOn(elms, 'focusin', PAUSE_FLAGS.FOCUS, false);
  3758. }
  3759. if (Elements.play) {
  3760. Splide.on('click', function () {
  3761. // Need to be removed a focus flag at first.
  3762. Autoplay.play(PAUSE_FLAGS.FOCUS);
  3763. Autoplay.play(PAUSE_FLAGS.MANUAL);
  3764. }, Elements.play);
  3765. }
  3766. if (Elements.pause) {
  3767. switchOn([Elements.pause], 'click', PAUSE_FLAGS.MANUAL, false);
  3768. }
  3769. Splide.on('move refresh', function () {
  3770. Autoplay.play();
  3771. }) // Rewind the timer.
  3772. .on('destroy', function () {
  3773. Autoplay.pause();
  3774. });
  3775. }
  3776. /**
  3777. * Play or pause on the given event.
  3778. *
  3779. * @param {Element[]} elms - Elements.
  3780. * @param {string} event - An event name or names.
  3781. * @param {number} flag - A pause flag defined on the top.
  3782. * @param {boolean} play - Determine whether to play or pause.
  3783. */
  3784. function switchOn(elms, event, flag, play) {
  3785. elms.forEach(function (elm) {
  3786. Splide.on(event, function () {
  3787. Autoplay[play ? 'play' : 'pause'](flag);
  3788. }, elm);
  3789. });
  3790. }
  3791. return Autoplay;
  3792. });
  3793. // CONCATENATED MODULE: ./src/js/components/cover/index.js
  3794. /**
  3795. * The component for change an img element to background image of its wrapper.
  3796. *
  3797. * @author Naotoshi Fujita
  3798. * @copyright Naotoshi Fujita. All rights reserved.
  3799. */
  3800. ;
  3801. /**
  3802. * The component for change an img element to background image of its wrapper.
  3803. *
  3804. * @param {Splide} Splide - A Splide instance.
  3805. * @param {Object} Components - An object containing components.
  3806. *
  3807. * @return {Object} - The component object.
  3808. */
  3809. /* harmony default export */ const cover = (function (Splide, Components) {
  3810. /**
  3811. * Hold options.
  3812. *
  3813. * @type {Object}
  3814. */
  3815. var options = Splide.options;
  3816. /**
  3817. * Cover component object.
  3818. *
  3819. * @type {Object}
  3820. */
  3821. var Cover = {
  3822. /**
  3823. * Required only when "cover" option is true.
  3824. *
  3825. * @type {boolean}
  3826. */
  3827. required: options.cover,
  3828. /**
  3829. * Called when the component is mounted.
  3830. */
  3831. mount: function mount() {
  3832. Splide.on('lazyload:loaded', function (img) {
  3833. cover(img, false);
  3834. });
  3835. Splide.on('mounted updated refresh', function () {
  3836. return apply(false);
  3837. });
  3838. },
  3839. /**
  3840. * Destroy.
  3841. */
  3842. destroy: function destroy() {
  3843. apply(true);
  3844. }
  3845. };
  3846. /**
  3847. * Apply "cover" to all slides.
  3848. *
  3849. * @param {boolean} uncover - If true, "cover" will be clear.
  3850. */
  3851. function apply(uncover) {
  3852. Components.Elements.each(function (Slide) {
  3853. var img = child(Slide.slide, 'IMG') || child(Slide.container, 'IMG');
  3854. if (img && img.src) {
  3855. cover(img, uncover);
  3856. }
  3857. });
  3858. }
  3859. /**
  3860. * Set background image of the parent element, using source of the given image element.
  3861. *
  3862. * @param {Element} img - An image element.
  3863. * @param {boolean} uncover - Reset "cover".
  3864. */
  3865. function cover(img, uncover) {
  3866. applyStyle(img.parentElement, {
  3867. background: uncover ? '' : "center/cover no-repeat url(\"" + img.src + "\")"
  3868. });
  3869. applyStyle(img, {
  3870. display: uncover ? '' : 'none'
  3871. });
  3872. }
  3873. return Cover;
  3874. });
  3875. // CONCATENATED MODULE: ./src/js/components/arrows/path.js
  3876. /**
  3877. * Export vector path for an arrow.
  3878. *
  3879. * @author Naotoshi Fujita
  3880. * @copyright Naotoshi Fujita. All rights reserved.
  3881. */
  3882. /**
  3883. * Namespace definition for SVG element.
  3884. *
  3885. * @type {string}
  3886. */
  3887. var XML_NAME_SPACE = 'http://www.w3.org/2000/svg';
  3888. /**
  3889. * The arrow vector path.
  3890. *
  3891. * @type {number}
  3892. */
  3893. 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';
  3894. /**
  3895. * SVG width and height.
  3896. *
  3897. * @type {number}
  3898. */
  3899. var SIZE = 40;
  3900. // CONCATENATED MODULE: ./src/js/components/arrows/index.js
  3901. /**
  3902. * The component for appending prev/next arrows.
  3903. *
  3904. * @author Naotoshi Fujita
  3905. * @copyright Naotoshi Fujita. All rights reserved.
  3906. */
  3907. ;
  3908. /**
  3909. * The component for appending prev/next arrows.
  3910. *
  3911. * @param {Splide} Splide - A Splide instance.
  3912. * @param {Object} Components - An object containing components.
  3913. * @param {string} name - A component name as a lowercase string.
  3914. *
  3915. * @return {Object} - The component object.
  3916. */
  3917. /* harmony default export */ const arrows = (function (Splide, Components, name) {
  3918. /**
  3919. * Previous arrow element.
  3920. *
  3921. * @type {Element|undefined}
  3922. */
  3923. var prev;
  3924. /**
  3925. * Next arrow element.
  3926. *
  3927. * @type {Element|undefined}
  3928. */
  3929. var next;
  3930. /**
  3931. * Store the class list.
  3932. *
  3933. * @type {Object}
  3934. */
  3935. var classes = Splide.classes;
  3936. /**
  3937. * Hold the root element.
  3938. *
  3939. * @type {Element}
  3940. */
  3941. var root = Splide.root;
  3942. /**
  3943. * Whether arrows are created programmatically or not.
  3944. *
  3945. * @type {boolean}
  3946. */
  3947. var created;
  3948. /**
  3949. * Hold the Elements component.
  3950. *
  3951. * @type {Object}
  3952. */
  3953. var Elements = Components.Elements;
  3954. /**
  3955. * Arrows component object.
  3956. *
  3957. * @type {Object}
  3958. */
  3959. var Arrows = {
  3960. /**
  3961. * Required when the arrows option is true.
  3962. *
  3963. * @type {boolean}
  3964. */
  3965. required: Splide.options.arrows,
  3966. /**
  3967. * Called when the component is mounted.
  3968. */
  3969. mount: function mount() {
  3970. // Attempt to get arrows from HTML source.
  3971. prev = Elements.arrows.prev;
  3972. next = Elements.arrows.next; // If arrows were not found in HTML, let's generate them.
  3973. if ((!prev || !next) && Splide.options.arrows) {
  3974. prev = createArrow(true);
  3975. next = createArrow(false);
  3976. created = true;
  3977. appendArrows();
  3978. }
  3979. if (prev && next) {
  3980. bind();
  3981. }
  3982. this.arrows = {
  3983. prev: prev,
  3984. next: next
  3985. };
  3986. },
  3987. /**
  3988. * Called after all components are mounted.
  3989. */
  3990. mounted: function mounted() {
  3991. Splide.emit(name + ":mounted", prev, next);
  3992. },
  3993. /**
  3994. * Destroy.
  3995. */
  3996. destroy: function destroy() {
  3997. removeAttribute([prev, next], 'disabled');
  3998. if (created) {
  3999. dom_remove(prev.parentElement);
  4000. }
  4001. }
  4002. };
  4003. /**
  4004. * Listen to native and custom events.
  4005. */
  4006. function bind() {
  4007. Splide.on('click', function () {
  4008. Splide.go('<');
  4009. }, prev).on('click', function () {
  4010. Splide.go('>');
  4011. }, next).on('mounted move updated refresh', updateDisabled);
  4012. }
  4013. /**
  4014. * Update a disabled attribute.
  4015. */
  4016. function updateDisabled() {
  4017. var _Components$Controlle = Components.Controller,
  4018. prevIndex = _Components$Controlle.prevIndex,
  4019. nextIndex = _Components$Controlle.nextIndex;
  4020. var isEnough = Splide.length > Splide.options.perPage || Splide.is(LOOP);
  4021. prev.disabled = prevIndex < 0 || !isEnough;
  4022. next.disabled = nextIndex < 0 || !isEnough;
  4023. Splide.emit(name + ":updated", prev, next, prevIndex, nextIndex);
  4024. }
  4025. /**
  4026. * Create a wrapper element and append arrows.
  4027. */
  4028. function appendArrows() {
  4029. var wrapper = create('div', {
  4030. "class": classes.arrows
  4031. });
  4032. append(wrapper, prev);
  4033. append(wrapper, next);
  4034. var slider = Elements.slider;
  4035. var parent = Splide.options.arrows === 'slider' && slider ? slider : root;
  4036. before(wrapper, parent.firstElementChild);
  4037. }
  4038. /**
  4039. * Create an arrow element.
  4040. *
  4041. * @param {boolean} prev - Determine to create a prev arrow or next arrow.
  4042. *
  4043. * @return {Element} - A created arrow element.
  4044. */
  4045. function createArrow(prev) {
  4046. 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) + "\" />");
  4047. return domify(arrow);
  4048. }
  4049. return Arrows;
  4050. });
  4051. // CONCATENATED MODULE: ./src/js/components/pagination/index.js
  4052. /**
  4053. * The component for handling pagination
  4054. *
  4055. * @author Naotoshi Fujita
  4056. * @copyright Naotoshi Fujita. All rights reserved.
  4057. */
  4058. ;
  4059. /**
  4060. * The event name for updating some attributes of pagination nodes.
  4061. *
  4062. * @type {string}
  4063. */
  4064. var ATTRIBUTES_UPDATE_EVENT = 'move.page';
  4065. /**
  4066. * The event name for recreating pagination.
  4067. *
  4068. * @type {string}
  4069. */
  4070. var UPDATE_EVENT = 'updated.page refresh.page';
  4071. /**
  4072. * The component for handling pagination
  4073. *
  4074. * @param {Splide} Splide - A Splide instance.
  4075. * @param {Object} Components - An object containing components.
  4076. * @param {string} name - A component name as a lowercase string.
  4077. *
  4078. * @return {Object} - The component object.
  4079. */
  4080. /* harmony default export */ const pagination = (function (Splide, Components, name) {
  4081. /**
  4082. * Store all data for pagination.
  4083. * - list: A list element.
  4084. * - items: An array that contains objects(li, button, index, page).
  4085. *
  4086. * @type {Object}
  4087. */
  4088. var data = {};
  4089. /**
  4090. * Hold the Elements component.
  4091. *
  4092. * @type {Object}
  4093. */
  4094. var Elements = Components.Elements;
  4095. /**
  4096. * Pagination component object.
  4097. *
  4098. * @type {Object}
  4099. */
  4100. var Pagination = {
  4101. /**
  4102. * Called when the component is mounted.
  4103. */
  4104. mount: function mount() {
  4105. var pagination = Splide.options.pagination;
  4106. if (pagination) {
  4107. data = createPagination();
  4108. var slider = Elements.slider;
  4109. var parent = pagination === 'slider' && slider ? slider : Splide.root;
  4110. append(parent, data.list);
  4111. Splide.on(ATTRIBUTES_UPDATE_EVENT, updateAttributes);
  4112. }
  4113. Splide.off(UPDATE_EVENT).on(UPDATE_EVENT, function () {
  4114. Pagination.destroy();
  4115. if (Splide.options.pagination) {
  4116. Pagination.mount();
  4117. Pagination.mounted();
  4118. }
  4119. });
  4120. },
  4121. /**
  4122. * Called after all components are mounted.
  4123. */
  4124. mounted: function mounted() {
  4125. if (Splide.options.pagination) {
  4126. var index = Splide.index;
  4127. Splide.emit(name + ":mounted", data, this.getItem(index));
  4128. updateAttributes(index, -1);
  4129. }
  4130. },
  4131. /**
  4132. * Destroy the pagination.
  4133. * Be aware that node.remove() is not supported by IE.
  4134. */
  4135. destroy: function destroy() {
  4136. dom_remove(data.list);
  4137. if (data.items) {
  4138. data.items.forEach(function (item) {
  4139. Splide.off('click', item.button);
  4140. });
  4141. } // Do not remove UPDATE_EVENT to recreate pagination if needed.
  4142. Splide.off(ATTRIBUTES_UPDATE_EVENT);
  4143. data = {};
  4144. },
  4145. /**
  4146. * Return an item by index.
  4147. *
  4148. * @param {number} index - A slide index.
  4149. *
  4150. * @return {Object|undefined} - An item object on success or undefined on failure.
  4151. */
  4152. getItem: function getItem(index) {
  4153. return data.items[Components.Controller.toPage(index)];
  4154. },
  4155. /**
  4156. * Return object containing pagination data.
  4157. *
  4158. * @return {Object} - Pagination data including list and items.
  4159. */
  4160. get data() {
  4161. return data;
  4162. }
  4163. };
  4164. /**
  4165. * Update attributes.
  4166. *
  4167. * @param {number} index - Active index.
  4168. * @param {number} prevIndex - Prev index.
  4169. */
  4170. function updateAttributes(index, prevIndex) {
  4171. var prev = Pagination.getItem(prevIndex);
  4172. var curr = Pagination.getItem(index);
  4173. var active = STATUS_CLASSES.active;
  4174. if (prev) {
  4175. removeClass(prev.button, active);
  4176. }
  4177. if (curr) {
  4178. addClass(curr.button, active);
  4179. }
  4180. Splide.emit(name + ":updated", data, prev, curr);
  4181. }
  4182. /**
  4183. * Create a wrapper and button elements.
  4184. *
  4185. * @return {Object} - An object contains all data.
  4186. */
  4187. function createPagination() {
  4188. var options = Splide.options;
  4189. var classes = Splide.classes;
  4190. var list = create('ul', {
  4191. "class": classes.pagination
  4192. });
  4193. var items = Elements.getSlides(false).filter(function (Slide) {
  4194. return options.focus !== false || Slide.index % options.perPage === 0;
  4195. }).map(function (Slide, page) {
  4196. var li = create('li', {});
  4197. var button = create('button', {
  4198. "class": classes.page,
  4199. type: 'button'
  4200. });
  4201. append(li, button);
  4202. append(list, li);
  4203. Splide.on('click', function () {
  4204. Splide.go(">" + page);
  4205. }, button);
  4206. return {
  4207. li: li,
  4208. button: button,
  4209. page: page,
  4210. Slides: Elements.getSlidesByPage(page)
  4211. };
  4212. });
  4213. return {
  4214. list: list,
  4215. items: items
  4216. };
  4217. }
  4218. return Pagination;
  4219. });
  4220. // CONCATENATED MODULE: ./src/js/components/lazyload/index.js
  4221. /**
  4222. * The component for loading slider images lazily.
  4223. *
  4224. * @author Naotoshi Fujita
  4225. * @copyright Naotoshi Fujita. All rights reserved.
  4226. */
  4227. ;
  4228. /**
  4229. * The name for a data attribute of src.
  4230. *
  4231. * @type {string}
  4232. */
  4233. var SRC_DATA_NAME = 'data-splide-lazy';
  4234. /**
  4235. * The name for a data attribute of srcset.
  4236. *
  4237. * @type {string}
  4238. */
  4239. var SRCSET_DATA_NAME = 'data-splide-lazy-srcset';
  4240. /**
  4241. * The component for loading slider images lazily.
  4242. *
  4243. * @param {Splide} Splide - A Splide instance.
  4244. * @param {Object} Components - An object containing components.
  4245. * @param {string} name - A component name as a lowercase string.
  4246. *
  4247. * @return {Object} - The component object.
  4248. */
  4249. /* harmony default export */ const lazyload = (function (Splide, Components, name) {
  4250. /**
  4251. * Next index for sequential loading.
  4252. *
  4253. * @type {number}
  4254. */
  4255. var nextIndex;
  4256. /**
  4257. * Store objects containing an img element and a Slide object.
  4258. *
  4259. * @type {Object[]}
  4260. */
  4261. var images;
  4262. /**
  4263. * Store the options.
  4264. *
  4265. * @type {Object}
  4266. */
  4267. var options = Splide.options;
  4268. /**
  4269. * Whether to load images sequentially or not.
  4270. *
  4271. * @type {boolean}
  4272. */
  4273. var isSequential = options.lazyLoad === 'sequential';
  4274. /**
  4275. * Lazyload component object.
  4276. *
  4277. * @type {Object}
  4278. */
  4279. var Lazyload = {
  4280. /**
  4281. * Mount only when the lazyload option is provided.
  4282. *
  4283. * @type {boolean}
  4284. */
  4285. required: options.lazyLoad,
  4286. /**
  4287. * Called when the component is mounted.
  4288. */
  4289. mount: function mount() {
  4290. Splide.on('mounted refresh', function () {
  4291. init();
  4292. Components.Elements.each(function (Slide) {
  4293. each(Slide.slide.querySelectorAll("[" + SRC_DATA_NAME + "], [" + SRCSET_DATA_NAME + "]"), function (img) {
  4294. if (!img.src && !img.srcset) {
  4295. images.push({
  4296. img: img,
  4297. Slide: Slide
  4298. });
  4299. applyStyle(img, {
  4300. display: 'none'
  4301. });
  4302. }
  4303. });
  4304. });
  4305. if (isSequential) {
  4306. loadNext();
  4307. }
  4308. });
  4309. if (!isSequential) {
  4310. Splide.on("mounted refresh moved." + name, check);
  4311. }
  4312. },
  4313. /**
  4314. * Destroy.
  4315. */
  4316. destroy: init
  4317. };
  4318. /**
  4319. * Initialize parameters.
  4320. */
  4321. function init() {
  4322. images = [];
  4323. nextIndex = 0;
  4324. }
  4325. /**
  4326. * Check how close each image is from the active slide and
  4327. * determine whether to start loading or not, according to the distance.
  4328. *
  4329. * @param {number} index - Current index.
  4330. */
  4331. function check(index) {
  4332. index = isNaN(index) ? Splide.index : index;
  4333. images = images.filter(function (image) {
  4334. if (image.Slide.isWithin(index, options.perPage * (options.preloadPages + 1))) {
  4335. load(image.img, image.Slide);
  4336. return false;
  4337. }
  4338. return true;
  4339. }); // Unbind if all images are loaded.
  4340. if (!images[0]) {
  4341. Splide.off("moved." + name);
  4342. }
  4343. }
  4344. /**
  4345. * Start loading an image.
  4346. * Creating a clone of the image element since setting src attribute directly to it
  4347. * often occurs 'hitch', blocking some other processes of a browser.
  4348. *
  4349. * @param {Element} img - An image element.
  4350. * @param {Object} Slide - A Slide object.
  4351. */
  4352. function load(img, Slide) {
  4353. addClass(Slide.slide, STATUS_CLASSES.loading);
  4354. var spinner = create('span', {
  4355. "class": Splide.classes.spinner
  4356. });
  4357. append(img.parentElement, spinner);
  4358. img.onload = function () {
  4359. loaded(img, spinner, Slide, false);
  4360. };
  4361. img.onerror = function () {
  4362. loaded(img, spinner, Slide, true);
  4363. };
  4364. setAttribute(img, 'srcset', getAttribute(img, SRCSET_DATA_NAME) || '');
  4365. setAttribute(img, 'src', getAttribute(img, SRC_DATA_NAME) || '');
  4366. }
  4367. /**
  4368. * Start loading a next image in images array.
  4369. */
  4370. function loadNext() {
  4371. if (nextIndex < images.length) {
  4372. var image = images[nextIndex];
  4373. load(image.img, image.Slide);
  4374. }
  4375. nextIndex++;
  4376. }
  4377. /**
  4378. * Called just after the image was loaded or loading was aborted by some error.
  4379. *
  4380. * @param {Element} img - An image element.
  4381. * @param {Element} spinner - A spinner element.
  4382. * @param {Object} Slide - A Slide object.
  4383. * @param {boolean} error - True if the image was loaded successfully or false on error.
  4384. */
  4385. function loaded(img, spinner, Slide, error) {
  4386. removeClass(Slide.slide, STATUS_CLASSES.loading);
  4387. if (!error) {
  4388. dom_remove(spinner);
  4389. applyStyle(img, {
  4390. display: ''
  4391. });
  4392. Splide.emit(name + ":loaded", img).emit('resize');
  4393. }
  4394. if (isSequential) {
  4395. loadNext();
  4396. }
  4397. }
  4398. return Lazyload;
  4399. });
  4400. // CONCATENATED MODULE: ./src/js/constants/a11y.js
  4401. /**
  4402. * Export aria attribute names.
  4403. *
  4404. * @author Naotoshi Fujita
  4405. * @copyright Naotoshi Fujita. All rights reserved.
  4406. */
  4407. /**
  4408. * Attribute name for aria-current.
  4409. *
  4410. * @type {string}
  4411. */
  4412. var ARIA_CURRENRT = 'aria-current';
  4413. /**
  4414. * Attribute name for aria-control.
  4415. *
  4416. * @type {string}
  4417. */
  4418. var ARIA_CONTROLS = 'aria-controls';
  4419. /**
  4420. * Attribute name for aria-control.
  4421. *
  4422. * @type {string}
  4423. */
  4424. var ARIA_LABEL = 'aria-label';
  4425. /**
  4426. * Attribute name for aria-labelledby.
  4427. *
  4428. * @type {string}
  4429. */
  4430. var ARIA_LABELLEDBY = 'aria-labelledby';
  4431. /**
  4432. * Attribute name for aria-hidden.
  4433. *
  4434. * @type {string}
  4435. */
  4436. var ARIA_HIDDEN = 'aria-hidden';
  4437. /**
  4438. * Attribute name for tab-index.
  4439. *
  4440. * @type {string}
  4441. */
  4442. var TAB_INDEX = 'tabindex';
  4443. // CONCATENATED MODULE: ./src/js/components/keyboard/index.js
  4444. /**
  4445. * The component for controlling slides via keyboard.
  4446. *
  4447. * @author Naotoshi Fujita
  4448. * @copyright Naotoshi Fujita. All rights reserved.
  4449. */
  4450. ;
  4451. /**
  4452. * Map a key to a slide control.
  4453. *
  4454. * @type {Object}
  4455. */
  4456. var KEY_MAP = {
  4457. ltr: {
  4458. ArrowLeft: '<',
  4459. ArrowRight: '>',
  4460. // For IE.
  4461. Left: '<',
  4462. Right: '>'
  4463. },
  4464. rtl: {
  4465. ArrowLeft: '>',
  4466. ArrowRight: '<',
  4467. // For IE.
  4468. Left: '>',
  4469. Right: '<'
  4470. },
  4471. ttb: {
  4472. ArrowUp: '<',
  4473. ArrowDown: '>',
  4474. // For IE.
  4475. Up: '<',
  4476. Down: '>'
  4477. }
  4478. };
  4479. /**
  4480. * The component for controlling slides via keyboard.
  4481. *
  4482. * @param {Splide} Splide - A Splide instance.
  4483. *
  4484. * @return {Object} - The component object.
  4485. */
  4486. /* harmony default export */ const keyboard = (function (Splide) {
  4487. /**
  4488. * Hold the target element.
  4489. *
  4490. * @type {Element|Document|undefined}
  4491. */
  4492. var target;
  4493. return {
  4494. /**
  4495. * Called when the component is mounted.
  4496. */
  4497. mount: function mount() {
  4498. Splide.on('mounted updated', function () {
  4499. var options = Splide.options;
  4500. var root = Splide.root;
  4501. var map = KEY_MAP[options.direction];
  4502. var keyboard = options.keyboard;
  4503. if (target) {
  4504. Splide.off('keydown', target);
  4505. removeAttribute(root, TAB_INDEX);
  4506. }
  4507. if (keyboard) {
  4508. if (keyboard === 'focused') {
  4509. target = root;
  4510. setAttribute(root, TAB_INDEX, 0);
  4511. } else {
  4512. target = document;
  4513. }
  4514. Splide.on('keydown', function (e) {
  4515. if (map[e.key]) {
  4516. Splide.go(map[e.key]);
  4517. }
  4518. }, target);
  4519. }
  4520. });
  4521. }
  4522. };
  4523. });
  4524. // CONCATENATED MODULE: ./src/js/components/a11y/index.js
  4525. /**
  4526. * The component for enhancing accessibility.
  4527. *
  4528. * @author Naotoshi Fujita
  4529. * @copyright Naotoshi Fujita. All rights reserved.
  4530. */
  4531. ;
  4532. /**
  4533. * The component for enhancing accessibility.
  4534. *
  4535. * @param {Splide} Splide - A Splide instance.
  4536. * @param {Object} Components - An object containing components.
  4537. *
  4538. * @return {Object} - The component object.
  4539. */
  4540. /* harmony default export */ const a11y = (function (Splide, Components) {
  4541. /**
  4542. * Hold a i18n object.
  4543. *
  4544. * @type {Object}
  4545. */
  4546. var i18n = Splide.i18n;
  4547. /**
  4548. * Hold the Elements component.
  4549. *
  4550. * @type {Object}
  4551. */
  4552. var Elements = Components.Elements;
  4553. /**
  4554. * All attributes related with A11y.
  4555. *
  4556. * @type {string[]}
  4557. */
  4558. var allAttributes = [ARIA_HIDDEN, TAB_INDEX, ARIA_CONTROLS, ARIA_LABEL, ARIA_CURRENRT, 'role'];
  4559. /**
  4560. * A11y component object.
  4561. *
  4562. * @type {Object}
  4563. */
  4564. var A11y = {
  4565. /**
  4566. * Required only when the accessibility option is true.
  4567. *
  4568. * @type {boolean}
  4569. */
  4570. required: Splide.options.accessibility,
  4571. /**
  4572. * Called when the component is mounted.
  4573. */
  4574. mount: function mount() {
  4575. Splide.on('visible', function (Slide) {
  4576. updateSlide(Slide.slide, true);
  4577. }).on('hidden', function (Slide) {
  4578. updateSlide(Slide.slide, false);
  4579. }).on('arrows:mounted', initArrows).on('arrows:updated', updateArrows).on('pagination:mounted', initPagination).on('pagination:updated', updatePagination).on('refresh', function () {
  4580. removeAttribute(Components.Clones.clones, allAttributes);
  4581. });
  4582. if (Splide.options.isNavigation) {
  4583. Splide.on('navigation:mounted navigation:updated', initNavigation).on('active', function (Slide) {
  4584. updateNavigation(Slide, true);
  4585. }).on('inactive', function (Slide) {
  4586. updateNavigation(Slide, false);
  4587. });
  4588. }
  4589. initAutoplay();
  4590. },
  4591. /**
  4592. * Destroy.
  4593. */
  4594. destroy: function destroy() {
  4595. var Arrows = Components.Arrows;
  4596. var arrows = Arrows ? Arrows.arrows : {};
  4597. removeAttribute(Elements.slides.concat([arrows.prev, arrows.next, Elements.play, Elements.pause]), allAttributes);
  4598. }
  4599. };
  4600. /**
  4601. * Update slide attributes when it gets visible or hidden.
  4602. *
  4603. * @param {Element} slide - A slide element.
  4604. * @param {Boolean} visible - True when the slide gets visible, or false when hidden.
  4605. */
  4606. function updateSlide(slide, visible) {
  4607. setAttribute(slide, ARIA_HIDDEN, !visible);
  4608. if (Splide.options.slideFocus) {
  4609. setAttribute(slide, TAB_INDEX, visible ? 0 : -1);
  4610. }
  4611. }
  4612. /**
  4613. * Initialize arrows if they are available.
  4614. * Append screen reader elements and add aria-controls attribute.
  4615. *
  4616. * @param {Element} prev - Previous arrow element.
  4617. * @param {Element} next - Next arrow element.
  4618. */
  4619. function initArrows(prev, next) {
  4620. var controls = Elements.track.id;
  4621. setAttribute(prev, ARIA_CONTROLS, controls);
  4622. setAttribute(next, ARIA_CONTROLS, controls);
  4623. }
  4624. /**
  4625. * Update arrow attributes.
  4626. *
  4627. * @param {Element} prev - Previous arrow element.
  4628. * @param {Element} next - Next arrow element.
  4629. * @param {number} prevIndex - Previous slide index or -1 when there is no precede slide.
  4630. * @param {number} nextIndex - Next slide index or -1 when there is no next slide.
  4631. */
  4632. function updateArrows(prev, next, prevIndex, nextIndex) {
  4633. var index = Splide.index;
  4634. var prevLabel = prevIndex > -1 && index < prevIndex ? i18n.last : i18n.prev;
  4635. var nextLabel = nextIndex > -1 && index > nextIndex ? i18n.first : i18n.next;
  4636. setAttribute(prev, ARIA_LABEL, prevLabel);
  4637. setAttribute(next, ARIA_LABEL, nextLabel);
  4638. }
  4639. /**
  4640. * Initialize pagination if it's available.
  4641. * Append a screen reader element and add aria-controls/label attribute to each item.
  4642. *
  4643. * @param {Object} data - Data object containing all items.
  4644. * @param {Object} activeItem - An initial active item.
  4645. */
  4646. function initPagination(data, activeItem) {
  4647. if (activeItem) {
  4648. setAttribute(activeItem.button, ARIA_CURRENRT, true);
  4649. }
  4650. data.items.forEach(function (item) {
  4651. var options = Splide.options;
  4652. var text = options.focus === false && options.perPage > 1 ? i18n.pageX : i18n.slideX;
  4653. var label = sprintf(text, item.page + 1);
  4654. var button = item.button;
  4655. var controls = item.Slides.map(function (Slide) {
  4656. return Slide.slide.id;
  4657. });
  4658. setAttribute(button, ARIA_CONTROLS, controls.join(' '));
  4659. setAttribute(button, ARIA_LABEL, label);
  4660. });
  4661. }
  4662. /**
  4663. * Update pagination attributes.
  4664. *
  4665. * @param {Object} data - Data object containing all items.
  4666. * @param {Element} prev - A previous active element.
  4667. * @param {Element} curr - A current active element.
  4668. */
  4669. function updatePagination(data, prev, curr) {
  4670. if (prev) {
  4671. removeAttribute(prev.button, ARIA_CURRENRT);
  4672. }
  4673. if (curr) {
  4674. setAttribute(curr.button, ARIA_CURRENRT, true);
  4675. }
  4676. }
  4677. /**
  4678. * Initialize autoplay buttons.
  4679. */
  4680. function initAutoplay() {
  4681. ['play', 'pause'].forEach(function (name) {
  4682. var elm = Elements[name];
  4683. if (elm) {
  4684. if (!isButton(elm)) {
  4685. setAttribute(elm, 'role', 'button');
  4686. }
  4687. setAttribute(elm, ARIA_CONTROLS, Elements.track.id);
  4688. setAttribute(elm, ARIA_LABEL, i18n[name]);
  4689. }
  4690. });
  4691. }
  4692. /**
  4693. * Initialize navigation slider.
  4694. * Add button role, aria-label, aria-controls to slide elements and append screen reader text to them.
  4695. *
  4696. * @param {Splide} main - A main Splide instance.
  4697. */
  4698. function initNavigation(main) {
  4699. Elements.each(function (Slide) {
  4700. var slide = Slide.slide;
  4701. var realIndex = Slide.realIndex;
  4702. if (!isButton(slide)) {
  4703. setAttribute(slide, 'role', 'button');
  4704. }
  4705. var slideIndex = realIndex > -1 ? realIndex : Slide.index;
  4706. var label = sprintf(i18n.slideX, slideIndex + 1);
  4707. var mainSlide = main.Components.Elements.getSlide(slideIndex);
  4708. setAttribute(slide, ARIA_LABEL, label);
  4709. if (mainSlide) {
  4710. setAttribute(slide, ARIA_CONTROLS, mainSlide.slide.id);
  4711. }
  4712. });
  4713. }
  4714. /**
  4715. * Update navigation attributes.
  4716. *
  4717. * @param {Object} Slide - A target Slide object.
  4718. * @param {boolean} active - True if the slide is active or false if inactive.
  4719. */
  4720. function updateNavigation(_ref, active) {
  4721. var slide = _ref.slide;
  4722. if (active) {
  4723. setAttribute(slide, ARIA_CURRENRT, true);
  4724. } else {
  4725. removeAttribute(slide, ARIA_CURRENRT);
  4726. }
  4727. }
  4728. /**
  4729. * Check if the given element is button or not.
  4730. *
  4731. * @param {Element} elm - An element to be checked.
  4732. *
  4733. * @return {boolean} - True if the given element is button.
  4734. */
  4735. function isButton(elm) {
  4736. return elm.tagName === 'BUTTON';
  4737. }
  4738. return A11y;
  4739. });
  4740. // CONCATENATED MODULE: ./src/js/components/sync/index.js
  4741. /**
  4742. * The component for synchronizing a slider with another.
  4743. *
  4744. * @author Naotoshi Fujita
  4745. * @copyright Naotoshi Fujita. All rights reserved.
  4746. */
  4747. ;
  4748. /**
  4749. * The event name for sync.
  4750. *
  4751. * @type {string}
  4752. */
  4753. var SYNC_EVENT = 'move.sync';
  4754. /**
  4755. * The event names for click navigation.
  4756. * @type {string}
  4757. */
  4758. var CLICK_EVENTS = 'mouseup touchend';
  4759. /**
  4760. * The keys for triggering the navigation button.
  4761. *
  4762. * @type {String[]}
  4763. */
  4764. var TRIGGER_KEYS = [' ', 'Enter', 'Spacebar'];
  4765. /**
  4766. * The component for synchronizing a slider with another.
  4767. *
  4768. * @param {Splide} Splide - A Splide instance.
  4769. *
  4770. * @return {Object} - The component object.
  4771. */
  4772. /* harmony default export */ const sync = (function (Splide) {
  4773. /**
  4774. * Keep the sibling Splide instance.
  4775. *
  4776. * @type {Splide}
  4777. */
  4778. var sibling = Splide.sibling;
  4779. /**
  4780. * Whether the sibling slider is navigation or not.
  4781. *
  4782. * @type {Splide|boolean}
  4783. */
  4784. var isNavigation = sibling && sibling.options.isNavigation;
  4785. /**
  4786. * Layout component object.
  4787. *
  4788. * @type {Object}
  4789. */
  4790. var Sync = {
  4791. /**
  4792. * Required only when the sub slider is available.
  4793. *
  4794. * @type {boolean}
  4795. */
  4796. required: !!sibling,
  4797. /**
  4798. * Called when the component is mounted.
  4799. */
  4800. mount: function mount() {
  4801. syncMain();
  4802. syncSibling();
  4803. if (isNavigation) {
  4804. bind();
  4805. Splide.on('refresh', function () {
  4806. setTimeout(function () {
  4807. bind();
  4808. sibling.emit('navigation:updated', Splide);
  4809. });
  4810. });
  4811. }
  4812. },
  4813. /**
  4814. * Called after all components are mounted.
  4815. */
  4816. mounted: function mounted() {
  4817. if (isNavigation) {
  4818. sibling.emit('navigation:mounted', Splide);
  4819. }
  4820. }
  4821. };
  4822. /**
  4823. * Listen the primary slider event to move secondary one.
  4824. * Must unbind a handler at first to avoid infinite loop.
  4825. */
  4826. function syncMain() {
  4827. Splide.on(SYNC_EVENT, function (newIndex, prevIndex, destIndex) {
  4828. sibling.off(SYNC_EVENT).go(sibling.is(LOOP) ? destIndex : newIndex, false);
  4829. syncSibling();
  4830. });
  4831. }
  4832. /**
  4833. * Listen the secondary slider event to move primary one.
  4834. * Must unbind a handler at first to avoid infinite loop.
  4835. */
  4836. function syncSibling() {
  4837. sibling.on(SYNC_EVENT, function (newIndex, prevIndex, destIndex) {
  4838. Splide.off(SYNC_EVENT).go(Splide.is(LOOP) ? destIndex : newIndex, false);
  4839. syncMain();
  4840. });
  4841. }
  4842. /**
  4843. * Listen some events on each slide.
  4844. */
  4845. function bind() {
  4846. sibling.Components.Elements.each(function (_ref) {
  4847. var slide = _ref.slide,
  4848. index = _ref.index;
  4849. /*
  4850. * Listen mouseup and touchend events to handle click.
  4851. */
  4852. Splide.off(CLICK_EVENTS, slide).on(CLICK_EVENTS, function (e) {
  4853. // Ignore a middle or right click.
  4854. if (!e.button || e.button === 0) {
  4855. moveSibling(index);
  4856. }
  4857. }, slide);
  4858. /*
  4859. * Subscribe keyup to handle Enter and Space key.
  4860. * Note that Array.includes is not supported by IE.
  4861. */
  4862. Splide.off('keyup', slide).on('keyup', function (e) {
  4863. if (TRIGGER_KEYS.indexOf(e.key) > -1) {
  4864. e.preventDefault();
  4865. moveSibling(index);
  4866. }
  4867. }, slide, {
  4868. passive: false
  4869. });
  4870. });
  4871. }
  4872. /**
  4873. * Move the sibling to the given index.
  4874. * Need to check "IDLE" status because slides can be moving by Drag component.
  4875. *
  4876. * @param {number} index - Target index.
  4877. */
  4878. function moveSibling(index) {
  4879. if (Splide.State.is(IDLE)) {
  4880. sibling.go(index);
  4881. }
  4882. }
  4883. return Sync;
  4884. });
  4885. // CONCATENATED MODULE: ./src/js/components/breakpoints/index.js
  4886. /**
  4887. * The component for updating options according to a current window width.
  4888. *
  4889. * @author Naotoshi Fujita
  4890. * @copyright Naotoshi Fujita. All rights reserved.
  4891. */
  4892. ;
  4893. /**
  4894. * Interval time for throttle.
  4895. *
  4896. * @type {number}
  4897. */
  4898. var THROTTLE = 50;
  4899. /**
  4900. * The component for updating options according to a current window width.
  4901. *
  4902. * @param {Splide} Splide - A Splide instance.
  4903. *
  4904. * @return {Object} - The component object.
  4905. */
  4906. /* harmony default export */ const breakpoints = (function (Splide) {
  4907. /**
  4908. * Store breakpoints.
  4909. *
  4910. * @type {Object|boolean}
  4911. */
  4912. var breakpoints = Splide.options.breakpoints;
  4913. /**
  4914. * The check function whose frequency of call is reduced.
  4915. *
  4916. * @type {Function}
  4917. */
  4918. var throttledCheck = throttle(check, THROTTLE);
  4919. /**
  4920. * Keep initial options.
  4921. *
  4922. * @type {Object}
  4923. */
  4924. var initialOptions;
  4925. /**
  4926. * An array containing objects of point and MediaQueryList.
  4927. *
  4928. * @type {Object[]}
  4929. */
  4930. var map = [];
  4931. /**
  4932. * Hold the previous breakpoint.
  4933. *
  4934. * @type {number|undefined}
  4935. */
  4936. var prevPoint;
  4937. /**
  4938. * Breakpoints component object.
  4939. *
  4940. * @type {Object}
  4941. */
  4942. var Breakpoints = {
  4943. /**
  4944. * Required only when the breakpoints definition is provided and browser supports matchMedia.
  4945. *
  4946. * @type {boolean}
  4947. */
  4948. required: breakpoints && matchMedia,
  4949. /**
  4950. * Called when the component is mounted.
  4951. */
  4952. mount: function mount() {
  4953. map = Object.keys(breakpoints).sort(function (n, m) {
  4954. return +n - +m;
  4955. }).map(function (point) {
  4956. return {
  4957. point: point,
  4958. mql: matchMedia("(max-width:" + point + "px)")
  4959. };
  4960. });
  4961. /*
  4962. * To keep monitoring resize event after destruction without "completely",
  4963. * use native addEventListener instead of Splide.on.
  4964. */
  4965. this.destroy(true);
  4966. addEventListener('resize', throttledCheck); // Keep initial options to apply them when no breakpoint matches.
  4967. initialOptions = Splide.options;
  4968. check();
  4969. },
  4970. /**
  4971. * Destroy.
  4972. *
  4973. * @param {boolean} completely - Whether to destroy Splide completely.
  4974. */
  4975. destroy: function destroy(completely) {
  4976. if (completely) {
  4977. removeEventListener('resize', throttledCheck);
  4978. }
  4979. }
  4980. };
  4981. /**
  4982. * Check the breakpoint.
  4983. */
  4984. function check() {
  4985. var point = getPoint();
  4986. if (point !== prevPoint) {
  4987. prevPoint = point;
  4988. var State = Splide.State;
  4989. var options = breakpoints[point] || initialOptions;
  4990. var destroy = options.destroy;
  4991. if (destroy) {
  4992. Splide.options = initialOptions;
  4993. Splide.destroy(destroy === 'completely');
  4994. } else {
  4995. if (State.is(DESTROYED)) {
  4996. Splide.mount();
  4997. }
  4998. Splide.options = options;
  4999. }
  5000. }
  5001. }
  5002. /**
  5003. * Return the breakpoint matching current window width.
  5004. * Note that Array.prototype.find is not supported by IE.
  5005. *
  5006. * @return {number|string} - A breakpoint as number or string. -1 if no point matches.
  5007. */
  5008. function getPoint() {
  5009. var item = map.filter(function (item) {
  5010. return item.mql.matches;
  5011. })[0];
  5012. return item ? item.point : -1;
  5013. }
  5014. return Breakpoints;
  5015. });
  5016. // CONCATENATED MODULE: ./src/js/components/index.js
  5017. /**
  5018. * Export components.
  5019. *
  5020. * @author Naotoshi Fujita
  5021. * @copyright Naotoshi Fujita. All rights reserved.
  5022. */
  5023. ;
  5024. var COMPLETE = {
  5025. Options: options,
  5026. Breakpoints: breakpoints,
  5027. Controller: controller,
  5028. Elements: components_elements,
  5029. Track: track,
  5030. Clones: clones,
  5031. Layout: layout,
  5032. Drag: drag,
  5033. Click: click,
  5034. Autoplay: autoplay,
  5035. Cover: cover,
  5036. Arrows: arrows,
  5037. Pagination: pagination,
  5038. LazyLoad: lazyload,
  5039. Keyboard: keyboard,
  5040. Sync: sync,
  5041. A11y: a11y
  5042. };
  5043. var LIGHT = {
  5044. Options: options,
  5045. Controller: controller,
  5046. Elements: components_elements,
  5047. Track: track,
  5048. Clones: clones,
  5049. Layout: layout,
  5050. Drag: drag,
  5051. Click: click,
  5052. Arrows: arrows,
  5053. Pagination: pagination,
  5054. A11y: a11y
  5055. };
  5056. // CONCATENATED MODULE: ./build/module/module.js
  5057. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
  5058. /**
  5059. * Export Splide class for import.
  5060. *
  5061. * @author Naotoshi Fujita
  5062. * @copyright Naotoshi Fujita. All rights reserved.
  5063. */
  5064. /**
  5065. * Export Splide class for import from other projects.
  5066. */
  5067. var module_Splide = /*#__PURE__*/function (_Core) {
  5068. _inheritsLoose(Splide, _Core);
  5069. function Splide(root, options) {
  5070. return _Core.call(this, root, options, COMPLETE) || this;
  5071. }
  5072. return Splide;
  5073. }(Splide);
  5074. /***/ })
  5075. /******/ });
  5076. /************************************************************************/
  5077. /******/ // The module cache
  5078. /******/ var __webpack_module_cache__ = {};
  5079. /******/
  5080. /******/ // The require function
  5081. /******/ function __webpack_require__(moduleId) {
  5082. /******/ // Check if module is in cache
  5083. /******/ if(__webpack_module_cache__[moduleId]) {
  5084. /******/ return __webpack_module_cache__[moduleId].exports;
  5085. /******/ }
  5086. /******/ // Create a new module (and put it into the cache)
  5087. /******/ var module = __webpack_module_cache__[moduleId] = {
  5088. /******/ // no module.id needed
  5089. /******/ // no module.loaded needed
  5090. /******/ exports: {}
  5091. /******/ };
  5092. /******/
  5093. /******/ // Execute the module function
  5094. /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
  5095. /******/
  5096. /******/ // Return the exports of the module
  5097. /******/ return module.exports;
  5098. /******/ }
  5099. /******/
  5100. /************************************************************************/
  5101. /******/ /* webpack/runtime/define property getters */
  5102. /******/ (() => {
  5103. /******/ // define getter functions for harmony exports
  5104. /******/ __webpack_require__.d = (exports, definition) => {
  5105. /******/ for(var key in definition) {
  5106. /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
  5107. /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
  5108. /******/ }
  5109. /******/ }
  5110. /******/ };
  5111. /******/ })();
  5112. /******/
  5113. /******/ /* webpack/runtime/hasOwnProperty shorthand */
  5114. /******/ (() => {
  5115. /******/ __webpack_require__.o = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop)
  5116. /******/ })();
  5117. /******/
  5118. /******/ /* webpack/runtime/make namespace object */
  5119. /******/ (() => {
  5120. /******/ // define __esModule on exports
  5121. /******/ __webpack_require__.r = (exports) => {
  5122. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  5123. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  5124. /******/ }
  5125. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  5126. /******/ };
  5127. /******/ })();
  5128. /******/
  5129. /************************************************************************/
  5130. /******/ // module exports must be returned from runtime so entry inlining is disabled
  5131. /******/ // startup
  5132. /******/ // Load entry module and return exports
  5133. /******/ return __webpack_require__(311);
  5134. /******/ })()
  5135. ;
  5136. });