splide.esm.js 81 KB

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