splide.cjs.js 81 KB

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