@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 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
  *
@@ -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
  *
package/swiper-element.js CHANGED
@@ -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) {
@@ -459,6 +459,23 @@
459
459
  el.innerHTML = html;
460
460
  }
461
461
  }
462
+ function computeAutoSlideSize(slideEl, getDirectionPropValue) {
463
+ const styles = getComputedStyle(slideEl);
464
+ const width = getDirectionPropValue(styles, 'width');
465
+ const paddingLeft = getDirectionPropValue(styles, 'padding-left');
466
+ const paddingRight = getDirectionPropValue(styles, 'padding-right');
467
+ const marginLeft = getDirectionPropValue(styles, 'margin-left');
468
+ const marginRight = getDirectionPropValue(styles, 'margin-right');
469
+ const boxSizing = styles.getPropertyValue('box-sizing');
470
+ if (boxSizing && boxSizing === 'border-box') {
471
+ return width + marginLeft + marginRight;
472
+ }
473
+ const {
474
+ clientWidth,
475
+ offsetWidth
476
+ } = slideEl;
477
+ return width + paddingLeft + paddingRight + marginLeft + marginRight + (offsetWidth - clientWidth);
478
+ }
462
479
 
463
480
  let support;
464
481
  function calcSupport() {
@@ -898,44 +915,87 @@
898
915
  // Calc slides
899
916
  let slideSize;
900
917
  const shouldResetSlideSize = params.slidesPerView === 'auto' && params.breakpoints && Object.keys(params.breakpoints).filter(key => typeof params.breakpoints[key].slidesPerView !== 'undefined').length > 0;
901
- for (let i = 0; i < slidesLength; i += 1) {
902
- slideSize = 0;
903
- let slide;
904
- if (slides[i]) slide = slides[i];
905
- if (slides[i] && elementStyle(slide, 'display') === 'none') continue; // eslint-disable-line
918
+ const isAutoSlides = params.slidesPerView === 'auto';
906
919
 
907
- if (params.slidesPerView === 'auto') {
908
- if (shouldResetSlideSize && slides[i]) {
920
+ // --- Phase 1: Batch DOM writes (grid updates, width/transform resets) ---
921
+ // Moving all style writes before any reads prevents per-slide forced reflows
922
+ if (gridEnabled) {
923
+ for (let i = 0; i < slidesLength; i += 1) {
924
+ if (slides[i]) swiper.grid.updateSlide(i, slides[i], slides);
925
+ }
926
+ }
927
+ const savedTransforms = [];
928
+ if (isAutoSlides) {
929
+ for (let i = 0; i < slidesLength; i += 1) {
930
+ if (!slides[i]) continue;
931
+ if (shouldResetSlideSize) {
909
932
  slides[i].style[swiper.getDirectionLabel('width')] = ``;
910
933
  }
911
- const slideStyles = getComputedStyle(slide);
912
- const currentTransform = slide.style.transform;
913
- const currentWebKitTransform = slide.style.webkitTransform;
914
- if (currentTransform) slide.style.transform = 'none';
915
- if (currentWebKitTransform) slide.style.webkitTransform = 'none';
934
+ const currentTransform = slides[i].style.transform;
935
+ const currentWebKitTransform = slides[i].style.webkitTransform;
936
+ savedTransforms[i] = {
937
+ transform: currentTransform,
938
+ webkitTransform: currentWebKitTransform
939
+ };
940
+ if (currentTransform) {
941
+ slides[i].style.transform = 'none';
942
+ }
943
+ if (currentWebKitTransform) {
944
+ slides[i].style.webkitTransform = 'none';
945
+ }
946
+ }
947
+ }
948
+
949
+ // --- Phase 2: Batch DOM reads (single forced reflow for all slides) ---
950
+ // Read wrapper offset here (before Phase 3 writes) so it's batched with slide reads, not after
951
+ const wrapperOffset = swiper.isElement ? swiper.wrapperEl[`offset${swiper.isHorizontal() ? 'Left' : 'Top'}`] : 0;
952
+ const slideVisible = [];
953
+ const slideSizes = [];
954
+ for (let i = 0; i < slidesLength; i += 1) {
955
+ if (!slides[i]) {
956
+ slideVisible[i] = false;
957
+ continue;
958
+ }
959
+ if (elementStyle(slides[i], 'display') === 'none') {
960
+ slideVisible[i] = false;
961
+ continue;
962
+ }
963
+ slideVisible[i] = true;
964
+
965
+ // Cache offsetHeight for autoHeight (batched here to avoid a separate forced reflow in updateAutoHeight)
966
+ if (params.autoHeight) {
967
+ slides[i].swiperSlideHeight = slides[i]['offsetHeight'];
968
+ }
969
+ if (isAutoSlides) {
916
970
  if (params.roundLengths) {
917
- slideSize = swiper.isHorizontal() ? elementOuterSize(slide, 'width', true) : elementOuterSize(slide, 'height', true);
971
+ slideSizes[i] = swiper.isHorizontal() ? elementOuterSize(slides[i], 'width', true) : elementOuterSize(slides[i], 'height', true);
918
972
  } else {
919
- // eslint-disable-next-line
920
- const width = parseFloat(slideStyles.getPropertyValue('width')) || slide.offsetWidth;
921
- const paddingLeft = parseFloat(slideStyles.getPropertyValue('padding-left')) || 0;
922
- const paddingRight = parseFloat(slideStyles.getPropertyValue('padding-right')) || 0;
923
- const marginLeft = parseFloat(slideStyles.getPropertyValue('margin-left')) || 0;
924
- const marginRight = parseFloat(slideStyles.getPropertyValue('margin-right')) || 0;
925
- const boxSizing = slideStyles.getPropertyValue('box-sizing');
926
- if (boxSizing && boxSizing === 'border-box') {
927
- slideSize = width + marginLeft + marginRight;
928
- } else {
929
- const {
930
- clientWidth,
931
- offsetWidth
932
- } = slide;
933
- slideSize = width + paddingLeft + paddingRight + marginLeft + marginRight + (offsetWidth - clientWidth);
934
- }
973
+ slideSizes[i] = computeAutoSlideSize(slides[i], getDirectionPropertyValue);
935
974
  }
936
- if (currentTransform) slide.style.transform = currentTransform;
937
- if (currentWebKitTransform) slide.style.webkitTransform = currentWebKitTransform;
938
- if (params.roundLengths) slideSize = Math.floor(slideSize);
975
+ if (params.roundLengths) slideSizes[i] = Math.floor(slideSizes[i]);
976
+ }
977
+ }
978
+
979
+ // --- Phase 3: Restore transforms (batch write) ---
980
+ if (isAutoSlides) {
981
+ for (let i = 0; i < slidesLength; i += 1) {
982
+ if (!savedTransforms[i]) continue;
983
+ if (savedTransforms[i].transform) {
984
+ slides[i].style.transform = savedTransforms[i].transform;
985
+ }
986
+ if (savedTransforms[i].webkitTransform) {
987
+ slides[i].style.webkitTransform = savedTransforms[i].webkitTransform;
988
+ }
989
+ }
990
+ }
991
+
992
+ // --- Phase 4: Calculate positions + set sizes (math + deferred writes) ---
993
+ const cssOverflowAdj = swiper.cssOverflowAdjustment();
994
+ for (let i = 0; i < slidesLength; i += 1) {
995
+ slideSize = 0;
996
+ if (!slideVisible[i]) continue;
997
+ if (isAutoSlides) {
998
+ slideSize = slideSizes[i] || 0;
939
999
  } else {
940
1000
  slideSize = (swiperSize - (params.slidesPerView - 1) * spaceBetween) / params.slidesPerView;
941
1001
  if (params.roundLengths) slideSize = Math.floor(slideSize);
@@ -963,7 +1023,12 @@
963
1023
  slidesGrid.push(slidePosition);
964
1024
  slidePosition = slidePosition + slideSize + spaceBetween;
965
1025
  }
966
- swiper.slidesTotalSize += slideSize + spaceBetween;
1026
+
1027
+ // Set swiperSlideOffset from computed grid position (avoids DOM reads in updateSlidesOffset)
1028
+ if (slides[i]) {
1029
+ slides[i].swiperSlideOffset = slidesGrid[slidesGrid.length - 1] - cssOverflowAdj - wrapperOffset;
1030
+ }
1031
+ swiper.virtualSize += slideSize + spaceBetween;
967
1032
  prevSlideSize = slideSize;
968
1033
  index += 1;
969
1034
  }
@@ -1058,7 +1123,9 @@
1058
1123
  swiper.emit('slidesGridLengthChange');
1059
1124
  }
1060
1125
  if (params.watchSlidesProgress) {
1061
- swiper.updateSlidesOffset();
1126
+ swiper.updateSlidesOffset({
1127
+ isCalculatedFromUpdateSlides: false
1128
+ });
1062
1129
  }
1063
1130
  swiper.emit('slidesUpdated');
1064
1131
  if (!params.cssMode && params.effect === 'slide') {
@@ -1103,14 +1170,20 @@
1103
1170
  let newHeight = 0;
1104
1171
  for (let i = 0; i < activeSlides.length; i += 1) {
1105
1172
  if (typeof activeSlides[i] !== 'undefined') {
1106
- const height = activeSlides[i].offsetHeight;
1173
+ const height = activeSlides[i].swiperSlideHeight ?? activeSlides[i]['offsetHeight'];
1107
1174
  newHeight = height > newHeight ? height : newHeight;
1108
1175
  }
1109
1176
  }
1110
1177
  if (newHeight || newHeight === 0) swiper.wrapperEl.style.height = `${newHeight}px`;
1111
1178
  }
1112
1179
 
1113
- function updateSlidesOffset() {
1180
+ function updateSlidesOffset(params) {
1181
+ const {
1182
+ isCalculatedFromUpdateSlides = false
1183
+ } = params ?? {};
1184
+ if (isCalculatedFromUpdateSlides) {
1185
+ return;
1186
+ }
1114
1187
  const swiper = this;
1115
1188
  const slides = swiper.slides;
1116
1189
  // eslint-disable-next-line
@@ -2397,7 +2470,9 @@
2397
2470
  swiper.updateSlides();
2398
2471
  }
2399
2472
  if (params.watchSlidesProgress) {
2400
- swiper.updateSlidesOffset();
2473
+ swiper.updateSlidesOffset({
2474
+ isCalculatedFromUpdateSlides: params.slidesPerView === 'auto'
2475
+ });
2401
2476
  }
2402
2477
  if (slideTo) {
2403
2478
  if (prependSlidesIndexes.length > 0 && isPrev) {
@@ -3962,7 +4037,8 @@
3962
4037
  },
3963
4038
  // Images
3964
4039
  imagesToLoad: [],
3965
- imagesLoaded: 0
4040
+ imagesLoaded: 0,
4041
+ rtl: params?.rtl
3966
4042
  });
3967
4043
  swiper.emit('_swiper');
3968
4044
 
@@ -4224,15 +4300,18 @@
4224
4300
  wrapperEl.append(slideEl);
4225
4301
  });
4226
4302
  }
4303
+ const rtl = swiper.params.rtl ?? (el.dir.toLowerCase() === 'rtl' || elementStyle(el, 'direction') === 'rtl');
4304
+ const wrongRTL = false;
4227
4305
  Object.assign(swiper, {
4228
4306
  el,
4229
4307
  wrapperEl,
4230
4308
  slidesEl: swiper.isElement && !el.parentNode.host.slideSlots ? el.parentNode.host : wrapperEl,
4231
4309
  hostEl: swiper.isElement ? el.parentNode.host : el,
4232
4310
  mounted: true,
4233
- rtl: el.dir.toLowerCase() === 'rtl' || elementStyle(el, 'direction') === 'rtl',
4234
- rtlTranslate: swiper.params.direction === 'horizontal' && (el.dir.toLowerCase() === 'rtl' || elementStyle(el, 'direction') === 'rtl'),
4235
- wrongRTL: elementStyle(wrapperEl, 'display') === '-webkit-box'
4311
+ // RTL
4312
+ rtl,
4313
+ rtlTranslate: swiper.params.direction === 'horizontal' && rtl,
4314
+ wrongRTL
4236
4315
  });
4237
4316
  return true;
4238
4317
  }
@@ -4312,7 +4391,8 @@
4312
4391
  });
4313
4392
  preload(swiper);
4314
4393
  swiper.initialized = true;
4315
- preload(swiper);
4394
+
4395
+ // Emit
4316
4396
  swiper.emit('init');
4317
4397
  swiper.emit('afterInit');
4318
4398
  return swiper;
@@ -4723,7 +4803,7 @@
4723
4803
  }
4724
4804
 
4725
4805
  /**
4726
- * Swiper Custom Element 0.0.15-dev.1
4806
+ * Swiper Custom Element 0.0.16-dev.1
4727
4807
  * Gem SDK - Swiper, Customized of swiper
4728
4808
  * https://swiperjs.com
4729
4809
  *