| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- # 生成 packages/chat-ui/src/keyline-avatars.ts(机器人头像图标)
- # 用法:npm pack @iconify-json/keyline-icons@1.2.18 && tar xzf iconify-json-keyline-icons-1.2.18.tgz
- # python3 scripts/gen-keyline-avatars.py package/icons.json packages/chat-ui/src/keyline-avatars.ts
- import json, re, sys
- src, out = sys.argv[1], sys.argv[2]
- d = json.load(open(src))['icons']
- groups = [
- ('助手', 'bot bot-simple bot-square bot-circle bot-message bot-heart bot-star bot-cloud'),
- ('智能', 'bot-droplet brain brain-sparkles brain-circuit brain-cog cpu-sparkles message-sparkles wand-sparkles'),
- ('人物', 'user user-cog user-sparkles user-shield user-search user-pen user-voice headset'),
- ('数据', 'bar-chart chart-pie chart-area database table calculator coins scale'),
- ('文档', 'file file-chart-column book-open notebook-pen pen clipboard-list sticky-note folder-open'),
- ('技术', 'code terminal server cloud cpu bug wrench toolbox'),
- ('运维', 'shield-check lock key-round settings plug briefcase factory truck'),
- ('沟通', 'mail message megaphone bell calendar clock send inbox'),
- ('目标', 'rocket lightbulb target trophy crown sparkles flame star'),
- ('探索', 'globe compass map search flask-conical atom palette puzzle'),
- ]
- icons = {}
- for _, names in groups:
- for n in names.split():
- body = d[n]['body']
- # 只允许纯图形:没有脚本、事件属性、外部引用
- assert not re.search(r'<script|\son\w+=|href|url\(|<foreignObject', body, re.I), n
- assert set(re.findall(r'<(\w+)', body)) <= {'g', 'path', 'circle', 'rect', 'ellipse', 'line', 'polyline', 'polygon'}, (n, set(re.findall(r'<(\w+)', body)))
- icons[n] = body
- license = '''MIT License
- Copyright (c) 2026 Keyline Icons
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
- The above copyright notice and this permission notice shall be included in all
- copies or substantial portions of the Software.
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- SOFTWARE.'''
- lines = ['// 机器人头像图标:Keyline Icons(https://keylineicons.com)的线条样式(stroke 2),24×24,取自 @iconify-json/keyline-icons 1.2.18。',
- '// 由 scripts/gen-keyline-avatars.py 生成,只收录头像用到的图标;新增图标时重新生成,不要手工修改 SVG。',
- '/*', *(' * ' + l if l else ' *' for l in license.splitlines()), ' */', '',
- '/** 头像选择面板中的分组(顺序即显示顺序) */',
- 'export const KEYLINE_AVATAR_GROUPS: { label: string; icons: string[] }[] = [']
- for label, names in groups:
- lines.append(f" {{ label: '{label}', icons: [{', '.join(repr(n) for n in names.split())}] }},")
- lines += [']', '', '/** 图标名称 → SVG 内容(viewBox 0 0 24 24,颜色为 currentColor) */', 'export const KEYLINE_AVATAR_SVGS: Record<string, string> = {']
- for n, b in icons.items():
- lines.append(f" {json.dumps(n)}: {json.dumps(b, ensure_ascii=False)},")
- lines += ['}', '']
- open(out, 'w').write('\n'.join(lines).replace("['", "['").replace("', '", "', '"))
- print(len(icons), 'icons')
|