splide.esm.js 136 KB

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