splide.cjs.js 81 KB

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