splide.cjs.js 78 KB

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