feat(posters): 接入 Base16 主题配色库(276 套 16 色方案)
- 新增 format transform: 'base16'(YAML → 结构化 JSON),零依赖逐行解析 palette.base00–base0F - 新增源 base16-schemes(MIT,tinted-theming/schemes@spec-0.11,276/277 通过率 99.6%) - 海报 palette 由 31 → 307 条,库总计 71 源 / 11,598 素材 - 结构校验:276 唯一 id、0 结构异常、198 套 dark 变体;版本联动 20261108f
This commit is contained in:
@@ -265,6 +265,12 @@ async function downloadGhFiles(src) {
|
||||
file = r.file.replace(/\.js$/i, '.svg');
|
||||
buf = Buffer.from(svg, 'utf8');
|
||||
}
|
||||
if (src.transform === 'base16') {
|
||||
const json = transformBase16(r.buf);
|
||||
if (!json) { fail++; continue; }
|
||||
file = r.file.replace(/\.ya?ml$/i, '.json');
|
||||
buf = Buffer.from(JSON.stringify(json), 'utf8');
|
||||
}
|
||||
const c = classifyPoster(name);
|
||||
const it = await buildItem(src, name, file, buf, c);
|
||||
if (it) { items.push(it); ok++; } else fail++;
|
||||
@@ -490,6 +496,31 @@ async function readLocalFiles(src) {
|
||||
* `url('data:image/svg+xml,%3Csvg%20width...%3E')`
|
||||
* 处理:剥离 import(依赖注入 sandbox)、以默认黑色调用函数、URL 解码出 <svg>…</svg>
|
||||
*/
|
||||
/**
|
||||
* Base16 配色方案(tinted-theming/schemes 的 base16/*.yaml)→ 结构化 JSON
|
||||
* YAML 结构固定:system/name/author/variant + palette.base00–base0F,逐行正则解析即可(不引依赖)
|
||||
*/
|
||||
function transformBase16(buf) {
|
||||
const text = buf.toString('utf8');
|
||||
const get = (key) => {
|
||||
const m = text.match(new RegExp('^' + key + ':\\s*"?([^"\\n]+)"?\\s*$', 'm'));
|
||||
return m ? m[1].trim() : '';
|
||||
};
|
||||
const name = get('name');
|
||||
if (!name) return null;
|
||||
const colors = {};
|
||||
const re = /^\s*base(0[0-9a-fA-F]):\s*"?(#[0-9a-fA-F]{3,8})"?/gm;
|
||||
let m;
|
||||
while ((m = re.exec(text))) colors['base' + m[1].toUpperCase()] = m[2];
|
||||
if (Object.keys(colors).length < 8) return null; // 至少 8 色才算有效方案
|
||||
return {
|
||||
scheme: name,
|
||||
author: get('author'),
|
||||
variant: get('variant') || 'dark',
|
||||
colors
|
||||
};
|
||||
}
|
||||
|
||||
function transformHeroPatterns(buf) {
|
||||
let code = buf.toString('utf8');
|
||||
code = code.replace(/^import\s+[^\n]*$/gm, ''); // 去掉 import 语句
|
||||
@@ -529,6 +560,7 @@ async function buildItem(src, name, filePath, buf, c) {
|
||||
const ext = path.extname(filePath).toLowerCase();
|
||||
// 字体素材不做应用场景推断(避免名称误命中词表,如 LeagueSpartan 含 "spa" → 医疗健康),统一归「字体排版」
|
||||
if (src.type === 'font') c = { cat: 'font', cn: '字体排版' };
|
||||
if (src.type === 'palette') c = { cat: 'palette', cn: '配色方案' };
|
||||
const base = { id: `${src.id}:${name}`, name, type: src.type, category: c.cat, categoryCn: c.cn, workspaces: src.workspaces || ['poster'] };
|
||||
|
||||
if (ext === '.svg') {
|
||||
|
||||
Reference in New Issue
Block a user