splide.cjs.js 78 KB

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