splide.esm.js 79 KB

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