splide.js 136 KB

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