splide.cjs.js 80 KB

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