splide.esm.js 77 KB

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