@rxdrag/website-lib 0.0.127 → 0.0.128

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.
@@ -1,10 +1,14 @@
1
1
  ---
2
- import type { BackgroundConfig, Locals } from "@rxdrag/website-lib-core";
2
+ import type { Locals } from "@rxdrag/website-lib-core";
3
3
  import {
4
4
  BackgroundVideoPlayer,
5
5
  BackgroundHlsVideoPlayer,
6
6
  Entify,
7
7
  } from "@rxdrag/website-lib-core";
8
+ import type { BackgroundConfig } from "./Background.type";
9
+ import { getImage } from "astro:assets";
10
+ import type { ImageMetadata } from "astro";
11
+ import Image from "./Image.astro";
8
12
 
9
13
  export interface Props {
10
14
  background: BackgroundConfig;
@@ -20,48 +24,43 @@ const {
20
24
  } = Astro.props;
21
25
 
22
26
  // 安全地提取 mediaRef 和 posterRef(只有部分背景类型有这些属性)
23
- const mediaRef =
24
- background.type === "image" ||
25
- background.type === "video" ||
26
- background.type === "spline"
27
- ? background.mediaRef
28
- : undefined;
29
-
30
- const posterRef =
31
- background.type === "video" ? background.posterRef : undefined;
27
+ const mediaRef = background.type === "video" ? background.mediaRef : undefined;
32
28
 
33
29
  const rx = Entify.getInstance(env, imageSizes);
34
30
 
35
31
  // 获取媒体数据
36
32
  const media = rx ? await rx.getMedia(mediaRef) : undefined;
37
- const poster = rx ? await rx.getMedia(posterRef) : undefined;
38
33
 
39
- // 构建 className
40
- const className = [defaultClass, background.className]
34
+ // 构建 className(同时支持 class 和 className)
35
+ const className = [defaultClass, background.class, background.className]
41
36
  .filter(Boolean)
42
37
  .join(" ");
43
38
 
44
39
  // 预计算视频相关数据
45
40
  const videoUrl =
46
41
  background.type === "video" ? media?.file?.original : undefined;
47
- const posterUrl =
48
- background.type === "video" ? poster?.file?.original : undefined;
42
+
43
+ // 处理视频封面
44
+ let posterUrl: string | undefined;
45
+ if (background.type === "video" && background.poster) {
46
+ if (typeof background.poster === "string") {
47
+ posterUrl = background.poster;
48
+ } else {
49
+ const posterImage = await getImage({
50
+ src: background.poster as ImageMetadata,
51
+ });
52
+ posterUrl = posterImage.src;
53
+ }
54
+ }
55
+
49
56
  const isHls =
50
57
  background.type === "video" &&
51
58
  (media?.storageType === "cloudflare_stream" ||
52
59
  videoUrl?.endsWith(".m3u8") ||
53
60
  videoUrl?.includes("cloudflarestream.com"));
54
61
 
55
- // 预计算图片 URL
56
- const imageUrl =
57
- background.type === "image" ? media?.file?.original : undefined;
58
-
59
62
  // 预计算 Spline URL
60
- const splineUrl =
61
- background.type === "spline"
62
- ? background.url ||
63
- (background.mediaRef ? `/media/${background.mediaRef}` : "")
64
- : undefined;
63
+ const splineUrl = background.type === "spline" ? background.url : undefined;
65
64
  ---
66
65
 
67
66
  {background.type === "color" && <div class={className} />}
@@ -69,8 +68,8 @@ const splineUrl =
69
68
  {background.type === "blur" && <div class={className} />}
70
69
 
71
70
  {
72
- background.type === "image" && (
73
- <img class={className} src={imageUrl} alt="Background Image" />
71
+ background.type === "image" && background.src && (
72
+ <Image class={className} src={background.src} alt="Background Image" />
74
73
  )
75
74
  }
76
75
 
@@ -0,0 +1,18 @@
1
+ import type { BlurBackgroundConfig, ColorBackgroundConfig, ImageBackgroundConfig, SplineBackgroundConfig, SvgBackgroundConfig, VideoBackgroundConfig } from "@rxdrag/website-lib-core";
2
+ import type { ImageMetadata } from "astro";
3
+
4
+
5
+ export type ImageBgConfig = Omit<ImageBackgroundConfig, "src"> & {
6
+ src?: string | ImageMetadata;
7
+ }
8
+
9
+ export type VideoBgConfig = Omit<VideoBackgroundConfig, "poster"> & {
10
+ poster?: string | ImageMetadata;
11
+ }
12
+
13
+ export type BackgroundConfig = | ColorBackgroundConfig
14
+ | BlurBackgroundConfig
15
+ | ImageBgConfig
16
+ | SvgBackgroundConfig
17
+ | VideoBgConfig
18
+ | SplineBackgroundConfig;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rxdrag/website-lib",
3
- "version": "0.0.127",
3
+ "version": "0.0.128",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./index.ts",
@@ -26,11 +26,11 @@
26
26
  "eslint": "^9.39.2",
27
27
  "gsap": "^3.12.7",
28
28
  "typescript": "^5",
29
- "@rxdrag/rxcms-models": "0.3.98",
30
29
  "@rxdrag/eslint-config-custom": "0.2.13",
31
30
  "@rxdrag/entify-hooks": "0.2.79",
32
- "@rxdrag/tiptap-preview": "0.0.3",
33
- "@rxdrag/tsconfig": "0.2.1"
31
+ "@rxdrag/rxcms-models": "0.3.98",
32
+ "@rxdrag/tsconfig": "0.2.1",
33
+ "@rxdrag/tiptap-preview": "0.0.3"
34
34
  },
35
35
  "dependencies": {
36
36
  "aos": "3.0.0-beta.6",