splide.esm.js 77 KB

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