splide.cjs.js 82 KB

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