Naotoshi Fujita преди 2 години
родител
ревизия
e113156c12
променени са 7 файла, в които са добавени 150 реда и са изтрити 146 реда
  1. 40 39
      dist/js/splide.cjs.js
  2. 40 39
      dist/js/splide.esm.js
  3. 0 0
      dist/js/splide.min.js
  4. BIN
      dist/js/splide.min.js.gz
  5. 0 0
      dist/js/splide.min.js.map
  6. 69 67
      dist/types/index.d.ts
  7. 1 1
      src/js/test/php/examples/default.php

+ 40 - 39
dist/js/splide.cjs.js

@@ -1170,13 +1170,14 @@ const Clones = (Splide, Components, options, event) => {
 
 const Move = (Splide, Components, options, event) => {
   const { on, emit } = event;
-  const { set } = Splide.state;
+  const { set, is } = Splide.state;
   const { Slides } = Components;
   const { slideSize, getPadding, listSize, sliderSize, totalSize, trackSize } = Components.Layout;
   const { resolve, orient } = Components.Direction;
   const { list, track } = Components.Elements;
   let Transition;
   let indices;
+  let callback;
   function mount() {
     Transition = Components.Transition;
     on([EVENT_MOUNTED, EVENT_RESIZED, EVENT_UPDATED, EVENT_REFRESH], reposition);
@@ -1188,29 +1189,27 @@ const Move = (Splide, Components, options, event) => {
       Slides.update();
     }
   }
-  function move(dest, index, prev, callback) {
-    const forwards = dest > prev;
-    const closest = toIndex(getPosition());
-    const detouring = exceededLimit(forwards) && abs(dest - closest) > abs(dest - prev);
+  function move(dest, index, prev, forwards, onMoved) {
     cancel();
-    if ((dest !== index || detouring) && canShift(forwards)) {
-      translate(shift(getPosition(), forwards), true);
-    }
+    const shiftBackwards = dest !== index ? dest > index : forwards;
+    const shouldShift = (dest !== index || exceededLimit(forwards)) && canShift(shiftBackwards);
+    shouldShift && translate(shift(getPosition(), shiftBackwards), true);
     indices = [index, prev, dest];
+    callback = onMoved;
     set(MOVING);
     emit(EVENT_MOVE, index, prev, dest);
-    Transition.start(index, () => {
-      set(IDLE);
-      emit(EVENT_MOVED, index, prev, dest);
-      callback && callback();
-    });
+    Transition.start(index, onTransitionEnd);
+  }
+  function onTransitionEnd() {
+    set(IDLE);
+    emit(EVENT_MOVED, ...indices);
+    callback && callback();
   }
   function cancel() {
-    if (Splide.state.is(MOVING) && indices) {
+    if (is(MOVING) && indices) {
       translate(getPosition(), true);
       Transition.cancel();
-      set(IDLE);
-      emit(EVENT_MOVED, ...indices);
+      onTransitionEnd();
     }
   }
   function jump(index) {
@@ -1361,19 +1360,16 @@ const Controller = (Splide, Components, options, event) => {
   }
   function go(control, callback) {
     if (!isBusy()) {
-      const dest = parse(control);
+      const [dest, forwards] = parse(control);
       const index = loop(dest);
-      if (canGo(dest, index)) {
+      const canGo = dest === index || Move.exceededLimit(!forwards) || Move.canShift(forwards);
+      if (index > -1 && canGo) {
         Scroll.cancel();
         setIndex(index);
-        Move.move(dest, index, prevIndex, callback);
+        Move.move(dest, index, prevIndex, forwards, callback);
       }
     }
   }
-  function canGo(dest, index) {
-    const forward = dest > prevIndex;
-    return index > -1 && (index !== currIndex || !isMoving()) && (dest === index || Move.exceededLimit(!forward) || Move.canShift(forward));
-  }
   function jump(control) {
     const { set } = Components.Breakpoints;
     const { speed } = options;
@@ -1389,22 +1385,23 @@ const Controller = (Splide, Components, options, event) => {
     });
   }
   function parse(control) {
-    let index = currIndex;
+    let dest = currIndex;
+    let forwards = true;
     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 if (indicator === ">|") {
-        index = endIndex;
+      const [, indicator, number] = control.match(/([+-]|>>?|<<?)(-?\d+)?/) || [];
+      const oneOf = (...indicators) => includes(indicators, indicator);
+      forwards = oneOf("+", ">", ">>");
+      if (oneOf("+", "-")) {
+        dest = computeDestIndex(currIndex + +`${indicator}${+number || 1}`, currIndex);
+      } else if (oneOf(">", "<")) {
+        dest = number ? toIndex(+number) : getAdjacent(!forwards, true);
+      } else if (oneOf(">>", "<<")) {
+        dest = number ? +number || 0 : forwards ? endIndex : 0;
       }
     } else {
-      index = isLoop ? control : clamp(control, 0, endIndex);
+      dest = isLoop ? control : clamp(control, 0, endIndex);
     }
-    return index;
+    return [dest, forwards];
   }
   function getAdjacent(prev, destination) {
     const number = perMove || (hasFocus() ? 1 : perPage);
@@ -1782,6 +1779,7 @@ const Drag = (Splide, Components, options, event) => {
   const { Move, Scroll, Controller, Elements: { track }, Breakpoints: { reduce } } = Components;
   const { resolve, orient } = Components.Direction;
   const { getPosition, exceededLimit } = Move;
+  let startCoord;
   let basePosition;
   let baseEvent;
   let prevBaseEvent;
@@ -1813,6 +1811,7 @@ const Drag = (Splide, Components, options, event) => {
           target = isTouch ? track : window;
           dragging = state.is([MOVING, SCROLLING]);
           prevBaseEvent = null;
+          startCoord = coordOf(e);
           binder.bind(target, POINTER_MOVE_EVENTS, onPointerMove, SCROLL_LISTENER_OPTIONS);
           binder.bind(target, POINTER_UP_EVENTS, onPointerUp, SCROLL_LISTENER_OPTIONS);
           Move.cancel();
@@ -1873,20 +1872,22 @@ const Drag = (Splide, Components, options, event) => {
     basePosition = getPosition();
   }
   function move(e) {
+    const { go } = Controller;
     const { updateOnDragged = true } = options;
     const velocity = computeVelocity(e);
     const destination = computeDestination(velocity);
+    const forwards = orient(coordOf(e) - startCoord) > 0;
     const rewind = options.rewind && options.rewindByDrag;
     const scroll = updateOnDragged ? Controller.scroll : Scroll.scroll;
     reduce(false);
     if (isFree) {
       scroll(destination, void 0, options.snap);
     } else if (Splide.is(FADE)) {
-      Controller.go(orient(sign(velocity)) < 0 ? rewind ? "<" : "-" : rewind ? ">" : "+");
+      go(forwards ? rewind ? ">" : "+" : rewind ? "<" : "-");
     } else if (Splide.is(SLIDE) && exceeded && rewind) {
-      Controller.go(exceededLimit(true) ? ">" : "<");
+      go(exceededLimit(true) ? ">" : "<");
     } else {
-      Controller.go(Controller.toDest(destination));
+      go(`${forwards ? ">>" : "<<"}${Controller.toDest(destination)}`);
     }
     reduce(true);
   }
@@ -2205,7 +2206,7 @@ const Sync = (Splide2, Components, options, event) => {
   function sync(splide, target) {
     const event2 = splide.event.create();
     event2.on(EVENT_MOVE, (index, prev, dest) => {
-      target.go(target.is(LOOP) ? dest : index);
+      target.index !== index && target.go(target.is(LOOP) ? dest : index);
     });
     events.push(event2);
   }

+ 40 - 39
dist/js/splide.esm.js

@@ -1166,13 +1166,14 @@ const Clones = (Splide, Components, options, event) => {
 
 const Move = (Splide, Components, options, event) => {
   const { on, emit } = event;
-  const { set } = Splide.state;
+  const { set, is } = Splide.state;
   const { Slides } = Components;
   const { slideSize, getPadding, listSize, sliderSize, totalSize, trackSize } = Components.Layout;
   const { resolve, orient } = Components.Direction;
   const { list, track } = Components.Elements;
   let Transition;
   let indices;
+  let callback;
   function mount() {
     Transition = Components.Transition;
     on([EVENT_MOUNTED, EVENT_RESIZED, EVENT_UPDATED, EVENT_REFRESH], reposition);
@@ -1184,29 +1185,27 @@ const Move = (Splide, Components, options, event) => {
       Slides.update();
     }
   }
-  function move(dest, index, prev, callback) {
-    const forwards = dest > prev;
-    const closest = toIndex(getPosition());
-    const detouring = exceededLimit(forwards) && abs(dest - closest) > abs(dest - prev);
+  function move(dest, index, prev, forwards, onMoved) {
     cancel();
-    if ((dest !== index || detouring) && canShift(forwards)) {
-      translate(shift(getPosition(), forwards), true);
-    }
+    const shiftBackwards = dest !== index ? dest > index : forwards;
+    const shouldShift = (dest !== index || exceededLimit(forwards)) && canShift(shiftBackwards);
+    shouldShift && translate(shift(getPosition(), shiftBackwards), true);
     indices = [index, prev, dest];
+    callback = onMoved;
     set(MOVING);
     emit(EVENT_MOVE, index, prev, dest);
-    Transition.start(index, () => {
-      set(IDLE);
-      emit(EVENT_MOVED, index, prev, dest);
-      callback && callback();
-    });
+    Transition.start(index, onTransitionEnd);
+  }
+  function onTransitionEnd() {
+    set(IDLE);
+    emit(EVENT_MOVED, ...indices);
+    callback && callback();
   }
   function cancel() {
-    if (Splide.state.is(MOVING) && indices) {
+    if (is(MOVING) && indices) {
       translate(getPosition(), true);
       Transition.cancel();
-      set(IDLE);
-      emit(EVENT_MOVED, ...indices);
+      onTransitionEnd();
     }
   }
   function jump(index) {
@@ -1357,19 +1356,16 @@ const Controller = (Splide, Components, options, event) => {
   }
   function go(control, callback) {
     if (!isBusy()) {
-      const dest = parse(control);
+      const [dest, forwards] = parse(control);
       const index = loop(dest);
-      if (canGo(dest, index)) {
+      const canGo = dest === index || Move.exceededLimit(!forwards) || Move.canShift(forwards);
+      if (index > -1 && canGo) {
         Scroll.cancel();
         setIndex(index);
-        Move.move(dest, index, prevIndex, callback);
+        Move.move(dest, index, prevIndex, forwards, callback);
       }
     }
   }
-  function canGo(dest, index) {
-    const forward = dest > prevIndex;
-    return index > -1 && (index !== currIndex || !isMoving()) && (dest === index || Move.exceededLimit(!forward) || Move.canShift(forward));
-  }
   function jump(control) {
     const { set } = Components.Breakpoints;
     const { speed } = options;
@@ -1385,22 +1381,23 @@ const Controller = (Splide, Components, options, event) => {
     });
   }
   function parse(control) {
-    let index = currIndex;
+    let dest = currIndex;
+    let forwards = true;
     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 if (indicator === ">|") {
-        index = endIndex;
+      const [, indicator, number] = control.match(/([+-]|>>?|<<?)(-?\d+)?/) || [];
+      const oneOf = (...indicators) => includes(indicators, indicator);
+      forwards = oneOf("+", ">", ">>");
+      if (oneOf("+", "-")) {
+        dest = computeDestIndex(currIndex + +`${indicator}${+number || 1}`, currIndex);
+      } else if (oneOf(">", "<")) {
+        dest = number ? toIndex(+number) : getAdjacent(!forwards, true);
+      } else if (oneOf(">>", "<<")) {
+        dest = number ? +number || 0 : forwards ? endIndex : 0;
       }
     } else {
-      index = isLoop ? control : clamp(control, 0, endIndex);
+      dest = isLoop ? control : clamp(control, 0, endIndex);
     }
-    return index;
+    return [dest, forwards];
   }
   function getAdjacent(prev, destination) {
     const number = perMove || (hasFocus() ? 1 : perPage);
@@ -1778,6 +1775,7 @@ const Drag = (Splide, Components, options, event) => {
   const { Move, Scroll, Controller, Elements: { track }, Breakpoints: { reduce } } = Components;
   const { resolve, orient } = Components.Direction;
   const { getPosition, exceededLimit } = Move;
+  let startCoord;
   let basePosition;
   let baseEvent;
   let prevBaseEvent;
@@ -1809,6 +1807,7 @@ const Drag = (Splide, Components, options, event) => {
           target = isTouch ? track : window;
           dragging = state.is([MOVING, SCROLLING]);
           prevBaseEvent = null;
+          startCoord = coordOf(e);
           binder.bind(target, POINTER_MOVE_EVENTS, onPointerMove, SCROLL_LISTENER_OPTIONS);
           binder.bind(target, POINTER_UP_EVENTS, onPointerUp, SCROLL_LISTENER_OPTIONS);
           Move.cancel();
@@ -1869,20 +1868,22 @@ const Drag = (Splide, Components, options, event) => {
     basePosition = getPosition();
   }
   function move(e) {
+    const { go } = Controller;
     const { updateOnDragged = true } = options;
     const velocity = computeVelocity(e);
     const destination = computeDestination(velocity);
+    const forwards = orient(coordOf(e) - startCoord) > 0;
     const rewind = options.rewind && options.rewindByDrag;
     const scroll = updateOnDragged ? Controller.scroll : Scroll.scroll;
     reduce(false);
     if (isFree) {
       scroll(destination, void 0, options.snap);
     } else if (Splide.is(FADE)) {
-      Controller.go(orient(sign(velocity)) < 0 ? rewind ? "<" : "-" : rewind ? ">" : "+");
+      go(forwards ? rewind ? ">" : "+" : rewind ? "<" : "-");
     } else if (Splide.is(SLIDE) && exceeded && rewind) {
-      Controller.go(exceededLimit(true) ? ">" : "<");
+      go(exceededLimit(true) ? ">" : "<");
     } else {
-      Controller.go(Controller.toDest(destination));
+      go(`${forwards ? ">>" : "<<"}${Controller.toDest(destination)}`);
     }
     reduce(true);
   }
@@ -2201,7 +2202,7 @@ const Sync = (Splide2, Components, options, event) => {
   function sync(splide, target) {
     const event2 = splide.event.create();
     event2.on(EVENT_MOVE, (index, prev, dest) => {
-      target.go(target.is(LOOP) ? dest : index);
+      target.index !== index && target.go(target.is(LOOP) ? dest : index);
     });
     events.push(event2);
   }

Файловите разлики са ограничени, защото са твърде много
+ 0 - 0
dist/js/splide.min.js


BIN
dist/js/splide.min.js.gz


Файловите разлики са ограничени, защото са твърде много
+ 0 - 0
dist/js/splide.min.js.map


+ 69 - 67
dist/types/index.d.ts

@@ -1,3 +1,68 @@
+/**
+ * The interface for the Media component.
+ *
+ * @since 4.0.0
+ */
+interface BreakpointsComponent extends BaseComponent {
+    /** @internal */
+    reduce(reduced: boolean): void;
+    set(options: Options, base?: boolean, notify?: boolean): void;
+}
+
+/**
+ * The interface for the Direction component.
+ *
+ * @since 3.0.0
+ */
+interface DirectionComponent extends BaseComponent {
+    resolve<K extends keyof typeof ORIENTATION_MAP>(prop: K, axisOnly?: boolean, direction?: Options['direction']): typeof ORIENTATION_MAP[K][number] | K;
+    resolve<R extends string>(prop: R, axisOnly?: boolean, direction?: Options['direction']): R;
+    orient(value: number): number;
+    left(): string;
+    right(): string;
+    width(): string;
+}
+/**
+ * The translation map for directions.
+ *
+ * @since 3.0.0
+ */
+declare const ORIENTATION_MAP: {
+    readonly width: readonly ["height"];
+    readonly left: readonly ["top", "right"];
+    readonly right: readonly ["bottom", "left"];
+    readonly x: readonly ["y"];
+    readonly X: readonly ["Y"];
+    readonly Y: readonly ["X"];
+    readonly ArrowLeft: readonly [string, string];
+    readonly ArrowRight: readonly [string, string];
+};
+
+/**
+ * The interface for elements which the slider consists of.
+ *
+ * @since 3.0.0
+ */
+interface ElementCollection {
+    root: HTMLElement;
+    track: HTMLElement;
+    list: HTMLElement;
+    slides: HTMLElement[];
+    arrows?: HTMLElement;
+    pagination?: HTMLUListElement;
+    prev?: HTMLButtonElement;
+    next?: HTMLButtonElement;
+    bar?: HTMLElement;
+    toggle?: HTMLElement;
+}
+/**
+ * The interface for the Elements component.
+ *
+ * @since 3.0.0
+ */
+interface ElementsComponent extends BaseComponent, Readonly<ElementCollection> {
+}
+
 /**
  * The type that matches any function.
  */
@@ -115,71 +180,6 @@ interface State {
  */
 declare function State(initialState: number): State;
 
-/**
- * The interface for the Media component.
- *
- * @since 4.0.0
- */
-interface BreakpointsComponent extends BaseComponent {
-    /** @internal */
-    reduce(reduced: boolean): void;
-    set(options: Options, base?: boolean, notify?: boolean): void;
-}
-
-/**
- * The interface for the Direction component.
- *
- * @since 3.0.0
- */
-interface DirectionComponent extends BaseComponent {
-    resolve<K extends keyof typeof ORIENTATION_MAP>(prop: K, axisOnly?: boolean, direction?: Options['direction']): typeof ORIENTATION_MAP[K][number] | K;
-    resolve<R extends string>(prop: R, axisOnly?: boolean, direction?: Options['direction']): R;
-    orient(value: number): number;
-    left(): string;
-    right(): string;
-    width(): string;
-}
-/**
- * The translation map for directions.
- *
- * @since 3.0.0
- */
-declare const ORIENTATION_MAP: {
-    readonly width: readonly ["height"];
-    readonly left: readonly ["top", "right"];
-    readonly right: readonly ["bottom", "left"];
-    readonly x: readonly ["y"];
-    readonly X: readonly ["Y"];
-    readonly Y: readonly ["X"];
-    readonly ArrowLeft: readonly [string, string];
-    readonly ArrowRight: readonly [string, string];
-};
-
-/**
- * The interface for elements which the slider consists of.
- *
- * @since 3.0.0
- */
-interface ElementCollection {
-    root: HTMLElement;
-    track: HTMLElement;
-    list: HTMLElement;
-    slides: HTMLElement[];
-    arrows?: HTMLElement;
-    pagination?: HTMLUListElement;
-    prev?: HTMLButtonElement;
-    next?: HTMLButtonElement;
-    bar?: HTMLElement;
-    toggle?: HTMLElement;
-}
-/**
- * The interface for the Elements component.
- *
- * @since 3.0.0
- */
-interface ElementsComponent extends BaseComponent, Readonly<ElementCollection> {
-}
-
 /**
  * The interface for the Slide sub component.
  *
@@ -228,7 +228,7 @@ interface ClonesComponent extends BaseComponent {
  * @since 3.0.0
  */
 interface MoveComponent extends BaseComponent {
-    move(dest: number, index: number, prev: number, callback?: AnyFunction): void;
+    move(dest: number, index: number, prev: number, forwards: boolean, callback?: AnyFunction): void;
     jump(index: number): void;
     translate(position: number, preventLoop?: boolean): void;
     shift(position: number, backwards: boolean): number;
@@ -1043,7 +1043,7 @@ declare class Splide {
     /**
      * The EventBusObject object.
      */
-    readonly event: EventInterface$1<Record<string, AnyFunction$1>>;
+    readonly event: EventInterface$1<EventMap & Record<string, AnyFunction>>;
     /**
      * The collection of all component objects.
      */
@@ -1118,6 +1118,8 @@ declare class Splide {
      * | `'>'` | Goes to the next page |
      * | `'<'` | Goes to the previous page |
      * | `>${i}` | Goes to the page `i` |
+     * | `>>` | Goes to the first page |
+     * | `<<` | Goes to the last page |
      *
      * In most cases, `'>'` and `'<'` notations are enough to control the slider
      * because they respect `perPage` and `perMove` options.

+ 1 - 1
src/js/test/php/examples/default.php

@@ -100,7 +100,7 @@ $settings = get_settings();
 
 
       document.querySelector( '#jump' ).addEventListener( 'click', () => {
-        splide.Components.Controller.go( 160 );
+        splide.Components.Controller.go( '<<' );
       } );
 
 	    // Array.from( document.getElementsByTagName( 'button' ) ).forEach( button => {

Някои файлове не бяха показани, защото твърде много файлове са промени