Ver Fonte

Skip the dimension check to resize a carousel after generating clones.

Naotoshi Fujita há 2 anos atrás
pai
commit
4b4cabb3ad

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

@@ -1212,18 +1212,17 @@ function Layout(Splide2, Components2, options) {
   }
 
   function init() {
-    rootRect = null;
     vertical = options.direction === TTB;
     style(root, "maxWidth", unit(options.width));
     style(track, resolve("paddingLeft"), cssPadding(false));
     style(track, resolve("paddingRight"), cssPadding(true));
-    resize();
+    resize(true);
   }
 
-  function resize() {
+  function resize(force) {
     var newRect = rect(root);
 
-    if (!rootRect || rootRect.width !== newRect.width || rootRect.height !== newRect.height) {
+    if (force || rootRect.width !== newRect.width || rootRect.height !== newRect.height) {
       style(track, "height", cssTrackHeight());
       styleSlides(resolve("marginRight"), unit(options.gap));
       styleSlides("width", cssSlideWidth());
@@ -1338,7 +1337,7 @@ function Clones(Splide2, Components2, options) {
 
     if (cloneCount = computeCloneCount()) {
       generate(cloneCount);
-      Components2.Layout.resize();
+      Components2.Layout.resize(true);
     }
   }
 

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

@@ -1207,18 +1207,17 @@ function Layout(Splide2, Components2, options) {
   }
 
   function init() {
-    rootRect = null;
     vertical = options.direction === TTB;
     style(root, "maxWidth", unit(options.width));
     style(track, resolve("paddingLeft"), cssPadding(false));
     style(track, resolve("paddingRight"), cssPadding(true));
-    resize();
+    resize(true);
   }
 
-  function resize() {
+  function resize(force) {
     var newRect = rect(root);
 
-    if (!rootRect || rootRect.width !== newRect.width || rootRect.height !== newRect.height) {
+    if (force || rootRect.width !== newRect.width || rootRect.height !== newRect.height) {
       style(track, "height", cssTrackHeight());
       styleSlides(resolve("marginRight"), unit(options.gap));
       styleSlides("width", cssSlideWidth());
@@ -1333,7 +1332,7 @@ function Clones(Splide2, Components2, options) {
 
     if (cloneCount = computeCloneCount()) {
       generate(cloneCount);
-      Components2.Layout.resize();
+      Components2.Layout.resize(true);
     }
   }
 

+ 4 - 5
dist/js/splide.js

@@ -1205,18 +1205,17 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
     }
 
     function init() {
-      rootRect = null;
       vertical = options.direction === TTB;
       style(root, "maxWidth", unit(options.width));
       style(track, resolve("paddingLeft"), cssPadding(false));
       style(track, resolve("paddingRight"), cssPadding(true));
-      resize();
+      resize(true);
     }
 
-    function resize() {
+    function resize(force) {
       var newRect = rect(root);
 
-      if (!rootRect || rootRect.width !== newRect.width || rootRect.height !== newRect.height) {
+      if (force || rootRect.width !== newRect.width || rootRect.height !== newRect.height) {
         style(track, "height", cssTrackHeight());
         styleSlides(resolve("marginRight"), unit(options.gap));
         styleSlides("width", cssSlideWidth());
@@ -1331,7 +1330,7 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
 
       if (cloneCount = computeCloneCount()) {
         generate(cloneCount);
-        Components2.Layout.resize();
+        Components2.Layout.resize(true);
       }
     }
 

Diff do ficheiro suprimidas por serem muito extensas
+ 0 - 0
dist/js/splide.min.js


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


Diff do ficheiro suprimidas por serem muito extensas
+ 0 - 0
dist/js/splide.min.js.map


+ 1 - 1
dist/types/index.d.ts

@@ -72,7 +72,7 @@ interface LayoutComponent extends BaseComponent {
     totalSize(index?: number, withoutGap?: boolean): number;
     getPadding(right: boolean): number;
     /** @internal */
-    resize(): void;
+    resize(force?: boolean): void;
 }
 
 /**

+ 1 - 1
src/js/components/Clones/Clones.ts

@@ -58,7 +58,7 @@ export function Clones( Splide: Splide, Components: Components, options: Options
 
     if ( ( cloneCount = computeCloneCount() ) ) {
       generate( cloneCount );
-      Components.Layout.resize();
+      Components.Layout.resize( true );
     }
   }
 

+ 6 - 5
src/js/components/Layout/Layout.ts

@@ -20,7 +20,7 @@ export interface LayoutComponent extends BaseComponent {
   getPadding( right: boolean ): number;
 
   /** @internal */
-  resize(): void;
+  resize( force?: boolean ): void;
 }
 
 /**
@@ -71,24 +71,25 @@ export function Layout( Splide: Splide, Components: Components, options: Options
    * Uses `max-width` for the root to prevent the slider from exceeding the parent element.
    */
   function init(): void {
-    rootRect = null;
     vertical = options.direction === TTB;
 
     style( root, 'maxWidth', unit( options.width ) );
     style( track, resolve( 'paddingLeft' ), cssPadding( false ) );
     style( track, resolve( 'paddingRight' ), cssPadding( true ) );
 
-    resize();
+    resize( true );
   }
 
   /**
    * Updates dimensions of some elements when the carousel is resized.
    * Also checks the carousel size and emits `overflow` events when it exceeds the list width.
+   *
+   * @param force - Skips checking the root dimension change and always performs the resizing process.
    */
-  function resize(): void {
+  function resize( force?: boolean ): void {
     const newRect = rect( root );
 
-    if ( ! rootRect || rootRect.width !== newRect.width || rootRect.height !== newRect.height ) {
+    if ( force || rootRect.width !== newRect.width || rootRect.height !== newRect.height ) {
       style( track, 'height', cssTrackHeight() );
 
       styleSlides( resolve( 'marginRight' ), unit( options.gap ) );

Alguns ficheiros não foram mostrados porque muitos ficheiros mudaram neste diff