Resource 资源
类型定义
Resource 类型定义
export type Resource = {
src: string;
type: "image" | "video" | "audio" | "other";
native?: {
width: number;
height: number;
};
rect?: {
x: number;
y: number;
width: number;
height: number;
};
};
字段说明
| 字段 | 类型 | 必选 | 描述 |
|---|---|---|---|
src | string | 是 | 资源的路径或 URL。 |
type | 'image' 或 'video' 或 'audio' 或 'other' | 是 | 资源的类型:'image'(图片)、'video'(视频)、'audio'(音频)、'other'(其他)。 |
native 字段(仅 type 为 'image' 时可用)
| 字段 | 类型 | 必选 | 描述 |
|---|---|---|---|
width | number | 是 | 图片的原始宽度(像素)。 |
height | number | 是 | 图片的原始高度(像素)。 |
rect 字段(仅 type 为 'image' 时可用)
| 字段 | 类型 | 必选 | 描述 |
|---|---|---|---|
x | number | 是 | 图片裁剪区域的左上角 x 坐标。 |
y | number | 是 | 图片裁剪区域的左上角 y 坐标。 |
width | number | 是 | 图片裁剪区域的宽度。 |
height | number | 是 | 图片裁剪区域的高度。 |
示例
图片资源(带 native 和 rect)
const imageResource: Resource = {
src: "https://example.com/image.jpg",
type: "image",
native: {
width: 1920,
height: 1080,
},
rect: {
x: 100,
y: 200,
width: 800,
height: 600,
},
};
视频资源(仅 src 和 type)
const videoResource: Resource = {
src: "https://example.com/video.mp4",
type: "video",
};
音频资源(仅 src 和 type)
const audioResource: Resource = {
src: "https://example.com/audio.mp3",
type: "audio",
};
其他资源(仅 src 和 type)
const otherResource: Resource = {
src: "https://example.com/data.json",
type: "other",
};
注意事项
native和rect字段- 仅当
type为'image'时可用,其他类型无需提供。
- 仅当
rect的作用- 用于指定图片的裁剪区域,单位为像素,基于原始图片尺寸(
native)。
- 用于指定图片的裁剪区域,单位为像素,基于原始图片尺寸(
type的扩展性- 如果未来需要支持更多资源类型,可以扩展
type的枚举值。
- 如果未来需要支持更多资源类型,可以扩展