Kaynağa Gözat

Make `getRate()` accept an index.

Naotoshi Fujita 2 yıl önce
ebeveyn
işleme
550a4db3e6

Dosya farkı çok büyük olduğundan ihmal edildi
+ 0 - 0
dist/js/splide-renderer.min.js


Dosya farkı çok büyük olduğundan ihmal edildi
+ 0 - 0
dist/js/splide-renderer.min.js.map


+ 6 - 5
dist/js/splide.cjs.js

@@ -538,8 +538,8 @@ const Direction = (Splide2, Components2, options) => {
       return offset > 0 ? replacement.charAt(0).toUpperCase() + replacement.slice(1) : replacement;
     });
   }
-  function orient(value) {
-    return value * (options.direction === RTL ? 1 : -1);
+  function orient(value, direction = options.direction) {
+    return value * (direction === RTL ? 1 : -1);
   }
   return {
     resolve,
@@ -1265,13 +1265,14 @@ const Move = (Splide, Components, options, event) => {
     const left = resolve("left");
     return rect(list)[left] - rect(track)[left] + orient(getPadding(false));
   }
-  function getRate() {
+  function getRate(index) {
+    const useIndex = !isUndefined(index);
     let rate;
     if (Splide.is(FADE)) {
-      rate = Splide.index / (Splide.length - 1);
+      rate = (useIndex ? index : Splide.index) / (Splide.length - 1);
     } else {
       const isLoop = Splide.is(LOOP);
-      const position = orient(getPosition());
+      const position = orient(useIndex ? toPosition(index) : getPosition());
       const min = orient(getLimit(false));
       const max = orient(getLimit(true));
       const size = sliderSize();

+ 6 - 5
dist/js/splide.esm.js

@@ -534,8 +534,8 @@ const Direction = (Splide2, Components2, options) => {
       return offset > 0 ? replacement.charAt(0).toUpperCase() + replacement.slice(1) : replacement;
     });
   }
-  function orient(value) {
-    return value * (options.direction === RTL ? 1 : -1);
+  function orient(value, direction = options.direction) {
+    return value * (direction === RTL ? 1 : -1);
   }
   return {
     resolve,
@@ -1261,13 +1261,14 @@ const Move = (Splide, Components, options, event) => {
     const left = resolve("left");
     return rect(list)[left] - rect(track)[left] + orient(getPadding(false));
   }
-  function getRate() {
+  function getRate(index) {
+    const useIndex = !isUndefined(index);
     let rate;
     if (Splide.is(FADE)) {
-      rate = Splide.index / (Splide.length - 1);
+      rate = (useIndex ? index : Splide.index) / (Splide.length - 1);
     } else {
       const isLoop = Splide.is(LOOP);
-      const position = orient(getPosition());
+      const position = orient(useIndex ? toPosition(index) : getPosition());
       const min = orient(getLimit(false));
       const max = orient(getLimit(true));
       const size = sliderSize();

+ 6 - 5
dist/js/splide.js

@@ -536,8 +536,8 @@
         return offset > 0 ? replacement.charAt(0).toUpperCase() + replacement.slice(1) : replacement;
       });
     }
-    function orient(value) {
-      return value * (options.direction === RTL ? 1 : -1);
+    function orient(value, direction = options.direction) {
+      return value * (direction === RTL ? 1 : -1);
     }
     return {
       resolve,
@@ -1261,13 +1261,14 @@
       const left = resolve("left");
       return rect(list)[left] - rect(track)[left] + orient(getPadding(false));
     }
-    function getRate() {
+    function getRate(index) {
+      const useIndex = !isUndefined(index);
       let rate;
       if (Splide.is(FADE)) {
-        rate = Splide.index / (Splide.length - 1);
+        rate = (useIndex ? index : Splide.index) / (Splide.length - 1);
       } else {
         const isLoop = Splide.is(LOOP);
-        const position = orient(getPosition());
+        const position = orient(useIndex ? toPosition(index) : getPosition());
         const min = orient(getLimit(false));
         const max = orient(getLimit(true));
         const size = sliderSize();

Dosya farkı çok büyük olduğundan ihmal edildi
+ 0 - 0
dist/js/splide.min.js


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


Dosya farkı çok büyük olduğundan ihmal edildi
+ 0 - 0
dist/js/splide.min.js.map


+ 18 - 2
dist/types/index.d.ts

@@ -132,12 +132,28 @@ interface BreakpointsComponent extends BaseComponent {
  * @since 3.0.0
  */
 interface DirectionComponent extends BaseComponent {
-    resolve<R extends string>(prop: string, axisOnly?: boolean, direction?: Options['direction']): R;
+    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.
@@ -220,7 +236,7 @@ interface MoveComponent extends BaseComponent {
     toIndex(position: number): number;
     toPosition(index: number): number;
     getPosition(): number;
-    getRate(): number;
+    getRate(index?: number): number;
     getLimit(max: boolean): number;
     exceededLimit(max?: boolean | undefined, position?: number): boolean;
     /** @internal */

+ 8 - 5
src/js/components/Move/Move.ts

@@ -10,7 +10,7 @@ import {
 import { IDLE, MOVING } from '../../constants/states';
 import { FADE, LOOP, SLIDE } from '../../constants/types';
 import { AnyFunction, BaseComponent, ComponentConstructor, TransitionComponent } from '../../types';
-import { abs, ceil, clamp, rect, style } from '@splidejs/utils';
+import { abs, ceil, clamp, isUndefined, rect, style } from '@splidejs/utils';
 
 
 /**
@@ -27,7 +27,7 @@ export interface MoveComponent extends BaseComponent {
   toIndex( position: number ): number;
   toPosition( index: number ): number;
   getPosition(): number;
-  getRate(): number;
+  getRate( index?: number ): number;
   getLimit( max: boolean ): number;
   exceededLimit( max?: boolean | undefined, position?: number ): boolean;
 
@@ -245,16 +245,19 @@ export const Move: ComponentConstructor<MoveComponent> = ( Splide, Components, o
   /**
    * Returns the carousel progress rate.
    *
+   * @param index - Optional. If specified, returns the rate of the slide at the index.
+   *
    * @return The progress rate.
    */
-  function getRate(): number {
+  function getRate( index?: number ): number {
+    const useIndex = ! isUndefined( index );
     let rate;
 
     if ( Splide.is( FADE ) ) {
-      rate = Splide.index / ( Splide.length - 1 );
+      rate = ( useIndex ? index : Splide.index ) / ( Splide.length - 1 );
     } else {
       const isLoop   = Splide.is( LOOP );
-      const position = orient( getPosition() );
+      const position = orient( useIndex ? toPosition( index ) : getPosition() );
       const min      = orient( getLimit( false ) );
       const max      = orient( getLimit( true ) );
       const size     = sliderSize();

Bu fark içinde çok fazla dosya değişikliği olduğu için bazı dosyalar gösterilmiyor