splide.cjs.js 78 KB

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