feat: 图库双源接入(Pexels+Unsplash,统一 PhotoProvider)与几何预设扩充

- providers.ts: PHOTO_PROVIDERS 注册表,Pexels 在前(dev 速率高);providerById
- unsplash.ts: 改造成 PhotoProvider(parseUnsplashResponse/unsplashProvider/
  notifyDownload),共享 PhotoProviderError 定义在此叶模块避免注册表互引成环;
  legacy searchUnsplash/unsplashStatus/toAsset/trackDownload 保留(基座旧
  SourcePanel 还在用,删了这轮 typecheck 过不了)
- pexels.ts(新): parsePexelsResponse 纯函数 + pexelsProvider;Authorization 头;
  fullUrl 取 large2x(≈1880)不取原图;无下载统计端点,不实现 notifyDownload
- 没配 key 一律静默 missing,search 抛 PhotoProviderError,模块顶层不抛
- geometry.ts: 新增 GEOMETRY_PRESETS 16 条(固定图案+人工配色,新背景菜单卡片
  数据源)+ 4 个新图案家族(waves/dots/horizon/glow)渲染,复用线性亮度钳制
  保证白字对比度;公开 GeometryKind 不动(旧面板缩略图字典闭合),遗留种子机制
  原样;导出 contrastToWhite/relativeLuminance 供自验
- selfcheck: 手写官方形状样本断言两家解析、缺失态/错误类、预设数量与对比度
This commit is contained in:
2026-09-05 18:24:11 +08:00
parent 19c8c604cb
commit 83f27d9e90
6 changed files with 960 additions and 83 deletions
+35 -9
View File
@@ -1,33 +1,59 @@
/**
* 背景来源汇总出口。
*
* 三个来源各写一个模块,都返回/产出 `BackgroundAsset`(形状见 `@/types`):
* 各来源都写成一个自包含模块,统一产出 `BackgroundAsset`(形状见 `@/types`):
* - upload.ts 本地文件 → object URL
* - geometry.ts 预设几何底纹:纯函数派生+渲染,DOM 只出现在薄薄一层
* - unsplash.ts Unsplash 搜索。Access Key 从 `import.meta.env.VITE_UNSPLASH_KEY` 读
* - geometry.ts 预设几何底纹:纯函数派生 + 渲染;`GEOMETRY_PRESETS` 是
* 新背景菜单的卡片数据源(固定图案 + 人工配色,无种子),
* `GEOMETRY_KINDS` 是 legacy 的种子随机配色 4 种
* - pexels.ts / unsplash.ts 图库搜索,都实现 `PhotoProvider` 接口,
* Pexels 在前(`PHOTO_PROVIDERS` 见 providers.ts)
*
* SourcePanel 按需从子模块直接 import;这里只是把表面聚成一个稳定出口,
* 供面板以外的地方统一消费。
* T4 时代的 legacy 函数面(`searchUnsplash` / `toAsset` 等)保留到旧
* SourcePanel 被 t13 清掉为止;新界面一律走 `PHOTO_PROVIDERS`。
*/
export { fromUpload, releaseObjectUrl } from "./upload";
export { fromUpload, releaseObjectUrl, pickImageFiles } from "./upload";
export {
deriveGeometryParams,
derivePresetParams,
renderGeometry,
geometryToDataUrl,
createGeometryAsset,
createPresetAsset,
GEOMETRY_KINDS,
GEOMETRY_PRESETS,
contrastToWhite,
relativeLuminance,
} from "./geometry";
export type {
GeometryParams,
GeometryKind,
RenderKind,
GeometryPreset,
RGB,
} from "./geometry";
export type { GeometryParams, GeometryKind, RGB } from "./geometry";
export {
unsplashStatus,
searchUnsplash,
trackDownload,
toAsset,
UnsplashError,
parseUnsplashResponse,
unsplashProvider,
} from "./unsplash";
export type { UnsplashStatus, UnsplashPhoto } from "./unsplash";
export type { BackgroundAsset, Attribution } from "../types";
export { parsePexelsResponse, pexelsProvider } from "./pexels";
export { PHOTO_PROVIDERS, providerById, PhotoProviderError } from "./providers";
export type {
BackgroundAsset,
Attribution,
StockPhoto,
PhotoProvider,
PhotoProviderId,
PhotoProviderStatus,
} from "../types";