1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989 |
- /*!
- * Splide.js
- * Version : 4.1.3
- * License : MIT
- * Copyright: 2022 Naotoshi Fujita
- */
- const MEDIA_PREFERS_REDUCED_MOTION = "(prefers-reduced-motion: reduce)";
- const CREATED = 1;
- const MOUNTED = 2;
- const IDLE = 3;
- const MOVING = 4;
- const SCROLLING = 5;
- const DRAGGING = 6;
- const DESTROYED = 7;
- const STATES = {
- CREATED,
- MOUNTED,
- IDLE,
- MOVING,
- SCROLLING,
- DRAGGING,
- DESTROYED
- };
- function empty(array) {
- array.length = 0;
- }
- function slice(arrayLike, start, end) {
- return Array.prototype.slice.call(arrayLike, start, end);
- }
- function apply(func) {
- return func.bind(null, ...slice(arguments, 1));
- }
- const nextTick = setTimeout;
- const noop = () => {
- };
- function raf(func) {
- return requestAnimationFrame(func);
- }
- function typeOf(type, subject) {
- return typeof subject === type;
- }
- function isObject(subject) {
- return !isNull(subject) && typeOf("object", subject);
- }
- const isArray = Array.isArray;
- const isFunction = apply(typeOf, "function");
- const isString = apply(typeOf, "string");
- const isUndefined = apply(typeOf, "undefined");
- function isNull(subject) {
- return subject === null;
- }
- function isHTMLElement(subject) {
- try {
- return subject instanceof (subject.ownerDocument.defaultView || window).HTMLElement;
- } catch (e) {
- return false;
- }
- }
- function toArray(value) {
- return isArray(value) ? value : [value];
- }
- function forEach(values, iteratee) {
- toArray(values).forEach(iteratee);
- }
- function includes(array, value) {
- return array.indexOf(value) > -1;
- }
- function push(array, items) {
- array.push(...toArray(items));
- return array;
- }
- function toggleClass(elm, classes, add) {
- if (elm) {
- forEach(classes, (name) => {
- if (name) {
- elm.classList[add ? "add" : "remove"](name);
- }
- });
- }
- }
- function addClass(elm, classes) {
- toggleClass(elm, isString(classes) ? classes.split(" ") : classes, true);
- }
- function append(parent, children) {
- forEach(children, parent.appendChild.bind(parent));
- }
- function before(nodes, ref) {
- forEach(nodes, (node) => {
- const parent = (ref || node).parentNode;
- if (parent) {
- parent.insertBefore(node, ref);
- }
- });
- }
- function matches(elm, selector) {
- return isHTMLElement(elm) && (elm["msMatchesSelector"] || elm.matches).call(elm, selector);
- }
- function children(parent, selector) {
- const children2 = parent ? slice(parent.children) : [];
- return selector ? children2.filter((child) => matches(child, selector)) : children2;
- }
- function child(parent, selector) {
- return selector ? children(parent, selector)[0] : parent.firstElementChild;
- }
- const ownKeys = Object.keys;
- function forOwn(object, iteratee, right) {
- if (object) {
- (right ? ownKeys(object).reverse() : ownKeys(object)).forEach((key) => {
- key !== "__proto__" && iteratee(object[key], key);
- });
- }
- return object;
- }
- function assign(object) {
- slice(arguments, 1).forEach((source) => {
- forOwn(source, (value, key) => {
- object[key] = source[key];
- });
- });
- return object;
- }
- function merge(object) {
- slice(arguments, 1).forEach((source) => {
- forOwn(source, (value, key) => {
- if (isArray(value)) {
- object[key] = value.slice();
- } else if (isObject(value)) {
- object[key] = merge({}, isObject(object[key]) ? object[key] : {}, value);
- } else {
- object[key] = value;
- }
- });
- });
- return object;
- }
- function omit(object, keys) {
- forEach(keys || ownKeys(object), (key) => {
- delete object[key];
- });
- }
- function removeAttribute(elms, attrs) {
- forEach(elms, (elm) => {
- forEach(attrs, (attr) => {
- elm && elm.removeAttribute(attr);
- });
- });
- }
- function setAttribute(elms, attrs, value) {
- if (isObject(attrs)) {
- forOwn(attrs, (value2, name) => {
- setAttribute(elms, name, value2);
- });
- } else {
- forEach(elms, (elm) => {
- isNull(value) || value === "" ? removeAttribute(elm, attrs) : elm.setAttribute(attrs, String(value));
- });
- }
- }
- function create(tag, attrs, parent) {
- const elm = document.createElement(tag);
- if (attrs) {
- isString(attrs) ? addClass(elm, attrs) : setAttribute(elm, attrs);
- }
- parent && append(parent, elm);
- return elm;
- }
- function style(elm, prop, value) {
- if (isUndefined(value)) {
- return getComputedStyle(elm)[prop];
- }
- if (!isNull(value)) {
- elm.style[prop] = `${value}`;
- }
- }
- function display(elm, display2) {
- style(elm, "display", display2);
- }
- function focus(elm) {
- elm["setActive"] && elm["setActive"]() || elm.focus({ preventScroll: true });
- }
- function getAttribute(elm, attr) {
- return elm.getAttribute(attr);
- }
- function hasClass(elm, className) {
- return elm && elm.classList.contains(className);
- }
- function rect(target) {
- return target.getBoundingClientRect();
- }
- function remove(nodes) {
- forEach(nodes, (node) => {
- if (node && node.parentNode) {
- node.parentNode.removeChild(node);
- }
- });
- }
- function parseHtml(html) {
- return child(new DOMParser().parseFromString(html, "text/html").body);
- }
- function prevent(e, stopPropagation) {
- e.preventDefault();
- if (stopPropagation) {
- e.stopPropagation();
- e.stopImmediatePropagation();
- }
- }
- function query(parent, selector) {
- return parent && parent.querySelector(selector);
- }
- function queryAll(parent, selector) {
- return selector ? slice(parent.querySelectorAll(selector)) : [];
- }
- function removeClass(elm, classes) {
- toggleClass(elm, classes, false);
- }
- function timeOf(e) {
- return e.timeStamp;
- }
- function unit(value) {
- return isString(value) ? value : value ? `${value}px` : "";
- }
- const PROJECT_CODE = "splide";
- const DATA_ATTRIBUTE = `data-${PROJECT_CODE}`;
- function assert(condition, message) {
- if (!condition) {
- throw new Error(`[${PROJECT_CODE}] ${message || ""}`);
- }
- }
- const { min, max, floor, ceil, abs } = Math;
- function approximatelyEqual(x, y, epsilon) {
- return abs(x - y) < epsilon;
- }
- function between(number, x, y, exclusive) {
- const minimum = min(x, y);
- const maximum = max(x, y);
- return exclusive ? minimum < number && number < maximum : minimum <= number && number <= maximum;
- }
- function clamp(number, x, y) {
- const minimum = min(x, y);
- const maximum = max(x, y);
- return min(max(minimum, number), maximum);
- }
- function sign(x) {
- return +(x > 0) - +(x < 0);
- }
- function camelToKebab(string) {
- return string.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
- }
- function format(string, replacements) {
- forEach(replacements, (replacement) => {
- string = string.replace("%s", `${replacement}`);
- });
- return string;
- }
- function pad(number) {
- return number < 10 ? `0${number}` : `${number}`;
- }
- const ids = {};
- function uniqueId(prefix) {
- return `${prefix}${pad(ids[prefix] = (ids[prefix] || 0) + 1)}`;
- }
- function EventBinder() {
- let listeners = [];
- function bind(targets, events, callback, options) {
- forEachEvent(targets, events, (target, event, namespace) => {
- const isEventTarget = "addEventListener" in target;
- const remover = isEventTarget ? target.removeEventListener.bind(target, event, callback, options) : target["removeListener"].bind(target, callback);
- isEventTarget ? target.addEventListener(event, callback, options) : target["addListener"](callback);
- listeners.push([target, event, namespace, callback, remover]);
- });
- }
- function unbind(targets, events, callback) {
- forEachEvent(targets, events, (target, event, namespace) => {
- listeners = listeners.filter((listener) => {
- if (listener[0] === target && listener[1] === event && listener[2] === namespace && (!callback || listener[3] === callback)) {
- listener[4]();
- return false;
- }
- return true;
- });
- });
- }
- function dispatch(target, type, detail) {
- let e;
- const bubbles = true;
- if (typeof CustomEvent === "function") {
- e = new CustomEvent(type, { bubbles, detail });
- } else {
- e = document.createEvent("CustomEvent");
- e.initCustomEvent(type, bubbles, false, detail);
- }
- target.dispatchEvent(e);
- return e;
- }
- function forEachEvent(targets, events, iteratee) {
- forEach(targets, (target) => {
- target && forEach(events, (events2) => {
- events2.split(" ").forEach((eventNS) => {
- const fragment = eventNS.split(".");
- iteratee(target, fragment[0], fragment[1]);
- });
- });
- });
- }
- function destroy() {
- listeners.forEach((data) => {
- data[4]();
- });
- empty(listeners);
- }
- return {
- bind,
- unbind,
- dispatch,
- destroy
- };
- }
- const EVENT_MOUNTED = "mounted";
- const EVENT_READY = "ready";
- const EVENT_MOVE = "move";
- const EVENT_MOVED = "moved";
- const EVENT_CLICK = "click";
- const EVENT_ACTIVE = "active";
- const EVENT_INACTIVE = "inactive";
- const EVENT_VISIBLE = "visible";
- const EVENT_HIDDEN = "hidden";
- const EVENT_REFRESH = "refresh";
- const EVENT_UPDATED = "updated";
- const EVENT_RESIZE = "resize";
- const EVENT_RESIZED = "resized";
- const EVENT_DRAG = "drag";
- const EVENT_DRAGGING = "dragging";
- const EVENT_DRAGGED = "dragged";
- const EVENT_SCROLL = "scroll";
- const EVENT_SCROLLED = "scrolled";
- const EVENT_OVERFLOW = "overflow";
- const EVENT_DESTROY = "destroy";
- const EVENT_ARROWS_MOUNTED = "arrows:mounted";
- const EVENT_ARROWS_UPDATED = "arrows:updated";
- const EVENT_PAGINATION_MOUNTED = "pagination:mounted";
- const EVENT_PAGINATION_UPDATED = "pagination:updated";
- const EVENT_NAVIGATION_MOUNTED = "navigation:mounted";
- const EVENT_AUTOPLAY_PLAY = "autoplay:play";
- const EVENT_AUTOPLAY_PLAYING = "autoplay:playing";
- const EVENT_AUTOPLAY_PAUSE = "autoplay:pause";
- const EVENT_LAZYLOAD_LOADED = "lazyload:loaded";
- const EVENT_SLIDE_KEYDOWN = "sk";
- const EVENT_SHIFTED = "sh";
- const EVENT_END_INDEX_CHANGED = "ei";
- function EventInterface(Splide2) {
- const bus = Splide2 ? Splide2.event.bus : document.createDocumentFragment();
- const binder = EventBinder();
- function on(events, callback) {
- binder.bind(bus, toArray(events).join(" "), (e) => {
- callback.apply(callback, isArray(e.detail) ? e.detail : []);
- });
- }
- function emit(event) {
- binder.dispatch(bus, event, slice(arguments, 1));
- }
- if (Splide2) {
- Splide2.event.on(EVENT_DESTROY, binder.destroy);
- }
- return assign(binder, {
- bus,
- on,
- off: apply(binder.unbind, bus),
- emit
- });
- }
- function RequestInterval(interval, onInterval, onUpdate, limit) {
- const { now } = Date;
- let startTime;
- let rate = 0;
- let id;
- let paused = true;
- let count = 0;
- function update() {
- if (!paused) {
- rate = interval ? min((now() - startTime) / interval, 1) : 1;
- onUpdate && onUpdate(rate);
- if (rate >= 1) {
- onInterval();
- startTime = now();
- if (limit && ++count >= limit) {
- return pause();
- }
- }
- id = raf(update);
- }
- }
- function start(resume) {
- resume || cancel();
- startTime = now() - (resume ? rate * interval : 0);
- paused = false;
- id = raf(update);
- }
- function pause() {
- paused = true;
- }
- function rewind() {
- startTime = now();
- rate = 0;
- if (onUpdate) {
- onUpdate(rate);
- }
- }
- function cancel() {
- id && cancelAnimationFrame(id);
- rate = 0;
- id = 0;
- paused = true;
- }
- function set(time) {
- interval = time;
- }
- function isPaused() {
- return paused;
- }
- return {
- start,
- rewind,
- pause,
- cancel,
- set,
- isPaused
- };
- }
- function State(initialState) {
- let state = initialState;
- function set(value) {
- state = value;
- }
- function is(states) {
- return includes(toArray(states), state);
- }
- return { set, is };
- }
- function Throttle(func, duration) {
- const interval = RequestInterval(duration || 0, func, null, 1);
- return () => {
- interval.isPaused() && interval.start();
- };
- }
- function Media(Splide2, Components2, options) {
- const { state } = Splide2;
- const breakpoints = options.breakpoints || {};
- const reducedMotion = options.reducedMotion || {};
- const binder = EventBinder();
- const queries = [];
- function setup() {
- const isMin = options.mediaQuery === "min";
- ownKeys(breakpoints).sort((n, m) => isMin ? +n - +m : +m - +n).forEach((key) => {
- register(breakpoints[key], `(${isMin ? "min" : "max"}-width:${key}px)`);
- });
- register(reducedMotion, MEDIA_PREFERS_REDUCED_MOTION);
- update();
- }
- function destroy(completely) {
- if (completely) {
- binder.destroy();
- }
- }
- function register(options2, query) {
- const queryList = matchMedia(query);
- binder.bind(queryList, "change", update);
- queries.push([options2, queryList]);
- }
- function update() {
- const destroyed = state.is(DESTROYED);
- const direction = options.direction;
- const merged = queries.reduce((merged2, entry) => {
- return merge(merged2, entry[1].matches ? entry[0] : {});
- }, {});
- omit(options);
- set(merged);
- if (options.destroy) {
- Splide2.destroy(options.destroy === "completely");
- } else if (destroyed) {
- destroy(true);
- Splide2.mount();
- } else {
- direction !== options.direction && Splide2.refresh();
- }
- }
- function reduce(enable) {
- if (matchMedia(MEDIA_PREFERS_REDUCED_MOTION).matches) {
- enable ? merge(options, reducedMotion) : omit(options, ownKeys(reducedMotion));
- }
- }
- function set(opts, base, notify) {
- merge(options, opts);
- base && merge(Object.getPrototypeOf(options), opts);
- if (notify || !state.is(CREATED)) {
- Splide2.emit(EVENT_UPDATED, options);
- }
- }
- return {
- setup,
- destroy,
- reduce,
- set
- };
- }
- const ARROW = "Arrow";
- const ARROW_LEFT = `${ARROW}Left`;
- const ARROW_RIGHT = `${ARROW}Right`;
- const ARROW_UP = `${ARROW}Up`;
- const ARROW_DOWN = `${ARROW}Down`;
- const LTR = "ltr";
- const RTL = "rtl";
- const TTB = "ttb";
- const ORIENTATION_MAP = {
- width: ["height"],
- left: ["top", "right"],
- right: ["bottom", "left"],
- x: ["y"],
- X: ["Y"],
- Y: ["X"],
- ArrowLeft: [ARROW_UP, ARROW_RIGHT],
- ArrowRight: [ARROW_DOWN, ARROW_LEFT]
- };
- function Direction(Splide2, Components2, options) {
- function resolve(prop, axisOnly, direction) {
- direction = direction || options.direction;
- const index = direction === RTL && !axisOnly ? 1 : direction === TTB ? 0 : -1;
- return ORIENTATION_MAP[prop] && ORIENTATION_MAP[prop][index] || prop.replace(/width|left|right/i, (match, offset) => {
- const replacement = ORIENTATION_MAP[match.toLowerCase()][index] || match;
- return offset > 0 ? replacement.charAt(0).toUpperCase() + replacement.slice(1) : replacement;
- });
- }
- function orient(value) {
- return value * (options.direction === RTL ? 1 : -1);
- }
- return {
- resolve,
- orient
- };
- }
- const ROLE = "role";
- const TAB_INDEX = "tabindex";
- const DISABLED = "disabled";
- const ARIA_PREFIX = "aria-";
- const ARIA_CONTROLS = `${ARIA_PREFIX}controls`;
- const ARIA_CURRENT = `${ARIA_PREFIX}current`;
- const ARIA_SELECTED = `${ARIA_PREFIX}selected`;
- const ARIA_LABEL = `${ARIA_PREFIX}label`;
- const ARIA_LABELLEDBY = `${ARIA_PREFIX}labelledby`;
- const ARIA_HIDDEN = `${ARIA_PREFIX}hidden`;
- const ARIA_ORIENTATION = `${ARIA_PREFIX}orientation`;
- const ARIA_ROLEDESCRIPTION = `${ARIA_PREFIX}roledescription`;
- const ARIA_LIVE = `${ARIA_PREFIX}live`;
- const ARIA_BUSY = `${ARIA_PREFIX}busy`;
- const ARIA_ATOMIC = `${ARIA_PREFIX}atomic`;
- const ALL_ATTRIBUTES = [
- ROLE,
- TAB_INDEX,
- DISABLED,
- ARIA_CONTROLS,
- ARIA_CURRENT,
- ARIA_LABEL,
- ARIA_LABELLEDBY,
- ARIA_HIDDEN,
- ARIA_ORIENTATION,
- ARIA_ROLEDESCRIPTION
- ];
- const CLASS_PREFIX = `${PROJECT_CODE}__`;
- const STATUS_CLASS_PREFIX = "is-";
- const CLASS_ROOT = PROJECT_CODE;
- const CLASS_TRACK = `${CLASS_PREFIX}track`;
- const CLASS_LIST = `${CLASS_PREFIX}list`;
- const CLASS_SLIDE = `${CLASS_PREFIX}slide`;
- const CLASS_CLONE = `${CLASS_SLIDE}--clone`;
- const CLASS_CONTAINER = `${CLASS_SLIDE}__container`;
- const CLASS_ARROWS = `${CLASS_PREFIX}arrows`;
- const CLASS_ARROW = `${CLASS_PREFIX}arrow`;
- const CLASS_ARROW_PREV = `${CLASS_ARROW}--prev`;
- const CLASS_ARROW_NEXT = `${CLASS_ARROW}--next`;
- const CLASS_PAGINATION = `${CLASS_PREFIX}pagination`;
- const CLASS_PAGINATION_PAGE = `${CLASS_PAGINATION}__page`;
- const CLASS_PROGRESS = `${CLASS_PREFIX}progress`;
- const CLASS_PROGRESS_BAR = `${CLASS_PROGRESS}__bar`;
- const CLASS_TOGGLE = `${CLASS_PREFIX}toggle`;
- const CLASS_TOGGLE_PLAY = `${CLASS_TOGGLE}__play`;
- const CLASS_TOGGLE_PAUSE = `${CLASS_TOGGLE}__pause`;
- const CLASS_SPINNER = `${CLASS_PREFIX}spinner`;
- const CLASS_SR = `${CLASS_PREFIX}sr`;
- const CLASS_INITIALIZED = `${STATUS_CLASS_PREFIX}initialized`;
- const CLASS_ACTIVE = `${STATUS_CLASS_PREFIX}active`;
- const CLASS_PREV = `${STATUS_CLASS_PREFIX}prev`;
- const CLASS_NEXT = `${STATUS_CLASS_PREFIX}next`;
- const CLASS_VISIBLE = `${STATUS_CLASS_PREFIX}visible`;
- const CLASS_LOADING = `${STATUS_CLASS_PREFIX}loading`;
- const CLASS_FOCUS_IN = `${STATUS_CLASS_PREFIX}focus-in`;
- const CLASS_OVERFLOW = `${STATUS_CLASS_PREFIX}overflow`;
- const STATUS_CLASSES = [
- CLASS_ACTIVE,
- CLASS_VISIBLE,
- CLASS_PREV,
- CLASS_NEXT,
- CLASS_LOADING,
- CLASS_FOCUS_IN,
- CLASS_OVERFLOW
- ];
- const CLASSES = {
- slide: CLASS_SLIDE,
- clone: CLASS_CLONE,
- arrows: CLASS_ARROWS,
- arrow: CLASS_ARROW,
- prev: CLASS_ARROW_PREV,
- next: CLASS_ARROW_NEXT,
- pagination: CLASS_PAGINATION,
- page: CLASS_PAGINATION_PAGE,
- spinner: CLASS_SPINNER
- };
- function closest(from, selector) {
- if (isFunction(from.closest)) {
- return from.closest(selector);
- }
- let elm = from;
- while (elm && elm.nodeType === 1) {
- if (matches(elm, selector)) {
- break;
- }
- elm = elm.parentElement;
- }
- return elm;
- }
- const FRICTION = 5;
- const LOG_INTERVAL = 200;
- const POINTER_DOWN_EVENTS = "touchstart mousedown";
- const POINTER_MOVE_EVENTS = "touchmove mousemove";
- const POINTER_UP_EVENTS = "touchend touchcancel mouseup click";
- function Elements(Splide2, Components2, options) {
- const { on, bind } = EventInterface(Splide2);
- const { root } = Splide2;
- const { i18n } = options;
- const elements = {};
- const slides = [];
- let rootClasses = [];
- let trackClasses = [];
- let track;
- let list;
- let isUsingKey;
- function setup() {
- collect();
- init();
- update();
- }
- function mount() {
- on(EVENT_REFRESH, destroy);
- on(EVENT_REFRESH, setup);
- on(EVENT_UPDATED, update);
- bind(document, `${POINTER_DOWN_EVENTS} keydown`, (e) => {
- isUsingKey = e.type === "keydown";
- }, { capture: true });
- bind(root, "focusin", () => {
- toggleClass(root, CLASS_FOCUS_IN, !!isUsingKey);
- });
- }
- function destroy(completely) {
- const attrs = ALL_ATTRIBUTES.concat("style");
- empty(slides);
- removeClass(root, rootClasses);
- removeClass(track, trackClasses);
- removeAttribute([track, list], attrs);
- removeAttribute(root, completely ? attrs : ["style", ARIA_ROLEDESCRIPTION]);
- }
- function update() {
- removeClass(root, rootClasses);
- removeClass(track, trackClasses);
- rootClasses = getClasses(CLASS_ROOT);
- trackClasses = getClasses(CLASS_TRACK);
- addClass(root, rootClasses);
- addClass(track, trackClasses);
- setAttribute(root, ARIA_LABEL, options.label);
- setAttribute(root, ARIA_LABELLEDBY, options.labelledby);
- }
- function collect() {
- track = find(`.${CLASS_TRACK}`);
- list = child(track, `.${CLASS_LIST}`);
- assert(track && list, "A track/list element is missing.");
- push(slides, children(list, `.${CLASS_SLIDE}:not(.${CLASS_CLONE})`));
- forOwn({
- arrows: CLASS_ARROWS,
- pagination: CLASS_PAGINATION,
- prev: CLASS_ARROW_PREV,
- next: CLASS_ARROW_NEXT,
- bar: CLASS_PROGRESS_BAR,
- toggle: CLASS_TOGGLE
- }, (className, key) => {
- elements[key] = find(`.${className}`);
- });
- assign(elements, { root, track, list, slides });
- }
- function init() {
- const id = root.id || uniqueId(PROJECT_CODE);
- const role = options.role;
- root.id = id;
- track.id = track.id || `${id}-track`;
- list.id = list.id || `${id}-list`;
- if (!getAttribute(root, ROLE) && root.tagName !== "SECTION" && role) {
- setAttribute(root, ROLE, role);
- }
- setAttribute(root, ARIA_ROLEDESCRIPTION, i18n.carousel);
- setAttribute(list, ROLE, "presentation");
- }
- function find(selector) {
- const elm = query(root, selector);
- return elm && closest(elm, `.${CLASS_ROOT}`) === root ? elm : void 0;
- }
- function getClasses(base) {
- return [
- `${base}--${options.type}`,
- `${base}--${options.direction}`,
- options.drag && `${base}--draggable`,
- options.isNavigation && `${base}--nav`,
- base === CLASS_ROOT && CLASS_ACTIVE
- ];
- }
- return assign(elements, {
- setup,
- mount,
- destroy
- });
- }
- const SLIDE = "slide";
- const LOOP = "loop";
- const FADE = "fade";
- function Slide$1(Splide2, index, slideIndex, slide) {
- const event = EventInterface(Splide2);
- const { on, emit, bind } = event;
- const { Components, root, options } = Splide2;
- const { isNavigation, updateOnMove, i18n, pagination, slideFocus } = options;
- const { resolve } = Components.Direction;
- const styles = getAttribute(slide, "style");
- const label = getAttribute(slide, ARIA_LABEL);
- const isClone = slideIndex > -1;
- const container = child(slide, `.${CLASS_CONTAINER}`);
- let destroyed;
- function mount() {
- if (!isClone) {
- slide.id = `${root.id}-slide${pad(index + 1)}`;
- setAttribute(slide, ROLE, pagination ? "tabpanel" : "group");
- setAttribute(slide, ARIA_ROLEDESCRIPTION, i18n.slide);
- setAttribute(slide, ARIA_LABEL, label || format(i18n.slideLabel, [index + 1, Splide2.length]));
- }
- listen();
- }
- function listen() {
- bind(slide, "click", apply(emit, EVENT_CLICK, self));
- bind(slide, "keydown", apply(emit, EVENT_SLIDE_KEYDOWN, self));
- on([EVENT_MOVED, EVENT_SHIFTED, EVENT_SCROLLED], update);
- on(EVENT_NAVIGATION_MOUNTED, initNavigation);
- if (updateOnMove) {
- on(EVENT_MOVE, onMove);
- }
- }
- function destroy() {
- destroyed = true;
- event.destroy();
- removeClass(slide, STATUS_CLASSES);
- removeAttribute(slide, ALL_ATTRIBUTES);
- setAttribute(slide, "style", styles);
- setAttribute(slide, ARIA_LABEL, label || "");
- }
- function initNavigation() {
- const controls = Splide2.splides.map((target) => {
- const Slide2 = target.splide.Components.Slides.getAt(index);
- return Slide2 ? Slide2.slide.id : "";
- }).join(" ");
- setAttribute(slide, ARIA_LABEL, format(i18n.slideX, (isClone ? slideIndex : index) + 1));
- setAttribute(slide, ARIA_CONTROLS, controls);
- setAttribute(slide, ROLE, slideFocus ? "button" : "");
- slideFocus && removeAttribute(slide, ARIA_ROLEDESCRIPTION);
- }
- function onMove() {
- if (!destroyed) {
- update();
- }
- }
- function update() {
- if (!destroyed) {
- const { index: curr } = Splide2;
- updateActivity();
- updateVisibility();
- toggleClass(slide, CLASS_PREV, index === curr - 1);
- toggleClass(slide, CLASS_NEXT, index === curr + 1);
- }
- }
- function updateActivity() {
- const active = isActive();
- if (active !== hasClass(slide, CLASS_ACTIVE)) {
- toggleClass(slide, CLASS_ACTIVE, active);
- setAttribute(slide, ARIA_CURRENT, isNavigation && active || "");
- emit(active ? EVENT_ACTIVE : EVENT_INACTIVE, self);
- }
- }
- function updateVisibility() {
- const visible = isVisible();
- const hidden = !visible && (!isActive() || isClone);
- if (!Splide2.state.is([MOVING, SCROLLING])) {
- setAttribute(slide, ARIA_HIDDEN, hidden || "");
- }
- setAttribute(queryAll(slide, options.focusableNodes || ""), TAB_INDEX, hidden ? -1 : "");
- if (slideFocus) {
- setAttribute(slide, TAB_INDEX, hidden ? -1 : 0);
- }
- if (visible !== hasClass(slide, CLASS_VISIBLE)) {
- toggleClass(slide, CLASS_VISIBLE, visible);
- emit(visible ? EVENT_VISIBLE : EVENT_HIDDEN, self);
- }
- if (!visible && document.activeElement === slide) {
- const Slide2 = Components.Slides.getAt(Splide2.index);
- Slide2 && focus(Slide2.slide);
- }
- }
- function style$1(prop, value, useContainer) {
- style(useContainer && container || slide, prop, value);
- }
- function isActive() {
- const { index: curr } = Splide2;
- return curr === index || options.cloneStatus && curr === slideIndex;
- }
- function isVisible() {
- if (Splide2.is(FADE)) {
- return isActive();
- }
- const trackRect = rect(Components.Elements.track);
- const slideRect = rect(slide);
- const left = resolve("left", true);
- const right = resolve("right", true);
- return floor(trackRect[left]) <= ceil(slideRect[left]) && floor(slideRect[right]) <= ceil(trackRect[right]);
- }
- function isWithin(from, distance) {
- let diff = abs(from - index);
- if (!isClone && (options.rewind || Splide2.is(LOOP))) {
- diff = min(diff, Splide2.length - diff);
- }
- return diff <= distance;
- }
- const self = {
- index,
- slideIndex,
- slide,
- container,
- isClone,
- mount,
- destroy,
- update,
- style: style$1,
- isWithin
- };
- return self;
- }
- function Slides(Splide2, Components2, options) {
- const { on, emit, bind } = EventInterface(Splide2);
- const { slides, list } = Components2.Elements;
- const Slides2 = [];
- function mount() {
- init();
- on(EVENT_REFRESH, destroy);
- on(EVENT_REFRESH, init);
- }
- function init() {
- slides.forEach((slide, index) => {
- register(slide, index, -1);
- });
- }
- function destroy() {
- forEach$1((Slide2) => {
- Slide2.destroy();
- });
- empty(Slides2);
- }
- function update() {
- forEach$1((Slide2) => {
- Slide2.update();
- });
- }
- function register(slide, index, slideIndex) {
- const object = Slide$1(Splide2, index, slideIndex, slide);
- object.mount();
- Slides2.push(object);
- Slides2.sort((Slide1, Slide2) => Slide1.index - Slide2.index);
- }
- function get(excludeClones) {
- return excludeClones ? filter((Slide2) => !Slide2.isClone) : Slides2;
- }
- function getIn(page) {
- const { Controller } = Components2;
- const index = Controller.toIndex(page);
- const max = Controller.hasFocus() ? 1 : options.perPage;
- return filter((Slide2) => between(Slide2.index, index, index + max - 1));
- }
- function getAt(index) {
- return filter(index)[0];
- }
- function add(items, index) {
- forEach(items, (slide) => {
- if (isString(slide)) {
- slide = parseHtml(slide);
- }
- if (isHTMLElement(slide)) {
- const ref = slides[index];
- ref ? before(slide, ref) : append(list, slide);
- addClass(slide, options.classes.slide);
- observeImages(slide, apply(emit, EVENT_RESIZE));
- }
- });
- emit(EVENT_REFRESH);
- }
- function remove$1(matcher) {
- remove(filter(matcher).map((Slide2) => Slide2.slide));
- emit(EVENT_REFRESH);
- }
- function forEach$1(iteratee, excludeClones) {
- get(excludeClones).forEach(iteratee);
- }
- function filter(matcher) {
- return Slides2.filter(
- isFunction(matcher) ? matcher : (Slide2) => isString(matcher) ? matches(Slide2.slide, matcher) : includes(toArray(matcher), Slide2.index)
- );
- }
- function style(prop, value, useContainer) {
- forEach$1((Slide2) => {
- Slide2.style(prop, value, useContainer);
- });
- }
- function observeImages(elm, callback) {
- const images = queryAll(elm, "img");
- let { length } = images;
- if (length) {
- images.forEach((img) => {
- bind(img, "load error", () => {
- if (!--length) {
- callback();
- }
- });
- });
- } else {
- callback();
- }
- }
- function getLength(excludeClones) {
- return excludeClones ? slides.length : Slides2.length;
- }
- function isEnough() {
- return Slides2.length > options.perPage;
- }
- return {
- mount,
- destroy,
- update,
- register,
- get,
- getIn,
- getAt,
- add,
- remove: remove$1,
- forEach: forEach$1,
- filter,
- style,
- getLength,
- isEnough
- };
- }
- function Layout(Splide2, Components2, options) {
- const { on, bind, emit } = EventInterface(Splide2);
- const { Slides } = Components2;
- const { resolve } = Components2.Direction;
- const { root, track, list } = Components2.Elements;
- const { getAt, style: styleSlides } = Slides;
- let vertical;
- let rootRect;
- let overflow;
- function mount() {
- init();
- bind(window, "resize load", Throttle(apply(emit, EVENT_RESIZE)));
- on([EVENT_UPDATED, EVENT_REFRESH], init);
- on(EVENT_RESIZE, resize);
- }
- function init() {
- vertical = options.direction === TTB;
- style(root, "maxWidth", unit(options.width));
- style(track, resolve("paddingLeft"), cssPadding(false));
- style(track, resolve("paddingRight"), cssPadding(true));
- resize(true);
- }
- function resize(force) {
- const newRect = rect(root);
- if (force || rootRect.width !== newRect.width || rootRect.height !== newRect.height) {
- style(track, "height", cssTrackHeight());
- styleSlides(resolve("marginRight"), unit(options.gap));
- styleSlides("width", cssSlideWidth());
- styleSlides("height", cssSlideHeight(), true);
- rootRect = newRect;
- emit(EVENT_RESIZED);
- if (overflow !== (overflow = isOverflow())) {
- toggleClass(root, CLASS_OVERFLOW, overflow);
- emit(EVENT_OVERFLOW, overflow);
- }
- }
- }
- function cssPadding(right) {
- const { padding } = options;
- const prop = resolve(right ? "right" : "left");
- return padding && unit(padding[prop] || (isObject(padding) ? 0 : padding)) || "0px";
- }
- function cssTrackHeight() {
- let height = "";
- if (vertical) {
- height = cssHeight();
- assert(height, "height or heightRatio is missing.");
- height = `calc(${height} - ${cssPadding(false)} - ${cssPadding(true)})`;
- }
- return height;
- }
- function cssHeight() {
- return unit(options.height || rect(list).width * options.heightRatio);
- }
- function cssSlideWidth() {
- return options.autoWidth ? null : unit(options.fixedWidth) || (vertical ? "" : cssSlideSize());
- }
- function cssSlideHeight() {
- return unit(options.fixedHeight) || (vertical ? options.autoHeight ? null : cssSlideSize() : cssHeight());
- }
- function cssSlideSize() {
- const gap = unit(options.gap);
- return `calc((100%${gap && ` + ${gap}`})/${options.perPage || 1}${gap && ` - ${gap}`})`;
- }
- function listSize() {
- return rect(list)[resolve("width")];
- }
- function slideSize(index, withoutGap) {
- const Slide = getAt(index || 0);
- return Slide ? rect(Slide.slide)[resolve("width")] + (withoutGap ? 0 : getGap()) : 0;
- }
- function totalSize(index, withoutGap) {
- const Slide = getAt(index);
- if (Slide) {
- const right = rect(Slide.slide)[resolve("right")];
- const left = rect(list)[resolve("left")];
- return abs(right - left) + (withoutGap ? 0 : getGap());
- }
- return 0;
- }
- function sliderSize(withoutGap) {
- return totalSize(Splide2.length - 1) - totalSize(0) + slideSize(0, withoutGap);
- }
- function getGap() {
- const Slide = getAt(0);
- return Slide && parseFloat(style(Slide.slide, resolve("marginRight"))) || 0;
- }
- function getPadding(right) {
- return parseFloat(style(track, resolve(`padding${right ? "Right" : "Left"}`))) || 0;
- }
- function isOverflow() {
- return Splide2.is(FADE) || sliderSize(true) > listSize();
- }
- return {
- mount,
- resize,
- listSize,
- slideSize,
- sliderSize,
- totalSize,
- getPadding,
- isOverflow
- };
- }
- const MULTIPLIER = 2;
- function Clones(Splide2, Components2, options) {
- const event = EventInterface(Splide2);
- const { on } = event;
- const { Elements, Slides } = Components2;
- const { resolve } = Components2.Direction;
- const clones = [];
- let cloneCount;
- function mount() {
- on(EVENT_REFRESH, remount);
- on([EVENT_UPDATED, EVENT_RESIZE], observe);
- if (cloneCount = computeCloneCount()) {
- generate(cloneCount);
- Components2.Layout.resize(true);
- }
- }
- function remount() {
- destroy();
- mount();
- }
- function destroy() {
- remove(clones);
- empty(clones);
- event.destroy();
- }
- function observe() {
- const count = computeCloneCount();
- if (cloneCount !== count) {
- if (cloneCount < count || !count) {
- event.emit(EVENT_REFRESH);
- }
- }
- }
- function generate(count) {
- const slides = Slides.get().slice();
- const { length } = slides;
- if (length) {
- while (slides.length < count) {
- push(slides, slides);
- }
- push(slides.slice(-count), slides.slice(0, count)).forEach((Slide, index) => {
- const isHead = index < count;
- const clone = cloneDeep(Slide.slide, index);
- isHead ? before(clone, slides[0].slide) : append(Elements.list, clone);
- push(clones, clone);
- Slides.register(clone, index - count + (isHead ? 0 : length), Slide.index);
- });
- }
- }
- function cloneDeep(elm, index) {
- const clone = elm.cloneNode(true);
- addClass(clone, options.classes.clone);
- clone.id = `${Splide2.root.id}-clone${pad(index + 1)}`;
- return clone;
- }
- function computeCloneCount() {
- let { clones: clones2 } = options;
- if (!Splide2.is(LOOP)) {
- clones2 = 0;
- } else if (isUndefined(clones2)) {
- const fixedSize = options[resolve("fixedWidth")] && Components2.Layout.slideSize(0);
- const fixedCount = fixedSize && ceil(rect(Elements.track)[resolve("width")] / fixedSize);
- clones2 = fixedCount || options[resolve("autoWidth")] && Splide2.length || options.perPage * MULTIPLIER;
- }
- return clones2;
- }
- return {
- mount,
- destroy
- };
- }
- function Move(Splide2, Components2, options) {
- const { on, emit } = EventInterface(Splide2);
- const { set } = Splide2.state;
- const { slideSize, getPadding, totalSize, listSize, sliderSize } = Components2.Layout;
- const { resolve, orient } = Components2.Direction;
- const { list, track } = Components2.Elements;
- let Transition;
- function mount() {
- Transition = Components2.Transition;
- on([EVENT_MOUNTED, EVENT_RESIZED, EVENT_UPDATED, EVENT_REFRESH], reposition);
- }
- function reposition() {
- if (!Components2.Controller.isBusy()) {
- Components2.Scroll.cancel();
- jump(Splide2.index);
- Components2.Slides.update();
- }
- }
- function move(dest, index, prev, callback) {
- if (dest !== index && canShift(dest > prev)) {
- cancel();
- translate(shift(getPosition(), dest > prev), true);
- }
- set(MOVING);
- emit(EVENT_MOVE, index, prev, dest);
- Transition.start(index, () => {
- set(IDLE);
- emit(EVENT_MOVED, index, prev, dest);
- callback && callback();
- });
- }
- function jump(index) {
- translate(toPosition(index, true));
- }
- function translate(position, preventLoop) {
- if (!Splide2.is(FADE)) {
- const destination = preventLoop ? position : loop(position);
- style(list, "transform", `translate${resolve("X")}(${destination}px)`);
- position !== destination && emit(EVENT_SHIFTED);
- }
- }
- function loop(position) {
- if (Splide2.is(LOOP)) {
- const index = toIndex(position);
- const exceededMax = index > Components2.Controller.getEnd();
- const exceededMin = index < 0;
- if (exceededMin || exceededMax) {
- position = shift(position, exceededMax);
- }
- }
- return position;
- }
- function shift(position, backwards) {
- const excess = position - getLimit(backwards);
- const size = sliderSize();
- position -= orient(size * (ceil(abs(excess) / size) || 1)) * (backwards ? 1 : -1);
- return position;
- }
- function cancel() {
- translate(getPosition(), true);
- Transition.cancel();
- }
- function toIndex(position) {
- const Slides = Components2.Slides.get();
- let index = 0;
- let minDistance = Infinity;
- for (let i = 0; i < Slides.length; i++) {
- const slideIndex = Slides[i].index;
- const distance = abs(toPosition(slideIndex, true) - position);
- if (distance <= minDistance) {
- minDistance = distance;
- index = slideIndex;
- } else {
- break;
- }
- }
- return index;
- }
- function toPosition(index, trimming) {
- const position = orient(totalSize(index - 1) - offset(index));
- return trimming ? trim(position) : position;
- }
- function getPosition() {
- const left = resolve("left");
- return rect(list)[left] - rect(track)[left] + orient(getPadding(false));
- }
- function trim(position) {
- if (options.trimSpace && Splide2.is(SLIDE)) {
- position = clamp(position, 0, orient(sliderSize(true) - listSize()));
- }
- return position;
- }
- function offset(index) {
- const { focus } = options;
- return focus === "center" ? (listSize() - slideSize(index, true)) / 2 : +focus * slideSize(index) || 0;
- }
- function getLimit(max) {
- return toPosition(max ? Components2.Controller.getEnd() : 0, !!options.trimSpace);
- }
- function canShift(backwards) {
- const shifted = orient(shift(getPosition(), backwards));
- return backwards ? shifted >= 0 : shifted <= list[resolve("scrollWidth")] - rect(track)[resolve("width")];
- }
- function exceededLimit(max, position) {
- position = isUndefined(position) ? getPosition() : position;
- const exceededMin = max !== true && orient(position) < orient(getLimit(false));
- const exceededMax = max !== false && orient(position) > orient(getLimit(true));
- return exceededMin || exceededMax;
- }
- return {
- mount,
- move,
- jump,
- translate,
- shift,
- cancel,
- toIndex,
- toPosition,
- getPosition,
- getLimit,
- exceededLimit,
- reposition
- };
- }
- function Controller(Splide2, Components2, options) {
- const { on, emit } = EventInterface(Splide2);
- const { Move } = Components2;
- const { getPosition, getLimit, toPosition } = Move;
- const { isEnough, getLength } = Components2.Slides;
- const { omitEnd } = options;
- const isLoop = Splide2.is(LOOP);
- const isSlide = Splide2.is(SLIDE);
- const getNext = apply(getAdjacent, false);
- const getPrev = apply(getAdjacent, true);
- let currIndex = options.start || 0;
- let endIndex;
- let prevIndex = currIndex;
- let slideCount;
- let perMove;
- let perPage;
- function mount() {
- init();
- on([EVENT_UPDATED, EVENT_REFRESH, EVENT_END_INDEX_CHANGED], init);
- on(EVENT_RESIZED, onResized);
- }
- function init() {
- slideCount = getLength(true);
- perMove = options.perMove;
- perPage = options.perPage;
- endIndex = getEnd();
- const index = clamp(currIndex, 0, omitEnd ? endIndex : slideCount - 1);
- if (index !== currIndex) {
- currIndex = index;
- Move.reposition();
- }
- }
- function onResized() {
- if (endIndex !== getEnd()) {
- emit(EVENT_END_INDEX_CHANGED);
- }
- }
- function go(control, allowSameIndex, callback) {
- if (!isBusy()) {
- const dest = parse(control);
- const index = loop(dest);
- if (index > -1 && (allowSameIndex || index !== currIndex)) {
- setIndex(index);
- Move.move(dest, index, prevIndex, callback);
- }
- }
- }
- function scroll(destination, duration, snap, callback) {
- Components2.Scroll.scroll(destination, duration, snap, () => {
- const index = loop(Move.toIndex(getPosition()));
- setIndex(omitEnd ? min(index, endIndex) : index);
- callback && callback();
- });
- }
- function parse(control) {
- let index = currIndex;
- if (isString(control)) {
- const [, indicator, number] = control.match(/([+\-<>])(\d+)?/) || [];
- if (indicator === "+" || indicator === "-") {
- index = computeDestIndex(currIndex + +`${indicator}${+number || 1}`, currIndex);
- } else if (indicator === ">") {
- index = number ? toIndex(+number) : getNext(true);
- } else if (indicator === "<") {
- index = getPrev(true);
- }
- } else {
- index = isLoop ? control : clamp(control, 0, endIndex);
- }
- return index;
- }
- function getAdjacent(prev, destination) {
- const number = perMove || (hasFocus() ? 1 : perPage);
- const dest = computeDestIndex(currIndex + number * (prev ? -1 : 1), currIndex, !(perMove || hasFocus()));
- if (dest === -1 && isSlide) {
- if (!approximatelyEqual(getPosition(), getLimit(!prev), 1)) {
- return prev ? 0 : endIndex;
- }
- }
- return destination ? dest : loop(dest);
- }
- function computeDestIndex(dest, from, snapPage) {
- if (isEnough() || hasFocus()) {
- const index = computeMovableDestIndex(dest);
- if (index !== dest) {
- from = dest;
- dest = index;
- snapPage = false;
- }
- if (dest < 0 || dest > endIndex) {
- if (!perMove && (between(0, dest, from, true) || between(endIndex, from, dest, true))) {
- dest = toIndex(toPage(dest));
- } else {
- if (isLoop) {
- dest = snapPage ? dest < 0 ? -(slideCount % perPage || perPage) : slideCount : dest;
- } else if (options.rewind) {
- dest = dest < 0 ? endIndex : 0;
- } else {
- dest = -1;
- }
- }
- } else {
- if (snapPage && dest !== from) {
- dest = toIndex(toPage(from) + (dest < from ? -1 : 1));
- }
- }
- } else {
- dest = -1;
- }
- return dest;
- }
- function computeMovableDestIndex(dest) {
- if (isSlide && options.trimSpace === "move" && dest !== currIndex) {
- const position = getPosition();
- while (position === toPosition(dest, true) && between(dest, 0, Splide2.length - 1, !options.rewind)) {
- dest < currIndex ? --dest : ++dest;
- }
- }
- return dest;
- }
- function loop(index) {
- return isLoop ? (index + slideCount) % slideCount || 0 : index;
- }
- function getEnd() {
- let end = slideCount - (hasFocus() || isLoop && perMove ? 1 : perPage);
- while (omitEnd && end-- > 0) {
- if (toPosition(slideCount - 1, true) !== toPosition(end, true)) {
- end++;
- break;
- }
- }
- return clamp(end, 0, slideCount - 1);
- }
- function toIndex(page) {
- return clamp(hasFocus() ? page : perPage * page, 0, endIndex);
- }
- function toPage(index) {
- return hasFocus() ? min(index, endIndex) : floor((index >= endIndex ? slideCount - 1 : index) / perPage);
- }
- function toDest(destination) {
- const closest = Move.toIndex(destination);
- return isSlide ? clamp(closest, 0, endIndex) : closest;
- }
- function setIndex(index) {
- if (index !== currIndex) {
- prevIndex = currIndex;
- currIndex = index;
- }
- }
- function getIndex(prev) {
- return prev ? prevIndex : currIndex;
- }
- function hasFocus() {
- return !isUndefined(options.focus) || options.isNavigation;
- }
- function isBusy() {
- return Splide2.state.is([MOVING, SCROLLING]) && !!options.waitForTransition;
- }
- return {
- mount,
- go,
- scroll,
- getNext,
- getPrev,
- getAdjacent,
- getEnd,
- setIndex,
- getIndex,
- toIndex,
- toPage,
- toDest,
- hasFocus,
- isBusy
- };
- }
- const XML_NAME_SPACE = "http://www.w3.org/2000/svg";
- 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";
- const SIZE = 40;
- function Arrows(Splide2, Components2, options) {
- const event = EventInterface(Splide2);
- const { on, bind, emit } = event;
- const { classes, i18n } = options;
- const { Elements, Controller } = Components2;
- const { arrows: placeholder, track } = Elements;
- let wrapper = placeholder;
- let prev = Elements.prev;
- let next = Elements.next;
- let created;
- let wrapperClasses;
- const arrows = {};
- function mount() {
- init();
- on(EVENT_UPDATED, remount);
- }
- function remount() {
- destroy();
- mount();
- }
- function init() {
- const enabled = options.arrows;
- if (enabled && !(prev && next)) {
- createArrows();
- }
- if (prev && next) {
- assign(arrows, { prev, next });
- display(wrapper, enabled ? "" : "none");
- addClass(wrapper, wrapperClasses = `${CLASS_ARROWS}--${options.direction}`);
- if (enabled) {
- listen();
- update();
- setAttribute([prev, next], ARIA_CONTROLS, track.id);
- emit(EVENT_ARROWS_MOUNTED, prev, next);
- }
- }
- }
- function destroy() {
- event.destroy();
- removeClass(wrapper, wrapperClasses);
- if (created) {
- remove(placeholder ? [prev, next] : wrapper);
- prev = next = null;
- } else {
- removeAttribute([prev, next], ALL_ATTRIBUTES);
- }
- }
- function listen() {
- on([EVENT_MOUNTED, EVENT_MOVED, EVENT_REFRESH, EVENT_SCROLLED, EVENT_END_INDEX_CHANGED], update);
- bind(next, "click", apply(go, ">"));
- bind(prev, "click", apply(go, "<"));
- }
- function go(control) {
- Controller.go(control, true);
- }
- function createArrows() {
- wrapper = placeholder || create("div", classes.arrows);
- prev = createArrow(true);
- next = createArrow(false);
- created = true;
- append(wrapper, [prev, next]);
- !placeholder && before(wrapper, track);
- }
- function createArrow(prev2) {
- 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}" focusable="false"><path d="${options.arrowPath || PATH}" />`;
- return parseHtml(arrow);
- }
- function update() {
- if (prev && next) {
- const index = Splide2.index;
- const prevIndex = Controller.getPrev();
- const nextIndex = Controller.getNext();
- const prevLabel = prevIndex > -1 && index < prevIndex ? i18n.last : i18n.prev;
- const nextLabel = nextIndex > -1 && index > nextIndex ? i18n.first : i18n.next;
- prev.disabled = prevIndex < 0;
- next.disabled = nextIndex < 0;
- setAttribute(prev, ARIA_LABEL, prevLabel);
- setAttribute(next, ARIA_LABEL, nextLabel);
- emit(EVENT_ARROWS_UPDATED, prev, next, prevIndex, nextIndex);
- }
- }
- return {
- arrows,
- mount,
- destroy,
- update
- };
- }
- const INTERVAL_DATA_ATTRIBUTE = `${DATA_ATTRIBUTE}-interval`;
- function Autoplay(Splide2, Components2, options) {
- const { on, bind, emit } = EventInterface(Splide2);
- const interval = RequestInterval(options.interval, Splide2.go.bind(Splide2, ">"), onAnimationFrame);
- const { isPaused } = interval;
- const { Elements, Elements: { root, toggle } } = Components2;
- const { autoplay } = options;
- let hovered;
- let focused;
- let stopped = autoplay === "pause";
- function mount() {
- if (autoplay) {
- listen();
- toggle && setAttribute(toggle, ARIA_CONTROLS, Elements.track.id);
- stopped || play();
- update();
- }
- }
- function listen() {
- if (options.pauseOnHover) {
- bind(root, "mouseenter mouseleave", (e) => {
- hovered = e.type === "mouseenter";
- autoToggle();
- });
- }
- if (options.pauseOnFocus) {
- bind(root, "focusin focusout", (e) => {
- focused = e.type === "focusin";
- autoToggle();
- });
- }
- if (toggle) {
- bind(toggle, "click", () => {
- stopped ? play() : pause(true);
- });
- }
- on([EVENT_MOVE, EVENT_SCROLL, EVENT_REFRESH], interval.rewind);
- on(EVENT_MOVE, onMove);
- }
- function play() {
- if (isPaused() && Components2.Slides.isEnough()) {
- interval.start(!options.resetProgress);
- focused = hovered = stopped = false;
- update();
- emit(EVENT_AUTOPLAY_PLAY);
- }
- }
- function pause(stop = true) {
- stopped = !!stop;
- update();
- if (!isPaused()) {
- interval.pause();
- emit(EVENT_AUTOPLAY_PAUSE);
- }
- }
- function autoToggle() {
- if (!stopped) {
- hovered || focused ? pause(false) : play();
- }
- }
- function update() {
- if (toggle) {
- toggleClass(toggle, CLASS_ACTIVE, !stopped);
- setAttribute(toggle, ARIA_LABEL, options.i18n[stopped ? "play" : "pause"]);
- }
- }
- function onAnimationFrame(rate) {
- const { bar } = Elements;
- bar && style(bar, "width", `${rate * 100}%`);
- emit(EVENT_AUTOPLAY_PLAYING, rate);
- }
- function onMove(index) {
- const Slide = Components2.Slides.getAt(index);
- interval.set(Slide && +getAttribute(Slide.slide, INTERVAL_DATA_ATTRIBUTE) || options.interval);
- }
- return {
- mount,
- destroy: interval.cancel,
- play,
- pause,
- isPaused
- };
- }
- function Cover(Splide2, Components2, options) {
- const { on } = EventInterface(Splide2);
- function mount() {
- if (options.cover) {
- on(EVENT_LAZYLOAD_LOADED, apply(toggle, true));
- on([EVENT_MOUNTED, EVENT_UPDATED, EVENT_REFRESH], apply(cover, true));
- }
- }
- function cover(cover2) {
- Components2.Slides.forEach((Slide) => {
- const img = child(Slide.container || Slide.slide, "img");
- if (img && img.src) {
- toggle(cover2, img, Slide);
- }
- });
- }
- function toggle(cover2, img, Slide) {
- Slide.style("background", cover2 ? `center/cover no-repeat url("${img.src}")` : "", true);
- display(img, cover2 ? "none" : "");
- }
- return {
- mount,
- destroy: apply(cover, false)
- };
- }
- const BOUNCE_DIFF_THRESHOLD = 10;
- const BOUNCE_DURATION = 600;
- const FRICTION_FACTOR = 0.6;
- const BASE_VELOCITY = 1.5;
- const MIN_DURATION = 800;
- function Scroll(Splide2, Components2, options) {
- const { on, emit } = EventInterface(Splide2);
- const { state: { set } } = Splide2;
- const { Move } = Components2;
- const { getPosition, getLimit, exceededLimit, translate } = Move;
- const isSlide = Splide2.is(SLIDE);
- let interval;
- let callback;
- let friction = 1;
- function mount() {
- on(EVENT_MOVE, clear);
- on([EVENT_UPDATED, EVENT_REFRESH], cancel);
- }
- function scroll(destination, duration, snap, onScrolled, noConstrain) {
- const from = getPosition();
- clear();
- if (snap && (!isSlide || !exceededLimit())) {
- const size = Components2.Layout.sliderSize();
- const offset = sign(destination) * size * floor(abs(destination) / size) || 0;
- destination = Move.toPosition(Components2.Controller.toDest(destination % size)) + offset;
- }
- const noDistance = approximatelyEqual(from, destination, 1);
- friction = 1;
- duration = noDistance ? 0 : duration || max(abs(destination - from) / BASE_VELOCITY, MIN_DURATION);
- callback = onScrolled;
- interval = RequestInterval(duration, onEnd, apply(update, from, destination, noConstrain), 1);
- set(SCROLLING);
- emit(EVENT_SCROLL);
- interval.start();
- }
- function onEnd() {
- set(IDLE);
- callback && callback();
- emit(EVENT_SCROLLED);
- }
- function update(from, to, noConstrain, rate) {
- const position = getPosition();
- const target = from + (to - from) * easing(rate);
- const diff = (target - position) * friction;
- translate(position + diff);
- if (isSlide && !noConstrain && exceededLimit()) {
- friction *= FRICTION_FACTOR;
- if (abs(diff) < BOUNCE_DIFF_THRESHOLD) {
- scroll(getLimit(exceededLimit(true)), BOUNCE_DURATION, false, callback, true);
- }
- }
- }
- function clear() {
- if (interval) {
- interval.cancel();
- }
- }
- function cancel() {
- if (interval && !interval.isPaused()) {
- clear();
- onEnd();
- }
- }
- function easing(t) {
- const { easingFunc } = options;
- return easingFunc ? easingFunc(t) : 1 - Math.pow(1 - t, 4);
- }
- return {
- mount,
- destroy: clear,
- scroll,
- cancel
- };
- }
- const SCROLL_LISTENER_OPTIONS = { passive: false, capture: true };
- function Drag(Splide2, Components2, options) {
- const { on, emit, bind, unbind } = EventInterface(Splide2);
- const { state } = Splide2;
- const { Move, Scroll, Controller, Elements: { track }, Media: { reduce } } = Components2;
- const { resolve, orient } = Components2.Direction;
- const { getPosition, exceededLimit } = Move;
- let basePosition;
- let baseEvent;
- let prevBaseEvent;
- let isFree;
- let dragging;
- let exceeded = false;
- let clickPrevented;
- let disabled;
- let target;
- function mount() {
- bind(track, POINTER_MOVE_EVENTS, noop, SCROLL_LISTENER_OPTIONS);
- bind(track, POINTER_UP_EVENTS, noop, SCROLL_LISTENER_OPTIONS);
- bind(track, POINTER_DOWN_EVENTS, onPointerDown, SCROLL_LISTENER_OPTIONS);
- bind(track, "click", onClick, { capture: true });
- bind(track, "dragstart", prevent);
- on([EVENT_MOUNTED, EVENT_UPDATED], init);
- }
- function init() {
- const { drag } = options;
- disable(!drag);
- isFree = drag === "free";
- }
- function onPointerDown(e) {
- clickPrevented = false;
- if (!disabled) {
- const isTouch = isTouchEvent(e);
- if (isDraggable(e.target) && (isTouch || !e.button)) {
- if (!Controller.isBusy()) {
- target = isTouch ? track : window;
- dragging = state.is([MOVING, SCROLLING]);
- prevBaseEvent = null;
- bind(target, POINTER_MOVE_EVENTS, onPointerMove, SCROLL_LISTENER_OPTIONS);
- bind(target, POINTER_UP_EVENTS, onPointerUp, SCROLL_LISTENER_OPTIONS);
- Move.cancel();
- Scroll.cancel();
- save(e);
- } else {
- prevent(e, true);
- }
- }
- }
- }
- function onPointerMove(e) {
- if (!state.is(DRAGGING)) {
- state.set(DRAGGING);
- emit(EVENT_DRAG);
- }
- if (e.cancelable) {
- if (dragging) {
- Move.translate(basePosition + constrain(diffCoord(e)));
- const expired = diffTime(e) > LOG_INTERVAL;
- const hasExceeded = exceeded !== (exceeded = exceededLimit());
- if (expired || hasExceeded) {
- save(e);
- }
- clickPrevented = true;
- emit(EVENT_DRAGGING);
- prevent(e);
- } else if (isSliderDirection(e)) {
- dragging = shouldStart(e);
- prevent(e);
- }
- }
- }
- function onPointerUp(e) {
- if (state.is(DRAGGING)) {
- state.set(IDLE);
- emit(EVENT_DRAGGED);
- }
- if (dragging) {
- move(e);
- prevent(e);
- }
- unbind(target, POINTER_MOVE_EVENTS, onPointerMove);
- unbind(target, POINTER_UP_EVENTS, onPointerUp);
- dragging = false;
- }
- function onClick(e) {
- if (!disabled && clickPrevented) {
- prevent(e, true);
- }
- }
- function save(e) {
- prevBaseEvent = baseEvent;
- baseEvent = e;
- basePosition = getPosition();
- }
- function move(e) {
- const velocity = computeVelocity(e);
- const destination = computeDestination(velocity);
- const rewind = options.rewind && options.rewindByDrag;
- reduce(false);
- if (isFree) {
- Controller.scroll(destination, 0, options.snap);
- } else if (Splide2.is(FADE)) {
- Controller.go(orient(sign(velocity)) < 0 ? rewind ? "<" : "-" : rewind ? ">" : "+");
- } else if (Splide2.is(SLIDE) && exceeded && rewind) {
- Controller.go(exceededLimit(true) ? ">" : "<");
- } else {
- Controller.go(Controller.toDest(destination), true);
- }
- reduce(true);
- }
- function shouldStart(e) {
- const { dragMinThreshold: thresholds } = options;
- const isObj = isObject(thresholds);
- const mouse = isObj && thresholds.mouse || 0;
- const touch = (isObj ? thresholds.touch : +thresholds) || 10;
- return abs(diffCoord(e)) > (isTouchEvent(e) ? touch : mouse);
- }
- function isSliderDirection(e) {
- return abs(diffCoord(e)) > abs(diffCoord(e, true));
- }
- function computeVelocity(e) {
- if (Splide2.is(LOOP) || !exceeded) {
- const time = diffTime(e);
- if (time && time < LOG_INTERVAL) {
- return diffCoord(e) / time;
- }
- }
- return 0;
- }
- function computeDestination(velocity) {
- return getPosition() + sign(velocity) * min(
- abs(velocity) * (options.flickPower || 600),
- isFree ? Infinity : Components2.Layout.listSize() * (options.flickMaxPages || 1)
- );
- }
- function diffCoord(e, orthogonal) {
- return coordOf(e, orthogonal) - coordOf(getBaseEvent(e), orthogonal);
- }
- function diffTime(e) {
- return timeOf(e) - timeOf(getBaseEvent(e));
- }
- function getBaseEvent(e) {
- return baseEvent === e && prevBaseEvent || baseEvent;
- }
- function coordOf(e, orthogonal) {
- return (isTouchEvent(e) ? e.changedTouches[0] : e)[`page${resolve(orthogonal ? "Y" : "X")}`];
- }
- function constrain(diff) {
- return diff / (exceeded && Splide2.is(SLIDE) ? FRICTION : 1);
- }
- function isDraggable(target2) {
- const { noDrag } = options;
- return !matches(target2, `.${CLASS_PAGINATION_PAGE}, .${CLASS_ARROW}`) && (!noDrag || !matches(target2, noDrag));
- }
- function isTouchEvent(e) {
- return typeof TouchEvent !== "undefined" && e instanceof TouchEvent;
- }
- function isDragging() {
- return dragging;
- }
- function disable(value) {
- disabled = value;
- }
- return {
- mount,
- disable,
- isDragging
- };
- }
- const NORMALIZATION_MAP = {
- Spacebar: " ",
- Right: ARROW_RIGHT,
- Left: ARROW_LEFT,
- Up: ARROW_UP,
- Down: ARROW_DOWN
- };
- function normalizeKey(key) {
- key = isString(key) ? key : key.key;
- return NORMALIZATION_MAP[key] || key;
- }
- const KEYBOARD_EVENT = "keydown";
- function Keyboard(Splide2, Components2, options) {
- const { on, bind, unbind } = EventInterface(Splide2);
- const { root } = Splide2;
- const { resolve } = Components2.Direction;
- let target;
- let disabled;
- function mount() {
- init();
- on(EVENT_UPDATED, destroy);
- on(EVENT_UPDATED, init);
- on(EVENT_MOVE, onMove);
- }
- function init() {
- const { keyboard } = options;
- if (keyboard) {
- target = keyboard === "global" ? window : root;
- bind(target, KEYBOARD_EVENT, onKeydown);
- }
- }
- function destroy() {
- unbind(target, KEYBOARD_EVENT);
- }
- function disable(value) {
- disabled = value;
- }
- function onMove() {
- const _disabled = disabled;
- disabled = true;
- nextTick(() => {
- disabled = _disabled;
- });
- }
- function onKeydown(e) {
- if (!disabled) {
- const key = normalizeKey(e);
- if (key === resolve(ARROW_LEFT)) {
- Splide2.go("<");
- } else if (key === resolve(ARROW_RIGHT)) {
- Splide2.go(">");
- }
- }
- }
- return {
- mount,
- destroy,
- disable
- };
- }
- const SRC_DATA_ATTRIBUTE = `${DATA_ATTRIBUTE}-lazy`;
- const SRCSET_DATA_ATTRIBUTE = `${SRC_DATA_ATTRIBUTE}-srcset`;
- const IMAGE_SELECTOR = `[${SRC_DATA_ATTRIBUTE}], [${SRCSET_DATA_ATTRIBUTE}]`;
- function LazyLoad(Splide2, Components2, options) {
- const { on, off, bind, emit } = EventInterface(Splide2);
- const isSequential = options.lazyLoad === "sequential";
- const events = [EVENT_MOVED, EVENT_SCROLLED];
- let entries = [];
- function mount() {
- if (options.lazyLoad) {
- init();
- on(EVENT_REFRESH, init);
- }
- }
- function init() {
- empty(entries);
- register();
- if (isSequential) {
- loadNext();
- } else {
- off(events);
- on(events, check);
- check();
- }
- }
- function register() {
- Components2.Slides.forEach((Slide) => {
- queryAll(Slide.slide, IMAGE_SELECTOR).forEach((img) => {
- const src = getAttribute(img, SRC_DATA_ATTRIBUTE);
- const srcset = getAttribute(img, SRCSET_DATA_ATTRIBUTE);
- if (src !== img.src || srcset !== img.srcset) {
- const className = options.classes.spinner;
- const parent = img.parentElement;
- const spinner = child(parent, `.${className}`) || create("span", className, parent);
- entries.push([img, Slide, spinner]);
- img.src || display(img, "none");
- }
- });
- });
- }
- function check() {
- entries = entries.filter((data) => {
- const distance = options.perPage * ((options.preloadPages || 1) + 1) - 1;
- return data[1].isWithin(Splide2.index, distance) ? load(data) : true;
- });
- entries.length || off(events);
- }
- function load(data) {
- const [img] = data;
- addClass(data[1].slide, CLASS_LOADING);
- bind(img, "load error", apply(onLoad, data));
- setAttribute(img, "src", getAttribute(img, SRC_DATA_ATTRIBUTE));
- setAttribute(img, "srcset", getAttribute(img, SRCSET_DATA_ATTRIBUTE));
- removeAttribute(img, SRC_DATA_ATTRIBUTE);
- removeAttribute(img, SRCSET_DATA_ATTRIBUTE);
- }
- function onLoad(data, e) {
- const [img, Slide] = data;
- removeClass(Slide.slide, CLASS_LOADING);
- if (e.type !== "error") {
- remove(data[2]);
- display(img, "");
- emit(EVENT_LAZYLOAD_LOADED, img, Slide);
- emit(EVENT_RESIZE);
- }
- isSequential && loadNext();
- }
- function loadNext() {
- entries.length && load(entries.shift());
- }
- return {
- mount,
- destroy: apply(empty, entries),
- check
- };
- }
- function Pagination(Splide2, Components2, options) {
- const event = EventInterface(Splide2);
- const { on, emit, bind } = event;
- const { Slides, Elements, Controller } = Components2;
- const { hasFocus, getIndex, go } = Controller;
- const { resolve } = Components2.Direction;
- const { pagination: placeholder } = Elements;
- const items = [];
- let list;
- let paginationClasses;
- function mount() {
- destroy();
- on([EVENT_UPDATED, EVENT_REFRESH, EVENT_END_INDEX_CHANGED], mount);
- const enabled = options.pagination;
- placeholder && display(placeholder, enabled ? "" : "none");
- if (enabled) {
- on([EVENT_MOVE, EVENT_SCROLL, EVENT_SCROLLED], update);
- createPagination();
- update();
- emit(EVENT_PAGINATION_MOUNTED, { list, items }, getAt(Splide2.index));
- }
- }
- function destroy() {
- if (list) {
- remove(placeholder ? slice(list.children) : list);
- removeClass(list, paginationClasses);
- empty(items);
- list = null;
- }
- event.destroy();
- }
- function createPagination() {
- const { length } = Splide2;
- const { classes, i18n, perPage } = options;
- const max = hasFocus() ? Controller.getEnd() + 1 : ceil(length / perPage);
- list = placeholder || create("ul", classes.pagination, Elements.track.parentElement);
- addClass(list, paginationClasses = `${CLASS_PAGINATION}--${getDirection()}`);
- setAttribute(list, ROLE, "tablist");
- setAttribute(list, ARIA_LABEL, i18n.select);
- setAttribute(list, ARIA_ORIENTATION, getDirection() === TTB ? "vertical" : "");
- for (let i = 0; i < max; i++) {
- const li = create("li", null, list);
- const button = create("button", { class: classes.page, type: "button" }, li);
- const controls = Slides.getIn(i).map((Slide) => Slide.slide.id);
- const text = !hasFocus() && perPage > 1 ? i18n.pageX : i18n.slideX;
- bind(button, "click", apply(onClick, i));
- if (options.paginationKeyboard) {
- bind(button, "keydown", apply(onKeydown, i));
- }
- setAttribute(li, ROLE, "presentation");
- setAttribute(button, ROLE, "tab");
- setAttribute(button, ARIA_CONTROLS, controls.join(" "));
- setAttribute(button, ARIA_LABEL, format(text, i + 1));
- setAttribute(button, TAB_INDEX, -1);
- items.push({ li, button, page: i });
- }
- }
- function onClick(page) {
- go(`>${page}`, true);
- }
- function onKeydown(page, e) {
- const { length } = items;
- const key = normalizeKey(e);
- const dir = getDirection();
- let nextPage = -1;
- if (key === resolve(ARROW_RIGHT, false, dir)) {
- nextPage = ++page % length;
- } else if (key === resolve(ARROW_LEFT, false, dir)) {
- nextPage = (--page + length) % length;
- } else if (key === "Home") {
- nextPage = 0;
- } else if (key === "End") {
- nextPage = length - 1;
- }
- const item = items[nextPage];
- if (item) {
- focus(item.button);
- go(`>${nextPage}`);
- prevent(e, true);
- }
- }
- function getDirection() {
- return options.paginationDirection || options.direction;
- }
- function getAt(index) {
- return items[Controller.toPage(index)];
- }
- function update() {
- const prev = getAt(getIndex(true));
- const curr = getAt(getIndex());
- if (prev) {
- const { button } = prev;
- removeClass(button, CLASS_ACTIVE);
- removeAttribute(button, ARIA_SELECTED);
- setAttribute(button, TAB_INDEX, -1);
- }
- if (curr) {
- const { button } = curr;
- addClass(button, CLASS_ACTIVE);
- setAttribute(button, ARIA_SELECTED, true);
- setAttribute(button, TAB_INDEX, "");
- }
- emit(EVENT_PAGINATION_UPDATED, { list, items }, prev, curr);
- }
- return {
- items,
- mount,
- destroy,
- getAt,
- update
- };
- }
- const TRIGGER_KEYS = [" ", "Enter"];
- function Sync(Splide2, Components2, options) {
- const { isNavigation, slideFocus } = options;
- const events = [];
- function mount() {
- Splide2.splides.forEach((target) => {
- if (!target.isParent) {
- sync(Splide2, target.splide);
- sync(target.splide, Splide2);
- }
- });
- if (isNavigation) {
- navigate();
- }
- }
- function destroy() {
- events.forEach((event) => {
- event.destroy();
- });
- empty(events);
- }
- function remount() {
- destroy();
- mount();
- }
- function sync(splide, target) {
- const event = EventInterface(splide);
- event.on(EVENT_MOVE, (index, prev, dest) => {
- target.go(target.is(LOOP) ? dest : index);
- });
- events.push(event);
- }
- function navigate() {
- const event = EventInterface(Splide2);
- const { on } = event;
- on(EVENT_CLICK, onClick);
- on(EVENT_SLIDE_KEYDOWN, onKeydown);
- on([EVENT_MOUNTED, EVENT_UPDATED], update);
- events.push(event);
- event.emit(EVENT_NAVIGATION_MOUNTED, Splide2.splides);
- }
- function update() {
- setAttribute(Components2.Elements.list, ARIA_ORIENTATION, options.direction === TTB ? "vertical" : "");
- }
- function onClick(Slide) {
- Splide2.go(Slide.index);
- }
- function onKeydown(Slide, e) {
- if (includes(TRIGGER_KEYS, normalizeKey(e))) {
- onClick(Slide);
- prevent(e);
- }
- }
- return {
- setup: apply(
- Components2.Media.set,
- { slideFocus: isUndefined(slideFocus) ? isNavigation : slideFocus },
- true
- ),
- mount,
- destroy,
- remount
- };
- }
- function Wheel(Splide2, Components2, options) {
- const { bind } = EventInterface(Splide2);
- let lastTime = 0;
- function mount() {
- if (options.wheel) {
- bind(Components2.Elements.track, "wheel", onWheel, SCROLL_LISTENER_OPTIONS);
- }
- }
- function onWheel(e) {
- if (e.cancelable) {
- const { deltaY } = e;
- const backwards = deltaY < 0;
- const timeStamp = timeOf(e);
- const min = options.wheelMinThreshold || 0;
- const sleep = options.wheelSleep || 0;
- if (abs(deltaY) > min && timeStamp - lastTime > sleep) {
- Splide2.go(backwards ? "<" : ">");
- lastTime = timeStamp;
- }
- shouldPrevent(backwards) && prevent(e);
- }
- }
- function shouldPrevent(backwards) {
- return !options.releaseWheel || Splide2.state.is(MOVING) || Components2.Controller.getAdjacent(backwards) !== -1;
- }
- return {
- mount
- };
- }
- const SR_REMOVAL_DELAY = 90;
- function Live(Splide2, Components2, options) {
- const { on } = EventInterface(Splide2);
- const { track } = Components2.Elements;
- const enabled = options.live && !options.isNavigation;
- const sr = create("span", CLASS_SR);
- const interval = RequestInterval(SR_REMOVAL_DELAY, apply(toggle, false));
- function mount() {
- if (enabled) {
- disable(!Components2.Autoplay.isPaused());
- setAttribute(track, ARIA_ATOMIC, true);
- sr.textContent = "\u2026";
- on(EVENT_AUTOPLAY_PLAY, apply(disable, true));
- on(EVENT_AUTOPLAY_PAUSE, apply(disable, false));
- on([EVENT_MOVED, EVENT_SCROLLED], apply(toggle, true));
- }
- }
- function toggle(active) {
- setAttribute(track, ARIA_BUSY, active);
- if (active) {
- append(track, sr);
- interval.start();
- } else {
- remove(sr);
- interval.cancel();
- }
- }
- function destroy() {
- removeAttribute(track, [ARIA_LIVE, ARIA_ATOMIC, ARIA_BUSY]);
- remove(sr);
- }
- function disable(disabled) {
- if (enabled) {
- setAttribute(track, ARIA_LIVE, disabled ? "off" : "polite");
- }
- }
- return {
- mount,
- disable,
- destroy
- };
- }
- var ComponentConstructors = /*#__PURE__*/Object.freeze({
- __proto__: null,
- Media: Media,
- Direction: Direction,
- Elements: Elements,
- Slides: Slides,
- Layout: Layout,
- Clones: Clones,
- Move: Move,
- Controller: Controller,
- Arrows: Arrows,
- Autoplay: Autoplay,
- Cover: Cover,
- Scroll: Scroll,
- Drag: Drag,
- Keyboard: Keyboard,
- LazyLoad: LazyLoad,
- Pagination: Pagination,
- Sync: Sync,
- Wheel: Wheel,
- Live: Live
- });
- const I18N = {
- prev: "Previous slide",
- next: "Next slide",
- first: "Go to first slide",
- last: "Go to last slide",
- slideX: "Go to slide %s",
- pageX: "Go to page %s",
- play: "Start autoplay",
- pause: "Pause autoplay",
- carousel: "carousel",
- slide: "slide",
- select: "Select a slide to show",
- slideLabel: "%s of %s"
- };
- const DEFAULTS = {
- type: "slide",
- role: "region",
- speed: 400,
- perPage: 1,
- cloneStatus: true,
- arrows: true,
- pagination: true,
- paginationKeyboard: true,
- interval: 5e3,
- pauseOnHover: true,
- pauseOnFocus: true,
- resetProgress: true,
- easing: "cubic-bezier(0.25, 1, 0.5, 1)",
- drag: true,
- direction: "ltr",
- trimSpace: true,
- focusableNodes: "a, button, textarea, input, select, iframe",
- live: true,
- classes: CLASSES,
- i18n: I18N,
- reducedMotion: {
- speed: 0,
- rewindSpeed: 0,
- autoplay: "pause"
- }
- };
- function Fade(Splide2, Components2, options) {
- const { Slides } = Components2;
- function mount() {
- EventInterface(Splide2).on([EVENT_MOUNTED, EVENT_REFRESH], init);
- }
- function init() {
- Slides.forEach((Slide) => {
- Slide.style("transform", `translateX(-${100 * Slide.index}%)`);
- });
- }
- function start(index, done) {
- Slides.style("transition", `opacity ${options.speed}ms ${options.easing}`);
- nextTick(done);
- }
- return {
- mount,
- start,
- cancel: noop
- };
- }
- function Slide(Splide2, Components2, options) {
- const { Move, Controller, Scroll } = Components2;
- const { list } = Components2.Elements;
- const transition = apply(style, list, "transition");
- let endCallback;
- function mount() {
- EventInterface(Splide2).bind(list, "transitionend", (e) => {
- if (e.target === list && endCallback) {
- cancel();
- endCallback();
- }
- });
- }
- function start(index, done) {
- const destination = Move.toPosition(index, true);
- const position = Move.getPosition();
- const speed = getSpeed(index);
- if (abs(destination - position) >= 1 && speed >= 1) {
- if (options.useScroll) {
- Scroll.scroll(destination, speed, false, done);
- } else {
- transition(`transform ${speed}ms ${options.easing}`);
- Move.translate(destination, true);
- endCallback = done;
- }
- } else {
- Move.jump(index);
- done();
- }
- }
- function cancel() {
- transition("");
- Scroll.cancel();
- }
- function getSpeed(index) {
- const { rewindSpeed } = options;
- if (Splide2.is(SLIDE) && rewindSpeed) {
- const prev = Controller.getIndex(true);
- const end = Controller.getEnd();
- if (prev === 0 && index >= end || prev >= end && index === 0) {
- return rewindSpeed;
- }
- }
- return options.speed;
- }
- return {
- mount,
- start,
- cancel
- };
- }
- class Splide {
- static defaults = {};
- static STATES = STATES;
- root;
- event = EventInterface();
- Components = {};
- state = State(CREATED);
- splides = [];
- _o = {};
- _C;
- _E = {};
- _T;
- constructor(target, options) {
- const root = isString(target) ? query(document, target) : target;
- assert(root, `${root} is invalid.`);
- this.root = root;
- options = merge({
- label: getAttribute(root, ARIA_LABEL) || "",
- labelledby: getAttribute(root, ARIA_LABELLEDBY) || ""
- }, DEFAULTS, Splide.defaults, options || {});
- try {
- merge(options, JSON.parse(getAttribute(root, DATA_ATTRIBUTE)));
- } catch (e) {
- assert(false, "Invalid JSON");
- }
- this._o = Object.create(merge({}, options));
- }
- mount(Extensions, Transition) {
- const { state, Components: Components2 } = this;
- assert(state.is([CREATED, DESTROYED]), "Already mounted!");
- state.set(CREATED);
- this._C = Components2;
- this._T = Transition || this._T || (this.is(FADE) ? Fade : Slide);
- this._E = Extensions || this._E;
- const Constructors = assign({}, ComponentConstructors, this._E, { Transition: this._T });
- forOwn(Constructors, (Component, key) => {
- const component = Component(this, Components2, this._o);
- Components2[key] = component;
- component.setup && component.setup();
- });
- forOwn(Components2, (component) => {
- component.mount && component.mount();
- });
- this.emit(EVENT_MOUNTED);
- addClass(this.root, CLASS_INITIALIZED);
- state.set(IDLE);
- this.emit(EVENT_READY);
- return this;
- }
- sync(splide) {
- this.splides.push({ splide });
- splide.splides.push({ splide: this, isParent: true });
- if (this.state.is(IDLE)) {
- this._C.Sync.remount();
- splide.Components.Sync.remount();
- }
- return this;
- }
- go(control) {
- this._C.Controller.go(control);
- return this;
- }
- on(events, callback) {
- this.event.on(events, callback);
- return this;
- }
- off(events) {
- this.event.off(events);
- return this;
- }
- emit(event) {
- this.event.emit(event, ...slice(arguments, 1));
- return this;
- }
- add(slides, index) {
- this._C.Slides.add(slides, index);
- return this;
- }
- remove(matcher) {
- this._C.Slides.remove(matcher);
- return this;
- }
- is(type) {
- return this._o.type === type;
- }
- refresh() {
- this.emit(EVENT_REFRESH);
- return this;
- }
- destroy(completely = true) {
- const { event, state } = this;
- if (state.is(CREATED)) {
- EventInterface(this).on(EVENT_READY, this.destroy.bind(this, completely));
- } else {
- forOwn(this._C, (component) => {
- component.destroy && component.destroy(completely);
- }, true);
- event.emit(EVENT_DESTROY);
- event.destroy();
- completely && empty(this.splides);
- state.set(DESTROYED);
- }
- return this;
- }
- get options() {
- return this._o;
- }
- set options(options) {
- this._C.Media.set(options, true, true);
- }
- get length() {
- return this._C.Slides.getLength(true);
- }
- get index() {
- return this._C.Controller.getIndex();
- }
- }
- const CLASS_RENDERED = "is-rendered";
- const RENDERER_DEFAULT_CONFIG = {
- listTag: "ul",
- slideTag: "li"
- };
- class Style {
- styles = {};
- id;
- options;
- constructor(id, options) {
- this.id = id;
- this.options = options;
- }
- rule(selector, prop, value, breakpoint) {
- breakpoint = breakpoint || "default";
- const selectors = this.styles[breakpoint] = this.styles[breakpoint] || {};
- const styles = selectors[selector] = selectors[selector] || {};
- styles[prop] = value;
- }
- build() {
- let css = "";
- if (this.styles.default) {
- css += this.buildSelectors(this.styles.default);
- }
- Object.keys(this.styles).sort((n, m) => this.options.mediaQuery === "min" ? +n - +m : +m - +n).forEach((breakpoint) => {
- if (breakpoint !== "default") {
- css += `@media screen and (max-width: ${breakpoint}px) {`;
- css += this.buildSelectors(this.styles[breakpoint]);
- css += `}`;
- }
- });
- return css;
- }
- buildSelectors(selectors) {
- let css = "";
- forOwn(selectors, (styles, selector) => {
- selector = `#${this.id} ${selector}`.trim();
- css += `${selector} {`;
- forOwn(styles, (value, prop) => {
- if (value || value === 0) {
- css += `${prop}: ${value};`;
- }
- });
- css += "}";
- });
- return css;
- }
- }
- class SplideRenderer {
- static clean(splide) {
- const { on } = EventInterface(splide);
- const { root } = splide;
- const clones = queryAll(root, `.${CLASS_CLONE}`);
- on(EVENT_MOUNTED, () => {
- remove(child(root, "style"));
- });
- remove(clones);
- }
- contents;
- slides = [];
- Direction;
- Style;
- options = {};
- config;
- id;
- breakpoints = [];
- constructor(contents, options, config, defaults) {
- merge(DEFAULTS, defaults || {});
- merge(merge(this.options, DEFAULTS), options || {});
- this.contents = contents;
- this.config = assign({}, RENDERER_DEFAULT_CONFIG, config || {});
- this.id = this.config.id || uniqueId("splide");
- this.Style = new Style(this.id, this.options);
- this.Direction = Direction(null, null, this.options);
- assert(this.contents.length, "Provide at least 1 content.");
- this.init();
- }
- init() {
- this.parseBreakpoints();
- this.initSlides();
- this.registerRootStyles();
- this.registerTrackStyles();
- this.registerSlideStyles();
- this.registerListStyles();
- }
- initSlides() {
- push(this.slides, this.contents.map((content, index) => {
- content = isString(content) ? { html: content } : content;
- content.styles = content.styles || {};
- content.attrs = content.attrs || {};
- this.cover(content);
- const classes = `${this.options.classes.slide} ${index === 0 ? CLASS_ACTIVE : ""}`;
- assign(content.attrs, {
- class: `${classes} ${content.attrs.class || ""}`.trim(),
- style: this.buildStyles(content.styles)
- });
- return content;
- }));
- if (this.isLoop()) {
- this.generateClones(this.slides);
- }
- }
- registerRootStyles() {
- this.breakpoints.forEach(([width, options]) => {
- this.Style.rule(" ", "max-width", unit(options.width), width);
- });
- }
- registerTrackStyles() {
- const { Style: Style2 } = this;
- const selector = `.${CLASS_TRACK}`;
- this.breakpoints.forEach(([width, options]) => {
- Style2.rule(selector, this.resolve("paddingLeft"), this.cssPadding(options, false), width);
- Style2.rule(selector, this.resolve("paddingRight"), this.cssPadding(options, true), width);
- Style2.rule(selector, "height", this.cssTrackHeight(options), width);
- });
- }
- registerListStyles() {
- const { Style: Style2 } = this;
- const selector = `.${CLASS_LIST}`;
- this.breakpoints.forEach(([width, options]) => {
- Style2.rule(selector, "transform", this.buildTranslate(options), width);
- if (!this.cssSlideHeight(options)) {
- Style2.rule(selector, "aspect-ratio", this.cssAspectRatio(options), width);
- }
- });
- }
- registerSlideStyles() {
- const { Style: Style2 } = this;
- const selector = `.${CLASS_SLIDE}`;
- this.breakpoints.forEach(([width, options]) => {
- Style2.rule(selector, "width", this.cssSlideWidth(options), width);
- Style2.rule(selector, "height", this.cssSlideHeight(options) || "100%", width);
- Style2.rule(selector, this.resolve("marginRight"), unit(options.gap) || "0px", width);
- Style2.rule(`${selector} > img`, "display", options.cover ? "none" : "inline", width);
- });
- }
- buildTranslate(options) {
- const { resolve, orient } = this.Direction;
- const values = [];
- values.push(this.cssOffsetClones(options));
- values.push(this.cssOffsetGaps(options));
- if (this.isCenter(options)) {
- values.push(this.buildCssValue(orient(-50), "%"));
- values.push(...this.cssOffsetCenter(options));
- }
- return values.filter(Boolean).map((value) => `translate${resolve("X")}(${value})`).join(" ");
- }
- cssOffsetClones(options) {
- const { resolve, orient } = this.Direction;
- const cloneCount = this.getCloneCount();
- if (this.isFixedWidth(options)) {
- const { value, unit: unit2 } = this.parseCssValue(options[resolve("fixedWidth")]);
- return this.buildCssValue(orient(value) * cloneCount, unit2);
- }
- const percent = 100 * cloneCount / options.perPage;
- return `${orient(percent)}%`;
- }
- cssOffsetCenter(options) {
- const { resolve, orient } = this.Direction;
- if (this.isFixedWidth(options)) {
- const { value, unit: unit2 } = this.parseCssValue(options[resolve("fixedWidth")]);
- return [this.buildCssValue(orient(value / 2), unit2)];
- }
- const values = [];
- const { perPage, gap } = options;
- values.push(`${orient(50 / perPage)}%`);
- if (gap) {
- const { value, unit: unit2 } = this.parseCssValue(gap);
- const gapOffset = (value / perPage - value) / 2;
- values.push(this.buildCssValue(orient(gapOffset), unit2));
- }
- return values;
- }
- cssOffsetGaps(options) {
- const cloneCount = this.getCloneCount();
- if (cloneCount && options.gap) {
- const { orient } = this.Direction;
- const { value, unit: unit2 } = this.parseCssValue(options.gap);
- if (this.isFixedWidth(options)) {
- return this.buildCssValue(orient(value * cloneCount), unit2);
- }
- const { perPage } = options;
- const gaps = cloneCount / perPage;
- return this.buildCssValue(orient(gaps * value), unit2);
- }
- return "";
- }
- resolve(prop) {
- return camelToKebab(this.Direction.resolve(prop));
- }
- cssPadding(options, right) {
- const { padding } = options;
- const prop = this.Direction.resolve(right ? "right" : "left", true);
- return padding && unit(padding[prop] || (isObject(padding) ? 0 : padding)) || "0px";
- }
- cssTrackHeight(options) {
- let height = "";
- if (this.isVertical()) {
- height = this.cssHeight(options);
- assert(height, '"height" is missing.');
- height = `calc(${height} - ${this.cssPadding(options, false)} - ${this.cssPadding(options, true)})`;
- }
- return height;
- }
- cssHeight(options) {
- return unit(options.height);
- }
- cssSlideWidth(options) {
- return options.autoWidth ? "" : unit(options.fixedWidth) || (this.isVertical() ? "" : this.cssSlideSize(options));
- }
- cssSlideHeight(options) {
- return unit(options.fixedHeight) || (this.isVertical() ? options.autoHeight ? "" : this.cssSlideSize(options) : this.cssHeight(options));
- }
- cssSlideSize(options) {
- const gap = unit(options.gap);
- return `calc((100%${gap && ` + ${gap}`})/${options.perPage || 1}${gap && ` - ${gap}`})`;
- }
- cssAspectRatio(options) {
- const { heightRatio } = options;
- return heightRatio ? `${1 / heightRatio}` : "";
- }
- buildCssValue(value, unit2) {
- return `${value}${unit2}`;
- }
- parseCssValue(value) {
- if (isString(value)) {
- const number = parseFloat(value) || 0;
- const unit2 = value.replace(/\d*(\.\d*)?/, "") || "px";
- return { value: number, unit: unit2 };
- }
- return { value, unit: "px" };
- }
- parseBreakpoints() {
- const { breakpoints } = this.options;
- this.breakpoints.push(["default", this.options]);
- if (breakpoints) {
- forOwn(breakpoints, (options, width) => {
- this.breakpoints.push([width, merge(merge({}, this.options), options)]);
- });
- }
- }
- isFixedWidth(options) {
- return !!options[this.Direction.resolve("fixedWidth")];
- }
- isLoop() {
- return this.options.type === LOOP;
- }
- isCenter(options) {
- if (options.focus === "center") {
- if (this.isLoop()) {
- return true;
- }
- if (this.options.type === SLIDE) {
- return !this.options.trimSpace;
- }
- }
- return false;
- }
- isVertical() {
- return this.options.direction === TTB;
- }
- buildClasses() {
- const { options } = this;
- return [
- CLASS_ROOT,
- `${CLASS_ROOT}--${options.type}`,
- `${CLASS_ROOT}--${options.direction}`,
- options.drag && `${CLASS_ROOT}--draggable`,
- options.isNavigation && `${CLASS_ROOT}--nav`,
- CLASS_ACTIVE,
- !this.config.hidden && CLASS_RENDERED
- ].filter(Boolean).join(" ");
- }
- buildAttrs(attrs) {
- let attr = "";
- forOwn(attrs, (value, key) => {
- attr += value ? ` ${camelToKebab(key)}="${value}"` : "";
- });
- return attr.trim();
- }
- buildStyles(styles) {
- let style = "";
- forOwn(styles, (value, key) => {
- style += ` ${camelToKebab(key)}:${value};`;
- });
- return style.trim();
- }
- renderSlides() {
- const { slideTag: tag } = this.config;
- return this.slides.map((content) => {
- return `<${tag} ${this.buildAttrs(content.attrs)}>${content.html || ""}</${tag}>`;
- }).join("");
- }
- cover(content) {
- const { styles, html = "" } = content;
- if (this.options.cover && !this.options.lazyLoad) {
- const src = html.match(/<img.*?src\s*=\s*(['"])(.+?)\1.*?>/);
- if (src && src[2]) {
- styles.background = `center/cover no-repeat url('${src[2]}')`;
- }
- }
- }
- generateClones(contents) {
- const { classes } = this.options;
- const count = this.getCloneCount();
- const slides = contents.slice();
- while (slides.length < count) {
- push(slides, slides);
- }
- push(slides.slice(-count).reverse(), slides.slice(0, count)).forEach((content, index) => {
- const attrs = assign({}, content.attrs, { class: `${content.attrs.class} ${classes.clone}` });
- const clone = assign({}, content, { attrs });
- index < count ? contents.unshift(clone) : contents.push(clone);
- });
- }
- getCloneCount() {
- if (this.isLoop()) {
- const { options } = this;
- if (options.clones) {
- return options.clones;
- }
- const perPage = max(...this.breakpoints.map(([, options2]) => options2.perPage));
- return perPage * ((options.flickMaxPages || 1) + 1);
- }
- return 0;
- }
- renderArrows() {
- let html = "";
- html += `<div class="${this.options.classes.arrows}">`;
- html += this.renderArrow(true);
- html += this.renderArrow(false);
- html += `</div>`;
- return html;
- }
- renderArrow(prev) {
- const { classes, i18n } = this.options;
- const attrs = {
- class: `${classes.arrow} ${prev ? classes.prev : classes.next}`,
- type: "button",
- ariaLabel: prev ? i18n.prev : i18n.next
- };
- 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>`;
- }
- html() {
- const { rootClass, listTag, arrows, beforeTrack, afterTrack, slider, beforeSlider, afterSlider } = this.config;
- let html = "";
- html += `<div id="${this.id}" class="${this.buildClasses()} ${rootClass || ""}">`;
- html += `<style>${this.Style.build()}</style>`;
- if (slider) {
- html += beforeSlider || "";
- html += `<div class="splide__slider">`;
- }
- html += beforeTrack || "";
- if (arrows) {
- html += this.renderArrows();
- }
- html += `<div class="splide__track">`;
- html += `<${listTag} class="splide__list">`;
- html += this.renderSlides();
- html += `</${listTag}>`;
- html += `</div>`;
- html += afterTrack || "";
- if (slider) {
- html += `</div>`;
- html += afterSlider || "";
- }
- html += `</div>`;
- return html;
- }
- }
- export { CLASSES, CLASS_ACTIVE, CLASS_ARROW, CLASS_ARROWS, CLASS_ARROW_NEXT, CLASS_ARROW_PREV, CLASS_CLONE, CLASS_CONTAINER, CLASS_FOCUS_IN, CLASS_INITIALIZED, CLASS_LIST, CLASS_LOADING, CLASS_NEXT, CLASS_OVERFLOW, CLASS_PAGINATION, CLASS_PAGINATION_PAGE, CLASS_PREV, CLASS_PROGRESS, CLASS_PROGRESS_BAR, CLASS_ROOT, CLASS_SLIDE, CLASS_SPINNER, CLASS_SR, CLASS_TOGGLE, CLASS_TOGGLE_PAUSE, CLASS_TOGGLE_PLAY, CLASS_TRACK, CLASS_VISIBLE, DEFAULTS, EVENT_ACTIVE, EVENT_ARROWS_MOUNTED, EVENT_ARROWS_UPDATED, EVENT_AUTOPLAY_PAUSE, EVENT_AUTOPLAY_PLAY, EVENT_AUTOPLAY_PLAYING, EVENT_CLICK, EVENT_DESTROY, EVENT_DRAG, EVENT_DRAGGED, EVENT_DRAGGING, EVENT_END_INDEX_CHANGED, EVENT_HIDDEN, EVENT_INACTIVE, EVENT_LAZYLOAD_LOADED, EVENT_MOUNTED, EVENT_MOVE, EVENT_MOVED, EVENT_NAVIGATION_MOUNTED, EVENT_OVERFLOW, EVENT_PAGINATION_MOUNTED, EVENT_PAGINATION_UPDATED, EVENT_READY, EVENT_REFRESH, EVENT_RESIZE, EVENT_RESIZED, EVENT_SCROLL, EVENT_SCROLLED, EVENT_SHIFTED, EVENT_SLIDE_KEYDOWN, EVENT_UPDATED, EVENT_VISIBLE, EventBinder, EventInterface, FADE, LOOP, LTR, RTL, RequestInterval, SLIDE, STATUS_CLASSES, Splide, SplideRenderer, State, TTB, Throttle, Splide as default };
|