@bagelink/vue 1.6.7 → 1.6.9
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/dist/components/Swiper.vue.d.ts +2321 -1
- package/dist/components/Swiper.vue.d.ts.map +1 -1
- package/dist/index.cjs +20 -46
- package/dist/index.mjs +5828 -6983
- package/dist/style.css +1 -1
- package/package.json +1 -1
- package/src/components/Carousel.vue +43 -43
- package/src/components/Swiper.vue +79 -75
- package/vite.config.ts +1 -1
package/package.json
CHANGED
|
@@ -69,51 +69,51 @@ let velocityTracker = $ref<VelocitySample[]>([])
|
|
|
69
69
|
const VELOCITY_SAMPLE_DURATION = 100 // ms to track velocity
|
|
70
70
|
|
|
71
71
|
function getAverageVelocity(): number {
|
|
72
|
-
if (
|
|
72
|
+
if (velocityTracker.length < 2) { return 0 }
|
|
73
73
|
|
|
74
74
|
const now = Date.now()
|
|
75
75
|
// Only consider samples within our sample duration
|
|
76
76
|
const recentSamples = velocityTracker.filter((sample: VelocitySample) => now - sample.time < VELOCITY_SAMPLE_DURATION)
|
|
77
77
|
|
|
78
|
-
if (
|
|
78
|
+
if (recentSamples.length < 2) { return 0 }
|
|
79
79
|
|
|
80
80
|
const first = recentSamples[0]
|
|
81
81
|
const last = recentSamples[recentSamples.length - 1]
|
|
82
82
|
const timeDelta = last.time - first.time
|
|
83
83
|
|
|
84
|
-
if (
|
|
84
|
+
if (timeDelta === 0) { return 0 }
|
|
85
85
|
|
|
86
86
|
return (last.position - first.position) / timeDelta
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
// Transform helpers
|
|
90
90
|
function getCurrentTransform(): number {
|
|
91
|
-
if (!bglSlider) {return 0}
|
|
91
|
+
if (!bglSlider) { return 0 }
|
|
92
92
|
const { transform } = bglSlider.style
|
|
93
93
|
const value = transform ? Number.parseInt(transform.replace(/[^-\d.]/g, '')) : 0
|
|
94
94
|
return props.rtl ? -value : value
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
function setTransform(value: number) {
|
|
98
|
-
if (!bglSlider) {return}
|
|
98
|
+
if (!bglSlider) { return }
|
|
99
99
|
const rtlValue = props.rtl ? -value : value
|
|
100
100
|
bglSlider.style.transform = `translateX(${rtlValue}px)`
|
|
101
101
|
}
|
|
102
102
|
|
|
103
103
|
function easeInOutQuad(t: number) {
|
|
104
|
-
return 0.5
|
|
104
|
+
return t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
function animateTransform(start: number, end: number, duration: number) {
|
|
108
108
|
const startTime = performance.now()
|
|
109
109
|
|
|
110
110
|
function animate(currentTime: number) {
|
|
111
|
-
if (!isSliderAvailable) {return}
|
|
111
|
+
if (!isSliderAvailable) { return }
|
|
112
112
|
const timeElapsed = currentTime - startTime
|
|
113
113
|
const progress = Math.min(timeElapsed / duration, 1)
|
|
114
114
|
const currentTransform = start + (end - start) * easeInOutQuad(progress)
|
|
115
115
|
setTransform(currentTransform)
|
|
116
|
-
if (
|
|
116
|
+
if (progress < 1) { requestAnimationFrame(animate) }
|
|
117
117
|
}
|
|
118
118
|
|
|
119
119
|
requestAnimationFrame(animate)
|
|
@@ -122,7 +122,7 @@ function animateTransform(start: number, end: number, duration: number) {
|
|
|
122
122
|
// Navigation
|
|
123
123
|
function goToSlide(index: number, isTouchNav = false) {
|
|
124
124
|
countSlides()
|
|
125
|
-
if (!isSliderAvailable || !bglSlider ||
|
|
125
|
+
if (!isSliderAvailable || !bglSlider || index < 0 || index >= slideCount) { return }
|
|
126
126
|
|
|
127
127
|
const containerWidth = bglSlider.offsetWidth
|
|
128
128
|
const gapWidth = (containerWidth * GAP_PERCENT) / 100
|
|
@@ -136,7 +136,7 @@ function goToSlide(index: number, isTouchNav = false) {
|
|
|
136
136
|
const currentTransform = getCurrentTransform()
|
|
137
137
|
const duration = isTouchNav
|
|
138
138
|
? ANIMATION_TIMINGS.TOUCH
|
|
139
|
-
:
|
|
139
|
+
: window.innerWidth < 600
|
|
140
140
|
? ANIMATION_TIMINGS.MOBILE
|
|
141
141
|
: ANIMATION_TIMINGS.DESKTOP
|
|
142
142
|
|
|
@@ -146,7 +146,7 @@ function goToSlide(index: number, isTouchNav = false) {
|
|
|
146
146
|
}
|
|
147
147
|
|
|
148
148
|
function next() {
|
|
149
|
-
if (!isSliderAvailable) {return}
|
|
149
|
+
if (!isSliderAvailable) { return }
|
|
150
150
|
countSlides()
|
|
151
151
|
// In RTL, next and prev are reversed
|
|
152
152
|
const nextIndex = props.rtl
|
|
@@ -156,7 +156,7 @@ function next() {
|
|
|
156
156
|
}
|
|
157
157
|
|
|
158
158
|
function prev() {
|
|
159
|
-
if (!isSliderAvailable) {return}
|
|
159
|
+
if (!isSliderAvailable) { return }
|
|
160
160
|
countSlides()
|
|
161
161
|
// In RTL, next and prev are reversed
|
|
162
162
|
const prevIndex = props.rtl
|
|
@@ -167,10 +167,10 @@ function prev() {
|
|
|
167
167
|
|
|
168
168
|
// Height management
|
|
169
169
|
function calcHeight() {
|
|
170
|
-
if (!isSliderAvailable || !bglSlider) {return}
|
|
170
|
+
if (!isSliderAvailable || !bglSlider) { return }
|
|
171
171
|
try {
|
|
172
172
|
const activeSlide = bglSlider.children[activeSlideIndex]
|
|
173
|
-
if (!activeSlide) {return}
|
|
173
|
+
if (!activeSlide) { return }
|
|
174
174
|
const children = Array.from(activeSlide.children) as HTMLElement[]
|
|
175
175
|
const totalHeight = children.reduce((sum, el) => sum + el.clientHeight, 0)
|
|
176
176
|
yHeight = `${totalHeight}px`
|
|
@@ -180,13 +180,13 @@ function calcHeight() {
|
|
|
180
180
|
}
|
|
181
181
|
|
|
182
182
|
function updateHeight() {
|
|
183
|
-
if (!props.autoHeight) {return}
|
|
183
|
+
if (!props.autoHeight) { return }
|
|
184
184
|
setTimeout(calcHeight, 200)
|
|
185
185
|
}
|
|
186
186
|
|
|
187
187
|
// Slide management
|
|
188
188
|
function countSlides() {
|
|
189
|
-
if (!isSliderAvailable || !bglSlider) {return}
|
|
189
|
+
if (!isSliderAvailable || !bglSlider) { return }
|
|
190
190
|
slideCount = bglSlider.children.length
|
|
191
191
|
}
|
|
192
192
|
|
|
@@ -198,10 +198,10 @@ function handleSlideChange() {
|
|
|
198
198
|
}
|
|
199
199
|
|
|
200
200
|
function handleResize() {
|
|
201
|
-
if (!isSliderAvailable || !bglSlider) {return}
|
|
202
|
-
itemCount =
|
|
201
|
+
if (!isSliderAvailable || !bglSlider) { return }
|
|
202
|
+
itemCount = window.innerWidth < 600
|
|
203
203
|
? 1
|
|
204
|
-
:
|
|
204
|
+
: window.innerWidth < 991
|
|
205
205
|
? Math.min(props.items, 2)
|
|
206
206
|
: props.items
|
|
207
207
|
|
|
@@ -217,7 +217,7 @@ function handleResize() {
|
|
|
217
217
|
}
|
|
218
218
|
|
|
219
219
|
function clearAutoplay() {
|
|
220
|
-
if (autoPlayInterval) {clearInterval(autoPlayInterval)}
|
|
220
|
+
if (autoPlayInterval) { clearInterval(autoPlayInterval) }
|
|
221
221
|
}
|
|
222
222
|
|
|
223
223
|
// Mouse events
|
|
@@ -230,7 +230,7 @@ function preventDefaultClick(e: MouseEvent) {
|
|
|
230
230
|
|
|
231
231
|
async function disableDrag() {
|
|
232
232
|
await nextTick()
|
|
233
|
-
if (!isSliderAvailable || !bglSlider) {return}
|
|
233
|
+
if (!isSliderAvailable || !bglSlider) { return }
|
|
234
234
|
|
|
235
235
|
const elements = Array.from(bglSlider.querySelectorAll('img, a')) as HTMLElement[]
|
|
236
236
|
elements.forEach((el) => {
|
|
@@ -252,7 +252,7 @@ async function disableDrag() {
|
|
|
252
252
|
|
|
253
253
|
function startDrag(e: MouseEvent) {
|
|
254
254
|
e.stopPropagation()
|
|
255
|
-
if (
|
|
255
|
+
if (e.button !== 0 || !props.freeDrag || !isSliderAvailable) { return }
|
|
256
256
|
|
|
257
257
|
clearAutoplay()
|
|
258
258
|
startX = e.pageX
|
|
@@ -265,12 +265,12 @@ function startDrag(e: MouseEvent) {
|
|
|
265
265
|
}
|
|
266
266
|
|
|
267
267
|
function onDrag(e: MouseEvent) {
|
|
268
|
-
if (!isSliderAvailable || !bglSlider || !isPressed) {return}
|
|
268
|
+
if (!isSliderAvailable || !bglSlider || !isPressed) { return }
|
|
269
269
|
|
|
270
270
|
const x = e.pageX
|
|
271
271
|
const distance = x - startX
|
|
272
272
|
|
|
273
|
-
if (Math.abs(distance) > THRESHOLDS.DRAG) {isDragging = true}
|
|
273
|
+
if (Math.abs(distance) > THRESHOLDS.DRAG) { isDragging = true }
|
|
274
274
|
if (isDragging) {
|
|
275
275
|
const newTranslate = translateX + (props.rtl ? -distance : distance)
|
|
276
276
|
const maxTranslate = 0
|
|
@@ -291,7 +291,7 @@ function endDrag() {
|
|
|
291
291
|
document.removeEventListener('mousemove', onDrag)
|
|
292
292
|
document.removeEventListener('mouseup', endDrag)
|
|
293
293
|
|
|
294
|
-
if (!isSliderAvailable || !bglSlider) {return}
|
|
294
|
+
if (!isSliderAvailable || !bglSlider) { return }
|
|
295
295
|
|
|
296
296
|
const currentTransform = getCurrentTransform()
|
|
297
297
|
const singleItemWidth = bglSlider.offsetWidth / itemCount
|
|
@@ -302,8 +302,8 @@ function endDrag() {
|
|
|
302
302
|
|
|
303
303
|
let targetPanel = currentPanel
|
|
304
304
|
if (dragPercentage > THRESHOLDS.SWIPE_PERCENT) {
|
|
305
|
-
const distnace =
|
|
306
|
-
targetPanel = Math.floor(currentPanel) + (
|
|
305
|
+
const distnace = totalDragDistance > 0 ? -1 : 1
|
|
306
|
+
targetPanel = Math.floor(currentPanel) + (distnace < 0 ? 0 : 1)
|
|
307
307
|
} else {
|
|
308
308
|
targetPanel = Math.round(currentPanel)
|
|
309
309
|
}
|
|
@@ -324,7 +324,7 @@ let hasScrollDirectionLock = $ref(false)
|
|
|
324
324
|
let isHorizontalScroll = $ref(false)
|
|
325
325
|
|
|
326
326
|
function onTouchStart(e: TouchEvent) {
|
|
327
|
-
if (!props.freeDrag || !isSliderAvailable) {return}
|
|
327
|
+
if (!props.freeDrag || !isSliderAvailable) { return }
|
|
328
328
|
|
|
329
329
|
const target = e.target as HTMLElement
|
|
330
330
|
const isInteractive = target.matches('button, a, input, select, textarea, [role="button"]')
|
|
@@ -351,7 +351,7 @@ function onTouchStart(e: TouchEvent) {
|
|
|
351
351
|
}
|
|
352
352
|
|
|
353
353
|
function onTouchMove(e: TouchEvent) {
|
|
354
|
-
if (!isSliderAvailable || !bglSlider || !isPressed) {return}
|
|
354
|
+
if (!isSliderAvailable || !bglSlider || !isPressed) { return }
|
|
355
355
|
|
|
356
356
|
const touch = e.touches[0]
|
|
357
357
|
const x = touch.pageX
|
|
@@ -362,7 +362,7 @@ function onTouchMove(e: TouchEvent) {
|
|
|
362
362
|
// Determine scroll direction if we haven't already
|
|
363
363
|
if (!hasScrollDirectionLock) {
|
|
364
364
|
// Only lock in a direction if there's significant movement
|
|
365
|
-
if (
|
|
365
|
+
if (Math.abs(deltaX) > 5 || Math.abs(deltaY) > 5) {
|
|
366
366
|
isHorizontalScroll = Math.abs(deltaX) > Math.abs(deltaY)
|
|
367
367
|
hasScrollDirectionLock = true
|
|
368
368
|
|
|
@@ -377,7 +377,7 @@ function onTouchMove(e: TouchEvent) {
|
|
|
377
377
|
}
|
|
378
378
|
|
|
379
379
|
// If we've determined this is a vertical scroll, don't handle the touch
|
|
380
|
-
if (!isHorizontalScroll) {return}
|
|
380
|
+
if (!isHorizontalScroll) { return }
|
|
381
381
|
|
|
382
382
|
// Update velocity tracking
|
|
383
383
|
const now = Date.now()
|
|
@@ -404,7 +404,7 @@ function onTouchMove(e: TouchEvent) {
|
|
|
404
404
|
let newTranslate = translateX + (props.rtl ? -deltaX : deltaX)
|
|
405
405
|
|
|
406
406
|
// Add smooth resistance when pulling beyond bounds
|
|
407
|
-
if (
|
|
407
|
+
if (newTranslate > 0) {
|
|
408
408
|
newTranslate *= 0.5 // Softer resistance at start
|
|
409
409
|
} else if (newTranslate < -totalWidth + containerWidth) {
|
|
410
410
|
const overDrag = -totalWidth + containerWidth - newTranslate
|
|
@@ -433,7 +433,7 @@ function onTouchEnd() {
|
|
|
433
433
|
|
|
434
434
|
// Normalize the transform value to handle overscroll
|
|
435
435
|
let normalizedTransform = currentTransform
|
|
436
|
-
if (
|
|
436
|
+
if (currentTransform > 0) {
|
|
437
437
|
normalizedTransform = 0
|
|
438
438
|
} else {
|
|
439
439
|
const minTransform = -(singleItemWidth * (slideCount - 1) + gapWidth * (slideCount - 1))
|
|
@@ -455,14 +455,14 @@ function onTouchEnd() {
|
|
|
455
455
|
|
|
456
456
|
// Determine direction based on velocity and distance
|
|
457
457
|
if (Math.abs(finalVelocity) > THRESHOLDS.VELOCITY) {
|
|
458
|
-
velocityDirection =
|
|
458
|
+
velocityDirection = finalVelocity < 0 ? 1 : -1
|
|
459
459
|
}
|
|
460
460
|
|
|
461
|
-
const isMobile =
|
|
461
|
+
const isMobile = window.innerWidth < 600
|
|
462
462
|
|
|
463
463
|
if (swipePercentage > THRESHOLDS.SWIPE_PERCENT || Math.abs(finalVelocity) > THRESHOLDS.VELOCITY) {
|
|
464
464
|
const direction = swipePercentage > THRESHOLDS.SWIPE_PERCENT
|
|
465
|
-
? (
|
|
465
|
+
? (totalSwipeDistance > 0 ? -1 : 1)
|
|
466
466
|
: velocityDirection
|
|
467
467
|
|
|
468
468
|
// Apply RTL correction to direction
|
|
@@ -500,7 +500,7 @@ function onTouchEnd() {
|
|
|
500
500
|
|
|
501
501
|
// Clear transition after animation
|
|
502
502
|
setTimeout(() => {
|
|
503
|
-
if (bglSlider) {bglSlider.style.transition = 'none'}
|
|
503
|
+
if (bglSlider) { bglSlider.style.transition = 'none' }
|
|
504
504
|
}, duration)
|
|
505
505
|
|
|
506
506
|
velocityTracker = []
|
|
@@ -510,13 +510,13 @@ function onTouchEnd() {
|
|
|
510
510
|
|
|
511
511
|
// Wheel events
|
|
512
512
|
function onWheel(e: WheelEvent) {
|
|
513
|
-
if (!props.allowScroll || !isSliderAvailable || !bglSlider || isPressed || isDragging) {return}
|
|
513
|
+
if (!props.allowScroll || !isSliderAvailable || !bglSlider || isPressed || isDragging) { return }
|
|
514
514
|
|
|
515
515
|
const isHorizontal = Math.abs(e.deltaX) > Math.abs(e.deltaY)
|
|
516
|
-
if (!isHorizontal) {return}
|
|
516
|
+
if (!isHorizontal) { return }
|
|
517
517
|
|
|
518
518
|
clearAutoplay()
|
|
519
|
-
if (wheelTimeout) {clearTimeout(wheelTimeout)}
|
|
519
|
+
if (wheelTimeout) { clearTimeout(wheelTimeout) }
|
|
520
520
|
|
|
521
521
|
// Reverse the delta direction for RTL mode
|
|
522
522
|
accumulatedDeltaX += props.rtl ? -e.deltaX : e.deltaX
|
|
@@ -529,7 +529,7 @@ function onWheel(e: WheelEvent) {
|
|
|
529
529
|
const moveThreshold = singleItemWidth * THRESHOLDS.WHEEL_PERCENT
|
|
530
530
|
|
|
531
531
|
if (Math.abs(accumulatedDeltaX) > moveThreshold) {
|
|
532
|
-
const direction =
|
|
532
|
+
const direction = accumulatedDeltaX > 0 ? 1 : -1
|
|
533
533
|
const nextPanel = Math.max(0, Math.min(activeSlideIndex + direction, slideCount - 1))
|
|
534
534
|
|
|
535
535
|
if (nextPanel !== activeSlideIndex) {
|
|
@@ -567,8 +567,8 @@ onUnmounted(() => {
|
|
|
567
567
|
document.removeEventListener('mousemove', onDrag)
|
|
568
568
|
document.removeEventListener('mouseup', endDrag)
|
|
569
569
|
clearAutoplay()
|
|
570
|
-
if (timeout) {clearTimeout(timeout)}
|
|
571
|
-
if (wheelTimeout) {clearTimeout(wheelTimeout)}
|
|
570
|
+
if (timeout) { clearTimeout(timeout) }
|
|
571
|
+
if (wheelTimeout) { clearTimeout(wheelTimeout) }
|
|
572
572
|
})
|
|
573
573
|
|
|
574
574
|
// Watchers
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
<script setup lang="ts" generic="T = any">
|
|
2
|
-
import type {
|
|
2
|
+
import type { Swiper as SwiperType } from 'swiper'
|
|
3
3
|
import type { AutoplayOptions, CoverflowEffectOptions, PaginationOptions, SwiperOptions } from 'swiper/types'
|
|
4
4
|
import { Icon } from '@bagelink/vue'
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { Autoplay, EffectCoverflow, EffectCube, EffectFade, EffectFlip, Navigation, Pagination } from 'swiper/modules'
|
|
6
|
+
import { Swiper, SwiperSlide } from 'swiper/vue'
|
|
7
|
+
import { computed, ref, watch } from 'vue'
|
|
7
8
|
import 'swiper/css'
|
|
8
9
|
import 'swiper/css/navigation'
|
|
9
10
|
import 'swiper/css/pagination'
|
|
@@ -178,15 +179,13 @@ const variantPresets: Record<SwiperVariant, VariantConfig> = {
|
|
|
178
179
|
},
|
|
179
180
|
}
|
|
180
181
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
const swiperEl = $ref<SwiperContainer | null>(null)
|
|
182
|
+
const swiperEl = ref<SwiperType | null>(null)
|
|
184
183
|
const isFirstSlide = ref(true)
|
|
185
184
|
const isLastSlide = ref(false)
|
|
186
185
|
const currentIndex = ref(props.index ?? props.initialSlide ?? 0)
|
|
187
186
|
let isUpdatingFromExternal = false // Guard to prevent update loops
|
|
188
187
|
|
|
189
|
-
const slideStyles =
|
|
188
|
+
const slideStyles = computed(() => {
|
|
190
189
|
const styles: Record<string, string> = {}
|
|
191
190
|
|
|
192
191
|
if (props.slideWidth !== undefined) {
|
|
@@ -197,18 +196,18 @@ const slideStyles = $computed(() => {
|
|
|
197
196
|
})
|
|
198
197
|
|
|
199
198
|
// Apply variant preset configuration
|
|
200
|
-
const variantConfig =
|
|
199
|
+
const variantConfig = computed(() => variantPresets[props.variant])
|
|
201
200
|
|
|
202
201
|
// Smart default: if slideWidth is set and slidesPerView wasn't set,
|
|
203
202
|
// automatically use 'auto' to let slides determine their own width
|
|
204
|
-
const effectiveSlidesPerView =
|
|
203
|
+
const effectiveSlidesPerView = computed(() => {
|
|
205
204
|
// Priority: explicit prop > variant config > smart default
|
|
206
205
|
if (props.slidesPerView !== undefined) {
|
|
207
206
|
return props.slidesPerView
|
|
208
207
|
}
|
|
209
208
|
|
|
210
|
-
if (variantConfig.slidesPerView !== undefined) {
|
|
211
|
-
return variantConfig.slidesPerView
|
|
209
|
+
if (variantConfig.value.slidesPerView !== undefined) {
|
|
210
|
+
return variantConfig.value.slidesPerView
|
|
212
211
|
}
|
|
213
212
|
|
|
214
213
|
// Smart default: if slideWidth is provided, use 'auto'
|
|
@@ -228,46 +227,41 @@ const swiperParams = computed((): SwiperOptions => {
|
|
|
228
227
|
defaultValue: any
|
|
229
228
|
) => {
|
|
230
229
|
if (propValue !== undefined) return propValue
|
|
231
|
-
if (variantConfig[variantKey] !== undefined) return variantConfig[variantKey]
|
|
230
|
+
if (variantConfig.value[variantKey] !== undefined) return variantConfig.value[variantKey]
|
|
232
231
|
return defaultValue
|
|
233
232
|
}
|
|
234
233
|
|
|
235
234
|
const params: SwiperOptions = {
|
|
235
|
+
modules: [Navigation, Pagination, Autoplay, EffectFade, EffectCoverflow, EffectCube, EffectFlip],
|
|
236
236
|
effect: getValue(props.effect, 'effect', 'slide'),
|
|
237
237
|
direction: props.direction ?? 'horizontal',
|
|
238
238
|
speed: getValue(props.speed, 'speed', 300),
|
|
239
239
|
loop: getValue(props.loop, 'loop', false),
|
|
240
240
|
initialSlide: props.index ?? props.initialSlide,
|
|
241
|
-
slidesPerView: effectiveSlidesPerView,
|
|
241
|
+
slidesPerView: effectiveSlidesPerView.value,
|
|
242
242
|
spaceBetween: getValue(props.spaceBetween, 'spaceBetween', 0),
|
|
243
243
|
centeredSlides: getValue(props.centeredSlides, 'centeredSlides', false),
|
|
244
244
|
grabCursor: props.grabCursor,
|
|
245
|
-
keyboard: props.keyboard
|
|
246
|
-
mousewheel: props.mousewheel
|
|
245
|
+
keyboard: props.keyboard,
|
|
246
|
+
mousewheel: props.mousewheel,
|
|
247
247
|
autoHeight: props.autoHeight,
|
|
248
248
|
}
|
|
249
249
|
|
|
250
250
|
// Navigation (priority: prop > variant > default)
|
|
251
251
|
const navigationEnabled = getValue(props.navigation, 'navigation', false)
|
|
252
|
-
|
|
253
|
-
params.navigation = true
|
|
254
|
-
}
|
|
252
|
+
params.navigation = !!navigationEnabled
|
|
255
253
|
|
|
256
254
|
// Pagination (priority: prop > variant > default)
|
|
257
255
|
const paginationConfig = getValue(props.pagination, 'pagination', false)
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
: paginationConfig
|
|
262
|
-
}
|
|
256
|
+
params.pagination = paginationConfig
|
|
257
|
+
? (typeof paginationConfig === 'boolean' ? { clickable: true } : paginationConfig)
|
|
258
|
+
: false
|
|
263
259
|
|
|
264
260
|
// Autoplay (priority: prop > variant > default)
|
|
265
261
|
const autoplayConfig = getValue(props.autoplay, 'autoplay', false)
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
: autoplayConfig
|
|
270
|
-
}
|
|
262
|
+
params.autoplay = autoplayConfig
|
|
263
|
+
? (typeof autoplayConfig === 'boolean' ? { delay: 3000 } : autoplayConfig)
|
|
264
|
+
: false
|
|
271
265
|
|
|
272
266
|
// Effect-specific options (merge variant and explicit)
|
|
273
267
|
const effectType = params.effect || 'slide'
|
|
@@ -281,7 +275,7 @@ const swiperParams = computed((): SwiperOptions => {
|
|
|
281
275
|
}
|
|
282
276
|
params.coverflowEffect = {
|
|
283
277
|
...baseCoverflowEffect,
|
|
284
|
-
...variantConfig.coverflowEffect,
|
|
278
|
+
...variantConfig.value.coverflowEffect,
|
|
285
279
|
...props.coverflowEffect,
|
|
286
280
|
}
|
|
287
281
|
}
|
|
@@ -300,16 +294,38 @@ const swiperParams = computed((): SwiperOptions => {
|
|
|
300
294
|
return params
|
|
301
295
|
})
|
|
302
296
|
|
|
303
|
-
|
|
297
|
+
// Format params for Swiper Vue component with proper types
|
|
298
|
+
const swiperVueProps = computed(() => ({
|
|
299
|
+
modules: swiperParams.value.modules,
|
|
300
|
+
effect: swiperParams.value.effect as 'slide' | 'fade' | 'cube' | 'coverflow' | 'flip',
|
|
301
|
+
direction: swiperParams.value.direction,
|
|
302
|
+
speed: swiperParams.value.speed,
|
|
303
|
+
loop: swiperParams.value.loop,
|
|
304
|
+
initialSlide: swiperParams.value.initialSlide,
|
|
305
|
+
slidesPerView: swiperParams.value.slidesPerView,
|
|
306
|
+
spaceBetween: swiperParams.value.spaceBetween as number,
|
|
307
|
+
centeredSlides: swiperParams.value.centeredSlides,
|
|
308
|
+
grabCursor: swiperParams.value.grabCursor,
|
|
309
|
+
keyboard: swiperParams.value.keyboard as boolean | undefined,
|
|
310
|
+
mousewheel: swiperParams.value.mousewheel as boolean | undefined,
|
|
311
|
+
autoHeight: swiperParams.value.autoHeight,
|
|
312
|
+
navigation: swiperParams.value.navigation as boolean | undefined,
|
|
313
|
+
pagination: swiperParams.value.pagination,
|
|
314
|
+
autoplay: swiperParams.value.autoplay,
|
|
315
|
+
coverflowEffect: swiperParams.value.coverflowEffect,
|
|
316
|
+
breakpoints: swiperParams.value.breakpoints,
|
|
317
|
+
}))
|
|
318
|
+
|
|
319
|
+
const swiperInstance = computed(() => swiperEl.value)
|
|
304
320
|
|
|
305
321
|
function updateNavigationState() {
|
|
306
|
-
if (swiperEl
|
|
307
|
-
isFirstSlide.value = swiperEl.
|
|
308
|
-
isLastSlide.value = swiperEl.
|
|
322
|
+
if (swiperEl.value && !isUpdatingFromExternal) {
|
|
323
|
+
isFirstSlide.value = swiperEl.value.isBeginning
|
|
324
|
+
isLastSlide.value = swiperEl.value.isEnd
|
|
309
325
|
|
|
310
326
|
// Emit index update for v-model support
|
|
311
327
|
// Use activeIndex for non-loop mode, realIndex for loop mode
|
|
312
|
-
const newIndex = props.loop ? swiperEl.
|
|
328
|
+
const newIndex = props.loop ? swiperEl.value.realIndex : swiperEl.value.activeIndex
|
|
313
329
|
currentIndex.value = newIndex
|
|
314
330
|
|
|
315
331
|
// Emit to keep external state in sync
|
|
@@ -318,46 +334,32 @@ function updateNavigationState() {
|
|
|
318
334
|
}
|
|
319
335
|
|
|
320
336
|
function slideTo(index: number) {
|
|
321
|
-
if (!swiperEl
|
|
322
|
-
swiperEl.
|
|
337
|
+
if (!swiperEl.value) return
|
|
338
|
+
swiperEl.value.slideTo(index)
|
|
323
339
|
}
|
|
324
340
|
|
|
325
341
|
function handleSlideNav(dir: 'prev' | 'next') {
|
|
326
|
-
if (!swiperEl
|
|
342
|
+
if (!swiperEl.value) return
|
|
327
343
|
|
|
328
344
|
if (dir === 'next') {
|
|
329
|
-
swiperEl.
|
|
345
|
+
swiperEl.value.slideNext()
|
|
330
346
|
} else {
|
|
331
|
-
swiperEl.
|
|
347
|
+
swiperEl.value.slidePrev()
|
|
332
348
|
}
|
|
333
349
|
}
|
|
334
350
|
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
const params = {
|
|
340
|
-
...swiperParams.value,
|
|
341
|
-
on: {
|
|
342
|
-
...swiperParams.value.on,
|
|
343
|
-
init: updateNavigationState,
|
|
344
|
-
slideChange: updateNavigationState,
|
|
345
|
-
slideChangeTransitionEnd: updateNavigationState,
|
|
346
|
-
reachBeginning: updateNavigationState,
|
|
347
|
-
reachEnd: updateNavigationState,
|
|
348
|
-
fromEdge: updateNavigationState,
|
|
349
|
-
},
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
Object.assign(swiperEl, params)
|
|
353
|
-
swiperEl.initialize()
|
|
354
|
-
})
|
|
351
|
+
function onSwiper(swiper: SwiperType) {
|
|
352
|
+
swiperEl.value = swiper
|
|
353
|
+
updateNavigationState()
|
|
354
|
+
}
|
|
355
355
|
|
|
356
356
|
watch(
|
|
357
357
|
() => props.initialSlide,
|
|
358
358
|
(index) => {
|
|
359
|
-
if (index !== undefined && swiperEl
|
|
360
|
-
setTimeout(() =>
|
|
359
|
+
if (index !== undefined && swiperEl.value) {
|
|
360
|
+
setTimeout(() => {
|
|
361
|
+
if (swiperEl.value) swiperEl.value.slideTo(index)
|
|
362
|
+
}, 1)
|
|
361
363
|
}
|
|
362
364
|
},
|
|
363
365
|
{ immediate: true },
|
|
@@ -370,11 +372,11 @@ watch(
|
|
|
370
372
|
if (newIndex !== undefined) {
|
|
371
373
|
currentIndex.value = newIndex
|
|
372
374
|
|
|
373
|
-
if (swiperEl
|
|
374
|
-
const activeIndex = props.loop ? swiperEl.
|
|
375
|
+
if (swiperEl.value) {
|
|
376
|
+
const activeIndex = props.loop ? swiperEl.value.realIndex : swiperEl.value.activeIndex
|
|
375
377
|
if (newIndex !== activeIndex) {
|
|
376
378
|
isUpdatingFromExternal = true
|
|
377
|
-
swiperEl.
|
|
379
|
+
swiperEl.value.slideTo(newIndex)
|
|
378
380
|
// Reset guard after a short delay to allow transition
|
|
379
381
|
setTimeout(() => {
|
|
380
382
|
isUpdatingFromExternal = false
|
|
@@ -389,9 +391,9 @@ watch(
|
|
|
389
391
|
watch(
|
|
390
392
|
swiperParams,
|
|
391
393
|
(newParams) => {
|
|
392
|
-
if (swiperEl
|
|
393
|
-
Object.assign(swiperEl.
|
|
394
|
-
swiperEl.
|
|
394
|
+
if (swiperEl.value) {
|
|
395
|
+
Object.assign(swiperEl.value.params, newParams)
|
|
396
|
+
swiperEl.value.update()
|
|
395
397
|
}
|
|
396
398
|
},
|
|
397
399
|
{ deep: true },
|
|
@@ -402,7 +404,7 @@ defineExpose({
|
|
|
402
404
|
slideNext: () => { handleSlideNav('next') },
|
|
403
405
|
slidePrev: () => { handleSlideNav('prev') },
|
|
404
406
|
slideTo,
|
|
405
|
-
update: () => swiperEl?.
|
|
407
|
+
update: () => swiperEl.value?.update(),
|
|
406
408
|
isFirst: isFirstSlide,
|
|
407
409
|
isLast: isLastSlide,
|
|
408
410
|
currentIndex,
|
|
@@ -411,11 +413,15 @@ defineExpose({
|
|
|
411
413
|
|
|
412
414
|
<template>
|
|
413
415
|
<div class="swi-wrap">
|
|
414
|
-
<
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
416
|
+
<Swiper
|
|
417
|
+
v-bind="swiperVueProps" class="swiper" @swiper="onSwiper" @slide-change="updateNavigationState"
|
|
418
|
+
@reach-beginning="updateNavigationState" @reach-end="updateNavigationState"
|
|
419
|
+
@from-edge="updateNavigationState"
|
|
420
|
+
>
|
|
421
|
+
<SwiperSlide v-for="(item, idx) in items" :key="idx" :style="slideStyles">
|
|
422
|
+
<slot :item="item" :index="idx" :currentIndex="currentIndex" />
|
|
423
|
+
</SwiperSlide>
|
|
424
|
+
</Swiper>
|
|
419
425
|
|
|
420
426
|
<!-- Custom Navigation Slot -->
|
|
421
427
|
<slot
|
|
@@ -446,8 +452,6 @@ defineExpose({
|
|
|
446
452
|
<style>
|
|
447
453
|
.swiper {
|
|
448
454
|
width: 100%;
|
|
449
|
-
padding-top: 50px;
|
|
450
|
-
padding-bottom: 50px;
|
|
451
455
|
}
|
|
452
456
|
|
|
453
457
|
:root {
|
package/vite.config.ts
CHANGED
|
@@ -28,7 +28,7 @@ export default defineConfig(() => ({
|
|
|
28
28
|
lib: {
|
|
29
29
|
entry: resolve(indexDir, 'index.ts'),
|
|
30
30
|
formats: ['es', 'cjs'],
|
|
31
|
-
fileName: (module, entry) => `${entry}.${ 'es'
|
|
31
|
+
fileName: (module, entry) => `${entry}.${module === 'es' ? 'mjs' : module}`,
|
|
32
32
|
cssFileName: 'style',
|
|
33
33
|
},
|
|
34
34
|
rollupOptions: {
|