splide.cjs.js 78 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833
  1. /*!
  2. * Splide.js
  3. * Version : 3.0.2
  4. * License : MIT
  5. * Copyright: 2021 Naotoshi Fujita
  6. */
  7. 'use strict';
  8. Object.defineProperty(exports, '__esModule', { value: true });
  9. const PROJECT_CODE = "splide";
  10. const DATA_ATTRIBUTE = `data-${PROJECT_CODE}`;
  11. const CREATED = 1;
  12. const MOUNTED = 2;
  13. const IDLE = 3;
  14. const MOVING = 4;
  15. const DESTROYED = 5;
  16. const STATES = {
  17. CREATED,
  18. MOUNTED,
  19. IDLE,
  20. MOVING,
  21. DESTROYED
  22. };
  23. const DEFAULT_EVENT_PRIORITY = 10;
  24. const DEFAULT_USER_EVENT_PRIORITY = 20;
  25. function empty(array) {
  26. array.length = 0;
  27. }
  28. function isObject(subject) {
  29. return !isNull(subject) && typeof subject === "object";
  30. }
  31. function isArray(subject) {
  32. return Array.isArray(subject);
  33. }
  34. function isFunction(subject) {
  35. return typeof subject === "function";
  36. }
  37. function isString(subject) {
  38. return typeof subject === "string";
  39. }
  40. function isUndefined(subject) {
  41. return typeof subject === "undefined";
  42. }
  43. function isNull(subject) {
  44. return subject === null;
  45. }
  46. function isHTMLElement(subject) {
  47. return subject instanceof HTMLElement;
  48. }
  49. function toArray(value) {
  50. return isArray(value) ? value : [value];
  51. }
  52. function forEach(values, iteratee) {
  53. toArray(values).forEach(iteratee);
  54. }
  55. function includes(array, value) {
  56. return array.indexOf(value) > -1;
  57. }
  58. function push(array, items) {
  59. array.push(...toArray(items));
  60. return array;
  61. }
  62. const arrayProto = Array.prototype;
  63. function slice(arrayLike, start, end) {
  64. return arrayProto.slice.call(arrayLike, start, end);
  65. }
  66. function find(arrayLike, predicate) {
  67. return slice(arrayLike).filter(predicate)[0];
  68. }
  69. function toggleClass(elm, classes, add) {
  70. if (elm) {
  71. forEach(classes, (name) => {
  72. if (name) {
  73. elm.classList[add ? "add" : "remove"](name);
  74. }
  75. });
  76. }
  77. }
  78. function addClass(elm, classes) {
  79. toggleClass(elm, isString(classes) ? classes.split(" ") : classes, true);
  80. }
  81. function append(parent, children) {
  82. forEach(children, parent.appendChild.bind(parent));
  83. }
  84. function before(nodes, ref) {
  85. forEach(nodes, (node) => {
  86. const parent = ref.parentNode;
  87. if (parent) {
  88. parent.insertBefore(node, ref);
  89. }
  90. });
  91. }
  92. function matches(elm, selector) {
  93. return (elm["msMatchesSelector"] || elm.matches).call(elm, selector);
  94. }
  95. function children(parent, selector) {
  96. return parent ? slice(parent.children).filter((child) => matches(child, selector)) : [];
  97. }
  98. function child(parent, selector) {
  99. return selector ? children(parent, selector)[0] : parent.firstElementChild;
  100. }
  101. function forOwn(object, iteratee) {
  102. if (object) {
  103. const keys = Object.keys(object);
  104. for (let i = 0; i < keys.length; i++) {
  105. const key = keys[i];
  106. if (key !== "__proto__") {
  107. if (iteratee(object[key], key) === false) {
  108. break;
  109. }
  110. }
  111. }
  112. }
  113. return object;
  114. }
  115. function assign(object) {
  116. slice(arguments, 1).forEach((source) => {
  117. forOwn(source, (value, key) => {
  118. object[key] = source[key];
  119. });
  120. });
  121. return object;
  122. }
  123. function merge(object, source) {
  124. forOwn(source, (value, key) => {
  125. if (isArray(value)) {
  126. object[key] = value.slice();
  127. } else if (isObject(value)) {
  128. object[key] = merge(isObject(object[key]) ? object[key] : {}, value);
  129. } else {
  130. object[key] = value;
  131. }
  132. });
  133. return object;
  134. }
  135. function removeAttribute(elm, attrs) {
  136. if (elm) {
  137. forEach(attrs, (attr) => {
  138. elm.removeAttribute(attr);
  139. });
  140. }
  141. }
  142. function setAttribute(elm, attrs, value) {
  143. if (isObject(attrs)) {
  144. forOwn(attrs, (value2, name) => {
  145. setAttribute(elm, name, value2);
  146. });
  147. } else {
  148. isNull(value) ? removeAttribute(elm, attrs) : elm.setAttribute(attrs, String(value));
  149. }
  150. }
  151. function create(tag, attrs, parent) {
  152. const elm = document.createElement(tag);
  153. if (attrs) {
  154. isString(attrs) ? addClass(elm, attrs) : setAttribute(elm, attrs);
  155. }
  156. parent && append(parent, elm);
  157. return elm;
  158. }
  159. function style(elm, styles) {
  160. if (isString(styles)) {
  161. return getComputedStyle(elm)[styles];
  162. }
  163. forOwn(styles, (value, key) => {
  164. if (!isNull(value)) {
  165. elm.style[key] = `${value}`;
  166. }
  167. });
  168. }
  169. function display(elm, display2) {
  170. style(elm, { display: display2 });
  171. }
  172. function getAttribute(elm, attr) {
  173. return elm.getAttribute(attr);
  174. }
  175. function hasClass(elm, className) {
  176. return elm && elm.classList.contains(className);
  177. }
  178. function rect(target) {
  179. return target.getBoundingClientRect();
  180. }
  181. function remove(nodes) {
  182. forEach(nodes, (node) => {
  183. if (node && node.parentNode) {
  184. node.parentNode.removeChild(node);
  185. }
  186. });
  187. }
  188. function measure(parent, value) {
  189. if (isString(value)) {
  190. const div = create("div", { style: `width: ${value}; position: absolute;` }, parent);
  191. value = rect(div).width;
  192. remove(div);
  193. }
  194. return value;
  195. }
  196. function parseHtml(html) {
  197. return child(new DOMParser().parseFromString(html, "text/html").body);
  198. }
  199. function prevent(e, stopPropagation) {
  200. e.preventDefault();
  201. if (stopPropagation) {
  202. e.stopPropagation();
  203. e.stopImmediatePropagation();
  204. }
  205. }
  206. function query(parent, selector) {
  207. return parent && parent.querySelector(selector);
  208. }
  209. function queryAll(parent, selector) {
  210. return slice(parent.querySelectorAll(selector));
  211. }
  212. function removeClass(elm, classes) {
  213. toggleClass(elm, classes, false);
  214. }
  215. function unit(value) {
  216. return isString(value) ? value : value ? `${value}px` : "";
  217. }
  218. function assert(condition, message = "") {
  219. if (!condition) {
  220. throw new Error(`[${PROJECT_CODE}] ${message}`);
  221. }
  222. }
  223. function nextTick(callback) {
  224. setTimeout(callback);
  225. }
  226. const noop = () => {
  227. };
  228. function raf(func) {
  229. return requestAnimationFrame(func);
  230. }
  231. const { min, max, floor, ceil, abs } = Math;
  232. function approximatelyEqual(x, y, epsilon) {
  233. return abs(x - y) < epsilon;
  234. }
  235. function between(number, minOrMax, maxOrMin, exclusive) {
  236. const minimum = min(minOrMax, maxOrMin);
  237. const maximum = max(minOrMax, maxOrMin);
  238. return exclusive ? minimum < number && number < maximum : minimum <= number && number <= maximum;
  239. }
  240. function clamp(number, x, y) {
  241. const minimum = min(x, y);
  242. const maximum = max(x, y);
  243. return min(max(minimum, number), maximum);
  244. }
  245. function sign(x) {
  246. return +(x > 0) - +(x < 0);
  247. }
  248. function camelToKebab(string) {
  249. return string.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
  250. }
  251. function format(string, replacements) {
  252. forEach(replacements, (replacement) => {
  253. string = string.replace("%s", `${replacement}`);
  254. });
  255. return string;
  256. }
  257. function pad(number) {
  258. return number < 10 ? `0${number}` : `${number}`;
  259. }
  260. const ids = {};
  261. function uniqueId(prefix) {
  262. return `${prefix}${pad(ids[prefix] = (ids[prefix] || 0) + 1)}`;
  263. }
  264. function EventBus() {
  265. let handlers = {};
  266. function on(events, callback, key, priority = DEFAULT_EVENT_PRIORITY) {
  267. forEachEvent(events, (event, namespace) => {
  268. handlers[event] = handlers[event] || [];
  269. push(handlers[event], {
  270. _event: event,
  271. _callback: callback,
  272. _namespace: namespace,
  273. _priority: priority,
  274. _key: key
  275. }).sort((handler1, handler2) => handler1._priority - handler2._priority);
  276. });
  277. }
  278. function off(events, key) {
  279. forEachEvent(events, (event, namespace) => {
  280. const eventHandlers = handlers[event];
  281. handlers[event] = eventHandlers && eventHandlers.filter((handler) => {
  282. return handler._key ? handler._key !== key : handler._namespace !== namespace;
  283. });
  284. });
  285. }
  286. function offBy(key) {
  287. forOwn(handlers, (eventHandlers, event) => {
  288. off(event, key);
  289. });
  290. }
  291. function emit(event) {
  292. (handlers[event] || []).forEach((handler) => {
  293. handler._callback.apply(handler, slice(arguments, 1));
  294. });
  295. }
  296. function destroy() {
  297. handlers = {};
  298. }
  299. function forEachEvent(events, iteratee) {
  300. toArray(events).join(" ").split(" ").forEach((eventNS) => {
  301. const fragments = eventNS.split(".");
  302. iteratee(fragments[0], fragments[1]);
  303. });
  304. }
  305. return {
  306. on,
  307. off,
  308. offBy,
  309. emit,
  310. destroy
  311. };
  312. }
  313. const EVENT_MOUNTED = "mounted";
  314. const EVENT_READY = "ready";
  315. const EVENT_MOVE = "move";
  316. const EVENT_MOVED = "moved";
  317. const EVENT_CLICK = "click";
  318. const EVENT_ACTIVE = "active";
  319. const EVENT_INACTIVE = "inactive";
  320. const EVENT_VISIBLE = "visible";
  321. const EVENT_HIDDEN = "hidden";
  322. const EVENT_SLIDE_KEYDOWN = "slide:keydown";
  323. const EVENT_REFRESH = "refresh";
  324. const EVENT_UPDATED = "updated";
  325. const EVENT_RESIZE = "resize";
  326. const EVENT_RESIZED = "resized";
  327. const EVENT_REPOSITIONED = "repositioned";
  328. const EVENT_DRAG = "drag";
  329. const EVENT_DRAGGING = "dragging";
  330. const EVENT_DRAGGED = "dragged";
  331. const EVENT_SCROLL = "scroll";
  332. const EVENT_SCROLLED = "scrolled";
  333. const EVENT_DESTROY = "destroy";
  334. const EVENT_ARROWS_MOUNTED = "arrows:mounted";
  335. const EVENT_ARROWS_UPDATED = "arrows:updated";
  336. const EVENT_PAGINATION_MOUNTED = "pagination:mounted";
  337. const EVENT_PAGINATION_UPDATED = "pagination:updated";
  338. const EVENT_NAVIGATION_MOUNTED = "navigation:mounted";
  339. const EVENT_AUTOPLAY_PLAY = "autoplay:play";
  340. const EVENT_AUTOPLAY_PLAYING = "autoplay:playing";
  341. const EVENT_AUTOPLAY_PAUSE = "autoplay:pause";
  342. const EVENT_LAZYLOAD_LOADED = "lazyload:loaded";
  343. function EventInterface(Splide2) {
  344. const { event } = Splide2;
  345. const key = {};
  346. let listeners = [];
  347. function on(events, callback, priority) {
  348. event.on(events, callback, key, priority);
  349. }
  350. function off(events) {
  351. event.off(events, key);
  352. }
  353. function bind(targets, events, callback, options) {
  354. forEachEvent(targets, events, (target, event2) => {
  355. listeners.push([target, event2, callback, options]);
  356. target.addEventListener(event2, callback, options);
  357. });
  358. }
  359. function unbind(targets, events) {
  360. forEachEvent(targets, events, (target, event2) => {
  361. listeners = listeners.filter((listener) => {
  362. if (listener[0] === target && listener[1] === event2) {
  363. target.removeEventListener(event2, listener[2], listener[3]);
  364. return false;
  365. }
  366. return true;
  367. });
  368. });
  369. }
  370. function forEachEvent(targets, events, iteratee) {
  371. forEach(targets, (target) => {
  372. if (target) {
  373. events.split(" ").forEach(iteratee.bind(null, target));
  374. }
  375. });
  376. }
  377. function destroy() {
  378. listeners = listeners.filter((data) => unbind(data[0], data[1]));
  379. event.offBy(key);
  380. }
  381. event.on(EVENT_DESTROY, destroy, key);
  382. return {
  383. on,
  384. off,
  385. emit: event.emit,
  386. bind,
  387. unbind,
  388. destroy
  389. };
  390. }
  391. function RequestInterval(interval, onInterval, onUpdate, limit) {
  392. const { now } = Date;
  393. let startTime;
  394. let rate = 0;
  395. let id;
  396. let paused = true;
  397. let count = 0;
  398. function update() {
  399. if (!paused) {
  400. const elapsed = now() - startTime;
  401. if (elapsed >= interval) {
  402. rate = 1;
  403. startTime = now();
  404. } else {
  405. rate = elapsed / interval;
  406. }
  407. if (onUpdate) {
  408. onUpdate(rate);
  409. }
  410. if (rate === 1) {
  411. onInterval();
  412. if (limit && ++count >= limit) {
  413. return pause();
  414. }
  415. }
  416. raf(update);
  417. }
  418. }
  419. function start(resume) {
  420. !resume && cancel();
  421. startTime = now() - (resume ? rate * interval : 0);
  422. paused = false;
  423. raf(update);
  424. }
  425. function pause() {
  426. paused = true;
  427. }
  428. function rewind() {
  429. startTime = now();
  430. rate = 0;
  431. if (onUpdate) {
  432. onUpdate(rate);
  433. }
  434. }
  435. function cancel() {
  436. cancelAnimationFrame(id);
  437. rate = 0;
  438. id = 0;
  439. paused = true;
  440. }
  441. function isPaused() {
  442. return paused;
  443. }
  444. return {
  445. start,
  446. rewind,
  447. pause,
  448. cancel,
  449. isPaused
  450. };
  451. }
  452. function State(initialState) {
  453. let state = initialState;
  454. function set(value) {
  455. state = value;
  456. }
  457. function is(states) {
  458. return includes(toArray(states), state);
  459. }
  460. return { set, is };
  461. }
  462. function Throttle(func, duration) {
  463. let interval;
  464. function throttled() {
  465. if (!interval) {
  466. interval = RequestInterval(duration || 0, () => {
  467. func.apply(this, arguments);
  468. interval = null;
  469. }, null, 1);
  470. interval.start();
  471. }
  472. }
  473. return throttled;
  474. }
  475. function Options(Splide2, Components2, options) {
  476. const throttledObserve = Throttle(observe);
  477. let initialOptions;
  478. let points;
  479. let currPoint;
  480. function setup() {
  481. try {
  482. merge(options, JSON.parse(getAttribute(Splide2.root, DATA_ATTRIBUTE)));
  483. } catch (e) {
  484. assert(false, e.message);
  485. }
  486. initialOptions = merge({}, options);
  487. const { breakpoints } = options;
  488. if (breakpoints) {
  489. const isMin = options.mediaQuery === "min";
  490. points = Object.keys(breakpoints).sort((n, m) => isMin ? +m - +n : +n - +m).map((point) => [
  491. point,
  492. matchMedia(`(${isMin ? "min" : "max"}-width:${point}px)`)
  493. ]);
  494. observe();
  495. }
  496. }
  497. function mount() {
  498. if (points) {
  499. addEventListener("resize", throttledObserve);
  500. }
  501. }
  502. function destroy(completely) {
  503. if (completely) {
  504. removeEventListener("resize", throttledObserve);
  505. }
  506. }
  507. function observe() {
  508. const item = find(points, (item2) => item2[1].matches) || [];
  509. if (item[0] !== currPoint) {
  510. onMatch(currPoint = item[0]);
  511. }
  512. }
  513. function onMatch(point) {
  514. const newOptions = options.breakpoints[point] || initialOptions;
  515. if (newOptions.destroy) {
  516. Splide2.options = initialOptions;
  517. Splide2.destroy(newOptions.destroy === "completely");
  518. } else {
  519. if (Splide2.state.is(DESTROYED)) {
  520. destroy(true);
  521. Splide2.mount();
  522. }
  523. Splide2.options = newOptions;
  524. }
  525. }
  526. return {
  527. setup,
  528. mount,
  529. destroy
  530. };
  531. }
  532. const RTL = "rtl";
  533. const TTB = "ttb";
  534. const ORIENTATION_MAP = {
  535. marginRight: ["marginBottom", "marginLeft"],
  536. autoWidth: ["autoHeight"],
  537. fixedWidth: ["fixedHeight"],
  538. paddingLeft: ["paddingTop", "paddingRight"],
  539. paddingRight: ["paddingBottom", "paddingLeft"],
  540. width: ["height"],
  541. left: ["top", "right"],
  542. right: ["bottom", "left"],
  543. x: ["y"],
  544. X: ["Y"],
  545. Y: ["X"],
  546. ArrowLeft: ["ArrowUp", "ArrowRight"],
  547. ArrowRight: ["ArrowDown", "ArrowLeft"]
  548. };
  549. function Direction(Splide2, Components2, options) {
  550. function resolve(prop, axisOnly) {
  551. const { direction } = options;
  552. const index = direction === RTL && !axisOnly ? 1 : direction === TTB ? 0 : -1;
  553. return ORIENTATION_MAP[prop][index] || prop;
  554. }
  555. function orient(value) {
  556. return value * (options.direction === RTL ? 1 : -1);
  557. }
  558. return {
  559. resolve,
  560. orient
  561. };
  562. }
  563. const CLASS_ROOT = PROJECT_CODE;
  564. const CLASS_SLIDER = `${PROJECT_CODE}__slider`;
  565. const CLASS_TRACK = `${PROJECT_CODE}__track`;
  566. const CLASS_LIST = `${PROJECT_CODE}__list`;
  567. const CLASS_SLIDE = `${PROJECT_CODE}__slide`;
  568. const CLASS_CLONE = `${CLASS_SLIDE}--clone`;
  569. const CLASS_CONTAINER = `${CLASS_SLIDE}__container`;
  570. const CLASS_ARROWS = `${PROJECT_CODE}__arrows`;
  571. const CLASS_ARROW = `${PROJECT_CODE}__arrow`;
  572. const CLASS_ARROW_PREV = `${CLASS_ARROW}--prev`;
  573. const CLASS_ARROW_NEXT = `${CLASS_ARROW}--next`;
  574. const CLASS_PAGINATION = `${PROJECT_CODE}__pagination`;
  575. const CLASS_PAGINATION_PAGE = `${CLASS_PAGINATION}__page`;
  576. const CLASS_PROGRESS = `${PROJECT_CODE}__progress`;
  577. const CLASS_PROGRESS_BAR = `${CLASS_PROGRESS}__bar`;
  578. const CLASS_AUTOPLAY = `${PROJECT_CODE}__autoplay`;
  579. const CLASS_PLAY = `${PROJECT_CODE}__play`;
  580. const CLASS_PAUSE = `${PROJECT_CODE}__pause`;
  581. const CLASS_SPINNER = `${PROJECT_CODE}__spinner`;
  582. const CLASS_INITIALIZED = "is-initialized";
  583. const CLASS_ACTIVE = "is-active";
  584. const CLASS_PREV = "is-prev";
  585. const CLASS_NEXT = "is-next";
  586. const CLASS_VISIBLE = "is-visible";
  587. const CLASS_LOADING = "is-loading";
  588. const STATUS_CLASSES = [CLASS_ACTIVE, CLASS_VISIBLE, CLASS_PREV, CLASS_NEXT, CLASS_LOADING];
  589. const CLASSES = {
  590. slide: CLASS_SLIDE,
  591. clone: CLASS_CLONE,
  592. arrows: CLASS_ARROWS,
  593. arrow: CLASS_ARROW,
  594. prev: CLASS_ARROW_PREV,
  595. next: CLASS_ARROW_NEXT,
  596. pagination: CLASS_PAGINATION,
  597. page: CLASS_PAGINATION_PAGE,
  598. spinner: CLASS_SPINNER
  599. };
  600. function Elements(Splide2, Components2, options) {
  601. const { on } = EventInterface(Splide2);
  602. const { root } = Splide2;
  603. const elements = {};
  604. const slides = [];
  605. let classes;
  606. let slider;
  607. let track;
  608. let list;
  609. function setup() {
  610. collect();
  611. identify();
  612. addClass(root, classes = getClasses());
  613. }
  614. function mount() {
  615. on(EVENT_REFRESH, refresh, DEFAULT_EVENT_PRIORITY - 2);
  616. on(EVENT_UPDATED, update);
  617. }
  618. function destroy() {
  619. empty(slides);
  620. removeClass(root, classes);
  621. }
  622. function refresh() {
  623. destroy();
  624. setup();
  625. }
  626. function update() {
  627. removeClass(root, classes);
  628. addClass(root, classes = getClasses());
  629. }
  630. function collect() {
  631. slider = child(root, `.${CLASS_SLIDER}`);
  632. track = query(root, `.${CLASS_TRACK}`);
  633. list = child(track, `.${CLASS_LIST}`);
  634. assert(track && list, "A track/list element is missing.");
  635. push(slides, children(list, `.${CLASS_SLIDE}:not(.${CLASS_CLONE})`));
  636. const autoplay = find(`.${CLASS_AUTOPLAY}`);
  637. const arrows = find(`.${CLASS_ARROWS}`);
  638. assign(elements, {
  639. root,
  640. slider,
  641. track,
  642. list,
  643. slides,
  644. arrows,
  645. autoplay,
  646. prev: query(arrows, `.${CLASS_ARROW_PREV}`),
  647. next: query(arrows, `.${CLASS_ARROW_NEXT}`),
  648. bar: query(find(`.${CLASS_PROGRESS}`), `.${CLASS_PROGRESS_BAR}`),
  649. play: query(autoplay, `.${CLASS_PLAY}`),
  650. pause: query(autoplay, `.${CLASS_PAUSE}`)
  651. });
  652. }
  653. function identify() {
  654. const id = root.id || uniqueId(PROJECT_CODE);
  655. root.id = id;
  656. track.id = track.id || `${id}-track`;
  657. list.id = list.id || `${id}-list`;
  658. }
  659. function find(selector) {
  660. return child(root, selector) || child(slider, selector);
  661. }
  662. function getClasses() {
  663. return [
  664. `${CLASS_ROOT}--${options.type}`,
  665. `${CLASS_ROOT}--${options.direction}`,
  666. options.drag && `${CLASS_ROOT}--draggable`,
  667. options.isNavigation && `${CLASS_ROOT}--nav`,
  668. CLASS_ACTIVE
  669. ];
  670. }
  671. return assign(elements, {
  672. setup,
  673. mount,
  674. destroy
  675. });
  676. }
  677. function Style$1() {
  678. let style;
  679. let sheet;
  680. function mount() {
  681. style = create("style", {}, document.head);
  682. sheet = style.sheet;
  683. }
  684. function destroy() {
  685. remove(style);
  686. sheet = null;
  687. }
  688. function rule(selector, prop, value) {
  689. const { cssRules } = sheet;
  690. const cssRule = find(cssRules, (cssRule2) => isCSSStyleRule(cssRule2) && cssRule2.selectorText === selector) || cssRules[sheet.insertRule(`${selector}{}`, 0)];
  691. if (isCSSStyleRule(cssRule)) {
  692. const { style: style2 } = cssRule;
  693. value = `${value}`;
  694. if (style2[prop] !== value) {
  695. style2[prop] = value;
  696. }
  697. }
  698. }
  699. function ruleBy(target, prop, value) {
  700. rule(`#${isHTMLElement(target) ? target.id : target}`, prop, value);
  701. }
  702. function isCSSStyleRule(cssRule) {
  703. return cssRule instanceof CSSStyleRule;
  704. }
  705. return {
  706. mount,
  707. destroy,
  708. rule,
  709. ruleBy
  710. };
  711. }
  712. const ROLE = "role";
  713. const ARIA_CONTROLS = "aria-controls";
  714. const ARIA_CURRENT = "aria-current";
  715. const ARIA_LABEL = "aria-label";
  716. const ARIA_HIDDEN = "aria-hidden";
  717. const TAB_INDEX = "tabindex";
  718. const DISABLED = "disabled";
  719. const ARIA_ORIENTATION = "aria-orientation";
  720. const ALL_ATTRIBUTES = [
  721. ROLE,
  722. ARIA_CONTROLS,
  723. ARIA_CURRENT,
  724. ARIA_LABEL,
  725. ARIA_HIDDEN,
  726. ARIA_ORIENTATION,
  727. TAB_INDEX,
  728. DISABLED
  729. ];
  730. const SLIDE = "slide";
  731. const LOOP = "loop";
  732. const FADE = "fade";
  733. function Slide$1(Splide2, index, slideIndex, slide) {
  734. const { on, emit, bind, destroy: destroyEvents } = EventInterface(Splide2);
  735. const { Components, root, options } = Splide2;
  736. const { isNavigation, updateOnMove } = options;
  737. const { resolve } = Components.Direction;
  738. const isClone = slideIndex > -1;
  739. const container = child(slide, `.${CLASS_CONTAINER}`);
  740. const focusableNodes = options.focusableNodes && queryAll(slide, options.focusableNodes);
  741. let destroyed;
  742. function mount() {
  743. init();
  744. bind(slide, "click keydown", (e) => {
  745. emit(e.type === "click" ? EVENT_CLICK : EVENT_SLIDE_KEYDOWN, this, e);
  746. });
  747. on([EVENT_REPOSITIONED, EVENT_MOVED, EVENT_SCROLLED], update.bind(this));
  748. if (updateOnMove) {
  749. on(EVENT_MOVE, onMove.bind(this));
  750. }
  751. }
  752. function init() {
  753. if (!isClone) {
  754. slide.id = `${root.id}-slide${pad(index + 1)}`;
  755. }
  756. if (isNavigation) {
  757. const idx = isClone ? slideIndex : index;
  758. const label = format(options.i18n.slideX, idx + 1);
  759. const controls = Splide2.splides.map((splide) => splide.root.id).join(" ");
  760. setAttribute(slide, ARIA_LABEL, label);
  761. setAttribute(slide, ARIA_CONTROLS, controls);
  762. setAttribute(slide, ROLE, "menuitem");
  763. }
  764. }
  765. function destroy() {
  766. destroyed = true;
  767. destroyEvents();
  768. removeClass(slide, STATUS_CLASSES);
  769. removeAttribute(slide, ALL_ATTRIBUTES);
  770. }
  771. function onMove(next, prev, dest) {
  772. if (!destroyed) {
  773. update.call(this);
  774. if (dest === index) {
  775. updateActivity.call(this, true);
  776. }
  777. }
  778. }
  779. function update() {
  780. if (!destroyed) {
  781. const { index: currIndex } = Splide2;
  782. updateActivity.call(this, isActive());
  783. updateVisibility.call(this, isVisible());
  784. toggleClass(slide, CLASS_PREV, index === currIndex - 1);
  785. toggleClass(slide, CLASS_NEXT, index === currIndex + 1);
  786. }
  787. }
  788. function updateActivity(active) {
  789. if (active !== hasClass(slide, CLASS_ACTIVE)) {
  790. toggleClass(slide, CLASS_ACTIVE, active);
  791. if (isNavigation) {
  792. setAttribute(slide, ARIA_CURRENT, active || null);
  793. }
  794. emit(active ? EVENT_ACTIVE : EVENT_INACTIVE, this);
  795. }
  796. }
  797. function updateVisibility(visible) {
  798. const ariaHidden = !visible && !isActive();
  799. setAttribute(slide, ARIA_HIDDEN, ariaHidden || null);
  800. setAttribute(slide, TAB_INDEX, !ariaHidden && options.slideFocus ? 0 : null);
  801. if (focusableNodes) {
  802. focusableNodes.forEach((node) => {
  803. setAttribute(node, TAB_INDEX, ariaHidden ? -1 : null);
  804. });
  805. }
  806. if (visible !== hasClass(slide, CLASS_VISIBLE)) {
  807. toggleClass(slide, CLASS_VISIBLE, visible);
  808. emit(visible ? EVENT_VISIBLE : EVENT_HIDDEN, this);
  809. }
  810. }
  811. function rule(prop, value, useContainer) {
  812. const selector = `#${slide.id}${container && useContainer ? ` > .${CLASS_CONTAINER}` : ""}`;
  813. Components.Style.rule(selector, prop, value);
  814. }
  815. function isActive() {
  816. return Splide2.index === index;
  817. }
  818. function isVisible() {
  819. if (Splide2.is(FADE)) {
  820. return isActive();
  821. }
  822. const trackRect = rect(Components.Elements.track);
  823. const slideRect = rect(slide);
  824. const left = resolve("left");
  825. const right = resolve("right");
  826. return floor(trackRect[left]) <= ceil(slideRect[left]) && floor(slideRect[right]) <= ceil(trackRect[right]);
  827. }
  828. function isWithin(from, distance) {
  829. let diff = abs(from - index);
  830. if (!Splide2.is(SLIDE) && !isClone) {
  831. diff = min(diff, Splide2.length - diff);
  832. }
  833. return diff <= distance;
  834. }
  835. return {
  836. index,
  837. slideIndex,
  838. slide,
  839. container,
  840. isClone,
  841. mount,
  842. destroy,
  843. rule,
  844. isWithin
  845. };
  846. }
  847. function Slides(Splide2, Components2, options) {
  848. const { on, emit, bind } = EventInterface(Splide2);
  849. const { slides, list } = Components2.Elements;
  850. const Slides2 = [];
  851. function mount() {
  852. init();
  853. on(EVENT_REFRESH, refresh);
  854. }
  855. function init() {
  856. slides.forEach((slide, index) => {
  857. register(slide, index, -1);
  858. });
  859. }
  860. function destroy() {
  861. forEach$1((Slide2) => {
  862. Slide2.destroy();
  863. });
  864. empty(Slides2);
  865. }
  866. function refresh() {
  867. destroy();
  868. init();
  869. }
  870. function register(slide, index, slideIndex) {
  871. const object = Slide$1(Splide2, index, slideIndex, slide);
  872. object.mount();
  873. Slides2.push(object);
  874. }
  875. function get(excludeClones) {
  876. return excludeClones ? filter((Slide2) => !Slide2.isClone) : Slides2;
  877. }
  878. function getIn(page) {
  879. const { Controller } = Components2;
  880. const index = Controller.toIndex(page);
  881. const max = Controller.hasFocus() ? 1 : options.perPage;
  882. return filter((Slide2) => between(Slide2.index, index, index + max - 1));
  883. }
  884. function getAt(index) {
  885. return filter(index)[0];
  886. }
  887. function add(items, index) {
  888. forEach(items, (slide) => {
  889. if (isString(slide)) {
  890. slide = parseHtml(slide);
  891. }
  892. if (isHTMLElement(slide)) {
  893. const ref = slides[index];
  894. ref ? before(slide, ref) : append(list, slide);
  895. addClass(slide, options.classes.slide);
  896. observeImages(slide, emit.bind(null, EVENT_RESIZE));
  897. }
  898. });
  899. emit(EVENT_REFRESH);
  900. }
  901. function remove$1(matcher) {
  902. remove(filter(matcher).map((Slide2) => Slide2.slide));
  903. emit(EVENT_REFRESH);
  904. }
  905. function forEach$1(iteratee, excludeClones) {
  906. get(excludeClones).forEach(iteratee);
  907. }
  908. function filter(matcher) {
  909. return Slides2.filter(isFunction(matcher) ? matcher : (Slide2) => isString(matcher) ? matches(Slide2.slide, matcher) : includes(toArray(matcher), Slide2.index));
  910. }
  911. function rule(prop, value, useContainer) {
  912. forEach$1((Slide2) => {
  913. Slide2.rule(prop, value, useContainer);
  914. });
  915. }
  916. function observeImages(elm, callback) {
  917. const images = queryAll(elm, "img");
  918. let { length } = images;
  919. if (length) {
  920. images.forEach((img) => {
  921. bind(img, "load error", () => {
  922. if (!--length) {
  923. callback();
  924. }
  925. });
  926. });
  927. } else {
  928. callback();
  929. }
  930. }
  931. function getLength(excludeClones) {
  932. return excludeClones ? slides.length : Slides2.length;
  933. }
  934. function isEnough() {
  935. return Slides2.length > options.perPage;
  936. }
  937. return {
  938. mount,
  939. destroy,
  940. register,
  941. get,
  942. getIn,
  943. getAt,
  944. add,
  945. remove: remove$1,
  946. forEach: forEach$1,
  947. filter,
  948. rule,
  949. getLength,
  950. isEnough
  951. };
  952. }
  953. function Clones(Splide2, Components2, options) {
  954. const { on, emit } = EventInterface(Splide2);
  955. const { Elements, Slides } = Components2;
  956. const { resolve } = Components2.Direction;
  957. const clones = [];
  958. let cloneCount;
  959. function mount() {
  960. init();
  961. on(EVENT_REFRESH, refresh);
  962. on([EVENT_UPDATED, EVENT_RESIZE], observe);
  963. }
  964. function init() {
  965. if (cloneCount = computeCloneCount()) {
  966. generate(cloneCount);
  967. }
  968. }
  969. function destroy() {
  970. remove(clones);
  971. empty(clones);
  972. }
  973. function refresh() {
  974. destroy();
  975. init();
  976. }
  977. function observe() {
  978. if (cloneCount !== computeCloneCount()) {
  979. emit(EVENT_REFRESH);
  980. }
  981. }
  982. function generate(count) {
  983. const slides = Slides.get().slice();
  984. const { length } = slides;
  985. if (length) {
  986. while (slides.length < count) {
  987. push(slides, slides);
  988. }
  989. push(slides.slice(-count), slides.slice(0, count)).forEach((Slide, index) => {
  990. const isHead = index < count;
  991. const clone = cloneDeep(Slide.slide, index);
  992. isHead ? before(clone, slides[0].slide) : append(Elements.list, clone);
  993. push(clones, clone);
  994. Slides.register(clone, index - count + (isHead ? 0 : length), Slide.index);
  995. });
  996. }
  997. }
  998. function cloneDeep(elm, index) {
  999. const clone = elm.cloneNode(true);
  1000. addClass(clone, options.classes.clone);
  1001. clone.id = `${Splide2.root.id}-clone${pad(index + 1)}`;
  1002. return clone;
  1003. }
  1004. function computeCloneCount() {
  1005. let { clones: clones2 } = options;
  1006. if (!Splide2.is(LOOP)) {
  1007. clones2 = 0;
  1008. } else if (!clones2) {
  1009. const fixedSize = measure(Elements.list, options[resolve("fixedWidth")]);
  1010. const fixedCount = fixedSize && ceil(rect(Elements.track)[resolve("width")] / fixedSize);
  1011. const baseCount = fixedCount || options[resolve("autoWidth")] && Splide2.length || options.perPage;
  1012. clones2 = baseCount * (options.drag ? (options.flickMaxPages || 1) + 1 : 2);
  1013. }
  1014. return clones2;
  1015. }
  1016. return {
  1017. mount,
  1018. destroy
  1019. };
  1020. }
  1021. function Layout(Splide2, Components2, options) {
  1022. const { on, bind, emit } = EventInterface(Splide2);
  1023. const { Slides } = Components2;
  1024. const { ruleBy } = Components2.Style;
  1025. const { resolve } = Components2.Direction;
  1026. const { track, list } = Components2.Elements;
  1027. const { getAt } = Slides;
  1028. let vertical;
  1029. function mount() {
  1030. init();
  1031. bind(window, "resize load", Throttle(emit.bind(this, EVENT_RESIZE)));
  1032. on([EVENT_UPDATED, EVENT_REFRESH], init);
  1033. on(EVENT_RESIZE, resize);
  1034. }
  1035. function init() {
  1036. vertical = options.direction === TTB;
  1037. ruleBy(Splide2.root, "maxWidth", unit(options.width));
  1038. ruleBy(track, resolve("paddingLeft"), cssPadding(false));
  1039. ruleBy(track, resolve("paddingRight"), cssPadding(true));
  1040. Slides.rule(resolve("marginRight"), unit(options.gap));
  1041. Slides.rule("width", cssSlideWidth());
  1042. setSlidesHeight();
  1043. resize();
  1044. }
  1045. function resize() {
  1046. ruleBy(track, "height", cssTrackHeight());
  1047. options.heightRatio && setSlidesHeight();
  1048. emit(EVENT_RESIZED);
  1049. }
  1050. function setSlidesHeight() {
  1051. Slides.rule("height", cssSlideHeight(), true);
  1052. }
  1053. function cssPadding(right) {
  1054. const { padding } = options;
  1055. const prop = resolve(right ? "right" : "left", true);
  1056. return padding && unit(padding[prop] || (isObject(padding) ? 0 : padding)) || "0px";
  1057. }
  1058. function cssTrackHeight() {
  1059. let height = "";
  1060. if (vertical) {
  1061. height = cssHeight();
  1062. assert(height, "height or heightRatio is missing.");
  1063. height = `calc(${height} - ${cssPadding(false)} - ${cssPadding(true)})`;
  1064. }
  1065. return height;
  1066. }
  1067. function cssHeight() {
  1068. return unit(options.height || rect(list).width * options.heightRatio);
  1069. }
  1070. function cssSlideWidth() {
  1071. return options.autoWidth ? "" : unit(options.fixedWidth) || (vertical ? "" : cssSlideSize());
  1072. }
  1073. function cssSlideHeight() {
  1074. return unit(options.fixedHeight) || (vertical ? options.autoHeight ? "" : cssSlideSize() : cssHeight());
  1075. }
  1076. function cssSlideSize() {
  1077. const gap = unit(options.gap);
  1078. return `calc((100%${gap && ` + ${gap}`})/${options.perPage || 1}${gap && ` - ${gap}`})`;
  1079. }
  1080. function listSize() {
  1081. return rect(list)[resolve("width")];
  1082. }
  1083. function slideSize(index, withoutGap) {
  1084. const Slide = getAt(index || 0);
  1085. return Slide ? rect(Slide.slide)[resolve("width")] + (withoutGap ? 0 : getGap()) : 0;
  1086. }
  1087. function totalSize(index, withoutGap) {
  1088. const Slide = getAt(index);
  1089. if (Slide) {
  1090. const right = rect(Slide.slide)[resolve("right")];
  1091. const left = rect(list)[resolve("left")];
  1092. return abs(right - left) + (withoutGap ? 0 : getGap());
  1093. }
  1094. return 0;
  1095. }
  1096. function sliderSize() {
  1097. return totalSize(Splide2.length - 1, true) - totalSize(-1, true);
  1098. }
  1099. function getGap() {
  1100. const Slide = getAt(0);
  1101. return Slide && parseFloat(style(Slide.slide, resolve("marginRight"))) || 0;
  1102. }
  1103. function getPadding(right) {
  1104. return parseFloat(style(track, resolve(`padding${right ? "Right" : "Left"}`, true))) || 0;
  1105. }
  1106. return {
  1107. mount,
  1108. listSize,
  1109. slideSize,
  1110. sliderSize,
  1111. totalSize,
  1112. getPadding
  1113. };
  1114. }
  1115. function Move(Splide2, Components2, options) {
  1116. const { on, emit } = EventInterface(Splide2);
  1117. const { slideSize, getPadding, totalSize, listSize, sliderSize } = Components2.Layout;
  1118. const { resolve, orient } = Components2.Direction;
  1119. const { list, track } = Components2.Elements;
  1120. let waiting;
  1121. function mount() {
  1122. if (!Splide2.is(FADE)) {
  1123. on([EVENT_MOUNTED, EVENT_RESIZED, EVENT_UPDATED, EVENT_REFRESH], reposition);
  1124. } else {
  1125. emit(EVENT_REPOSITIONED);
  1126. }
  1127. }
  1128. function reposition() {
  1129. Components2.Scroll.cancel();
  1130. jump(Splide2.index);
  1131. emit(EVENT_REPOSITIONED);
  1132. }
  1133. function move(dest, index, prev, callback) {
  1134. if (!isBusy()) {
  1135. const { set } = Splide2.state;
  1136. const position = getPosition();
  1137. const looping = dest !== index;
  1138. waiting = looping || options.waitForTransition;
  1139. set(MOVING);
  1140. emit(EVENT_MOVE, index, prev, dest);
  1141. Components2.Transition.start(dest, () => {
  1142. looping && jump(index);
  1143. waiting = false;
  1144. set(IDLE);
  1145. emit(EVENT_MOVED, index, prev, dest);
  1146. if (options.trimSpace === "move" && dest !== prev && position === getPosition()) {
  1147. Components2.Controller.go(dest > prev ? ">" : "<", false, callback);
  1148. } else {
  1149. callback && callback();
  1150. }
  1151. });
  1152. }
  1153. }
  1154. function jump(index) {
  1155. translate(toPosition(index, true));
  1156. }
  1157. function translate(position, preventLoop) {
  1158. Components2.Style.ruleBy(list, "transform", `translate${resolve("X")}(${preventLoop ? position : loop(position)}px)`);
  1159. }
  1160. function loop(position) {
  1161. if (!waiting && Splide2.is(LOOP)) {
  1162. const diff = orient(position - getPosition());
  1163. const exceededMin = exceededLimit(false, position) && diff < 0;
  1164. const exceededMax = exceededLimit(true, position) && diff > 0;
  1165. if (exceededMin || exceededMax) {
  1166. const excess = position - getLimit(exceededMax);
  1167. const size = sliderSize();
  1168. position -= sign(excess) * size * ceil(abs(excess) / size);
  1169. }
  1170. }
  1171. return position;
  1172. }
  1173. function cancel() {
  1174. waiting = false;
  1175. Components2.Transition.cancel();
  1176. translate(getPosition());
  1177. }
  1178. function toIndex(position) {
  1179. const Slides = Components2.Slides.get();
  1180. let index = 0;
  1181. let minDistance = Infinity;
  1182. for (let i = 0; i < Slides.length; i++) {
  1183. const slideIndex = Slides[i].index;
  1184. const distance = abs(toPosition(slideIndex, true) - position);
  1185. if (distance < minDistance) {
  1186. minDistance = distance;
  1187. index = slideIndex;
  1188. } else {
  1189. break;
  1190. }
  1191. }
  1192. return index;
  1193. }
  1194. function toPosition(index, trimming) {
  1195. const position = orient(totalSize(index - 1) - offset(index));
  1196. return trimming ? trim(position) : position;
  1197. }
  1198. function getPosition() {
  1199. const left = resolve("left");
  1200. return rect(list)[left] - rect(track)[left] + orient(getPadding(false));
  1201. }
  1202. function trim(position) {
  1203. if (options.trimSpace && Splide2.is(SLIDE)) {
  1204. position = clamp(position, 0, orient(sliderSize() - listSize()));
  1205. }
  1206. return position;
  1207. }
  1208. function offset(index) {
  1209. const { focus } = options;
  1210. return focus === "center" ? (listSize() - slideSize(index, true)) / 2 : +focus * slideSize(index) || 0;
  1211. }
  1212. function getLimit(max) {
  1213. return toPosition(max ? Components2.Controller.getEnd() : 0, !!options.trimSpace);
  1214. }
  1215. function isBusy() {
  1216. return !!waiting;
  1217. }
  1218. function exceededLimit(max, position) {
  1219. position = isUndefined(position) ? getPosition() : position;
  1220. const exceededMin = max !== true && orient(position) < orient(getLimit(false));
  1221. const exceededMax = max !== false && orient(position) > orient(getLimit(true));
  1222. return exceededMin || exceededMax;
  1223. }
  1224. return {
  1225. mount,
  1226. move,
  1227. jump,
  1228. translate,
  1229. cancel,
  1230. toIndex,
  1231. toPosition,
  1232. getPosition,
  1233. getLimit,
  1234. isBusy,
  1235. exceededLimit
  1236. };
  1237. }
  1238. function Controller(Splide2, Components2, options) {
  1239. const { on } = EventInterface(Splide2);
  1240. const { Move } = Components2;
  1241. const { getPosition, getLimit } = Move;
  1242. const { isEnough, getLength } = Components2.Slides;
  1243. const isLoop = Splide2.is(LOOP);
  1244. let currIndex = options.start || 0;
  1245. let prevIndex = currIndex;
  1246. let slideCount;
  1247. let perMove;
  1248. let perPage;
  1249. function mount() {
  1250. init();
  1251. on([EVENT_UPDATED, EVENT_REFRESH], init, DEFAULT_EVENT_PRIORITY - 1);
  1252. on(EVENT_SCROLLED, reindex, 0);
  1253. }
  1254. function init() {
  1255. slideCount = getLength(true);
  1256. perMove = options.perMove;
  1257. perPage = options.perPage;
  1258. currIndex = clamp(currIndex, 0, slideCount - 1);
  1259. }
  1260. function reindex() {
  1261. setIndex(Move.toIndex(getPosition()));
  1262. }
  1263. function go(control, allowSameIndex, callback) {
  1264. const dest = parse(control);
  1265. const index = loop(dest);
  1266. if (index > -1 && !Move.isBusy() && (allowSameIndex || index !== currIndex)) {
  1267. setIndex(index);
  1268. Move.move(dest, index, prevIndex, callback);
  1269. }
  1270. }
  1271. function parse(control) {
  1272. let index = currIndex;
  1273. if (isString(control)) {
  1274. const [, indicator, number] = control.match(/([+\-<>])(\d+)?/) || [];
  1275. if (indicator === "+" || indicator === "-") {
  1276. index = computeDestIndex(currIndex + +`${indicator}${+number || 1}`, currIndex, true);
  1277. } else if (indicator === ">") {
  1278. index = number ? toIndex(+number) : getNext(true);
  1279. } else if (indicator === "<") {
  1280. index = getPrev(true);
  1281. }
  1282. } else {
  1283. if (isLoop) {
  1284. index = clamp(control, -perPage, slideCount + perPage - 1);
  1285. } else {
  1286. index = clamp(control, 0, getEnd());
  1287. }
  1288. }
  1289. return index;
  1290. }
  1291. function getNext(destination) {
  1292. return getAdjacent(false, destination);
  1293. }
  1294. function getPrev(destination) {
  1295. return getAdjacent(true, destination);
  1296. }
  1297. function getAdjacent(prev, destination) {
  1298. const number = perMove || hasFocus() ? 1 : perPage;
  1299. const dest = computeDestIndex(currIndex + number * (prev ? -1 : 1), currIndex);
  1300. if (dest === -1 && Splide2.is(SLIDE)) {
  1301. if (!approximatelyEqual(getPosition(), getLimit(!prev), 1)) {
  1302. return prev ? 0 : getEnd();
  1303. }
  1304. }
  1305. return destination ? dest : loop(dest);
  1306. }
  1307. function computeDestIndex(dest, from, incremental) {
  1308. if (isEnough()) {
  1309. const end = getEnd();
  1310. if (dest < 0 || dest > end) {
  1311. if (between(0, dest, from, true) || between(end, from, dest, true)) {
  1312. dest = toIndex(toPage(dest));
  1313. } else {
  1314. if (isLoop) {
  1315. dest = perMove ? dest : dest < 0 ? -(slideCount % perPage || perPage) : slideCount;
  1316. } else if (options.rewind) {
  1317. dest = dest < 0 ? end : 0;
  1318. } else {
  1319. dest = -1;
  1320. }
  1321. }
  1322. } else {
  1323. if (!isLoop && !incremental && dest !== from) {
  1324. dest = perMove ? dest : toIndex(toPage(from) + (dest < from ? -1 : 1));
  1325. }
  1326. }
  1327. } else {
  1328. dest = -1;
  1329. }
  1330. return dest;
  1331. }
  1332. function getEnd() {
  1333. let end = slideCount - perPage;
  1334. if (hasFocus() || isLoop && perMove) {
  1335. end = slideCount - 1;
  1336. }
  1337. return max(end, 0);
  1338. }
  1339. function loop(index) {
  1340. if (isLoop) {
  1341. return isEnough() ? index % slideCount + (index < 0 ? slideCount : 0) : -1;
  1342. }
  1343. return index;
  1344. }
  1345. function toIndex(page) {
  1346. return clamp(hasFocus() ? page : perPage * page, 0, getEnd());
  1347. }
  1348. function toPage(index) {
  1349. if (!hasFocus()) {
  1350. index = between(index, slideCount - perPage, slideCount - 1) ? slideCount - 1 : index;
  1351. index = floor(index / perPage);
  1352. }
  1353. return index;
  1354. }
  1355. function setIndex(index) {
  1356. if (index !== currIndex) {
  1357. prevIndex = currIndex;
  1358. currIndex = index;
  1359. }
  1360. }
  1361. function getIndex(prev) {
  1362. return prev ? prevIndex : currIndex;
  1363. }
  1364. function hasFocus() {
  1365. return !isUndefined(options.focus) || options.isNavigation;
  1366. }
  1367. return {
  1368. mount,
  1369. go,
  1370. getNext,
  1371. getPrev,
  1372. getEnd,
  1373. setIndex,
  1374. getIndex,
  1375. toIndex,
  1376. toPage,
  1377. hasFocus
  1378. };
  1379. }
  1380. const XML_NAME_SPACE = "http://www.w3.org/2000/svg";
  1381. const 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";
  1382. const SIZE = 40;
  1383. function Arrows(Splide2, Components2, options) {
  1384. const { on, bind, emit } = EventInterface(Splide2);
  1385. const { classes, i18n } = options;
  1386. const { Elements, Controller } = Components2;
  1387. let wrapper = Elements.arrows;
  1388. let prev = Elements.prev;
  1389. let next = Elements.next;
  1390. let created;
  1391. const arrows = {};
  1392. function mount() {
  1393. init();
  1394. on(EVENT_UPDATED, init);
  1395. }
  1396. function init() {
  1397. if (options.arrows) {
  1398. if (!prev || !next) {
  1399. createArrows();
  1400. }
  1401. }
  1402. if (prev && next) {
  1403. if (!arrows.prev) {
  1404. const { id } = Elements.track;
  1405. setAttribute(prev, ARIA_CONTROLS, id);
  1406. setAttribute(next, ARIA_CONTROLS, id);
  1407. arrows.prev = prev;
  1408. arrows.next = next;
  1409. listen();
  1410. emit(EVENT_ARROWS_MOUNTED, prev, next);
  1411. } else {
  1412. display(wrapper, options.arrows === false ? "none" : "");
  1413. }
  1414. }
  1415. }
  1416. function destroy() {
  1417. if (created) {
  1418. remove(wrapper);
  1419. } else {
  1420. removeAttribute(prev, ALL_ATTRIBUTES);
  1421. removeAttribute(next, ALL_ATTRIBUTES);
  1422. }
  1423. }
  1424. function listen() {
  1425. const { go } = Controller;
  1426. on([EVENT_MOUNTED, EVENT_MOVED, EVENT_UPDATED, EVENT_REFRESH, EVENT_SCROLLED], update);
  1427. bind(next, "click", () => {
  1428. go(">", true);
  1429. });
  1430. bind(prev, "click", () => {
  1431. go("<", true);
  1432. });
  1433. }
  1434. function createArrows() {
  1435. wrapper = create("div", classes.arrows);
  1436. prev = createArrow(true);
  1437. next = createArrow(false);
  1438. created = true;
  1439. append(wrapper, [prev, next]);
  1440. before(wrapper, child(options.arrows === "slider" && Elements.slider || Splide2.root));
  1441. }
  1442. function createArrow(prev2) {
  1443. const arrow = `<button class="${classes.arrow} ${prev2 ? classes.prev : classes.next}" type="button"><svg xmlns="${XML_NAME_SPACE}" viewBox="0 0 ${SIZE} ${SIZE}" width="${SIZE}" height="${SIZE}"><path d="${options.arrowPath || PATH}" />`;
  1444. return parseHtml(arrow);
  1445. }
  1446. function update() {
  1447. const index = Splide2.index;
  1448. const prevIndex = Controller.getPrev();
  1449. const nextIndex = Controller.getNext();
  1450. const prevLabel = prevIndex > -1 && index < prevIndex ? i18n.last : i18n.prev;
  1451. const nextLabel = nextIndex > -1 && index > nextIndex ? i18n.first : i18n.next;
  1452. prev.disabled = prevIndex < 0;
  1453. next.disabled = nextIndex < 0;
  1454. setAttribute(prev, ARIA_LABEL, prevLabel);
  1455. setAttribute(next, ARIA_LABEL, nextLabel);
  1456. emit(EVENT_ARROWS_UPDATED, prev, next, prevIndex, nextIndex);
  1457. }
  1458. return {
  1459. arrows,
  1460. mount,
  1461. destroy
  1462. };
  1463. }
  1464. function Autoplay(Splide2, Components2, options) {
  1465. const { on, bind, emit } = EventInterface(Splide2);
  1466. const { Elements } = Components2;
  1467. const interval = RequestInterval(options.interval, Splide2.go.bind(Splide2, ">"), update);
  1468. const { isPaused } = interval;
  1469. let hovered;
  1470. let focused;
  1471. let paused;
  1472. function mount() {
  1473. const { autoplay } = options;
  1474. if (autoplay) {
  1475. initButton(true);
  1476. initButton(false);
  1477. listen();
  1478. if (autoplay !== "pause") {
  1479. play();
  1480. }
  1481. }
  1482. }
  1483. function initButton(forPause) {
  1484. const prop = forPause ? "pause" : "play";
  1485. const button = Elements[prop];
  1486. if (button) {
  1487. setAttribute(button, ARIA_CONTROLS, Elements.track.id);
  1488. setAttribute(button, ARIA_LABEL, options.i18n[prop]);
  1489. bind(button, "click", forPause ? pause : play);
  1490. }
  1491. }
  1492. function listen() {
  1493. const { root } = Elements;
  1494. if (options.pauseOnHover) {
  1495. bind(root, "mouseenter mouseleave", (e) => {
  1496. hovered = e.type === "mouseenter";
  1497. autoToggle();
  1498. });
  1499. }
  1500. if (options.pauseOnFocus) {
  1501. bind(root, "focusin focusout", (e) => {
  1502. focused = e.type === "focusin";
  1503. autoToggle();
  1504. });
  1505. }
  1506. on([EVENT_MOVE, EVENT_SCROLL, EVENT_REFRESH], interval.rewind);
  1507. }
  1508. function play() {
  1509. if (isPaused() && Components2.Slides.isEnough()) {
  1510. interval.start(!options.resetProgress);
  1511. focused = hovered = paused = false;
  1512. emit(EVENT_AUTOPLAY_PLAY);
  1513. }
  1514. }
  1515. function pause(manual = true) {
  1516. if (!isPaused()) {
  1517. interval.pause();
  1518. emit(EVENT_AUTOPLAY_PAUSE);
  1519. }
  1520. paused = manual;
  1521. }
  1522. function autoToggle() {
  1523. if (!paused) {
  1524. if (!hovered && !focused) {
  1525. play();
  1526. } else {
  1527. pause(false);
  1528. }
  1529. }
  1530. }
  1531. function update(rate) {
  1532. const { bar } = Elements;
  1533. if (bar) {
  1534. style(bar, { width: `${rate * 100}%` });
  1535. }
  1536. emit(EVENT_AUTOPLAY_PLAYING, rate);
  1537. }
  1538. return {
  1539. mount,
  1540. destroy: interval.cancel,
  1541. play,
  1542. pause,
  1543. isPaused
  1544. };
  1545. }
  1546. function Cover(Splide2, Components2, options) {
  1547. const { on } = EventInterface(Splide2);
  1548. function mount() {
  1549. if (options.cover) {
  1550. on(EVENT_LAZYLOAD_LOADED, (img, Slide) => {
  1551. toggle(true, img, Slide);
  1552. });
  1553. on([EVENT_MOUNTED, EVENT_UPDATED, EVENT_REFRESH], apply.bind(null, true));
  1554. }
  1555. }
  1556. function destroy() {
  1557. apply(false);
  1558. }
  1559. function apply(cover) {
  1560. Components2.Slides.forEach((Slide) => {
  1561. const img = child(Slide.container || Slide.slide, "img");
  1562. if (img && img.src) {
  1563. toggle(cover, img, Slide);
  1564. }
  1565. });
  1566. }
  1567. function toggle(cover, img, Slide) {
  1568. Slide.rule("background", cover ? `center/cover no-repeat url("${img.src}")` : "", true);
  1569. display(img, cover ? "none" : "");
  1570. }
  1571. return {
  1572. mount,
  1573. destroy
  1574. };
  1575. }
  1576. const BOUNCE_DIFF_THRESHOLD = 10;
  1577. const BOUNCE_DURATION = 600;
  1578. const FRICTION_FACTOR = 0.6;
  1579. const BASE_VELOCITY = 1.5;
  1580. const MIN_DURATION = 800;
  1581. function Scroll(Splide2, Components2, options) {
  1582. const { on, emit } = EventInterface(Splide2);
  1583. const { Move } = Components2;
  1584. const { getPosition, getLimit, exceededLimit } = Move;
  1585. let interval;
  1586. function mount() {
  1587. on(EVENT_MOVE, clear);
  1588. on([EVENT_UPDATED, EVENT_REFRESH], cancel);
  1589. }
  1590. function scroll(destination, duration, suppressConstraint) {
  1591. const start = getPosition();
  1592. let friction = 1;
  1593. duration = duration || computeDuration(abs(destination - start));
  1594. clear();
  1595. interval = RequestInterval(duration, onScrolled, (rate) => {
  1596. const position = getPosition();
  1597. const target = start + (destination - start) * easing(rate);
  1598. const diff = (target - getPosition()) * friction;
  1599. Move.translate(position + diff);
  1600. if (Splide2.is(SLIDE) && !suppressConstraint && exceededLimit()) {
  1601. friction *= FRICTION_FACTOR;
  1602. if (abs(diff) < BOUNCE_DIFF_THRESHOLD) {
  1603. bounce(exceededLimit(false));
  1604. }
  1605. }
  1606. }, 1);
  1607. emit(EVENT_SCROLL);
  1608. interval.start();
  1609. }
  1610. function bounce(backwards) {
  1611. scroll(getLimit(!backwards), BOUNCE_DURATION, true);
  1612. }
  1613. function onScrolled() {
  1614. emit(EVENT_SCROLLED);
  1615. }
  1616. function computeDuration(distance) {
  1617. return max(distance / BASE_VELOCITY, MIN_DURATION);
  1618. }
  1619. function clear() {
  1620. if (interval) {
  1621. interval.cancel();
  1622. }
  1623. }
  1624. function cancel() {
  1625. if (interval && !interval.isPaused()) {
  1626. clear();
  1627. onScrolled();
  1628. }
  1629. }
  1630. function easing(t) {
  1631. const { easingFunc } = options;
  1632. return easingFunc ? easingFunc(t) : 1 - Math.pow(1 - t, 4);
  1633. }
  1634. return {
  1635. mount,
  1636. destroy: clear,
  1637. scroll,
  1638. cancel
  1639. };
  1640. }
  1641. const FRICTION = 5;
  1642. const LOG_INTERVAL = 50;
  1643. const POINTER_DOWN_EVENTS = "touchstart mousedown";
  1644. const POINTER_MOVE_EVENTS = "touchmove mousemove";
  1645. const POINTER_UP_EVENTS = "touchend touchcancel mouseup mouseleave";
  1646. function Drag(Splide2, Components2, options) {
  1647. const { on, emit, bind, unbind } = EventInterface(Splide2);
  1648. const { Move, Scroll, Controller } = Components2;
  1649. const { ruleBy } = Components2.Style;
  1650. const { track } = Components2.Elements;
  1651. const { resolve, orient } = Components2.Direction;
  1652. const { getPosition, exceededLimit } = Move;
  1653. const isSlide = Splide2.is(SLIDE);
  1654. const isFade = Splide2.is(FADE);
  1655. let basePosition;
  1656. let baseEvent;
  1657. let prevBaseEvent;
  1658. let lastEvent;
  1659. let isFree;
  1660. let isDragging;
  1661. let isMouse;
  1662. let hasExceeded = false;
  1663. let clickPrevented;
  1664. let disabled;
  1665. let target;
  1666. function mount() {
  1667. bind(track, POINTER_DOWN_EVENTS, onPointerDown, { passive: false, capture: true });
  1668. bind(track, "click", onClick, { capture: true });
  1669. on([EVENT_MOUNTED, EVENT_UPDATED], init);
  1670. }
  1671. function init() {
  1672. const { drag } = options;
  1673. disable(!drag);
  1674. isFree = drag === "free";
  1675. }
  1676. function onPointerDown(e) {
  1677. if (!disabled) {
  1678. isMouse = e.type === "mousedown";
  1679. if (!isMouse || !e.button) {
  1680. if (!Move.isBusy()) {
  1681. target = isMouse ? window : track;
  1682. prevBaseEvent = null;
  1683. lastEvent = null;
  1684. clickPrevented = false;
  1685. bind(target, POINTER_MOVE_EVENTS, onPointerMove);
  1686. bind(target, POINTER_UP_EVENTS, onPointerUp);
  1687. Move.cancel();
  1688. Scroll.cancel();
  1689. ruleBy(track, "will-change", "transform");
  1690. save(e);
  1691. } else {
  1692. prevent(e, true);
  1693. }
  1694. }
  1695. }
  1696. }
  1697. function onPointerMove(e) {
  1698. if (!lastEvent) {
  1699. clickPrevented = true;
  1700. emit(EVENT_DRAG);
  1701. }
  1702. lastEvent = e;
  1703. if (e.cancelable) {
  1704. if (isDragging) {
  1705. const expired = timeOf(e) - timeOf(baseEvent) > LOG_INTERVAL;
  1706. const exceeded = hasExceeded !== (hasExceeded = exceededLimit());
  1707. if (expired || exceeded) {
  1708. save(e);
  1709. }
  1710. if (!isFade) {
  1711. Move.translate(basePosition + constrain(coordOf(e) - coordOf(baseEvent)));
  1712. }
  1713. emit(EVENT_DRAGGING);
  1714. prevent(e);
  1715. } else {
  1716. const threshold = options.dragMinThreshold || 15;
  1717. isDragging = isMouse || abs(coordOf(e) - coordOf(baseEvent)) > threshold;
  1718. if (isSliderDirection()) {
  1719. prevent(e);
  1720. }
  1721. }
  1722. }
  1723. }
  1724. function onPointerUp(e) {
  1725. unbind(target, `${POINTER_MOVE_EVENTS} ${POINTER_UP_EVENTS}`);
  1726. ruleBy(track, "will-change", "");
  1727. if (lastEvent) {
  1728. if (isDragging || e.cancelable && isSliderDirection()) {
  1729. const velocity = computeVelocity(e);
  1730. const destination = computeDestination(velocity);
  1731. if (isFree) {
  1732. Scroll.scroll(destination);
  1733. } else if (isFade) {
  1734. Controller.go(Splide2.index + orient(sign(velocity)));
  1735. } else {
  1736. Controller.go(computeIndex(destination), true);
  1737. }
  1738. prevent(e);
  1739. }
  1740. emit(EVENT_DRAGGED);
  1741. }
  1742. isDragging = false;
  1743. }
  1744. function save(e) {
  1745. prevBaseEvent = baseEvent;
  1746. baseEvent = e;
  1747. basePosition = getPosition();
  1748. }
  1749. function onClick(e) {
  1750. if (!disabled && clickPrevented) {
  1751. prevent(e, true);
  1752. }
  1753. }
  1754. function isSliderDirection() {
  1755. const diffX = abs(coordOf(lastEvent) - coordOf(baseEvent));
  1756. const diffY = abs(coordOf(lastEvent, true) - coordOf(baseEvent, true));
  1757. return diffX > diffY;
  1758. }
  1759. function computeVelocity(e) {
  1760. if (Splide2.is(LOOP) || !hasExceeded) {
  1761. const base = baseEvent === lastEvent && prevBaseEvent || baseEvent;
  1762. const diffCoord = coordOf(lastEvent) - coordOf(base);
  1763. const diffTime = timeOf(e) - timeOf(base);
  1764. const isFlick = timeOf(e) - timeOf(lastEvent) < LOG_INTERVAL;
  1765. if (diffTime && isFlick) {
  1766. return diffCoord / diffTime;
  1767. }
  1768. }
  1769. return 0;
  1770. }
  1771. function computeDestination(velocity) {
  1772. return getPosition() + sign(velocity) * min(abs(velocity) * (options.flickPower || 600), isFree ? Infinity : Components2.Layout.listSize() * (options.flickMaxPages || 1));
  1773. }
  1774. function computeIndex(destination) {
  1775. const dest = Move.toIndex(destination);
  1776. return isSlide ? clamp(dest, 0, Controller.getEnd()) : dest;
  1777. }
  1778. function coordOf(e, orthogonal) {
  1779. const prop = `page${resolve(orthogonal ? "Y" : "X")}`;
  1780. return (isMouse ? e : e.touches[0])[prop];
  1781. }
  1782. function timeOf(e) {
  1783. return e.timeStamp;
  1784. }
  1785. function constrain(diff) {
  1786. return diff / (hasExceeded && isSlide ? FRICTION : 1);
  1787. }
  1788. function disable(value) {
  1789. disabled = value;
  1790. }
  1791. return {
  1792. mount,
  1793. disable
  1794. };
  1795. }
  1796. const IE_ARROW_KEYS = ["Left", "Right", "Up", "Down"];
  1797. function Keyboard(Splide2, Components2, options) {
  1798. const { on, bind, unbind } = EventInterface(Splide2);
  1799. const { root } = Components2.Elements;
  1800. const { resolve } = Components2.Direction;
  1801. let target;
  1802. function mount() {
  1803. init();
  1804. on(EVENT_UPDATED, () => {
  1805. destroy();
  1806. init();
  1807. });
  1808. }
  1809. function init() {
  1810. const { keyboard = "global" } = options;
  1811. if (keyboard) {
  1812. if (keyboard === "focused") {
  1813. target = root;
  1814. setAttribute(root, TAB_INDEX, 0);
  1815. } else {
  1816. target = window;
  1817. }
  1818. bind(target, "keydown", onKeydown);
  1819. }
  1820. }
  1821. function destroy() {
  1822. unbind(target, "keydown");
  1823. if (isHTMLElement(target)) {
  1824. removeAttribute(target, TAB_INDEX);
  1825. }
  1826. }
  1827. function onKeydown(e) {
  1828. const { key } = e;
  1829. const normalizedKey = includes(IE_ARROW_KEYS, key) ? `Arrow${key}` : key;
  1830. if (normalizedKey === resolve("ArrowLeft")) {
  1831. Splide2.go("<");
  1832. } else if (normalizedKey === resolve("ArrowRight")) {
  1833. Splide2.go(">");
  1834. }
  1835. }
  1836. return {
  1837. mount,
  1838. destroy
  1839. };
  1840. }
  1841. const SRC_DATA_ATTRIBUTE = `${DATA_ATTRIBUTE}-lazy`;
  1842. const SRCSET_DATA_ATTRIBUTE = `${SRC_DATA_ATTRIBUTE}-srcset`;
  1843. const IMAGE_SELECTOR = `[${SRC_DATA_ATTRIBUTE}], [${SRCSET_DATA_ATTRIBUTE}]`;
  1844. function LazyLoad(Splide2, Components2, options) {
  1845. const { on, off, bind, emit } = EventInterface(Splide2);
  1846. const isSequential = options.lazyLoad === "sequential";
  1847. let images = [];
  1848. let index = 0;
  1849. function mount() {
  1850. if (options.lazyLoad) {
  1851. on([EVENT_MOUNTED, EVENT_REFRESH], () => {
  1852. destroy();
  1853. init();
  1854. });
  1855. if (!isSequential) {
  1856. on([EVENT_MOUNTED, EVENT_REFRESH, EVENT_MOVED], observe);
  1857. }
  1858. }
  1859. }
  1860. function init() {
  1861. Components2.Slides.forEach((_Slide) => {
  1862. queryAll(_Slide.slide, IMAGE_SELECTOR).forEach((_img) => {
  1863. const src = getAttribute(_img, SRC_DATA_ATTRIBUTE);
  1864. const srcset = getAttribute(_img, SRCSET_DATA_ATTRIBUTE);
  1865. if (src !== _img.src || srcset !== _img.srcset) {
  1866. const _spinner = create("span", options.classes.spinner, _img.parentElement);
  1867. setAttribute(_spinner, ROLE, "presentation");
  1868. images.push({ _img, _Slide, src, srcset, _spinner });
  1869. display(_img, "none");
  1870. }
  1871. });
  1872. });
  1873. if (isSequential) {
  1874. loadNext();
  1875. }
  1876. }
  1877. function destroy() {
  1878. index = 0;
  1879. images = [];
  1880. }
  1881. function observe() {
  1882. images = images.filter((data) => {
  1883. if (data._Slide.isWithin(Splide2.index, options.perPage * ((options.preloadPages || 1) + 1))) {
  1884. return load(data);
  1885. }
  1886. return true;
  1887. });
  1888. if (!images.length) {
  1889. off(EVENT_MOVED);
  1890. }
  1891. }
  1892. function load(data) {
  1893. const { _img } = data;
  1894. addClass(data._Slide.slide, CLASS_LOADING);
  1895. bind(_img, "load error", (e) => {
  1896. onLoad(data, e.type === "error");
  1897. });
  1898. ["src", "srcset"].forEach((name) => {
  1899. if (data[name]) {
  1900. setAttribute(_img, name, data[name]);
  1901. removeAttribute(_img, name === "src" ? SRC_DATA_ATTRIBUTE : SRCSET_DATA_ATTRIBUTE);
  1902. }
  1903. });
  1904. }
  1905. function onLoad(data, error) {
  1906. const { _Slide } = data;
  1907. removeClass(_Slide.slide, CLASS_LOADING);
  1908. if (!error) {
  1909. remove(data._spinner);
  1910. display(data._img, "");
  1911. emit(EVENT_LAZYLOAD_LOADED, data._img, _Slide);
  1912. emit(EVENT_RESIZE);
  1913. }
  1914. if (isSequential) {
  1915. loadNext();
  1916. }
  1917. }
  1918. function loadNext() {
  1919. if (index < images.length) {
  1920. load(images[index++]);
  1921. }
  1922. }
  1923. return {
  1924. mount,
  1925. destroy
  1926. };
  1927. }
  1928. function Pagination(Splide2, Components2, options) {
  1929. const { on, emit, bind, unbind } = EventInterface(Splide2);
  1930. const { Slides, Elements, Controller } = Components2;
  1931. const { hasFocus, getIndex } = Controller;
  1932. const items = [];
  1933. let list;
  1934. function mount() {
  1935. init();
  1936. on([EVENT_UPDATED, EVENT_REFRESH], init);
  1937. on([EVENT_MOVE, EVENT_SCROLLED], update);
  1938. }
  1939. function init() {
  1940. destroy();
  1941. if (options.pagination && Slides.isEnough()) {
  1942. createPagination();
  1943. emit(EVENT_PAGINATION_MOUNTED, { list, items }, getAt(Splide2.index));
  1944. update();
  1945. }
  1946. }
  1947. function destroy() {
  1948. if (list) {
  1949. remove(list);
  1950. items.forEach((item) => {
  1951. unbind(item.button, "click");
  1952. });
  1953. empty(items);
  1954. list = null;
  1955. }
  1956. }
  1957. function createPagination() {
  1958. const { length } = Splide2;
  1959. const { classes, i18n, perPage } = options;
  1960. const parent = options.pagination === "slider" && Elements.slider || Elements.root;
  1961. const max = hasFocus() ? length : ceil(length / perPage);
  1962. list = create("ul", classes.pagination, parent);
  1963. for (let i = 0; i < max; i++) {
  1964. const li = create("li", null, list);
  1965. const button = create("button", { class: classes.page, type: "button" }, li);
  1966. const controls = Slides.getIn(i).map((Slide) => Slide.slide.id);
  1967. const text = !hasFocus() && perPage > 1 ? i18n.pageX : i18n.slideX;
  1968. bind(button, "click", onClick.bind(null, i));
  1969. setAttribute(button, ARIA_CONTROLS, controls.join(" "));
  1970. setAttribute(button, ARIA_LABEL, format(text, i + 1));
  1971. items.push({ li, button, page: i });
  1972. }
  1973. }
  1974. function onClick(page) {
  1975. Controller.go(`>${page}`, true, () => {
  1976. const Slide = Slides.getAt(Controller.toIndex(page));
  1977. Slide && Slide.slide.focus();
  1978. });
  1979. }
  1980. function getAt(index) {
  1981. return items[Controller.toPage(index)];
  1982. }
  1983. function update() {
  1984. const prev = getAt(getIndex(true));
  1985. const curr = getAt(getIndex());
  1986. if (prev) {
  1987. removeClass(prev.button, CLASS_ACTIVE);
  1988. removeAttribute(prev.button, ARIA_CURRENT);
  1989. }
  1990. if (curr) {
  1991. addClass(curr.button, CLASS_ACTIVE);
  1992. setAttribute(curr.button, ARIA_CURRENT, true);
  1993. }
  1994. emit(EVENT_PAGINATION_UPDATED, { list, items }, prev, curr);
  1995. }
  1996. return {
  1997. items,
  1998. mount,
  1999. destroy,
  2000. getAt
  2001. };
  2002. }
  2003. const TRIGGER_KEYS = [" ", "Enter", "Spacebar"];
  2004. function Sync(Splide2, Components2, options) {
  2005. const { splides } = Splide2;
  2006. const { list } = Components2.Elements;
  2007. function mount() {
  2008. if (options.isNavigation) {
  2009. navigate();
  2010. } else {
  2011. sync();
  2012. }
  2013. }
  2014. function destroy() {
  2015. removeAttribute(list, ALL_ATTRIBUTES);
  2016. }
  2017. function sync() {
  2018. const processed = [];
  2019. splides.concat(Splide2).forEach((splide, index, instances) => {
  2020. EventInterface(splide).on(EVENT_MOVE, (index2, prev, dest) => {
  2021. instances.forEach((instance) => {
  2022. if (instance !== splide && !includes(processed, splide)) {
  2023. processed.push(instance);
  2024. instance.go(instance.is(LOOP) ? dest : index2);
  2025. }
  2026. });
  2027. empty(processed);
  2028. });
  2029. });
  2030. }
  2031. function navigate() {
  2032. const { on, emit } = EventInterface(Splide2);
  2033. on(EVENT_CLICK, onClick);
  2034. on(EVENT_SLIDE_KEYDOWN, onKeydown);
  2035. on([EVENT_MOUNTED, EVENT_UPDATED], update);
  2036. setAttribute(list, ROLE, "menu");
  2037. emit(EVENT_NAVIGATION_MOUNTED, Splide2.splides);
  2038. }
  2039. function update() {
  2040. setAttribute(list, ARIA_ORIENTATION, options.direction !== TTB ? "horizontal" : null);
  2041. }
  2042. function onClick(Slide) {
  2043. Splide2.go(Slide.index);
  2044. }
  2045. function onKeydown(Slide, e) {
  2046. if (includes(TRIGGER_KEYS, e.key)) {
  2047. onClick(Slide);
  2048. prevent(e);
  2049. }
  2050. }
  2051. return {
  2052. mount,
  2053. destroy
  2054. };
  2055. }
  2056. function Wheel(Splide2, Components2, options) {
  2057. const { bind } = EventInterface(Splide2);
  2058. function mount() {
  2059. if (options.wheel) {
  2060. bind(Components2.Elements.track, "wheel", onWheel, { passive: false, capture: true });
  2061. }
  2062. }
  2063. function onWheel(e) {
  2064. const { deltaY } = e;
  2065. if (deltaY) {
  2066. Splide2.go(deltaY < 0 ? "<" : ">");
  2067. prevent(e);
  2068. }
  2069. }
  2070. return {
  2071. mount
  2072. };
  2073. }
  2074. var ComponentConstructors = /*#__PURE__*/Object.freeze({
  2075. __proto__: null,
  2076. Options: Options,
  2077. Direction: Direction,
  2078. Elements: Elements,
  2079. Style: Style$1,
  2080. Slides: Slides,
  2081. Clones: Clones,
  2082. Layout: Layout,
  2083. Move: Move,
  2084. Controller: Controller,
  2085. Arrows: Arrows,
  2086. Autoplay: Autoplay,
  2087. Cover: Cover,
  2088. Scroll: Scroll,
  2089. Drag: Drag,
  2090. Keyboard: Keyboard,
  2091. LazyLoad: LazyLoad,
  2092. Pagination: Pagination,
  2093. Sync: Sync,
  2094. Wheel: Wheel
  2095. });
  2096. const I18N = {
  2097. prev: "Previous slide",
  2098. next: "Next slide",
  2099. first: "Go to first slide",
  2100. last: "Go to last slide",
  2101. slideX: "Go to slide %s",
  2102. pageX: "Go to page %s",
  2103. play: "Start autoplay",
  2104. pause: "Pause autoplay"
  2105. };
  2106. const DEFAULTS = {
  2107. type: "slide",
  2108. speed: 400,
  2109. waitForTransition: true,
  2110. perPage: 1,
  2111. arrows: true,
  2112. pagination: true,
  2113. interval: 5e3,
  2114. pauseOnHover: true,
  2115. pauseOnFocus: true,
  2116. resetProgress: true,
  2117. easing: "cubic-bezier(.42,.65,.27,.99)",
  2118. drag: true,
  2119. direction: "ltr",
  2120. slideFocus: true,
  2121. trimSpace: true,
  2122. focusableNodes: "a, button, textarea, input, select, iframe",
  2123. classes: CLASSES,
  2124. i18n: I18N
  2125. };
  2126. function Fade(Splide2, Components2, options) {
  2127. const { on } = EventInterface(Splide2);
  2128. const { ruleBy } = Components2.Style;
  2129. function mount() {
  2130. on([EVENT_MOUNTED, EVENT_REFRESH], () => {
  2131. nextTick(() => {
  2132. Components2.Slides.forEach((Slide) => {
  2133. ruleBy(Slide.slide, "transition", `opacity ${options.speed}ms ${options.easing}`);
  2134. });
  2135. });
  2136. });
  2137. }
  2138. function start(index, done) {
  2139. const { track } = Components2.Elements;
  2140. ruleBy(track, "height", unit(rect(track).height));
  2141. nextTick(() => {
  2142. done();
  2143. ruleBy(track, "height", "");
  2144. });
  2145. }
  2146. return {
  2147. mount,
  2148. start,
  2149. cancel: noop
  2150. };
  2151. }
  2152. function Slide(Splide2, Components2, options) {
  2153. const { bind } = EventInterface(Splide2);
  2154. const { Move, Controller } = Components2;
  2155. const { list } = Components2.Elements;
  2156. let endCallback;
  2157. function mount() {
  2158. bind(list, "transitionend", (e) => {
  2159. if (e.target === list && endCallback) {
  2160. cancel();
  2161. endCallback();
  2162. }
  2163. });
  2164. }
  2165. function start(index, done) {
  2166. const destination = Move.toPosition(index, true);
  2167. const position = Move.getPosition();
  2168. const speed = getSpeed(index);
  2169. if (abs(destination - position) >= 1 && speed >= 1) {
  2170. apply(`transform ${speed}ms ${options.easing}`);
  2171. Move.translate(destination, true);
  2172. endCallback = done;
  2173. } else {
  2174. Move.jump(index);
  2175. done();
  2176. }
  2177. }
  2178. function cancel() {
  2179. apply("");
  2180. }
  2181. function getSpeed(index) {
  2182. const { rewindSpeed } = options;
  2183. if (Splide2.is(SLIDE) && rewindSpeed) {
  2184. const prev = Controller.getIndex(true);
  2185. const end = Controller.getEnd();
  2186. if (prev === 0 && index >= end || prev >= end && index === 0) {
  2187. return rewindSpeed;
  2188. }
  2189. }
  2190. return options.speed;
  2191. }
  2192. function apply(transition) {
  2193. Components2.Style.ruleBy(list, "transition", transition);
  2194. }
  2195. return {
  2196. mount,
  2197. start,
  2198. cancel
  2199. };
  2200. }
  2201. const _Splide = class {
  2202. constructor(target, options) {
  2203. this.event = EventBus();
  2204. this.Components = {};
  2205. this.state = State(CREATED);
  2206. this.splides = [];
  2207. this._options = {};
  2208. this._Extensions = {};
  2209. const root = isString(target) ? query(document, target) : target;
  2210. assert(root, `${root} is invalid.`);
  2211. this.root = root;
  2212. merge(DEFAULTS, _Splide.defaults);
  2213. merge(merge(this._options, DEFAULTS), options || {});
  2214. }
  2215. mount(Extensions, Transition) {
  2216. const { state, Components: Components2 } = this;
  2217. assert(state.is([CREATED, DESTROYED]), "Already mounted!");
  2218. state.set(CREATED);
  2219. this._Components = Components2;
  2220. this._Transition = Transition || this._Transition || (this.is(FADE) ? Fade : Slide);
  2221. this._Extensions = Extensions || this._Extensions;
  2222. const Constructors = assign({}, ComponentConstructors, this._Extensions, { Transition: this._Transition });
  2223. forOwn(Constructors, (Component, key) => {
  2224. const component = Component(this, Components2, this._options);
  2225. Components2[key] = component;
  2226. component.setup && component.setup();
  2227. });
  2228. forOwn(Components2, (component) => {
  2229. component.mount && component.mount();
  2230. });
  2231. this.emit(EVENT_MOUNTED);
  2232. addClass(this.root, CLASS_INITIALIZED);
  2233. state.set(IDLE);
  2234. this.emit(EVENT_READY);
  2235. return this;
  2236. }
  2237. sync(splide) {
  2238. this.splides.push(splide);
  2239. splide.splides.push(this);
  2240. return this;
  2241. }
  2242. go(control) {
  2243. this._Components.Controller.go(control);
  2244. return this;
  2245. }
  2246. on(events, callback) {
  2247. this.event.on(events, callback, null, DEFAULT_USER_EVENT_PRIORITY);
  2248. return this;
  2249. }
  2250. off(events) {
  2251. this.event.off(events);
  2252. return this;
  2253. }
  2254. emit(event) {
  2255. this.event.emit(event, ...slice(arguments, 1));
  2256. return this;
  2257. }
  2258. add(slides, index) {
  2259. this._Components.Slides.add(slides, index);
  2260. return this;
  2261. }
  2262. remove(matcher) {
  2263. this._Components.Slides.remove(matcher);
  2264. return this;
  2265. }
  2266. is(type) {
  2267. return this._options.type === type;
  2268. }
  2269. refresh() {
  2270. this.emit(EVENT_REFRESH);
  2271. return this;
  2272. }
  2273. destroy(completely = true) {
  2274. const { event, state } = this;
  2275. if (state.is(CREATED)) {
  2276. event.on(EVENT_READY, this.destroy.bind(this, completely), this);
  2277. } else {
  2278. forOwn(this._Components, (component) => {
  2279. component.destroy && component.destroy(completely);
  2280. });
  2281. event.emit(EVENT_DESTROY);
  2282. event.destroy();
  2283. empty(this.splides);
  2284. state.set(DESTROYED);
  2285. }
  2286. return this;
  2287. }
  2288. get options() {
  2289. return this._options;
  2290. }
  2291. set options(options) {
  2292. const { _options } = this;
  2293. merge(_options, options);
  2294. if (!this.state.is(CREATED)) {
  2295. this.emit(EVENT_UPDATED, _options);
  2296. }
  2297. }
  2298. get length() {
  2299. return this._Components.Slides.getLength(true);
  2300. }
  2301. get index() {
  2302. return this._Components.Controller.getIndex();
  2303. }
  2304. };
  2305. let Splide = _Splide;
  2306. Splide.defaults = {};
  2307. Splide.STATES = STATES;
  2308. const CLASS_RENDERED = "is-rendered";
  2309. const RENDERER_DEFAULT_CONFIG = {
  2310. listTag: "ul",
  2311. slideTag: "li"
  2312. };
  2313. class Style {
  2314. constructor(id, options) {
  2315. this.styles = {};
  2316. this.id = id;
  2317. this.options = options;
  2318. }
  2319. rule(selector, prop, value, breakpoint) {
  2320. breakpoint = breakpoint || "default";
  2321. const selectors = this.styles[breakpoint] = this.styles[breakpoint] || {};
  2322. const styles = selectors[selector] = selectors[selector] || {};
  2323. styles[prop] = value;
  2324. }
  2325. build() {
  2326. let css = "";
  2327. if (this.styles.default) {
  2328. css += this.buildSelectors(this.styles.default);
  2329. }
  2330. Object.keys(this.styles).sort((n, m) => this.options.mediaQuery === "min" ? +n - +m : +m - +n).forEach((breakpoint) => {
  2331. if (breakpoint !== "default") {
  2332. css += `@media screen and (max-width: ${breakpoint}px) {`;
  2333. css += this.buildSelectors(this.styles[breakpoint]);
  2334. css += `}`;
  2335. }
  2336. });
  2337. return css;
  2338. }
  2339. buildSelectors(selectors) {
  2340. let css = "";
  2341. forOwn(selectors, (styles, selector) => {
  2342. css += `#${this.id} ${selector} {`;
  2343. forOwn(styles, (value, prop) => {
  2344. if (value || value === 0) {
  2345. css += `${prop}: ${value};`;
  2346. }
  2347. });
  2348. css += "}";
  2349. });
  2350. return css;
  2351. }
  2352. }
  2353. class SplideRenderer {
  2354. constructor(contents, options, config, defaults) {
  2355. this.slides = [];
  2356. this.options = {};
  2357. this.breakpoints = [];
  2358. merge(DEFAULTS, defaults || {});
  2359. merge(merge(this.options, DEFAULTS), options || {});
  2360. this.contents = contents;
  2361. this.config = assign({}, RENDERER_DEFAULT_CONFIG, config || {});
  2362. this.id = this.config.id || uniqueId("splide");
  2363. this.Style = new Style(this.id, this.options);
  2364. this.Direction = Direction(null, null, this.options);
  2365. assert(this.contents.length, "Provide at least 1 content.");
  2366. this.init();
  2367. }
  2368. static clean(splide) {
  2369. const { on } = EventInterface(splide);
  2370. const { root } = splide;
  2371. const clones = queryAll(root, `.${CLASS_CLONE}`);
  2372. on(EVENT_MOUNTED, () => {
  2373. remove(child(root, "style"));
  2374. });
  2375. remove(clones);
  2376. }
  2377. init() {
  2378. this.parseBreakpoints();
  2379. this.initSlides();
  2380. this.registerRootStyles();
  2381. this.registerTrackStyles();
  2382. this.registerSlideStyles();
  2383. this.registerListStyles();
  2384. }
  2385. initSlides() {
  2386. push(this.slides, this.contents.map((content, index) => {
  2387. content = isString(content) ? { html: content } : content;
  2388. content.styles = content.styles || {};
  2389. content.attrs = content.attrs || {};
  2390. this.cover(content);
  2391. const classes = `${this.options.classes.slide} ${index === 0 ? CLASS_ACTIVE : ""}`;
  2392. assign(content.attrs, {
  2393. class: `${classes} ${content.attrs.class || ""}`.trim(),
  2394. style: this.buildStyles(content.styles)
  2395. });
  2396. return content;
  2397. }));
  2398. if (this.isLoop()) {
  2399. this.generateClones(this.slides);
  2400. }
  2401. }
  2402. registerRootStyles() {
  2403. this.breakpoints.forEach(([width, options]) => {
  2404. this.Style.rule(" ", "max-width", unit(options.width), width);
  2405. });
  2406. }
  2407. registerTrackStyles() {
  2408. const { Style: Style2 } = this;
  2409. const selector = `.${CLASS_TRACK}`;
  2410. this.breakpoints.forEach(([width, options]) => {
  2411. Style2.rule(selector, this.resolve("paddingLeft"), this.cssPadding(options, false), width);
  2412. Style2.rule(selector, this.resolve("paddingRight"), this.cssPadding(options, true), width);
  2413. Style2.rule(selector, "height", this.cssTrackHeight(options), width);
  2414. });
  2415. }
  2416. registerListStyles() {
  2417. const { Style: Style2 } = this;
  2418. const selector = `.${CLASS_LIST}`;
  2419. this.breakpoints.forEach(([width, options]) => {
  2420. Style2.rule(selector, "transform", this.buildTranslate(options), width);
  2421. });
  2422. }
  2423. registerSlideStyles() {
  2424. const { Style: Style2 } = this;
  2425. const selector = `.${CLASS_SLIDE}`;
  2426. this.breakpoints.forEach(([width, options]) => {
  2427. Style2.rule(selector, "width", this.cssSlideWidth(options), width);
  2428. Style2.rule(selector, this.resolve("marginRight"), unit(options.gap) || "0px", width);
  2429. const height = this.cssSlideHeight(options);
  2430. if (height) {
  2431. Style2.rule(selector, "height", height, width);
  2432. } else {
  2433. Style2.rule(selector, "padding-top", this.cssSlidePadding(options), width);
  2434. }
  2435. Style2.rule(`${selector} > img`, "display", options.cover ? "none" : "inline", width);
  2436. });
  2437. }
  2438. buildTranslate(options) {
  2439. const { resolve, orient } = this.Direction;
  2440. const values = [];
  2441. values.push(this.cssOffsetClones(options));
  2442. values.push(this.cssOffsetGaps(options));
  2443. if (this.isCenter(options)) {
  2444. values.push(this.buildCssValue(orient(-50), "%"));
  2445. values.push(...this.cssOffsetCenter(options));
  2446. }
  2447. return values.filter(Boolean).map((value) => `translate${resolve("X")}(${value})`).join(" ");
  2448. }
  2449. cssOffsetClones(options) {
  2450. const { resolve, orient } = this.Direction;
  2451. const cloneCount = this.getCloneCount();
  2452. if (this.isFixedWidth(options)) {
  2453. const { value, unit: unit2 } = this.parseCssValue(options[resolve("fixedWidth")]);
  2454. return this.buildCssValue(orient(value) * cloneCount, unit2);
  2455. }
  2456. const percent = 100 * cloneCount / options.perPage;
  2457. return `${orient(percent)}%`;
  2458. }
  2459. cssOffsetCenter(options) {
  2460. const { resolve, orient } = this.Direction;
  2461. if (this.isFixedWidth(options)) {
  2462. const { value, unit: unit2 } = this.parseCssValue(options[resolve("fixedWidth")]);
  2463. return [this.buildCssValue(orient(value / 2), unit2)];
  2464. }
  2465. const values = [];
  2466. const { perPage, gap } = options;
  2467. values.push(`${orient(50 / perPage)}%`);
  2468. if (gap) {
  2469. const { value, unit: unit2 } = this.parseCssValue(gap);
  2470. const gapOffset = (value / perPage - value) / 2;
  2471. values.push(this.buildCssValue(orient(gapOffset), unit2));
  2472. }
  2473. return values;
  2474. }
  2475. cssOffsetGaps(options) {
  2476. const cloneCount = this.getCloneCount();
  2477. if (cloneCount && options.gap) {
  2478. const { orient } = this.Direction;
  2479. const { value, unit: unit2 } = this.parseCssValue(options.gap);
  2480. if (this.isFixedWidth(options)) {
  2481. return this.buildCssValue(orient(value * cloneCount), unit2);
  2482. }
  2483. const { perPage } = options;
  2484. const gaps = cloneCount / perPage;
  2485. return this.buildCssValue(orient(gaps * value), unit2);
  2486. }
  2487. return "";
  2488. }
  2489. resolve(prop) {
  2490. return camelToKebab(this.Direction.resolve(prop));
  2491. }
  2492. cssPadding(options, right) {
  2493. const { padding } = options;
  2494. const prop = this.Direction.resolve(right ? "right" : "left", true);
  2495. return padding && unit(padding[prop] || (isObject(padding) ? 0 : padding)) || "0px";
  2496. }
  2497. cssTrackHeight(options) {
  2498. let height = "";
  2499. if (this.isVertical()) {
  2500. height = this.cssHeight(options);
  2501. assert(height, '"height" is missing.');
  2502. height = `calc(${height} - ${this.cssPadding(options, false)} - ${this.cssPadding(options, true)})`;
  2503. }
  2504. return height;
  2505. }
  2506. cssHeight(options) {
  2507. return unit(options.height);
  2508. }
  2509. cssSlideWidth(options) {
  2510. return options.autoWidth ? "" : unit(options.fixedWidth) || (this.isVertical() ? "" : this.cssSlideSize(options));
  2511. }
  2512. cssSlideHeight(options) {
  2513. return unit(options.fixedHeight) || (this.isVertical() ? options.autoHeight ? "" : this.cssSlideSize(options) : this.cssHeight(options));
  2514. }
  2515. cssSlideSize(options) {
  2516. const gap = unit(options.gap);
  2517. return `calc((100%${gap && ` + ${gap}`})/${options.perPage || 1}${gap && ` - ${gap}`})`;
  2518. }
  2519. cssSlidePadding(options) {
  2520. const { heightRatio } = options;
  2521. return heightRatio ? `${heightRatio * 100}%` : "";
  2522. }
  2523. buildCssValue(value, unit2) {
  2524. return `${value}${unit2}`;
  2525. }
  2526. parseCssValue(value) {
  2527. if (isString(value)) {
  2528. const number = parseFloat(value) || 0;
  2529. const unit2 = value.replace(/\d*(\.\d*)?/, "") || "px";
  2530. return { value: number, unit: unit2 };
  2531. }
  2532. return { value, unit: "px" };
  2533. }
  2534. parseBreakpoints() {
  2535. const { breakpoints } = this.options;
  2536. this.breakpoints.push(["default", this.options]);
  2537. if (breakpoints) {
  2538. forOwn(breakpoints, (options, width) => {
  2539. this.breakpoints.push([width, merge(merge({}, this.options), options)]);
  2540. });
  2541. }
  2542. }
  2543. isFixedWidth(options) {
  2544. return !!options[this.Direction.resolve("fixedWidth")];
  2545. }
  2546. isLoop() {
  2547. return this.options.type === LOOP;
  2548. }
  2549. isCenter(options) {
  2550. if (options.focus === "center") {
  2551. if (this.isLoop()) {
  2552. return true;
  2553. }
  2554. if (this.options.type === SLIDE) {
  2555. return !this.options.trimSpace;
  2556. }
  2557. }
  2558. return false;
  2559. }
  2560. isVertical() {
  2561. return this.options.direction === TTB;
  2562. }
  2563. buildClasses() {
  2564. const { options } = this;
  2565. return [
  2566. CLASS_ROOT,
  2567. `${CLASS_ROOT}--${options.type}`,
  2568. `${CLASS_ROOT}--${options.direction}`,
  2569. options.drag && `${CLASS_ROOT}--draggable`,
  2570. options.isNavigation && `${CLASS_ROOT}--nav`,
  2571. CLASS_ACTIVE,
  2572. !this.config.hidden && CLASS_RENDERED
  2573. ].filter(Boolean).join(" ");
  2574. }
  2575. buildAttrs(attrs) {
  2576. let attr = "";
  2577. forOwn(attrs, (value, key) => {
  2578. attr += value ? ` ${camelToKebab(key)}="${value}"` : "";
  2579. });
  2580. return attr.trim();
  2581. }
  2582. buildStyles(styles) {
  2583. let style = "";
  2584. forOwn(styles, (value, key) => {
  2585. style += ` ${camelToKebab(key)}:${value};`;
  2586. });
  2587. return style.trim();
  2588. }
  2589. renderSlides() {
  2590. const { slideTag: tag } = this.config;
  2591. return this.slides.map((content) => {
  2592. return `<${tag} ${this.buildAttrs(content.attrs)}>${content.html || ""}</${tag}>`;
  2593. }).join("");
  2594. }
  2595. cover(content) {
  2596. const { styles, html = "" } = content;
  2597. if (this.options.cover && !this.options.lazyLoad) {
  2598. const src = html.match(/<img.*?src\s*=\s*(['"])(.+?)\1.*?>/);
  2599. if (src && src[2]) {
  2600. styles.background = `center/cover no-repeat url('${src[2]}')`;
  2601. }
  2602. }
  2603. }
  2604. generateClones(contents) {
  2605. const { classes } = this.options;
  2606. const count = this.getCloneCount();
  2607. const slides = contents.slice();
  2608. while (slides.length < count) {
  2609. push(slides, slides);
  2610. }
  2611. push(slides.slice(-count).reverse(), slides.slice(0, count)).forEach((content, index) => {
  2612. const attrs = assign({}, content.attrs, { class: `${content.attrs.class} ${classes.clone}` });
  2613. const clone = assign({}, content, { attrs });
  2614. index < count ? contents.unshift(clone) : contents.push(clone);
  2615. });
  2616. }
  2617. getCloneCount() {
  2618. if (this.isLoop()) {
  2619. const { options } = this;
  2620. if (options.clones) {
  2621. return options.clones;
  2622. }
  2623. const perPage = max(...this.breakpoints.map(([, options2]) => options2.perPage));
  2624. return perPage * ((options.flickMaxPages || 1) + 1);
  2625. }
  2626. return 0;
  2627. }
  2628. renderArrows() {
  2629. let html = "";
  2630. html += `<div class="${this.options.classes.arrows}">`;
  2631. html += this.renderArrow(true);
  2632. html += this.renderArrow(false);
  2633. html += `</div>`;
  2634. return html;
  2635. }
  2636. renderArrow(prev) {
  2637. const { classes, i18n } = this.options;
  2638. const attrs = {
  2639. class: `${classes.arrow} ${prev ? classes.prev : classes.next}`,
  2640. type: "button",
  2641. ariaLabel: prev ? i18n.prev : i18n.next
  2642. };
  2643. return `<button ${this.buildAttrs(attrs)}><svg xmlns="${XML_NAME_SPACE}" viewBox="0 0 ${SIZE} ${SIZE}" width="${SIZE}" height="${SIZE}"><path d="${this.options.arrowPath || PATH}" /></svg></button>`;
  2644. }
  2645. html() {
  2646. const { rootClass, listTag, arrows, beforeTrack, afterTrack, slider, beforeSlider, afterSlider } = this.config;
  2647. let html = "";
  2648. html += `<div id="${this.id}" class="${this.buildClasses()} ${rootClass || ""}">`;
  2649. html += `<style>${this.Style.build()}</style>`;
  2650. if (slider) {
  2651. html += beforeSlider || "";
  2652. html += `<div class="splide__slider">`;
  2653. }
  2654. html += beforeTrack || "";
  2655. if (arrows) {
  2656. html += this.renderArrows();
  2657. }
  2658. html += `<div class="splide__track">`;
  2659. html += `<${listTag} class="splide__list">`;
  2660. html += this.renderSlides();
  2661. html += `</${listTag}>`;
  2662. html += `</div>`;
  2663. html += afterTrack || "";
  2664. if (slider) {
  2665. html += `</div>`;
  2666. html += afterSlider || "";
  2667. }
  2668. html += `</div>`;
  2669. return html;
  2670. }
  2671. }
  2672. exports.CLASSES = CLASSES;
  2673. exports.CLASS_ACTIVE = CLASS_ACTIVE;
  2674. exports.CLASS_ARROW = CLASS_ARROW;
  2675. exports.CLASS_ARROWS = CLASS_ARROWS;
  2676. exports.CLASS_ARROW_NEXT = CLASS_ARROW_NEXT;
  2677. exports.CLASS_ARROW_PREV = CLASS_ARROW_PREV;
  2678. exports.CLASS_AUTOPLAY = CLASS_AUTOPLAY;
  2679. exports.CLASS_CLONE = CLASS_CLONE;
  2680. exports.CLASS_CONTAINER = CLASS_CONTAINER;
  2681. exports.CLASS_INITIALIZED = CLASS_INITIALIZED;
  2682. exports.CLASS_LIST = CLASS_LIST;
  2683. exports.CLASS_LOADING = CLASS_LOADING;
  2684. exports.CLASS_NEXT = CLASS_NEXT;
  2685. exports.CLASS_PAGINATION = CLASS_PAGINATION;
  2686. exports.CLASS_PAGINATION_PAGE = CLASS_PAGINATION_PAGE;
  2687. exports.CLASS_PAUSE = CLASS_PAUSE;
  2688. exports.CLASS_PLAY = CLASS_PLAY;
  2689. exports.CLASS_PREV = CLASS_PREV;
  2690. exports.CLASS_PROGRESS = CLASS_PROGRESS;
  2691. exports.CLASS_PROGRESS_BAR = CLASS_PROGRESS_BAR;
  2692. exports.CLASS_ROOT = CLASS_ROOT;
  2693. exports.CLASS_SLIDE = CLASS_SLIDE;
  2694. exports.CLASS_SLIDER = CLASS_SLIDER;
  2695. exports.CLASS_SPINNER = CLASS_SPINNER;
  2696. exports.CLASS_TRACK = CLASS_TRACK;
  2697. exports.CLASS_VISIBLE = CLASS_VISIBLE;
  2698. exports.EVENT_ACTIVE = EVENT_ACTIVE;
  2699. exports.EVENT_ARROWS_MOUNTED = EVENT_ARROWS_MOUNTED;
  2700. exports.EVENT_ARROWS_UPDATED = EVENT_ARROWS_UPDATED;
  2701. exports.EVENT_AUTOPLAY_PAUSE = EVENT_AUTOPLAY_PAUSE;
  2702. exports.EVENT_AUTOPLAY_PLAY = EVENT_AUTOPLAY_PLAY;
  2703. exports.EVENT_AUTOPLAY_PLAYING = EVENT_AUTOPLAY_PLAYING;
  2704. exports.EVENT_CLICK = EVENT_CLICK;
  2705. exports.EVENT_DESTROY = EVENT_DESTROY;
  2706. exports.EVENT_DRAG = EVENT_DRAG;
  2707. exports.EVENT_DRAGGED = EVENT_DRAGGED;
  2708. exports.EVENT_DRAGGING = EVENT_DRAGGING;
  2709. exports.EVENT_HIDDEN = EVENT_HIDDEN;
  2710. exports.EVENT_INACTIVE = EVENT_INACTIVE;
  2711. exports.EVENT_LAZYLOAD_LOADED = EVENT_LAZYLOAD_LOADED;
  2712. exports.EVENT_MOUNTED = EVENT_MOUNTED;
  2713. exports.EVENT_MOVE = EVENT_MOVE;
  2714. exports.EVENT_MOVED = EVENT_MOVED;
  2715. exports.EVENT_NAVIGATION_MOUNTED = EVENT_NAVIGATION_MOUNTED;
  2716. exports.EVENT_PAGINATION_MOUNTED = EVENT_PAGINATION_MOUNTED;
  2717. exports.EVENT_PAGINATION_UPDATED = EVENT_PAGINATION_UPDATED;
  2718. exports.EVENT_READY = EVENT_READY;
  2719. exports.EVENT_REFRESH = EVENT_REFRESH;
  2720. exports.EVENT_REPOSITIONED = EVENT_REPOSITIONED;
  2721. exports.EVENT_RESIZE = EVENT_RESIZE;
  2722. exports.EVENT_RESIZED = EVENT_RESIZED;
  2723. exports.EVENT_SCROLL = EVENT_SCROLL;
  2724. exports.EVENT_SCROLLED = EVENT_SCROLLED;
  2725. exports.EVENT_SLIDE_KEYDOWN = EVENT_SLIDE_KEYDOWN;
  2726. exports.EVENT_UPDATED = EVENT_UPDATED;
  2727. exports.EVENT_VISIBLE = EVENT_VISIBLE;
  2728. exports.EventBus = EventBus;
  2729. exports.EventInterface = EventInterface;
  2730. exports.RequestInterval = RequestInterval;
  2731. exports.STATUS_CLASSES = STATUS_CLASSES;
  2732. exports.Splide = Splide;
  2733. exports.SplideRenderer = SplideRenderer;
  2734. exports.State = State;
  2735. exports.Throttle = Throttle;
  2736. exports['default'] = Splide;