splide.esm.js 76 KB

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