splide.cjs.js 80 KB

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