splide.js 124 KB

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