Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3baa76d0cd |
No files matched your search
@@ -234,6 +234,39 @@ P 下双击 = 结束当前路径(`commitPenPath`),不再进节点编辑。
|
|||||||
- 文字 / 形状 / 钢笔会被直接栅格化进结果层(PS 合并矢量层也是这个结果)。
|
- 文字 / 形状 / 钢笔会被直接栅格化进结果层(PS 合并矢量层也是这个结果)。
|
||||||
- 结果层落回「原最低参与层」的位置,`assignLayerZ` 重新连续编号,不产生重复 z。
|
- 结果层落回「原最低参与层」的位置,`assignLayerZ` 重新连续编号,不产生重复 z。
|
||||||
|
|
||||||
|
## v1.17.0:描边也能是「无色」+ 一边无色时 Shift+X 照样交换
|
||||||
|
|
||||||
|
用户两句话:「让矢量图形与钢笔的描边色也可以去掉」「描边与填充有一个是无色的时候可以交换,
|
||||||
|
现在是不可以的」。
|
||||||
|
|
||||||
|
### 描边的第三态
|
||||||
|
|
||||||
|
以前描边只有「什么颜色」,没有「有没有」。现在形状对象多一个 `strokeOn`(缺省 = 有,
|
||||||
|
老对象与历史快照没有这个字段一律当有描边,不需要数据迁移):
|
||||||
|
|
||||||
|
- `drawShape()` 里所有 `ctx.stroke()` 都按 `strokeOn` 跳过。**不能用 `lineWidth = 0` 实现**——
|
||||||
|
canvas 会忽略 0 并保留上一次的线宽,且改回需要记住原值;
|
||||||
|
- 「无」按钮出现在**描边槽**(色板头部 / 右栏面板同一份 DOM),点一下只关外框、颜色留着,
|
||||||
|
下次选色直接恢复(与「文字描边宽度 0 时选色自动给 6px」同一条逻辑,选色共用一张快照,撤销一步);
|
||||||
|
- 「只描边」的形状去掉描边会整体消失,所以**顺手切实心** —— 结果是「一个没有框的色块」,
|
||||||
|
而不是「对象凭空没了」;反过来在选项栏点「描边」也会自动恢复 `strokeOn`;
|
||||||
|
- 只有**「去掉后还看得见」才给「无」**:矩形/圆形、闭合钢笔可以;箭头、未闭合钢笔不给
|
||||||
|
(判据复用 `fillSlotOn()`,与「填充槽存不存在」同一份逻辑);
|
||||||
|
- 视觉:工具栏描边格与色板 tab 画红斜杠(复用 `.is-none`),选项栏描边色块置灰(`.is-off`)。
|
||||||
|
|
||||||
|
### Shift+X:交换的是「颜色 + 有无」
|
||||||
|
|
||||||
|
以前只交换颜色值,所以「无填充」时按 X 看不出任何变化(只有一个颜色,被判定为「无需交换」)。
|
||||||
|
现在交换整份状态:
|
||||||
|
|
||||||
|
- 两边都有色 → 颜色对调,开关不动(v1.13.1 的语义保留);
|
||||||
|
- 只有一边有色 → 有色那边连同颜色整体换到另一边(无填充 + 有色描边 ⇄ 有色填充 + 无描边);
|
||||||
|
- 填充色还在「跟随描边色」(`fillColor=null`)→ 只换有无,颜色继续跟随,不拆成独立色;
|
||||||
|
- 两边都无色、或箭头/未闭合钢笔(换完什么都不剩)→ toast 提示,不写历史。
|
||||||
|
|
||||||
|
`__debug().shapes` 增加 `strokeOn`,harness 补 6 条(描边像素清零、三处 UI 斜杠态、
|
||||||
|
选色恢复描边、钢笔闭合可去描边、未闭合不给入口、一边无色可交换并回退)。
|
||||||
|
|
||||||
## v1.16.0:右栏常驻调色面板 + 可拖宽度 + 整体字号提升
|
## v1.16.0:右栏常驻调色面板 + 可拖宽度 + 整体字号提升
|
||||||
|
|
||||||
用户三句话拆成四件事:面板文字偏小、右栏要能拖宽、把调色面板(含常用色)搬进右栏、
|
用户三句话拆成四件事:面板文字偏小、右栏要能拖宽、把调色面板(含常用色)搬进右栏、
|
||||||
|
|||||||
@@ -311,6 +311,7 @@ getCompositeCanvas() // 当前这一张
|
|||||||
| 工具参数解耦与选项栏 | ✅ v1.2.0:`S.shapeLineWidth` / `S.textSize` 独立于 `S.brushSize`;选项栏按工具出参数(画笔三参、形状线宽+填充、文字字号、选区形状/羽化),与右侧面板双向同步 |
|
| 工具参数解耦与选项栏 | ✅ v1.2.0:`S.shapeLineWidth` / `S.textSize` 独立于 `S.brushSize`;选项栏按工具出参数(画笔三参、形状线宽+填充、文字字号、选区形状/羽化),与右侧面板双向同步 |
|
||||||
| P3 图层增强 | 🟡 v1.7:缩略图 / 重命名 / 多选 / 不透明度滑杆已补;混合模式 / 图层蒙版 / 编组未做 |
|
| P3 图层增强 | 🟡 v1.7:缩略图 / 重命名 / 多选 / 不透明度滑杆已补;混合模式 / 图层蒙版 / 编组未做 |
|
||||||
| P4 单张输出 | ✅ PNG/JPG/WebP、透明/白底、800×800(长边 80%)、≤500KB 迭代降质、下载、设置记忆;无队列 |
|
| P4 单张输出 | ✅ PNG/JPG/WebP、透明/白底、800×800(长边 80%)、≤500KB 迭代降质、下载、设置记忆;无队列 |
|
||||||
|
| 描边「无色」+ X 交换整份状态(v1.17.0) | ✅ 形状对象新增 `strokeOn`(缺省有描边,老对象/历史快照无此字段照旧),`drawShape()` 按它跳过 `ctx.stroke()`(不能用 `lineWidth=0`:canvas 忽略 0 且丢失原值);「无」按钮扩到**描边槽**,只关外框、颜色留着,选色即恢复(共用一张快照);去掉描边后会把「只描边」的形状顺手切实心,避免对象消失;箭头与未闭合钢笔不给入口(判据复用 `fillSlotOn()`)。Shift+X 从「只交换颜色」升级为**交换颜色 + 有无**:一边有色时连同颜色整体换到另一边,填充「跟随描边色」时只换有无不拆独立色,两边都无色或换完一无所有则提示不执行 |
|
||||||
| 右栏调色面板 / 可拖宽度 / 字号(v1.16.0) | ✅ 调色面板从「只弹层」变成「右栏常驻 + 弹层保留」,两处共用同一份 DOM(`dom.js#colorSurfaceHtml`),按 `[data-color-surface]` 各绑一次交互、`updateColorUI` 改遍历同步(HEX / SV / 色相 / 「无」显隐 / 常用色与最近色高亮);右栏宽度统一到 CSS 变量 `--iwb-side-w`(原三处硬编码 240/240/220),手柄 9px 热区、范围 220–520 且 ≤ 窗口 45%、默认 280、双击复位、写 `settings.sideWidth` 记忆;字号在 CSS 末尾用 `#iwb-editor-overlay` 前缀集中 +1 档(面板行名 12.5 / 标题 13 / 状态栏 12 / 选项栏 13 / 颜色 tab 12.5),调节名称列 46→50、数值框 36→40 |
|
| 右栏调色面板 / 可拖宽度 / 字号(v1.16.0) | ✅ 调色面板从「只弹层」变成「右栏常驻 + 弹层保留」,两处共用同一份 DOM(`dom.js#colorSurfaceHtml`),按 `[data-color-surface]` 各绑一次交互、`updateColorUI` 改遍历同步(HEX / SV / 色相 / 「无」显隐 / 常用色与最近色高亮);右栏宽度统一到 CSS 变量 `--iwb-side-w`(原三处硬编码 240/240/220),手柄 9px 热区、范围 220–520 且 ≤ 窗口 45%、默认 280、双击复位、写 `settings.sideWidth` 记忆;字号在 CSS 末尾用 `#iwb-editor-overlay` 前缀集中 +1 档(面板行名 12.5 / 标题 13 / 状态栏 12 / 选项栏 13 / 颜色 tab 12.5),调节名称列 46→50、数值框 36→40 |
|
||||||
| 调节基准跨图串用修复(v1.15.1) | ✅ 退出编辑器后 `sourceCache`(key = `layer.id`,原图恒为 `'base'`)与 `S.adjust` 未清 ⇒ 第二张图一拖滑杆就把上一张图的像素重算上来,且 `ensureAdjustTarget()` 因 `layerId` 相同而跳过重拍基准。新增 `resetAdjustCache()`,在 `resetState()` 与 `releaseEditorMemory()` 双路径清空;`__debug()` 增 `adjustCacheSize` 观测口,harness 补「退出→重开」三条断言 |
|
| 调节基准跨图串用修复(v1.15.1) | ✅ 退出编辑器后 `sourceCache`(key = `layer.id`,原图恒为 `'base'`)与 `S.adjust` 未清 ⇒ 第二张图一拖滑杆就把上一张图的像素重算上来,且 `ensureAdjustTarget()` 因 `layerId` 相同而跳过重拍基准。新增 `resetAdjustCache()`,在 `resetState()` 与 `releaseEditorMemory()` 双路径清空;`__debug()` 增 `adjustCacheSize` 观测口,harness 补「退出→重开」三条断言 |
|
||||||
| 图片调节(v1.15.0) | ✅ 右侧栏新增 11 项连续调色:曝光(±2EV)/明度/对比度/阴影/高光/色相/饱和度/温度/色调/锐度/清晰度。走 `getImageData` 逐像素(CSS filter 做不到阴影高光的分区蒙版、白平衡的通道增益、锐化的卷积);拖动用长边 ≤900 的降采样预览(6.7ms),松手才全量(4000² 144ms)。`source` + 每层 `sourceCache` 保证永远从基准重算不叠加;撤销后滑块归零并重拍基准。顺带修强度:增强 brightness 1.12→1.4、高对比 contrast 1.4→1.6 |
|
| 图片调节(v1.15.0) | ✅ 右侧栏新增 11 项连续调色:曝光(±2EV)/明度/对比度/阴影/高光/色相/饱和度/温度/色调/锐度/清晰度。走 `getImageData` 逐像素(CSS filter 做不到阴影高光的分区蒙版、白平衡的通道增益、锐化的卷积);拖动用长边 ≤900 的降采样预览(6.7ms),松手才全量(4000² 144ms)。`source` + 每层 `sourceCache` 保证永远从基准重算不叠加;撤销后滑块归零并重拍基准。顺带修强度:增强 brightness 1.12→1.4、高对比 contrast 1.4→1.6 |
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@iwb-plugin/image-annotate",
|
"name": "@iwb-plugin/image-annotate",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "1.16.0",
|
"version": "1.17.0",
|
||||||
"description": "IWB 插件:图片标注 / 修图(编辑器移植自 iwb-plaus 扩展,纯 Canvas 2D)",
|
"description": "IWB 插件:图片标注 / 修图(编辑器移植自 iwb-plaus 扩展,纯 Canvas 2D)",
|
||||||
"ibwPlugin": {
|
"ibwPlugin": {
|
||||||
"id": "image-annotate",
|
"id": "image-annotate",
|
||||||
|
|||||||
@@ -549,6 +549,7 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
lw: Math.max(1, S.shapeLineWidth),
|
lw: Math.max(1, S.shapeLineWidth),
|
||||||
lineWidth: Math.max(1, S.shapeLineWidth),
|
lineWidth: Math.max(1, S.shapeLineWidth),
|
||||||
fill: S.tool === 'rect' || S.tool === 'circle' ? !!S.rectFill : false,
|
fill: S.tool === 'rect' || S.tool === 'circle' ? !!S.rectFill : false,
|
||||||
|
strokeOn: S.shapeStrokeOn !== false,
|
||||||
radius: S.tool === 'rect' ? Math.max(0, S.shapeRadius) : 0,
|
radius: S.tool === 'rect' ? Math.max(0, S.shapeRadius) : 0,
|
||||||
opacity: 1,
|
opacity: 1,
|
||||||
visible: true
|
visible: true
|
||||||
@@ -754,6 +755,7 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
fillColor: S.shapeFillColor, // null = 跟随描边色(改主色时整块跟着变)
|
fillColor: S.shapeFillColor, // null = 跟随描边色(改主色时整块跟着变)
|
||||||
lw: Math.max(1, S.shapeLineWidth),
|
lw: Math.max(1, S.shapeLineWidth),
|
||||||
fill: S.tool === 'rect' || S.tool === 'circle' ? !!S.rectFill : false,
|
fill: S.tool === 'rect' || S.tool === 'circle' ? !!S.rectFill : false,
|
||||||
|
strokeOn: S.shapeStrokeOn !== false,
|
||||||
radius: S.tool === 'rect' ? Math.max(0, S.shapeRadius) : 0,
|
radius: S.tool === 'rect' ? Math.max(0, S.shapeRadius) : 0,
|
||||||
opacity: 1,
|
opacity: 1,
|
||||||
visible: true,
|
visible: true,
|
||||||
@@ -899,6 +901,16 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
return sh.type === 'rect' || sh.type === 'circle' || (sh.type === 'pen' && !!sh.closed)
|
return sh.type === 'rect' || sh.type === 'circle' || (sh.type === 'pen' && !!sh.closed)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 「无描边」(v1.17)能不能给:只有「去掉描边后画面还看得见」才给。
|
||||||
|
* 判据就是 fillSlotOn() —— 能填充才谈得上不要描边:
|
||||||
|
* 箭头没有内部、未闭合的钢笔没有面积,去掉描边等于把这个对象删掉,
|
||||||
|
* 这两种情况宁可不给按钮,也别让用户点出一个「看不见的对象」。
|
||||||
|
* 文字不在此列:文字描边是第二格「描边」,早就有「无」了。 */
|
||||||
|
function strokeSlotCanBeNone() {
|
||||||
|
const ctx = colorContext()
|
||||||
|
return ctx.kind === 'shape' && fillSlotOn()
|
||||||
|
}
|
||||||
|
|
||||||
/** 文字的三个颜色槽(v1.12)。
|
/** 文字的三个颜色槽(v1.12)。
|
||||||
* 文字对象本来就有三个颜色字段:color(文字本身)/ strokeColor(字的外描边)/
|
* 文字对象本来就有三个颜色字段:color(文字本身)/ strokeColor(字的外描边)/
|
||||||
* bgColor(文本框底色)。上一版把它们硬塞进「描边 / 填充」两格,第二格其实是
|
* bgColor(文本框底色)。上一版把它们硬塞进「描边 / 填充」两格,第二格其实是
|
||||||
@@ -935,9 +947,15 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
const fillOn = sh
|
const fillOn = sh
|
||||||
? (sh.type === 'pen' ? (!!sh.fill && !!sh.closed) : !!sh.fill)
|
? (sh.type === 'pen' ? (!!sh.fill && !!sh.closed) : !!sh.fill)
|
||||||
: (S.tool === 'pen' ? !!S.penFill : !!S.rectFill)
|
: (S.tool === 'pen' ? !!S.penFill : !!S.rectFill)
|
||||||
|
// v1.17:描边也有「有 / 无」两态。老对象没有 strokeOn 字段 ⇒ 视为有描边。
|
||||||
|
// 只有 shape 上下文才谈得上无描边:箭头/画笔那一格是「唯一颜色」,
|
||||||
|
// 显示成斜杠会让人以为画笔也画不出颜色。
|
||||||
|
const strokeOn = ctx.kind !== 'shape'
|
||||||
|
? true
|
||||||
|
: (sh ? (sh.strokeOn !== false) : (S.shapeStrokeOn !== false))
|
||||||
return {
|
return {
|
||||||
mode: ctx.kind === 'shape' ? 'shape' : 'single',
|
mode: ctx.kind === 'shape' ? 'shape' : 'single',
|
||||||
stroke, fill: rawFill || stroke, fillOn, follow: !rawFill,
|
stroke, strokeOn, fill: rawFill || stroke, fillOn, follow: !rawFill,
|
||||||
bg: null, bgOn: false, bgAlpha: 1,
|
bg: null, bgOn: false, bgAlpha: 1,
|
||||||
strokeName: '描边', fillName: '填充', bgName: '底色'
|
strokeName: '描边', fillName: '填充', bgName: '底色'
|
||||||
}
|
}
|
||||||
@@ -972,11 +990,15 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
const dot = strokeBtn.querySelector('i')
|
const dot = strokeBtn.querySelector('i')
|
||||||
if (dot) dot.style.backgroundColor = sl.stroke
|
if (dot) dot.style.backgroundColor = sl.stroke
|
||||||
strokeBtn.classList.toggle('active', S.colorTarget === 'stroke')
|
strokeBtn.classList.toggle('active', S.colorTarget === 'stroke')
|
||||||
|
// v1.17:无描边时色块画红斜杠,和「无填充」同一套视觉语言
|
||||||
|
strokeBtn.classList.toggle('is-none', !isText && sl.strokeOn === false)
|
||||||
strokeBtn.title = isText
|
strokeBtn.title = isText
|
||||||
? `文字色 ${String(sl.stroke).toUpperCase()}:改文字本身的颜色(右边「描边」是字的外描边)`
|
? `文字色 ${String(sl.stroke).toUpperCase()}:改文字本身的颜色(右边「描边」是字的外描边)`
|
||||||
: (second
|
: (sl.strokeOn === false
|
||||||
? `描边色 ${String(sl.stroke).toUpperCase()}:形状描边也用这个值。点开色板调色`
|
? '描边:无(只有填充)。点开选色会自动恢复描边'
|
||||||
: `${strokeName}色 ${String(sl.stroke).toUpperCase()}:点开色板调色`)
|
: (second
|
||||||
|
? `描边色 ${String(sl.stroke).toUpperCase()}:形状描边也用这个值。点开色板调色,「无」= 去掉描边`
|
||||||
|
: `${strokeName}色 ${String(sl.stroke).toUpperCase()}:点开色板调色`))
|
||||||
const popEl = runtime.el.querySelector('.iwb-editor-color-pop')
|
const popEl = runtime.el.querySelector('.iwb-editor-color-pop')
|
||||||
strokeBtn.setAttribute('aria-expanded', String(!!(popEl && !popEl.hidden && S.colorTarget === 'stroke')))
|
strokeBtn.setAttribute('aria-expanded', String(!!(popEl && !popEl.hidden && S.colorTarget === 'stroke')))
|
||||||
}
|
}
|
||||||
@@ -1030,19 +1052,24 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
: (isText ? '正在调文字色(文字本身的颜色)' : '正在调描边色'))
|
: (isText ? '正在调文字色(文字本身的颜色)' : '正在调描边色'))
|
||||||
if (isFill) { tab.classList.toggle('is-none', !sl.fillOn); tab.hidden = !second }
|
if (isFill) { tab.classList.toggle('is-none', !sl.fillOn); tab.hidden = !second }
|
||||||
if (isBg) { tab.classList.toggle('is-none', !sl.bgOn); tab.hidden = !isText }
|
if (isBg) { tab.classList.toggle('is-none', !sl.bgOn); tab.hidden = !isText }
|
||||||
|
// 描边格:文字的「描边」是第二格(上面已处理),文字色/单槽上下文不允许「无」
|
||||||
|
if (!isFill && !isBg) tab.classList.toggle('is-none', !isText && sl.strokeOn === false)
|
||||||
})
|
})
|
||||||
// 「无」:形状 = 无填充;文字描边 = 描边宽度 0;文字底色 = 关掉底色块
|
// 「无」:形状/钢笔 = 无描边或无填充;文字描边 = 描边宽度 0;文字底色 = 关掉底色块
|
||||||
// (文字色没有「无」—— 字没有颜色就等于把字删了,不该给这个按钮)
|
// (文字色与箭头单槽没有「无」—— 去掉就等于把对象删了,不该给这个按钮)
|
||||||
// v1.16:右栏与弹层各有一个「无」,必须按集合刷,否则只有先出现的那个对
|
// v1.16:右栏与弹层各有一个「无」,必须按集合刷,否则只有先出现的那个对
|
||||||
const onBg = S.colorTarget === 'bg' && isText
|
const onBg = S.colorTarget === 'bg' && isText
|
||||||
const onFill = S.colorTarget === 'fill' && second
|
const onFill = S.colorTarget === 'fill' && second
|
||||||
const showNone = onBg || onFill
|
const onStroke = S.colorTarget === 'stroke' && !isText && strokeSlotCanBeNone()
|
||||||
|
const showNone = onBg || onFill || onStroke
|
||||||
runtime.el.querySelectorAll('[data-color-none]').forEach(noneBtn => {
|
runtime.el.querySelectorAll('[data-color-none]').forEach(noneBtn => {
|
||||||
noneBtn.hidden = !showNone
|
noneBtn.hidden = !showNone
|
||||||
noneBtn.classList.toggle('active', showNone && (onBg ? !sl.bgOn : !sl.fillOn))
|
noneBtn.classList.toggle('active', showNone && (onBg ? !sl.bgOn : (onFill ? !sl.fillOn : !sl.strokeOn)))
|
||||||
noneBtn.title = onBg
|
noneBtn.title = onBg
|
||||||
? '无底色:文字后面完全透明'
|
? '无底色:文字后面完全透明'
|
||||||
: (isText ? '无描边:把描边宽度置 0,只留文字本身' : '无填充:形状内部透明,只留描边')
|
: (onStroke
|
||||||
|
? (sl.strokeOn === false ? '当前已是无描边;点选颜色可恢复描边' : '无描边:去掉形状外框,只留内部填充')
|
||||||
|
: (isText ? '无描边:把描边宽度置 0,只留文字本身' : '无填充:形状内部透明,只留描边'))
|
||||||
})
|
})
|
||||||
|
|
||||||
const cur = activeColor()
|
const cur = activeColor()
|
||||||
@@ -1162,7 +1189,7 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
// 取值与工具栏两个色块完全同一份(colorSlots),不再各自算一遍
|
// 取值与工具栏两个色块完全同一份(colorSlots),不再各自算一遍
|
||||||
const sl = colorSlots()
|
const sl = colorSlots()
|
||||||
let html = '<span class="iwb-opt-label">描边</span>'
|
let html = '<span class="iwb-opt-label">描边</span>'
|
||||||
+ `<input type="color" class="iwb-opt-color" data-shape-color="stroke" value="${sl.stroke}" title="描边色:与工具栏左上的描边色块是同一份,改哪边都一样">`
|
+ `<input type="color" class="iwb-opt-color${sl.strokeOn === false ? ' is-off' : ''}" data-shape-color="stroke" value="${sl.stroke}" title="描边色:与工具栏左上的描边色块是同一份,改哪边都一样${sl.strokeOn === false ? ';当前无描边,选色会自动恢复' : ''}">`
|
||||||
if (owner) {
|
if (owner) {
|
||||||
html += '<span class="iwb-opt-label">填充</span>'
|
html += '<span class="iwb-opt-label">填充</span>'
|
||||||
+ `<input type="color" class="iwb-opt-color${sl.fillOn ? '' : ' is-off'}" data-shape-color="fill" data-fill-owner="${owner}" value="${sl.fill}" title="填充色:与工具栏右下的填充色块是同一份${sl.fillOn ? '' : ';当前无填充,选色会自动切成实心'}">`
|
+ `<input type="color" class="iwb-opt-color${sl.fillOn ? '' : ' is-off'}" data-shape-color="fill" data-fill-owner="${owner}" value="${sl.fill}" title="填充色:与工具栏右下的填充色块是同一份${sl.fillOn ? '' : ';当前无填充,选色会自动切成实心'}">`
|
||||||
@@ -1441,7 +1468,12 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
? '填充色:与工具栏右下的填充色块是同一份'
|
? '填充色:与工具栏右下的填充色块是同一份'
|
||||||
: '当前无填充(形状内部透明)。选色会自动切成实心,也可点工具栏填充色块选「无」'
|
: '当前无填充(形状内部透明)。选色会自动切成实心,也可点工具栏填充色块选「无」'
|
||||||
} else {
|
} else {
|
||||||
inp.title = '描边色:与工具栏左上的描边色块是同一份'
|
// v1.17:无描边时描边色块也要置灰(和「无填充」同一套提示)
|
||||||
|
const off = sl.strokeOn === false
|
||||||
|
inp.classList.toggle('is-off', off)
|
||||||
|
inp.title = off
|
||||||
|
? '当前无描边(只有填充)。选色会自动恢复描边,也可点工具栏描边色块选「无」'
|
||||||
|
: '描边色:与工具栏左上的描边色块是同一份'
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
// 选项栏与工具栏是同一份颜色数据:这里一刷新,工具栏两个色槽必须跟着刷。
|
// 选项栏与工具栏是同一份颜色数据:这里一刷新,工具栏两个色槽必须跟着刷。
|
||||||
@@ -1580,9 +1612,9 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
syncOptionBar()
|
syncOptionBar()
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 「无」按钮(v1.11 起只管填充;v1.12 起按格子分派):
|
/** 「无」按钮(v1.11 起只管填充;v1.12 起按格子分派;v1.17 起描边也支持):
|
||||||
* 形状填充 → 内部透明;文字描边 → 描边宽度 0;文字底色 → 关掉底色块。
|
* 形状填充 → 内部透明;形状描边 → 不画外框;文字描边 → 描边宽度 0;文字底色 → 关掉底色块。
|
||||||
* 三种情况都只改开关,颜色留着不动 —— 下次点颜色还是它。 */
|
* 四种情况都只改开关,颜色留着不动 —— 下次点颜色还是它。 */
|
||||||
function applyColorNone() {
|
function applyColorNone() {
|
||||||
const sl = colorSlots()
|
const sl = colorSlots()
|
||||||
if (sl.mode === 'text') {
|
if (sl.mode === 'text') {
|
||||||
@@ -1592,9 +1624,33 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
syncOptionBar()
|
syncOptionBar()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if (S.colorTarget === 'stroke') { applyStrokeNone(); return }
|
||||||
applyShapeColor('none')
|
applyShapeColor('none')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 无描边(v1.17):只关外框,描边色留着,下次选色直接恢复。
|
||||||
|
* 「只描边」的形状去掉描边会整体消失 —— 顺手切实心,
|
||||||
|
* 让结果是「一个没有框的色块」而不是「对象凭空没了」。 */
|
||||||
|
function applyStrokeNone() {
|
||||||
|
if (!strokeSlotCanBeNone()) return
|
||||||
|
S.colorTarget = 'stroke'
|
||||||
|
S.shapeStrokeOn = false
|
||||||
|
const sh = getSelectedShape()
|
||||||
|
if (sh && !sh.locked && sh.strokeOn !== false) {
|
||||||
|
saveSnapshot('无描边')
|
||||||
|
sh.strokeOn = false
|
||||||
|
if (!sh.fill && (sh.type === 'rect' || sh.type === 'circle' || (sh.type === 'pen' && sh.closed))) {
|
||||||
|
sh.fill = true
|
||||||
|
if (sh.type === 'pen') S.penFill = true
|
||||||
|
else S.rectFill = true
|
||||||
|
}
|
||||||
|
renderObjects()
|
||||||
|
}
|
||||||
|
updateFillUI()
|
||||||
|
updateColorUI()
|
||||||
|
syncOptionBar()
|
||||||
|
}
|
||||||
|
|
||||||
/** 形状描边色 / 填充色(v1.10;v1.11 起同时承接「无填充」)。
|
/** 形状描边色 / 填充色(v1.10;v1.11 起同时承接「无填充」)。
|
||||||
* 描边色不另存一份 —— 直接走 applyColorChange 写主色,左侧色板、吸管、
|
* 描边色不另存一份 —— 直接走 applyColorChange 写主色,左侧色板、吸管、
|
||||||
* 文字色、形状描边色四处因此永远同一个值(上一版的教训:同一个概念存两处必分叉)。
|
* 文字色、形状描边色四处因此永远同一个值(上一版的教训:同一个概念存两处必分叉)。
|
||||||
@@ -1622,6 +1678,9 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
if (!/^#[0-9a-f]{6}$/.test(hex)) return
|
if (!/^#[0-9a-f]{6}$/.test(hex)) return
|
||||||
if (kind === 'stroke') {
|
if (kind === 'stroke') {
|
||||||
S.colorTarget = 'stroke'
|
S.colorTarget = 'stroke'
|
||||||
|
// 新建默认值也恢复描边:否则「无描边」状态下改一次描边色,
|
||||||
|
// 下一个新形状仍然是没框的,用户会以为设置没生效
|
||||||
|
S.shapeStrokeOn = true
|
||||||
applyColorChange(hex, opts)
|
applyColorChange(hex, opts)
|
||||||
if (skipHistory) syncOptionBarSoon()
|
if (skipHistory) syncOptionBarSoon()
|
||||||
else syncOptionBar()
|
else syncOptionBar()
|
||||||
@@ -1702,30 +1761,52 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
saveSnapshot('填充')
|
saveSnapshot('填充')
|
||||||
// 未闭合的钢笔路径没有可填区域:保持描边,不动视觉结果
|
// 未闭合的钢笔路径没有可填区域:保持描边,不动视觉结果
|
||||||
sh.fill = isPen ? (!!S.penFill && !!sh.closed) : !!S.rectFill
|
sh.fill = isPen ? (!!S.penFill && !!sh.closed) : !!S.rectFill
|
||||||
|
// 用户明确点了「描边」= 要看见框:无描边的对象顺手恢复,否则点完毫无变化
|
||||||
|
if (!sh.fill && sh.strokeOn === false) { sh.strokeOn = true; S.shapeStrokeOn = true }
|
||||||
renderObjects()
|
renderObjects()
|
||||||
// 对象的 fill 更新在 sync 之后,选择工具下按钮的激活态要再刷一次
|
// 对象的 fill 更新在 sync 之后,选择工具下按钮的激活态要再刷一次
|
||||||
syncOptionBar()
|
syncOptionBar()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** PS 的 X 语义(v1.13.1):把选中形状的「填充色」与「描边色」对调。
|
/** PS 的 X 语义:把选中形状的「描边」与「填充」对调。
|
||||||
* 以前 Shift+X 绑的是「实心 ↔ 只描边」开关 —— 按下去填充被关掉、描边纹丝不动,
|
* v1.13.1:以前 Shift+X 绑的是「实心 ↔ 只描边」开关,按下去填充被关掉、
|
||||||
* 用户的主观体验就是「填充色丢了」,再按一次才回来。用户要的是**交换两个颜色**:
|
* 描边纹丝不动,用户的主观体验就是「填充色丢了」。改为**交换两个颜色**。
|
||||||
* 填充色换到描边的位置、描边色换到填充的位置,填充的开关状态不变(交换的是颜色,不是有无)。
|
* v1.17:交换的是整份状态(颜色 + 有/无),不只是颜色 ——
|
||||||
* 填充色仍「跟随描边色」(fillColor=null)时只有一个颜色,没有可交换的对象,只提示不动数据。 */
|
* 「无填充 + 有色描边」按一下 → 「有色填充 + 无描边」,反之亦然。
|
||||||
|
* 这样「有一边是无色」时也能用(用户反馈的第二个问题);
|
||||||
|
* 两边都有色且填充还在跟随描边时只有一个颜色,才提示不动。
|
||||||
|
* 「未闭合钢笔 / 箭头」没有可填内部:交换后整条路径会消失,直接提示不执行。 */
|
||||||
function swapShapeColors() {
|
function swapShapeColors() {
|
||||||
const sh = getSelectedShape()
|
const sh = getSelectedShape()
|
||||||
if (!sh || sh.locked) return false
|
if (!sh || sh.locked) return false
|
||||||
if (sh.type === 'arrow') { toast('箭头只有描边色,没有可交换的填充色', 'info'); return true }
|
if (sh.type === 'arrow') { toast('箭头只有描边色,没有可交换的填充色', 'info'); return true }
|
||||||
const stroke = sh.color || S.color
|
const canFill = sh.type === 'rect' || sh.type === 'circle' || (sh.type === 'pen' && !!sh.closed)
|
||||||
const fill = sh.fillColor || null
|
const strokeOn = sh.strokeOn !== false
|
||||||
if (!fill) { toast('填充色正跟随描边色(两者同一个颜色),无需交换', 'info'); return true }
|
const fillOn = !!sh.fill
|
||||||
|
const strokeColor = sh.color || S.color
|
||||||
|
const fillColor = sh.fillColor || null // null = 跟随描边色
|
||||||
|
if (!canFill && !fillOn) { toast('这条路径没有可填内部,交换后什么都看不见', 'info'); return true }
|
||||||
|
if (!strokeOn && !fillOn) { toast('描边与填充都是无色,没有可交换的颜色', 'info'); return true }
|
||||||
|
if (strokeOn && fillOn && !fillColor) { toast('填充色正跟随描边色(两者同一个颜色),无需交换', 'info'); return true }
|
||||||
|
|
||||||
saveSnapshot('交换填充与描边色')
|
saveSnapshot('交换填充与描边色')
|
||||||
sh.color = fill
|
// 1) 交换「有 / 无」:哪边有色,交换后就跑到另一边去
|
||||||
S.color = fill // 描边色与主色永远同一份(v1.10 的约定)
|
sh.strokeOn = fillOn
|
||||||
sh.fillColor = stroke
|
sh.fill = strokeOn && canFill
|
||||||
S.shapeFillColor = stroke // 交换后就是独立填充色了,不再跟随描边
|
S.shapeStrokeOn = fillOn
|
||||||
|
if (sh.type === 'pen') S.penFill = !!(sh.fill && sh.closed)
|
||||||
|
else if (sh.type === 'rect' || sh.type === 'circle') S.rectFill = !!sh.fill
|
||||||
|
// 2) 交换颜色。填充原来「跟随描边色」(fillColor=null)就继续跟随 ——
|
||||||
|
// 跟随值恰好就是原描边色,换过去还是同一个颜色,不必把它拆成独立色。
|
||||||
|
if (fillColor) {
|
||||||
|
sh.color = fillColor
|
||||||
|
S.color = fillColor
|
||||||
|
sh.fillColor = strokeColor
|
||||||
|
S.shapeFillColor = strokeColor
|
||||||
|
}
|
||||||
renderObjects()
|
renderObjects()
|
||||||
|
updateFillUI()
|
||||||
updateColorUI()
|
updateColorUI()
|
||||||
syncOptionBar()
|
syncOptionBar()
|
||||||
return true
|
return true
|
||||||
@@ -2509,7 +2590,7 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
function commitPenPath() {
|
function commitPenPath() {
|
||||||
if (!S.penPath || S.penPath.pts.length < 2) { S.penPath = null; renderObjects(); return }
|
if (!S.penPath || S.penPath.pts.length < 2) { S.penPath = null; renderObjects(); return }
|
||||||
saveSnapshot()
|
saveSnapshot()
|
||||||
const shape = { id: 's' + Date.now() + Math.floor(Math.random() * 1000), type: 'pen', pts: S.penPath.pts.slice(), closed: !!S.penPath.closed, color: S.color, fillColor: S.shapeFillColor, lw: Math.max(1, S.shapeLineWidth), fill: !!S.penFill && !!S.penPath.closed, opacity: 1, visible: true, locked: false, z: ++S.zCounter }
|
const shape = { id: 's' + Date.now() + Math.floor(Math.random() * 1000), type: 'pen', pts: S.penPath.pts.slice(), closed: !!S.penPath.closed, color: S.color, fillColor: S.shapeFillColor, lw: Math.max(1, S.shapeLineWidth), fill: !!S.penFill && !!S.penPath.closed, strokeOn: S.shapeStrokeOn !== false, opacity: 1, visible: true, locked: false, z: ++S.zCounter }
|
||||||
// 路径落成即回 V 并选中(v1.5):连续画多条就再按一次 P;节点编辑仍走 V 下双击
|
// 路径落成即回 V 并选中(v1.5):连续画多条就再按一次 P;节点编辑仍走 V 下双击
|
||||||
S.shapeLayers.push(shape); S.penPath = null; renderObjects(); renderLayerPanel()
|
S.shapeLayers.push(shape); S.penPath = null; renderObjects(); renderLayerPanel()
|
||||||
finishCreateTool('shape', shape.id)
|
finishCreateTool('shape', shape.id)
|
||||||
|
|||||||
@@ -338,7 +338,7 @@ import { toast } from './commands.js'
|
|||||||
opacity: l.opacity == null ? 1 : l.opacity,
|
opacity: l.opacity == null ? 1 : l.opacity,
|
||||||
cssOpacity: l.canvas ? parseFloat(l.canvas.style.opacity || '1') : null
|
cssOpacity: l.canvas ? parseFloat(l.canvas.style.opacity || '1') : null
|
||||||
})),
|
})),
|
||||||
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) })),
|
shapes: S.shapeLayers.map(s => ({ id: s.id, type: s.type, lw: s.lw, fill: !!s.fill, closed: !!s.closed, strokeOn: s.strokeOn !== false, 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 => ({
|
texts: S.textLayers.map(t => ({
|
||||||
id: t.id, text: t.text, x: t.x, y: t.y, fontSize: t.fontSize, color: t.color,
|
id: t.id, text: t.text, x: t.x, y: t.y, fontSize: t.fontSize, color: t.color,
|
||||||
fontWeight: t.fontWeight, fontFamily: t.fontFamily, align: t.align, lineHeight: t.lineHeight,
|
fontWeight: t.fontWeight, fontFamily: t.fontFamily, align: t.align, lineHeight: t.lineHeight,
|
||||||
|
|||||||
@@ -45,6 +45,9 @@
|
|||||||
// v1.2 工具参数解耦:形状线宽与文字字号不再借用画笔粗细,
|
// v1.2 工具参数解耦:形状线宽与文字字号不再借用画笔粗细,
|
||||||
// 否则「调细画笔」会顺手把所有形状的描边一起改掉。
|
// 否则「调细画笔」会顺手把所有形状的描边一起改掉。
|
||||||
shapeLineWidth: 3, // 矩形/圆形/箭头/钢笔的描边粗细
|
shapeLineWidth: 3, // 矩形/圆形/箭头/钢笔的描边粗细
|
||||||
|
// v1.17:默认是否画描边。关掉后形状只剩填充(「无描边」),
|
||||||
|
// 对象上另存 strokeOn,老对象没有这个字段一律视为有描边。
|
||||||
|
shapeStrokeOn: true,
|
||||||
shapeRadius: 0, // 矩形圆角半径 px(v1.9,仅 rect 有意义)
|
shapeRadius: 0, // 矩形圆角半径 px(v1.9,仅 rect 有意义)
|
||||||
// v1.10:矢量图形的填充色。null = 跟随描边色(新画的就是「同色实心」,
|
// v1.10:矢量图形的填充色。null = 跟随描边色(新画的就是「同色实心」,
|
||||||
// 换主色时整体跟着变),一旦单独选过填充色就固定下来(每形状自己存 fillColor)。
|
// 换主色时整体跟着变),一旦单独选过填充色就固定下来(每形状自己存 fillColor)。
|
||||||
|
|||||||
@@ -201,9 +201,18 @@ import { rememberColor } from './recent-colors.js'
|
|||||||
ctx.lineWidth = s.lw
|
ctx.lineWidth = s.lw
|
||||||
ctx.lineCap = 'round'
|
ctx.lineCap = 'round'
|
||||||
ctx.lineJoin = 'round'
|
ctx.lineJoin = 'round'
|
||||||
|
// v1.17:无描边(strokeOn === false)。老对象没有这个字段,一律当有描边。
|
||||||
|
// 注意不能靠 lineWidth = 0 实现:canvas 会忽略 0 从而保持上一次的值。
|
||||||
|
const strokeOn = s.strokeOn !== false
|
||||||
if (s.type === 'pen') {
|
if (s.type === 'pen') {
|
||||||
const pts = Array.isArray(s.pts) ? s.pts : []
|
const pts = Array.isArray(s.pts) ? s.pts : []
|
||||||
if (pts.length > 1) { ctx.beginPath(); ctx.moveTo(pts[0].x, pts[0].y); for (let i = 1; i < pts.length; i++) ctx.lineTo(pts[i].x, pts[i].y); if (s.closed) ctx.closePath(); if (s.closed && s.fill) { ctx.fillStyle = fillOf(s); ctx.fill() } ctx.stroke() }
|
if (pts.length > 1) {
|
||||||
|
ctx.beginPath(); ctx.moveTo(pts[0].x, pts[0].y)
|
||||||
|
for (let i = 1; i < pts.length; i++) ctx.lineTo(pts[i].x, pts[i].y)
|
||||||
|
if (s.closed) ctx.closePath()
|
||||||
|
if (s.closed && s.fill) { ctx.fillStyle = fillOf(s); ctx.fill() }
|
||||||
|
if (strokeOn) ctx.stroke()
|
||||||
|
}
|
||||||
} else if (s.type === 'rect') {
|
} else if (s.type === 'rect') {
|
||||||
const rx = Math.min(s.x1, s.x2), ry = Math.min(s.y1, s.y2), rw = Math.abs(s.x2 - s.x1), rh = Math.abs(s.y2 - s.y1)
|
const rx = Math.min(s.x1, s.x2), ry = Math.min(s.y1, s.y2), rw = Math.abs(s.x2 - s.x1), rh = Math.abs(s.y2 - s.y1)
|
||||||
const radius = roundedRadius(s, rw, rh)
|
const radius = roundedRadius(s, rw, rh)
|
||||||
@@ -211,10 +220,10 @@ import { rememberColor } from './recent-colors.js'
|
|||||||
ctx.beginPath()
|
ctx.beginPath()
|
||||||
roundRectPath(ctx, rx, ry, rw, rh, radius)
|
roundRectPath(ctx, rx, ry, rw, rh, radius)
|
||||||
if (s.fill) { ctx.fillStyle = fillOf(s); ctx.fill() }
|
if (s.fill) { ctx.fillStyle = fillOf(s); ctx.fill() }
|
||||||
ctx.stroke()
|
if (strokeOn) ctx.stroke()
|
||||||
} else {
|
} else {
|
||||||
if (s.fill) { ctx.fillStyle = fillOf(s); ctx.fillRect(rx, ry, rw, rh) }
|
if (s.fill) { ctx.fillStyle = fillOf(s); ctx.fillRect(rx, ry, rw, rh) }
|
||||||
ctx.strokeRect(rx, ry, rw, rh)
|
if (strokeOn) ctx.strokeRect(rx, ry, rw, rh)
|
||||||
}
|
}
|
||||||
} else if (s.type === 'circle') {
|
} else if (s.type === 'circle') {
|
||||||
const rx = Math.min(s.x1, s.x2), ry = Math.min(s.y1, s.y2)
|
const rx = Math.min(s.x1, s.x2), ry = Math.min(s.y1, s.y2)
|
||||||
@@ -222,8 +231,9 @@ import { rememberColor } from './recent-colors.js'
|
|||||||
ctx.beginPath()
|
ctx.beginPath()
|
||||||
ctx.ellipse(rx + rw / 2, ry + rh / 2, Math.max(1, rw / 2), Math.max(1, rh / 2), 0, 0, Math.PI * 2)
|
ctx.ellipse(rx + rw / 2, ry + rh / 2, Math.max(1, rw / 2), Math.max(1, rh / 2), 0, 0, Math.PI * 2)
|
||||||
if (s.fill) { ctx.fillStyle = fillOf(s); ctx.fill() }
|
if (s.fill) { ctx.fillStyle = fillOf(s); ctx.fill() }
|
||||||
ctx.stroke()
|
if (strokeOn) ctx.stroke()
|
||||||
} else {
|
} else if (strokeOn) {
|
||||||
|
// 箭头:没有可填内部,去掉描边等于不画(UI 也不提供这个入口)
|
||||||
ctx.fillStyle = strokeOf(s)
|
ctx.fillStyle = strokeOf(s)
|
||||||
ctx.beginPath()
|
ctx.beginPath()
|
||||||
ctx.moveTo(s.x1, s.y1)
|
ctx.moveTo(s.x1, s.y1)
|
||||||
@@ -424,9 +434,13 @@ import { rememberColor } from './recent-colors.js'
|
|||||||
renderObjects()
|
renderObjects()
|
||||||
}
|
}
|
||||||
const sh = getSelectedShape()
|
const sh = getSelectedShape()
|
||||||
if (sh && !sh.locked && S.tool !== 'text' && sh.color !== S.color) {
|
if (sh && !sh.locked && S.tool !== 'text' && (sh.color !== S.color || sh.strokeOn === false)) {
|
||||||
|
// v1.17:给「无描边」的形状选颜色 = 想再看见描边,顺手打开。
|
||||||
|
// 与改色共用同一张快照,撤销一步就能回到「无描边 + 旧色」。
|
||||||
|
const revive = sh.strokeOn === false
|
||||||
if (!skipHistory) saveSnapshot()
|
if (!skipHistory) saveSnapshot()
|
||||||
sh.color = S.color
|
sh.color = S.color
|
||||||
|
if (revive) { sh.strokeOn = true; S.shapeStrokeOn = true }
|
||||||
renderObjects()
|
renderObjects()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+91
-22
@@ -9,7 +9,7 @@
|
|||||||
var __IWB_ANNOTATE_MANIFEST__ = {
|
var __IWB_ANNOTATE_MANIFEST__ = {
|
||||||
id: 'image-annotate',
|
id: 'image-annotate',
|
||||||
name: '标注 / 修图',
|
name: '标注 / 修图',
|
||||||
version: '1.16.0',
|
version: '1.17.0',
|
||||||
apiVersion: 1,
|
apiVersion: 1,
|
||||||
capabilities: ['commands', 'nodeActions', 'canvas', 'canvasWrite'],
|
capabilities: ['commands', 'nodeActions', 'canvas', 'canvasWrite'],
|
||||||
settings: {
|
settings: {
|
||||||
@@ -222,6 +222,9 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
// 否则「调细画笔」会顺手把所有形状的描边一起改掉。
|
// 否则「调细画笔」会顺手把所有形状的描边一起改掉。
|
||||||
shapeLineWidth: 3,
|
shapeLineWidth: 3,
|
||||||
// 矩形/圆形/箭头/钢笔的描边粗细
|
// 矩形/圆形/箭头/钢笔的描边粗细
|
||||||
|
// v1.17:默认是否画描边。关掉后形状只剩填充(「无描边」),
|
||||||
|
// 对象上另存 strokeOn,老对象没有这个字段一律视为有描边。
|
||||||
|
shapeStrokeOn: true,
|
||||||
shapeRadius: 0,
|
shapeRadius: 0,
|
||||||
// 矩形圆角半径 px(v1.9,仅 rect 有意义)
|
// 矩形圆角半径 px(v1.9,仅 rect 有意义)
|
||||||
// v1.10:矢量图形的填充色。null = 跟随描边色(新画的就是「同色实心」,
|
// v1.10:矢量图形的填充色。null = 跟随描边色(新画的就是「同色实心」,
|
||||||
@@ -868,6 +871,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
ctx.lineWidth = s.lw;
|
ctx.lineWidth = s.lw;
|
||||||
ctx.lineCap = "round";
|
ctx.lineCap = "round";
|
||||||
ctx.lineJoin = "round";
|
ctx.lineJoin = "round";
|
||||||
|
const strokeOn = s.strokeOn !== false;
|
||||||
if (s.type === "pen") {
|
if (s.type === "pen") {
|
||||||
const pts = Array.isArray(s.pts) ? s.pts : [];
|
const pts = Array.isArray(s.pts) ? s.pts : [];
|
||||||
if (pts.length > 1) {
|
if (pts.length > 1) {
|
||||||
@@ -879,7 +883,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
ctx.fillStyle = fillOf(s);
|
ctx.fillStyle = fillOf(s);
|
||||||
ctx.fill();
|
ctx.fill();
|
||||||
}
|
}
|
||||||
ctx.stroke();
|
if (strokeOn) ctx.stroke();
|
||||||
}
|
}
|
||||||
} else if (s.type === "rect") {
|
} else if (s.type === "rect") {
|
||||||
const rx = Math.min(s.x1, s.x2), ry = Math.min(s.y1, s.y2), rw = Math.abs(s.x2 - s.x1), rh = Math.abs(s.y2 - s.y1);
|
const rx = Math.min(s.x1, s.x2), ry = Math.min(s.y1, s.y2), rw = Math.abs(s.x2 - s.x1), rh = Math.abs(s.y2 - s.y1);
|
||||||
@@ -891,13 +895,13 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
ctx.fillStyle = fillOf(s);
|
ctx.fillStyle = fillOf(s);
|
||||||
ctx.fill();
|
ctx.fill();
|
||||||
}
|
}
|
||||||
ctx.stroke();
|
if (strokeOn) ctx.stroke();
|
||||||
} else {
|
} else {
|
||||||
if (s.fill) {
|
if (s.fill) {
|
||||||
ctx.fillStyle = fillOf(s);
|
ctx.fillStyle = fillOf(s);
|
||||||
ctx.fillRect(rx, ry, rw, rh);
|
ctx.fillRect(rx, ry, rw, rh);
|
||||||
}
|
}
|
||||||
ctx.strokeRect(rx, ry, rw, rh);
|
if (strokeOn) ctx.strokeRect(rx, ry, rw, rh);
|
||||||
}
|
}
|
||||||
} else if (s.type === "circle") {
|
} else if (s.type === "circle") {
|
||||||
const rx = Math.min(s.x1, s.x2), ry = Math.min(s.y1, s.y2);
|
const rx = Math.min(s.x1, s.x2), ry = Math.min(s.y1, s.y2);
|
||||||
@@ -908,8 +912,8 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
ctx.fillStyle = fillOf(s);
|
ctx.fillStyle = fillOf(s);
|
||||||
ctx.fill();
|
ctx.fill();
|
||||||
}
|
}
|
||||||
ctx.stroke();
|
if (strokeOn) ctx.stroke();
|
||||||
} else {
|
} else if (strokeOn) {
|
||||||
ctx.fillStyle = strokeOf(s);
|
ctx.fillStyle = strokeOf(s);
|
||||||
ctx.beginPath();
|
ctx.beginPath();
|
||||||
ctx.moveTo(s.x1, s.y1);
|
ctx.moveTo(s.x1, s.y1);
|
||||||
@@ -1068,9 +1072,14 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
renderObjects();
|
renderObjects();
|
||||||
}
|
}
|
||||||
const sh = getSelectedShape();
|
const sh = getSelectedShape();
|
||||||
if (sh && !sh.locked && S.tool !== "text" && sh.color !== S.color) {
|
if (sh && !sh.locked && S.tool !== "text" && (sh.color !== S.color || sh.strokeOn === false)) {
|
||||||
|
const revive = sh.strokeOn === false;
|
||||||
if (!skipHistory) saveSnapshot();
|
if (!skipHistory) saveSnapshot();
|
||||||
sh.color = S.color;
|
sh.color = S.color;
|
||||||
|
if (revive) {
|
||||||
|
sh.strokeOn = true;
|
||||||
|
S.shapeStrokeOn = true;
|
||||||
|
}
|
||||||
renderObjects();
|
renderObjects();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4997,6 +5006,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
lw: Math.max(1, S.shapeLineWidth),
|
lw: Math.max(1, S.shapeLineWidth),
|
||||||
lineWidth: Math.max(1, S.shapeLineWidth),
|
lineWidth: Math.max(1, S.shapeLineWidth),
|
||||||
fill: S.tool === "rect" || S.tool === "circle" ? !!S.rectFill : false,
|
fill: S.tool === "rect" || S.tool === "circle" ? !!S.rectFill : false,
|
||||||
|
strokeOn: S.shapeStrokeOn !== false,
|
||||||
radius: S.tool === "rect" ? Math.max(0, S.shapeRadius) : 0,
|
radius: S.tool === "rect" ? Math.max(0, S.shapeRadius) : 0,
|
||||||
opacity: 1,
|
opacity: 1,
|
||||||
visible: true
|
visible: true
|
||||||
@@ -5188,6 +5198,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
// null = 跟随描边色(改主色时整块跟着变)
|
// null = 跟随描边色(改主色时整块跟着变)
|
||||||
lw: Math.max(1, S.shapeLineWidth),
|
lw: Math.max(1, S.shapeLineWidth),
|
||||||
fill: S.tool === "rect" || S.tool === "circle" ? !!S.rectFill : false,
|
fill: S.tool === "rect" || S.tool === "circle" ? !!S.rectFill : false,
|
||||||
|
strokeOn: S.shapeStrokeOn !== false,
|
||||||
radius: S.tool === "rect" ? Math.max(0, S.shapeRadius) : 0,
|
radius: S.tool === "rect" ? Math.max(0, S.shapeRadius) : 0,
|
||||||
opacity: 1,
|
opacity: 1,
|
||||||
visible: true,
|
visible: true,
|
||||||
@@ -5305,6 +5316,10 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
if (!sh) return true;
|
if (!sh) return true;
|
||||||
return sh.type === "rect" || sh.type === "circle" || sh.type === "pen" && !!sh.closed;
|
return sh.type === "rect" || sh.type === "circle" || sh.type === "pen" && !!sh.closed;
|
||||||
}
|
}
|
||||||
|
function strokeSlotCanBeNone() {
|
||||||
|
const ctx = colorContext();
|
||||||
|
return ctx.kind === "shape" && fillSlotOn();
|
||||||
|
}
|
||||||
function textColorSlots(t) {
|
function textColorSlots(t) {
|
||||||
const color = (t ? t.color : S.color) || S.color;
|
const color = (t ? t.color : S.color) || S.color;
|
||||||
const strokeColor = (t ? t.strokeColor : S.textStrokeColor) || TEXT_DEFAULTS.strokeColor;
|
const strokeColor = (t ? t.strokeColor : S.textStrokeColor) || TEXT_DEFAULTS.strokeColor;
|
||||||
@@ -5333,9 +5348,11 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
const stroke = sh && sh.color || S.color;
|
const stroke = sh && sh.color || S.color;
|
||||||
const rawFill = sh ? sh.fillColor || null : S.shapeFillColor;
|
const rawFill = sh ? sh.fillColor || null : S.shapeFillColor;
|
||||||
const fillOn = sh ? sh.type === "pen" ? !!sh.fill && !!sh.closed : !!sh.fill : S.tool === "pen" ? !!S.penFill : !!S.rectFill;
|
const fillOn = sh ? sh.type === "pen" ? !!sh.fill && !!sh.closed : !!sh.fill : S.tool === "pen" ? !!S.penFill : !!S.rectFill;
|
||||||
|
const strokeOn = ctx.kind !== "shape" ? true : sh ? sh.strokeOn !== false : S.shapeStrokeOn !== false;
|
||||||
return {
|
return {
|
||||||
mode: ctx.kind === "shape" ? "shape" : "single",
|
mode: ctx.kind === "shape" ? "shape" : "single",
|
||||||
stroke,
|
stroke,
|
||||||
|
strokeOn,
|
||||||
fill: rawFill || stroke,
|
fill: rawFill || stroke,
|
||||||
fillOn,
|
fillOn,
|
||||||
follow: !rawFill,
|
follow: !rawFill,
|
||||||
@@ -5369,7 +5386,8 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
const dot = strokeBtn.querySelector("i");
|
const dot = strokeBtn.querySelector("i");
|
||||||
if (dot) dot.style.backgroundColor = sl.stroke;
|
if (dot) dot.style.backgroundColor = sl.stroke;
|
||||||
strokeBtn.classList.toggle("active", S.colorTarget === "stroke");
|
strokeBtn.classList.toggle("active", S.colorTarget === "stroke");
|
||||||
strokeBtn.title = isText ? `文字色 ${String(sl.stroke).toUpperCase()}:改文字本身的颜色(右边「描边」是字的外描边)` : second ? `描边色 ${String(sl.stroke).toUpperCase()}:形状描边也用这个值。点开色板调色` : `${strokeName}色 ${String(sl.stroke).toUpperCase()}:点开色板调色`;
|
strokeBtn.classList.toggle("is-none", !isText && sl.strokeOn === false);
|
||||||
|
strokeBtn.title = isText ? `文字色 ${String(sl.stroke).toUpperCase()}:改文字本身的颜色(右边「描边」是字的外描边)` : sl.strokeOn === false ? "描边:无(只有填充)。点开选色会自动恢复描边" : second ? `描边色 ${String(sl.stroke).toUpperCase()}:形状描边也用这个值。点开色板调色,「无」= 去掉描边` : `${strokeName}色 ${String(sl.stroke).toUpperCase()}:点开色板调色`;
|
||||||
const popEl = runtime.el.querySelector(".iwb-editor-color-pop");
|
const popEl = runtime.el.querySelector(".iwb-editor-color-pop");
|
||||||
strokeBtn.setAttribute("aria-expanded", String(!!(popEl && !popEl.hidden && S.colorTarget === "stroke")));
|
strokeBtn.setAttribute("aria-expanded", String(!!(popEl && !popEl.hidden && S.colorTarget === "stroke")));
|
||||||
}
|
}
|
||||||
@@ -5414,14 +5432,16 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
tab.classList.toggle("is-none", !sl.bgOn);
|
tab.classList.toggle("is-none", !sl.bgOn);
|
||||||
tab.hidden = !isText;
|
tab.hidden = !isText;
|
||||||
}
|
}
|
||||||
|
if (!isFill && !isBg) tab.classList.toggle("is-none", !isText && sl.strokeOn === false);
|
||||||
});
|
});
|
||||||
const onBg = S.colorTarget === "bg" && isText;
|
const onBg = S.colorTarget === "bg" && isText;
|
||||||
const onFill = S.colorTarget === "fill" && second;
|
const onFill = S.colorTarget === "fill" && second;
|
||||||
const showNone = onBg || onFill;
|
const onStroke = S.colorTarget === "stroke" && !isText && strokeSlotCanBeNone();
|
||||||
|
const showNone = onBg || onFill || onStroke;
|
||||||
runtime.el.querySelectorAll("[data-color-none]").forEach((noneBtn) => {
|
runtime.el.querySelectorAll("[data-color-none]").forEach((noneBtn) => {
|
||||||
noneBtn.hidden = !showNone;
|
noneBtn.hidden = !showNone;
|
||||||
noneBtn.classList.toggle("active", showNone && (onBg ? !sl.bgOn : !sl.fillOn));
|
noneBtn.classList.toggle("active", showNone && (onBg ? !sl.bgOn : onFill ? !sl.fillOn : !sl.strokeOn));
|
||||||
noneBtn.title = onBg ? "无底色:文字后面完全透明" : isText ? "无描边:把描边宽度置 0,只留文字本身" : "无填充:形状内部透明,只留描边";
|
noneBtn.title = onBg ? "无底色:文字后面完全透明" : onStroke ? sl.strokeOn === false ? "当前已是无描边;点选颜色可恢复描边" : "无描边:去掉形状外框,只留内部填充" : isText ? "无描边:把描边宽度置 0,只留文字本身" : "无填充:形状内部透明,只留描边";
|
||||||
});
|
});
|
||||||
const cur = activeColor();
|
const cur = activeColor();
|
||||||
let matchPreset = false;
|
let matchPreset = false;
|
||||||
@@ -5531,7 +5551,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
}
|
}
|
||||||
function shapeColorHTML(sh, owner) {
|
function shapeColorHTML(sh, owner) {
|
||||||
const sl = colorSlots();
|
const sl = colorSlots();
|
||||||
let html = `<span class="iwb-opt-label">描边</span><input type="color" class="iwb-opt-color" data-shape-color="stroke" value="${sl.stroke}" title="描边色:与工具栏左上的描边色块是同一份,改哪边都一样">`;
|
let html = `<span class="iwb-opt-label">描边</span><input type="color" class="iwb-opt-color${sl.strokeOn === false ? " is-off" : ""}" data-shape-color="stroke" value="${sl.stroke}" title="描边色:与工具栏左上的描边色块是同一份,改哪边都一样${sl.strokeOn === false ? ";当前无描边,选色会自动恢复" : ""}">`;
|
||||||
if (owner) {
|
if (owner) {
|
||||||
html += `<span class="iwb-opt-label">填充</span><input type="color" class="iwb-opt-color${sl.fillOn ? "" : " is-off"}" data-shape-color="fill" data-fill-owner="${owner}" value="${sl.fill}" title="填充色:与工具栏右下的填充色块是同一份${sl.fillOn ? "" : ";当前无填充,选色会自动切成实心"}">`;
|
html += `<span class="iwb-opt-label">填充</span><input type="color" class="iwb-opt-color${sl.fillOn ? "" : " is-off"}" data-shape-color="fill" data-fill-owner="${owner}" value="${sl.fill}" title="填充色:与工具栏右下的填充色块是同一份${sl.fillOn ? "" : ";当前无填充,选色会自动切成实心"}">`;
|
||||||
}
|
}
|
||||||
@@ -5730,7 +5750,9 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
inp.classList.toggle("is-off", !sl.fillOn);
|
inp.classList.toggle("is-off", !sl.fillOn);
|
||||||
inp.title = sl.fillOn ? "填充色:与工具栏右下的填充色块是同一份" : "当前无填充(形状内部透明)。选色会自动切成实心,也可点工具栏填充色块选「无」";
|
inp.title = sl.fillOn ? "填充色:与工具栏右下的填充色块是同一份" : "当前无填充(形状内部透明)。选色会自动切成实心,也可点工具栏填充色块选「无」";
|
||||||
} else {
|
} else {
|
||||||
inp.title = "描边色:与工具栏左上的描边色块是同一份";
|
const off = sl.strokeOn === false;
|
||||||
|
inp.classList.toggle("is-off", off);
|
||||||
|
inp.title = off ? "当前无描边(只有填充)。选色会自动恢复描边,也可点工具栏描边色块选「无」" : "描边色:与工具栏左上的描边色块是同一份";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
updateColorUI();
|
updateColorUI();
|
||||||
@@ -5866,8 +5888,31 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
syncOptionBar();
|
syncOptionBar();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (S.colorTarget === "stroke") {
|
||||||
|
applyStrokeNone();
|
||||||
|
return;
|
||||||
|
}
|
||||||
applyShapeColor("none");
|
applyShapeColor("none");
|
||||||
}
|
}
|
||||||
|
function applyStrokeNone() {
|
||||||
|
if (!strokeSlotCanBeNone()) return;
|
||||||
|
S.colorTarget = "stroke";
|
||||||
|
S.shapeStrokeOn = false;
|
||||||
|
const sh = getSelectedShape();
|
||||||
|
if (sh && !sh.locked && sh.strokeOn !== false) {
|
||||||
|
saveSnapshot("无描边");
|
||||||
|
sh.strokeOn = false;
|
||||||
|
if (!sh.fill && (sh.type === "rect" || sh.type === "circle" || sh.type === "pen" && sh.closed)) {
|
||||||
|
sh.fill = true;
|
||||||
|
if (sh.type === "pen") S.penFill = true;
|
||||||
|
else S.rectFill = true;
|
||||||
|
}
|
||||||
|
renderObjects();
|
||||||
|
}
|
||||||
|
updateFillUI();
|
||||||
|
updateColorUI();
|
||||||
|
syncOptionBar();
|
||||||
|
}
|
||||||
function applyShapeColor(kind, raw, opts) {
|
function applyShapeColor(kind, raw, opts) {
|
||||||
const skipHistory = !!(opts && opts.skipHistory);
|
const skipHistory = !!(opts && opts.skipHistory);
|
||||||
const sh = getSelectedShape();
|
const sh = getSelectedShape();
|
||||||
@@ -5890,6 +5935,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
if (!/^#[0-9a-f]{6}$/.test(hex)) return;
|
if (!/^#[0-9a-f]{6}$/.test(hex)) return;
|
||||||
if (kind === "stroke") {
|
if (kind === "stroke") {
|
||||||
S.colorTarget = "stroke";
|
S.colorTarget = "stroke";
|
||||||
|
S.shapeStrokeOn = true;
|
||||||
applyColorChange(hex, opts);
|
applyColorChange(hex, opts);
|
||||||
if (skipHistory) syncOptionBarSoon();
|
if (skipHistory) syncOptionBarSoon();
|
||||||
else syncOptionBar();
|
else syncOptionBar();
|
||||||
@@ -5963,6 +6009,10 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
if (sh && types.indexOf(sh.type) >= 0 && !sh.locked) {
|
if (sh && types.indexOf(sh.type) >= 0 && !sh.locked) {
|
||||||
saveSnapshot("填充");
|
saveSnapshot("填充");
|
||||||
sh.fill = isPen ? !!S.penFill && !!sh.closed : !!S.rectFill;
|
sh.fill = isPen ? !!S.penFill && !!sh.closed : !!S.rectFill;
|
||||||
|
if (!sh.fill && sh.strokeOn === false) {
|
||||||
|
sh.strokeOn = true;
|
||||||
|
S.shapeStrokeOn = true;
|
||||||
|
}
|
||||||
renderObjects();
|
renderObjects();
|
||||||
syncOptionBar();
|
syncOptionBar();
|
||||||
}
|
}
|
||||||
@@ -5974,18 +6024,37 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
toast("箭头只有描边色,没有可交换的填充色", "info");
|
toast("箭头只有描边色,没有可交换的填充色", "info");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
const stroke = sh.color || S.color;
|
const canFill = sh.type === "rect" || sh.type === "circle" || sh.type === "pen" && !!sh.closed;
|
||||||
const fill = sh.fillColor || null;
|
const strokeOn = sh.strokeOn !== false;
|
||||||
if (!fill) {
|
const fillOn = !!sh.fill;
|
||||||
|
const strokeColor = sh.color || S.color;
|
||||||
|
const fillColor = sh.fillColor || null;
|
||||||
|
if (!canFill && !fillOn) {
|
||||||
|
toast("这条路径没有可填内部,交换后什么都看不见", "info");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!strokeOn && !fillOn) {
|
||||||
|
toast("描边与填充都是无色,没有可交换的颜色", "info");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (strokeOn && fillOn && !fillColor) {
|
||||||
toast("填充色正跟随描边色(两者同一个颜色),无需交换", "info");
|
toast("填充色正跟随描边色(两者同一个颜色),无需交换", "info");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
saveSnapshot("交换填充与描边色");
|
saveSnapshot("交换填充与描边色");
|
||||||
sh.color = fill;
|
sh.strokeOn = fillOn;
|
||||||
S.color = fill;
|
sh.fill = strokeOn && canFill;
|
||||||
sh.fillColor = stroke;
|
S.shapeStrokeOn = fillOn;
|
||||||
S.shapeFillColor = stroke;
|
if (sh.type === "pen") S.penFill = !!(sh.fill && sh.closed);
|
||||||
|
else if (sh.type === "rect" || sh.type === "circle") S.rectFill = !!sh.fill;
|
||||||
|
if (fillColor) {
|
||||||
|
sh.color = fillColor;
|
||||||
|
S.color = fillColor;
|
||||||
|
sh.fillColor = strokeColor;
|
||||||
|
S.shapeFillColor = strokeColor;
|
||||||
|
}
|
||||||
renderObjects();
|
renderObjects();
|
||||||
|
updateFillUI();
|
||||||
updateColorUI();
|
updateColorUI();
|
||||||
syncOptionBar();
|
syncOptionBar();
|
||||||
return true;
|
return true;
|
||||||
@@ -6731,7 +6800,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
saveSnapshot();
|
saveSnapshot();
|
||||||
const shape = { id: "s" + Date.now() + Math.floor(Math.random() * 1e3), type: "pen", pts: S.penPath.pts.slice(), closed: !!S.penPath.closed, color: S.color, fillColor: S.shapeFillColor, lw: Math.max(1, S.shapeLineWidth), fill: !!S.penFill && !!S.penPath.closed, opacity: 1, visible: true, locked: false, z: ++S.zCounter };
|
const shape = { id: "s" + Date.now() + Math.floor(Math.random() * 1e3), type: "pen", pts: S.penPath.pts.slice(), closed: !!S.penPath.closed, color: S.color, fillColor: S.shapeFillColor, lw: Math.max(1, S.shapeLineWidth), fill: !!S.penFill && !!S.penPath.closed, strokeOn: S.shapeStrokeOn !== false, opacity: 1, visible: true, locked: false, z: ++S.zCounter };
|
||||||
S.shapeLayers.push(shape);
|
S.shapeLayers.push(shape);
|
||||||
S.penPath = null;
|
S.penPath = null;
|
||||||
renderObjects();
|
renderObjects();
|
||||||
@@ -8703,7 +8772,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
opacity: l.opacity == null ? 1 : l.opacity,
|
opacity: l.opacity == null ? 1 : l.opacity,
|
||||||
cssOpacity: l.canvas ? parseFloat(l.canvas.style.opacity || "1") : null
|
cssOpacity: l.canvas ? parseFloat(l.canvas.style.opacity || "1") : null
|
||||||
})),
|
})),
|
||||||
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) })),
|
shapes: S.shapeLayers.map((s) => ({ id: s.id, type: s.type, lw: s.lw, fill: !!s.fill, closed: !!s.closed, strokeOn: s.strokeOn !== false, 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) => ({
|
texts: S.textLayers.map((t) => ({
|
||||||
id: t.id,
|
id: t.id,
|
||||||
text: t.text,
|
text: t.text,
|
||||||
|
|||||||
@@ -246,6 +246,36 @@ if (!SKIP_PASTE) {
|
|||||||
await page.locator('.iwb-editor-side-resizer').dblclick()
|
await page.locator('.iwb-editor-side-resizer').dblclick()
|
||||||
await page.waitForTimeout(150)
|
await page.waitForTimeout(150)
|
||||||
|
|
||||||
|
// v1.17:描边可以是「无色」。真站要验的是按钮真的出现在描边槽、点完对象上真的关了,
|
||||||
|
// 而不只是 CSS 里多了个类 —— 形状消失与否只有跑起来才知道。
|
||||||
|
await page.locator('.iwb-editor-tool[data-tool="rect"]').click()
|
||||||
|
await page.mouse.move(imgBox.x + imgBox.width * 0.12, imgBox.y + imgBox.height * 0.12)
|
||||||
|
await page.mouse.down()
|
||||||
|
await page.mouse.move(imgBox.x + imgBox.width * 0.30, imgBox.y + imgBox.height * 0.30, { steps: 6 })
|
||||||
|
await page.mouse.up()
|
||||||
|
await page.waitForTimeout(250)
|
||||||
|
await page.locator('.iwb-editor-tool[data-tool="select"]').click()
|
||||||
|
await page.mouse.click(imgBox.x + imgBox.width * 0.21, imgBox.y + imgBox.height * 0.21)
|
||||||
|
await page.waitForTimeout(200)
|
||||||
|
await page.locator('.iwb-editor-tools [data-action="toggleColorPop"][data-color-slot="stroke"]').click()
|
||||||
|
await page.waitForTimeout(250)
|
||||||
|
const noneOnStroke = await page.evaluate(() => {
|
||||||
|
const n = document.querySelector('.iwb-editor-color-pop [data-color-none]')
|
||||||
|
return Boolean(n) && !n.hidden
|
||||||
|
})
|
||||||
|
await page.evaluate(() => document.querySelector('.iwb-editor-color-pop [data-color-none]').click())
|
||||||
|
await page.waitForTimeout(300)
|
||||||
|
const noStrokeState = await page.evaluate(() => {
|
||||||
|
const d = window.__iwbEditor.__debug()
|
||||||
|
const s = d.shapes.find((x) => x.id === d.selectedShapeId)
|
||||||
|
return s ? { strokeOn: s.strokeOn, fill: s.fill } : null
|
||||||
|
})
|
||||||
|
check('真站:描边能置「无」(去掉描边顺手切实心,对象不会消失)',
|
||||||
|
noneOnStroke && Boolean(noStrokeState) && noStrokeState.strokeOn === false && noStrokeState.fill === true,
|
||||||
|
JSON.stringify({ noneOnStroke, noStrokeState }))
|
||||||
|
await page.keyboard.press('Escape')
|
||||||
|
await page.waitForTimeout(120)
|
||||||
|
|
||||||
// v1.14 字体选择:真站是带 CSP 的环境,这里确认下拉可用、字体切换真的落到了对象上。
|
// v1.14 字体选择:真站是带 CSP 的环境,这里确认下拉可用、字体切换真的落到了对象上。
|
||||||
// 系统字体不受 CSP 约束(CSP 管的是网络字体),所以只要 canvas 能画就没问题。
|
// 系统字体不受 CSP 约束(CSP 管的是网络字体),所以只要 canvas 能画就没问题。
|
||||||
const famDbg = () => page.evaluate(() => window.__iwbEditor.__debug())
|
const famDbg = () => page.evaluate(() => window.__iwbEditor.__debug())
|
||||||
|
|||||||
@@ -2532,6 +2532,159 @@ const shiftXSwap = await (async () => {
|
|||||||
})()
|
})()
|
||||||
check('Shift+X 交换填充色与描边色(填充不会被关掉、再按回到原样)', shiftXSwap.ok, shiftXSwap.detail)
|
check('Shift+X 交换填充色与描边色(填充不会被关掉、再按回到原样)', shiftXSwap.ok, shiftXSwap.detail)
|
||||||
|
|
||||||
|
// ================================================================
|
||||||
|
// v1.17:描边也能是「无色」;只要有一边无色,Shift+X 照样能交换
|
||||||
|
// ================================================================
|
||||||
|
// 用户原话:「让矢量图形与钢笔的描边色也可以去掉」
|
||||||
|
// 「让描边与填充,有一个是无色的时候,可以交换,现在是不可以的」
|
||||||
|
const setOptColor = (slot, hex) => page.evaluate(({ slot, hex }) => {
|
||||||
|
const el = document.querySelector(`.iwb-editor-optionbar-body [data-shape-color="${slot}"]`)
|
||||||
|
el.value = hex
|
||||||
|
el.dispatchEvent(new Event('change', { bubbles: true }))
|
||||||
|
}, { slot, hex })
|
||||||
|
|
||||||
|
async function drawRectAt(x1, y1, x2, y2) {
|
||||||
|
await page.locator('.iwb-editor-tool[data-tool="rect"]').click()
|
||||||
|
const a = { x: imgBox.x + imgBox.width * x1, y: imgBox.y + imgBox.height * y1 }
|
||||||
|
const b = { x: imgBox.x + imgBox.width * x2, y: imgBox.y + imgBox.height * y2 }
|
||||||
|
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(160)
|
||||||
|
return { a, b }
|
||||||
|
}
|
||||||
|
|
||||||
|
// 取选中形状 + 三处 UI 的「无」状态,后面几条都用它
|
||||||
|
const selectedShapeState = () => page.evaluate(() => {
|
||||||
|
const d = window.__iwbEditor.__debug()
|
||||||
|
const s = d.shapes.find(x => x.id === d.selectedShapeId)
|
||||||
|
const btn = document.querySelector('.iwb-editor-color-pair [data-color-slot="stroke"]')
|
||||||
|
const opt = document.querySelector('.iwb-editor-optionbar-body [data-shape-color="stroke"]')
|
||||||
|
const none = document.querySelector('.iwb-editor-color-pop [data-color-none]')
|
||||||
|
return {
|
||||||
|
type: s && s.type, closed: s && s.closed,
|
||||||
|
strokeOn: s && s.strokeOn, fill: s && s.fill,
|
||||||
|
color: s && s.color, fillColor: s && s.fillColor,
|
||||||
|
strokeBtnNone: !!btn && btn.classList.contains('is-none'),
|
||||||
|
optOff: !!opt && opt.classList.contains('is-off'),
|
||||||
|
noneHidden: !none || none.hidden,
|
||||||
|
noneActive: !!none && none.classList.contains('active')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// ---- 形状:去掉描边 ----
|
||||||
|
// 描边给一个画布上没出现过的洋红,靠像素数证明「框真的没了」而不是只改了数据
|
||||||
|
await drawRectAt(0.55, 0.52, 0.82, 0.74)
|
||||||
|
await setOptColor('fill', '#0aa6c8')
|
||||||
|
await page.waitForTimeout(160)
|
||||||
|
await setOptColor('stroke', '#ff00aa')
|
||||||
|
await page.waitForTimeout(220)
|
||||||
|
// 按画布分别数:画布上还躺着别的早期用例留下的同色对象(文字就用了 #ff00aa),
|
||||||
|
// 全局求和会把它们算进来 —— 只认「某一个画布从有变没有」才说得清这条描边真的没了
|
||||||
|
const magentaPerCanvas = () => page.evaluate(() => [...document.querySelectorAll('.iwb-editor-vec-canvas')].map(cv => {
|
||||||
|
const d = cv.getContext('2d').getImageData(0, 0, cv.width, cv.height).data
|
||||||
|
let n = 0
|
||||||
|
for (let i = 0; i < d.length; i += 4) {
|
||||||
|
if (d[i + 3] > 200 && Math.abs(d[i] - 255) < 8 && d[i + 1] < 8 && Math.abs(d[i + 2] - 170) < 8) n++
|
||||||
|
}
|
||||||
|
return n
|
||||||
|
}))
|
||||||
|
const magentaBefore = await magentaPerCanvas()
|
||||||
|
await page.locator('.iwb-editor-color-btn[data-color-slot="stroke"]').click()
|
||||||
|
await page.waitForTimeout(220)
|
||||||
|
const noneShownOnStroke = await page.evaluate(() =>
|
||||||
|
!document.querySelector('.iwb-editor-color-pop [data-color-none]').hidden)
|
||||||
|
await page.evaluate(() => document.querySelector('.iwb-editor-color-pop [data-color-none]').click())
|
||||||
|
await page.waitForTimeout(320)
|
||||||
|
const noStroke = await selectedShapeState()
|
||||||
|
const magentaAfter = await magentaPerCanvas()
|
||||||
|
const cyanStill = await countColorInVec([10, 166, 200], 8)
|
||||||
|
const strokeGone = magentaBefore.some((n, i) => n > 300 && magentaAfter[i] === 0)
|
||||||
|
const noNewMagenta = magentaAfter.every((n, i) => n <= magentaBefore[i])
|
||||||
|
check('形状可以去掉描边:描边像素清零,填充色与描边色都留着',
|
||||||
|
noneShownOnStroke && strokeGone && noNewMagenta &&
|
||||||
|
noStroke.strokeOn === false && noStroke.fill === true &&
|
||||||
|
noStroke.color === '#ff00aa' && cyanStill > 300,
|
||||||
|
JSON.stringify({ noneShownOnStroke, magentaBefore, magentaAfter, cyanStill, ...noStroke }))
|
||||||
|
check('无描边时工具栏描边格画斜杠、选项栏描边色块置灰、色板「无」高亮',
|
||||||
|
noStroke.strokeBtnNone === true && noStroke.optOff === true && noStroke.noneActive === true,
|
||||||
|
JSON.stringify({ btn: noStroke.strokeBtnNone, opt: noStroke.optOff, none: noStroke.noneActive }))
|
||||||
|
|
||||||
|
// 选色即恢复描边:与「文字描边宽度 0 时选色自动给 6px」同一条逻辑,
|
||||||
|
// 否则用户选了颜色画面没变化,会以为颜色设置坏了
|
||||||
|
await page.evaluate(() => {
|
||||||
|
const el = document.querySelector('.iwb-editor-color-pop .iwb-editor-color-hex-input')
|
||||||
|
el.value = '#ff00aa'
|
||||||
|
el.dispatchEvent(new Event('change', { bubbles: true }))
|
||||||
|
})
|
||||||
|
await page.waitForTimeout(320)
|
||||||
|
const revivedStroke = await selectedShapeState()
|
||||||
|
const magentaRevived = await magentaPerCanvas()
|
||||||
|
const strokeBack = magentaRevived.some((n, i) => n > 300 && magentaAfter[i] === 0)
|
||||||
|
check('无描边时再选一次颜色 → 自动恢复描边(选了色一定有变化)',
|
||||||
|
revivedStroke.strokeOn === true && revivedStroke.color === '#ff00aa' && strokeBack,
|
||||||
|
JSON.stringify({ ...revivedStroke, strokeBack, magentaAfter, magentaRevived }))
|
||||||
|
|
||||||
|
// ---- 钢笔闭合路径:同样能去掉描边 ----
|
||||||
|
await page.locator('.iwb-editor-tool[data-tool="pen"]').click()
|
||||||
|
const t1 = { x: imgBox.x + imgBox.width * 0.34, y: imgBox.y + imgBox.height * 0.16 }
|
||||||
|
const t2 = { x: imgBox.x + imgBox.width * 0.46, y: imgBox.y + imgBox.height * 0.16 }
|
||||||
|
const t3 = { x: imgBox.x + imgBox.width * 0.40, y: imgBox.y + imgBox.height * 0.34 }
|
||||||
|
await page.mouse.click(t1.x, t1.y); await page.waitForTimeout(90)
|
||||||
|
await page.mouse.click(t2.x, t2.y); await page.waitForTimeout(90)
|
||||||
|
await page.mouse.click(t3.x, t3.y); await page.waitForTimeout(90)
|
||||||
|
await page.mouse.click(t1.x, t1.y); await page.waitForTimeout(280) // 回到起点 = 闭合
|
||||||
|
await page.locator('.iwb-editor-color-btn[data-color-slot="stroke"]').click()
|
||||||
|
await page.waitForTimeout(220)
|
||||||
|
await page.evaluate(() => document.querySelector('.iwb-editor-color-pop [data-color-none]').click())
|
||||||
|
await page.waitForTimeout(320)
|
||||||
|
const penNoStroke = await selectedShapeState()
|
||||||
|
check('钢笔闭合路径也能去掉描边(去掉后只剩填充面,不会整个消失)',
|
||||||
|
penNoStroke.type === 'pen' && penNoStroke.closed === true &&
|
||||||
|
penNoStroke.strokeOn === false && penNoStroke.fill === true,
|
||||||
|
JSON.stringify(penNoStroke))
|
||||||
|
|
||||||
|
// 未闭合路径没有可填内部:去掉描边 = 这条线没了,索性不给「无」
|
||||||
|
await page.locator('.iwb-editor-tool[data-tool="pen"]').click()
|
||||||
|
await page.mouse.click(imgBox.x + imgBox.width * 0.62, imgBox.y + imgBox.height * 0.36)
|
||||||
|
await page.waitForTimeout(90)
|
||||||
|
await page.mouse.click(imgBox.x + imgBox.width * 0.76, imgBox.y + imgBox.height * 0.42)
|
||||||
|
await page.waitForTimeout(90)
|
||||||
|
await page.keyboard.press('Enter') // 回车结束开放路径
|
||||||
|
await page.waitForTimeout(280)
|
||||||
|
await page.locator('.iwb-editor-color-btn[data-color-slot="stroke"]').click()
|
||||||
|
await page.waitForTimeout(220)
|
||||||
|
const openPen = await selectedShapeState()
|
||||||
|
check('未闭合钢笔不给「无描边」(去掉等于把这条线删了)',
|
||||||
|
openPen.type === 'pen' && openPen.closed === false && openPen.noneHidden === true,
|
||||||
|
JSON.stringify(openPen))
|
||||||
|
|
||||||
|
// ---- 一边无色也能交换(用户反馈的第二个问题)----
|
||||||
|
await page.keyboard.press('Escape')
|
||||||
|
await drawRectAt(0.08, 0.10, 0.30, 0.30)
|
||||||
|
// 先做成「只有描边」:fill 关掉,描边给独立色
|
||||||
|
await page.evaluate(() => {
|
||||||
|
const btn = document.querySelector('.iwb-editor-optionbar-body [data-opt-toggle="stroke"]')
|
||||||
|
if (btn) btn.click()
|
||||||
|
})
|
||||||
|
await page.waitForTimeout(200)
|
||||||
|
await setOptColor('stroke', '#ff00aa')
|
||||||
|
await page.waitForTimeout(220)
|
||||||
|
const onlyStroke = await selectedShapeState()
|
||||||
|
await page.keyboard.press('Shift+x')
|
||||||
|
await page.waitForTimeout(260)
|
||||||
|
const afterSwap1 = await selectedShapeState()
|
||||||
|
await page.keyboard.press('Shift+x')
|
||||||
|
await page.waitForTimeout(260)
|
||||||
|
const afterSwap2 = await selectedShapeState()
|
||||||
|
check('一边无色也能交换:只描边 → 只填充(描边关、填充开),再按回到原样',
|
||||||
|
onlyStroke.strokeOn === true && onlyStroke.fill === false &&
|
||||||
|
afterSwap1.strokeOn === false && afterSwap1.fill === true &&
|
||||||
|
afterSwap2.strokeOn === true && afterSwap2.fill === false,
|
||||||
|
JSON.stringify({ 原: onlyStroke, 按一次: afterSwap1, 再按: afterSwap2 }))
|
||||||
|
|
||||||
// ================================================================
|
// ================================================================
|
||||||
// v1.15 图片调节(放最后:会改像素,放中间会污染依赖像素的用例)
|
// v1.15 图片调节(放最后:会改像素,放中间会污染依赖像素的用例)
|
||||||
// ================================================================
|
// ================================================================
|
||||||
|
|||||||
Reference in new issue
Block a user