@rxdrag/website-lib-core 0.0.122 → 0.0.124
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 +3 -3
- package/src/astro/background.ts +5 -11
- package/src/astro/image.ts +239 -0
- package/src/astro/index.ts +1 -0
- package/src/astro/media.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rxdrag/website-lib-core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.124",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./index.ts"
|
|
@@ -34,10 +34,10 @@
|
|
|
34
34
|
"hls.js": "^1.6.13",
|
|
35
35
|
"lodash-es": "^4.17.21",
|
|
36
36
|
"@rxdrag/entify-lib": "0.0.24",
|
|
37
|
-
"@rxdrag/rxcms-models": "0.3.
|
|
37
|
+
"@rxdrag/rxcms-models": "0.3.105"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
|
-
"astro": "^
|
|
40
|
+
"astro": "^5.16.6",
|
|
41
41
|
"react": "^18.0.0 || ^19.0.0",
|
|
42
42
|
"react-dom": "^18.0.0 || ^19.0.0"
|
|
43
43
|
},
|
package/src/astro/background.ts
CHANGED
|
@@ -1,33 +1,30 @@
|
|
|
1
|
-
|
|
1
|
+
import { ImageLayout, ImageMetadata } from "./image";
|
|
2
|
+
|
|
2
3
|
// 背景样式类型定义,支持tailwind类
|
|
3
4
|
export type ColorBackgroundConfig = {
|
|
4
5
|
id?: string;
|
|
5
6
|
type: "color";
|
|
6
7
|
class?: string; // 颜色 ,模糊,图案等,如 "bg-blue-500", "bg-gradient-to-r from-blue-500 to-purple-600"
|
|
7
|
-
className?: string;//兼容旧的
|
|
8
8
|
};
|
|
9
9
|
|
|
10
10
|
export type BlurBackgroundConfig = {
|
|
11
11
|
id?: string;
|
|
12
12
|
type: "blur";
|
|
13
13
|
class?: string; // 模糊,如 "backdrop-blur"
|
|
14
|
-
className?: string;//兼容旧的
|
|
15
14
|
};
|
|
16
15
|
|
|
17
16
|
export type ImageBackgroundConfig = {
|
|
18
17
|
id?: string;
|
|
19
18
|
type: "image";
|
|
20
19
|
class?: string; // 图片,如 "bg-cover bg-center bg-no-repeat"
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
src?: string; // 图片源
|
|
20
|
+
layout?: ImageLayout;
|
|
21
|
+
src?: string | ImageMetadata; // 图片源
|
|
24
22
|
};
|
|
25
23
|
|
|
26
24
|
export type SvgBackgroundConfig = {
|
|
27
25
|
id?: string;
|
|
28
26
|
type: "svg";
|
|
29
27
|
class?: string; // 图案,如 "bg-dots-sm bg-gray-100"
|
|
30
|
-
className?: string;//兼容旧的
|
|
31
28
|
code?: string; // SVG代码
|
|
32
29
|
};
|
|
33
30
|
|
|
@@ -35,17 +32,14 @@ export type VideoBackgroundConfig = {
|
|
|
35
32
|
id?: string;
|
|
36
33
|
type: "video";
|
|
37
34
|
class?: string; // 视频,如 "bg-cover bg-center bg-no-repeat"
|
|
38
|
-
className?: string;//兼容旧的
|
|
39
35
|
mediaRef?: string; // 视频源
|
|
40
|
-
|
|
41
|
-
poster?: string; // 视频封面图源
|
|
36
|
+
poster?: string | ImageMetadata; // 视频封面图源
|
|
42
37
|
};
|
|
43
38
|
|
|
44
39
|
export type SplineBackgroundConfig = {
|
|
45
40
|
id?: string;
|
|
46
41
|
type: "spline";
|
|
47
42
|
class?: string; // Spline,如 "bg-cover bg-center bg-no-repeat"
|
|
48
|
-
className?: string;//兼容旧的
|
|
49
43
|
spline?: string; // Spline ID
|
|
50
44
|
url?: string; // Spline 场景 URL
|
|
51
45
|
};
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import type { HTMLAttributes } from "astro/types";
|
|
2
|
+
import type { ImageLayout } from "astro/dist/assets/types";
|
|
3
|
+
export type ImageMetadata = import("astro").ImageMetadata;
|
|
4
|
+
|
|
5
|
+
export type { ImageLayout };
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 图片输出格式
|
|
9
|
+
*/
|
|
10
|
+
export type ImageFormat = "webp" | "avif" | "png" | "jpg" | "gif" | "svg";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 图片在页面中的布局位置(用于优化下载尺寸)
|
|
14
|
+
*/
|
|
15
|
+
export type ImageSizePreset =
|
|
16
|
+
| "auto" // 自动处理(让 layout 决定)
|
|
17
|
+
| "full" // 全宽内容
|
|
18
|
+
| "half" // 两栏布局(约 50%)
|
|
19
|
+
| "third" // 三栏布局(约 33%)
|
|
20
|
+
| "quarter" // 四栏布局(约 25%)
|
|
21
|
+
| "sidebar"; // 侧边栏内图片
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* ============================================================
|
|
26
|
+
* 图片组件属性
|
|
27
|
+
* ============================================================
|
|
28
|
+
*
|
|
29
|
+
* 设计原则:
|
|
30
|
+
* 1. Props 只处理图片核心功能(来源、加载、优化)
|
|
31
|
+
* 2. 样式相关属性通过 Tailwind class 设置
|
|
32
|
+
*
|
|
33
|
+
* ============================================================
|
|
34
|
+
* 样式设置指南(通过 class 属性使用 Tailwind)
|
|
35
|
+
* ============================================================
|
|
36
|
+
*
|
|
37
|
+
* 【尺寸】
|
|
38
|
+
* - 宽度:w-full, w-1/2, w-64, w-[300px]
|
|
39
|
+
* - 高度:h-auto, h-64, h-screen, h-[200px]
|
|
40
|
+
* - 最大宽度:max-w-md, max-w-lg, max-w-full
|
|
41
|
+
*
|
|
42
|
+
* 【宽高比】
|
|
43
|
+
* - 正方形:aspect-square
|
|
44
|
+
* - 视频:aspect-video (16:9)
|
|
45
|
+
* - 自定义:aspect-[4/3], aspect-[3/2]
|
|
46
|
+
*
|
|
47
|
+
* 【填充模式】
|
|
48
|
+
* - 裁剪填满:object-cover(推荐用于背景图、卡片图)
|
|
49
|
+
* - 完整显示:object-contain(推荐用于 logo)
|
|
50
|
+
* - 拉伸填满:object-fill
|
|
51
|
+
* - 原始尺寸:object-none
|
|
52
|
+
*
|
|
53
|
+
* 【位置(配合 object-cover/contain 使用)】
|
|
54
|
+
* - 居中:object-center(默认)
|
|
55
|
+
* - 顶部:object-top
|
|
56
|
+
* - 底部:object-bottom
|
|
57
|
+
* - 左右:object-left, object-right
|
|
58
|
+
*
|
|
59
|
+
* 【圆角】
|
|
60
|
+
* - 小:rounded-sm
|
|
61
|
+
* - 中:rounded-md, rounded-lg
|
|
62
|
+
* - 大:rounded-xl, rounded-2xl
|
|
63
|
+
* - 圆形:rounded-full
|
|
64
|
+
*
|
|
65
|
+
* 【阴影】
|
|
66
|
+
* - 小:shadow-sm
|
|
67
|
+
* - 中:shadow, shadow-md
|
|
68
|
+
* - 大:shadow-lg, shadow-xl
|
|
69
|
+
*
|
|
70
|
+
* 【边框】
|
|
71
|
+
* - 细边框:border
|
|
72
|
+
* - 边框颜色:border-gray-200, border-white
|
|
73
|
+
*
|
|
74
|
+
* 【滤镜效果】
|
|
75
|
+
* - 灰度:grayscale
|
|
76
|
+
* - 模糊:blur-sm, blur-md
|
|
77
|
+
* - 亮度:brightness-50, brightness-150
|
|
78
|
+
* - 悬停效果:hover:scale-105, hover:brightness-110
|
|
79
|
+
*
|
|
80
|
+
* 使用示例:
|
|
81
|
+
* ```astro
|
|
82
|
+
* <Image
|
|
83
|
+
* src="/hero.jpg"
|
|
84
|
+
* alt="英雄图"
|
|
85
|
+
* class="w-full aspect-video object-cover rounded-lg shadow-lg"
|
|
86
|
+
* />
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
export interface ImageProps extends Omit<HTMLAttributes<"img">, "src" | "width" | "height"> {
|
|
90
|
+
/**
|
|
91
|
+
* 图片来源
|
|
92
|
+
* - 本地图片:使用 import 导入
|
|
93
|
+
* - 远程图片:使用完整 URL
|
|
94
|
+
* - CMS 图片:使用媒体库路径
|
|
95
|
+
*/
|
|
96
|
+
src: string | ImageMetadata;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* 图片宽度
|
|
100
|
+
* - 本地图片可自动推断,可不填
|
|
101
|
+
* - 本地图片使用 layout="fixed" 时必须填写
|
|
102
|
+
* - 远程图片不需要填写,用 Tailwind 样式代替
|
|
103
|
+
*/
|
|
104
|
+
width?: number;
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* 图片宽度列表
|
|
108
|
+
* - Astro Image/Picture 的 widths 参数
|
|
109
|
+
*/
|
|
110
|
+
widths?: number[];
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* 图片高度
|
|
114
|
+
* - 本地图片可自动推断,可不填
|
|
115
|
+
* - 本地图片使用 layout="fixed" 时必须填写
|
|
116
|
+
* - 远程图片不需要填写,用 Tailwind 样式代替
|
|
117
|
+
*/
|
|
118
|
+
height?: number;
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* 图片描述(用于无障碍访问和 SEO)
|
|
122
|
+
* - 内容图片:填写描述文字
|
|
123
|
+
* - 装饰性图片:设为空字符串 alt="",屏幕阅读器会忽略
|
|
124
|
+
*/
|
|
125
|
+
alt?: string;
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* 响应式布局模式(Astro 原生值)
|
|
129
|
+
* - responsive: 跟随容器宽度,最大不超过原图尺寸(推荐)
|
|
130
|
+
* - full-width: 填满父容器(100% 宽度)
|
|
131
|
+
* - fixed: 固定尺寸,不响应屏幕变化
|
|
132
|
+
* - none: 不使用 Astro 响应式处理
|
|
133
|
+
*/
|
|
134
|
+
layout?: ImageLayout;
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* 输出格式(用于 Picture 组件)
|
|
138
|
+
* - 浏览器会自动选择最优格式
|
|
139
|
+
* - 推荐:['avif', 'webp'] 获得最佳压缩
|
|
140
|
+
* @example ['avif', 'webp']
|
|
141
|
+
*/
|
|
142
|
+
formats?: ImageFormat[];
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* 加载策略
|
|
146
|
+
* - lazy: 延迟加载,首屏外的图片使用
|
|
147
|
+
* - eager: 立即加载,首屏图片使用
|
|
148
|
+
* @default "lazy"
|
|
149
|
+
*/
|
|
150
|
+
loading?: "lazy" | "eager";
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* 是否为重要图片(LCP 优化,Astro 原生支持)
|
|
154
|
+
* - 设为 true 会自动设置 loading="eager" 和 fetchpriority="high"
|
|
155
|
+
* - 仅对首屏最大的图片使用
|
|
156
|
+
*/
|
|
157
|
+
priority?: boolean;
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* 图片质量(1-100)
|
|
161
|
+
* - 数值越高质量越好,文件越大
|
|
162
|
+
* - 推荐 80-90 平衡质量和大小
|
|
163
|
+
* 备注:这个可以先不提供可视化支持,小白理解不了
|
|
164
|
+
* @default 80
|
|
165
|
+
*/
|
|
166
|
+
quality?: number;
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* sizes 属性(兼容 Astro Image 原生)
|
|
170
|
+
* - 用于响应式图片选择
|
|
171
|
+
* - 传递原生 CSS sizes 字符串
|
|
172
|
+
* @example "(max-width: 768px) 100vw, 50vw"
|
|
173
|
+
*/
|
|
174
|
+
sizes?: string;
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* 图片在页面中的布局位置预设(用于优化下载尺寸)
|
|
178
|
+
* - auto: 自动处理(推荐,让 layout 决定)
|
|
179
|
+
* - full: 全宽内容
|
|
180
|
+
* - half: 两栏布局
|
|
181
|
+
* - third: 三栏布局
|
|
182
|
+
* - quarter: 四栏布局
|
|
183
|
+
* - sidebar: 侧边栏内图片
|
|
184
|
+
* 会自动映射为 sizes 属性值
|
|
185
|
+
* @default "auto"
|
|
186
|
+
*/
|
|
187
|
+
sizeHint?: ImageSizePreset;
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* 样式类(使用 Tailwind)
|
|
191
|
+
*
|
|
192
|
+
* 【避免布局偏移】
|
|
193
|
+
* 设置宽高比可预留空间,防止图片加载时页面跳动:
|
|
194
|
+
* - aspect-square(1:1)
|
|
195
|
+
* - aspect-video(16:9)
|
|
196
|
+
* - aspect-[4/3]、aspect-[3/2] 等自定义比例
|
|
197
|
+
*
|
|
198
|
+
* 【常用宽高比】
|
|
199
|
+
* - 1:1 - 正方形,电商产品、头像、社交卡片
|
|
200
|
+
* - 4:3 - 传统屏幕,博客卡片、新闻缩略图
|
|
201
|
+
* - 3:2 - 单反照片,摄影作品、画廊
|
|
202
|
+
* - 16:9 - 宽屏视频,英雄图、视频封面
|
|
203
|
+
* - 21:9 - 超宽屏,电影海报、横幅广告
|
|
204
|
+
* - 4:5 - 竖版,Instagram、社交媒体
|
|
205
|
+
* - 9:16 - 竖屏视频,Stories、短视频封面
|
|
206
|
+
*
|
|
207
|
+
* 【快捷模板】
|
|
208
|
+
* - 英雄图:w-full aspect-video object-cover
|
|
209
|
+
* - 博客卡片:w-full aspect-[16/9] object-cover rounded-lg
|
|
210
|
+
* - 新闻卡片:w-full aspect-[4/3] object-cover rounded-lg
|
|
211
|
+
* - 电商卡片:w-full aspect-square object-cover rounded-lg
|
|
212
|
+
* - 社交卡片:w-full aspect-[4/5] object-cover rounded-lg
|
|
213
|
+
* - 缩略图:w-32 aspect-square object-cover rounded
|
|
214
|
+
* - 头像(小):w-8 h-8 object-cover rounded-full
|
|
215
|
+
* - 头像(中):w-12 h-12 object-cover rounded-full
|
|
216
|
+
* - 头像(大):w-16 h-16 object-cover rounded-full
|
|
217
|
+
* - Logo:h-8 w-auto object-contain
|
|
218
|
+
* - 产品图:w-full aspect-square object-contain bg-white
|
|
219
|
+
* - 背景图:w-full h-full object-cover absolute inset-0
|
|
220
|
+
* - 画廊图:w-full aspect-[3/2] object-cover hover:scale-105 transition
|
|
221
|
+
* - 横幅广告:w-full aspect-[21/9] object-cover
|
|
222
|
+
*
|
|
223
|
+
* 【常用样式】
|
|
224
|
+
* - 尺寸:w-full, w-1/2, w-32, h-64, max-w-lg, max-w-screen-xl
|
|
225
|
+
* - 填充:object-cover(裁剪填满), object-contain(完整显示), object-fill(拉伸)
|
|
226
|
+
* - 位置:object-center, object-top, object-bottom, object-left, object-right
|
|
227
|
+
* - 圆角:rounded-sm, rounded, rounded-md, rounded-lg, rounded-xl, rounded-full
|
|
228
|
+
* - 阴影:shadow-sm, shadow, shadow-md, shadow-lg, shadow-xl
|
|
229
|
+
* - 边框:border, border-2, border-white, border-gray-200
|
|
230
|
+
* - 滤镜:grayscale, blur-sm, brightness-75, contrast-125
|
|
231
|
+
* - 过渡:transition, hover:scale-105, hover:brightness-110, hover:shadow-xl
|
|
232
|
+
*
|
|
233
|
+
* @example "w-full aspect-video object-cover rounded-lg"
|
|
234
|
+
*/
|
|
235
|
+
class?: string;
|
|
236
|
+
//兼容react组件
|
|
237
|
+
className?: string;
|
|
238
|
+
}
|
|
239
|
+
|
package/src/astro/index.ts
CHANGED