|
@@ -1171,6 +1171,7 @@
|
|
const { resolve, orient } = Components.Direction;
|
|
const { resolve, orient } = Components.Direction;
|
|
const { list, track } = Components.Elements;
|
|
const { list, track } = Components.Elements;
|
|
let Transition;
|
|
let Transition;
|
|
|
|
+ let indices;
|
|
function mount() {
|
|
function mount() {
|
|
Transition = Components.Transition;
|
|
Transition = Components.Transition;
|
|
on([EVENT_MOUNTED, EVENT_RESIZED, EVENT_UPDATED, EVENT_REFRESH], reposition);
|
|
on([EVENT_MOUNTED, EVENT_RESIZED, EVENT_UPDATED, EVENT_REFRESH], reposition);
|
|
@@ -1183,12 +1184,11 @@
|
|
}
|
|
}
|
|
}
|
|
}
|
|
function move(dest, index, prev, callback) {
|
|
function move(dest, index, prev, callback) {
|
|
|
|
+ Transition.cancel();
|
|
if (dest !== index && canShift(dest > prev)) {
|
|
if (dest !== index && canShift(dest > prev)) {
|
|
- cancel();
|
|
|
|
translate(shift(getPosition(), dest > prev), true);
|
|
translate(shift(getPosition(), dest > prev), true);
|
|
- } else {
|
|
|
|
- Transition.cancel();
|
|
|
|
}
|
|
}
|
|
|
|
+ indices = [index, prev, dest];
|
|
set(MOVING);
|
|
set(MOVING);
|
|
emit(EVENT_MOVE, index, prev, dest);
|
|
emit(EVENT_MOVE, index, prev, dest);
|
|
Transition.start(index, () => {
|
|
Transition.start(index, () => {
|
|
@@ -1209,10 +1209,9 @@
|
|
}
|
|
}
|
|
function loop(position) {
|
|
function loop(position) {
|
|
if (Splide.is(LOOP)) {
|
|
if (Splide.is(LOOP)) {
|
|
- const exceededMax = exceededLimit(true, position);
|
|
|
|
- const exceededMin = exceededLimit(false, position);
|
|
|
|
- if (exceededMin || exceededMax) {
|
|
|
|
- position = shift(position, exceededMax);
|
|
|
|
|
|
+ const diff = orient(position) - orient(getPosition());
|
|
|
|
+ if (diff && exceededLimit(diff > 0, position)) {
|
|
|
|
+ position = shift(position, diff > 0);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return position;
|
|
return position;
|
|
@@ -1224,8 +1223,11 @@
|
|
return position;
|
|
return position;
|
|
}
|
|
}
|
|
function cancel() {
|
|
function cancel() {
|
|
- translate(getPosition(), true);
|
|
|
|
- Transition.cancel();
|
|
|
|
|
|
+ if (Splide.state.is(MOVING) && indices) {
|
|
|
|
+ translate(getPosition(), true);
|
|
|
|
+ Transition.cancel();
|
|
|
|
+ emit(EVENT_MOVED, ...indices);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
function toIndex(position) {
|
|
function toIndex(position) {
|
|
const slides = Slides.get();
|
|
const slides = Slides.get();
|
|
@@ -1251,6 +1253,25 @@
|
|
const left = resolve("left");
|
|
const left = resolve("left");
|
|
return rect(list)[left] - rect(track)[left] + orient(getPadding(false));
|
|
return rect(list)[left] - rect(track)[left] + orient(getPadding(false));
|
|
}
|
|
}
|
|
|
|
+ function getRate() {
|
|
|
|
+ let rate;
|
|
|
|
+ if (Splide.is(FADE)) {
|
|
|
|
+ rate = Splide.index / (Splide.length - 1);
|
|
|
|
+ } else {
|
|
|
|
+ const isLoop = Splide.is(LOOP);
|
|
|
|
+ const position = orient(getPosition());
|
|
|
|
+ const min = orient(getLimit(false));
|
|
|
|
+ const max = orient(getLimit(true));
|
|
|
|
+ const size = sliderSize();
|
|
|
|
+ const curr = (position - min) % size;
|
|
|
|
+ const base = isLoop ? size : max - min;
|
|
|
|
+ rate = curr / base || 0;
|
|
|
|
+ if (isLoop && rate < 0) {
|
|
|
|
+ rate += 1;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return clamp(rate, 0, 1);
|
|
|
|
+ }
|
|
function trim(position) {
|
|
function trim(position) {
|
|
if (options.trimSpace && Splide.is(SLIDE)) {
|
|
if (options.trimSpace && Splide.is(SLIDE)) {
|
|
position = clamp(position, 0, orient(sliderSize(true) - listSize()));
|
|
position = clamp(position, 0, orient(sliderSize(true) - listSize()));
|
|
@@ -1284,6 +1305,7 @@
|
|
toIndex,
|
|
toIndex,
|
|
toPosition,
|
|
toPosition,
|
|
getPosition,
|
|
getPosition,
|
|
|
|
+ getRate,
|
|
getLimit,
|
|
getLimit,
|
|
exceededLimit,
|
|
exceededLimit,
|
|
reposition,
|
|
reposition,
|
|
@@ -1676,22 +1698,28 @@
|
|
on([EVENT_UPDATED, EVENT_REFRESH], cancel);
|
|
on([EVENT_UPDATED, EVENT_REFRESH], cancel);
|
|
}
|
|
}
|
|
function scroll(destination, duration, snap, onScrolled, noConstrain) {
|
|
function scroll(destination, duration, snap, onScrolled, noConstrain) {
|
|
- const from = getPosition();
|
|
|
|
clear();
|
|
clear();
|
|
- if (snap && (!isSlide || !exceededLimit())) {
|
|
|
|
- const size = Components.Layout.sliderSize();
|
|
|
|
- const offset = sign(destination) * size * floor(abs(destination) / size) || 0;
|
|
|
|
- destination = Move.toPosition(Components.Controller.toDest(destination % size)) + offset;
|
|
|
|
- }
|
|
|
|
- const immediately = approximatelyEqual(from, destination, 1) || duration === 0;
|
|
|
|
|
|
+ const dest = computeDestination(destination, snap);
|
|
|
|
+ const from = getPosition();
|
|
|
|
+ const immediately = approximatelyEqual(from, dest, 1) || duration === 0;
|
|
friction = 1;
|
|
friction = 1;
|
|
- duration = immediately ? 0 : duration || max(abs(destination - from) / BASE_VELOCITY, MIN_DURATION);
|
|
|
|
|
|
+ duration = immediately ? 0 : duration || max(abs(dest - from) / BASE_VELOCITY, MIN_DURATION);
|
|
callback = onScrolled;
|
|
callback = onScrolled;
|
|
- interval = RequestInterval(duration, onEnd, apply(update, from, destination, noConstrain), 1);
|
|
|
|
|
|
+ interval = RequestInterval(duration, onEnd, apply(update, from, dest, noConstrain), 1);
|
|
set(SCROLLING);
|
|
set(SCROLLING);
|
|
emit(EVENT_SCROLL);
|
|
emit(EVENT_SCROLL);
|
|
interval.start();
|
|
interval.start();
|
|
}
|
|
}
|
|
|
|
+ function computeDestination(destination, snap) {
|
|
|
|
+ if (snap) {
|
|
|
|
+ if (!isSlide || !exceededLimit()) {
|
|
|
|
+ const position = destination % Components.Layout.sliderSize();
|
|
|
|
+ const snapped = Move.toPosition(Components.Controller.toDest(position));
|
|
|
|
+ destination -= position - snapped;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return destination;
|
|
|
|
+ }
|
|
function onEnd() {
|
|
function onEnd() {
|
|
set(IDLE);
|
|
set(IDLE);
|
|
callback && callback();
|
|
callback && callback();
|