@rxdrag/website-lib 0.0.141 → 0.0.144

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.
@@ -19,7 +19,7 @@ interface Props extends HTMLAttributes<"header"> {
19
19
  const { className, backgrounds, class: originalClass, ...rest } = Astro.props;
20
20
  ---
21
21
 
22
- <header class:list={["header-block", className, originalClass]} {...rest}>
22
+ <header class:list={["header", className, originalClass]} {...rest}>
23
23
  <BackgroundGroup backgrounds={backgrounds} />
24
24
  <slot />
25
25
  </header>
@@ -1,6 +1,8 @@
1
1
  ---
2
2
  import type { HTMLAttributes } from "astro/types";
3
3
  import BaseBlock from "./BaseBlock.astro";
4
+ import type { BackgroundConfig } from "@rxdrag/website-lib-core";
5
+ import BackgroundGroup from "./BackgroundGroup.astro";
4
6
 
5
7
  /**
6
8
  * 容器
@@ -13,9 +15,10 @@ import BaseBlock from "./BaseBlock.astro";
13
15
  interface Props extends HTMLAttributes<"div"> {
14
16
  //布局
15
17
  className?: string;
18
+ backgrounds?: BackgroundConfig[];
16
19
  }
17
20
 
18
- const { className, class: classAttr, ...rest } = Astro.props;
21
+ const { className, class: classAttr, backgrounds, ...rest } = Astro.props;
19
22
  ---
20
23
 
21
24
  <BaseBlock
@@ -24,5 +27,6 @@ const { className, class: classAttr, ...rest } = Astro.props;
24
27
  class={classAttr}
25
28
  {...rest}
26
29
  >
30
+ <BackgroundGroup backgrounds={backgrounds} />
27
31
  <slot />
28
32
  </BaseBlock>
@@ -0,0 +1,204 @@
1
+ ---
2
+ import Section from "./Section.astro";
3
+ import clsx from "clsx";
4
+ import "swiper/css";
5
+ import "swiper/css/pagination";
6
+ import "swiper/css/navigation";
7
+
8
+ interface Props {
9
+ class?: string;
10
+ }
11
+
12
+ const { class: className, ...rest } = Astro.props;
13
+ ---
14
+
15
+ <Section
16
+ className={clsx(
17
+ "w-full h-[300px] sm:h-[400px] md:h-screen flex flex-col mt-0 bg-black relative overflow-hidden z-10 py-0",
18
+ className,
19
+ )}
20
+ disableContainer
21
+ {...rest}
22
+ >
23
+ <div class="hero-carousel w-full h-full relative" data-hero-carousel>
24
+ <div class="swiper h-full relative">
25
+ <div class="swiper-wrapper h-full">
26
+ <slot />
27
+ </div>
28
+ <slot name="navigation" />
29
+ <slot name="pagination" />
30
+ </div>
31
+ </div>
32
+ </Section>
33
+
34
+ <script>
35
+ type SwiperRootEl = HTMLElement & { __swiperInstance?: any };
36
+ type SwiperType = typeof import("swiper").default;
37
+ type SwiperModulesType = typeof import("swiper/modules");
38
+
39
+ type BootWindow = Window & {
40
+ __heroCarouselBootstrapped?: boolean;
41
+ };
42
+
43
+ const destroyRoot = (root: SwiperRootEl) => {
44
+ const existing = root.__swiperInstance;
45
+ if (existing && typeof existing.destroy === "function") {
46
+ existing.destroy(true, true);
47
+ root.__swiperInstance = null;
48
+ }
49
+ root.dataset.heroCarouselInited = "";
50
+ };
51
+
52
+ const loadSwiperResources = async () => {
53
+ const [{ default: Swiper }, { Autoplay, Navigation, Pagination }] =
54
+ await Promise.all([import("swiper"), import("swiper/modules")]);
55
+ return { Swiper, Autoplay, Navigation, Pagination };
56
+ };
57
+
58
+ let swiperCache: {
59
+ Swiper: SwiperType;
60
+ Autoplay: SwiperModulesType["Autoplay"];
61
+ Navigation: SwiperModulesType["Navigation"];
62
+ Pagination: SwiperModulesType["Pagination"];
63
+ } | null = null;
64
+
65
+ const getSwiperModules = async () => {
66
+ if (!swiperCache) {
67
+ swiperCache = await loadSwiperResources();
68
+ }
69
+ return swiperCache;
70
+ };
71
+
72
+ const initRoot = async (root: SwiperRootEl) => {
73
+ if (root.dataset.heroCarouselInited === "1") {
74
+ return;
75
+ }
76
+
77
+ const el = root.querySelector(".swiper") as HTMLElement | null;
78
+ if (!el) return;
79
+
80
+ const paginationEl = root.querySelector(
81
+ ".swiper-pagination",
82
+ ) as HTMLElement | null;
83
+ const prevEl = root.querySelector(
84
+ ".swiper-button-prev",
85
+ ) as HTMLElement | null;
86
+ const nextEl = root.querySelector(
87
+ ".swiper-button-next",
88
+ ) as HTMLElement | null;
89
+
90
+ const wantPagination = !!paginationEl;
91
+ const wantNavigation = !!prevEl && !!nextEl;
92
+
93
+ destroyRoot(root);
94
+
95
+ const { Swiper, Autoplay, Navigation, Pagination } =
96
+ await getSwiperModules();
97
+
98
+ const modules = [Autoplay] as any[];
99
+ if (wantPagination) {
100
+ modules.push(Pagination);
101
+ }
102
+ if (wantNavigation) {
103
+ modules.push(Navigation);
104
+ }
105
+
106
+ const instance = new Swiper(el, {
107
+ modules,
108
+ slidesPerView: 1,
109
+ spaceBetween: 0,
110
+ rewind: true,
111
+ observer: true,
112
+ observeParents: true,
113
+ autoplay: {
114
+ delay: 3500,
115
+ disableOnInteraction: false,
116
+ pauseOnMouseEnter: false,
117
+ },
118
+ ...(wantPagination && paginationEl
119
+ ? {
120
+ pagination: {
121
+ el: paginationEl,
122
+ clickable: true,
123
+ type: "bullets",
124
+ bulletActiveClass: "swiper-pagination-bullet-active",
125
+ },
126
+ }
127
+ : {}),
128
+ ...(wantNavigation && prevEl && nextEl
129
+ ? {
130
+ navigation: {
131
+ prevEl,
132
+ nextEl,
133
+ },
134
+ }
135
+ : {}),
136
+ });
137
+
138
+ try {
139
+ instance.autoplay?.start?.();
140
+ } catch {}
141
+
142
+ root.__swiperInstance = instance;
143
+ root.dataset.heroCarouselInited = "1";
144
+ };
145
+
146
+ const initAll = async () => {
147
+ const roots = document.querySelectorAll(
148
+ "[data-hero-carousel]",
149
+ ) as NodeListOf<SwiperRootEl>;
150
+ if (roots.length === 0) return;
151
+ await Promise.all(Array.from(roots).map((root) => initRoot(root)));
152
+ };
153
+
154
+ const destroyAll = () => {
155
+ const roots = document.querySelectorAll(
156
+ "[data-hero-carousel]",
157
+ ) as NodeListOf<SwiperRootEl>;
158
+ roots.forEach((root) => destroyRoot(root));
159
+ };
160
+
161
+ const ensureAutoplayAll = () => {
162
+ const roots = document.querySelectorAll(
163
+ "[data-hero-carousel]",
164
+ ) as NodeListOf<SwiperRootEl>;
165
+ roots.forEach((root) => {
166
+ const inst = root.__swiperInstance;
167
+ try {
168
+ inst?.autoplay?.start?.();
169
+ } catch {}
170
+ });
171
+ };
172
+
173
+ const boot = async () => {
174
+ try {
175
+ await initAll();
176
+ } catch (e) {
177
+ console.log("HeroCarousel init error:", e);
178
+ }
179
+ };
180
+
181
+ const w = window as BootWindow;
182
+ if (!w.__heroCarouselBootstrapped) {
183
+ w.__heroCarouselBootstrapped = true;
184
+
185
+ if (document.readyState === "loading") {
186
+ document.addEventListener("DOMContentLoaded", boot);
187
+ } else {
188
+ boot();
189
+ }
190
+
191
+ document.addEventListener("astro:page-load", boot);
192
+ document.addEventListener("astro:after-swap", () => {
193
+ boot();
194
+ ensureAutoplayAll();
195
+ });
196
+ window.addEventListener("astro:before-swap", destroyAll);
197
+
198
+ document.addEventListener("visibilitychange", () => {
199
+ if (!document.hidden) {
200
+ ensureAutoplayAll();
201
+ }
202
+ });
203
+ }
204
+ </script>
@@ -0,0 +1,24 @@
1
+ ---
2
+ import Box from "./Box.astro";
3
+ import Container from "./Container.astro";
4
+ import clsx from "clsx";
5
+ import type { BackgroundConfig } from "@rxdrag/website-lib-core";
6
+
7
+ interface Props {
8
+ class?: string;
9
+ backgrounds?: BackgroundConfig[];
10
+ }
11
+
12
+ const { class: className, backgrounds } = Astro.props;
13
+ ---
14
+
15
+ <div class={clsx("swiper-slide h-full")}>
16
+ <Box
17
+ class={clsx("w-full h-full flex flex-col justify-center")}
18
+ backgrounds={backgrounds}
19
+ >
20
+ <Container class={className}>
21
+ <slot />
22
+ </Container>
23
+ </Box>
24
+ </div>
package/package.json CHANGED
@@ -1,9 +1,11 @@
1
1
  {
2
2
  "name": "@rxdrag/website-lib",
3
- "version": "0.0.141",
3
+ "version": "0.0.144",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./index.ts",
7
+ "./components/HeroCarousel.astro": "./components/HeroCarousel.astro",
8
+ "./components/HeroCarouselPanel.astro": "./components/HeroCarouselPanel.astro",
7
9
  "./components/*.astro": "./components/*.astro"
8
10
  },
9
11
  "files": [
@@ -25,12 +27,13 @@
25
27
  "astro": "^5.16.6",
26
28
  "eslint": "^9.39.2",
27
29
  "gsap": "^3.12.7",
30
+ "swiper": "^12.0.3",
28
31
  "typescript": "^5",
29
- "@rxdrag/eslint-config-custom": "0.2.13",
30
- "@rxdrag/tiptap-preview": "0.0.3",
32
+ "@rxdrag/entify-hooks": "0.2.79",
31
33
  "@rxdrag/rxcms-models": "0.3.106",
34
+ "@rxdrag/eslint-config-custom": "0.2.13",
32
35
  "@rxdrag/tsconfig": "0.2.1",
33
- "@rxdrag/entify-hooks": "0.2.79"
36
+ "@rxdrag/tiptap-preview": "0.0.3"
34
37
  },
35
38
  "dependencies": {
36
39
  "aos": "3.0.0-beta.6",
@@ -39,10 +42,11 @@
39
42
  "react-dom": "^19.1.0",
40
43
  "vanilla-cookieconsent": "3.1.0",
41
44
  "@rxdrag/rxcms-models": "0.3.106",
42
- "@rxdrag/website-lib-core": "0.0.124"
45
+ "@rxdrag/website-lib-core": "0.0.125"
43
46
  },
44
47
  "peerDependencies": {
45
- "astro": "^5.16.6"
48
+ "astro": "^5.16.6",
49
+ "swiper": "^12.0.3"
46
50
  },
47
51
  "scripts": {
48
52
  "lint": "eslint . --ext .ts,tsx",