astro-swiper 2.3.0 → 2.4.0
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astro-swiper",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0",
|
|
4
4
|
"description": "Astro component for swiper, dedicated to slider / carousel / photo swiper / slide, including thumbnails",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
|
@@ -35,9 +35,9 @@
|
|
|
35
35
|
},
|
|
36
36
|
"packageManager": "pnpm@10.30.3",
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@biomejs/biome": "^2.4.
|
|
39
|
-
"@types/node": "^24.
|
|
40
|
-
"astro": "^5.18.
|
|
38
|
+
"@biomejs/biome": "^2.4.9",
|
|
39
|
+
"@types/node": "^24.12.0",
|
|
40
|
+
"astro": "^5.18.1",
|
|
41
41
|
"prettier": "^3.8.1",
|
|
42
42
|
"prettier-plugin-astro": "^0.14.1",
|
|
43
43
|
"typescript": "^5.9.3"
|
|
@@ -58,6 +58,6 @@
|
|
|
58
58
|
"thumbnail"
|
|
59
59
|
],
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"swiper": "^12.1.
|
|
61
|
+
"swiper": "^12.1.3"
|
|
62
62
|
}
|
|
63
63
|
}
|
|
@@ -69,12 +69,16 @@ const {
|
|
|
69
69
|
delete _useDelaySwiper[delayedClass]; // remove it from the delayed list
|
|
70
70
|
const delayedOptions = _useOptions[delayedClass];
|
|
71
71
|
delayedOptions.thumbs = {
|
|
72
|
-
swiper: _useSwiper[delayedThumbClass],
|
|
72
|
+
swiper: _useSwiper[delayedThumbClass], // add the thumbnail swiper link to the options
|
|
73
73
|
...delayedOptions.thumbs,
|
|
74
74
|
};
|
|
75
75
|
|
|
76
|
-
_createSwiperAndObserver(
|
|
77
|
-
|
|
76
|
+
_createSwiperAndObserver(
|
|
77
|
+
delayedClass,
|
|
78
|
+
delayedOptions,
|
|
79
|
+
document.querySelector(`.${delayedClass}`) as AstroSwiper,
|
|
80
|
+
);
|
|
81
|
+
_useOptions[delayedClass] = delayedOptions; // update the options with the thumbnail link
|
|
78
82
|
}
|
|
79
83
|
});
|
|
80
84
|
}
|
|
@@ -97,42 +101,43 @@ const {
|
|
|
97
101
|
|
|
98
102
|
function _createObserver(uniqueClass: string, options: AstroSwiperOptions, element: AstroSwiper) {
|
|
99
103
|
const observerOptions = options.astro?.intersectionObserver || {};
|
|
100
|
-
const observer = new IntersectionObserver(
|
|
101
|
-
(entries)
|
|
102
|
-
if (
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
observer.disconnect();
|
|
107
|
-
}
|
|
104
|
+
const observer = new IntersectionObserver((entries) => {
|
|
105
|
+
if (entries[0].isIntersecting) {
|
|
106
|
+
if (observerOptions?.initSwiper && !element.astroSwiper) {
|
|
107
|
+
_initSwiper(uniqueClass, options, element);
|
|
108
|
+
if (observerOptions?.disconnectOnInit) {
|
|
109
|
+
observer.disconnect();
|
|
108
110
|
}
|
|
109
111
|
}
|
|
112
|
+
}
|
|
110
113
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
114
|
+
const swiper = element?.astroSwiper;
|
|
115
|
+
if (!swiper) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
115
118
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}
|
|
119
|
+
if (observerOptions?.controlAutoplay && options.autoplay) {
|
|
120
|
+
if (entries[0].isIntersecting) {
|
|
121
|
+
swiper.autoplay.start();
|
|
122
|
+
} else {
|
|
123
|
+
swiper.autoplay.stop();
|
|
122
124
|
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
);
|
|
125
|
+
}
|
|
126
|
+
}, observerOptions.options);
|
|
126
127
|
|
|
127
128
|
observer.observe(element);
|
|
128
|
-
window.addEventListener(
|
|
129
|
+
window.addEventListener('unload', observer.disconnect);
|
|
129
130
|
}
|
|
130
131
|
|
|
131
132
|
// create the swiper and the observer
|
|
132
133
|
// - init the swiper if it should not be done by the observer
|
|
133
134
|
// - create the observer if required
|
|
134
|
-
function _createSwiperAndObserver(
|
|
135
|
-
|
|
135
|
+
function _createSwiperAndObserver(
|
|
136
|
+
uniqueClass: string,
|
|
137
|
+
options: AstroSwiperOptions,
|
|
138
|
+
element: AstroSwiper,
|
|
139
|
+
) {
|
|
140
|
+
if (!options.astro?.intersectionObserver?.initSwiper) {
|
|
136
141
|
// create the swiper immediatly
|
|
137
142
|
_initSwiper(uniqueClass, options, element);
|
|
138
143
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
---
|
|
2
|
+
// Copyright (c) Pascal Brand
|
|
3
|
+
// MIT License
|
|
4
|
+
|
|
5
|
+
import 'swiper/css/bundle';
|
|
6
|
+
|
|
7
|
+
import type { HTMLAttributes } from 'astro/types';
|
|
8
|
+
|
|
9
|
+
interface Props extends HTMLAttributes<'div'> {
|
|
10
|
+
/** add the default swiper class, true by default */
|
|
11
|
+
addDefaultClass?: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const { class: className = null, addDefaultClass = true, ...props } = Astro.props;
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
<div class:list={[addDefaultClass ? 'swiper-lazy-preloader' : null, className]} {...props}>
|
|
18
|
+
<slot />
|
|
19
|
+
</div>
|
package/src/index.ts
CHANGED
|
@@ -7,7 +7,7 @@ import type { HTMLAttributes } from 'astro/types';
|
|
|
7
7
|
/** Swiper options for the Astro component.
|
|
8
8
|
* Basically the same as the original SwiperOptions, but extended
|
|
9
9
|
* with new capabilities
|
|
10
|
-
*/
|
|
10
|
+
*/
|
|
11
11
|
export interface AstroSwiperOptions extends SwiperOptions {
|
|
12
12
|
/** options specific to astro-swiper component */
|
|
13
13
|
astro?: {
|
|
@@ -25,10 +25,10 @@ export interface AstroSwiperOptions extends SwiperOptions {
|
|
|
25
25
|
controlAutoplay?: boolean;
|
|
26
26
|
/** options for the IntersectionObserver */
|
|
27
27
|
options?: IntersectionObserverInit;
|
|
28
|
-
}
|
|
28
|
+
};
|
|
29
29
|
/** TODO: uniqueClass and linkToThumbUniqueClass may be part of it */
|
|
30
|
-
}
|
|
31
|
-
}
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
32
|
|
|
33
33
|
/** properties passed to the <Swiper> component
|
|
34
34
|
* It extends a div (that is may have class, style,...), plus other attributes
|
|
@@ -69,6 +69,7 @@ export interface AstroSwiperType extends HTMLAttributes<'div'> {
|
|
|
69
69
|
export { default as Swiper } from './components/Swiper.astro';
|
|
70
70
|
export { default as SwiperButtonNext } from './components/SwiperButtonNext.astro';
|
|
71
71
|
export { default as SwiperButtonPrev } from './components/SwiperButtonPrev.astro';
|
|
72
|
+
export { default as SwiperLazyPreloader } from './components/SwiperLazyPreloader.astro';
|
|
72
73
|
export { default as SwiperPagination } from './components/SwiperPagination.astro';
|
|
73
74
|
export { default as SwiperScrollbar } from './components/SwiperScrollbar.astro';
|
|
74
75
|
export { default as SwiperSlide } from './components/SwiperSlide.astro';
|