Files
drawlogo/js/poster-skills/core.js
T

50 lines
2.0 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* 画个标 · 海报技能资源库(核心:注册表 + 通用工具)
* 海报专属技能,分 8 类:layout(版式构图) color(配色) typography(字体排版)
* grid(网格系统) hierarchy(视觉层级) print(印刷输出) creative(创意手法) ai(智能工作流)
*
* 与共享技能库(HGB_Skills)的复用与区分:
* - 复用:共享技能库的构图/配色/字体等通用技能跨工作区复用(HGB_Skills.forWorkspace)
* - 区分:本库收录海报专属技能,统一 workspaces:['poster'];按分类拆分 js/poster-skills/{category}.js
* 每个技能标准化字段:id / name / category / emoji / scene / summary / params / source / run / test
*/
const HGB_PosterSkills = (function () {
'use strict';
const skills = [];
const DEFAULT_WORKSPACES = ['poster'];
function register(defs) {
for (const d of (defs || [])) skills.push(d);
return skills.length;
}
function all() { return skills; }
function categories() {
const map = {};
for (const s of skills) map[s.category] = (map[s.category] || 0) + 1;
return Object.entries(map).map(([id, count]) => ({ id, count }));
}
function get(id) { return skills.find(s => s.id === id) || null; }
function run(id, args) {
const s = get(id);
if (!s) return { error: '海报技能不存在: ' + id };
try { return s.run(args || {}); }
catch (e) { return { error: '海报技能执行失败: ' + e.message }; }
}
function test(id) {
const s = get(id);
if (!s) return { error: '海报技能不存在: ' + id };
try { return s.test ? s.test() : { note: '该技能未提供自测' }; }
catch (e) { return { error: '海报技能自测失败: ' + e.message }; }
}
function workspacesOf(id) {
const s = get(id);
return (s && s.workspaces) || DEFAULT_WORKSPACES;
}
function forWorkspace(ws) {
return skills.filter(s => workspacesOf(s.id).includes(ws));
}
return { register, all, categories, get, run, test, workspacesOf, forWorkspace };
})();