Merge branch 'main' into feature/#69_Add-pages-to-show-pages-to-scroll
# Conflicts: # src/components/Carousel/Carousel.svelte # src/utils/page.js
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "svelte-carousel",
|
"name": "svelte-carousel",
|
||||||
"version": "1.0.14",
|
"version": "1.0.15-rc1",
|
||||||
"description": "Svelte carousel",
|
"description": "Svelte carousel",
|
||||||
"main": "src/main.js",
|
"main": "src/main.js",
|
||||||
"author": "vadimkorr",
|
"author": "vadimkorr",
|
||||||
|
|||||||
@@ -13,12 +13,12 @@
|
|||||||
removeResizeEventListener
|
removeResizeEventListener
|
||||||
} from '../../utils/event'
|
} from '../../utils/event'
|
||||||
import {
|
import {
|
||||||
getSizes,
|
|
||||||
applyParticleSizes,
|
applyParticleSizes,
|
||||||
getCurrentPageIndex,
|
getCurrentPageIndex,
|
||||||
getPartialPageSize,
|
getPartialPageSize,
|
||||||
getPagesCountByParticlesCount,
|
getPagesCountByParticlesCount,
|
||||||
getParticleIndexByPageIndex,
|
getParticleIndexByPageIndex,
|
||||||
|
createResizeObserver,
|
||||||
} from '../../utils/page'
|
} from '../../utils/page'
|
||||||
import {
|
import {
|
||||||
getClones,
|
getClones,
|
||||||
@@ -181,6 +181,22 @@
|
|||||||
let offset = 0
|
let offset = 0
|
||||||
let pageWindowElement
|
let pageWindowElement
|
||||||
let particlesContainer
|
let particlesContainer
|
||||||
|
|
||||||
|
const pageWindowElementResizeObserver = createResizeObserver(({
|
||||||
|
width,
|
||||||
|
}) => {
|
||||||
|
pageWindowWidth = width
|
||||||
|
particleWidth = pageWindowWidth / particlesToShow
|
||||||
|
|
||||||
|
applyParticleSizes({
|
||||||
|
particlesContainerChildren: particlesContainer.children,
|
||||||
|
particleWidth,
|
||||||
|
})
|
||||||
|
offsetPage({
|
||||||
|
animated: false,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
let focused = false
|
let focused = false
|
||||||
|
|
||||||
let progressValue
|
let progressValue
|
||||||
@@ -211,26 +227,6 @@
|
|||||||
particlesToScroll,
|
particlesToScroll,
|
||||||
}).particleIndexes
|
}).particleIndexes
|
||||||
|
|
||||||
function initPageSizes() {
|
|
||||||
const sizes = getSizes({
|
|
||||||
pageWindowElement,
|
|
||||||
particlesContainerChildren: particlesContainer.children,
|
|
||||||
particlesToShow,
|
|
||||||
})
|
|
||||||
applyParticleSizes({
|
|
||||||
particlesContainerChildren: particlesContainer.children,
|
|
||||||
particleWidth: sizes.particleWidth,
|
|
||||||
})
|
|
||||||
|
|
||||||
pageWindowWidth = sizes.pageWindowWidth
|
|
||||||
particleWidth = sizes.particleWidth
|
|
||||||
particlesCount = sizes.particlesCount
|
|
||||||
|
|
||||||
offsetPage({
|
|
||||||
animated: false,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
function addClones() {
|
function addClones() {
|
||||||
const {
|
const {
|
||||||
clonesToAppend,
|
clonesToAppend,
|
||||||
@@ -288,6 +284,7 @@
|
|||||||
|
|
||||||
await tick()
|
await tick()
|
||||||
infinite && addClones()
|
infinite && addClones()
|
||||||
|
particlesCount = particlesContainer.children.length
|
||||||
|
|
||||||
store.init(getParticleIndexByPageIndex({
|
store.init(getParticleIndexByPageIndex({
|
||||||
infinite,
|
infinite,
|
||||||
@@ -299,15 +296,13 @@
|
|||||||
particlesToShow,
|
particlesToShow,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
initPageSizes()
|
pageWindowElementResizeObserver.observe(pageWindowElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
addResizeEventListener(initPageSizes)
|
|
||||||
})()
|
})()
|
||||||
})
|
})
|
||||||
|
|
||||||
onDestroy(() => {
|
onDestroy(() => {
|
||||||
removeResizeEventListener(initPageSizes)
|
pageWindowElementResizeObserver.disconnect()
|
||||||
cleanupFns.filter(fn => fn && typeof fn === 'function').forEach(fn => fn())
|
cleanupFns.filter(fn => fn && typeof fn === 'function').forEach(fn => fn())
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,3 @@
|
|||||||
// resize event
|
|
||||||
export function addResizeEventListener(cb) {
|
|
||||||
window.addEventListener('resize', cb)
|
|
||||||
}
|
|
||||||
export function removeResizeEventListener(cb) {
|
|
||||||
window.removeEventListener('resize', cb)
|
|
||||||
}
|
|
||||||
|
|
||||||
export function createDispatcher(source) {
|
export function createDispatcher(source) {
|
||||||
return function (event, data) {
|
return function (event, data) {
|
||||||
source.dispatchEvent(
|
source.dispatchEvent(
|
||||||
|
|||||||
@@ -1,22 +1,6 @@
|
|||||||
import {
|
import {
|
||||||
getValueInRange,
|
getValueInRange,
|
||||||
} from './math'
|
} from './math'
|
||||||
|
|
||||||
export function getSizes({
|
|
||||||
pageWindowElement,
|
|
||||||
particlesContainerChildren,
|
|
||||||
particlesToShow,
|
|
||||||
}) {
|
|
||||||
const pageWindowWidth = pageWindowElement.clientWidth
|
|
||||||
const particleWidth = pageWindowWidth / particlesToShow
|
|
||||||
const particlesCount = particlesContainerChildren.length
|
|
||||||
|
|
||||||
return {
|
|
||||||
pageWindowWidth,
|
|
||||||
particleWidth,
|
|
||||||
particlesCount,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function applyParticleSizes({
|
export function applyParticleSizes({
|
||||||
particlesContainerChildren,
|
particlesContainerChildren,
|
||||||
@@ -122,3 +106,11 @@ export function getParticleIndexByPageIndex({
|
|||||||
particlesToShow,
|
particlesToShow,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function createResizeObserver(onResize) {
|
||||||
|
return new ResizeObserver(entries => {
|
||||||
|
onResize({
|
||||||
|
width: entries[0].contentRect.width,
|
||||||
|
})
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user