@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.
package/swiper.js 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
  *
@@ -189,7 +189,7 @@ var Swiper = (function () {
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 @@ var Swiper = (function () {
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) {
@@ -447,6 +447,23 @@ var Swiper = (function () {
447
447
  }
448
448
  return el.offsetWidth;
449
449
  }
450
+ function computeAutoSlideSize(slideEl, getDirectionPropValue) {
451
+ const styles = getComputedStyle(slideEl);
452
+ const width = getDirectionPropValue(styles, 'width');
453
+ const paddingLeft = getDirectionPropValue(styles, 'padding-left');
454
+ const paddingRight = getDirectionPropValue(styles, 'padding-right');
455
+ const marginLeft = getDirectionPropValue(styles, 'margin-left');
456
+ const marginRight = getDirectionPropValue(styles, 'margin-right');
457
+ const boxSizing = styles.getPropertyValue('box-sizing');
458
+ if (boxSizing && boxSizing === 'border-box') {
459
+ return width + marginLeft + marginRight;
460
+ }
461
+ const {
462
+ clientWidth,
463
+ offsetWidth
464
+ } = slideEl;
465
+ return width + paddingLeft + paddingRight + marginLeft + marginRight + (offsetWidth - clientWidth);
466
+ }
450
467
 
451
468
  let support;
452
469
  function calcSupport() {
@@ -886,44 +903,87 @@ var Swiper = (function () {
886
903
  // Calc slides
887
904
  let slideSize;
888
905
  const shouldResetSlideSize = params.slidesPerView === 'auto' && params.breakpoints && Object.keys(params.breakpoints).filter(key => typeof params.breakpoints[key].slidesPerView !== 'undefined').length > 0;
889
- for (let i = 0; i < slidesLength; i += 1) {
890
- slideSize = 0;
891
- let slide;
892
- if (slides[i]) slide = slides[i];
893
- if (slides[i] && elementStyle(slide, 'display') === 'none') continue; // eslint-disable-line
906
+ const isAutoSlides = params.slidesPerView === 'auto';
894
907
 
895
- if (params.slidesPerView === 'auto') {
896
- if (shouldResetSlideSize && slides[i]) {
908
+ // --- Phase 1: Batch DOM writes (grid updates, width/transform resets) ---
909
+ // Moving all style writes before any reads prevents per-slide forced reflows
910
+ if (gridEnabled) {
911
+ for (let i = 0; i < slidesLength; i += 1) {
912
+ if (slides[i]) swiper.grid.updateSlide(i, slides[i], slides);
913
+ }
914
+ }
915
+ const savedTransforms = [];
916
+ if (isAutoSlides) {
917
+ for (let i = 0; i < slidesLength; i += 1) {
918
+ if (!slides[i]) continue;
919
+ if (shouldResetSlideSize) {
897
920
  slides[i].style[swiper.getDirectionLabel('width')] = ``;
898
921
  }
899
- const slideStyles = getComputedStyle(slide);
900
- const currentTransform = slide.style.transform;
901
- const currentWebKitTransform = slide.style.webkitTransform;
902
- if (currentTransform) slide.style.transform = 'none';
903
- if (currentWebKitTransform) slide.style.webkitTransform = 'none';
922
+ const currentTransform = slides[i].style.transform;
923
+ const currentWebKitTransform = slides[i].style.webkitTransform;
924
+ savedTransforms[i] = {
925
+ transform: currentTransform,
926
+ webkitTransform: currentWebKitTransform
927
+ };
928
+ if (currentTransform) {
929
+ slides[i].style.transform = 'none';
930
+ }
931
+ if (currentWebKitTransform) {
932
+ slides[i].style.webkitTransform = 'none';
933
+ }
934
+ }
935
+ }
936
+
937
+ // --- Phase 2: Batch DOM reads (single forced reflow for all slides) ---
938
+ // Read wrapper offset here (before Phase 3 writes) so it's batched with slide reads, not after
939
+ const wrapperOffset = swiper.isElement ? swiper.wrapperEl[`offset${swiper.isHorizontal() ? 'Left' : 'Top'}`] : 0;
940
+ const slideVisible = [];
941
+ const slideSizes = [];
942
+ for (let i = 0; i < slidesLength; i += 1) {
943
+ if (!slides[i]) {
944
+ slideVisible[i] = false;
945
+ continue;
946
+ }
947
+ if (elementStyle(slides[i], 'display') === 'none') {
948
+ slideVisible[i] = false;
949
+ continue;
950
+ }
951
+ slideVisible[i] = true;
952
+
953
+ // Cache offsetHeight for autoHeight (batched here to avoid a separate forced reflow in updateAutoHeight)
954
+ if (params.autoHeight) {
955
+ slides[i].swiperSlideHeight = slides[i]['offsetHeight'];
956
+ }
957
+ if (isAutoSlides) {
904
958
  if (params.roundLengths) {
905
- slideSize = swiper.isHorizontal() ? elementOuterSize(slide, 'width', true) : elementOuterSize(slide, 'height', true);
959
+ slideSizes[i] = swiper.isHorizontal() ? elementOuterSize(slides[i], 'width', true) : elementOuterSize(slides[i], 'height', true);
906
960
  } else {
907
- // eslint-disable-next-line
908
- const width = parseFloat(slideStyles.getPropertyValue('width')) || slide.offsetWidth;
909
- const paddingLeft = parseFloat(slideStyles.getPropertyValue('padding-left')) || 0;
910
- const paddingRight = parseFloat(slideStyles.getPropertyValue('padding-right')) || 0;
911
- const marginLeft = parseFloat(slideStyles.getPropertyValue('margin-left')) || 0;
912
- const marginRight = parseFloat(slideStyles.getPropertyValue('margin-right')) || 0;
913
- const boxSizing = slideStyles.getPropertyValue('box-sizing');
914
- if (boxSizing && boxSizing === 'border-box') {
915
- slideSize = width + marginLeft + marginRight;
916
- } else {
917
- const {
918
- clientWidth,
919
- offsetWidth
920
- } = slide;
921
- slideSize = width + paddingLeft + paddingRight + marginLeft + marginRight + (offsetWidth - clientWidth);
922
- }
961
+ slideSizes[i] = computeAutoSlideSize(slides[i], getDirectionPropertyValue);
923
962
  }
924
- if (currentTransform) slide.style.transform = currentTransform;
925
- if (currentWebKitTransform) slide.style.webkitTransform = currentWebKitTransform;
926
- if (params.roundLengths) slideSize = Math.floor(slideSize);
963
+ if (params.roundLengths) slideSizes[i] = Math.floor(slideSizes[i]);
964
+ }
965
+ }
966
+
967
+ // --- Phase 3: Restore transforms (batch write) ---
968
+ if (isAutoSlides) {
969
+ for (let i = 0; i < slidesLength; i += 1) {
970
+ if (!savedTransforms[i]) continue;
971
+ if (savedTransforms[i].transform) {
972
+ slides[i].style.transform = savedTransforms[i].transform;
973
+ }
974
+ if (savedTransforms[i].webkitTransform) {
975
+ slides[i].style.webkitTransform = savedTransforms[i].webkitTransform;
976
+ }
977
+ }
978
+ }
979
+
980
+ // --- Phase 4: Calculate positions + set sizes (math + deferred writes) ---
981
+ const cssOverflowAdj = swiper.cssOverflowAdjustment();
982
+ for (let i = 0; i < slidesLength; i += 1) {
983
+ slideSize = 0;
984
+ if (!slideVisible[i]) continue;
985
+ if (isAutoSlides) {
986
+ slideSize = slideSizes[i] || 0;
927
987
  } else {
928
988
  slideSize = (swiperSize - (params.slidesPerView - 1) * spaceBetween) / params.slidesPerView;
929
989
  if (params.roundLengths) slideSize = Math.floor(slideSize);
@@ -951,7 +1011,12 @@ var Swiper = (function () {
951
1011
  slidesGrid.push(slidePosition);
952
1012
  slidePosition = slidePosition + slideSize + spaceBetween;
953
1013
  }
954
- swiper.slidesTotalSize += slideSize + spaceBetween;
1014
+
1015
+ // Set swiperSlideOffset from computed grid position (avoids DOM reads in updateSlidesOffset)
1016
+ if (slides[i]) {
1017
+ slides[i].swiperSlideOffset = slidesGrid[slidesGrid.length - 1] - cssOverflowAdj - wrapperOffset;
1018
+ }
1019
+ swiper.virtualSize += slideSize + spaceBetween;
955
1020
  prevSlideSize = slideSize;
956
1021
  index += 1;
957
1022
  }
@@ -1046,7 +1111,9 @@ var Swiper = (function () {
1046
1111
  swiper.emit('slidesGridLengthChange');
1047
1112
  }
1048
1113
  if (params.watchSlidesProgress) {
1049
- swiper.updateSlidesOffset();
1114
+ swiper.updateSlidesOffset({
1115
+ isCalculatedFromUpdateSlides: false
1116
+ });
1050
1117
  }
1051
1118
  swiper.emit('slidesUpdated');
1052
1119
  if (!params.cssMode && params.effect === 'slide') {
@@ -1091,14 +1158,20 @@ var Swiper = (function () {
1091
1158
  let newHeight = 0;
1092
1159
  for (let i = 0; i < activeSlides.length; i += 1) {
1093
1160
  if (typeof activeSlides[i] !== 'undefined') {
1094
- const height = activeSlides[i].offsetHeight;
1161
+ const height = activeSlides[i].swiperSlideHeight ?? activeSlides[i]['offsetHeight'];
1095
1162
  newHeight = height > newHeight ? height : newHeight;
1096
1163
  }
1097
1164
  }
1098
1165
  if (newHeight || newHeight === 0) swiper.wrapperEl.style.height = `${newHeight}px`;
1099
1166
  }
1100
1167
 
1101
- function updateSlidesOffset() {
1168
+ function updateSlidesOffset(params) {
1169
+ const {
1170
+ isCalculatedFromUpdateSlides = false
1171
+ } = params ?? {};
1172
+ if (isCalculatedFromUpdateSlides) {
1173
+ return;
1174
+ }
1102
1175
  const swiper = this;
1103
1176
  const slides = swiper.slides;
1104
1177
  // eslint-disable-next-line
@@ -2385,7 +2458,9 @@ var Swiper = (function () {
2385
2458
  swiper.updateSlides();
2386
2459
  }
2387
2460
  if (params.watchSlidesProgress) {
2388
- swiper.updateSlidesOffset();
2461
+ swiper.updateSlidesOffset({
2462
+ isCalculatedFromUpdateSlides: params.slidesPerView === 'auto'
2463
+ });
2389
2464
  }
2390
2465
  if (slideTo) {
2391
2466
  if (prependSlidesIndexes.length > 0 && isPrev) {
@@ -3950,7 +4025,8 @@ var Swiper = (function () {
3950
4025
  },
3951
4026
  // Images
3952
4027
  imagesToLoad: [],
3953
- imagesLoaded: 0
4028
+ imagesLoaded: 0,
4029
+ rtl: params?.rtl
3954
4030
  });
3955
4031
  swiper.emit('_swiper');
3956
4032
 
@@ -4212,15 +4288,18 @@ var Swiper = (function () {
4212
4288
  wrapperEl.append(slideEl);
4213
4289
  });
4214
4290
  }
4291
+ const rtl = swiper.params.rtl ?? (el.dir.toLowerCase() === 'rtl' || elementStyle(el, 'direction') === 'rtl');
4292
+ const wrongRTL = false;
4215
4293
  Object.assign(swiper, {
4216
4294
  el,
4217
4295
  wrapperEl,
4218
4296
  slidesEl: swiper.isElement && !el.parentNode.host.slideSlots ? el.parentNode.host : wrapperEl,
4219
4297
  hostEl: swiper.isElement ? el.parentNode.host : el,
4220
4298
  mounted: true,
4221
- rtl: el.dir.toLowerCase() === 'rtl' || elementStyle(el, 'direction') === 'rtl',
4222
- rtlTranslate: swiper.params.direction === 'horizontal' && (el.dir.toLowerCase() === 'rtl' || elementStyle(el, 'direction') === 'rtl'),
4223
- wrongRTL: elementStyle(wrapperEl, 'display') === '-webkit-box'
4299
+ // RTL
4300
+ rtl,
4301
+ rtlTranslate: swiper.params.direction === 'horizontal' && rtl,
4302
+ wrongRTL
4224
4303
  });
4225
4304
  return true;
4226
4305
  }
@@ -4300,7 +4379,8 @@ var Swiper = (function () {
4300
4379
  });
4301
4380
  preload(swiper);
4302
4381
  swiper.initialized = true;
4303
- preload(swiper);
4382
+
4383
+ // Emit
4304
4384
  swiper.emit('init');
4305
4385
  swiper.emit('afterInit');
4306
4386
  return swiper;
package/swiper.less 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
  *
package/swiper.min.css 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
  *