splide.cjs.js 78 KB

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