From c90a2c444679060a87cf78ceeffac5ab64fdb9f6 Mon Sep 17 00:00:00 2001 From: "mula.liu" Date: Tue, 3 Nov 2026 10:15:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A3=80=E6=9F=A5=E7=82=B9=EF=BC=9A=E4=BF=9D?= =?UTF-8?q?=E7=95=99=E6=89=8B=E5=86=99=E5=9B=BE=E6=A0=87=E4=BD=93=E7=B3=BB?= =?UTF-8?q?=E4=B8=8E=E5=B0=BA=E5=AD=90=EF=BC=8C=E4=BD=9C=E4=B8=BA=20antd?= =?UTF-8?q?=20=E9=87=8D=E5=86=99=E7=9A=84=E5=AF=B9=E7=85=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/components/icons/Icon.tsx | 78 +++++++++++++++ frontend/src/components/icons/glyphs.ts | 128 ++++++++++++++++++++++++ frontend/src/components/icons/index.ts | 4 + frontend/src/styles/app.css | 10 ++ frontend/src/theme/metrics.ts | 31 ++++++ 5 files changed, 251 insertions(+) create mode 100644 frontend/src/components/icons/Icon.tsx create mode 100644 frontend/src/components/icons/glyphs.ts create mode 100644 frontend/src/components/icons/index.ts diff --git a/frontend/src/components/icons/Icon.tsx b/frontend/src/components/icons/Icon.tsx new file mode 100644 index 0000000..2d6ccfe --- /dev/null +++ b/frontend/src/components/icons/Icon.tsx @@ -0,0 +1,78 @@ +/** + * Icon:全站唯一的图标渲染器(图形来自 ./glyphs,尺子来自 ../../theme/metrics)。 + * + * 为什么要有这一只组件:图标以前是**写在文字里的 Unicode 字符**, + * 于是同一站里「关闭」有四五种长相——字号随手写、粗细由字体决定、 + * emoji(🎙🔊👁🗑📝🎥)在 macOS 上直接渲染成彩色贴图,深色主题下亮成一块。 + * 现在图形是 24×24 的 SVG,颜色只有 currentColor,粗细由尺寸档算出来, + * 页面能选的只有「哪个图形、哪一档、什么颜色(继承)」。 + * + * 用法约定(docs/UI规范.md §8): + * · `size` 取六档之一,按**所在容器**选:标签 xs / 紧凑控件与菜单行 sm / + * 主档控件 md / 左导航与页签 lg / 卡片标题 xl / 空状态与帮助步骤 2xl; + * · `label` 只给「图标自己就是全部内容」的地方(会输出 role=img + ); + * 挨着文字放的一律不写 label,图标自动 aria-hidden,读屏只念文字; + * · 颜色不传:靠容器文字色,hover / 选中 / 危险态因此自动跟着走。 + * · `name` 写错在 DEV 会 console.error——audit 的第 6 项判据(console 干净)会当场抓住。 + */ +import { type CSSProperties } from 'react' +import { icon, iconStrokeAt, type IconSize } from '../../theme/metrics' +import { cn } from '../../lib/cn' +import { glyphs, type IconName } from './glyphs' + +export type { IconName } + +export type IconProps = { + name: IconName | string + /** 六档之一;传数字是给「贴图必须和某个既有高度严丝合缝」的例外,页面里几乎没有 */ + size?: IconSize | number + /** 图标自己就是全部内容时给名字;纯装饰一律不写 */ + label?: string + /** 等后台的转圈(配 refresh / hourglass / loader 用) */ + spin?: boolean + className?: string + style?: CSSProperties +} + +export function iconPx(size: IconSize | number = 'md'): number { + return typeof size === 'number' ? size : icon[size] +} + +export function Icon({ name, size = 'md', label, spin, className, style }: IconProps) { + const px = iconPx(size) + // viewBox 固定 24,描边按边长反算,六档看起来才是同一条线 + const sw = (iconStrokeAt(px) * 24) / px + const g = (glyphs as Record<string, any>)[name as string] + + if (!g) { + if (import.meta.env.DEV) console.error(`未知图标名: "${name}"(见 components/icons/glyphs.ts)`) + return ( + <svg className={cn('nex-icon', className)} viewBox="0 0 24 24" width={px} height={px} + fill="none" stroke="currentColor" strokeWidth={sw} strokeDasharray="3 3" + aria-hidden={label ? undefined : true} role={label ? 'img' : undefined} focusable="false" style={style}> + <rect x="3.5" y="3.5" width="17" height="17" rx="3" /> + </svg> + ) + } + + const stroke = { fill: 'none' as const, stroke: 'currentColor' as const } + const solid = { fill: 'currentColor' as const, stroke: 'currentColor' as const, strokeWidth: sw * 0.6 } + + return ( + <svg className={cn('nex-icon', spin && 'nex-icon-spin', className)} viewBox="0 0 24 24" + width={px} height={px} fill="none" stroke="currentColor" strokeWidth={sw} + strokeLinecap="round" strokeLinejoin="round" aria-hidden={label ? undefined : true} + role={label ? 'img' : undefined} focusable="false" style={style}> + {label ? <title>{label} : null} + {g.lines?.map((d: string, i: number) => )} + {g.rects?.map(([x, y, w, h, r]: number[], i: number) => )} + {g.dots?.map(([cx, cy, r]: number[], i: number) => )} + {g.dashed && } + {g.solids?.map((d: string, i: number) => )} + {g.srects?.map(([x, y, w, h, r]: number[], i: number) => )} + {g.spots?.map(([cx, cy, r]: number[], i: number) => )} + + ) +} + +export default Icon diff --git a/frontend/src/components/icons/glyphs.ts b/frontend/src/components/icons/glyphs.ts new file mode 100644 index 0000000..4391ef3 --- /dev/null +++ b/frontend/src/components/icons/glyphs.ts @@ -0,0 +1,128 @@ +/** + * 图标表:全站唯一的图标来源(24×24 网格 / 视觉描边等宽 / currentColor)。 + * + * 为什么自己画而不用图标库: + * · 换 antd 之前全站 60 多个图标是 Unicode 字符(⌂ ✧ ◫ ✕ ▶ ▧ ◉ ♫ ⇪ ⇶ ⏻ ⌄ …), + * 粗细由字体决定、emoji 类(🎙🔊👁🗑)在 macOS 上会被渲染成彩色贴图, + * 同一个「关闭」在抽屉里是 ✕、在胶囊上又成了 ×; + * · 成套库(lucide / heroicons / tabler)能解决渲染,但它们的画法是通用办公软件的 + * 词汇,我们的七个业务环节(分镜、调度、时间线合成、导出成本)没有对应图形, + * 补齐又要引第二套画法——两套画法就是我们刚刚花一整轮删掉的东西。 + * · 自绘的代价很小:一张表、一套几何约定、零运行时依赖(antd 的图标包只留了一颗)。 + * + * 几何约定(改图标前先读这段): + * 1) 网格 24×24,可视区留 2px 内缩(内容落在 2~22),这样 12px 与 24px 的两档边距一致; + * 2) 一律描边(fill:none / stroke:currentColor),只有播放、暂停、圆点这类 + * 「必须实心才认得出」的形状走 solids / srects / spots; + * 3) 圆角与本站尺子对齐:容器类矩形 r=2.2~2.8(对应 radius.control=7 的手感), + * 小方块 r≈1,端点与拐角全部 round(在 Icon.tsx 上统一给,别在每个形状上写); + * 4) 不写颜色:颜色永远继承容器文字色,明暗主题与 hover 因此自动跟着走; + * 5) 同一族图标共用骨架(媒体族共用 3.4~20.6 的外框、动作族共用 4.4~19.6 的十字), + * 加新图标请从同族复制再改局部,别从空白开始画。 + */ + +/** lines=描边路径;rects/dots=描边形;solids/srects/spots=实心;dashed=虚线圆(读作「样本 / 非参考」) */ +export type Glyph = { + lines?: string[] + rects?: [x: number, y: number, w: number, h: number, r: number][] + dots?: [cx: number, cy: number, r: number][] + solids?: string[] + srects?: [x: number, y: number, w: number, h: number, r: number][] + spots?: [cx: number, cy: number, r: number][] + dashed?: [cx: number, cy: number, r: number] +} + +export const glyphs = { + /* ── 导航:全局三项 + 项目七个环节(侧栏、帮助页、控制台共用同一批图形) ── */ + dashboard: { rects: [[3.2, 3.2, 7, 8.2, 2.2], [13.8, 3.2, 7, 4.4, 2.2], [13.8, 10.8, 7, 10, 2.2], [3.2, 14.6, 7, 6.2, 2.2]] }, + archive: { rects: [[3.6, 4.4, 16.8, 3.8, 1.4]], lines: ['M5.4 8.2v10a2.2 2.2 0 0 0 2.2 2.2h8.8a2.2 2.2 0 0 0 2.2-2.2v-10', 'M9.8 12.2h4.4'] }, + cpu: { rects: [[7.4, 7.4, 9.2, 9.2, 2.2], [10.8, 10.8, 2.4, 2.4, 0.8]], lines: ['M10.4 3.4v4M13.6 3.4v4M10.4 16.6v4M13.6 16.6v4M3.4 10.4h4M3.4 13.6h4M16.6 10.4h4M16.6 13.6h4'] }, + hub: { dots: [[12, 12, 2.7], [5.6, 5.6, 2], [18.4, 5.6, 2], [12, 18.6, 2]], lines: ['M7.1 7.1l3.4 3.4M16.9 7.1l-3.4 3.4M12 16.6v-2'] }, + layers: { lines: ['M12 3.4 20.6 8 12 12.6 3.4 8Z', 'M3.4 12.2 12 16.8l8.6-4.6', 'M3.4 16.2 12 20.8l8.6-4.6'] }, + frames: { rects: [[3, 5.6, 18, 12.8, 2.4]], lines: ['M9 5.6v12.8M15 5.6v12.8', 'M4.4 8.8h3.2M4.4 15.2h3.2M16.4 8.8h3.2M16.4 15.2h3.2'] }, + queue: { rects: [[3.4, 4.4, 3, 3, 1], [3.4, 10.5, 3, 3, 1], [3.4, 16.6, 3, 3, 1]], lines: ['M9.8 5.9h10.8M9.8 12h10.8M9.8 18.1h6.8'] }, + 'shield-check': { lines: ['M12 3.4 19.4 6.2v5.3c0 4.3-2.9 7.2-7.4 9.1-4.5-1.9-7.4-4.8-7.4-9.1V6.2Z', 'M8.6 11.8l2.6 2.6 4.4-4.7'] }, + timeline: { lines: ['M2.8 3.6v16.8'], rects: [[6.2, 5, 6.4, 4.8, 1.6], [16, 5, 4.8, 4.8, 1.6], [6.2, 14, 3.8, 4.8, 1.6], [13, 14, 7.8, 4.8, 1.6]] }, + export: { lines: ['M4.4 14.4v4.2a2.2 2.2 0 0 0 2.2 2.2h10.8a2.2 2.2 0 0 0 2.2-2.2v-4.2', 'M12 15.6V3.4', 'M7.4 8 12 3.4 16.6 8'] }, + + /* ── 媒体:播放控制与素材类型(缩略图角标、灯箱、试听行共用) ── */ + play: { solids: ['M8.6 5.2 18.9 12 8.6 18.8Z'] }, + pause: { srects: [[7.8, 5.4, 3, 13.2, 1.4], [13.2, 5.4, 3, 13.2, 1.4]] }, + stop: { srects: [[6.6, 6.6, 10.8, 10.8, 2.2]] }, + record: { spots: [[12, 12, 5]] }, + mic: { rects: [[9, 2.8, 6, 10.6, 3]], lines: ['M5.4 11.4a6.6 6.6 0 0 0 13.2 0', 'M12 18v2.6M8.6 20.6h6.8'] }, + waveform: { lines: ['M4 9.4v5.2M8 5.6v12.8M12 8.4v7.2M16 4.4v15.2M20 10v4'] }, + music: { dots: [[6.6, 17.4, 2.8], [15.6, 15, 2.8]], lines: ['M9.4 17.4V6.5l9-2.3v10.6'] }, + image: { rects: [[3.4, 4.8, 17.2, 14.4, 2.6]], dots: [[8.6, 9.6, 1.7]], lines: ['M4.4 17.4 9.6 12.2 13.4 15.6 16.6 12.8 20 16.2'] }, + video: { rects: [[3, 6.4, 12.6, 11.2, 2.6]], lines: ['M15.6 11.2 21 8v8l-5.4-3.2Z'] }, + subtitle: { rects: [[3, 5.6, 18, 12.8, 2.8]], lines: ['M10.4 10.6a2.7 2.7 0 1 0 0 2.8M16.6 10.6a2.7 2.7 0 1 0 0 2.8'] }, + volume: { lines: ['M4.4 9.4h3l4.6-3.9v13l-4.6-3.9h-3Z', 'M16.6 9.4a3.9 3.9 0 0 1 0 5.2', 'M19 6.8a7.4 7.4 0 0 1 0 10.4'] }, + + /* ── 动作 ─────────────────────────────────────────────────────────────── */ + plus: { lines: ['M12 4.8v14.4M4.8 12h14.4'] }, + minus: { lines: ['M4.8 12h14.4'] }, + close: { lines: ['M6.2 6.2 17.8 17.8M17.8 6.2 6.2 17.8'] }, + check: { lines: ['M4.8 12.6 9.8 17.6 19.2 6.6'] }, + 'check-circle': { dots: [[12, 12, 8.4]], lines: ['M8.2 12.2l2.9 2.9 5-5.4'] }, + edit: { lines: ['M4.6 19.4l1-4L16.1 4.9a2.1 2.1 0 0 1 3 3L8.6 18.4Z', 'M14.4 6.6l3 3'] }, + copy: { rects: [[8.6, 8.6, 11, 11, 2.6]], lines: ['M15.4 5.4H6.6a3 3 0 0 0-3 3v8.8'] }, + trash: { lines: ['M4.6 6.8h14.8', 'M9.6 6.8V4.9a1.1 1.1 0 0 1 1.1-1.1h2.6a1.1 1.1 0 0 1 1.1 1.1v1.9', 'M6.6 6.8l.8 12.1a1.7 1.7 0 0 0 1.7 1.6h5.8a1.7 1.7 0 0 0 1.7-1.6l.8-12.1', 'M10.4 10.6v6.2M13.6 10.6v6.2'] }, + backspace: { lines: ['M8.9 5.4H19a2 2 0 0 1 2 2v9.2a2 2 0 0 1-2 2H8.9L2.6 12Z', 'M12.2 9.6l4.4 4.8M16.6 9.6l-4.4 4.8'] }, + refresh: { lines: ['M20.5 12a8.5 8.5 0 1 1-2.6-6.1', 'M20.9 3.4v5h-5'] }, + reset: { lines: ['M3.5 12a8.5 8.5 0 1 0 2.6-6.1', 'M3.1 3.4v5h5'] }, + upload: { lines: ['M4.4 19.6h15.2', 'M12 16.2V3.6', 'M6.9 8.7 12 3.6l5.1 5.1'] }, + download: { lines: ['M4.4 19.6h15.2', 'M12 3.6v12.6', 'M6.9 10.5 12 15.6l5.1-5.1'] }, + external: { lines: ['M13.6 4.4h6v6', 'M19.6 4.4 11.2 12.8', 'M18 14.4v4.2a2.4 2.4 0 0 1-2.4 2.4H6.4A2.4 2.4 0 0 1 4 18.6V9.4A2.4 2.4 0 0 1 6.4 7h4.2'] }, + search: { dots: [[10.6, 10.6, 6.2]], lines: ['M15.2 15.2 20.2 20.2'] }, + eye: { lines: ['M2.6 12S6.4 5.6 12 5.6 21.4 12 21.4 12 17.6 18.4 12 18.4 2.6 12 2.6 12Z'], dots: [[12, 12, 3.1]] }, + 'eye-off': { lines: ['M4 4l16 16', 'M9.8 6.1A9.9 9.9 0 0 1 12 5.8c5.6 0 9.4 6.2 9.4 6.2a18.3 18.3 0 0 1-3.6 4.3', 'M6.5 8.1A17.6 17.6 0 0 0 2.6 12s3.8 6.2 9.4 6.2a9.6 9.6 0 0 0 3.5-.7', 'M10.2 10.3a2.9 2.9 0 0 0 3.6 4.2'] }, + sparkle: { solids: ['M9.9 3.2c.7 3.5 1.7 4.5 5.2 5.2-3.5.7-4.5 1.7-5.2 5.2-.7-3.5-1.7-4.5-5.2-5.2 3.5-.7 4.5-1.7 5.2-5.2Z', 'M16.6 14.2c.4 1.9.9 2.4 2.8 2.8-1.9.4-2.4.9-2.8 2.8-.4-1.9-.9-2.4-2.8-2.8 1.9-.4 2.4-.9 2.8-2.8Z'] }, + star: { lines: ['M12 3.6l2.6 5.3 5.8.9-4.2 4.1 1 5.7L12 16.9l-5.2 2.7 1-5.7-4.2-4.1 5.8-.9Z'] }, + 'star-filled': { solids: ['M12 3.6l2.6 5.3 5.8.9-4.2 4.1 1 5.7L12 16.9l-5.2 2.7 1-5.7-4.2-4.1 5.8-.9Z'] }, + flag: { lines: ['M6 20.6V3.8h11.6l-2.2 3.7 2.2 3.7H6'] }, + sample: { dashed: [12, 12, 7.6] }, + clock: { dots: [[12, 12, 8.4]], lines: ['M12 7.2V12l3.4 2.1'] }, + hourglass: { lines: ['M7.4 3.8h9.2M7.4 20.2h9.2', 'M8.6 3.8v2.9c0 2 6.8 2 6.8 0V3.8', 'M8.6 20.2v-2.9c0-2 6.8-2 6.8 0v2.9'] }, + expand: { lines: ['M14.4 4.4h5.2v5.2', 'M19.6 4.4 13 11', 'M9.6 19.6H4.4v-5.2', 'M4.4 19.6 11 13'] }, + send: { lines: ['M20.6 3.4 3.4 10.2l6.4 2.6 2.6 6.4Z', 'M20.6 3.4 9.8 12.8'] }, + drag: { spots: [[9, 6.4, 1.3], [15, 6.4, 1.3], [9, 12, 1.3], [15, 12, 1.3], [9, 17.6, 1.3], [15, 17.6, 1.3]] }, + more: { spots: [[5.6, 12, 1.4], [12, 12, 1.4], [18.4, 12, 1.4]] }, + filter: { lines: ['M3.8 5.4h16.4l-6.4 7.4v5.8l-3.6 2v-7.8Z'] }, + sliders: { lines: ['M4 7.2h16M4 16.8h16'], dots: [[9.4, 7.2, 2.2], [14.6, 16.8, 2.2]] }, + swap: { lines: ['M4.6 8.6h13.2', 'M14.2 5 17.8 8.6 14.2 12.2', 'M19.4 15.4H6.2', 'M9.8 11.8 6.2 15.4l3.6 3.6'] }, + + /* ── 方向与折叠 ───────────────────────────────────────────────────────── */ + 'chevron-down': { lines: ['M5.6 9.2 12 15.2l6.4-6'] }, + 'chevron-up': { lines: ['M5.6 14.8 12 8.8l6.4 6'] }, + 'chevron-left': { lines: ['M14.8 5.6 8.8 12l6 6.4'] }, + 'chevron-right': { lines: ['M9.2 5.6 15.2 12l-6 6.4'] }, + 'arrow-up': { lines: ['M12 19.6V4.6', 'M6.4 10.2 12 4.6l5.6 5.6'] }, + 'arrow-down': { lines: ['M12 4.4v15', 'M6.4 13.8 12 19.4l5.6-5.6'] }, + 'arrow-left': { lines: ['M19.6 12H4.6', 'M10.2 6.4 4.6 12l5.6 5.6'] }, + 'arrow-right': { lines: ['M4.4 12h15', 'M13.8 6.4 19.4 12l-5.6 5.6'] }, + 'to-top': { lines: ['M12 20.4V9', 'M6.6 14.4 12 9l5.4 5.4', 'M4.6 4.4h14.8'] }, + 'sort-asc': { lines: ['M8 6.4v11.2', 'M3.6 10.8 8 6.4l4.4 4.4', 'M14 8.4h6.4M14 13h5M14 17.6h3.4'] }, + + /* ── 视图切换 / 主题 / 账号 / 状态 ────────────────────────────────────── */ + grid: { rects: [[3.2, 3.2, 7, 7, 2], [13.8, 3.2, 7, 7, 2], [3.2, 13.8, 7, 7, 2], [13.8, 13.8, 7, 7, 2]] }, + list: { lines: ['M9.4 6.6h11M9.4 12h11M9.4 17.4h11'], spots: [[5, 6.6, 1.3], [5, 12, 1.3], [5, 17.4, 1.3]] }, + sun: { dots: [[12, 12, 4.2]], lines: ['M12 2.8v2.4M12 18.8v2.4M2.8 12h2.4M18.8 12h2.4M5.5 5.5l1.7 1.7M16.8 16.8l1.7 1.7M18.5 5.5l-1.7 1.7M7.2 16.8l-1.7 1.7'] }, + moon: { lines: ['M20.4 14.6A8.8 8.8 0 0 1 9.4 3.6a8.8 8.8 0 1 0 11 11Z'] }, + user: { dots: [[12, 8.2, 3.9]], lines: ['M4.9 20.4c0-3.7 3.2-5.9 7.1-5.9s7.1 2.2 7.1 5.9'] }, + users: { dots: [[9.4, 8.4, 3.5]], lines: ['M3 20.2c0-3.4 2.9-5.4 6.4-5.4 1.3 0 2.5.3 3.5.8', 'M16 5.2a3.5 3.5 0 0 1 0 6.6', 'M17.6 14.9c2.1.6 3.4 2.2 3.4 4.6'] }, + power: { lines: ['M12 3.6v8.2', 'M7.1 7a7.6 7.6 0 1 0 9.8 0'] }, + book: { lines: ['M12 6.6A3.2 3.2 0 0 0 8.8 4.4H4v13.2h4.8a3.2 3.2 0 0 1 3.2 2.2', 'M12 6.6a3.2 3.2 0 0 1 3.2-2.2H20v13.2h-4.8A3.2 3.2 0 0 0 12 18.8', 'M12 6.6v12.2'] }, + palette: { lines: ['M12 3.4a8.6 8.6 0 0 0 0 17.2c1.3 0 2-.8 2-1.8s-.8-1.6-.8-2.5c0-1 .8-1.6 1.9-1.6h1.9a3.6 3.6 0 0 0 3.6-3.6C20.6 6.6 16.7 3.4 12 3.4Z'], spots: [[8.2, 11.4, 1.1], [11, 8.2, 1.1], [15, 8.8, 1.1]] }, + target: { dots: [[12, 12, 8.4], [12, 12, 4.4]], spots: [[12, 12, 1.4]] }, + lock: { rects: [[4.8, 10.2, 14.4, 9.8, 2.4]], lines: ['M8.2 10.2V7.8a3.8 3.8 0 0 1 7.6 0v2.4'] }, + key: { dots: [[8.4, 15.6, 4.2]], lines: ['M11.4 12.6 19.8 4.2', 'M16.4 7.6l2.6 2.6'] }, + info: { dots: [[12, 12, 8.4]], lines: ['M12 11v5.4'], spots: [[12, 8.1, 1.1]] }, + warning: { lines: ['M12 4.2 20.9 19.6H3.1Z', 'M12 9.8v4.2'], spots: [[12, 17, 1.1]] }, + 'alert-circle': { dots: [[12, 12, 8.4]], lines: ['M12 7.6v5'], spots: [[12, 15.9, 1.1]] }, + 'minus-circle': { dots: [[12, 12, 8.4]], lines: ['M8.2 12h7.6'] }, + link: { lines: ['M10.2 13.8a4.2 4.2 0 0 0 6 0l2.4-2.4a4.2 4.2 0 0 0-6-6l-1.2 1.2', 'M13.8 10.2a4.2 4.2 0 0 0-6 0l-2.4 2.4a4.2 4.2 0 0 0 6 6l1.2-1.2'] }, + 'folder-open': { lines: ['M3.6 19.4 6.2 7.4h4.2l-1 3.2h7.6a1.6 1.6 0 0 1 1.6 2l-1.4 6.8Z', 'M6.2 7.4V4.6h5.4v2.8'] }, + cost: { rects: [[3.4, 5.4, 17.2, 13.2, 2.4]], lines: ['M7 9.8h6', 'M7 14.2h3.4'], dots: [[16.2, 11.6, 2.3]] } +} satisfies Record + +export type IconName = keyof typeof glyphs diff --git a/frontend/src/components/icons/index.ts b/frontend/src/components/icons/index.ts new file mode 100644 index 0000000..9b72e11 --- /dev/null +++ b/frontend/src/components/icons/index.ts @@ -0,0 +1,4 @@ +export { Icon, iconPx, default as IconDefault } from './Icon' +export type { IconProps } from './Icon' +export { glyphs } from './glyphs' +export type { IconName, Glyph } from './glyphs' diff --git a/frontend/src/styles/app.css b/frontend/src/styles/app.css index 78c83ed..206fa9c 100644 --- a/frontend/src/styles/app.css +++ b/frontend/src/styles/app.css @@ -400,3 +400,13 @@ h3 { font-size: var(--fs-title); line-height: var(--fs-title-lh); font-weight: 7 .ant-table-cell .ant-tag + .ant-tag { margin-inline-start: 0 } .ant-table-wrapper .ant-table-cell { overflow-wrap: anywhere } .ant-table-wrapper .ant-table-cell-fix-left, .ant-table-wrapper .ant-table-cell-fix-right { background: var(--c-bg-panel) } + +/* ── 图标:全站唯一的图形出口(components/icons/Icon.tsx)───────────────── + SVG 默认 display:inline 并按基线对齐,贴进一排 flex 控件里会莫名高出三四像素、 + 还会被父级的 line-height 撑开;统一 block + flex:none,尺寸交给组件的 width/height, + 这里不写任何一档的具体数字(尺子只有一把:theme/metrics.ts 的 icon)。 */ +.nex-icon { display: block; flex: none } +.nex-icon-spin { animation: nex-icon-spin 1.1s linear infinite } +@keyframes nex-icon-spin { to { transform: rotate(360deg) } } +/* 转圈图标要绕自己的中心,而不是绕元素盒左上角(Safari 对 inline SVG 的默认值不一致) */ +.nex-icon-spin { transform-origin: 50% 50% } diff --git a/frontend/src/theme/metrics.ts b/frontend/src/theme/metrics.ts index 8dec388..a29a087 100644 --- a/frontend/src/theme/metrics.ts +++ b/frontend/src/theme/metrics.ts @@ -72,6 +72,37 @@ export const fieldLabelWidth = 66 export const checkboxSize = 14 export const checkboxSizeTouch = 18 +/** + * 图标六档 + 描边阶梯(components/icons 的唯一尺子)。 + * + * 为什么图标也要一把尺子:重写之前全站图标是 60 多个 Unicode 字符 + * (⌂ ✧ ◫ ✕ ▶ ▧ ◉ ♫ ⇪ ⇶ ⏻ ⌄ …),字号随手写、粗细随字体、颜色随 text-*, + * 同一个「关闭」在灯箱里是 ✕、在抽屉里是 ✕ 但字号差两档、在标签上又是 ×。 + * 现在只有六个尺寸,页面按**所在容器**选档: + * xs 12 —— 只跟 10/11px 文字同排(标签内、chip 内) + * sm 14 —— 紧凑档控件(31px 按钮、chip、表格行内、菜单行) + * md 16 —— 主档控件(38px 按钮、输入框后缀、段落图标) + * lg 18 —— 左导航项、页签 + * xl 20 —— 卡片标题、分组头 + * 2xl 24 —— 空状态、帮助页步骤图 + * + * 描边给的是**视觉厚度**(设备像素),不是 viewBox 单位:等比缩放的描边在 14px 上 + * 会细到看不见,而 Unicode 字符的粗细根本不由我们决定。Icon 组件按 + * `userUnits = 视觉厚度 × 24 / 边长` 换算,所以六档看起来是一条线宽。 + */ +export const icon = { xs: 12, sm: 14, md: 16, lg: 18, xl: 20, '2xl': 24 } as const +export type IconSize = keyof typeof icon + +export const iconStroke: Record = { 12: 1.15, 14: 1.3, 16: 1.45, 18: 1.5, 20: 1.5, 24: 1.6 } + +/** 某个图标边长该用的视觉描边(设备像素)。越界边长退到最近的一档。 */ +export function iconStrokeAt(px: number): number { + const keys = Object.keys(iconStroke).map(Number).sort((a, b) => a - b) + let best = keys[0] + for (const k of keys) if (Math.abs(k - px) < Math.abs(best - px)) best = k + return iconStroke[best] +} + /** 顶栏高度:侧栏 sticky、分镜检查器的 top 都取这个值,差 1px 就露缝 */ export const barHeight = 64