feat: 背景来源——本地上传 / 预设几何 / Unsplash 搜索

SourcePanel 常驻在右栏「背景」一节,三个来源任选:

- 本地上传:文件选择 + 全窗口拖放,转 object URL 装进画布,
  换图与卸载时释放旧的 blob 地址
- 预设几何:四种底纹(斜向圆角条纹 / 噪点渐变 / 网格线 / 同心弧),
  用标题字符串作种子派生配色,同种子像素级确定——纯函数派生+渲染,
  DOM 只留在薄薄一层出口,Node 侧可直接验确定性;色相按前缀分桶,
  同系列标题自动落在相邻色区
- Unsplash 搜索:Access Key 读 VITE_UNSPLASH_KEY,未配置只显示提示、
  另两个来源照常可用;缩略图网格点选装 regular 尺寸;选定即触发
  download 统计(条款义务);署名不画进图,面板上给复制按钮
This commit is contained in:
2026-09-04 16:10:37 +08:00
parent 95eeb69ff8
commit d072067b00
5 changed files with 1152 additions and 22 deletions
+29 -14
View File
@@ -1,18 +1,33 @@
import type { BackgroundAsset } from "@/types";
/**
* 【T4 待实现 — 背景来源】
* 背景来源汇总出口。
*
* 三个来源各写一个模块,都返回 BackgroundAsset:
* - upload.ts 本地文件 -> object URL
* - geometry.ts 预设几何底纹,程序生成(画到离屏 canvas 再 toDataURL)
* - unsplash.ts Unsplash 搜索。Access Key 从 import.meta.env.VITE_UNSPLASH_KEY 读,
* 放 .env.local(已 gitignore)。条款强制署名,返回时填 attribution。
* 三个来源各写一个模块,都返回/产出 `BackgroundAsset`(形状见 `@/types`):
* - upload.ts 本地文件 → object URL
* - geometry.ts 预设几何底纹:纯函数派生+渲染,DOM 只出现在薄薄一层
* - unsplash.ts Unsplash 搜索。Access Key 从 `import.meta.env.VITE_UNSPLASH_KEY` 读
*
* SourcePanel 按需从子模块直接 import;这里只是把表面聚成一个稳定出口,
* 供面板以外的地方统一消费。
*/
export async function fromUpload(_file: File): Promise<BackgroundAsset> {
throw new Error("T4 未实现:fromUpload");
}
export async function searchUnsplash(_query: string): Promise<BackgroundAsset[]> {
throw new Error("T4 未实现:searchUnsplash");
}
export { fromUpload, releaseObjectUrl } from "./upload";
export {
deriveGeometryParams,
renderGeometry,
geometryToDataUrl,
createGeometryAsset,
GEOMETRY_KINDS,
} from "./geometry";
export type { GeometryParams, GeometryKind, RGB } from "./geometry";
export {
unsplashStatus,
searchUnsplash,
trackDownload,
toAsset,
UnsplashError,
} from "./unsplash";
export type { UnsplashStatus, UnsplashPhoto } from "./unsplash";
export type { BackgroundAsset, Attribution } from "../types";