splide.js 134 KB

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