splide.esm.js 136 KB

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