splide.cjs.js 79 KB

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