splide.esm.js 136 KB

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