@gem-sdk/swiper 0.0.15-dev.1 → 0.0.16-dev.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Swiper 0.0.15-dev.1
2
+ * Swiper 0.0.16-dev.1
3
3
  * Gem SDK - Swiper, Customized of swiper
4
4
  * https://swiperjs.com
5
5
  *
package/swiper-bundle.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Swiper 0.0.15-dev.1
2
+ * Swiper 0.0.16-dev.1
3
3
  * Gem SDK - Swiper, Customized of swiper
4
4
  * https://swiperjs.com
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Swiper 0.0.15-dev.1
2
+ * Swiper 0.0.16-dev.1
3
3
  * Gem SDK - Swiper, Customized of swiper
4
4
  * https://swiperjs.com
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Swiper 0.0.15-dev.1
2
+ * Swiper 0.0.16-dev.1
3
3
  * Gem SDK - Swiper, Customized of swiper
4
4
  * https://swiperjs.com
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Swiper Custom Element 0.0.15-dev.1
2
+ * Swiper Custom Element 0.0.16-dev.1
3
3
  * Gem SDK - Swiper, Customized of swiper
4
4
  * https://swiperjs.com
5
5
  *
@@ -189,7 +189,7 @@
189
189
  function now() {
190
190
  return Date.now();
191
191
  }
192
- function getComputedStyle$1(el) {
192
+ function getComputedStyle(el) {
193
193
  const window = getWindow();
194
194
  let style;
195
195
  if (window.getComputedStyle) {
@@ -211,7 +211,7 @@
211
211
  let matrix;
212
212
  let curTransform;
213
213
  let transformMatrix;
214
- const curStyle = getComputedStyle$1(el);
214
+ const curStyle = getComputedStyle(el);
215
215
  if (window.WebKitCSSMatrix) {
216
216
  curTransform = curStyle.transform || curStyle.webkitTransform;
217
217
  if (curTransform.split(',').length > 6) {
@@ -497,6 +497,23 @@
497
497
  el.innerHTML = html;
498
498
  }
499
499
  }
500
+ function computeAutoSlideSize(slideEl, getDirectionPropValue) {
501
+ const styles = getComputedStyle(slideEl);
502
+ const width = getDirectionPropValue(styles, 'width');
503
+ const paddingLeft = getDirectionPropValue(styles, 'padding-left');
504
+ const paddingRight = getDirectionPropValue(styles, 'padding-right');
505
+ const marginLeft = getDirectionPropValue(styles, 'margin-left');
506
+ const marginRight = getDirectionPropValue(styles, 'margin-right');
507
+ const boxSizing = styles.getPropertyValue('box-sizing');
508
+ if (boxSizing && boxSizing === 'border-box') {
509
+ return width + marginLeft + marginRight;
510
+ }
511
+ const {
512
+ clientWidth,
513
+ offsetWidth
514
+ } = slideEl;
515
+ return width + paddingLeft + paddingRight + marginLeft + marginRight + (offsetWidth - clientWidth);
516
+ }
500
517
 
501
518
  let support;
502
519
  function calcSupport() {
@@ -936,44 +953,87 @@
936
953
  // Calc slides
937
954
  let slideSize;
938
955
  const shouldResetSlideSize = params.slidesPerView === 'auto' && params.breakpoints && Object.keys(params.breakpoints).filter(key => typeof params.breakpoints[key].slidesPerView !== 'undefined').length > 0;
939
- for (let i = 0; i < slidesLength; i += 1) {
940
- slideSize = 0;
941
- let slide;
942
- if (slides[i]) slide = slides[i];
943
- if (slides[i] && elementStyle(slide, 'display') === 'none') continue; // eslint-disable-line
956
+ const isAutoSlides = params.slidesPerView === 'auto';
944
957
 
945
- if (params.slidesPerView === 'auto') {
946
- if (shouldResetSlideSize && slides[i]) {
958
+ // --- Phase 1: Batch DOM writes (grid updates, width/transform resets) ---
959
+ // Moving all style writes before any reads prevents per-slide forced reflows
960
+ if (gridEnabled) {
961
+ for (let i = 0; i < slidesLength; i += 1) {
962
+ if (slides[i]) swiper.grid.updateSlide(i, slides[i], slides);
963
+ }
964
+ }
965
+ const savedTransforms = [];
966
+ if (isAutoSlides) {
967
+ for (let i = 0; i < slidesLength; i += 1) {
968
+ if (!slides[i]) continue;
969
+ if (shouldResetSlideSize) {
947
970
  slides[i].style[swiper.getDirectionLabel('width')] = ``;
948
971
  }
949
- const slideStyles = getComputedStyle(slide);
950
- const currentTransform = slide.style.transform;
951
- const currentWebKitTransform = slide.style.webkitTransform;
952
- if (currentTransform) slide.style.transform = 'none';
953
- if (currentWebKitTransform) slide.style.webkitTransform = 'none';
972
+ const currentTransform = slides[i].style.transform;
973
+ const currentWebKitTransform = slides[i].style.webkitTransform;
974
+ savedTransforms[i] = {
975
+ transform: currentTransform,
976
+ webkitTransform: currentWebKitTransform
977
+ };
978
+ if (currentTransform) {
979
+ slides[i].style.transform = 'none';
980
+ }
981
+ if (currentWebKitTransform) {
982
+ slides[i].style.webkitTransform = 'none';
983
+ }
984
+ }
985
+ }
986
+
987
+ // --- Phase 2: Batch DOM reads (single forced reflow for all slides) ---
988
+ // Read wrapper offset here (before Phase 3 writes) so it's batched with slide reads, not after
989
+ const wrapperOffset = swiper.isElement ? swiper.wrapperEl[`offset${swiper.isHorizontal() ? 'Left' : 'Top'}`] : 0;
990
+ const slideVisible = [];
991
+ const slideSizes = [];
992
+ for (let i = 0; i < slidesLength; i += 1) {
993
+ if (!slides[i]) {
994
+ slideVisible[i] = false;
995
+ continue;
996
+ }
997
+ if (elementStyle(slides[i], 'display') === 'none') {
998
+ slideVisible[i] = false;
999
+ continue;
1000
+ }
1001
+ slideVisible[i] = true;
1002
+
1003
+ // Cache offsetHeight for autoHeight (batched here to avoid a separate forced reflow in updateAutoHeight)
1004
+ if (params.autoHeight) {
1005
+ slides[i].swiperSlideHeight = slides[i]['offsetHeight'];
1006
+ }
1007
+ if (isAutoSlides) {
954
1008
  if (params.roundLengths) {
955
- slideSize = swiper.isHorizontal() ? elementOuterSize(slide, 'width', true) : elementOuterSize(slide, 'height', true);
1009
+ slideSizes[i] = swiper.isHorizontal() ? elementOuterSize(slides[i], 'width', true) : elementOuterSize(slides[i], 'height', true);
956
1010
  } else {
957
- // eslint-disable-next-line
958
- const width = parseFloat(slideStyles.getPropertyValue('width')) || slide.offsetWidth;
959
- const paddingLeft = parseFloat(slideStyles.getPropertyValue('padding-left')) || 0;
960
- const paddingRight = parseFloat(slideStyles.getPropertyValue('padding-right')) || 0;
961
- const marginLeft = parseFloat(slideStyles.getPropertyValue('margin-left')) || 0;
962
- const marginRight = parseFloat(slideStyles.getPropertyValue('margin-right')) || 0;
963
- const boxSizing = slideStyles.getPropertyValue('box-sizing');
964
- if (boxSizing && boxSizing === 'border-box') {
965
- slideSize = width + marginLeft + marginRight;
966
- } else {
967
- const {
968
- clientWidth,
969
- offsetWidth
970
- } = slide;
971
- slideSize = width + paddingLeft + paddingRight + marginLeft + marginRight + (offsetWidth - clientWidth);
972
- }
1011
+ slideSizes[i] = computeAutoSlideSize(slides[i], getDirectionPropertyValue);
973
1012
  }
974
- if (currentTransform) slide.style.transform = currentTransform;
975
- if (currentWebKitTransform) slide.style.webkitTransform = currentWebKitTransform;
976
- if (params.roundLengths) slideSize = Math.floor(slideSize);
1013
+ if (params.roundLengths) slideSizes[i] = Math.floor(slideSizes[i]);
1014
+ }
1015
+ }
1016
+
1017
+ // --- Phase 3: Restore transforms (batch write) ---
1018
+ if (isAutoSlides) {
1019
+ for (let i = 0; i < slidesLength; i += 1) {
1020
+ if (!savedTransforms[i]) continue;
1021
+ if (savedTransforms[i].transform) {
1022
+ slides[i].style.transform = savedTransforms[i].transform;
1023
+ }
1024
+ if (savedTransforms[i].webkitTransform) {
1025
+ slides[i].style.webkitTransform = savedTransforms[i].webkitTransform;
1026
+ }
1027
+ }
1028
+ }
1029
+
1030
+ // --- Phase 4: Calculate positions + set sizes (math + deferred writes) ---
1031
+ const cssOverflowAdj = swiper.cssOverflowAdjustment();
1032
+ for (let i = 0; i < slidesLength; i += 1) {
1033
+ slideSize = 0;
1034
+ if (!slideVisible[i]) continue;
1035
+ if (isAutoSlides) {
1036
+ slideSize = slideSizes[i] || 0;
977
1037
  } else {
978
1038
  slideSize = (swiperSize - (params.slidesPerView - 1) * spaceBetween) / params.slidesPerView;
979
1039
  if (params.roundLengths) slideSize = Math.floor(slideSize);
@@ -1001,7 +1061,12 @@
1001
1061
  slidesGrid.push(slidePosition);
1002
1062
  slidePosition = slidePosition + slideSize + spaceBetween;
1003
1063
  }
1004
- swiper.slidesTotalSize += slideSize + spaceBetween;
1064
+
1065
+ // Set swiperSlideOffset from computed grid position (avoids DOM reads in updateSlidesOffset)
1066
+ if (slides[i]) {
1067
+ slides[i].swiperSlideOffset = slidesGrid[slidesGrid.length - 1] - cssOverflowAdj - wrapperOffset;
1068
+ }
1069
+ swiper.virtualSize += slideSize + spaceBetween;
1005
1070
  prevSlideSize = slideSize;
1006
1071
  index += 1;
1007
1072
  }
@@ -1096,7 +1161,9 @@
1096
1161
  swiper.emit('slidesGridLengthChange');
1097
1162
  }
1098
1163
  if (params.watchSlidesProgress) {
1099
- swiper.updateSlidesOffset();
1164
+ swiper.updateSlidesOffset({
1165
+ isCalculatedFromUpdateSlides: false
1166
+ });
1100
1167
  }
1101
1168
  swiper.emit('slidesUpdated');
1102
1169
  if (!params.cssMode && params.effect === 'slide') {
@@ -1141,14 +1208,20 @@
1141
1208
  let newHeight = 0;
1142
1209
  for (let i = 0; i < activeSlides.length; i += 1) {
1143
1210
  if (typeof activeSlides[i] !== 'undefined') {
1144
- const height = activeSlides[i].offsetHeight;
1211
+ const height = activeSlides[i].swiperSlideHeight ?? activeSlides[i]['offsetHeight'];
1145
1212
  newHeight = height > newHeight ? height : newHeight;
1146
1213
  }
1147
1214
  }
1148
1215
  if (newHeight || newHeight === 0) swiper.wrapperEl.style.height = `${newHeight}px`;
1149
1216
  }
1150
1217
 
1151
- function updateSlidesOffset() {
1218
+ function updateSlidesOffset(params) {
1219
+ const {
1220
+ isCalculatedFromUpdateSlides = false
1221
+ } = params ?? {};
1222
+ if (isCalculatedFromUpdateSlides) {
1223
+ return;
1224
+ }
1152
1225
  const swiper = this;
1153
1226
  const slides = swiper.slides;
1154
1227
  // eslint-disable-next-line
@@ -2435,7 +2508,9 @@
2435
2508
  swiper.updateSlides();
2436
2509
  }
2437
2510
  if (params.watchSlidesProgress) {
2438
- swiper.updateSlidesOffset();
2511
+ swiper.updateSlidesOffset({
2512
+ isCalculatedFromUpdateSlides: params.slidesPerView === 'auto'
2513
+ });
2439
2514
  }
2440
2515
  if (slideTo) {
2441
2516
  if (prependSlidesIndexes.length > 0 && isPrev) {
@@ -4000,7 +4075,8 @@
4000
4075
  },
4001
4076
  // Images
4002
4077
  imagesToLoad: [],
4003
- imagesLoaded: 0
4078
+ imagesLoaded: 0,
4079
+ rtl: params?.rtl
4004
4080
  });
4005
4081
  swiper.emit('_swiper');
4006
4082
 
@@ -4262,15 +4338,18 @@
4262
4338
  wrapperEl.append(slideEl);
4263
4339
  });
4264
4340
  }
4341
+ const rtl = swiper.params.rtl ?? (el.dir.toLowerCase() === 'rtl' || elementStyle(el, 'direction') === 'rtl');
4342
+ const wrongRTL = false;
4265
4343
  Object.assign(swiper, {
4266
4344
  el,
4267
4345
  wrapperEl,
4268
4346
  slidesEl: swiper.isElement && !el.parentNode.host.slideSlots ? el.parentNode.host : wrapperEl,
4269
4347
  hostEl: swiper.isElement ? el.parentNode.host : el,
4270
4348
  mounted: true,
4271
- rtl: el.dir.toLowerCase() === 'rtl' || elementStyle(el, 'direction') === 'rtl',
4272
- rtlTranslate: swiper.params.direction === 'horizontal' && (el.dir.toLowerCase() === 'rtl' || elementStyle(el, 'direction') === 'rtl'),
4273
- wrongRTL: elementStyle(wrapperEl, 'display') === '-webkit-box'
4349
+ // RTL
4350
+ rtl,
4351
+ rtlTranslate: swiper.params.direction === 'horizontal' && rtl,
4352
+ wrongRTL
4274
4353
  });
4275
4354
  return true;
4276
4355
  }
@@ -4350,7 +4429,8 @@
4350
4429
  });
4351
4430
  preload(swiper);
4352
4431
  swiper.initialized = true;
4353
- preload(swiper);
4432
+
4433
+ // Emit
4354
4434
  swiper.emit('init');
4355
4435
  swiper.emit('afterInit');
4356
4436
  return swiper;
@@ -9825,7 +9905,7 @@
9825
9905
  }
9826
9906
 
9827
9907
  /**
9828
- * Swiper 0.0.15-dev.1
9908
+ * Swiper 0.0.16-dev.1
9829
9909
  * Gem SDK - Swiper, Customized of swiper
9830
9910
  * https://swiperjs.com
9831
9911
  *
@@ -10167,7 +10247,7 @@
10167
10247
  }
10168
10248
 
10169
10249
  /**
10170
- * Swiper Custom Element 0.0.15-dev.1
10250
+ * Swiper Custom Element 0.0.16-dev.1
10171
10251
  * Gem SDK - Swiper, Customized of swiper
10172
10252
  * https://swiperjs.com
10173
10253
  *