Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
244fc9c2b2 | ||
|
|
546999fdf9 | ||
|
|
bf32ec6ddb |
No files matched your search
@@ -234,6 +234,108 @@ P 下双击 = 结束当前路径(`commitPenPath`),不再进节点编辑。
|
||||
- 文字 / 形状 / 钢笔会被直接栅格化进结果层(PS 合并矢量层也是这个结果)。
|
||||
- 结果层落回「原最低参与层」的位置,`assignLayerZ` 重新连续编号,不产生重复 z。
|
||||
|
||||
## v1.14.0:文字可以选字体(黑 / 宋 / 楷 / 圆)
|
||||
|
||||
需求:「文字工具能不能选字体」。可以,而且成本很低 —— 但**只做了系统字体族**,没有内置字体文件,
|
||||
原因见下。
|
||||
|
||||
### 怎么用
|
||||
|
||||
选中文字(或切到文字工具、不选任何东西)→ 选项栏「字体」下拉,四档:
|
||||
|
||||
| 档位 | 字体栈(按命中顺序) | 适合 |
|
||||
| --- | --- | --- |
|
||||
| 黑体 | PingFang SC → Microsoft YaHei → Heiti SC → 思源黑体 → sans-serif | 默认。现代无衬线,信息密度高 |
|
||||
| 宋体 | Songti SC → SimSun → 思源宋体 → serif | 正式、印刷感,标题压得住 |
|
||||
| 楷体 | Kaiti SC → KaiTi → STKaiti → serif | 手写感,批注、签名、便签 |
|
||||
| 圆体 | Yuanti SC → YouYuan → 苹方 → sans-serif | 柔和,促销、亲子、轻食 |
|
||||
|
||||
选中文字时立刻生效;没选中时改的是「下一段文字的默认字体」——与字重 / 对齐 / 行距同一套逻辑。
|
||||
双击编辑文字时,输入框的字形和字重也跟着这段文字走,不会出现「输入时是黑体、确认后变宋体」。
|
||||
|
||||
### 为什么不内置字体文件
|
||||
|
||||
三条硬约束:
|
||||
|
||||
1. **CSP 拦死了第三方字体**。宿主 `_headers` 是 `default-src 'self'`,`font-src` 回落它,
|
||||
`https:` 只放给了 `img-src` / `connect-src`。Google Fonts 或任何字体 CDN 都会被浏览器直接拒绝。
|
||||
2. **中文字体太大**。本机参照:宋体 2.3MB、楷体 2.2MB、苹方全字重 64MB;插件产物现在 392KB,
|
||||
内联等于涨 5–150 倍。子集化到 3500 常用字约 0.8–1.5MB/个,能接受,但要放宿主静态目录,
|
||||
发布链得一起改。
|
||||
3. **异步字体的时序坑**。Web 字体异步加载,字体没 ready 就 `measureText`,量出来的是 fallback
|
||||
的宽度 —— 选中框和实际字形错位,导出还可能画成 fallback。系统字体同步可用,没有这个问题。
|
||||
|
||||
### 性能:字体不是瓶颈
|
||||
|
||||
1000×1000 画布、30 个文字对象(每个对象一张整图画布,见 `layers.js#vecCanvasFor`):
|
||||
|
||||
| | 首次绘制 | 热重绘 |
|
||||
| --- | --- | --- |
|
||||
| 现在(`sans-serif`) | 42.1 ms | 0.2 ms |
|
||||
| 苹方 | 13.5 ms | 0.1 ms |
|
||||
| 宋体 | 13.2 ms | 0.1 ms |
|
||||
| 楷体 | 22.2 ms | 0.1 ms |
|
||||
| 圆体 | 21.2 ms | 0.1 ms |
|
||||
|
||||
换字体只在**首次**多一次字形光栅化(13–42ms,一到两帧),之后走字形缓存,比现状还略快。
|
||||
|
||||
顺带记一条既有开销(与本版无关,但图大了要注意):每个文字对象占一张 imgW×imgH 的画布,
|
||||
1000² 是 3.8MB、4000² 是 61MB;20 个文字对象在 4000² 图上约 1.2GB。
|
||||
|
||||
### 一个反直觉的事实
|
||||
|
||||
**中文是全角等宽,换字体不改字宽**。同一段 10 个字在 6 种字体下 `measureText` 全是 480px
|
||||
(48px × 10)。所以切换字体不会让已有标注的版面跳动,只有拉丁字母和数字会伸缩 ——
|
||||
这也是锚点继续用「左上角」而不是居中的理由。
|
||||
|
||||
### 兼容性
|
||||
|
||||
- 老文字对象没有 `fontFamily` 字段 → `fontKeyOf()` 回退到 `sans`,行为与旧版一致。
|
||||
- 不认识的值(外部写入、脏数据)也收敛回 `sans`,不会把非法字符串塞进 `ctx.font`
|
||||
—— 那会让整串字体失效、静默退回浏览器默认字体,画面上看不出报错,极难排查。
|
||||
- 默认档的字体栈比旧的 `sans-serif` 更明确(苹方优先),**英文和数字的字形会有细微变化**,
|
||||
中文基本无感。这是「让字体可控」的代价,比留着跨平台不可控的 `sans-serif` 要好。
|
||||
|
||||
回归:harness 192 → 197 条(新增 5 条,含脏值收敛与「换字体不改中文宽度」);`npm run validate` 9/9。
|
||||
|
||||
## v1.13.1:Shift+X 改成「交换填充色与描边色」
|
||||
|
||||
反馈:「矩形 圆形 钢笔,切换填充与描边色的时候,会导致填充丢掉」→ 补一句关键信息
|
||||
「shift+x 切换填充与描边色的时候,就会出现丢失填充色的问题……再按这个快捷键填色又回来了,
|
||||
但是描边一直不变」。
|
||||
|
||||
### 不是颜色被清空,是快捷键语义错了
|
||||
|
||||
先把能想到的入口全实测了一遍(工具栏两个色槽、色板头部 tab、SV 拖动、hex 输入、选项栏原生
|
||||
色块、切换工具往返、矩形/圆形/钢笔、钢笔闭合与未闭合):**`fillColor` 从来没被清空,画面像素
|
||||
也没有丢**。真正的错在 **Shift+X 的语义**:
|
||||
|
||||
| | 旧行为 | 用户期望 |
|
||||
| --- | --- | --- |
|
||||
| 按一次 | 填充开关被关掉(只剩描边),描边色不动 | 填充色与描边色**对调** |
|
||||
| 再按一次 | 填充开关恢复,描边色仍然不动 | 换回来 |
|
||||
|
||||
用户看到的正是「填充没了、描边一直不变,再按一次填充又回来」—— 那是**开关**的行为,
|
||||
而 PS 里 `X` 是**交换前景/背景色**。所以这不是"颜色丢了",是把颜色交换做成了开关。
|
||||
|
||||
### 改法
|
||||
|
||||
新增 `swapShapeColors()`(`events.js`),Shift+X 改为调它:
|
||||
|
||||
- 描边色 ↔ 填充色对调:`sh.color ⇄ sh.fillColor`,同时同步主色 `S.color` 与默认填充色
|
||||
`S.shapeFillColor`(v1.10 起这两个就是同一份真相源,不另存)
|
||||
- **填充的开关状态不动**:交换的是颜色,不是有无。实心图形交换后仍是实心
|
||||
- 箭头没有内部,直接 toast 说明;填充还在「跟随描边色」(`fillColor=null`,两边同一个值)
|
||||
时也只提示,不改数据
|
||||
- 一步历史:`saveSnapshot('交换填充与描边色')`,`Ctrl+Z` 一次回退
|
||||
|
||||
实心/描边的切换**没有丢**,仍在选项栏那两个按钮上(`data-opt-toggle`),只是不再占 Shift+X;
|
||||
按钮的 tooltip 里原来写着「(Shift+X 切换)」,容易让人以为 Shift+X 是开关,已改成说明交换语义。
|
||||
|
||||
回归:`tools/harness.mjs` 里那条旧用例(断言按 Shift+X 后 `fill` 变 true)换成新的交换用例,
|
||||
断言「描边/填充两个色值互换、`fill` 开关不变、再按一次回到原样」。这条用例放在文件末尾跑 ——
|
||||
交换会把「下一个图形的填充色」也写成具体色值,夹在中间会污染后面「新建图形填充默认跟随描边色」的断言。
|
||||
|
||||
## v1.13.0:顶栏瘦身 / 视图按钮归位 / R·O·L 快捷键 / 填充色实时 / 图层解封
|
||||
|
||||
五条调整,前四条是界面与手感,最后一条是能力解禁(原型是 PS,但「原图不许压」这条并不是 PS 的规矩)。
|
||||
|
||||
@@ -311,6 +311,8 @@ getCompositeCanvas() // 当前这一张
|
||||
| 工具参数解耦与选项栏 | ✅ v1.2.0:`S.shapeLineWidth` / `S.textSize` 独立于 `S.brushSize`;选项栏按工具出参数(画笔三参、形状线宽+填充、文字字号、选区形状/羽化),与右侧面板双向同步 |
|
||||
| P3 图层增强 | 🟡 v1.7:缩略图 / 重命名 / 多选 / 不透明度滑杆已补;混合模式 / 图层蒙版 / 编组未做 |
|
||||
| P4 单张输出 | ✅ PNG/JPG/WebP、透明/白底、800×800(长边 80%)、≤500KB 迭代降质、下载、设置记忆;无队列 |
|
||||
| 文字字体选择 | ✅ v1.14.0:文字对象新增 `fontFamily`(预设 key:`sans` 黑体 / `serif` 宋体 / `kai` 楷体 / `round` 圆体),`fontOf()` 从硬编码 `sans-serif` 改为读 `TEXT_FONTS[key].stack` 的跨平台字体栈;选项栏加「字体」下拉(`select[data-opt-text]`,走 `change` 委托,其余文字样式仍走 `click`),复用 `TEXT_STYLE_STATE_KEY` 一条写回路径;输入框同步字体族与字重;`fontKeyOf()` 把脏值收敛回默认。**明确不做内置字体**:宿主 CSP `default-src 'self'` 拦第三方字体、CJK 字体 2–64MB 无法内联、异步字体有 measureText 时序坑。实测换字体仅首次多 13–42ms 字形光栅化,热重绘 0.1–0.2ms;中文全角等宽,换字体不改字宽(1000²/30 对象内存 114MB 属既有架构,与字体无关) |
|
||||
| 快捷键语义修正(v1.13.1) | ✅ v1.13.1:Shift+X 从「实心 ↔ 只描边」开关改成**交换填充色与描边色**(PS 的 X 语义)。旧行为下按一次填充被关掉、描边色不动,用户看到的就是「填充丢了」。新 `swapShapeColors()` 对调 `sh.color ⇄ sh.fillColor` 并同步 `S.color` / `S.shapeFillColor`,**填充开关不动**(交换颜色不改有无),箭头跳过、跟随态只提示,一步历史。实心/描边切换仍留在选项栏按钮上 |
|
||||
| 界面瘦身 / 快捷键 / 实时预览 / 图层解封 | ✅ v1.13.0:顶栏删掉四个层级按钮(`.iwb-editor-commands` 整块移除,`updateLayerUI()` / `bindLayerOrderButtons()` 一并清除);「适应窗口 / 收起侧栏」移到工具栏 DOM 末尾(shrink-to-fit 天然最右);快捷键 `R` 矩形 / `O` 圆形 / `L` 箭头(套索迁 `A`,`U` 保留),键盘处理改为优先匹配 `e.code` 以兼容中文输入法;原生 `<input type="color">` 补接 `input` 做实时预览(`skipHistory` + `nativeColorSnapped`,一次拖动仍只记 1 步撤销);原图不再钉底——`planPanelOrder` / `updateSortTarget` / `onSortEnd` / `moveLayer` / `mergeUnits` 五处解封,其他图层可拖到原图下方 |
|
||||
| 颜色体系与矢量属性 | ✅ v1.12.0:颜色上下文收敛成 `colorContext()` 三档(文字 / 形状 / 只有主色),文字上下文给**三格**(文字 / 描边 / 底色,`data-color-mode="triple"`),`applyTextColor()` 统管描边色与底色的写回(含 `skipHistory` 拖拽);「无」按当前格分派(无填充 / 无描边 / 无底色);原文「文本不支持描边与字体色切换」已修 |
|
||||
| 颜色体系与矢量属性(v1.11) | ✅ v1.11.0:颜色收敛为**描边 / 填充两格**——工具栏改 PS 式双色槽(`S.colorTarget` 决定色板写哪一格),选项栏两色块与工具栏双向同步,`colorSlots()` 成为唯一取值处;填充支持**无**(`fill=false`,颜色保留,槽位画灰底红斜杠);画笔/文字/箭头等无填充概念的工具只显示一格(v1.12 起文字改三格) |
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@iwb-plugin/image-annotate",
|
||||
"private": true,
|
||||
"version": "1.13.0",
|
||||
"version": "1.14.0",
|
||||
"description": "IWB 插件:图片标注 / 修图(编辑器移植自 iwb-plaus 扩展,纯 Canvas 2D)",
|
||||
"ibwPlugin": {
|
||||
"id": "image-annotate",
|
||||
|
||||
@@ -1458,6 +1458,14 @@
|
||||
width: 46px; padding: 2px 4px; background: #313244; color: #e8a735;
|
||||
border: 1px solid #45475a; border-radius: 5px; text-align: center; font-size: 12px;
|
||||
}
|
||||
/* 字体下拉:flex:0 0 auto 不能被压 —— 选项文字是 2 个汉字宽,压窄后会被截成「黑…」,
|
||||
用户没法确认自己选的是哪一档。 */
|
||||
.iwb-opt-select {
|
||||
flex: 0 0 auto; padding: 2px 4px; background: #313244; color: #cdd6f4;
|
||||
border: 1px solid #45475a; border-radius: 5px; font-size: 12px; cursor: pointer;
|
||||
}
|
||||
.iwb-opt-select:hover { background: #45475a; }
|
||||
.iwb-opt-select option { background: #1e1e2e; color: #cdd6f4; }
|
||||
.iwb-opt-current { color: #e8a735; font-weight: 600; white-space: nowrap; }
|
||||
/* hint 是「说明」不是「控件」:不许被压缩。
|
||||
早先带 text-overflow:ellipsis,在 36px 高的选项栏里会被压成「双击改…」这种半截文案,
|
||||
|
||||
@@ -17,7 +17,7 @@ import { showSelectionContext, hideSelectionContext } from './floating.js'
|
||||
import { applyConstraintDrag, cancelCrop, clearOverlay, confirmCrop, drawCropPreview, hideCropBar, hitCropHandle, insideRect, resizeCropRect, setConstraint, showCropBar, updateCropInfo } from './crop.js'
|
||||
import { applyShapeHandle, beginPenEdit, beginShapeHandleDrag, beginTextRotate, beginTextScaleDrag, commitTextInput, deleteSelectedShape, deleteSelectedText, exitPenEdit, getPenEditingShape, getSelectedShape, getSelectedText, hideTextInput, hitAnyObject, hitPenEdgeInsert, hitPenPoint, hitShapeHandle, hitShapeLayer, hitTextHandle, hitTextLayer, hitTopmost, moveLayer, otherObjectBoxes, renderObjects, selectNeighborLayer, selectUnit, shapeBounds, showTextInput, textBounds } from './objects.js'
|
||||
import { snapMove } from './snap.js'
|
||||
import { TEXT_DEFAULTS, TEXT_LINE_HEIGHT } from './text.js'
|
||||
import { TEXT_DEFAULTS, TEXT_FONTS, TEXT_FONT_KEYS, TEXT_LINE_HEIGHT, fontKeyOf } from './text.js'
|
||||
import { rememberColor } from './recent-colors.js'
|
||||
import { cancelImagePlacement, confirmImagePlacement, drawPlacementPreview, hitPlacementHandle, insidePlacementRect, resizePlacement } from './placement.js'
|
||||
import { close, copyResult, exportResult } from './index.js'
|
||||
@@ -1163,8 +1163,8 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
||||
const own = !!sh && (owner === 'pen' ? sh.type === 'pen' : (sh.type === 'rect' || sh.type === 'circle'))
|
||||
const fill = own ? !!sh.fill : (owner === 'pen' ? S.penFill : S.rectFill)
|
||||
return `<span class="iwb-opt-label">样式</span>
|
||||
<button class="iwb-opt-btn${fill ? '' : ' active'}" data-opt-toggle="stroke" data-fill-owner="${owner}" data-value="stroke" title="只描边 (Shift+X 切换)">描边</button>
|
||||
<button class="iwb-opt-btn${fill ? ' active' : ''}" data-opt-toggle="fill" data-fill-owner="${owner}" data-value="fill" title="实心填充 (Shift+X 切换)">实心</button>`
|
||||
<button class="iwb-opt-btn${fill ? '' : ' active'}" data-opt-toggle="stroke" data-fill-owner="${owner}" data-value="stroke" title="只描边:内部透明,只留描边(快捷键 Shift+X 是交换填充/描边色)">描边</button>
|
||||
<button class="iwb-opt-btn${fill ? ' active' : ''}" data-opt-toggle="fill" data-fill-owner="${owner}" data-value="fill" title="实心填充:内部用填充色(快捷键 Shift+X 是交换填充/描边色)">实心</button>`
|
||||
}
|
||||
|
||||
const SHAPE_NAMES = { rect: '矩形', circle: '圆形', arrow: '箭头', pen: '钢笔路径' }
|
||||
@@ -1173,7 +1173,7 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
||||
// 控件既作用于「当前选中的文字」,也写回「新建文字的默认值」:
|
||||
// 没选中时光调参数就是调下一次输入的样子,选中后调则立刻改这一段。
|
||||
const TEXT_STYLE_STATE_KEY = {
|
||||
fontWeight: 'textWeight', align: 'textAlign', lineHeight: 'textLineHeight',
|
||||
fontWeight: 'textWeight', fontFamily: 'textFamily', align: 'textAlign', lineHeight: 'textLineHeight',
|
||||
strokeWidth: 'textStrokeWidth', strokeColor: 'textStrokeColor',
|
||||
bgFill: 'textBgFill', bgColor: 'textBgColor'
|
||||
}
|
||||
@@ -1186,6 +1186,8 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
||||
}
|
||||
return {
|
||||
fontWeight: String(pick('fontWeight', 'textWeight', 'bold')),
|
||||
// 字体走 fontKeyOf 收敛:老对象没有 fontFamily,或存了不认识的 key,都落回默认黑体
|
||||
fontFamily: fontKeyOf({ fontFamily: pick('fontFamily', 'textFamily', 'sans') }),
|
||||
align: pick('align', 'textAlign', 'left'),
|
||||
lineHeight: Number(pick('lineHeight', 'textLineHeight', TEXT_LINE_HEIGHT)) || TEXT_LINE_HEIGHT,
|
||||
strokeWidth: Math.max(0, Number(pick('strokeWidth', 'textStrokeWidth', TEXT_DEFAULTS.strokeWidth)) || 0),
|
||||
@@ -1203,6 +1205,9 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
||||
const aBtn = (val, label, title) =>
|
||||
`<button class="iwb-opt-btn${v.align === val ? ' active' : ''}" data-opt-text="align" data-value="${val}" title="${title}">${label}</button>`
|
||||
return `<span class="iwb-opt-sep"></span>
|
||||
<span class="iwb-opt-label">字体</span>
|
||||
<select class="iwb-opt-select" data-opt-text="fontFamily" title="字体:改选中的这段文字,同时作为下一段新文字的默认字体">${TEXT_FONT_KEYS.map(k =>
|
||||
`<option value="${k}"${v.fontFamily === k ? ' selected' : ''}>${TEXT_FONTS[k].label}</option>`).join('')}</select>
|
||||
<span class="iwb-opt-label">字重</span>${wBtn('normal', '常规', '常规字重')}${wBtn('bold', '粗', '粗体(默认)')}${wBtn('900', '特粗', '特粗,封面标题用')}
|
||||
<span class="iwb-opt-label">对齐</span>${aBtn('left', '左', '多行时按左缘对齐')}${aBtn('center', '中', '多行时居中')}${aBtn('right', '右', '多行时按右缘对齐')}
|
||||
<span class="iwb-opt-label">行距</span>
|
||||
@@ -1488,6 +1493,8 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
||||
let value = raw
|
||||
// data-value 是字符串:'0' 也是真值,必须显式判,不能直接 !!raw
|
||||
if (key === 'bgFill') value = raw === true || raw === 1 || raw === '1' || raw === 'true'
|
||||
// 字体只收已知 key:下拉理论上不会给出脏值,但快捷键/外部调用可能,收敛一次更安全
|
||||
else if (key === 'fontFamily') value = fontKeyOf({ fontFamily: raw })
|
||||
else if (key === 'lineHeight') value = clamp(Number(raw) || 125, 80, 300) / 100
|
||||
else if (key === 'strokeWidth') value = clamp(Number(raw) || 0, 0, 40)
|
||||
else if (key === 'strokeColor' || key === 'bgColor') value = String(raw || TEXT_DEFAULTS.bgColor).toLowerCase()
|
||||
@@ -1686,6 +1693,29 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
||||
}
|
||||
}
|
||||
|
||||
/** PS 的 X 语义(v1.13.1):把选中形状的「填充色」与「描边色」对调。
|
||||
* 以前 Shift+X 绑的是「实心 ↔ 只描边」开关 —— 按下去填充被关掉、描边纹丝不动,
|
||||
* 用户的主观体验就是「填充色丢了」,再按一次才回来。用户要的是**交换两个颜色**:
|
||||
* 填充色换到描边的位置、描边色换到填充的位置,填充的开关状态不变(交换的是颜色,不是有无)。
|
||||
* 填充色仍「跟随描边色」(fillColor=null)时只有一个颜色,没有可交换的对象,只提示不动数据。 */
|
||||
function swapShapeColors() {
|
||||
const sh = getSelectedShape()
|
||||
if (!sh || sh.locked) return false
|
||||
if (sh.type === 'arrow') { toast('箭头只有描边色,没有可交换的填充色', 'info'); return true }
|
||||
const stroke = sh.color || S.color
|
||||
const fill = sh.fillColor || null
|
||||
if (!fill) { toast('填充色正跟随描边色(两者同一个颜色),无需交换', 'info'); return true }
|
||||
saveSnapshot('交换填充与描边色')
|
||||
sh.color = fill
|
||||
S.color = fill // 描边色与主色永远同一份(v1.10 的约定)
|
||||
sh.fillColor = stroke
|
||||
S.shapeFillColor = stroke // 交换后就是独立填充色了,不再跟随描边
|
||||
renderObjects()
|
||||
updateColorUI()
|
||||
syncOptionBar()
|
||||
return true
|
||||
}
|
||||
|
||||
function setOptionFromControl(el, committed) {
|
||||
const key = el && el.dataset ? el.dataset.opt : ''
|
||||
if (!key) return
|
||||
@@ -1831,6 +1861,14 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
||||
setOptionFromControl(e.target, false)
|
||||
})
|
||||
body.addEventListener('change', (e) => {
|
||||
// 字体下拉:唯一走 change 而不是 click 的文字样式控件(<select> 没有 click 语义)
|
||||
const textSel = e.target && e.target.closest ? e.target.closest('select[data-opt-text]') : null
|
||||
if (textSel) {
|
||||
e.stopPropagation()
|
||||
applyTextStyle(textSel.dataset.optText, textSel.value, true)
|
||||
syncOptionBar()
|
||||
return
|
||||
}
|
||||
const colorEl = nativeColorOf(e.target)
|
||||
if (colorEl) { e.stopPropagation(); applyNativeColor(colorEl, false); return }
|
||||
setOptionFromControl(e.target, true)
|
||||
@@ -2546,14 +2584,11 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
||||
return
|
||||
}
|
||||
|
||||
// PS 风格:Shift+X 切换选中形状的 描边/实心(与选项栏按钮共用 setShapeFill)
|
||||
if (!mod && e.shiftKey && key === 'x') {
|
||||
const sh = getSelectedShape()
|
||||
if (sh && !sh.locked) {
|
||||
e.preventDefault()
|
||||
if (sh.type === 'arrow') { toast('箭头没有实心样式', 'info'); return }
|
||||
setShapeFill(!sh.fill, sh.type === 'pen' ? 'pen' : 'rect')
|
||||
}
|
||||
// PS 同款:Shift+X 交换选中形状的「填充色」与「描边色」(v1.13.1)。
|
||||
// 以前这里绑的是「实心 ↔ 只描边」开关,用户按下去看到的是「填充色丢了、描边没变」——
|
||||
// 语义错了,不是颜色没了。实心/描边仍可从选项栏那两个按钮切。
|
||||
if (!mod && !e.altKey && e.shiftKey && key === 'x') {
|
||||
if (swapShapeColors()) e.preventDefault()
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -326,7 +326,7 @@ import { toast } from './commands.js'
|
||||
shapes: S.shapeLayers.map(s => ({ id: s.id, type: s.type, lw: s.lw, fill: !!s.fill, closed: !!s.closed, z: s.z, color: s.color, fillColor: s.fillColor || null, radius: s.radius || 0, x1: Math.round(s.x1 || 0), y1: Math.round(s.y1 || 0), x2: Math.round(s.x2 || 0), y2: Math.round(s.y2 || 0) })),
|
||||
texts: S.textLayers.map(t => ({
|
||||
id: t.id, text: t.text, x: t.x, y: t.y, fontSize: t.fontSize, color: t.color,
|
||||
fontWeight: t.fontWeight, align: t.align, lineHeight: t.lineHeight,
|
||||
fontWeight: t.fontWeight, fontFamily: t.fontFamily, align: t.align, lineHeight: t.lineHeight,
|
||||
strokeWidth: t.strokeWidth, strokeColor: t.strokeColor, bgFill: !!t.bgFill, bgColor: t.bgColor,
|
||||
// 包围盒:吸附/多行/底色/描边的断言都靠它,和绘制共用同一套度量
|
||||
box: (() => { const b = textBounds(t); return { x: Math.round(b.x), y: Math.round(b.y), w: Math.round(b.w), h: Math.round(b.h) } })()
|
||||
@@ -335,7 +335,7 @@ import { toast } from './commands.js'
|
||||
guides: S.guides ? S.guides.map(g => ({ axis: g.axis, at: Math.round(g.at * 10) / 10 })) : [],
|
||||
recentColors: (S.recentColors || []).slice(),
|
||||
textDefaults: {
|
||||
weight: S.textWeight, align: S.textAlign, lineHeight: S.textLineHeight,
|
||||
weight: S.textWeight, family: S.textFamily, align: S.textAlign, lineHeight: S.textLineHeight,
|
||||
strokeWidth: S.textStrokeWidth, strokeColor: S.textStrokeColor,
|
||||
bgFill: S.textBgFill, bgColor: S.textBgColor, bgAlpha: S.textBgAlpha
|
||||
},
|
||||
|
||||
@@ -16,7 +16,7 @@ import { drawShape, setTool } from './tools.js'
|
||||
import { saveSnapshot, snapshotState } from './history.js'
|
||||
import { toast } from './commands.js'
|
||||
import { renderOptionBar } from './events.js'
|
||||
import { fontOf, newTextStyle, textBox } from './text.js'
|
||||
import { fontOf, fontStackOf, newTextStyle, textBox, weightOf } from './text.js'
|
||||
import { drawGuides } from './snap.js'
|
||||
import { isDrawableLayer } from '../vendor/layer-logic.js'
|
||||
|
||||
@@ -608,6 +608,12 @@ import { isDrawableLayer } from '../vendor/layer-logic.js'
|
||||
input.value = ''
|
||||
S.textEditingId = null
|
||||
}
|
||||
// 输入时看到的字形要和提交后一致:字体族与字重跟随这段文字自己的样式
|
||||
// (新建时跟随「下一段文字的默认值」)。字号仍按 CSS 的 14px —— 那是输入框的可读性取舍,
|
||||
// 跟字体不同:字体不一致会让人以为「选错字体了」,字号不一致只是大小不同。
|
||||
const styleSrc = layer || { fontFamily: S.textFamily, fontWeight: S.textWeight }
|
||||
input.style.fontFamily = fontStackOf(styleSrc)
|
||||
input.style.fontWeight = weightOf(styleSrc)
|
||||
input.focus()
|
||||
input.select()
|
||||
input.dataset.x = x
|
||||
@@ -661,7 +667,7 @@ import { isDrawableLayer } from '../vendor/layer-logic.js'
|
||||
fontSize: Math.max(8, S.textSize),
|
||||
// 样式一次性随默认值落进对象:老对象没有这些字段,text.js 会各自回退到等价默认值
|
||||
...newTextStyle({
|
||||
fontWeight: S.textWeight, align: S.textAlign, lineHeight: S.textLineHeight,
|
||||
fontWeight: S.textWeight, fontFamily: S.textFamily, align: S.textAlign, lineHeight: S.textLineHeight,
|
||||
strokeWidth: S.textStrokeWidth, strokeColor: S.textStrokeColor,
|
||||
bgFill: S.textBgFill, bgColor: S.textBgColor
|
||||
}),
|
||||
|
||||
@@ -52,6 +52,7 @@
|
||||
textSize: 32, // 新建文字的字号 px
|
||||
// ---- v1.9 文字样式:这套是「新建文字」的默认值,每段文字自己存一份 ----
|
||||
textWeight: 'bold', // bold | normal | 900
|
||||
textFamily: 'sans', // v1.14 字体预设 key:sans 黑体 | serif 宋体 | kai 楷体 | round 圆体
|
||||
textAlign: 'left', // left | center | right(多行时各行按块宽对齐)
|
||||
textLineHeight: 1.25, // 行高倍数(1.25 = 老版单行高度,勿随意改)
|
||||
textStrokeWidth: TEXT_DEFAULTS.strokeWidth, // 描边宽度 px,0 = 无描边
|
||||
|
||||
@@ -54,9 +54,56 @@
|
||||
return w == null || w === '' ? 'bold' : String(w)
|
||||
}
|
||||
|
||||
/**
|
||||
* 字体预设(v1.14):key → { label, stack }。
|
||||
*
|
||||
* 为什么只做「系统字体族」而不是内置字体文件:
|
||||
* 1. 宿主 CSP 是 `default-src 'self'`,font-src 回落它,第三方字体 CDN 会被浏览器直接拦;
|
||||
* 2. 中文字体动辄 2–64MB(本机宋体 2.3MB / 楷体 2.2MB / 苹方全字重 64MB),
|
||||
* 插件产物现在才 389KB,内联等于体积涨 5–150 倍;
|
||||
* 3. 系统字体同步可用,没有「字体没加载完就 measureText」导致框和字错位的时序问题。
|
||||
* 每个 stack 都是跨平台候选队列:macOS 先命中苹方/宋体,Windows 命中雅黑/宋体,
|
||||
* 全不命中时退到通用的 sans-serif / serif —— 永远不会渲染失败。
|
||||
*
|
||||
* 注意:中文是全角等宽,换字体不改字宽(实测 10 字 48px 在 6 种字体下都是 480px),
|
||||
* 所以切换不会引起版面跳动;只有拉丁字母和数字会伸缩。
|
||||
*/
|
||||
export const TEXT_FONTS = {
|
||||
sans: {
|
||||
label: '黑体',
|
||||
stack: '"PingFang SC", "Microsoft YaHei", "Heiti SC", "Hiragino Sans GB", "Source Han Sans SC", "Noto Sans SC", sans-serif'
|
||||
},
|
||||
serif: {
|
||||
label: '宋体',
|
||||
stack: '"Songti SC", "SimSun", "STSong", "Source Han Serif SC", "Noto Serif SC", serif'
|
||||
},
|
||||
kai: {
|
||||
label: '楷体',
|
||||
stack: '"Kaiti SC", "KaiTi", "STKaiti", "AR PL UKai CN", "Noto Serif SC", serif'
|
||||
},
|
||||
round: {
|
||||
label: '圆体',
|
||||
stack: '"Yuanti SC", "YouYuan", "STYuanti", "PingFang SC", sans-serif'
|
||||
}
|
||||
}
|
||||
|
||||
export const TEXT_FONT_KEYS = ['sans', 'serif', 'kai', 'round']
|
||||
export const TEXT_FONT_DEFAULT = 'sans'
|
||||
|
||||
/** 把任意输入收敛成已知的字体 key:老对象没有 fontFamily、或存了脏值,都回退到默认 */
|
||||
export function fontKeyOf(t) {
|
||||
const k = t && t.fontFamily
|
||||
return TEXT_FONTS[k] ? k : TEXT_FONT_DEFAULT
|
||||
}
|
||||
|
||||
/** 字体栈串(不含字号字重),选项栏下拉与预览都用它 */
|
||||
export function fontStackOf(t) {
|
||||
return TEXT_FONTS[fontKeyOf(t)].stack
|
||||
}
|
||||
|
||||
export function fontOf(t) {
|
||||
const size = Math.max(4, Number(t && t.fontSize) || 32)
|
||||
return weightOf(t) + ' ' + size + 'px sans-serif'
|
||||
return weightOf(t) + ' ' + size + 'px ' + fontStackOf(t)
|
||||
}
|
||||
|
||||
/** 文字的排布度量:分行、每行宽度、行高、底色 padding、描边宽度 */
|
||||
@@ -163,6 +210,9 @@
|
||||
const s = src || {}
|
||||
return {
|
||||
fontWeight: weightOf(s),
|
||||
// 字体 key 过一遍收敛:外部传进来不认识的字符串不会进 ctx.font(脏值会让整个
|
||||
// 字体串失效、静默退回浏览器默认,文件本身看不出问题,极难排查)
|
||||
fontFamily: fontKeyOf(s),
|
||||
align: alignOf(s),
|
||||
lineHeight: Number(s.lineHeight) || TEXT_LINE_HEIGHT,
|
||||
strokeWidth: Math.max(0, Number(s.strokeWidth) || 0),
|
||||
|
||||
+81
-15
@@ -9,7 +9,7 @@
|
||||
var __IWB_ANNOTATE_MANIFEST__ = {
|
||||
id: 'image-annotate',
|
||||
name: '标注 / 修图',
|
||||
version: '1.13.0',
|
||||
version: '1.14.0',
|
||||
apiVersion: 1,
|
||||
capabilities: ['commands', 'nodeActions', 'canvas', 'canvasWrite'],
|
||||
settings: {
|
||||
@@ -49,9 +49,36 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
||||
const w = t && t.fontWeight;
|
||||
return w == null || w === "" ? "bold" : String(w);
|
||||
}
|
||||
var TEXT_FONTS = {
|
||||
sans: {
|
||||
label: "黑体",
|
||||
stack: '"PingFang SC", "Microsoft YaHei", "Heiti SC", "Hiragino Sans GB", "Source Han Sans SC", "Noto Sans SC", sans-serif'
|
||||
},
|
||||
serif: {
|
||||
label: "宋体",
|
||||
stack: '"Songti SC", "SimSun", "STSong", "Source Han Serif SC", "Noto Serif SC", serif'
|
||||
},
|
||||
kai: {
|
||||
label: "楷体",
|
||||
stack: '"Kaiti SC", "KaiTi", "STKaiti", "AR PL UKai CN", "Noto Serif SC", serif'
|
||||
},
|
||||
round: {
|
||||
label: "圆体",
|
||||
stack: '"Yuanti SC", "YouYuan", "STYuanti", "PingFang SC", sans-serif'
|
||||
}
|
||||
};
|
||||
var TEXT_FONT_KEYS = ["sans", "serif", "kai", "round"];
|
||||
var TEXT_FONT_DEFAULT = "sans";
|
||||
function fontKeyOf(t) {
|
||||
const k = t && t.fontFamily;
|
||||
return TEXT_FONTS[k] ? k : TEXT_FONT_DEFAULT;
|
||||
}
|
||||
function fontStackOf(t) {
|
||||
return TEXT_FONTS[fontKeyOf(t)].stack;
|
||||
}
|
||||
function fontOf(t) {
|
||||
const size = Math.max(4, Number(t && t.fontSize) || 32);
|
||||
return weightOf(t) + " " + size + "px sans-serif";
|
||||
return weightOf(t) + " " + size + "px " + fontStackOf(t);
|
||||
}
|
||||
function textMetrics(t) {
|
||||
const ctx = measureCtx();
|
||||
@@ -139,6 +166,9 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
||||
const s = src || {};
|
||||
return {
|
||||
fontWeight: weightOf(s),
|
||||
// 字体 key 过一遍收敛:外部传进来不认识的字符串不会进 ctx.font(脏值会让整个
|
||||
// 字体串失效、静默退回浏览器默认,文件本身看不出问题,极难排查)
|
||||
fontFamily: fontKeyOf(s),
|
||||
align: alignOf(s),
|
||||
lineHeight: Number(s.lineHeight) || TEXT_LINE_HEIGHT,
|
||||
strokeWidth: Math.max(0, Number(s.strokeWidth) || 0),
|
||||
@@ -203,6 +233,8 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
||||
// ---- v1.9 文字样式:这套是「新建文字」的默认值,每段文字自己存一份 ----
|
||||
textWeight: "bold",
|
||||
// bold | normal | 900
|
||||
textFamily: "sans",
|
||||
// v1.14 字体预设 key:sans 黑体 | serif 宋体 | kai 楷体 | round 圆体
|
||||
textAlign: "left",
|
||||
// left | center | right(多行时各行按块宽对齐)
|
||||
textLineHeight: 1.25,
|
||||
@@ -1739,6 +1771,9 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
||||
input.value = "";
|
||||
S.textEditingId = null;
|
||||
}
|
||||
const styleSrc = layer || { fontFamily: S.textFamily, fontWeight: S.textWeight };
|
||||
input.style.fontFamily = fontStackOf(styleSrc);
|
||||
input.style.fontWeight = weightOf(styleSrc);
|
||||
input.focus();
|
||||
input.select();
|
||||
input.dataset.x = x;
|
||||
@@ -1792,6 +1827,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
||||
// 样式一次性随默认值落进对象:老对象没有这些字段,text.js 会各自回退到等价默认值
|
||||
...newTextStyle({
|
||||
fontWeight: S.textWeight,
|
||||
fontFamily: S.textFamily,
|
||||
align: S.textAlign,
|
||||
lineHeight: S.textLineHeight,
|
||||
strokeWidth: S.textStrokeWidth,
|
||||
@@ -5063,12 +5099,13 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
||||
const own = !!sh && (owner === "pen" ? sh.type === "pen" : sh.type === "rect" || sh.type === "circle");
|
||||
const fill = own ? !!sh.fill : owner === "pen" ? S.penFill : S.rectFill;
|
||||
return `<span class="iwb-opt-label">样式</span>
|
||||
<button class="iwb-opt-btn${fill ? "" : " active"}" data-opt-toggle="stroke" data-fill-owner="${owner}" data-value="stroke" title="只描边 (Shift+X 切换)">描边</button>
|
||||
<button class="iwb-opt-btn${fill ? " active" : ""}" data-opt-toggle="fill" data-fill-owner="${owner}" data-value="fill" title="实心填充 (Shift+X 切换)">实心</button>`;
|
||||
<button class="iwb-opt-btn${fill ? "" : " active"}" data-opt-toggle="stroke" data-fill-owner="${owner}" data-value="stroke" title="只描边:内部透明,只留描边(快捷键 Shift+X 是交换填充/描边色)">描边</button>
|
||||
<button class="iwb-opt-btn${fill ? " active" : ""}" data-opt-toggle="fill" data-fill-owner="${owner}" data-value="fill" title="实心填充:内部用填充色(快捷键 Shift+X 是交换填充/描边色)">实心</button>`;
|
||||
}
|
||||
var SHAPE_NAMES = { rect: "矩形", circle: "圆形", arrow: "箭头", pen: "钢笔路径" };
|
||||
var TEXT_STYLE_STATE_KEY = {
|
||||
fontWeight: "textWeight",
|
||||
fontFamily: "textFamily",
|
||||
align: "textAlign",
|
||||
lineHeight: "textLineHeight",
|
||||
strokeWidth: "textStrokeWidth",
|
||||
@@ -5083,6 +5120,8 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
||||
};
|
||||
return {
|
||||
fontWeight: String(pick("fontWeight", "textWeight", "bold")),
|
||||
// 字体走 fontKeyOf 收敛:老对象没有 fontFamily,或存了不认识的 key,都落回默认黑体
|
||||
fontFamily: fontKeyOf({ fontFamily: pick("fontFamily", "textFamily", "sans") }),
|
||||
align: pick("align", "textAlign", "left"),
|
||||
lineHeight: Number(pick("lineHeight", "textLineHeight", TEXT_LINE_HEIGHT)) || TEXT_LINE_HEIGHT,
|
||||
strokeWidth: Math.max(0, Number(pick("strokeWidth", "textStrokeWidth", TEXT_DEFAULTS.strokeWidth)) || 0),
|
||||
@@ -5097,6 +5136,8 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
||||
const wBtn = (val, label, title) => `<button class="iwb-opt-btn${v.fontWeight === val ? " active" : ""}" data-opt-text="fontWeight" data-value="${val}" title="${title}">${label}</button>`;
|
||||
const aBtn = (val, label, title) => `<button class="iwb-opt-btn${v.align === val ? " active" : ""}" data-opt-text="align" data-value="${val}" title="${title}">${label}</button>`;
|
||||
return `<span class="iwb-opt-sep"></span>
|
||||
<span class="iwb-opt-label">字体</span>
|
||||
<select class="iwb-opt-select" data-opt-text="fontFamily" title="字体:改选中的这段文字,同时作为下一段新文字的默认字体">${TEXT_FONT_KEYS.map((k) => `<option value="${k}"${v.fontFamily === k ? " selected" : ""}>${TEXT_FONTS[k].label}</option>`).join("")}</select>
|
||||
<span class="iwb-opt-label">字重</span>${wBtn("normal", "常规", "常规字重")}${wBtn("bold", "粗", "粗体(默认)")}${wBtn("900", "特粗", "特粗,封面标题用")}
|
||||
<span class="iwb-opt-label">对齐</span>${aBtn("left", "左", "多行时按左缘对齐")}${aBtn("center", "中", "多行时居中")}${aBtn("right", "右", "多行时按右缘对齐")}
|
||||
<span class="iwb-opt-label">行距</span>
|
||||
@@ -5304,6 +5345,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
||||
if (!stateKey) return;
|
||||
let value = raw;
|
||||
if (key === "bgFill") value = raw === true || raw === 1 || raw === "1" || raw === "true";
|
||||
else if (key === "fontFamily") value = fontKeyOf({ fontFamily: raw });
|
||||
else if (key === "lineHeight") value = clamp(Number(raw) || 125, 80, 300) / 100;
|
||||
else if (key === "strokeWidth") value = clamp(Number(raw) || 0, 0, 40);
|
||||
else if (key === "strokeColor" || key === "bgColor") value = String(raw || TEXT_DEFAULTS.bgColor).toLowerCase();
|
||||
@@ -5483,6 +5525,29 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
||||
syncOptionBar();
|
||||
}
|
||||
}
|
||||
function swapShapeColors() {
|
||||
const sh = getSelectedShape();
|
||||
if (!sh || sh.locked) return false;
|
||||
if (sh.type === "arrow") {
|
||||
toast("箭头只有描边色,没有可交换的填充色", "info");
|
||||
return true;
|
||||
}
|
||||
const stroke = sh.color || S.color;
|
||||
const fill = sh.fillColor || null;
|
||||
if (!fill) {
|
||||
toast("填充色正跟随描边色(两者同一个颜色),无需交换", "info");
|
||||
return true;
|
||||
}
|
||||
saveSnapshot("交换填充与描边色");
|
||||
sh.color = fill;
|
||||
S.color = fill;
|
||||
sh.fillColor = stroke;
|
||||
S.shapeFillColor = stroke;
|
||||
renderObjects();
|
||||
updateColorUI();
|
||||
syncOptionBar();
|
||||
return true;
|
||||
}
|
||||
function setOptionFromControl(el, committed) {
|
||||
const key = el && el.dataset ? el.dataset.opt : "";
|
||||
if (!key) return;
|
||||
@@ -5616,6 +5681,13 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
||||
setOptionFromControl(e.target, false);
|
||||
});
|
||||
body.addEventListener("change", (e) => {
|
||||
const textSel = e.target && e.target.closest ? e.target.closest("select[data-opt-text]") : null;
|
||||
if (textSel) {
|
||||
e.stopPropagation();
|
||||
applyTextStyle(textSel.dataset.optText, textSel.value, true);
|
||||
syncOptionBar();
|
||||
return;
|
||||
}
|
||||
const colorEl = nativeColorOf(e.target);
|
||||
if (colorEl) {
|
||||
e.stopPropagation();
|
||||
@@ -6337,16 +6409,8 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
||||
togglePanelsCollapsed();
|
||||
return;
|
||||
}
|
||||
if (!mod && e.shiftKey && key === "x") {
|
||||
const sh = getSelectedShape();
|
||||
if (sh && !sh.locked) {
|
||||
e.preventDefault();
|
||||
if (sh.type === "arrow") {
|
||||
toast("箭头没有实心样式", "info");
|
||||
return;
|
||||
}
|
||||
setShapeFill(!sh.fill, sh.type === "pen" ? "pen" : "rect");
|
||||
}
|
||||
if (!mod && !e.altKey && e.shiftKey && key === "x") {
|
||||
if (swapShapeColors()) e.preventDefault();
|
||||
return;
|
||||
}
|
||||
const isBracket = e.key === "[" || e.key === "]" || e.code === "BracketLeft" || e.code === "BracketRight";
|
||||
@@ -8071,6 +8135,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
||||
fontSize: t.fontSize,
|
||||
color: t.color,
|
||||
fontWeight: t.fontWeight,
|
||||
fontFamily: t.fontFamily,
|
||||
align: t.align,
|
||||
lineHeight: t.lineHeight,
|
||||
strokeWidth: t.strokeWidth,
|
||||
@@ -8088,6 +8153,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
||||
recentColors: (S.recentColors || []).slice(),
|
||||
textDefaults: {
|
||||
weight: S.textWeight,
|
||||
family: S.textFamily,
|
||||
align: S.textAlign,
|
||||
lineHeight: S.textLineHeight,
|
||||
strokeWidth: S.textStrokeWidth,
|
||||
@@ -8199,7 +8265,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
||||
};
|
||||
|
||||
// image-annotate/plugin/editor.css
|
||||
var editor_default = '/* IWB 鲜艺抠图节点 - 注入样式 */\n\n/* 抠图按钮 */\n.iwb-cutout-btn {\n cursor: pointer;\n opacity: 0.7;\n transition: opacity 0.15s, transform 0.15s;\n}\n\n.iwb-cutout-btn:hover {\n opacity: 1;\n transform: scale(1.15);\n}\n\n.iwb-cutout-btn svg {\n width: 14px;\n height: 14px;\n display: block;\n}\n\n/* 正在处理中的按钮状态 */\n.iwb-cutout-btn.processing {\n animation: iwb-cutout-pulse 1s infinite;\n pointer-events: none;\n}\n\n@keyframes iwb-cutout-pulse {\n 0%, 100% { opacity: 0.4; }\n 50% { opacity: 1; }\n}\n\n/* 全屏遮罩 */\n.iwb-cutout-overlay {\n position: fixed;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n background: rgba(0, 0, 0, 0.25);\n display: none;\n align-items: center;\n justify-content: center;\n flex-direction: column;\n gap: 12px;\n z-index: 999999;\n pointer-events: all;\n backdrop-filter: blur(2px);\n}\n\n/* 自定义按钮提示(挂在 body,最高层级,不会被图片遮挡) */\n#iwb-cutout-tip {\n position: fixed;\n z-index: 2147483647;\n background: rgba(30, 30, 46, 0.95);\n color: #fff;\n padding: 5px 10px;\n border-radius: 6px;\n font-size: 12px;\n line-height: 1.5;\n white-space: nowrap;\n pointer-events: none;\n display: none;\n box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);\n border: 1px solid rgba(255, 255, 255, 0.14);\n font-family: system-ui, -apple-system, "Segoe UI", sans-serif;\n max-width: 320px;\n white-space: normal;\n word-break: break-all;\n}\n\n/* 加载动画 */\n.iwb-cutout-spinner {\n width: 48px;\n height: 48px;\n border: 4px solid rgba(255, 255, 255, 0.3);\n border-top-color: #e8a735;\n border-radius: 50%;\n animation: iwb-cutout-spin 0.8s linear infinite;\n}\n\n@keyframes iwb-cutout-spin {\n to { transform: rotate(360deg); }\n}\n\n/* 遮罩文字 */\n.iwb-cutout-text {\n color: #fff;\n font-size: 14px;\n font-weight: 500;\n text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);\n background: rgba(0, 0, 0, 0.6);\n padding: 8px 16px;\n border-radius: 6px;\n}\n\n/* Toast 提示 */\n.iwb-cutout-toast {\n position: fixed;\n bottom: 24px;\n left: 50%;\n transform: translateX(-50%);\n padding: 10px 20px;\n border-radius: 8px;\n font-size: 13px;\n font-weight: 500;\n z-index: 999999;\n transition: opacity 0.3s;\n box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);\n display: none;\n max-width: 400px;\n}\n\n.iwb-cutout-toast-success {\n background: #1a7f37;\n color: #fff;\n}\n\n.iwb-cutout-toast-error {\n background: #cf222e;\n color: #fff;\n}\n\n.iwb-cutout-toast-info {\n background: #1f6feb;\n color: #fff;\n}\n\n/* 白底按钮 */\n.iwb-whitebg-btn {\n cursor: pointer;\n opacity: 0.7;\n transition: opacity 0.15s, transform 0.15s;\n}\n.iwb-whitebg-btn:hover { opacity: 1; transform: scale(1.15); }\n.iwb-whitebg-btn svg { width: 14px; height: 14px; display: block; }\n.iwb-whitebg-btn.processing { animation: iwb-cutout-pulse 1s infinite; pointer-events: none; }\n\n/* 编辑按钮 */\n.iwb-editor-btn-icon {\n cursor: pointer;\n opacity: 0.7;\n transition: opacity 0.15s, transform 0.15s;\n}\n.iwb-editor-btn-icon:hover { opacity: 1; transform: scale(1.15); }\n.iwb-editor-btn-icon svg { width: 14px; height: 14px; display: block; }\n\n/* ==================== 图片编辑器 ==================== */\n\n.iwb-editor-overlay {\n position: fixed;\n top: 0; left: 0;\n width: 100%; height: 100%;\n background: rgba(0, 0, 0, 0.6);\n display: none;\n align-items: center;\n justify-content: center;\n z-index: 999998;\n backdrop-filter: blur(3px);\n}\n\n.iwb-editor-modal {\n background: #1e1e2e;\n border-radius: 0;\n box-shadow: none;\n display: flex;\n flex-direction: column;\n width: 100vw;\n height: 100vh;\n max-width: none;\n max-height: none;\n overflow: visible;\n}\n\n/* 新增:主区域(画布 + 图层面板)flex 布局 */\n.iwb-editor-main {\n display: flex;\n flex: 1 1 auto;\n min-height: 0;\n overflow: visible;\n}\n\n.iwb-editor-header {\n display: flex;\n align-items: center;\n gap: 12px;\n padding: 10px 16px;\n background: #181825;\n border-bottom: 1px solid #313244;\n flex-wrap: nowrap;\n}\n.iwb-editor-header > .iwb-editor-tools {\n position: absolute;\n left: 12px;\n top: 68px;\n width: 44px;\n flex-direction: column;\n padding: 6px;\n background: #181825;\n border: 1px solid #313244;\n border-radius: 8px;\n z-index: 20;\n}\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action { position: static; }\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action[data-action="undo"],\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action[data-action="redo"],\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action[data-action="reset"],\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action[data-action="restore"] {\n position: absolute;\n top: -54px;\n left: auto;\n}\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action[data-action="undo"] { right: 154px; }\n.iwb-editor-header > .iwb-edLine truncated
|
||||
var editor_default = '/* IWB 鲜艺抠图节点 - 注入样式 */\n\n/* 抠图按钮 */\n.iwb-cutout-btn {\n cursor: pointer;\n opacity: 0.7;\n transition: opacity 0.15s, transform 0.15s;\n}\n\n.iwb-cutout-btn:hover {\n opacity: 1;\n transform: scale(1.15);\n}\n\n.iwb-cutout-btn svg {\n width: 14px;\n height: 14px;\n display: block;\n}\n\n/* 正在处理中的按钮状态 */\n.iwb-cutout-btn.processing {\n animation: iwb-cutout-pulse 1s infinite;\n pointer-events: none;\n}\n\n@keyframes iwb-cutout-pulse {\n 0%, 100% { opacity: 0.4; }\n 50% { opacity: 1; }\n}\n\n/* 全屏遮罩 */\n.iwb-cutout-overlay {\n position: fixed;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n background: rgba(0, 0, 0, 0.25);\n display: none;\n align-items: center;\n justify-content: center;\n flex-direction: column;\n gap: 12px;\n z-index: 999999;\n pointer-events: all;\n backdrop-filter: blur(2px);\n}\n\n/* 自定义按钮提示(挂在 body,最高层级,不会被图片遮挡) */\n#iwb-cutout-tip {\n position: fixed;\n z-index: 2147483647;\n background: rgba(30, 30, 46, 0.95);\n color: #fff;\n padding: 5px 10px;\n border-radius: 6px;\n font-size: 12px;\n line-height: 1.5;\n white-space: nowrap;\n pointer-events: none;\n display: none;\n box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);\n border: 1px solid rgba(255, 255, 255, 0.14);\n font-family: system-ui, -apple-system, "Segoe UI", sans-serif;\n max-width: 320px;\n white-space: normal;\n word-break: break-all;\n}\n\n/* 加载动画 */\n.iwb-cutout-spinner {\n width: 48px;\n height: 48px;\n border: 4px solid rgba(255, 255, 255, 0.3);\n border-top-color: #e8a735;\n border-radius: 50%;\n animation: iwb-cutout-spin 0.8s linear infinite;\n}\n\n@keyframes iwb-cutout-spin {\n to { transform: rotate(360deg); }\n}\n\n/* 遮罩文字 */\n.iwb-cutout-text {\n color: #fff;\n font-size: 14px;\n font-weight: 500;\n text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);\n background: rgba(0, 0, 0, 0.6);\n padding: 8px 16px;\n border-radius: 6px;\n}\n\n/* Toast 提示 */\n.iwb-cutout-toast {\n position: fixed;\n bottom: 24px;\n left: 50%;\n transform: translateX(-50%);\n padding: 10px 20px;\n border-radius: 8px;\n font-size: 13px;\n font-weight: 500;\n z-index: 999999;\n transition: opacity 0.3s;\n box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);\n display: none;\n max-width: 400px;\n}\n\n.iwb-cutout-toast-success {\n background: #1a7f37;\n color: #fff;\n}\n\n.iwb-cutout-toast-error {\n background: #cf222e;\n color: #fff;\n}\n\n.iwb-cutout-toast-info {\n background: #1f6feb;\n color: #fff;\n}\n\n/* 白底按钮 */\n.iwb-whitebg-btn {\n cursor: pointer;\n opacity: 0.7;\n transition: opacity 0.15s, transform 0.15s;\n}\n.iwb-whitebg-btn:hover { opacity: 1; transform: scale(1.15); }\n.iwb-whitebg-btn svg { width: 14px; height: 14px; display: block; }\n.iwb-whitebg-btn.processing { animation: iwb-cutout-pulse 1s infinite; pointer-events: none; }\n\n/* 编辑按钮 */\n.iwb-editor-btn-icon {\n cursor: pointer;\n opacity: 0.7;\n transition: opacity 0.15s, transform 0.15s;\n}\n.iwb-editor-btn-icon:hover { opacity: 1; transform: scale(1.15); }\n.iwb-editor-btn-icon svg { width: 14px; height: 14px; display: block; }\n\n/* ==================== 图片编辑器 ==================== */\n\n.iwb-editor-overlay {\n position: fixed;\n top: 0; left: 0;\n width: 100%; height: 100%;\n background: rgba(0, 0, 0, 0.6);\n display: none;\n align-items: center;\n justify-content: center;\n z-index: 999998;\n backdrop-filter: blur(3px);\n}\n\n.iwb-editor-modal {\n background: #1e1e2e;\n border-radius: 0;\n box-shadow: none;\n display: flex;\n flex-direction: column;\n width: 100vw;\n height: 100vh;\n max-width: none;\n max-height: none;\n overflow: visible;\n}\n\n/* 新增:主区域(画布 + 图层面板)flex 布局 */\n.iwb-editor-main {\n display: flex;\n flex: 1 1 auto;\n min-height: 0;\n overflow: visible;\n}\n\n.iwb-editor-header {\n display: flex;\n align-items: center;\n gap: 12px;\n padding: 10px 16px;\n background: #181825;\n border-bottom: 1px solid #313244;\n flex-wrap: nowrap;\n}\n.iwb-editor-header > .iwb-editor-tools {\n position: absolute;\n left: 12px;\n top: 68px;\n width: 44px;\n flex-direction: column;\n padding: 6px;\n background: #181825;\n border: 1px solid #313244;\n border-radius: 8px;\n z-index: 20;\n}\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action { position: static; }\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action[data-action="undo"],\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action[data-action="redo"],\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action[data-action="reset"],\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action[data-action="restore"] {\n position: absolute;\n top: -54px;\n left: auto;\n}\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action[data-action="undo"] { right: 154px; }\n.iwb-editor-header > .iwb-edLine truncated
|
||||
|
||||
// image-annotate/plugin/glue.js
|
||||
function createGlue(ctx, css) {
|
||||
|
||||
@@ -176,20 +176,68 @@ if (!SKIP_PASTE) {
|
||||
check('点击「截图+图形」重叠区选中最上层截图(不被下方图形抢走)',
|
||||
Boolean(activeItem && activeItem.type === 'bitmap' && /图层/.test(activeItem.name)), JSON.stringify(activeItem))
|
||||
|
||||
// v1.13 起顶栏四个层级按钮已删除(改为图层拖动 + Ctrl+]/[ 快捷键),
|
||||
// 这里改为断言「按钮确实没了」+ 用快捷键验证排序仍然可用。
|
||||
check('顶栏不再有层级排序按钮(改用图层拖动 + Ctrl+]/[)',
|
||||
(await page.locator('.iwb-editor-layer-btn').count()) === 0 &&
|
||||
(await page.locator('.iwb-editor-header .iwb-editor-commands').count()) === 0,
|
||||
'layerBtn=' + await page.locator('.iwb-editor-layer-btn').count())
|
||||
|
||||
const toolsTail = await page.evaluate(() => Array.from(document.querySelectorAll('.iwb-editor-tools > *'))
|
||||
.slice(-2).map((n) => n.dataset.action || n.className))
|
||||
check('工具栏最右两个按钮是「适应窗口 / 收起侧栏」',
|
||||
JSON.stringify(toolsTail) === JSON.stringify(['zoomFit', 'togglePanels']), JSON.stringify(toolsTail))
|
||||
|
||||
const before = await panelSeq()
|
||||
await page.locator('.iwb-editor-layer-btn[data-layer="down"]').click()
|
||||
const activeName = await page.evaluate(() => document.querySelector('.iwb-editor-layer-list .iwb-layer-item.active .iwb-layer-name')?.textContent)
|
||||
await page.keyboard.press('Control+[') // 下移一层
|
||||
const afterDown = await panelSeq()
|
||||
check('「下移一层」改变图层顺序', before !== afterDown, before + ' → ' + afterDown)
|
||||
await page.locator('.iwb-editor-layer-btn[data-layer="up"]').click()
|
||||
check('「上移一层」恢复原顺序', (await panelSeq()) === before, await panelSeq())
|
||||
await page.locator('.iwb-editor-layer-btn[data-layer="bottom"]').click()
|
||||
check('Ctrl+[ 下移一层改变图层顺序', before !== afterDown, before + ' → ' + afterDown)
|
||||
await page.keyboard.press('Control+]') // 上移一层
|
||||
check('Ctrl+] 上移一层恢复原顺序', (await panelSeq()) === before, await panelSeq())
|
||||
|
||||
await page.keyboard.press('Control+Shift+[') // 置底
|
||||
const afterBottom = await panelSeq()
|
||||
check('「置底」生效且原图仍在最底(元素不会消失)',
|
||||
afterBottom !== before && afterBottom.endsWith('原图'), afterBottom)
|
||||
await page.locator('.iwb-editor-layer-btn[data-layer="top"]').click()
|
||||
check('「置顶」生效', (await panelSeq()) !== afterBottom, await panelSeq())
|
||||
check('Ctrl+Shift+[ 置底生效(元素不会消失)',
|
||||
afterBottom !== before && afterBottom.endsWith(String(activeName)), afterBottom)
|
||||
check('置底后原图不再被钉在最底 —— 图层可以压到原图下面(v1.13 解封)',
|
||||
!afterBottom.endsWith('原图'), afterBottom)
|
||||
await page.keyboard.press('Control+Shift+]') // 置顶
|
||||
check('Ctrl+Shift+] 置顶生效', (await panelSeq()) !== afterBottom, await panelSeq())
|
||||
check('排序后仍只有一个选中项', (await activeCount()) === 1, 'active=' + await activeCount())
|
||||
|
||||
// v1.14 字体选择:真站是带 CSP 的环境,这里确认下拉可用、字体切换真的落到了对象上。
|
||||
// 系统字体不受 CSP 约束(CSP 管的是网络字体),所以只要 canvas 能画就没问题。
|
||||
const famDbg = () => page.evaluate(() => window.__iwbEditor.__debug())
|
||||
const FAM_SEL = '.iwb-editor-optionbar-body select[data-opt-text="fontFamily"]'
|
||||
await page.locator('.iwb-editor-tool[data-tool="text"]').click()
|
||||
const famBox = await page.locator('.iwb-editor-layer-canvas').first().boundingBox()
|
||||
await page.mouse.click(famBox.x + 60, famBox.y + 60)
|
||||
await page.waitForTimeout(300)
|
||||
await page.evaluate(() => {
|
||||
const el = document.querySelector('.iwb-editor-text-input')
|
||||
if (!el) return
|
||||
el.focus()
|
||||
el.value = '字体测试'
|
||||
el.dispatchEvent(new Event('input', { bubbles: true }))
|
||||
})
|
||||
await page.keyboard.press('Enter')
|
||||
await page.waitForTimeout(400)
|
||||
|
||||
const famOpts = await page.locator(FAM_SEL + ' option').allTextContents()
|
||||
check('真站选项栏出现字体下拉,四档:黑体 / 宋体 / 楷体 / 圆体',
|
||||
famOpts.length === 4, JSON.stringify(famOpts))
|
||||
|
||||
const wSans = ((await famDbg()).texts.find((t) => t.text === '字体测试') || {}).box
|
||||
await page.selectOption(FAM_SEL, 'serif')
|
||||
await page.waitForTimeout(320)
|
||||
const tSerif = (await famDbg()).texts.find((t) => t.text === '字体测试')
|
||||
check('真站切换宋体生效,且中文宽度不变(全角等宽,版面不跳动)',
|
||||
Boolean(tSerif && tSerif.fontFamily === 'serif' && wSans && Math.abs(tSerif.box.w - wSans.w) <= 1),
|
||||
(wSans ? wSans.w : '?') + ' → ' + (tSerif ? tSerif.box.w : '?'))
|
||||
await page.keyboard.press('Delete')
|
||||
await page.waitForTimeout(200)
|
||||
|
||||
// 复原成画笔工具,避免影响后面「覆盖」链路的画笔取样
|
||||
await page.locator('.iwb-editor-tool[data-tool="brush"]').click()
|
||||
}
|
||||
|
||||
@@ -865,18 +865,8 @@ selShapeDbg = await dbg()
|
||||
check('选中矩形就地改线宽 9', selShapeDbg.shapes[selShapeDbg.shapes.length - 1].lw === 9,
|
||||
JSON.stringify(selShapeDbg.shapes.slice(-1)))
|
||||
|
||||
// Shift+X:选中形状切 描边/实心(PS 风格;数字框输完值直接按也必须生效)
|
||||
check('Shift+X 切换选中形状 描边/实心(对象与选项栏按钮同步)', await (async () => {
|
||||
await page.keyboard.press('Shift+x')
|
||||
const d = await dbg()
|
||||
const sh = d.shapes.find(s => s.id === d.selectedShapeId)
|
||||
const btnActive = await page.evaluate(() => document.querySelector('.iwb-editor-optionbar-body [data-opt-toggle="fill"][data-fill-owner="rect"]').classList.contains('active'))
|
||||
const flipped = sh && sh.fill === true && btnActive
|
||||
await page.keyboard.press('Shift+x') // 切回描边,恢复现场
|
||||
const d2 = await dbg()
|
||||
const sh2 = d2.shapes.find(s => s.id === d2.selectedShapeId)
|
||||
return flipped && sh2 && sh2.fill === false
|
||||
})())
|
||||
// Shift+X 的用例在文件末尾(它会把「下一个图形的填充色」也写成具体色值,
|
||||
// 落在中间会污染后面「新建图形填充默认跟随描边色」那条断言)
|
||||
|
||||
// 钢笔:闭合路径选中后同样可切描边/实心
|
||||
await page.locator('.iwb-editor-tool[data-tool="pen"]').click()
|
||||
@@ -1082,7 +1072,7 @@ check('画笔按住 Alt 临时吸色,松开 Alt 回到画笔(可连续取色
|
||||
: 'up: tool=' + d3.tool + ' alt=' + d3.altPicker
|
||||
})())
|
||||
|
||||
// Shift+X:选中形状切 描边/实心(PS 风格,用户裁定 2026-11-04 晚)
|
||||
// Shift+X 的用例见上面「Shift+X 交换填充色与描边色」(v1.13.1 起是交换语义,不再是实心/描边开关)
|
||||
|
||||
// 图层快捷键:Ctrl+]/[ 上/下移、Ctrl+Shift+]/[ 置顶/置底、Alt+]/[ 选层、Delete 删图层
|
||||
// 注意:__debug().layers 是 S.layers 数组原序,叠放顺序必须看 z(位图与矢量共用一套 z)
|
||||
@@ -1737,6 +1727,84 @@ check('文字支持多行(Shift+Enter 换行,包围盒高 ≈ 两行)',
|
||||
multiLine && vdbg.texts[0].box.h >= singleH * 2 - 2,
|
||||
multiLine ? 'h=' + vdbg.texts[0].box.h + ' 单行=' + Math.round(singleH) : JSON.stringify(vdbg.texts))
|
||||
|
||||
// ---- v1.14 字体选择:系统字体族(黑 / 宋 / 楷 / 圆)----
|
||||
// 为什么只做系统字体:宿主 CSP 是 default-src 'self',font-src 回落它,第三方字体 CDN
|
||||
// 会被浏览器直接拦掉;中文字体 2–64MB(本机宋体 2.3MB、楷体 2.2MB、苹方全字重 64MB),
|
||||
// 内联进 389KB 的插件不现实。系统字体栈 0 字节、同步可用,没有「字体没加载完就
|
||||
// measureText」导致选中框和字形错位的时序问题 —— 这是内置字体方案最大的坑。
|
||||
const FAM_SEL = '.iwb-editor-optionbar-body select[data-opt-text="fontFamily"]'
|
||||
const FAM_KEYS = ['sans', 'serif', 'kai', 'round']
|
||||
const famCount = await page.locator(FAM_SEL).count()
|
||||
const famOpts = famCount ? await page.locator(FAM_SEL + ' option').allTextContents() : []
|
||||
check('选中文字后选项栏出现字体下拉,四档:黑体 / 宋体 / 楷体 / 圆体',
|
||||
famCount === 1 && famOpts.join(',') === '黑体,宋体,楷体,圆体',
|
||||
'count=' + famCount + ' opts=' + famOpts.join(','))
|
||||
|
||||
// 切换字体要同时做两件事:写进选中的这段文字 + 成为下一段新文字的默认值
|
||||
await page.selectOption(FAM_SEL, 'kai')
|
||||
await page.waitForTimeout(240)
|
||||
let famDbg = await dbg()
|
||||
check('下拉切换字体写到选中文字,并同步「新建文字默认字体」',
|
||||
famDbg.texts[0].fontFamily === 'kai' && famDbg.textDefaults.family === 'kai',
|
||||
'obj=' + famDbg.texts[0].fontFamily + ' default=' + famDbg.textDefaults.family)
|
||||
|
||||
// 一次切换 = 一步历史
|
||||
// 注意断言只查对象、不查 textDefaults:快照(history.js#snapshotState)只存
|
||||
// texts/shapes/bitmaps/layerOrder,不含「新建文字默认值」—— 字重、对齐、行距
|
||||
// 都是同一行为,撤销回到对象上一步的样子,但"下一段文字用什么样式"不会跟着回退。
|
||||
await page.keyboard.press('Control+z')
|
||||
await page.waitForTimeout(240)
|
||||
famDbg = await dbg()
|
||||
check('Ctrl+Z 撤销字体切换,文字对象回到上一个字体',
|
||||
famDbg.texts[0].fontFamily === 'sans',
|
||||
'obj=' + famDbg.texts[0].fontFamily)
|
||||
|
||||
// 中文是全角等宽:换字体不改字宽,所以切字体不会让已有的标注版面跳动。
|
||||
// (拉丁字母和数字是比例宽,会伸缩 —— 这也是选择「左上角锚定」而不是居中的理由。)
|
||||
await page.locator('.iwb-editor-tool[data-tool="text"]').click()
|
||||
const cnPt = await imgToScreen(4, 30)
|
||||
await page.mouse.click(cnPt.x, cnPt.y)
|
||||
await page.waitForTimeout(220)
|
||||
await page.evaluate(() => {
|
||||
const el = document.querySelector('.iwb-editor-text-input')
|
||||
el.focus()
|
||||
el.value = '测试'
|
||||
el.dispatchEvent(new Event('input', { bubbles: true }))
|
||||
})
|
||||
await page.keyboard.press('Enter')
|
||||
await page.waitForTimeout(320)
|
||||
const cnBefore = ((await dbg()).texts.find(t => t.text === '测试') || {}).box
|
||||
await page.selectOption(FAM_SEL, 'serif')
|
||||
await page.waitForTimeout(240)
|
||||
const cnAfter = ((await dbg()).texts.find(t => t.text === '测试') || {}).box
|
||||
check('换字体不改变中文宽度(全角等宽,版面不跳动)',
|
||||
cnBefore && cnAfter && Math.abs(cnAfter.w - cnBefore.w) <= 1,
|
||||
(cnBefore ? cnBefore.w : '?') + ' → ' + (cnAfter ? cnAfter.w : '?'))
|
||||
|
||||
// 脏值防御:不认识的 fontFamily 必须收敛回默认。否则整串 ctx.font 会失效、
|
||||
// 静默退回浏览器默认字体 —— 画面上看不出报错,排查成本极高。
|
||||
const badDispatch = await page.evaluate(() => {
|
||||
const s = document.querySelector('.iwb-editor-optionbar-body select[data-opt-text="fontFamily"]')
|
||||
if (!s) return 'no-select'
|
||||
const o = document.createElement('option')
|
||||
o.value = 'NotAFont'
|
||||
o.textContent = 'NotAFont'
|
||||
s.appendChild(o)
|
||||
s.value = 'NotAFont'
|
||||
s.dispatchEvent(new Event('change', { bubbles: true }))
|
||||
return 'dispatched'
|
||||
})
|
||||
await page.waitForTimeout(200)
|
||||
const badDbg = await dbg()
|
||||
check('不认识的字体值被收敛回默认(脏值不会写进 ctx.font)',
|
||||
badDispatch === 'dispatched' && badDbg.texts.length > 0 &&
|
||||
badDbg.texts.every(t => FAM_KEYS.indexOf(t.fontFamily) >= 0),
|
||||
JSON.stringify(badDbg.texts.map(t => t.fontFamily)))
|
||||
|
||||
// 清理:这一小段是为字体用例新建的,删掉避免污染后面的像素断言
|
||||
await page.keyboard.press('Delete')
|
||||
await page.waitForTimeout(200)
|
||||
|
||||
// 选择工具在「未选中任何元素」时也必须露出全选/反选/取消三个图标,且只能有一组。
|
||||
// 它们曾被排在 margin-left:auto 的 hint 之后,被一路推到最右、滚出可视区,
|
||||
// 表现就是「文字工具下有这三个按钮,切到选择工具就没了」。
|
||||
@@ -2399,6 +2467,50 @@ check('无选中时 Ctrl+] 有 toast 提示(不再无声失败)', await (asy
|
||||
return t.indexOf('选中') >= 0
|
||||
})())
|
||||
|
||||
// ---- v1.13.1:Shift+X 改成「交换填充色与描边色」(以前是 实心/描边 开关)----
|
||||
// 旧语义下按一次,填充被关掉、描边纹丝不动 —— 用户的原话是「丢失填充色」。
|
||||
// 放在最后跑:交换会把「下一个图形的填充色」也写成具体色值,前面有条断言要求它是 null。
|
||||
const shiftXSwap = await (async () => {
|
||||
await page.locator('.iwb-editor-tool[data-tool="rect"]').click()
|
||||
const a = { x: imgBox.x + imgBox.width * 0.10, y: imgBox.y + imgBox.height * 0.10 }
|
||||
const b = { x: imgBox.x + imgBox.width * 0.30, y: imgBox.y + imgBox.height * 0.30 }
|
||||
await page.mouse.move(a.x, a.y); await page.mouse.down()
|
||||
await page.mouse.move(b.x, b.y, { steps: 6 }); await page.mouse.up()
|
||||
await page.waitForTimeout(180)
|
||||
await page.locator('.iwb-editor-tool[data-tool="select"]').click()
|
||||
await page.mouse.click((a.x + b.x) / 2, (a.y + b.y) / 2)
|
||||
await page.waitForTimeout(150)
|
||||
// 给个独立填充色,描边色保持主色,两边不同才看得出交换
|
||||
await page.evaluate(() => {
|
||||
const el = document.querySelector('.iwb-editor-optionbar-body [data-shape-color="fill"]')
|
||||
el.value = '#22cc55'
|
||||
el.dispatchEvent(new Event('input', { bubbles: true }))
|
||||
el.dispatchEvent(new Event('change', { bubbles: true }))
|
||||
})
|
||||
await page.waitForTimeout(180)
|
||||
const d0 = await dbg()
|
||||
const sh0 = d0.shapes.find(s => s.id === d0.selectedShapeId)
|
||||
if (!sh0) return { ok: false, detail: '没选中形状' }
|
||||
const stroke0 = sh0.color, fill0 = sh0.fillColor, fillOn0 = sh0.fill
|
||||
await page.keyboard.press('Shift+x')
|
||||
const d1 = await dbg()
|
||||
const sh1 = d1.shapes.find(s => s.id === d1.selectedShapeId)
|
||||
const swapped = Boolean(sh1 && sh1.color === fill0 && sh1.fillColor === stroke0 && sh1.fill === fillOn0)
|
||||
await page.keyboard.press('Shift+x') // 再按一次回到原样
|
||||
const d2 = await dbg()
|
||||
const sh2 = d2.shapes.find(s => s.id === d2.selectedShapeId)
|
||||
const back = Boolean(sh2 && sh2.color === stroke0 && sh2.fillColor === fill0 && sh2.fill === fillOn0)
|
||||
return {
|
||||
ok: swapped && back,
|
||||
detail: JSON.stringify({
|
||||
原: { 描边: stroke0, 填充: fill0, 填充开: fillOn0 },
|
||||
交换后: sh1 && { 描边: sh1.color, 填充: sh1.fillColor, 填充开: sh1.fill },
|
||||
再按: sh2 && { 描边: sh2.color, 填充: sh2.fillColor }
|
||||
})
|
||||
}
|
||||
})()
|
||||
check('Shift+X 交换填充色与描边色(填充不会被关掉、再按回到原样)', shiftXSwap.ok, shiftXSwap.detail)
|
||||
|
||||
await page.locator('[data-action="cancel"]').click()
|
||||
const openState = await poll(async () => page.evaluate(() => window.__openState))
|
||||
check('点「退出」:宿主 Promise 结算为 cancel 且编辑器关闭',
|
||||
|
||||
Reference in new issue
Block a user