Merge branch 'main' into feature/#31_Show-pause-indicator
# Conflicts: # README.md # src/components/Carousel/Carousel.svelte # src/components/Dots/Dots.svelte # src/docs/Carousel.svx
This commit is contained in:
@@ -67,7 +67,7 @@
|
|||||||
let _duration = duration
|
let _duration = duration
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enables auto play of pages
|
* Enables autoplay of pages
|
||||||
*/
|
*/
|
||||||
export let autoplay = false
|
export let autoplay = false
|
||||||
|
|
||||||
@@ -101,21 +101,17 @@
|
|||||||
if (typeof pageIndex !== 'number') {
|
if (typeof pageIndex !== 'number') {
|
||||||
throw new Error('pageIndex should be a number')
|
throw new Error('pageIndex should be a number')
|
||||||
}
|
}
|
||||||
showPage(pageIndex + Number(infinite), { offsetDelayMs: 0, animated })
|
showPage(pageIndex + Number(infinite), { animated })
|
||||||
}
|
}
|
||||||
|
|
||||||
export function goToPrev(options) {
|
export function goToPrev(options) {
|
||||||
const animated = get(options, 'animated', true)
|
const animated = get(options, 'animated', true)
|
||||||
showPrevPage({
|
showPrevPage({ animated })
|
||||||
animated
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function goToNext(options) {
|
export function goToNext(options) {
|
||||||
const animated = get(options, 'animated', true)
|
const animated = get(options, 'animated', true)
|
||||||
showNextPage({
|
showNextPage({ animated })
|
||||||
animated
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let store = createStore()
|
let store = createStore()
|
||||||
@@ -173,7 +169,7 @@
|
|||||||
pagesElement.append(first.cloneNode(true))
|
pagesElement.append(first.cloneNode(true))
|
||||||
}
|
}
|
||||||
|
|
||||||
function applyAutoplay() {
|
function applyAutoplay(options) {
|
||||||
// prevent progress change if not infinite for first and last page
|
// prevent progress change if not infinite for first and last page
|
||||||
if (
|
if (
|
||||||
!infinite && (
|
!infinite && (
|
||||||
@@ -185,7 +181,14 @@
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (autoplay) {
|
if (autoplay) {
|
||||||
autoplayDirectionFnDescription[autoplayDirection]()
|
const delaysMs = get(options, 'delaysMs', 0)
|
||||||
|
if (delaysMs) {
|
||||||
|
setTimeout(() => {
|
||||||
|
autoplayDirectionFnDescription[autoplayDirection]()
|
||||||
|
}, delaysMs)
|
||||||
|
} else {
|
||||||
|
autoplayDirectionFnDescription[autoplayDirection]()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -220,19 +223,29 @@
|
|||||||
})
|
})
|
||||||
|
|
||||||
function handlePageChange(pageIndex) {
|
function handlePageChange(pageIndex) {
|
||||||
showPage(pageIndex + Number(infinite), { offsetDelayMs: 0, animated: true })
|
showPage(pageIndex + Number(infinite))
|
||||||
}
|
}
|
||||||
|
|
||||||
function offsetPage(animated) {
|
function offsetPage(animated) {
|
||||||
|
// _duration is an offset animation time
|
||||||
_duration = animated ? duration : 0
|
_duration = animated ? duration : 0
|
||||||
offset = -currentPageIndex * pageWidth
|
offset = -currentPageIndex * pageWidth
|
||||||
|
}
|
||||||
|
|
||||||
|
// makes delayed jump to 1st or last element
|
||||||
|
function jumpIfNeeded() {
|
||||||
|
let jumped = false
|
||||||
if (infinite) {
|
if (infinite) {
|
||||||
if (currentPageIndex === 0) {
|
if (currentPageIndex === 0) {
|
||||||
|
// offsetDelayMs should depend on _duration, as it wait when offset finishes
|
||||||
showPage(pagesCount - 2, { offsetDelayMs: _duration, animated: false })
|
showPage(pagesCount - 2, { offsetDelayMs: _duration, animated: false })
|
||||||
|
jumped = true
|
||||||
} else if (currentPageIndex === pagesCount - 1) {
|
} else if (currentPageIndex === pagesCount - 1) {
|
||||||
showPage(1, { offsetDelayMs: _duration, animated: false })
|
showPage(1, { offsetDelayMs: _duration, animated: false })
|
||||||
|
jumped = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return jumped
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disable page change while animation is in progress
|
// Disable page change while animation is in progress
|
||||||
@@ -244,7 +257,6 @@
|
|||||||
disabled = true
|
disabled = true
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
disabled = false
|
disabled = false
|
||||||
applyAutoplay()
|
|
||||||
}, animated ? duration : 0)
|
}, animated ? duration : 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -253,8 +265,11 @@
|
|||||||
const offsetDelayMs = get(options, 'offsetDelayMs', 0)
|
const offsetDelayMs = get(options, 'offsetDelayMs', 0)
|
||||||
safeChangePage(() => {
|
safeChangePage(() => {
|
||||||
store.moveToPage({ pageIndex, pagesCount })
|
store.moveToPage({ pageIndex, pagesCount })
|
||||||
|
// delayed page transition, used for infinite autoplay to jump to real page
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
offsetPage(animated)
|
offsetPage(animated)
|
||||||
|
const jumped = jumpIfNeeded()
|
||||||
|
!jumped && applyAutoplay({ delaysMs: _duration })
|
||||||
}, offsetDelayMs)
|
}, offsetDelayMs)
|
||||||
}, { animated })
|
}, { animated })
|
||||||
}
|
}
|
||||||
@@ -263,6 +278,8 @@
|
|||||||
safeChangePage(() => {
|
safeChangePage(() => {
|
||||||
store.prev({ infinite, pagesCount })
|
store.prev({ infinite, pagesCount })
|
||||||
offsetPage(animated)
|
offsetPage(animated)
|
||||||
|
const jumped = jumpIfNeeded()
|
||||||
|
!jumped && applyAutoplay({ delaysMs: _duration })
|
||||||
}, { animated })
|
}, { animated })
|
||||||
}
|
}
|
||||||
function showNextPage(options) {
|
function showNextPage(options) {
|
||||||
@@ -270,6 +287,8 @@
|
|||||||
safeChangePage(() => {
|
safeChangePage(() => {
|
||||||
store.next({ infinite, pagesCount })
|
store.next({ infinite, pagesCount })
|
||||||
offsetPage(animated)
|
offsetPage(animated)
|
||||||
|
const jumped = jumpIfNeeded()
|
||||||
|
!jumped && applyAutoplay({ delaysMs: _duration })
|
||||||
}, { animated })
|
}, { animated })
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -284,7 +303,7 @@
|
|||||||
offset += event.detail.dx
|
offset += event.detail.dx
|
||||||
}
|
}
|
||||||
function handleSwipeEnd() {
|
function handleSwipeEnd() {
|
||||||
showPage(currentPageIndex, { offsetDelayMs: 0, animated: true })
|
showPage(currentPageIndex)
|
||||||
}
|
}
|
||||||
function handleFocused(event) {
|
function handleFocused(event) {
|
||||||
focused = event.detail.value
|
focused = event.detail.value
|
||||||
@@ -362,10 +381,8 @@
|
|||||||
|
|
||||||
<style>
|
<style>
|
||||||
:root {
|
:root {
|
||||||
--sc-arrow-size: 2px;
|
|
||||||
|
|
||||||
--sc-color-rgb-light-50p: rgba(93, 93, 93, 0.5);
|
--sc-color-rgb-light-50p: rgba(93, 93, 93, 0.5);
|
||||||
|
--sc-color-rgb-light: #5d5d5d;
|
||||||
--sc-color-hex-dark-50p: rgba(30, 30, 30, 0.5);
|
--sc-color-hex-dark-50p: rgba(30, 30, 30, 0.5);
|
||||||
--sc-color-hex-dark: #1e1e1e;
|
--sc-color-hex-dark: #1e1e1e;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@
|
|||||||
export let duration = 500
|
export let duration = 500
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enables auto play of pages
|
* Enables autoplay of pages
|
||||||
*/
|
*/
|
||||||
export let autoplay = false
|
export let autoplay = false
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@
|
|||||||
export let duration = 500
|
export let duration = 500
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enables auto play of pages
|
* Enables autoplay of pages
|
||||||
*/
|
*/
|
||||||
export let autoplay = false
|
export let autoplay = false
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@
|
|||||||
export let duration = 500
|
export let duration = 500
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enables auto play of pages
|
* Enables autoplay of pages
|
||||||
*/
|
*/
|
||||||
export let autoplay = false
|
export let autoplay = false
|
||||||
|
|
||||||
|
|||||||
@@ -41,7 +41,7 @@
|
|||||||
width: 16px;
|
width: 16px;
|
||||||
}
|
}
|
||||||
.sc-carousel-dot__dot {
|
.sc-carousel-dot__dot {
|
||||||
background-color: #5d5d5d;
|
background-color: var(--sc-color-rgb-light);
|
||||||
border-radius: 50%;
|
border-radius: 50%;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
opacity: 0.5;
|
opacity: 0.5;
|
||||||
|
|||||||
@@ -43,7 +43,7 @@
|
|||||||
}
|
}
|
||||||
.sc-carousel-dots__dot-container {
|
.sc-carousel-dots__dot-container {
|
||||||
height: calc(var(--sc-dot-size) + 10px);
|
height: calc(var(--sc-dot-size) + 10px);
|
||||||
width: calc(var(--sc-dot-size) + 10x);
|
width: calc(var(--sc-dot-size) + 6px);
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
|
|||||||
Reference in New Issue
Block a user