Files
drawlogo/js/skills/ai.js
T

225 lines
12 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.
/**
* 画个标 · 技能库:AI 工作流类(ai)
* 注册:HGB_Skills.register([...])
*/
(function () {
'use strict';
HGB_Skills.register([
{
id: 'ai-workflow',
name: 'AI 品牌设计工作流',
category: 'ai',
emoji: '🤖',
scene: '从品牌简报 → AI 生成 → 校验 → 迭代的全流程设计',
summary: '借鉴 9 阶段专业工作流(需求采集/方向/配色策略/排版/交付/迭代),驱动 DeepSeek 完成智能设计并在渲染层自动校验修正。',
params: [
{ name: 'brand', type: 'string', required: true, desc: '品牌名' },
{ name: 'industry', type: 'string', required: true, desc: '行业 id' },
{ name: 'desc', type: 'string', required: false, desc: '品牌描述' }
],
source: 'GitHub: atypica-ai/logo-design-skill(9 阶段工作流)',
run: function (args) {
const ind = HGB_Industries.find(x => x.id === args.industry) || HGB_Industries[0];
const brand = String(args.brand || '');
const desc = String(args.desc || '');
const stages = [
{ phase: '1 需求采集', out: `${brand} / ${ind.name} / ${desc || '行业默认'}` },
{ phase: '2 方向探索', out: '由 DeepSeek 基于品牌描述确定设计方向(AI 生成 5 套)' },
{ phase: '3 图标选择', out: 'AI 从内置库按语义匹配图标' },
{ phase: '4 配色策略', out: '行业配色 + 描述色系偏好 + WCAG 对比度校验' },
{ phase: '5 排版实施', out: '布局模板 + 字号自适应 + 构图审计' },
{ phase: '6 交付迭代', out: '方案库一屏展示 + 换配色/布局变体 + 导出' }
];
return { workflow: stages, model: HGB_AI.getModel(), keyConfigured: HGB_AI.hasKey() };
},
test: function () {
return { model: HGB_AI.getModel(), stages: this.run({ brand: '远渡教育', industry: 'edu' }).workflow.length };
}
},
{
id: 'brand-brief',
name: '品牌简报解析',
category: 'ai',
emoji: '📋',
scene: '解析品牌描述,提炼设计关键词与方向',
summary: '将用户自然语言品牌描述解析为结构化简报:行业倾向、色系偏好、气质关键词、适用场景,供 AI 生成与人工确认。',
params: [
{ name: 'desc', type: 'string', required: true, desc: '品牌描述(自然语言)' }
],
source: '自研(关键词启发式解析)',
run: function (args) {
const desc = String(args.desc || '');
const D = desc.toLowerCase();
const indMap = [
{ kw: ['教育', '学习', '培训', '学校'], ind: 'edu' },
{ kw: ['餐饮', '美食', '烘焙', '咖啡', '餐厅'], ind: 'food' },
{ kw: ['医疗', '健康', '诊所', '药'], ind: 'health' },
{ kw: ['科技', '软件', '互联网', 'AI', '数码'], ind: 'tech' },
{ kw: ['运动', '健身', '体育'], ind: 'sport' },
{ kw: ['金融', '投资', '银行', '财富'], ind: 'finance' }
];
const ind = indMap.find(m => m.kw.some(k => desc.includes(k)));
const toneMap = [
{ kw: ['高端', '奢华', '优雅', '专业'], tone: '高端专业' },
{ kw: ['活力', '年轻', '热情', '潮流'], tone: '年轻活力' },
{ kw: ['温馨', '治愈', '亲切', '温暖'], tone: '温馨亲切' },
{ kw: ['科技', '未来', '极简', '现代'], tone: '科技极简' },
{ kw: ['自然', '环保', '清新', '绿色'], tone: '自然清新' }
];
const tone = toneMap.find(m => m.kw.some(k => desc.includes(k)));
const colorMap = [
{ kw: ['蓝'], color: '蓝色系' }, { kw: ['红'], color: '红色系' },
{ kw: ['绿'], color: '绿色系' }, { kw: ['橙', '橘'], color: '橙色系' },
{ kw: ['紫'], color: '紫色系' }, { kw: ['金', '黄'], color: '金色/黄色系' },
{ kw: ['黑', '灰'], color: '黑灰系' }, { kw: ['白'], color: '白色系' }
];
const color = colorMap.find(m => m.kw.some(k => desc.includes(k)));
return {
desc: desc || '(空)',
industry: ind ? ind.ind : '(未识别,默认通用)',
tone: tone ? tone.tone : '(未识别,默认通用)',
color: color ? color.color : '(未指定,智能匹配)',
keywords: desc.split(/[,,。\s]+/).filter(Boolean).slice(0, 6)
};
},
test: function () {
return this.run({ desc: '一家高端优雅的蓝色科技教育品牌' });
}
},
{
id: 'slogan-gen',
name: '品牌标语生成',
category: 'ai',
emoji: '💬',
scene: '基于品牌名与行业生成英文品牌标语',
summary: '按行业气质与品牌名生成 3 条英文 Slogan 候选(形容词 + 品牌名 + 场景短语结构),附中文释义,供副标题/宣传使用。',
params: [
{ name: 'brand', type: 'string', required: true, desc: '品牌名(英文或拼音)' },
{ name: 'industry', type: 'string', required: false, desc: '行业 id' }
],
source: '自研(标语模板引擎)',
run: function (args) {
const brand = String(args.brand || '');
const ind = HGB_Industries.find(x => x.id === args.industry) || HGB_Industries[0];
const styleMap = {
edu: { adj: ['Bright', 'Wise', 'Future-ready'], phrase: 'Learn Beyond Limits', zh: '学无止境' },
food: { adj: ['Fresh', 'Tasty', 'Warm'], phrase: 'Taste the Moment', zh: '品味当下' },
health: { adj: ['Gentle', 'Careful', 'Vital'], phrase: 'Care for Life', zh: '守护生命' },
tech: { adj: ['Smart', 'Swift', 'Next-gen'], phrase: 'Innovate Forward', zh: '创新向前' },
sport: { adj: ['Strong', 'Swift', 'Relentless'], phrase: 'Push Your Limits', zh: '突破极限' },
finance: { adj: ['Secure', 'Stable', 'Wealth-wise'], phrase: 'Grow with Trust', zh: '信任成长' }
};
const st = styleMap[ind.id] || { adj: ['Great', 'Remarkable', 'Beyond'], phrase: 'Make It Stand Out', zh: '与众不同' };
const en = /^[a-zA-Z0-9\s.-]+$/.test(brand) ? brand.toUpperCase() : (brand || 'BRAND');
const slogans = st.adj.map(a => a + ' ' + en + ' — ' + st.phrase);
return { brand: en, industry: ind.name, slogans, zh: st.zh };
},
test: function () {
return this.run({ brand: 'NEXUS', industry: 'tech' });
}
},
{
id: 'prompt-craft',
name: 'AI 提示词工坊',
category: 'ai',
emoji: '🧪',
scene: '把品牌需求编译成可直接提交 DeepSeek 的提示词',
summary: '将品牌名/行业/描述/偏好转译为结构化 AI 提示词(风格/布局/图标/字体),与内置 AI 生成器同源规范,可复制使用。',
params: [
{ name: 'brand', type: 'string', required: true, desc: '品牌名' },
{ name: 'industry', type: 'string', required: false, desc: '行业 id' },
{ name: 'desc', type: 'string', required: false, desc: '品牌描述' },
{ name: 'styleId', type: 'string', required: false, desc: '风格 id(可选)' }
],
source: '自研(与 HGB_AIDesigner.buildPrompt 同源)',
run: function (args) {
const brand = String(args.brand || '');
const ind = HGB_Industries.find(x => x.id === args.industry) || HGB_Industries[0];
const style = HGB_Styles.find(s => s.id === args.styleId) || null;
const prompt = [
'你是资深品牌设计师。为品牌「' + brand + '」设计一套 LOGO。',
'行业:' + ind.name,
'品牌描述:' + (args.desc || '无'),
'请输出 JSON:{styleId, layoutId, iconId(可选), fontFamily, 主色建议}',
'约束:极简、充足负空间、可缩放至 64px 仍清晰、不使用渐变描边。'
].join('\n');
return {
brand, industry: ind.name, style: style ? style.name : '(自动)',
prompt,
model: HGB_AI.getModel(),
copyable: true
};
},
test: function () {
const r = this.run({ brand: '远渡教育', industry: 'edu', desc: '高端教育品牌' });
return { lines: r.prompt.split('\n').length, model: r.model, style: r.style };
}
},
{
id: 'ai-iterate',
name: 'AI 迭代方案',
category: 'ai',
emoji: '🔄',
scene: '根据审计结果生成方案的迭代改进步骤',
summary: '汇总构图/配色/字体/图标等技能审计结论,转化为按优先级排序的迭代动作,指导用户快速改进方案。',
params: [
{ name: 'plan', type: 'object', required: true, desc: '方案对象' },
{ name: 'audits', type: 'object', required: false, desc: '各技能审计结果 {skillId: result}' }
],
source: '自研(审计 → 迭代动作编排)',
run: function (args) {
const audits = args.audits || {};
const steps = [];
for (const [sid, r] of Object.entries(audits)) {
if (r && r.pass === false && (r.verdict || r.issues)) {
steps.push({ skill: sid, action: r.verdict || (Array.isArray(r.issues) ? r.issues.join(';') : '见审计详情'), priority: sid === 'composition' ? '高' : '中' });
}
}
if (!steps.length) steps.push({ skill: '-', action: '各项审计均通过,可尝试换配色/布局体验更多变体', priority: '低' });
return { total: steps.length, steps, order: '按「高→低」优先级逐条执行后重新生成预览' };
},
test: function () {
return this.run({ audits: { composition: { pass: false, verdict: '存在元素重叠,请加大间距' }, contrast: { pass: true }, spacing: { pass: false, issues: ['留白不足'] } } });
}
},
{
id: 'concept-words',
name: '品牌概念词联想',
category: 'ai',
emoji: '💡',
scene: '从品牌名 + 行业发散概念关键词(供 AI Prompt / 图标检索使用)',
summary: '基于行业联想词库 + 品牌名首字拆解,输出名词/特质/场景三类概念词:直接喂给 AI Prompt 或图标检索,让生成方向更聚焦。',
params: [
{ name: 'brand', type: 'string', required: true, desc: '品牌名' },
{ name: 'industry', type: 'string', required: false, desc: '行业 id' }
],
source: '自研(行业概念词库 + 词根拆解)',
run: function (args) {
const brand = String(args.brand || '');
const ind = HGB_Industries.find(x => x.id === args.industry) || HGB_Industries[0];
const BANK = {
edu: { noun: ['书本', '毕业帽', '铅笔', '阶梯', '灯塔'], trait: ['专业', '求知', '成长'], scene: ['教室', '图书馆'] },
food: { noun: ['餐具', '锅铲', '食材', '火焰', '餐盘'], trait: ['温暖', '食欲', '烟火气'], scene: ['厨房', '餐桌'] },
health: { noun: ['十字', '爱心', '叶子', '药丸', '听诊器'], trait: ['健康', '治愈', '可靠'], scene: ['诊室', '自然'] },
tech: { noun: ['芯片', '齿轮', '闪电', '终端', '云朵'], trait: ['创新', '极客', '高效'], scene: ['机房', '代码'] },
sport: { noun: ['奖杯', '速度', '球', '火焰', '奖牌'], trait: ['活力', '拼搏', '突破'], scene: ['赛场', '跑道'] },
finance: { noun: ['盾牌', '钱币', '上升线', '钥匙', '建筑'], trait: ['稳健', '财富', '信任'], scene: ['银行', '投资'] }
};
const hit = BANK[ind.id] || { noun: ['星星', '圆环', '翅膀', '箭头', '闪电'], trait: ['创意', '独特', '进取'], scene: ['灵感', '未来'] };
const cjk = brand.match(/[\u4e00-\u9fa5]/g);
const initial = cjk ? cjk[0] : (brand.slice(0, 1) || '').toUpperCase();
return {
brand, industry: ind.name, initial,
noun: hit.noun, trait: hit.trait, scene: hit.scene,
suggested: hit.noun.slice(0, 3).concat(hit.trait.slice(0, 2)).join('、'),
note: '概念词可直接用于 AI Prompt(主题/气质/场景)或图标检索关键词'
};
},
test: function () {
return { food: this.run({ brand: '香满堂', industry: 'food' }).suggested, tech: this.run({ brand: '云帆', industry: 'tech' }).noun.length };
}
}
]);
})();