splide.cjs.js 82 KB

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