feat(image-annotate): v1.9.0 文字样式包、吸附参考线、圆角与最近色、复制到剪贴板

文字从「字号 + 颜色」扩到完整样式:字重(常规/粗/特粗)、对齐(左/中/右)、
行距、描边、底色块、多行(textarea + Shift+Enter)。新增叶子模块 text.js,
fontOf / textMetrics / textBox / drawTextObject 成为唯一事实来源,
objects.js(预览/命中/包围盒)与 layers.js(栅格化)共用,避免量一套画一套;
描边与底色撑大包围盒,手柄、吸附、缩略图随之变化。单行无描边无底色的老文字
包围盒与旧实现逐像素一致,老作业打开不变形。

吸附参考线:snap.js 只做纯计算。目标线为画布 0/中/满 + 其他可见元素的左中右、
上中下;阈值 6 屏幕像素按 viewScale() 折回图片像素,磁力不随缩放变大;
命中画洋红参考线(区别于选中框的橙),松手清空;Alt 全程禁用。
位图/文字/形状三条拖动路径都接,文字需补 b.x - t.x 原点偏移。

矩形圆角:shapeRadius 进 drawShape,半径夹到 min(w,h)/2,路径手写 arcTo
(不用 ctx.roundRect,老内核没有)。最近使用颜色最多 8 个,存 ctx.settings
跨会话保留,只有落定的改色才记录;色板改用事件委托以覆盖动态插入的色块。

导出「复制」:结果编成 PNG 写 ClipboardItem,可直接粘进聊天窗口/后台上传框
且不关闭编辑器。优先 createImageBitmap 绕开宿主 CSP 的 img-src 限制;
非安全上下文无 navigator.clipboard 时明确提示改用「导出」而非静默失败。

顺带修:选项栏中文双字标签加 white-space:nowrap(否则 36px 一行内竖排成
「常/规」);.iwb-editor-optionbar-tip 补基础样式(原来只有 display:none,
裸 span 参与 flex 收缩被挤成两行贴边);文字工具的 hint 移到按钮之后,
放不下时让说明滚出视野而不是把操作按钮顶没。

harness 140 → 158 条,全部通过;validate 9/9。
This commit is contained in:
qiqi committed 2026-11-08 20:27:32 +08:00
1 parent 040b08fe28
commit e699c22fa0
17 files changed
+1678 -99

No files matched your search

+62 -1
View File
@@ -563,10 +563,17 @@
border: 2px solid #4488ff;
border-radius: 4px;
font-size: 14px;
line-height: 1.35;
/* textarea:默认会显示右下角拖拽柄与滚动条,画布上的就地输入框都不要 */
resize: none;
overflow: hidden;
white-space: pre;
background: rgba(255, 255, 255, 0.95);
color: #1e1e2e;
z-index: 10;
min-width: 120px;
min-height: 30px;
font-family: inherit;
}
.iwb-editor-text-input:focus { outline: none; box-shadow: 0 0 0 3px rgba(68, 136, 255, 0.3); }
@@ -1434,6 +1441,12 @@
}
.iwb-editor-optionbar-label { color: #7f849c; font-weight: 600; white-space: nowrap; }
.iwb-editor-optionbar-body { display: flex; align-items: center; gap: 8px; flex: 1 1 auto; min-width: 0; }
/* 右端通用快捷键提示。原来只有 @media 里的 display:none,没有任何基础样式,
于是它作为裸 span 参与 flex 收缩,被挤成两行还贴到右边缘外。 */
.iwb-editor-optionbar-tip {
flex: 0 0 auto; white-space: nowrap;
color: #6c7086; font-size: 11px; padding-left: 4px;
}
.iwb-opt-label { color: #a6adc8; white-space: nowrap; }
.iwb-opt-btn {
background: #313244; color: #cdd6f4; border: 1px solid transparent; border-radius: 5px;
@@ -1446,7 +1459,10 @@
border: 1px solid #45475a; border-radius: 5px; text-align: center; font-size: 12px;
}
.iwb-opt-current { color: #e8a735; font-weight: 600; white-space: nowrap; }
.iwb-opt-hint { color: #7f849c; font-size: 11px; margin-left: auto; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* hint 是「说明」不是「控件」:不许被压缩。
早先带 text-overflow:ellipsis,在 36px 高的选项栏里会被压成「双击改…」这种半截文案,
比不显示更误导人;现在由父级 overflow-x 决定是完整显示还是整体滚出视野。 */
.iwb-opt-hint { color: #7f849c; font-size: 11px; margin-left: auto; white-space: nowrap; flex: 0 0 auto; }
.iwb-editor-more-wrap, .iwb-editor-export-settings-wrap { position: relative; flex: 0 0 auto; z-index: 45; }
.iwb-editor-more-btn, .iwb-editor-panel-toggle, .iwb-editor-export-settings-btn {
@@ -1858,3 +1874,48 @@
border-color: #89b4fa;
color: #cdd6f4;
}
/* ================================================================
v1.9:文字样式控件 / 圆角 / 最近使用颜色 / 复制按钮
================================================================ */
/* 选项栏里的原生颜色框(描边色 / 底色):压成和数字框同高的小方块 */
.iwb-opt-color {
width: 22px;
height: 20px;
padding: 0;
flex: 0 0 auto;
border: 1px solid #45475a;
border-radius: 4px;
background: transparent;
cursor: pointer;
}
.iwb-opt-color::-webkit-color-swatch-wrapper { padding: 2px; }
.iwb-opt-color::-webkit-color-swatch { border: 0; border-radius: 3px; }
/* 「最近使用」:色板弹层里 4 列 × 2 行,空的时候整块隐藏(不占位) */
.iwb-editor-color-pop .iwb-editor-recent-colors {
display: grid;
grid-template-columns: repeat(4, 18px);
grid-auto-rows: 18px;
gap: 5px;
flex: 0 0 auto;
align-content: center;
}
.iwb-editor-recent-colors[hidden] { display: none; }
.iwb-editor-color-pop .iwb-editor-recent-colors .iwb-editor-color-panel-swatch {
width: 18px;
height: 18px;
padding: 0;
border: 0;
border-radius: 50%;
cursor: pointer;
}
.iwb-editor-color-pop .iwb-editor-recent-colors .iwb-editor-color-panel-swatch:hover { transform: scale(1.12); }
/* 复制到剪贴板:与「导出」同尺寸但用低饱和色,避免两个绿色按钮抢眼 */
.iwb-editor-btn-copy { background: #313244 !important; color: #cdd6f4 !important; }
.iwb-editor-btn-copy:hover { background: #3b3d52 !important; }
/* 选项栏按钮里是中文双字标签(常规/特粗/底色),不给 nowrap 会被挤成竖排 */
.iwb-editor-optionbar-body .iwb-opt-btn { white-space: nowrap; }