@slidejs/runner-swiper 0.1.1 → 0.1.3
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/.turbo/turbo-build.log +15 -15
- package/LICENSE +22 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +401 -382
- package/dist/index.mjs.map +1 -1
- package/package.json +16 -13
- package/src/adapter.ts +8 -10
- package/src/env.d.ts +17 -0
- package/src/index.ts +3 -0
- package/src/runner.ts +39 -2
- package/src/style.css +154 -0
- package/tsconfig.json +1 -1
- package/vite.config.ts +12 -0
package/src/runner.ts
CHANGED
|
@@ -9,6 +9,9 @@ import { SlideRunner } from '@slidejs/runner';
|
|
|
9
9
|
import type { SlideContext } from '@slidejs/context';
|
|
10
10
|
import { SwiperAdapter } from './adapter';
|
|
11
11
|
import type { SwiperAdapterOptions } from './types';
|
|
12
|
+
// 导入 CSS 内容用于注入
|
|
13
|
+
import swiperCSS from 'swiper/css?inline';
|
|
14
|
+
import customCSS from './style.css?inline';
|
|
12
15
|
|
|
13
16
|
/**
|
|
14
17
|
* SlideRunner 配置选项
|
|
@@ -65,10 +68,44 @@ export async function createSlideRunner<TContext extends SlideContext = SlideCon
|
|
|
65
68
|
// 2. 编译为 SlideDSL
|
|
66
69
|
const slideDSL = compile<TContext>(ast);
|
|
67
70
|
|
|
68
|
-
//
|
|
71
|
+
// 2.1 Set to Global
|
|
72
|
+
const globalStyles = document.head.querySelector('#swiper-styles');
|
|
73
|
+
if (!globalStyles) {
|
|
74
|
+
const style = document.createElement('style');
|
|
75
|
+
style.id = 'swiper-styles';
|
|
76
|
+
style.textContent = swiperCSS;
|
|
77
|
+
document.head.appendChild(style);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// 2.2 获取用户提供的容器元素
|
|
81
|
+
let userContainer: HTMLElement;
|
|
82
|
+
if (typeof config.container === 'string') {
|
|
83
|
+
const element = document.querySelector(config.container);
|
|
84
|
+
if (!element) {
|
|
85
|
+
throw new Error(`Container not found: ${config.container}`);
|
|
86
|
+
}
|
|
87
|
+
userContainer = element as HTMLElement;
|
|
88
|
+
} else {
|
|
89
|
+
userContainer = config.container;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// 2.3 注入自定义 CSS 样式到容器
|
|
93
|
+
const styleId = 'slidejs-runner-swiper-styles';
|
|
94
|
+
if (!userContainer.querySelector(`#${styleId}`)) {
|
|
95
|
+
const style = document.createElement('style');
|
|
96
|
+
style.id = styleId;
|
|
97
|
+
style.textContent = customCSS;
|
|
98
|
+
userContainer.appendChild(style);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// 2.4 创建一个新的 div 节点用于 Swiper(Swiper 会接管这个 div)
|
|
102
|
+
const swiperContainer = document.createElement('div');
|
|
103
|
+
userContainer.appendChild(swiperContainer);
|
|
104
|
+
|
|
105
|
+
// 3. 创建适配器和 Runner(将 swiperContainer 传给 Runner,而不是 userContainer)
|
|
69
106
|
const adapter = new SwiperAdapter();
|
|
70
107
|
const runner = new SlideRunner<TContext>({
|
|
71
|
-
container:
|
|
108
|
+
container: swiperContainer,
|
|
72
109
|
adapter,
|
|
73
110
|
adapterOptions: {
|
|
74
111
|
swiperConfig: config.swiperOptions,
|
package/src/style.css
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @slidejs/runner-swiper - Swiper 核心样式
|
|
3
|
+
*
|
|
4
|
+
* 此文件导入 Swiper 的核心 CSS,用户只需导入此包即可获得所有必需的样式。
|
|
5
|
+
* 可选样式(如 navigation、pagination)需要单独导入。
|
|
6
|
+
*
|
|
7
|
+
* 使用示例:
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import '@slidejs/runner-swiper';
|
|
10
|
+
* // 或显式导入样式
|
|
11
|
+
* import '@slidejs/runner-swiper/style.css';
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* 自定义样式:
|
|
15
|
+
* 可以通过 CSS 变量自定义样式,例如:
|
|
16
|
+
* ```css
|
|
17
|
+
* :root {
|
|
18
|
+
* --slidejs-swiper-navigation-color: #007aff;
|
|
19
|
+
* --slidejs-swiper-pagination-color: #007aff;
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
/* Swiper 容器基础样式 */
|
|
25
|
+
.swiper {
|
|
26
|
+
width: 100%;
|
|
27
|
+
height: 100%;
|
|
28
|
+
|
|
29
|
+
/* Runner 特定变量映射 - 将标准变量映射到 Swiper 特定变量 */
|
|
30
|
+
/* 注意:标准变量的默认值由 @slidejs/theme 包定义,runner 只消费这些变量 */
|
|
31
|
+
|
|
32
|
+
/* Swiper 导航按钮颜色 - 从标准变量映射(fallback 仅作为临时默认值) */
|
|
33
|
+
--slidejs-swiper-navigation-color: var(--slidejs-navigation-color, #007aff);
|
|
34
|
+
/* Swiper 分页器颜色 - 从标准变量映射(fallback 仅作为临时默认值) */
|
|
35
|
+
--slidejs-swiper-pagination-color: var(--slidejs-pagination-color, #007aff);
|
|
36
|
+
/* Swiper 分页器激活颜色 - 从标准变量映射(fallback 仅作为临时默认值) */
|
|
37
|
+
--slidejs-swiper-pagination-bullet-active-color: var(--slidejs-pagination-active-color, #007aff);
|
|
38
|
+
/* Swiper 滚动条颜色 - 从标准变量映射(fallback 仅作为临时默认值) */
|
|
39
|
+
--slidejs-swiper-scrollbar-bg: var(--slidejs-scrollbar-bg, rgba(0, 0, 0, 0.1));
|
|
40
|
+
--slidejs-swiper-scrollbar-drag-bg: var(--slidejs-scrollbar-drag-bg, rgba(0, 0, 0, 0.5));
|
|
41
|
+
|
|
42
|
+
/* 同时设置 Swiper 自己的 CSS 变量(Swiper 的 CSS 使用这些变量) */
|
|
43
|
+
/* 注意:标准变量的默认值由 @slidejs/theme 包定义 */
|
|
44
|
+
--swiper-navigation-color: var(--slidejs-navigation-color, #007aff);
|
|
45
|
+
--swiper-pagination-color: var(--slidejs-pagination-color, #007aff);
|
|
46
|
+
--swiper-pagination-bullet-active-color: var(--slidejs-pagination-active-color, #007aff);
|
|
47
|
+
--swiper-theme-color: var(--slidejs-navigation-color, #007aff);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/* 应用 CSS 变量到 Swiper 组件 */
|
|
51
|
+
/* 使用更具体的选择器确保能够覆盖 Swiper 的默认样式 */
|
|
52
|
+
.swiper .swiper-button-next,
|
|
53
|
+
.swiper .swiper-button-prev {
|
|
54
|
+
color: var(--swiper-navigation-color, var(--slidejs-swiper-navigation-color, #007aff)) !important;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.swiper .swiper-pagination-bullet {
|
|
58
|
+
background-color: var(
|
|
59
|
+
--swiper-pagination-color,
|
|
60
|
+
var(--slidejs-swiper-pagination-color, #007aff)
|
|
61
|
+
) !important;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.swiper .swiper-pagination-bullet-active {
|
|
65
|
+
background-color: var(
|
|
66
|
+
--swiper-pagination-bullet-active-color,
|
|
67
|
+
var(--slidejs-swiper-pagination-bullet-active-color, #007aff)
|
|
68
|
+
) !important;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
.swiper .swiper-scrollbar {
|
|
72
|
+
background: var(--slidejs-swiper-scrollbar-bg, rgba(0, 0, 0, 0.1)) !important;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
.swiper .swiper-scrollbar-drag {
|
|
76
|
+
background: var(--slidejs-swiper-scrollbar-drag-bg, rgba(0, 0, 0, 0.5)) !important;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/* Swiper Slide 样式 - 确保内容垂直和水平居中 */
|
|
80
|
+
/* 注意:标准变量的默认值由 @slidejs/theme 包定义,fallback 仅作为临时默认值 */
|
|
81
|
+
.swiper-slide {
|
|
82
|
+
display: flex;
|
|
83
|
+
align-items: center;
|
|
84
|
+
justify-content: center;
|
|
85
|
+
width: 100%;
|
|
86
|
+
height: 100%;
|
|
87
|
+
background: var(--slidejs-background-color, #fff);
|
|
88
|
+
padding: 2rem;
|
|
89
|
+
box-sizing: border-box;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/* Slide Content 容器样式 - 允许通过 CSS 变量自定义 */
|
|
93
|
+
/* 注意:标准变量的默认值由 @slidejs/theme 包定义,fallback 仅作为临时默认值 */
|
|
94
|
+
.slide-content {
|
|
95
|
+
width: 100%;
|
|
96
|
+
text-align: center;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
.slide-content h1 {
|
|
100
|
+
font-size: 3rem;
|
|
101
|
+
margin-bottom: 1rem;
|
|
102
|
+
color: var(--slidejs-heading-color, #333);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
.slide-content h2 {
|
|
106
|
+
font-size: 2rem;
|
|
107
|
+
margin-bottom: 1rem;
|
|
108
|
+
color: var(--slidejs-heading-color, #666);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
.slide-content h3 {
|
|
112
|
+
font-size: 1.5rem;
|
|
113
|
+
margin-bottom: 0.5rem;
|
|
114
|
+
color: var(--slidejs-heading-color, #666);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
.slide-content p {
|
|
118
|
+
font-size: 1.2rem;
|
|
119
|
+
line-height: 1.6;
|
|
120
|
+
color: var(--slidejs-text-color, #555);
|
|
121
|
+
margin-bottom: 1rem;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
.slide-content ul {
|
|
125
|
+
text-align: left;
|
|
126
|
+
display: inline-block;
|
|
127
|
+
font-size: 1.2rem;
|
|
128
|
+
line-height: 1.8;
|
|
129
|
+
color: var(--slidejs-text-color, #555);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
.slide-content li {
|
|
133
|
+
margin-bottom: 0.5rem;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
.slide-content img {
|
|
137
|
+
border-radius: 8px;
|
|
138
|
+
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/* 导航按钮样式 */
|
|
142
|
+
.swiper-button-next:after,
|
|
143
|
+
.swiper-button-prev:after {
|
|
144
|
+
font-size: 24px;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/* 分页器样式 */
|
|
148
|
+
.swiper-pagination-bullet {
|
|
149
|
+
opacity: 0.5;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
.swiper-pagination-bullet-active {
|
|
153
|
+
opacity: 1;
|
|
154
|
+
}
|
package/tsconfig.json
CHANGED
package/vite.config.ts
CHANGED
|
@@ -20,8 +20,20 @@ export default defineConfig({
|
|
|
20
20
|
// Only externalize JS modules from swiper, NOT CSS
|
|
21
21
|
/^swiper\/.*\.js$/,
|
|
22
22
|
],
|
|
23
|
+
output: {
|
|
24
|
+
// 确保 CSS 文件被正确提取为 style.css
|
|
25
|
+
assetFileNames: assetInfo => {
|
|
26
|
+
// 将所有 CSS 文件重命名为 style.css(与 package.json exports 一致)
|
|
27
|
+
if (assetInfo.name && assetInfo.name.endsWith('.css')) {
|
|
28
|
+
return 'style.css';
|
|
29
|
+
}
|
|
30
|
+
return assetInfo.name || 'assets/[name].[ext]';
|
|
31
|
+
},
|
|
32
|
+
},
|
|
23
33
|
},
|
|
24
34
|
sourcemap: true,
|
|
35
|
+
// CSS 被提取到单独文件,但通过 import 语句自动加载
|
|
36
|
+
cssCodeSplit: false,
|
|
25
37
|
},
|
|
26
38
|
plugins: [
|
|
27
39
|
dts({
|