浏览代码

Refactoring.

NaotoshiFujita 3 年之前
父节点
当前提交
004016f944

+ 67 - 72
dist/js/splide.cjs.js

@@ -276,6 +276,10 @@ function raf(func) {
   return requestAnimationFrame(func);
 }
 
+function approximatelyEqual(x, y, epsilon) {
+  return Math.abs(x - y) < epsilon;
+}
+
 function between(number, minOrMax, maxOrMin, exclusive) {
   const min = Math.min(minOrMax, maxOrMin);
   const max = Math.max(minOrMax, maxOrMin);
@@ -1153,12 +1157,7 @@ function Layout(Splide2, Components2, options) {
     return 0;
   }
   function sliderSize() {
-    const firstSlide = getAt(0);
-    const lastSlide = getAt(Slides.getLength(true) - 1);
-    if (firstSlide && lastSlide) {
-      return rect(lastSlide.slide)[resolve("right")] - rect(firstSlide.slide)[resolve("left")];
-    }
-    return 0;
+    return totalSize(Splide2.length - 1, true) - totalSize(-1, true);
   }
   function getGap() {
     const Slide = getAt(0);
@@ -1184,71 +1183,50 @@ function Move(Splide2, Components2, options) {
   const { slideSize, getPadding, totalSize, listSize, sliderSize } = Components2.Layout;
   const { resolve, orient } = Components2.Direction;
   const { list, track } = Components2.Elements;
-  let looping;
   let waiting;
-  let currPosition = 0;
-  let positionRate = 0;
+  let shouldSnap = true;
   function mount() {
-    on([EVENT_RESIZE, EVENT_RESIZED, EVENT_UPDATED, EVENT_REFRESH], reposition, DEFAULT_EVENT_PRIORITY - 1);
+    on([EVENT_RESIZED, EVENT_UPDATED, EVENT_REFRESH], reposition, DEFAULT_EVENT_PRIORITY - 1);
   }
   function reposition() {
-    if (options.drag !== "free") {
+    if (exceededLimit(true)) {
+      translate(getLimit(true));
+    } else if (shouldSnap || (shouldSnap = canSnap())) {
       jump(Splide2.index);
-    } else {
-      if (!options[resolve("fixedWidth")] && !options[resolve("autoWidth")]) {
-        translate(listSize() * positionRate);
-      }
-      if (exceededLimit(true)) {
-        translate(getLimit(true));
-      } else {
-        snap(SNAP_THRESHOLD);
-      }
-    }
-  }
-  function snap(threshold) {
-    const position = getPosition();
-    const index = toIndex(position);
-    if (abs(position - toPosition(index)) < threshold) {
-      jump(index);
     }
   }
   function move(dest, index, prev) {
     if (!isBusy()) {
+      const { set } = Splide2.state;
       const position = getPosition();
-      looping = dest !== index;
-      waiting = options.waitForTransition;
-      Splide2.state.set(MOVING);
+      const looping = dest !== index;
+      waiting = looping || options.waitForTransition;
+      set(MOVING);
       emit(EVENT_MOVE, index, prev, dest);
       Components2.Transition.start(dest, () => {
-        onMoved(dest, index, prev, position);
+        looping && jump(index);
+        waiting = false;
+        set(IDLE);
+        emit(EVENT_MOVED, index, prev, dest);
+        if (options.trimSpace === "move" && dest !== prev && position === getPosition()) {
+          Components2.Controller.go(dest > prev ? ">" : "<");
+        }
       });
     }
   }
-  function onMoved(dest, index, prev, oldPosition) {
-    if (looping) {
-      jump(index);
-    }
-    waiting = false;
-    Splide2.state.set(IDLE);
-    emit(EVENT_MOVED, index, prev, dest);
-    if (options.trimSpace === "move" && dest !== prev && oldPosition === getPosition()) {
-      Components2.Controller.go(dest > prev ? ">" : "<");
-    }
-  }
   function jump(index) {
     waiting = false;
-    looping = false;
     Components2.Transition.cancel();
     translate(toPosition(index, true));
   }
   function translate(position) {
-    currPosition = loop(position);
-    positionRate = currPosition / listSize();
-    Components2.Style.ruleBy(list, "transform", `translate${resolve("X")}(${currPosition}px)`);
+    position = loop(position);
+    shouldSnap = canSnap(position);
+    Components2.Style.ruleBy(list, "transform", `translate${resolve("X")}(${100 * position / listSize()}%)`);
   }
   function loop(position) {
-    if (!looping && Splide2.is(LOOP)) {
-      const diff = position - currPosition;
+    if (!waiting && Splide2.is(LOOP)) {
+      const diff = position - getPosition();
       const exceededMin = exceededLimit(false, position);
       const exceededMax = exceededLimit(true, position);
       if (exceededMin && diff > 0 || exceededMax && diff < 0) {
@@ -1267,7 +1245,7 @@ function Move(Splide2, Components2, options) {
     let minDistance = Infinity;
     for (let i = 0; i < Slides.length; i++) {
       const slideIndex = Slides[i].index;
-      const distance = abs(toPosition(slideIndex) - position);
+      const distance = abs(toPosition(slideIndex, true) - position);
       if (distance < minDistance) {
         minDistance = distance;
         index = slideIndex;
@@ -1293,19 +1271,20 @@ function Move(Splide2, Components2, options) {
   }
   function offset(index) {
     const { focus } = options;
-    if (focus === "center") {
-      return (listSize() - slideSize(index, true)) / 2;
-    }
-    return (+focus || 0) * slideSize(index);
+    return focus === "center" ? (listSize() - slideSize(index, true)) / 2 : +focus * slideSize(index) || 0;
   }
   function getLimit(max) {
-    const trimming = !!options.trimSpace;
-    return max ? toPosition(Components2.Controller.getEnd(), trimming) : toPosition(0, trimming);
+    return toPosition(max ? Components2.Controller.getEnd() : 0, !!options.trimSpace);
+  }
+  function canSnap(position) {
+    position = isUndefined(position) ? getPosition() : position;
+    return abs(position - toPosition(toIndex(position), true)) < SNAP_THRESHOLD;
   }
   function isBusy() {
-    return !!(looping || waiting);
+    return waiting;
   }
-  function exceededLimit(max, position = currPosition) {
+  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;
@@ -1389,6 +1368,18 @@ function Controller(Splide2, Components2, options) {
   function getAdjacent(prev, destination) {
     const number = perMove || hasFocus() ? 1 : perPage;
     const dest = computeDestIndex(currIndex + number * (prev ? -1 : 1), currIndex);
+    if (dest === -1 && Splide2.is(SLIDE)) {
+      const position = Move.getPosition();
+      if (prev) {
+        if (!approximatelyEqual(position, 0, 1)) {
+          return 0;
+        }
+      } else {
+        if (!approximatelyEqual(position, Move.getLimit(true), 1)) {
+          return getEnd();
+        }
+      }
+    }
     return destination ? dest : loop(dest);
   }
   function computeDestIndex(dest, from, incremental) {
@@ -1512,12 +1503,12 @@ function Arrows(Splide2, Components2, options) {
   }
   function listen() {
     const { go } = Controller;
-    on([EVENT_MOUNTED, EVENT_MOVE, EVENT_UPDATED, EVENT_REFRESH, EVENT_SCROLLED], update);
+    on([EVENT_MOUNTED, EVENT_MOVE, EVENT_MOVED, EVENT_UPDATED, EVENT_REFRESH, EVENT_SCROLLED], update);
     bind(next, "click", () => {
-      go(">");
+      go(">", true);
     });
     bind(prev, "click", () => {
-      go("<");
+      go("<", true);
     });
   }
   function createArrows() {
@@ -1672,7 +1663,7 @@ function Cover(Splide2, Components2, options) {
 const BOUNCE_DIFF_THRESHOLD = 10;
 const BOUNCE_DURATION = 600;
 const FRICTION_FACTOR = 0.6;
-const BASE_VELOCITY = 1.2;
+const BASE_VELOCITY = 1.5;
 const MIN_DURATION = 800;
 
 function Scroll(Splide2, Components2, options) {
@@ -1774,16 +1765,20 @@ function Drag(Splide2, Components2, options) {
   function onPointerDown(e) {
     if (!disabled) {
       isMouse = e.type === "mousedown";
-      if (!Move.isBusy() && (!isMouse || !e.button)) {
-        target = isMouse ? window : track;
-        prevBaseEvent = null;
-        lastEvent = null;
-        clickPrevented = false;
-        bind(target, POINTER_MOVE_EVENTS, onPointerMove);
-        bind(target, POINTER_UP_EVENTS, onPointerUp);
-        Move.cancel();
-        Scroll.cancel();
-        save(e);
+      if (!isMouse || !e.button) {
+        if (!Move.isBusy()) {
+          target = isMouse ? window : track;
+          prevBaseEvent = null;
+          lastEvent = null;
+          clickPrevented = false;
+          bind(target, POINTER_MOVE_EVENTS, onPointerMove);
+          bind(target, POINTER_UP_EVENTS, onPointerUp);
+          Move.cancel();
+          Scroll.cancel();
+          save(e);
+        } else {
+          prevent(e, true);
+        }
       }
     }
   }
@@ -2067,7 +2062,7 @@ function Pagination(Splide2, Components2, options) {
       const controls = Slides.getIn(i).map((Slide) => Slide.slide.id);
       const text = !hasFocus() && perPage > 1 ? i18n.pageX : i18n.slideX;
       bind(button, "click", () => {
-        go(`>${i}`);
+        go(`>${i}`, true);
       });
       setAttribute(button, ARIA_CONTROLS, controls.join(" "));
       setAttribute(button, ARIA_LABEL, format(text, i + 1));

+ 67 - 72
dist/js/splide.esm.js

@@ -272,6 +272,10 @@ function raf(func) {
   return requestAnimationFrame(func);
 }
 
+function approximatelyEqual(x, y, epsilon) {
+  return Math.abs(x - y) < epsilon;
+}
+
 function between(number, minOrMax, maxOrMin, exclusive) {
   const min = Math.min(minOrMax, maxOrMin);
   const max = Math.max(minOrMax, maxOrMin);
@@ -1149,12 +1153,7 @@ function Layout(Splide2, Components2, options) {
     return 0;
   }
   function sliderSize() {
-    const firstSlide = getAt(0);
-    const lastSlide = getAt(Slides.getLength(true) - 1);
-    if (firstSlide && lastSlide) {
-      return rect(lastSlide.slide)[resolve("right")] - rect(firstSlide.slide)[resolve("left")];
-    }
-    return 0;
+    return totalSize(Splide2.length - 1, true) - totalSize(-1, true);
   }
   function getGap() {
     const Slide = getAt(0);
@@ -1180,71 +1179,50 @@ function Move(Splide2, Components2, options) {
   const { slideSize, getPadding, totalSize, listSize, sliderSize } = Components2.Layout;
   const { resolve, orient } = Components2.Direction;
   const { list, track } = Components2.Elements;
-  let looping;
   let waiting;
-  let currPosition = 0;
-  let positionRate = 0;
+  let shouldSnap = true;
   function mount() {
-    on([EVENT_RESIZE, EVENT_RESIZED, EVENT_UPDATED, EVENT_REFRESH], reposition, DEFAULT_EVENT_PRIORITY - 1);
+    on([EVENT_RESIZED, EVENT_UPDATED, EVENT_REFRESH], reposition, DEFAULT_EVENT_PRIORITY - 1);
   }
   function reposition() {
-    if (options.drag !== "free") {
+    if (exceededLimit(true)) {
+      translate(getLimit(true));
+    } else if (shouldSnap || (shouldSnap = canSnap())) {
       jump(Splide2.index);
-    } else {
-      if (!options[resolve("fixedWidth")] && !options[resolve("autoWidth")]) {
-        translate(listSize() * positionRate);
-      }
-      if (exceededLimit(true)) {
-        translate(getLimit(true));
-      } else {
-        snap(SNAP_THRESHOLD);
-      }
-    }
-  }
-  function snap(threshold) {
-    const position = getPosition();
-    const index = toIndex(position);
-    if (abs(position - toPosition(index)) < threshold) {
-      jump(index);
     }
   }
   function move(dest, index, prev) {
     if (!isBusy()) {
+      const { set } = Splide2.state;
       const position = getPosition();
-      looping = dest !== index;
-      waiting = options.waitForTransition;
-      Splide2.state.set(MOVING);
+      const looping = dest !== index;
+      waiting = looping || options.waitForTransition;
+      set(MOVING);
       emit(EVENT_MOVE, index, prev, dest);
       Components2.Transition.start(dest, () => {
-        onMoved(dest, index, prev, position);
+        looping && jump(index);
+        waiting = false;
+        set(IDLE);
+        emit(EVENT_MOVED, index, prev, dest);
+        if (options.trimSpace === "move" && dest !== prev && position === getPosition()) {
+          Components2.Controller.go(dest > prev ? ">" : "<");
+        }
       });
     }
   }
-  function onMoved(dest, index, prev, oldPosition) {
-    if (looping) {
-      jump(index);
-    }
-    waiting = false;
-    Splide2.state.set(IDLE);
-    emit(EVENT_MOVED, index, prev, dest);
-    if (options.trimSpace === "move" && dest !== prev && oldPosition === getPosition()) {
-      Components2.Controller.go(dest > prev ? ">" : "<");
-    }
-  }
   function jump(index) {
     waiting = false;
-    looping = false;
     Components2.Transition.cancel();
     translate(toPosition(index, true));
   }
   function translate(position) {
-    currPosition = loop(position);
-    positionRate = currPosition / listSize();
-    Components2.Style.ruleBy(list, "transform", `translate${resolve("X")}(${currPosition}px)`);
+    position = loop(position);
+    shouldSnap = canSnap(position);
+    Components2.Style.ruleBy(list, "transform", `translate${resolve("X")}(${100 * position / listSize()}%)`);
   }
   function loop(position) {
-    if (!looping && Splide2.is(LOOP)) {
-      const diff = position - currPosition;
+    if (!waiting && Splide2.is(LOOP)) {
+      const diff = position - getPosition();
       const exceededMin = exceededLimit(false, position);
       const exceededMax = exceededLimit(true, position);
       if (exceededMin && diff > 0 || exceededMax && diff < 0) {
@@ -1263,7 +1241,7 @@ function Move(Splide2, Components2, options) {
     let minDistance = Infinity;
     for (let i = 0; i < Slides.length; i++) {
       const slideIndex = Slides[i].index;
-      const distance = abs(toPosition(slideIndex) - position);
+      const distance = abs(toPosition(slideIndex, true) - position);
       if (distance < minDistance) {
         minDistance = distance;
         index = slideIndex;
@@ -1289,19 +1267,20 @@ function Move(Splide2, Components2, options) {
   }
   function offset(index) {
     const { focus } = options;
-    if (focus === "center") {
-      return (listSize() - slideSize(index, true)) / 2;
-    }
-    return (+focus || 0) * slideSize(index);
+    return focus === "center" ? (listSize() - slideSize(index, true)) / 2 : +focus * slideSize(index) || 0;
   }
   function getLimit(max) {
-    const trimming = !!options.trimSpace;
-    return max ? toPosition(Components2.Controller.getEnd(), trimming) : toPosition(0, trimming);
+    return toPosition(max ? Components2.Controller.getEnd() : 0, !!options.trimSpace);
+  }
+  function canSnap(position) {
+    position = isUndefined(position) ? getPosition() : position;
+    return abs(position - toPosition(toIndex(position), true)) < SNAP_THRESHOLD;
   }
   function isBusy() {
-    return !!(looping || waiting);
+    return waiting;
   }
-  function exceededLimit(max, position = currPosition) {
+  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;
@@ -1385,6 +1364,18 @@ function Controller(Splide2, Components2, options) {
   function getAdjacent(prev, destination) {
     const number = perMove || hasFocus() ? 1 : perPage;
     const dest = computeDestIndex(currIndex + number * (prev ? -1 : 1), currIndex);
+    if (dest === -1 && Splide2.is(SLIDE)) {
+      const position = Move.getPosition();
+      if (prev) {
+        if (!approximatelyEqual(position, 0, 1)) {
+          return 0;
+        }
+      } else {
+        if (!approximatelyEqual(position, Move.getLimit(true), 1)) {
+          return getEnd();
+        }
+      }
+    }
     return destination ? dest : loop(dest);
   }
   function computeDestIndex(dest, from, incremental) {
@@ -1508,12 +1499,12 @@ function Arrows(Splide2, Components2, options) {
   }
   function listen() {
     const { go } = Controller;
-    on([EVENT_MOUNTED, EVENT_MOVE, EVENT_UPDATED, EVENT_REFRESH, EVENT_SCROLLED], update);
+    on([EVENT_MOUNTED, EVENT_MOVE, EVENT_MOVED, EVENT_UPDATED, EVENT_REFRESH, EVENT_SCROLLED], update);
     bind(next, "click", () => {
-      go(">");
+      go(">", true);
     });
     bind(prev, "click", () => {
-      go("<");
+      go("<", true);
     });
   }
   function createArrows() {
@@ -1668,7 +1659,7 @@ function Cover(Splide2, Components2, options) {
 const BOUNCE_DIFF_THRESHOLD = 10;
 const BOUNCE_DURATION = 600;
 const FRICTION_FACTOR = 0.6;
-const BASE_VELOCITY = 1.2;
+const BASE_VELOCITY = 1.5;
 const MIN_DURATION = 800;
 
 function Scroll(Splide2, Components2, options) {
@@ -1770,16 +1761,20 @@ function Drag(Splide2, Components2, options) {
   function onPointerDown(e) {
     if (!disabled) {
       isMouse = e.type === "mousedown";
-      if (!Move.isBusy() && (!isMouse || !e.button)) {
-        target = isMouse ? window : track;
-        prevBaseEvent = null;
-        lastEvent = null;
-        clickPrevented = false;
-        bind(target, POINTER_MOVE_EVENTS, onPointerMove);
-        bind(target, POINTER_UP_EVENTS, onPointerUp);
-        Move.cancel();
-        Scroll.cancel();
-        save(e);
+      if (!isMouse || !e.button) {
+        if (!Move.isBusy()) {
+          target = isMouse ? window : track;
+          prevBaseEvent = null;
+          lastEvent = null;
+          clickPrevented = false;
+          bind(target, POINTER_MOVE_EVENTS, onPointerMove);
+          bind(target, POINTER_UP_EVENTS, onPointerUp);
+          Move.cancel();
+          Scroll.cancel();
+          save(e);
+        } else {
+          prevent(e, true);
+        }
       }
     }
   }
@@ -2063,7 +2058,7 @@ function Pagination(Splide2, Components2, options) {
       const controls = Slides.getIn(i).map((Slide) => Slide.slide.id);
       const text = !hasFocus() && perPage > 1 ? i18n.pageX : i18n.slideX;
       bind(button, "click", () => {
-        go(`>${i}`);
+        go(`>${i}`, true);
       });
       setAttribute(button, ARIA_CONTROLS, controls.join(" "));
       setAttribute(button, ARIA_LABEL, format(text, i + 1));

+ 2 - 8
dist/js/splide.js

@@ -1524,17 +1524,11 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
 
     function offset(index) {
       var focus = options.focus;
-
-      if (focus === "center") {
-        return (listSize() - slideSize(index, true)) / 2;
-      }
-
-      return +focus * slideSize(index) || 0;
+      return focus === "center" ? (listSize() - slideSize(index, true)) / 2 : +focus * slideSize(index) || 0;
     }
 
     function getLimit(max) {
-      var trimming = !!options.trimSpace;
-      return max ? toPosition(Components2.Controller.getEnd(), trimming) : toPosition(0, trimming);
+      return toPosition(max ? Components2.Controller.getEnd() : 0, !!options.trimSpace);
     }
 
     function canSnap(position) {

文件差异内容过多而无法显示
+ 0 - 0
dist/js/splide.js.map


文件差异内容过多而无法显示
+ 0 - 0
dist/js/splide.min.js


二进制
dist/js/splide.min.js.gz


+ 1 - 1
dist/types/components/Controller/Controller.d.ts.map

@@ -1 +1 @@
-{"version":3,"file":"Controller.d.ts","sourceRoot":"","sources":["Controller.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAIjE;;;;GAIG;AACH,MAAM,WAAW,mBAAoB,SAAQ,aAAa;IACxD,EAAE,CAAE,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,cAAc,CAAC,EAAE,OAAO,GAAI,IAAI,CAAC;IAC/D,OAAO,CAAE,WAAW,CAAC,EAAE,OAAO,GAAI,MAAM,CAAC;IACzC,OAAO,CAAE,WAAW,CAAC,EAAE,OAAO,GAAI,MAAM,CAAC;IACzC,MAAM,IAAI,MAAM,CAAC;IACjB,QAAQ,CAAE,KAAK,EAAE,MAAM,GAAI,IAAI,CAAC;IAChC,QAAQ,CAAE,IAAI,CAAC,EAAE,OAAO,GAAI,MAAM,CAAC;IACnC,OAAO,CAAE,IAAI,EAAE,MAAM,GAAI,MAAM,CAAC;IAChC,MAAM,CAAE,KAAK,EAAE,MAAM,GAAI,MAAM,CAAC;IAChC,QAAQ,IAAI,OAAO,CAAC;CACrB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,UAAU,CAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,GAAI,mBAAmB,CA+R1G"}
+{"version":3,"file":"Controller.d.ts","sourceRoot":"","sources":["Controller.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAIjE;;;;GAIG;AACH,MAAM,WAAW,mBAAoB,SAAQ,aAAa;IACxD,EAAE,CAAE,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,cAAc,CAAC,EAAE,OAAO,GAAI,IAAI,CAAC;IAC/D,OAAO,CAAE,WAAW,CAAC,EAAE,OAAO,GAAI,MAAM,CAAC;IACzC,OAAO,CAAE,WAAW,CAAC,EAAE,OAAO,GAAI,MAAM,CAAC;IACzC,MAAM,IAAI,MAAM,CAAC;IACjB,QAAQ,CAAE,KAAK,EAAE,MAAM,GAAI,IAAI,CAAC;IAChC,QAAQ,CAAE,IAAI,CAAC,EAAE,OAAO,GAAI,MAAM,CAAC;IACnC,OAAO,CAAE,IAAI,EAAE,MAAM,GAAI,MAAM,CAAC;IAChC,MAAM,CAAE,KAAK,EAAE,MAAM,GAAI,MAAM,CAAC;IAChC,QAAQ,IAAI,OAAO,CAAC;CACrB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,UAAU,CAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,GAAI,mBAAmB,CA8S1G"}

+ 1 - 1
dist/types/components/Drag/Drag.d.ts.map

@@ -1 +1 @@
-{"version":3,"file":"Drag.d.ts","sourceRoot":"","sources":["Drag.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAKjE;;;;GAIG;AACH,MAAM,WAAW,aAAc,SAAQ,aAAa;IAClD,OAAO,CAAE,QAAQ,EAAE,OAAO,GAAI,IAAI,CAAA;CACnC;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,IAAI,CAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,GAAI,aAAa,CAyT9F"}
+{"version":3,"file":"Drag.d.ts","sourceRoot":"","sources":["Drag.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAKjE;;;;GAIG;AACH,MAAM,WAAW,aAAc,SAAQ,aAAa;IAClD,OAAO,CAAE,QAAQ,EAAE,OAAO,GAAI,IAAI,CAAA;CACnC;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,IAAI,CAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,GAAI,aAAa,CA8T9F"}

+ 1 - 1
dist/types/components/Layout/Layout.d.ts.map

@@ -1 +1 @@
-{"version":3,"file":"Layout.d.ts","sourceRoot":"","sources":["Layout.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAIjE;;;;GAIG;AACH,MAAM,WAAW,eAAgB,SAAQ,aAAa;IACpD,QAAQ,IAAI,MAAM,CAAC;IACnB,SAAS,CAAE,KAAK,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,OAAO,GAAI,MAAM,CAAC;IACzD,UAAU,IAAI,MAAM,CAAC;IACrB,SAAS,CAAE,KAAK,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,OAAO,GAAI,MAAM,CAAC;IAC1D,UAAU,CAAE,KAAK,EAAE,OAAO,GAAI,MAAM,CAAC;CACtC;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,MAAM,CAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,GAAI,eAAe,CA0NlG"}
+{"version":3,"file":"Layout.d.ts","sourceRoot":"","sources":["Layout.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAIjE;;;;GAIG;AACH,MAAM,WAAW,eAAgB,SAAQ,aAAa;IACpD,QAAQ,IAAI,MAAM,CAAC;IACnB,SAAS,CAAE,KAAK,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,OAAO,GAAI,MAAM,CAAC;IACzD,UAAU,IAAI,MAAM,CAAC;IACrB,SAAS,CAAE,KAAK,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,OAAO,GAAI,MAAM,CAAC;IAC1D,UAAU,CAAE,KAAK,EAAE,OAAO,GAAI,MAAM,CAAC;CACtC;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,MAAM,CAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,GAAI,eAAe,CAoNlG"}

+ 1 - 1
dist/types/components/Move/Move.d.ts.map

@@ -1 +1 @@
-{"version":3,"file":"Move.d.ts","sourceRoot":"","sources":["Move.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAKjE;;;;GAIG;AACH,MAAM,WAAW,aAAc,SAAQ,aAAa;IAClD,IAAI,CAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAI,IAAI,CAAC;IACxD,IAAI,CAAE,KAAK,EAAE,MAAM,GAAI,IAAI,CAAC;IAC5B,SAAS,CAAE,QAAQ,EAAE,MAAM,GAAI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AI,MAAM,CAAC;IACjC,MAAM,IAAI,OAAO,CAAC;IAClB,aAAa,CAAE,GAAG,CAAC,EAAE,OAAO,GAAG,SAAS,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAI,OAAO,CAAC;CACxE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,IAAI,CAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,GAAI,aAAa,CA+P9F"}

+ 1 - 1
dist/types/components/Scroll/constants.d.ts

@@ -21,7 +21,7 @@ export declare const FRICTION_FACTOR = 0.6;
  *
  * @since 3.0.0
  */
-export declare const BASE_VELOCITY = 1.2;
+export declare const BASE_VELOCITY = 1.5;
 /**
  * The minimum duration of scroll.
  *

+ 4 - 2
dist/types/test/utils/utils.d.ts

@@ -18,11 +18,13 @@ export declare function init(options?: Options, args?: InitArgs): Splide;
 /**
  * Converts translate values to positions.
  *
- * @param elm - An element to parse.
+ * @param elm        - An element to parse.
+ * @param baseWidth  - The width of the element.
+ * @param baseHeight - The height of the element.
  *
  * @return An object with left and top offsets.
  */
-export declare function parseTransform(elm: HTMLElement): {
+export declare function parseTransform(elm: HTMLElement, baseWidth: number, baseHeight: number): {
     left: number;
     top: number;
 };

+ 1 - 1
dist/types/test/utils/utils.d.ts.map

@@ -1 +1 @@
-{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAEtC,OAAO,EAAa,aAAa,EAAE,MAAM,aAAa,CAAC;AAIvD,UAAU,QAAS,SAAQ,aAAa;IACtC,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED;;;;;;;GAOG;AACH,wBAAgB,IAAI,CAAE,OAAO,GAAE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GAQG;AACH,wBAAgB,cAAc,CAC5B,GAAG,EAAE,WAAW,EAChB,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,GACjB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAmB/B;AAED;;;;;;;;;GASG;AACH,wBAAgB,IAAI,CAClB,MAAM,EAAE,MAAM,GAAG,QAAQ,GAAG,OAAO,EACnC,IAAI,EAAE,MAAM,EACZ,IAAI,GAAE,GAAQ,EACd,aAAa,GAAE,SAAc,GAC5B,KAAK,CAUP;AAED;;;;;GAKG;AACH,wBAAgB,OAAO,CAAE,GAAG,EAAE,MAAM,EAAE,MAAM,GAAE,MAAM,GAAG,OAAgB,GAAI,IAAI,CAE9E;AAED;;;;;;GAMG;AACH,wBAAgB,IAAI,CAAE,QAAQ,EAAE,MAAM,GAAI,OAAO,CAAC,IAAI,CAAC,CAItD;AAED;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAE,QAAQ,EAAE,MAAM,GAAI,YAAY,CAMzD;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAE,MAAM,EAAE,MAAM,GAAG,WAAW,GAAI,YAAY,CAEvE"}

+ 11 - 0
dist/types/utils/math/approximatelyEqual/approximatelyEqual.d.ts

@@ -0,0 +1,11 @@
+/**
+ * Checks if the provided 2 numbers are approximately equal or not.
+ *
+ * @param x       - A number.
+ * @param y       - Another number to compare.
+ * @param epsilon - An accuracy that defines the approximation.
+ *
+ * @return `true` if 2 numbers are considered to be equal, or otherwise `false`.
+ */
+export declare function approximatelyEqual(x: number, y: number, epsilon: number): boolean;
+//# sourceMappingURL=../../../../../src/js/utils/math/approximatelyEqual/approximatelyEqual.d.ts.map

+ 1 - 0
dist/types/utils/math/approximatelyEqual/approximatelyEqual.d.ts.map

@@ -0,0 +1 @@
+{"version":3,"file":"approximatelyEqual.d.ts","sourceRoot":"","sources":["approximatelyEqual.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAI,OAAO,CAEnF"}

+ 1 - 0
dist/types/utils/math/index.d.ts

@@ -1,3 +1,4 @@
+export { approximatelyEqual } from './approximatelyEqual/approximatelyEqual';
 export { between } from './between/between';
 export { clamp } from './clamp/clamp';
 export { sign } from './sign/sign';

+ 1 - 1
dist/types/utils/math/index.d.ts.map

@@ -1 +1 @@
-{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,KAAK,EAAE,MAAQ,eAAe,CAAC;AACxC,OAAO,EAAE,IAAI,EAAE,MAAS,aAAa,CAAC;AAEtC,eAAO,MAAQ,GAAG,mCAAE,GAAG,mCAAE,KAAK,yBAAE,IAAI,yBAAE,GAAG,yBAAE,KAAK,uBAAS,CAAC"}
+{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,yCAAyC,CAAC;AAC7E,OAAO,EAAE,OAAO,EAAE,MAAiB,mBAAmB,CAAC;AACvD,OAAO,EAAE,KAAK,EAAE,MAAmB,eAAe,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,MAAoB,aAAa,CAAC;AAEjD,eAAO,MAAQ,GAAG,mCAAE,GAAG,mCAAE,KAAK,yBAAE,IAAI,yBAAE,GAAG,yBAAE,KAAK,uBAAS,CAAC"}

+ 1 - 1
package.json

@@ -56,7 +56,7 @@
     "develop": "node scripts/develop.js",
     "build:js": "node scripts/build-script.js",
     "build:module": "node scripts/build-module.js",
-    "build:types": "tsc --emitDeclarationOnly",
+    "build:types": "node scripts/clean.js && tsc --emitDeclarationOnly",
     "build:css": "node scripts/build-css.js",
     "build:all": "npm run build:js && npm run build:module && npm run build:css && npm run build:types",
     "check:types": "tsc --noEmit",

+ 8 - 0
scripts/clean.js

@@ -0,0 +1,8 @@
+const fs = require( 'fs' ).promises;
+
+
+async function clean() {
+  await fs.rm( './dist/types', { recursive: true, force: true } );
+}
+
+clean().catch( e => console.error( e ) );

+ 7 - 13
src/js/components/Move/Move.ts

@@ -74,9 +74,9 @@ export function Move( Splide: Splide, Components: Components, options: Options )
   }
 
   /**
-   * Goes to the slide at the specified index with the Transition component.
+   * Moves the slider to the dest index with the Transition component.
    *
-   * @param dest  - A destination index to go to.
+   * @param dest  - A destination index to go to, including clones'.
    * @param index - A slide index.
    * @param prev  - A previous index.
    */
@@ -115,9 +115,9 @@ export function Move( Splide: Splide, Components: Components, options: Options )
   }
 
   /**
-   * Moves the slider to the specified position.
+   * Moves the slider to the provided position.
    *
-   * @param position - The destination.
+   * @param position - The position to move to.
    */
   function translate( position: number ): void {
     position   = loop( position );
@@ -131,7 +131,7 @@ export function Move( Splide: Splide, Components: Components, options: Options )
   }
 
   /**
-   * Loops the provided position if it exceeds limits.
+   * Loops the provided position if it exceeds bounds.
    *
    * @param position - A position to loop.
    */
@@ -230,12 +230,7 @@ export function Move( Splide: Splide, Components: Components, options: Options )
    */
   function offset( index: number ): number {
     const { focus } = options;
-
-    if ( focus === 'center' ) {
-      return ( listSize() - slideSize( index, true ) ) / 2;
-    }
-
-    return +focus * slideSize( index ) || 0;
+    return focus === 'center' ? ( listSize() - slideSize( index, true ) ) / 2 : +focus * slideSize( index ) || 0;
   }
 
   /**
@@ -246,8 +241,7 @@ export function Move( Splide: Splide, Components: Components, options: Options )
    * @return The border number.
    */
   function getLimit( max: boolean ): number {
-    const trimming = !! options.trimSpace;
-    return max ? toPosition( Components.Controller.getEnd(), trimming ) : toPosition( 0, trimming );
+    return toPosition( max ? Components.Controller.getEnd() : 0, !! options.trimSpace );
   }
 
   /**

+ 0 - 2
src/js/test/php/examples/autoWidth.php

@@ -26,8 +26,6 @@ $settings = get_settings();
 
       splide01.mount();
 
-      return;
-
       var splide02 = new Splide( '#splide02', {
         // width     : 1000,
         autoWidth : true,

部分文件因为文件数量过多而无法显示