splide.cjs.js 78 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830
  1. /*!
  2. * Splide.js
  3. * Version : 3.0.0
  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 { track } = Components2.Elements;
  1650. const { resolve, orient } = Components2.Direction;
  1651. const { getPosition, exceededLimit } = Move;
  1652. const isSlide = Splide2.is(SLIDE);
  1653. const isFade = Splide2.is(FADE);
  1654. let basePosition;
  1655. let baseEvent;
  1656. let prevBaseEvent;
  1657. let lastEvent;
  1658. let isFree;
  1659. let isDragging;
  1660. let isMouse;
  1661. let hasExceeded = false;
  1662. let clickPrevented;
  1663. let disabled;
  1664. let target;
  1665. function mount() {
  1666. bind(track, POINTER_DOWN_EVENTS, onPointerDown, { passive: false, capture: true });
  1667. bind(track, "click", onClick, { capture: true });
  1668. on([EVENT_MOUNTED, EVENT_UPDATED], init);
  1669. }
  1670. function init() {
  1671. const { drag } = options;
  1672. disable(!drag);
  1673. isFree = drag === "free";
  1674. }
  1675. function onPointerDown(e) {
  1676. if (!disabled) {
  1677. isMouse = e.type === "mousedown";
  1678. if (!isMouse || !e.button) {
  1679. if (!Move.isBusy()) {
  1680. target = isMouse ? window : track;
  1681. prevBaseEvent = null;
  1682. lastEvent = null;
  1683. clickPrevented = false;
  1684. bind(target, POINTER_MOVE_EVENTS, onPointerMove);
  1685. bind(target, POINTER_UP_EVENTS, onPointerUp);
  1686. Move.cancel();
  1687. Scroll.cancel();
  1688. save(e);
  1689. } else {
  1690. prevent(e, true);
  1691. }
  1692. }
  1693. }
  1694. }
  1695. function onPointerMove(e) {
  1696. if (!lastEvent) {
  1697. clickPrevented = true;
  1698. emit(EVENT_DRAG);
  1699. }
  1700. lastEvent = e;
  1701. if (e.cancelable) {
  1702. if (isDragging) {
  1703. const expired = timeOf(e) - timeOf(baseEvent) > LOG_INTERVAL;
  1704. const exceeded = hasExceeded !== (hasExceeded = exceededLimit());
  1705. if (expired || exceeded) {
  1706. save(e);
  1707. }
  1708. if (!isFade) {
  1709. Move.translate(basePosition + constrain(coordOf(e) - coordOf(baseEvent)));
  1710. }
  1711. emit(EVENT_DRAGGING);
  1712. prevent(e);
  1713. } else {
  1714. const threshold = options.dragMinThreshold || 15;
  1715. isDragging = isMouse || abs(coordOf(e) - coordOf(baseEvent)) > threshold;
  1716. if (isSliderDirection()) {
  1717. prevent(e);
  1718. }
  1719. }
  1720. }
  1721. }
  1722. function onPointerUp(e) {
  1723. unbind(target, `${POINTER_MOVE_EVENTS} ${POINTER_UP_EVENTS}`);
  1724. if (lastEvent) {
  1725. if (isDragging || e.cancelable && isSliderDirection()) {
  1726. const velocity = computeVelocity(e);
  1727. const destination = computeDestination(velocity);
  1728. if (isFree) {
  1729. Scroll.scroll(destination);
  1730. } else if (isFade) {
  1731. Controller.go(Splide2.index + orient(sign(velocity)));
  1732. } else {
  1733. Controller.go(computeIndex(destination), true);
  1734. }
  1735. prevent(e);
  1736. }
  1737. emit(EVENT_DRAGGED);
  1738. }
  1739. isDragging = false;
  1740. }
  1741. function save(e) {
  1742. prevBaseEvent = baseEvent;
  1743. baseEvent = e;
  1744. basePosition = getPosition();
  1745. }
  1746. function onClick(e) {
  1747. if (!disabled && clickPrevented) {
  1748. prevent(e, true);
  1749. }
  1750. }
  1751. function isSliderDirection() {
  1752. const diffX = abs(coordOf(lastEvent) - coordOf(baseEvent));
  1753. const diffY = abs(coordOf(lastEvent, true) - coordOf(baseEvent, true));
  1754. return diffX > diffY;
  1755. }
  1756. function computeVelocity(e) {
  1757. if (Splide2.is(LOOP) || !hasExceeded) {
  1758. const base = baseEvent === lastEvent && prevBaseEvent || baseEvent;
  1759. const diffCoord = coordOf(lastEvent) - coordOf(base);
  1760. const diffTime = timeOf(e) - timeOf(base);
  1761. const isFlick = timeOf(e) - timeOf(lastEvent) < LOG_INTERVAL;
  1762. if (diffTime && isFlick) {
  1763. return diffCoord / diffTime;
  1764. }
  1765. }
  1766. return 0;
  1767. }
  1768. function computeDestination(velocity) {
  1769. return getPosition() + sign(velocity) * min(abs(velocity) * (options.flickPower || 600), isFree ? Infinity : Components2.Layout.listSize() * (options.flickMaxPages || 1));
  1770. }
  1771. function computeIndex(destination) {
  1772. const dest = Move.toIndex(destination);
  1773. return isSlide ? clamp(dest, 0, Controller.getEnd()) : dest;
  1774. }
  1775. function coordOf(e, orthogonal) {
  1776. const prop = `page${resolve(orthogonal ? "Y" : "X")}`;
  1777. return (isMouse ? e : e.touches[0])[prop];
  1778. }
  1779. function timeOf(e) {
  1780. return e.timeStamp;
  1781. }
  1782. function constrain(diff) {
  1783. return diff / (hasExceeded && isSlide ? FRICTION : 1);
  1784. }
  1785. function disable(value) {
  1786. disabled = value;
  1787. }
  1788. return {
  1789. mount,
  1790. disable
  1791. };
  1792. }
  1793. const IE_ARROW_KEYS = ["Left", "Right", "Up", "Down"];
  1794. function Keyboard(Splide2, Components2, options) {
  1795. const { on, bind, unbind } = EventInterface(Splide2);
  1796. const { root } = Components2.Elements;
  1797. const { resolve } = Components2.Direction;
  1798. let target;
  1799. function mount() {
  1800. init();
  1801. on(EVENT_UPDATED, () => {
  1802. destroy();
  1803. init();
  1804. });
  1805. }
  1806. function init() {
  1807. const { keyboard = "global" } = options;
  1808. if (keyboard) {
  1809. if (keyboard === "focused") {
  1810. target = root;
  1811. setAttribute(root, TAB_INDEX, 0);
  1812. } else {
  1813. target = window;
  1814. }
  1815. bind(target, "keydown", onKeydown);
  1816. }
  1817. }
  1818. function destroy() {
  1819. unbind(target, "keydown");
  1820. if (isHTMLElement(target)) {
  1821. removeAttribute(target, TAB_INDEX);
  1822. }
  1823. }
  1824. function onKeydown(e) {
  1825. const { key } = e;
  1826. const normalizedKey = includes(IE_ARROW_KEYS, key) ? `Arrow${key}` : key;
  1827. if (normalizedKey === resolve("ArrowLeft")) {
  1828. Splide2.go("<");
  1829. } else if (normalizedKey === resolve("ArrowRight")) {
  1830. Splide2.go(">");
  1831. }
  1832. }
  1833. return {
  1834. mount,
  1835. destroy
  1836. };
  1837. }
  1838. const SRC_DATA_ATTRIBUTE = `${DATA_ATTRIBUTE}-lazy`;
  1839. const SRCSET_DATA_ATTRIBUTE = `${SRC_DATA_ATTRIBUTE}-srcset`;
  1840. const IMAGE_SELECTOR = `[${SRC_DATA_ATTRIBUTE}], [${SRCSET_DATA_ATTRIBUTE}]`;
  1841. function LazyLoad(Splide2, Components2, options) {
  1842. const { on, off, bind, emit } = EventInterface(Splide2);
  1843. const isSequential = options.lazyLoad === "sequential";
  1844. let images = [];
  1845. let index = 0;
  1846. function mount() {
  1847. if (options.lazyLoad) {
  1848. on([EVENT_MOUNTED, EVENT_REFRESH], () => {
  1849. destroy();
  1850. init();
  1851. });
  1852. if (!isSequential) {
  1853. on([EVENT_MOUNTED, EVENT_REFRESH, EVENT_MOVED], observe);
  1854. }
  1855. }
  1856. }
  1857. function init() {
  1858. Components2.Slides.forEach((_Slide) => {
  1859. queryAll(_Slide.slide, IMAGE_SELECTOR).forEach((_img) => {
  1860. const src = getAttribute(_img, SRC_DATA_ATTRIBUTE);
  1861. const srcset = getAttribute(_img, SRCSET_DATA_ATTRIBUTE);
  1862. if (src !== _img.src || srcset !== _img.srcset) {
  1863. const _spinner = create("span", options.classes.spinner, _img.parentElement);
  1864. setAttribute(_spinner, ROLE, "presentation");
  1865. images.push({ _img, _Slide, src, srcset, _spinner });
  1866. display(_img, "none");
  1867. }
  1868. });
  1869. });
  1870. if (isSequential) {
  1871. loadNext();
  1872. }
  1873. }
  1874. function destroy() {
  1875. index = 0;
  1876. images = [];
  1877. }
  1878. function observe() {
  1879. images = images.filter((data) => {
  1880. if (data._Slide.isWithin(Splide2.index, options.perPage * ((options.preloadPages || 1) + 1))) {
  1881. return load(data);
  1882. }
  1883. return true;
  1884. });
  1885. if (!images.length) {
  1886. off(EVENT_MOVED);
  1887. }
  1888. }
  1889. function load(data) {
  1890. const { _img } = data;
  1891. addClass(data._Slide.slide, CLASS_LOADING);
  1892. bind(_img, "load error", (e) => {
  1893. onLoad(data, e.type === "error");
  1894. });
  1895. ["src", "srcset"].forEach((name) => {
  1896. if (data[name]) {
  1897. setAttribute(_img, name, data[name]);
  1898. removeAttribute(_img, name === "src" ? SRC_DATA_ATTRIBUTE : SRCSET_DATA_ATTRIBUTE);
  1899. }
  1900. });
  1901. }
  1902. function onLoad(data, error) {
  1903. const { _Slide } = data;
  1904. removeClass(_Slide.slide, CLASS_LOADING);
  1905. if (!error) {
  1906. remove(data._spinner);
  1907. display(data._img, "");
  1908. emit(EVENT_LAZYLOAD_LOADED, data._img, _Slide);
  1909. emit(EVENT_RESIZE);
  1910. }
  1911. if (isSequential) {
  1912. loadNext();
  1913. }
  1914. }
  1915. function loadNext() {
  1916. if (index < images.length) {
  1917. load(images[index++]);
  1918. }
  1919. }
  1920. return {
  1921. mount,
  1922. destroy
  1923. };
  1924. }
  1925. function Pagination(Splide2, Components2, options) {
  1926. const { on, emit, bind, unbind } = EventInterface(Splide2);
  1927. const { Slides, Elements, Controller } = Components2;
  1928. const { hasFocus, getIndex } = Controller;
  1929. const items = [];
  1930. let list;
  1931. function mount() {
  1932. init();
  1933. on([EVENT_UPDATED, EVENT_REFRESH], init);
  1934. on([EVENT_MOVE, EVENT_SCROLLED], update);
  1935. }
  1936. function init() {
  1937. destroy();
  1938. if (options.pagination && Slides.isEnough()) {
  1939. createPagination();
  1940. emit(EVENT_PAGINATION_MOUNTED, { list, items }, getAt(Splide2.index));
  1941. update();
  1942. }
  1943. }
  1944. function destroy() {
  1945. if (list) {
  1946. remove(list);
  1947. items.forEach((item) => {
  1948. unbind(item.button, "click");
  1949. });
  1950. empty(items);
  1951. list = null;
  1952. }
  1953. }
  1954. function createPagination() {
  1955. const { length } = Splide2;
  1956. const { classes, i18n, perPage } = options;
  1957. const parent = options.pagination === "slider" && Elements.slider || Elements.root;
  1958. const max = hasFocus() ? length : ceil(length / perPage);
  1959. list = create("ul", classes.pagination, parent);
  1960. for (let i = 0; i < max; i++) {
  1961. const li = create("li", null, list);
  1962. const button = create("button", { class: classes.page, type: "button" }, li);
  1963. const controls = Slides.getIn(i).map((Slide) => Slide.slide.id);
  1964. const text = !hasFocus() && perPage > 1 ? i18n.pageX : i18n.slideX;
  1965. bind(button, "click", onClick.bind(null, i));
  1966. setAttribute(button, ARIA_CONTROLS, controls.join(" "));
  1967. setAttribute(button, ARIA_LABEL, format(text, i + 1));
  1968. items.push({ li, button, page: i });
  1969. }
  1970. }
  1971. function onClick(page) {
  1972. Controller.go(`>${page}`, true, () => {
  1973. const Slide = Slides.getAt(Controller.toIndex(page));
  1974. Slide && Slide.slide.focus();
  1975. });
  1976. }
  1977. function getAt(index) {
  1978. return items[Controller.toPage(index)];
  1979. }
  1980. function update() {
  1981. const prev = getAt(getIndex(true));
  1982. const curr = getAt(getIndex());
  1983. if (prev) {
  1984. removeClass(prev.button, CLASS_ACTIVE);
  1985. removeAttribute(prev.button, ARIA_CURRENT);
  1986. }
  1987. if (curr) {
  1988. addClass(curr.button, CLASS_ACTIVE);
  1989. setAttribute(curr.button, ARIA_CURRENT, true);
  1990. }
  1991. emit(EVENT_PAGINATION_UPDATED, { list, items }, prev, curr);
  1992. }
  1993. return {
  1994. items,
  1995. mount,
  1996. destroy,
  1997. getAt
  1998. };
  1999. }
  2000. const TRIGGER_KEYS = [" ", "Enter", "Spacebar"];
  2001. function Sync(Splide2, Components2, options) {
  2002. const { splides } = Splide2;
  2003. const { list } = Components2.Elements;
  2004. function mount() {
  2005. if (options.isNavigation) {
  2006. navigate();
  2007. } else {
  2008. sync();
  2009. }
  2010. }
  2011. function destroy() {
  2012. removeAttribute(list, ALL_ATTRIBUTES);
  2013. }
  2014. function sync() {
  2015. const processed = [];
  2016. splides.concat(Splide2).forEach((splide, index, instances) => {
  2017. EventInterface(splide).on(EVENT_MOVE, (index2, prev, dest) => {
  2018. instances.forEach((instance) => {
  2019. if (instance !== splide && !includes(processed, splide)) {
  2020. processed.push(instance);
  2021. instance.go(instance.is(LOOP) ? dest : index2);
  2022. }
  2023. });
  2024. empty(processed);
  2025. });
  2026. });
  2027. }
  2028. function navigate() {
  2029. const { on, emit } = EventInterface(Splide2);
  2030. on(EVENT_CLICK, onClick);
  2031. on(EVENT_SLIDE_KEYDOWN, onKeydown);
  2032. on([EVENT_MOUNTED, EVENT_UPDATED], update);
  2033. setAttribute(list, ROLE, "menu");
  2034. emit(EVENT_NAVIGATION_MOUNTED, Splide2.splides);
  2035. }
  2036. function update() {
  2037. setAttribute(list, ARIA_ORIENTATION, options.direction !== TTB ? "horizontal" : null);
  2038. }
  2039. function onClick(Slide) {
  2040. Splide2.go(Slide.index);
  2041. }
  2042. function onKeydown(Slide, e) {
  2043. if (includes(TRIGGER_KEYS, e.key)) {
  2044. onClick(Slide);
  2045. prevent(e);
  2046. }
  2047. }
  2048. return {
  2049. mount,
  2050. destroy
  2051. };
  2052. }
  2053. function Wheel(Splide2, Components2, options) {
  2054. const { bind } = EventInterface(Splide2);
  2055. function mount() {
  2056. if (options.wheel) {
  2057. bind(Components2.Elements.track, "wheel", onWheel, { passive: false, capture: true });
  2058. }
  2059. }
  2060. function onWheel(e) {
  2061. const { deltaY } = e;
  2062. if (deltaY) {
  2063. Splide2.go(deltaY < 0 ? "<" : ">");
  2064. prevent(e);
  2065. }
  2066. }
  2067. return {
  2068. mount
  2069. };
  2070. }
  2071. var ComponentConstructors = /*#__PURE__*/Object.freeze({
  2072. __proto__: null,
  2073. Options: Options,
  2074. Direction: Direction,
  2075. Elements: Elements,
  2076. Style: Style$1,
  2077. Slides: Slides,
  2078. Clones: Clones,
  2079. Layout: Layout,
  2080. Move: Move,
  2081. Controller: Controller,
  2082. Arrows: Arrows,
  2083. Autoplay: Autoplay,
  2084. Cover: Cover,
  2085. Scroll: Scroll,
  2086. Drag: Drag,
  2087. Keyboard: Keyboard,
  2088. LazyLoad: LazyLoad,
  2089. Pagination: Pagination,
  2090. Sync: Sync,
  2091. Wheel: Wheel
  2092. });
  2093. const I18N = {
  2094. prev: "Previous slide",
  2095. next: "Next slide",
  2096. first: "Go to first slide",
  2097. last: "Go to last slide",
  2098. slideX: "Go to slide %s",
  2099. pageX: "Go to page %s",
  2100. play: "Start autoplay",
  2101. pause: "Pause autoplay"
  2102. };
  2103. const DEFAULTS = {
  2104. type: "slide",
  2105. speed: 400,
  2106. waitForTransition: true,
  2107. perPage: 1,
  2108. arrows: true,
  2109. pagination: true,
  2110. interval: 5e3,
  2111. pauseOnHover: true,
  2112. pauseOnFocus: true,
  2113. resetProgress: true,
  2114. easing: "cubic-bezier(.42,.65,.27,.99)",
  2115. drag: true,
  2116. direction: "ltr",
  2117. slideFocus: true,
  2118. trimSpace: true,
  2119. focusableNodes: "a, button, textarea, input, select, iframe",
  2120. classes: CLASSES,
  2121. i18n: I18N
  2122. };
  2123. function Fade(Splide2, Components2, options) {
  2124. const { on } = EventInterface(Splide2);
  2125. const { ruleBy } = Components2.Style;
  2126. function mount() {
  2127. on([EVENT_MOUNTED, EVENT_REFRESH], () => {
  2128. nextTick(() => {
  2129. Components2.Slides.forEach((Slide) => {
  2130. ruleBy(Slide.slide, "transition", `opacity ${options.speed}ms ${options.easing}`);
  2131. });
  2132. });
  2133. });
  2134. }
  2135. function start(index, done) {
  2136. const { track } = Components2.Elements;
  2137. ruleBy(track, "height", unit(rect(track).height));
  2138. nextTick(() => {
  2139. done();
  2140. ruleBy(track, "height", "");
  2141. });
  2142. }
  2143. return {
  2144. mount,
  2145. start,
  2146. cancel: noop
  2147. };
  2148. }
  2149. function Slide(Splide2, Components2, options) {
  2150. const { bind } = EventInterface(Splide2);
  2151. const { Move, Controller } = Components2;
  2152. const { list } = Components2.Elements;
  2153. let endCallback;
  2154. function mount() {
  2155. bind(list, "transitionend", (e) => {
  2156. if (e.target === list && endCallback) {
  2157. cancel();
  2158. endCallback();
  2159. }
  2160. });
  2161. }
  2162. function start(index, done) {
  2163. const destination = Move.toPosition(index, true);
  2164. const position = Move.getPosition();
  2165. const speed = getSpeed(index);
  2166. if (abs(destination - position) >= 1 && speed >= 1) {
  2167. apply(`transform ${speed}ms ${options.easing}`);
  2168. Move.translate(destination, true);
  2169. endCallback = done;
  2170. } else {
  2171. Move.jump(index);
  2172. done();
  2173. }
  2174. }
  2175. function cancel() {
  2176. apply("");
  2177. }
  2178. function getSpeed(index) {
  2179. const { rewindSpeed } = options;
  2180. if (Splide2.is(SLIDE) && rewindSpeed) {
  2181. const prev = Controller.getIndex(true);
  2182. const end = Controller.getEnd();
  2183. if (prev === 0 && index >= end || prev >= end && index === 0) {
  2184. return rewindSpeed;
  2185. }
  2186. }
  2187. return options.speed;
  2188. }
  2189. function apply(transition) {
  2190. Components2.Style.ruleBy(list, "transition", transition);
  2191. }
  2192. return {
  2193. mount,
  2194. start,
  2195. cancel
  2196. };
  2197. }
  2198. const _Splide = class {
  2199. constructor(target, options) {
  2200. this.event = EventBus();
  2201. this.Components = {};
  2202. this.state = State(CREATED);
  2203. this.splides = [];
  2204. this._options = {};
  2205. this._Extensions = {};
  2206. const root = isString(target) ? query(document, target) : target;
  2207. assert(root, `${root} is invalid.`);
  2208. this.root = root;
  2209. merge(DEFAULTS, _Splide.defaults);
  2210. merge(merge(this._options, DEFAULTS), options || {});
  2211. }
  2212. mount(Extensions, Transition) {
  2213. const { state, Components: Components2 } = this;
  2214. assert(state.is([CREATED, DESTROYED]), "Already mounted!");
  2215. state.set(CREATED);
  2216. this._Components = Components2;
  2217. this._Transition = Transition || this._Transition || (this.is(FADE) ? Fade : Slide);
  2218. this._Extensions = Extensions || this._Extensions;
  2219. const Constructors = assign({}, ComponentConstructors, this._Extensions, { Transition: this._Transition });
  2220. forOwn(Constructors, (Component, key) => {
  2221. const component = Component(this, Components2, this._options);
  2222. Components2[key] = component;
  2223. component.setup && component.setup();
  2224. });
  2225. forOwn(Components2, (component) => {
  2226. component.mount && component.mount();
  2227. });
  2228. this.emit(EVENT_MOUNTED);
  2229. addClass(this.root, CLASS_INITIALIZED);
  2230. state.set(IDLE);
  2231. this.emit(EVENT_READY);
  2232. return this;
  2233. }
  2234. sync(splide) {
  2235. this.splides.push(splide);
  2236. splide.splides.push(this);
  2237. return this;
  2238. }
  2239. go(control) {
  2240. this._Components.Controller.go(control);
  2241. return this;
  2242. }
  2243. on(events, callback) {
  2244. this.event.on(events, callback, null, DEFAULT_USER_EVENT_PRIORITY);
  2245. return this;
  2246. }
  2247. off(events) {
  2248. this.event.off(events);
  2249. return this;
  2250. }
  2251. emit(event) {
  2252. this.event.emit(event, ...slice(arguments, 1));
  2253. return this;
  2254. }
  2255. add(slides, index) {
  2256. this._Components.Slides.add(slides, index);
  2257. return this;
  2258. }
  2259. remove(matcher) {
  2260. this._Components.Slides.remove(matcher);
  2261. return this;
  2262. }
  2263. is(type) {
  2264. return this._options.type === type;
  2265. }
  2266. refresh() {
  2267. this.emit(EVENT_REFRESH);
  2268. return this;
  2269. }
  2270. destroy(completely = true) {
  2271. const { event, state } = this;
  2272. if (state.is(CREATED)) {
  2273. event.on(EVENT_READY, this.destroy.bind(this, completely), this);
  2274. } else {
  2275. forOwn(this._Components, (component) => {
  2276. component.destroy && component.destroy(completely);
  2277. });
  2278. event.emit(EVENT_DESTROY);
  2279. event.destroy();
  2280. empty(this.splides);
  2281. state.set(DESTROYED);
  2282. }
  2283. return this;
  2284. }
  2285. get options() {
  2286. return this._options;
  2287. }
  2288. set options(options) {
  2289. const { _options } = this;
  2290. merge(_options, options);
  2291. if (!this.state.is(CREATED)) {
  2292. this.emit(EVENT_UPDATED, _options);
  2293. }
  2294. }
  2295. get length() {
  2296. return this._Components.Slides.getLength(true);
  2297. }
  2298. get index() {
  2299. return this._Components.Controller.getIndex();
  2300. }
  2301. };
  2302. let Splide = _Splide;
  2303. Splide.defaults = {};
  2304. Splide.STATES = STATES;
  2305. const CLASS_RENDERED = "is-rendered";
  2306. const RENDERER_DEFAULT_CONFIG = {
  2307. listTag: "ul",
  2308. slideTag: "li"
  2309. };
  2310. class Style {
  2311. constructor(id, options) {
  2312. this.styles = {};
  2313. this.id = id;
  2314. this.options = options;
  2315. }
  2316. rule(selector, prop, value, breakpoint) {
  2317. breakpoint = breakpoint || "default";
  2318. const selectors = this.styles[breakpoint] = this.styles[breakpoint] || {};
  2319. const styles = selectors[selector] = selectors[selector] || {};
  2320. styles[prop] = value;
  2321. }
  2322. build() {
  2323. let css = "";
  2324. if (this.styles.default) {
  2325. css += this.buildSelectors(this.styles.default);
  2326. }
  2327. Object.keys(this.styles).sort((n, m) => this.options.mediaQuery === "min" ? +n - +m : +m - +n).forEach((breakpoint) => {
  2328. if (breakpoint !== "default") {
  2329. css += `@media screen and (max-width: ${breakpoint}px) {`;
  2330. css += this.buildSelectors(this.styles[breakpoint]);
  2331. css += `}`;
  2332. }
  2333. });
  2334. return css;
  2335. }
  2336. buildSelectors(selectors) {
  2337. let css = "";
  2338. forOwn(selectors, (styles, selector) => {
  2339. css += `#${this.id} ${selector} {`;
  2340. forOwn(styles, (value, prop) => {
  2341. if (value || value === 0) {
  2342. css += `${prop}: ${value};`;
  2343. }
  2344. });
  2345. css += "}";
  2346. });
  2347. return css;
  2348. }
  2349. }
  2350. class SplideRenderer {
  2351. constructor(contents, options, config, defaults) {
  2352. this.slides = [];
  2353. this.options = {};
  2354. this.breakpoints = [];
  2355. merge(DEFAULTS, defaults || {});
  2356. merge(merge(this.options, DEFAULTS), options || {});
  2357. this.contents = contents;
  2358. this.config = assign({}, RENDERER_DEFAULT_CONFIG, config || {});
  2359. this.id = this.config.id || uniqueId("splide");
  2360. this.Style = new Style(this.id, this.options);
  2361. this.Direction = Direction(null, null, this.options);
  2362. assert(this.contents.length, "Provide at least 1 content.");
  2363. this.init();
  2364. }
  2365. static clean(splide) {
  2366. const { on } = EventInterface(splide);
  2367. const { root } = splide;
  2368. const clones = queryAll(root, `.${CLASS_CLONE}`);
  2369. on(EVENT_MOUNTED, () => {
  2370. remove(child(root, "style"));
  2371. });
  2372. remove(clones);
  2373. }
  2374. init() {
  2375. this.parseBreakpoints();
  2376. this.initSlides();
  2377. this.registerRootStyles();
  2378. this.registerTrackStyles();
  2379. this.registerSlideStyles();
  2380. this.registerListStyles();
  2381. }
  2382. initSlides() {
  2383. push(this.slides, this.contents.map((content, index) => {
  2384. content = isString(content) ? { html: content } : content;
  2385. content.styles = content.styles || {};
  2386. content.attrs = content.attrs || {};
  2387. this.cover(content);
  2388. const classes = `${this.options.classes.slide} ${index === 0 ? CLASS_ACTIVE : ""}`;
  2389. assign(content.attrs, {
  2390. class: `${classes} ${content.attrs.class || ""}`.trim(),
  2391. style: this.buildStyles(content.styles)
  2392. });
  2393. return content;
  2394. }));
  2395. if (this.isLoop()) {
  2396. this.generateClones(this.slides);
  2397. }
  2398. }
  2399. registerRootStyles() {
  2400. this.breakpoints.forEach(([width, options]) => {
  2401. this.Style.rule(" ", "max-width", unit(options.width), width);
  2402. });
  2403. }
  2404. registerTrackStyles() {
  2405. const { Style: Style2 } = this;
  2406. const selector = `.${CLASS_TRACK}`;
  2407. this.breakpoints.forEach(([width, options]) => {
  2408. Style2.rule(selector, this.resolve("paddingLeft"), this.cssPadding(options, false), width);
  2409. Style2.rule(selector, this.resolve("paddingRight"), this.cssPadding(options, true), width);
  2410. Style2.rule(selector, "height", this.cssTrackHeight(options), width);
  2411. });
  2412. }
  2413. registerListStyles() {
  2414. const { Style: Style2 } = this;
  2415. const selector = `.${CLASS_LIST}`;
  2416. this.breakpoints.forEach(([width, options]) => {
  2417. Style2.rule(selector, "transform", this.buildTranslate(options), width);
  2418. });
  2419. }
  2420. registerSlideStyles() {
  2421. const { Style: Style2 } = this;
  2422. const selector = `.${CLASS_SLIDE}`;
  2423. this.breakpoints.forEach(([width, options]) => {
  2424. Style2.rule(selector, "width", this.cssSlideWidth(options), width);
  2425. Style2.rule(selector, this.resolve("marginRight"), unit(options.gap) || "0px", width);
  2426. const height = this.cssSlideHeight(options);
  2427. if (height) {
  2428. Style2.rule(selector, "height", height, width);
  2429. } else {
  2430. Style2.rule(selector, "padding-top", this.cssSlidePadding(options), width);
  2431. }
  2432. Style2.rule(`${selector} > img`, "display", options.cover ? "none" : "inline", width);
  2433. });
  2434. }
  2435. buildTranslate(options) {
  2436. const { resolve, orient } = this.Direction;
  2437. const values = [];
  2438. values.push(this.cssOffsetClones(options));
  2439. values.push(this.cssOffsetGaps(options));
  2440. if (this.isCenter(options)) {
  2441. values.push(this.buildCssValue(orient(-50), "%"));
  2442. values.push(...this.cssOffsetCenter(options));
  2443. }
  2444. return values.filter(Boolean).map((value) => `translate${resolve("X")}(${value})`).join(" ");
  2445. }
  2446. cssOffsetClones(options) {
  2447. const { resolve, orient } = this.Direction;
  2448. const cloneCount = this.getCloneCount();
  2449. if (this.isFixedWidth(options)) {
  2450. const { value, unit: unit2 } = this.parseCssValue(options[resolve("fixedWidth")]);
  2451. return this.buildCssValue(orient(value) * cloneCount, unit2);
  2452. }
  2453. const percent = 100 * cloneCount / options.perPage;
  2454. return `${orient(percent)}%`;
  2455. }
  2456. cssOffsetCenter(options) {
  2457. const { resolve, orient } = this.Direction;
  2458. if (this.isFixedWidth(options)) {
  2459. const { value, unit: unit2 } = this.parseCssValue(options[resolve("fixedWidth")]);
  2460. return [this.buildCssValue(orient(value / 2), unit2)];
  2461. }
  2462. const values = [];
  2463. const { perPage, gap } = options;
  2464. values.push(`${orient(50 / perPage)}%`);
  2465. if (gap) {
  2466. const { value, unit: unit2 } = this.parseCssValue(gap);
  2467. const gapOffset = (value / perPage - value) / 2;
  2468. values.push(this.buildCssValue(orient(gapOffset), unit2));
  2469. }
  2470. return values;
  2471. }
  2472. cssOffsetGaps(options) {
  2473. const cloneCount = this.getCloneCount();
  2474. if (cloneCount && options.gap) {
  2475. const { orient } = this.Direction;
  2476. const { value, unit: unit2 } = this.parseCssValue(options.gap);
  2477. if (this.isFixedWidth(options)) {
  2478. return this.buildCssValue(orient(value * cloneCount), unit2);
  2479. }
  2480. const { perPage } = options;
  2481. const gaps = cloneCount / perPage;
  2482. return this.buildCssValue(orient(gaps * value), unit2);
  2483. }
  2484. return "";
  2485. }
  2486. resolve(prop) {
  2487. return camelToKebab(this.Direction.resolve(prop));
  2488. }
  2489. cssPadding(options, right) {
  2490. const { padding } = options;
  2491. const prop = this.Direction.resolve(right ? "right" : "left", true);
  2492. return padding && unit(padding[prop] || (isObject(padding) ? 0 : padding)) || "0px";
  2493. }
  2494. cssTrackHeight(options) {
  2495. let height = "";
  2496. if (this.isVertical()) {
  2497. height = this.cssHeight(options);
  2498. assert(height, '"height" is missing.');
  2499. height = `calc(${height} - ${this.cssPadding(options, false)} - ${this.cssPadding(options, true)})`;
  2500. }
  2501. return height;
  2502. }
  2503. cssHeight(options) {
  2504. return unit(options.height);
  2505. }
  2506. cssSlideWidth(options) {
  2507. return options.autoWidth ? "" : unit(options.fixedWidth) || (this.isVertical() ? "" : this.cssSlideSize(options));
  2508. }
  2509. cssSlideHeight(options) {
  2510. return unit(options.fixedHeight) || (this.isVertical() ? options.autoHeight ? "" : this.cssSlideSize(options) : this.cssHeight(options));
  2511. }
  2512. cssSlideSize(options) {
  2513. const gap = unit(options.gap);
  2514. return `calc((100%${gap && ` + ${gap}`})/${options.perPage || 1}${gap && ` - ${gap}`})`;
  2515. }
  2516. cssSlidePadding(options) {
  2517. const { heightRatio } = options;
  2518. return heightRatio ? `${heightRatio * 100}%` : "";
  2519. }
  2520. buildCssValue(value, unit2) {
  2521. return `${value}${unit2}`;
  2522. }
  2523. parseCssValue(value) {
  2524. if (isString(value)) {
  2525. const number = parseFloat(value) || 0;
  2526. const unit2 = value.replace(/\d*(\.\d*)?/, "") || "px";
  2527. return { value: number, unit: unit2 };
  2528. }
  2529. return { value, unit: "px" };
  2530. }
  2531. parseBreakpoints() {
  2532. const { breakpoints } = this.options;
  2533. this.breakpoints.push(["default", this.options]);
  2534. if (breakpoints) {
  2535. forOwn(breakpoints, (options, width) => {
  2536. this.breakpoints.push([width, merge(merge({}, this.options), options)]);
  2537. });
  2538. }
  2539. }
  2540. isFixedWidth(options) {
  2541. return !!options[this.Direction.resolve("fixedWidth")];
  2542. }
  2543. isLoop() {
  2544. return this.options.type === LOOP;
  2545. }
  2546. isCenter(options) {
  2547. if (options.focus === "center") {
  2548. if (this.isLoop()) {
  2549. return true;
  2550. }
  2551. if (this.options.type === SLIDE) {
  2552. return !this.options.trimSpace;
  2553. }
  2554. }
  2555. return false;
  2556. }
  2557. isVertical() {
  2558. return this.options.direction === TTB;
  2559. }
  2560. buildClasses() {
  2561. const { options } = this;
  2562. return [
  2563. CLASS_ROOT,
  2564. `${CLASS_ROOT}--${options.type}`,
  2565. `${CLASS_ROOT}--${options.direction}`,
  2566. options.drag && `${CLASS_ROOT}--draggable`,
  2567. options.isNavigation && `${CLASS_ROOT}--nav`,
  2568. CLASS_ACTIVE,
  2569. !this.config.hidden && CLASS_RENDERED
  2570. ].filter(Boolean).join(" ");
  2571. }
  2572. buildAttrs(attrs) {
  2573. let attr = "";
  2574. forOwn(attrs, (value, key) => {
  2575. attr += value ? ` ${camelToKebab(key)}="${value}"` : "";
  2576. });
  2577. return attr.trim();
  2578. }
  2579. buildStyles(styles) {
  2580. let style = "";
  2581. forOwn(styles, (value, key) => {
  2582. style += ` ${camelToKebab(key)}:${value};`;
  2583. });
  2584. return style.trim();
  2585. }
  2586. renderSlides() {
  2587. const { slideTag: tag } = this.config;
  2588. return this.slides.map((content) => {
  2589. return `<${tag} ${this.buildAttrs(content.attrs)}>${content.html || ""}</${tag}>`;
  2590. }).join("");
  2591. }
  2592. cover(content) {
  2593. const { styles, html = "" } = content;
  2594. if (this.options.cover && !this.options.lazyLoad) {
  2595. const src = html.match(/<img.*?src\s*=\s*(['"])(.+?)\1.*?>/);
  2596. if (src && src[2]) {
  2597. styles.background = `center/cover no-repeat url('${src[2]}')`;
  2598. }
  2599. }
  2600. }
  2601. generateClones(contents) {
  2602. const { classes } = this.options;
  2603. const count = this.getCloneCount();
  2604. const slides = contents.slice();
  2605. while (slides.length < count) {
  2606. push(slides, slides);
  2607. }
  2608. push(slides.slice(-count).reverse(), slides.slice(0, count)).forEach((content, index) => {
  2609. const attrs = assign({}, content.attrs, { class: `${content.attrs.class} ${classes.clone}` });
  2610. const clone = assign({}, content, { attrs });
  2611. index < count ? contents.unshift(clone) : contents.push(clone);
  2612. });
  2613. }
  2614. getCloneCount() {
  2615. if (this.isLoop()) {
  2616. const { options } = this;
  2617. if (options.clones) {
  2618. return options.clones;
  2619. }
  2620. const perPage = max(...this.breakpoints.map(([, options2]) => options2.perPage));
  2621. return perPage * ((options.flickMaxPages || 1) + 1);
  2622. }
  2623. return 0;
  2624. }
  2625. renderArrows() {
  2626. let html = "";
  2627. html += `<div class="${this.options.classes.arrows}">`;
  2628. html += this.renderArrow(true);
  2629. html += this.renderArrow(false);
  2630. html += `</div>`;
  2631. return html;
  2632. }
  2633. renderArrow(prev) {
  2634. const { classes, i18n } = this.options;
  2635. const attrs = {
  2636. class: `${classes.arrow} ${prev ? classes.prev : classes.next}`,
  2637. type: "button",
  2638. ariaLabel: prev ? i18n.prev : i18n.next
  2639. };
  2640. 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>`;
  2641. }
  2642. html() {
  2643. const { rootClass, listTag, arrows, beforeTrack, afterTrack, slider, beforeSlider, afterSlider } = this.config;
  2644. let html = "";
  2645. html += `<div id="${this.id}" class="${this.buildClasses()} ${rootClass || ""}">`;
  2646. html += `<style>${this.Style.build()}</style>`;
  2647. if (slider) {
  2648. html += beforeSlider || "";
  2649. html += `<div class="splide__slider">`;
  2650. }
  2651. html += beforeTrack || "";
  2652. if (arrows) {
  2653. html += this.renderArrows();
  2654. }
  2655. html += `<div class="splide__track">`;
  2656. html += `<${listTag} class="splide__list">`;
  2657. html += this.renderSlides();
  2658. html += `</${listTag}>`;
  2659. html += `</div>`;
  2660. html += afterTrack || "";
  2661. if (slider) {
  2662. html += `</div>`;
  2663. html += afterSlider || "";
  2664. }
  2665. html += `</div>`;
  2666. return html;
  2667. }
  2668. }
  2669. exports.CLASSES = CLASSES;
  2670. exports.CLASS_ACTIVE = CLASS_ACTIVE;
  2671. exports.CLASS_ARROW = CLASS_ARROW;
  2672. exports.CLASS_ARROWS = CLASS_ARROWS;
  2673. exports.CLASS_ARROW_NEXT = CLASS_ARROW_NEXT;
  2674. exports.CLASS_ARROW_PREV = CLASS_ARROW_PREV;
  2675. exports.CLASS_AUTOPLAY = CLASS_AUTOPLAY;
  2676. exports.CLASS_CLONE = CLASS_CLONE;
  2677. exports.CLASS_CONTAINER = CLASS_CONTAINER;
  2678. exports.CLASS_INITIALIZED = CLASS_INITIALIZED;
  2679. exports.CLASS_LIST = CLASS_LIST;
  2680. exports.CLASS_LOADING = CLASS_LOADING;
  2681. exports.CLASS_NEXT = CLASS_NEXT;
  2682. exports.CLASS_PAGINATION = CLASS_PAGINATION;
  2683. exports.CLASS_PAGINATION_PAGE = CLASS_PAGINATION_PAGE;
  2684. exports.CLASS_PAUSE = CLASS_PAUSE;
  2685. exports.CLASS_PLAY = CLASS_PLAY;
  2686. exports.CLASS_PREV = CLASS_PREV;
  2687. exports.CLASS_PROGRESS = CLASS_PROGRESS;
  2688. exports.CLASS_PROGRESS_BAR = CLASS_PROGRESS_BAR;
  2689. exports.CLASS_ROOT = CLASS_ROOT;
  2690. exports.CLASS_SLIDE = CLASS_SLIDE;
  2691. exports.CLASS_SLIDER = CLASS_SLIDER;
  2692. exports.CLASS_SPINNER = CLASS_SPINNER;
  2693. exports.CLASS_TRACK = CLASS_TRACK;
  2694. exports.CLASS_VISIBLE = CLASS_VISIBLE;
  2695. exports.EVENT_ACTIVE = EVENT_ACTIVE;
  2696. exports.EVENT_ARROWS_MOUNTED = EVENT_ARROWS_MOUNTED;
  2697. exports.EVENT_ARROWS_UPDATED = EVENT_ARROWS_UPDATED;
  2698. exports.EVENT_AUTOPLAY_PAUSE = EVENT_AUTOPLAY_PAUSE;
  2699. exports.EVENT_AUTOPLAY_PLAY = EVENT_AUTOPLAY_PLAY;
  2700. exports.EVENT_AUTOPLAY_PLAYING = EVENT_AUTOPLAY_PLAYING;
  2701. exports.EVENT_CLICK = EVENT_CLICK;
  2702. exports.EVENT_DESTROY = EVENT_DESTROY;
  2703. exports.EVENT_DRAG = EVENT_DRAG;
  2704. exports.EVENT_DRAGGED = EVENT_DRAGGED;
  2705. exports.EVENT_DRAGGING = EVENT_DRAGGING;
  2706. exports.EVENT_HIDDEN = EVENT_HIDDEN;
  2707. exports.EVENT_INACTIVE = EVENT_INACTIVE;
  2708. exports.EVENT_LAZYLOAD_LOADED = EVENT_LAZYLOAD_LOADED;
  2709. exports.EVENT_MOUNTED = EVENT_MOUNTED;
  2710. exports.EVENT_MOVE = EVENT_MOVE;
  2711. exports.EVENT_MOVED = EVENT_MOVED;
  2712. exports.EVENT_NAVIGATION_MOUNTED = EVENT_NAVIGATION_MOUNTED;
  2713. exports.EVENT_PAGINATION_MOUNTED = EVENT_PAGINATION_MOUNTED;
  2714. exports.EVENT_PAGINATION_UPDATED = EVENT_PAGINATION_UPDATED;
  2715. exports.EVENT_READY = EVENT_READY;
  2716. exports.EVENT_REFRESH = EVENT_REFRESH;
  2717. exports.EVENT_REPOSITIONED = EVENT_REPOSITIONED;
  2718. exports.EVENT_RESIZE = EVENT_RESIZE;
  2719. exports.EVENT_RESIZED = EVENT_RESIZED;
  2720. exports.EVENT_SCROLL = EVENT_SCROLL;
  2721. exports.EVENT_SCROLLED = EVENT_SCROLLED;
  2722. exports.EVENT_SLIDE_KEYDOWN = EVENT_SLIDE_KEYDOWN;
  2723. exports.EVENT_UPDATED = EVENT_UPDATED;
  2724. exports.EVENT_VISIBLE = EVENT_VISIBLE;
  2725. exports.EventBus = EventBus;
  2726. exports.EventInterface = EventInterface;
  2727. exports.RequestInterval = RequestInterval;
  2728. exports.STATUS_CLASSES = STATUS_CLASSES;
  2729. exports.Splide = Splide;
  2730. exports.SplideRenderer = SplideRenderer;
  2731. exports.State = State;
  2732. exports.Throttle = Throttle;
  2733. exports['default'] = Splide;