astro-swiper 1.3.0 → 2.0.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/README.md +6 -2
- package/index.ts +4 -4
- package/package.json +21 -3
- package/src/components/Swiper.astro +103 -104
- package/src/components/SwiperButtonNext.astro +19 -26
- package/src/components/SwiperButtonPrev.astro +19 -26
- package/src/components/SwiperPagination.astro +19 -26
- package/src/components/SwiperScrollbar.astro +19 -26
- package/src/components/SwiperSlide.astro +18 -26
- package/src/components/SwiperWrapper.astro +19 -26
- package/src/index.ts +61 -47
package/README.md
CHANGED
|
@@ -24,8 +24,12 @@
|
|
|
24
24
|
# Help needed
|
|
25
25
|
|
|
26
26
|
Do you need help to integrate ```astro-swiper``` in your
|
|
27
|
-
astro template / component?
|
|
28
|
-
|
|
27
|
+
astro template / component? 2 ways to ask:
|
|
28
|
+
* mention me with ```@pascal-brand38``` in an issue on your own github repo
|
|
29
|
+
* or [fill a github issue](https://github.com/pascal-brand38/astro-swiper/issues/new?template=help-needed.md)
|
|
30
|
+
in ```astro-swiper``` github
|
|
31
|
+
|
|
32
|
+
I'll be happy to help!
|
|
29
33
|
|
|
30
34
|
|
|
31
35
|
<br>
|
package/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright (c) Pascal Brand
|
|
2
|
-
// MIT License
|
|
3
|
-
|
|
4
|
-
export * from
|
|
1
|
+
// Copyright (c) Pascal Brand
|
|
2
|
+
// MIT License
|
|
3
|
+
|
|
4
|
+
export * from './src';
|
package/package.json
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astro-swiper",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Astro component for swiper, dedicated to slider / carousel / photo swiper / slide, including thumbnails",
|
|
5
5
|
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"format": "biome format --write && prettier -w \"**/*.astro\"",
|
|
8
|
+
"lint": "biome lint",
|
|
9
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
10
|
+
},
|
|
6
11
|
"repository": {
|
|
7
12
|
"type": "git",
|
|
8
13
|
"url": "git+https://github.com/pascal-brand38/astro-swiper.git"
|
|
@@ -19,14 +24,27 @@
|
|
|
19
24
|
"src/**"
|
|
20
25
|
],
|
|
21
26
|
"devDependencies": {
|
|
27
|
+
"@biomejs/biome": "^2.3.14",
|
|
22
28
|
"@types/node": "^24.0.0",
|
|
23
29
|
"astro": "^5.9.2",
|
|
30
|
+
"prettier": "^3.8.1",
|
|
31
|
+
"prettier-plugin-astro": "^0.14.1",
|
|
24
32
|
"typescript": "^5.8.3"
|
|
25
33
|
},
|
|
26
34
|
"keywords": [
|
|
27
35
|
"swiper",
|
|
28
|
-
"withastro",
|
|
29
|
-
"
|
|
36
|
+
"withastro",
|
|
37
|
+
"astro-component",
|
|
38
|
+
"image",
|
|
39
|
+
"carousel",
|
|
40
|
+
"swiper",
|
|
41
|
+
"slider",
|
|
42
|
+
"slideshow",
|
|
43
|
+
"gallery",
|
|
44
|
+
"lightweight",
|
|
45
|
+
"touch",
|
|
46
|
+
"responsive",
|
|
47
|
+
"thumbnail"
|
|
30
48
|
],
|
|
31
49
|
"dependencies": {
|
|
32
50
|
"swiper": "^12.0.0"
|
|
@@ -1,104 +1,103 @@
|
|
|
1
|
-
---
|
|
2
|
-
// Copyright (c) Pascal Brand
|
|
3
|
-
// MIT License
|
|
4
|
-
|
|
5
|
-
import 'swiper/css/bundle'
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
this.
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
</script>
|
|
1
|
+
---
|
|
2
|
+
// Copyright (c) Pascal Brand
|
|
3
|
+
// MIT License
|
|
4
|
+
|
|
5
|
+
import 'swiper/css/bundle';
|
|
6
|
+
import type { AstroSwiperType } from '../index';
|
|
7
|
+
|
|
8
|
+
type Props = AstroSwiperType;
|
|
9
|
+
|
|
10
|
+
const {
|
|
11
|
+
options = {},
|
|
12
|
+
uniqueClass = `astro-swiper-${Math.random().toString(36).slice(2, 11)}`,
|
|
13
|
+
class: className = null,
|
|
14
|
+
linkToThumbUniqueClass = null,
|
|
15
|
+
addDefaultClass = true,
|
|
16
|
+
...props
|
|
17
|
+
} = Astro.props;
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
<!-- Slider main container -->
|
|
21
|
+
<div class:list={[addDefaultClass ? 'swiper' : '', uniqueClass, className]} {...props} >
|
|
22
|
+
<astro-swiper
|
|
23
|
+
data-options={JSON.stringify(options)}
|
|
24
|
+
data-linktothumbuniqueclass={linkToThumbUniqueClass}
|
|
25
|
+
data-uniqueclass={uniqueClass}
|
|
26
|
+
/>
|
|
27
|
+
<slot />
|
|
28
|
+
</div>
|
|
29
|
+
|
|
30
|
+
<script>
|
|
31
|
+
import Swiper from 'swiper/bundle';
|
|
32
|
+
import type { SwiperOptions } from 'swiper/types';
|
|
33
|
+
|
|
34
|
+
/** contains the swiper json object once created, for each uniqueClass */
|
|
35
|
+
const _useSwiper: { [uniqueClass: string]: Swiper } = {};
|
|
36
|
+
|
|
37
|
+
/** contains the option used when creating the swiper object for each uniqueClass */
|
|
38
|
+
const _useOptions: { [uniqueClass: string]: SwiperOptions } = {};
|
|
39
|
+
|
|
40
|
+
/** contains all the uniqueClass that have their swiper object delayed because the
|
|
41
|
+
* related thumbnail swiper is not created yet
|
|
42
|
+
* For each uniqueClass, is equal to the thumbnail slider uniqueClass
|
|
43
|
+
*/
|
|
44
|
+
const _useDelaySwiper: { [uniqueClass: string]: string } = {};
|
|
45
|
+
|
|
46
|
+
class AstroSwiper extends HTMLElement {
|
|
47
|
+
/** pointer to the swiper structure that was created using "new",
|
|
48
|
+
* even when not initialized */
|
|
49
|
+
astroSwiper: Swiper | undefined;
|
|
50
|
+
|
|
51
|
+
constructor() {
|
|
52
|
+
super();
|
|
53
|
+
this.astroSwiper = undefined;
|
|
54
|
+
|
|
55
|
+
// Read the message from the data attribute.
|
|
56
|
+
const options = JSON.parse(this.dataset.options || '{}');
|
|
57
|
+
const uniqueClass = this.dataset.uniqueclass || ''; // to have more than 1 swiper in a single page
|
|
58
|
+
const linkToThumbUniqueClass = this.dataset.linktothumbuniqueclass || '';
|
|
59
|
+
|
|
60
|
+
if (linkToThumbUniqueClass === '') {
|
|
61
|
+
// no thumbnail link - the swiper can be created immediatly
|
|
62
|
+
const swiper = new Swiper(`.${uniqueClass}`, options);
|
|
63
|
+
_useSwiper[uniqueClass] = swiper;
|
|
64
|
+
this.astroSwiper = swiper;
|
|
65
|
+
} else {
|
|
66
|
+
// a thumbnail link is provided
|
|
67
|
+
// if the thumbnail swiper is already created, the main slider can be created also
|
|
68
|
+
// otherwise, it will be added in the delayed swiper list
|
|
69
|
+
if (_useSwiper[linkToThumbUniqueClass] !== undefined) {
|
|
70
|
+
options.thumbs = { swiper: _useSwiper[linkToThumbUniqueClass], ...options.thumbs };
|
|
71
|
+
const swiper = new Swiper(`.${uniqueClass}`, options);
|
|
72
|
+
_useSwiper[uniqueClass] = swiper;
|
|
73
|
+
this.astroSwiper = swiper;
|
|
74
|
+
} else {
|
|
75
|
+
// cannot create the swiper as the thumbnail swiper not created yet
|
|
76
|
+
// will be done later
|
|
77
|
+
_useDelaySwiper[uniqueClass] = linkToThumbUniqueClass;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
_useOptions[uniqueClass] = options;
|
|
82
|
+
|
|
83
|
+
// look if any delayed swiper can be created, that is its related thumbnail swiper is now created
|
|
84
|
+
Object.keys(_useDelaySwiper).forEach((delayedClass) => {
|
|
85
|
+
const delayedThumbClass = _useDelaySwiper[delayedClass];
|
|
86
|
+
if (_useSwiper[delayedThumbClass] !== undefined) {
|
|
87
|
+
const delayedOptions = _useOptions[delayedClass];
|
|
88
|
+
delayedOptions.thumbs = {
|
|
89
|
+
swiper: _useSwiper[delayedThumbClass],
|
|
90
|
+
...delayedOptions.thumbs,
|
|
91
|
+
};
|
|
92
|
+
const swiper = new Swiper(`.${delayedClass}`, delayedOptions);
|
|
93
|
+
_useSwiper[delayedClass] = swiper;
|
|
94
|
+
(document.querySelector(`.${delayedClass}`) as AstroSwiper).astroSwiper = swiper;
|
|
95
|
+
_useOptions[delayedClass] = delayedOptions;
|
|
96
|
+
delete _useDelaySwiper[delayedClass];
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
customElements.define('astro-swiper', AstroSwiper);
|
|
103
|
+
</script>
|
|
@@ -1,26 +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<
|
|
10
|
-
/** add the default swiper class, true by default */
|
|
11
|
-
addDefaultClass?: boolean
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
---
|
|
21
|
-
|
|
22
|
-
<div
|
|
23
|
-
class:list={[(addDefaultClass ? 'swiper-button-next' : ''), className]}
|
|
24
|
-
{...props}>
|
|
25
|
-
<slot/>
|
|
26
|
-
</div>
|
|
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 = '', addDefaultClass = true, ...props } = Astro.props;
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
<div class:list={[addDefaultClass ? 'swiper-button-next' : '', className]} {...props}>
|
|
18
|
+
<slot />
|
|
19
|
+
</div>
|
|
@@ -1,26 +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<
|
|
10
|
-
/** add the default swiper class, true by default */
|
|
11
|
-
addDefaultClass?: boolean
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
---
|
|
21
|
-
|
|
22
|
-
<div
|
|
23
|
-
class:list={[(addDefaultClass ? 'swiper-button-prev' : ''), className]}
|
|
24
|
-
{...props}>
|
|
25
|
-
<slot/>
|
|
26
|
-
</div>
|
|
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 = '', addDefaultClass = true, ...props } = Astro.props;
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
<div class:list={[addDefaultClass ? 'swiper-button-prev' : '', className]} {...props}>
|
|
18
|
+
<slot />
|
|
19
|
+
</div>
|
|
@@ -1,26 +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<
|
|
10
|
-
/** add the default swiper class, true by default */
|
|
11
|
-
addDefaultClass?: boolean
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
---
|
|
21
|
-
|
|
22
|
-
<div
|
|
23
|
-
class:list={[(addDefaultClass ? 'swiper-pagination' : ''), className]}
|
|
24
|
-
{...props}>
|
|
25
|
-
<slot/>
|
|
26
|
-
</div>
|
|
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 = '', addDefaultClass = true, ...props } = Astro.props;
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
<div class:list={[addDefaultClass ? 'swiper-pagination' : '', className]} {...props}>
|
|
18
|
+
<slot />
|
|
19
|
+
</div>
|
|
@@ -1,26 +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<
|
|
10
|
-
/** add the default swiper class, true by default */
|
|
11
|
-
addDefaultClass?: boolean
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
---
|
|
21
|
-
|
|
22
|
-
<div
|
|
23
|
-
class:list={[(addDefaultClass ? 'swiper-scrollbar' : ''), className]}
|
|
24
|
-
{...props}>
|
|
25
|
-
<slot/>
|
|
26
|
-
</div>
|
|
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 = '', addDefaultClass = true, ...props } = Astro.props;
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
<div class:list={[addDefaultClass ? 'swiper-scrollbar' : '', className]} {...props}>
|
|
18
|
+
<slot />
|
|
19
|
+
</div>
|
|
@@ -1,26 +1,18 @@
|
|
|
1
|
-
---
|
|
2
|
-
// Copyright (c) Pascal Brand
|
|
3
|
-
// MIT License
|
|
4
|
-
|
|
5
|
-
import 'swiper/css/bundle'
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
---
|
|
21
|
-
|
|
22
|
-
<div
|
|
23
|
-
class:list={[(addDefaultClass ? 'swiper-slide' : ''), className]}
|
|
24
|
-
{...props}>
|
|
25
|
-
<slot/>
|
|
26
|
-
</div>
|
|
1
|
+
---
|
|
2
|
+
// Copyright (c) Pascal Brand
|
|
3
|
+
// MIT License
|
|
4
|
+
|
|
5
|
+
import 'swiper/css/bundle';
|
|
6
|
+
import type { HTMLAttributes } from 'astro/types';
|
|
7
|
+
|
|
8
|
+
interface Props extends HTMLAttributes<'div'> {
|
|
9
|
+
/** add the default swiper class, true by default */
|
|
10
|
+
addDefaultClass?: boolean;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const { class: className = '', addDefaultClass = true, ...props } = Astro.props;
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
<div class:list={[addDefaultClass ? 'swiper-slide' : null, className]} {...props}>
|
|
17
|
+
<slot />
|
|
18
|
+
</div>
|
|
@@ -1,26 +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<
|
|
10
|
-
/** add the default swiper class, true by default */
|
|
11
|
-
addDefaultClass?: boolean
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
---
|
|
21
|
-
|
|
22
|
-
<div
|
|
23
|
-
class:list={[(addDefaultClass ? 'swiper-wrapper' : ''), className]}
|
|
24
|
-
{...props}>
|
|
25
|
-
<slot/>
|
|
26
|
-
</div>
|
|
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 = '', addDefaultClass = true, ...props } = Astro.props;
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
<div class:list={[addDefaultClass ? 'swiper-wrapper' : '', className]} {...props}>
|
|
18
|
+
<slot />
|
|
19
|
+
</div>
|
package/src/index.ts
CHANGED
|
@@ -1,47 +1,61 @@
|
|
|
1
|
-
// Copyright (c) Pascal Brand
|
|
2
|
-
// MIT License
|
|
3
|
-
|
|
4
|
-
import type { Swiper, SwiperOptions } from 'swiper/types'
|
|
5
|
-
import type { HTMLAttributes } from 'astro/types'
|
|
6
|
-
|
|
7
|
-
/** properties passed to the <Swiper> component
|
|
8
|
-
* It extends a div (that is may have class, style,...), plus other attributes
|
|
9
|
-
* Note that all other components (<SwiperSlide>, <SwiperButtonNext>...) extends a div only
|
|
10
|
-
*/
|
|
11
|
-
export interface AstroSwiperType extends HTMLAttributes<
|
|
12
|
-
/** swiper options, to set autoplay, navigation, thumbnails,...
|
|
13
|
-
* check fullset of options: https://swiperjs.com/swiper-api#parameters
|
|
14
|
-
*/
|
|
15
|
-
options?: SwiperOptions
|
|
16
|
-
|
|
17
|
-
/** unique class to be able to retrieve the swiper instance, if required
|
|
18
|
-
* Mandatory on thumbnail for example
|
|
19
|
-
* When undefined, an automatic unique class name is provided
|
|
20
|
-
*/
|
|
21
|
-
uniqueClass?: string
|
|
22
|
-
|
|
23
|
-
/** a thumbnail slider is build, this parameter is provided on the main slider
|
|
24
|
-
* (the one with big slides, not the one to track the progress) and equal
|
|
25
|
-
* the unique class of the thumbnail slider
|
|
26
|
-
*/
|
|
27
|
-
linkToThumbUniqueClass?: string
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
export { default as
|
|
35
|
-
export { default as
|
|
36
|
-
export { default as
|
|
37
|
-
export { default as
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
1
|
+
// Copyright (c) Pascal Brand
|
|
2
|
+
// MIT License
|
|
3
|
+
|
|
4
|
+
import type { Swiper, SwiperOptions } from 'swiper/types';
|
|
5
|
+
import type { HTMLAttributes } from 'astro/types';
|
|
6
|
+
|
|
7
|
+
/** properties passed to the <Swiper> component
|
|
8
|
+
* It extends a div (that is may have class, style,...), plus other attributes
|
|
9
|
+
* Note that all other components (<SwiperSlide>, <SwiperButtonNext>...) extends a div only
|
|
10
|
+
*/
|
|
11
|
+
export interface AstroSwiperType extends HTMLAttributes<'div'> {
|
|
12
|
+
/** swiper options, to set autoplay, navigation, thumbnails,...
|
|
13
|
+
* check fullset of options: https://swiperjs.com/swiper-api#parameters
|
|
14
|
+
*/
|
|
15
|
+
options?: SwiperOptions;
|
|
16
|
+
|
|
17
|
+
/** unique class to be able to retrieve the swiper instance, if required
|
|
18
|
+
* Mandatory on thumbnail for example
|
|
19
|
+
* When undefined, an automatic unique class name is provided
|
|
20
|
+
*/
|
|
21
|
+
uniqueClass?: string;
|
|
22
|
+
|
|
23
|
+
/** a thumbnail slider is build, this parameter is provided on the main slider
|
|
24
|
+
* (the one with big slides, not the one to track the progress) and equal
|
|
25
|
+
* the unique class of the thumbnail slider
|
|
26
|
+
*/
|
|
27
|
+
linkToThumbUniqueClass?: string;
|
|
28
|
+
|
|
29
|
+
/** add the default swiper class, true by default */
|
|
30
|
+
addDefaultClass?: boolean;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** astro components exported, used to create a swiper */
|
|
34
|
+
export { default as Swiper } from './components/Swiper.astro';
|
|
35
|
+
export { default as SwiperButtonNext } from './components/SwiperButtonNext.astro';
|
|
36
|
+
export { default as SwiperButtonPrev } from './components/SwiperButtonPrev.astro';
|
|
37
|
+
export { default as SwiperPagination } from './components/SwiperPagination.astro';
|
|
38
|
+
export { default as SwiperScrollbar } from './components/SwiperScrollbar.astro';
|
|
39
|
+
export { default as SwiperSlide } from './components/SwiperSlide.astro';
|
|
40
|
+
export { default as SwiperWrapper } from './components/SwiperWrapper.astro';
|
|
41
|
+
|
|
42
|
+
declare class AstroSwiper extends HTMLElement {
|
|
43
|
+
/** pointer to the swiper structure that was created using "new",
|
|
44
|
+
* even when not initialized */
|
|
45
|
+
astroSwiper: Swiper | undefined;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** @deprecated: use getSwiperFromUniqueSelector() instead */
|
|
49
|
+
export function getSwiperFromUniqueClass(uniqueClass: string): Swiper | undefined {
|
|
50
|
+
return getSwiperFromUniqueSelector(`.${uniqueClass}`);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Retrieve the swiper instance from the unique selector provided
|
|
54
|
+
* when creating the swiper
|
|
55
|
+
* @param uniqueSelector the unique selector provided when creating the swiper,
|
|
56
|
+
* @example const swiper = getSwiperFromUniqueSelector('.my-unique-class')
|
|
57
|
+
* const swiper = getSwiperFromUniqueSelector('#my-unique-id')
|
|
58
|
+
*/
|
|
59
|
+
export function getSwiperFromUniqueSelector(uniqueSelector: string): Swiper | undefined {
|
|
60
|
+
return (document.querySelector(uniqueSelector)?.firstElementChild as AstroSwiper)?.astroSwiper;
|
|
61
|
+
}
|