Forráskód Böngészése

Restores `speed` to the initial value after drag since it's not "non-essential" motion.

NaotoshiFujita 3 éve
szülő
commit
9de478b2ef

A különbségek nem kerülnek megjelenítésre, a fájl túl nagy
+ 0 - 0
dist/js/splide-renderer.min.js


+ 13 - 3
dist/js/splide.js

@@ -1634,11 +1634,11 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
     function computeDestIndex(dest, from, snapPage) {
       if (isEnough()) {
         var end = getEnd();
-        var movable = computeMovableDestIndex(dest);
+        var index = computeMovableDestIndex(dest);
 
-        if (movable !== dest) {
+        if (index !== dest) {
           from = dest;
-          dest = movable;
+          dest = index;
           snapPage = false;
         }
 
@@ -2215,8 +2215,13 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
       var velocity = computeVelocity(e);
       var destination = computeDestination(velocity);
       var rewind = options.rewind && options.rewindByDrag;
+      var reduced = Components2.Media.matches("motion");
       var go = Controller.go;
 
+      if (reduced) {
+        options.speed = Splide2._io.speed;
+      }
+
       if (isFree) {
         Controller.scroll(destination, 0, options.snap);
       } else if (Splide2.is(FADE)) {
@@ -2226,6 +2231,10 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
       } else {
         go(Controller.toDest(destination), true);
       }
+
+      if (reduced) {
+        options.speed = 0;
+      }
     }
 
     function shouldStart(e) {
@@ -2848,6 +2857,7 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
     i18n: I18N,
     reducedMotion: {
       speed: 0,
+      rewindSpeed: 0,
       autoplay: "pause"
     }
   };

A különbségek nem kerülnek megjelenítésre, a fájl túl nagy
+ 0 - 0
dist/js/splide.min.js


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


A különbségek nem kerülnek megjelenítésre, a fájl túl nagy
+ 0 - 0
dist/js/splide.min.js.map


+ 4 - 17
src/js/components/Controller/Controller.ts

@@ -14,7 +14,6 @@ import { apply, approximatelyEqual, between, clamp, floor, isString, isUndefined
  */
 export interface ControllerComponent extends BaseComponent {
   go( control: number | string, allowSameIndex?: boolean, callback?: AnyFunction ): void;
-  // scrollTo( index: number, duration?: number, callback?: AnyFunction ): void;
   scroll( destination: number, duration?: number, snap?: boolean, callback?: AnyFunction ): void;
   getNext( destination?: boolean ): number;
   getPrev( destination?: boolean ): number;
@@ -137,17 +136,6 @@ export function Controller( Splide: Splide, Components: Components, options: Opt
     } );
   }
 
-  // /**
-  //  * Scrolls the slider to the specified index with updating indices.
-  //  *
-  //  * @param index    - An index to scroll the slider to.
-  //  * @param duration - Optional. Specifies the scroll duration.
-  //  * @param callback - Optional. A callback function invoked after scroll ends.
-  //  */
-  // function scrollTo( index: number, duration?: number, callback?: AnyFunction ): void {
-  //   scroll( toPosition( index, true ), duration, false, callback );
-  // }
-
   /**
    * Parses the control and returns a slide index.
    *
@@ -213,12 +201,12 @@ export function Controller( Splide: Splide, Components: Components, options: Opt
    */
   function computeDestIndex( dest: number, from: number, snapPage?: boolean ): number {
     if ( isEnough() ) {
-      const end         = getEnd();
-      const movable     = computeMovableDestIndex( dest );
+      const end   = getEnd();
+      const index = computeMovableDestIndex( dest );
 
-      if ( movable !== dest ) {
+      if ( index !== dest ) {
         from     = dest;
-        dest     = movable;
+        dest     = index;
         snapPage = false;
       }
 
@@ -369,7 +357,6 @@ export function Controller( Splide: Splide, Components: Components, options: Opt
     mount,
     go,
     scroll,
-    // scrollTo,
     getNext,
     getPrev,
     getAdjacent,

+ 13 - 1
src/js/components/Drag/Drag.ts

@@ -1,4 +1,5 @@
 import { CLASS_ARROW, CLASS_PAGINATION_PAGE } from '../../constants/classes';
+import { DEFAULTS } from '../../constants/defaults';
 import { EVENT_DRAG, EVENT_DRAGGED, EVENT_DRAGGING, EVENT_MOUNTED, EVENT_UPDATED } from '../../constants/events';
 import { SCROLL_LISTENER_OPTIONS } from '../../constants/listener-options';
 import { DRAGGING, IDLE, MOVING, SCROLLING } from '../../constants/states';
@@ -218,7 +219,9 @@ export function Drag( Splide: Splide, Components: Components, options: Options )
   }
 
   /**
-   * Moves the slider according to the drag result.
+   * Calculates the destination by the drag velocity and moves the carousel.
+   * If motion is reduced, restores transition speed to the initial value
+   * because it's "essential" motion for the user to recognize what happens on the carousel.
    *
    * @param e - A TouchEvent or MouseEvent object.
    */
@@ -226,8 +229,13 @@ export function Drag( Splide: Splide, Components: Components, options: Options )
     const velocity    = computeVelocity( e );
     const destination = computeDestination( velocity );
     const rewind      = options.rewind && options.rewindByDrag;
+    const reduced     = Components.Media.matches( 'motion' );
     const { go } = Controller;
 
+    if ( reduced ) {
+      options.speed = Splide._io.speed;
+    }
+
     if ( isFree ) {
       Controller.scroll( destination, 0, options.snap );
     } else if ( Splide.is( FADE ) ) {
@@ -237,6 +245,10 @@ export function Drag( Splide: Splide, Components: Components, options: Options )
     } else {
       go( Controller.toDest( destination ), true );
     }
+
+    if ( reduced ) {
+      options.speed = 0;
+    }
   }
 
   /**

+ 3 - 2
src/js/constants/defaults.ts

@@ -31,7 +31,8 @@ export const DEFAULTS: Options = {
   classes           : CLASSES,
   i18n              : I18N,
   reducedMotion: {
-    speed   : 0,
-    autoplay: 'pause',
+    speed      : 0,
+    rewindSpeed: 0,
+    autoplay   : 'pause',
   },
 };

Nem az összes módosított fájl került megjelenítésre, mert túl sok fájl változott