Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b63771f6e4 |
No files matched your search
@@ -234,6 +234,53 @@ P 下双击 = 结束当前路径(`commitPenPath`),不再进节点编辑。
|
|||||||
- 文字 / 形状 / 钢笔会被直接栅格化进结果层(PS 合并矢量层也是这个结果)。
|
- 文字 / 形状 / 钢笔会被直接栅格化进结果层(PS 合并矢量层也是这个结果)。
|
||||||
- 结果层落回「原最低参与层」的位置,`assignLayerZ` 重新连续编号,不产生重复 z。
|
- 结果层落回「原最低参与层」的位置,`assignLayerZ` 重新连续编号,不产生重复 z。
|
||||||
|
|
||||||
|
## v1.10.0:颜色语义统一 / 选中框改实线 / 选区命令归位 / 矢量图形补描边与填充
|
||||||
|
|
||||||
|
这一版全部来自同一张界面截图上的四个疑问:「字体颜色有 3 个位置」「那个黑色应该换成
|
||||||
|
默认的参数」「字体这里有选区,这个不该出现」「选区工具反而没有这些按钮」。
|
||||||
|
四个都是真实缺陷,不是偏好。
|
||||||
|
|
||||||
|
### 1. 三处颜色各司其职(不再是三个长得一样的色块)
|
||||||
|
|
||||||
|
以前 `#ff4444` / `#ffffff` / `#000000` / `0.68` 这些默认值散在 `state.js`、`text.js`、
|
||||||
|
`events.js` 三处,改一处另两处不跟,界面上就出现「同一个概念三种颜色」。现在:
|
||||||
|
|
||||||
|
- `text.js` 导出 `TEXT_DEFAULTS`,**默认值单点定义**,`state.js` 与选项栏都从这里取;
|
||||||
|
- 描边色 / 底色 / 图形描边色的色块**统一外观**,但**标记生效状态**:
|
||||||
|
描边宽度为 0、底色关闭、图形处于「描边模式」时,色块显示为**灰色斜纹**
|
||||||
|
(不是颜色本身),语义是「这里还没有颜色」。以前半透明灰化不够——深色照样是一块黑方块,
|
||||||
|
用户会以为「设了个黑色没生效」;
|
||||||
|
- 文字底色默认从纯黑 `#000000` 改为中性近黑 `#101014`(68% 透明),色块按真实不透明度显示,
|
||||||
|
所见即所得,不再是一块死黑;
|
||||||
|
- 选描边色时若宽度为 0,自动给 6px(与「选底色即开底色」同一条原则:选了就是要用)。
|
||||||
|
|
||||||
|
### 2. 选中框从虚线改成实线
|
||||||
|
|
||||||
|
虚线在修图软件里的语义是**像素选区(蚂蚁线)**。文字/图形外面套一圈虚线,
|
||||||
|
用户会以为「莫名其妙多出来一个选区」,还删不掉。现在对象选中一律实线 + 四角手柄
|
||||||
|
(`objects.js` 的文字/形状、`layers.js` 的位图图层三处同步),虚线只留给真正的像素选区。
|
||||||
|
|
||||||
|
### 3. 选区命令(全选/反选/取消)归位到选区工具
|
||||||
|
|
||||||
|
那三个命令操作的是像素选区,跟文字对象没关系。以前它们挂在「选中文字/图形」的选项栏里,
|
||||||
|
选中一段文字就冒出来,看着像文字自带了选区;而真正的**矩形/套索选区工具**反而没有。
|
||||||
|
现在:选区工具(矩形、套索)有,选择工具「未选中任何元素」时也有,选中对象时不再出现。
|
||||||
|
|
||||||
|
### 4. 矢量图形补上描边色与填充色
|
||||||
|
|
||||||
|
- 每个形状新增独立的 `fillColor`;**描边色不再另起一份**,直接就是主色
|
||||||
|
(左侧色板 / 吸管 / 选项栏一个真相源,四处永远同步);
|
||||||
|
- `fillColor === null` 表示「跟随描边色」,于是新画的实心图形是**同色实心**,
|
||||||
|
换主色整块跟着变;一旦单独选过填充色就固定下来;
|
||||||
|
- 矩形/圆形/钢笔/箭头的选项栏都出现 `描边 ■` / `填充 ■` 色块(箭头没有填充区域,只给描边色),
|
||||||
|
选中已有图形时读它自己的值,没选中时改的是「下一次新建」的默认值;
|
||||||
|
- 选填充色即自动切到实心,色块随之从斜纹变成实际颜色;「样式 描边/实心」按钮
|
||||||
|
也改成读**选中对象自己**的 `fill`(以前只看全局默认值,选中一个已实心的矩形,
|
||||||
|
按钮却高亮「描边」,和画面反着来)。
|
||||||
|
|
||||||
|
回归:`tools/harness.mjs` **172 条全部通过**(新增 10 条:默认色不写死、色块生效态、
|
||||||
|
选区命令归位、选中框实线覆盖率 ≥0.85、图形描边/填充色与实际像素)。
|
||||||
|
|
||||||
## v1.9.1:输入框贴住点击点 / 选区图标归位 / 底色一选就亮
|
## v1.9.1:输入框贴住点击点 / 选区图标归位 / 底色一选就亮
|
||||||
|
|
||||||
v1.9.0 上线后用户反馈的三处「操作与实际反应不相符」。
|
v1.9.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 迭代降质、下载、设置记忆;无队列 |
|
||||||
|
| 颜色体系与矢量属性 | ✅ v1.10.0:默认值收口到 `TEXT_DEFAULTS`(文字底色去掉纯黑);三个色块标记「生效/未生效」(未生效显示灰色斜纹);对象选中框改实线(虚线只留给像素选区);选区命令归位到矩形/套索选区工具;矢量图形新增独立 `fillColor`,描边色复用主色,选项栏出 `描边 ■ / 填充 ■` 色块,填充缺省跟随描边 |
|
||||||
| 文字样式与吸附 | ✅ v1.9.0:文字补字重/对齐/行距/描边/底色块/多行(`text.js` 统一量算与绘制,描边底色撑大包围盒);拖动吸附画布中心/边缘 + 其他元素,阈值按屏幕像素折算故不随缩放变化,Alt 禁用;矩形圆角;最近使用颜色(存 `ctx.settings`,跨会话) |
|
| 文字样式与吸附 | ✅ v1.9.0:文字补字重/对齐/行距/描边/底色块/多行(`text.js` 统一量算与绘制,描边底色撑大包围盒);拖动吸附画布中心/边缘 + 其他元素,阈值按屏幕像素折算故不随缩放变化,Alt 禁用;矩形圆角;最近使用颜色(存 `ctx.settings`,跨会话) |
|
||||||
| 历史快照升级 | ✅ `snapshotState()` 记录完整图层集合(含 image 引用),能撤销「新建/删除图层」,这是复制新层与还原原图可撤销的前提 |
|
| 历史快照升级 | ✅ `snapshotState()` 记录完整图层集合(含 image 引用),能撤销「新建/删除图层」,这是复制新层与还原原图可撤销的前提 |
|
||||||
| 历史面板 / 多选 / 亮色主题 / 草稿 | ⏳ P3/P5 |
|
| 历史面板 / 多选 / 亮色主题 / 草稿 | ⏳ P3/P5 |
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@iwb-plugin/image-annotate",
|
"name": "@iwb-plugin/image-annotate",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "1.9.1",
|
"version": "1.10.0",
|
||||||
"description": "IWB 插件:图片标注 / 修图(编辑器移植自 iwb-plaus 扩展,纯 Canvas 2D)",
|
"description": "IWB 插件:图片标注 / 修图(编辑器移植自 iwb-plaus 扩展,纯 Canvas 2D)",
|
||||||
"ibwPlugin": {
|
"ibwPlugin": {
|
||||||
"id": "image-annotate",
|
"id": "image-annotate",
|
||||||
|
|||||||
@@ -1896,6 +1896,21 @@
|
|||||||
}
|
}
|
||||||
.iwb-opt-color::-webkit-color-swatch-wrapper { padding: 2px; }
|
.iwb-opt-color::-webkit-color-swatch-wrapper { padding: 2px; }
|
||||||
.iwb-opt-color::-webkit-color-swatch { border: 0; border-radius: 3px; }
|
.iwb-opt-color::-webkit-color-swatch { border: 0; border-radius: 3px; }
|
||||||
|
/* 底色是半透明的:色块按真实不透明度显示(--sw-a),看起来和画布上的效果一致,
|
||||||
|
不再是一块实心纯黑让人以为「又多了一个字体颜色」 */
|
||||||
|
.iwb-opt-color { opacity: var(--sw-a, 1); }
|
||||||
|
/* 该颜色当前没生效(描边宽度 0 / 底色未开 / 图形是描边模式):
|
||||||
|
不再显示那块颜色本身,而是显示为一块灰色斜纹 —— 语义是「这里还没有颜色」。
|
||||||
|
只做半透明灰化的话,纯黑/深色照样是一块黑方块,用户仍会以为「设了个黑色没生效」。 */
|
||||||
|
.iwb-opt-color.is-off {
|
||||||
|
opacity: 1;
|
||||||
|
border-style: dashed;
|
||||||
|
border-color: #4b4f66;
|
||||||
|
background: repeating-linear-gradient(45deg, #353849 0 3px, #262939 3px 6px);
|
||||||
|
}
|
||||||
|
.iwb-opt-color.is-off::-webkit-color-swatch { opacity: 0; }
|
||||||
|
/* 选项栏里色块旁边的分组标签,和「描边 / 底色」这类双字按钮区分开 */
|
||||||
|
.iwb-opt-swatch-label { color: #7f849c; font-size: 11px; flex: 0 0 auto; }
|
||||||
|
|
||||||
/* 「最近使用」:色板弹层里 4 列 × 2 行,空的时候整块隐藏(不占位) */
|
/* 「最近使用」:色板弹层里 4 列 × 2 行,空的时候整块隐藏(不占位) */
|
||||||
.iwb-editor-color-pop .iwb-editor-recent-colors {
|
.iwb-editor-color-pop .iwb-editor-recent-colors {
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ import { showSelectionContext, hideSelectionContext } from './floating.js'
|
|||||||
import { applyConstraintDrag, cancelCrop, clearOverlay, confirmCrop, drawCropPreview, hideCropBar, hitCropHandle, insideRect, resizeCropRect, setConstraint, showCropBar, updateCropInfo } from './crop.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 { 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 { snapMove } from './snap.js'
|
||||||
|
import { TEXT_DEFAULTS, TEXT_LINE_HEIGHT } from './text.js'
|
||||||
|
import { rememberColor } from './recent-colors.js'
|
||||||
import { cancelImagePlacement, confirmImagePlacement, drawPlacementPreview, hitPlacementHandle, insidePlacementRect, resizePlacement } from './placement.js'
|
import { cancelImagePlacement, confirmImagePlacement, drawPlacementPreview, hitPlacementHandle, insidePlacementRect, resizePlacement } from './placement.js'
|
||||||
import { close, copyResult, exportResult } from './index.js'
|
import { close, copyResult, exportResult } from './index.js'
|
||||||
import { loadImage } from './dom.js'
|
import { loadImage } from './dom.js'
|
||||||
@@ -535,6 +537,7 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
x1: S.startX, y1: S.startY,
|
x1: S.startX, y1: S.startY,
|
||||||
x2: pos.x, y2: pos.y,
|
x2: pos.x, y2: pos.y,
|
||||||
color: S.color,
|
color: S.color,
|
||||||
|
fillColor: S.shapeFillColor,
|
||||||
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,
|
||||||
@@ -740,6 +743,7 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
x1: S.startX, y1: S.startY,
|
x1: S.startX, y1: S.startY,
|
||||||
x2: pos.x, y2: pos.y,
|
x2: pos.x, y2: pos.y,
|
||||||
color: S.color,
|
color: S.color,
|
||||||
|
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,
|
||||||
radius: S.tool === 'rect' ? Math.max(0, S.shapeRadius) : 0,
|
radius: S.tool === 'rect' ? Math.max(0, S.shapeRadius) : 0,
|
||||||
@@ -972,11 +976,32 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
|
|
||||||
/** 描边/实心切换按钮组:owner 区分两套默认值(rect=矩形/圆,pen=钢笔)。
|
/** 描边/实心切换按钮组:owner 区分两套默认值(rect=矩形/圆,pen=钢笔)。
|
||||||
* 钢笔只在闭合路径上才有填充面积,但开关本身一直可点,便于先选后画。 */
|
* 钢笔只在闭合路径上才有填充面积,但开关本身一直可点,便于先选后画。 */
|
||||||
function fillStyleHTML(owner) {
|
/** 矢量图形的描边色 / 填充色块(v1.10)。
|
||||||
const fill = owner === 'pen' ? S.penFill : S.rectFill
|
* 描边色就是主色 S.color —— 左侧色板、吸管、选项栏三处读写同一个值,
|
||||||
|
* 不再为「形状描边」单独造一个色,否则又是一处「同一个概念两个颜色」。
|
||||||
|
* 填充色独立存在形状自己的 fillColor 上,没单独设过就跟随描边色(同色实心)。
|
||||||
|
* 填充关着的时候色块置灰(is-off),一眼能看出哪个颜色正在生效。 */
|
||||||
|
function shapeColorHTML(sh, owner) {
|
||||||
|
const stroke = sh ? (sh.color || S.color) : S.color
|
||||||
|
const fillOn = sh ? !!sh.fill : (owner === 'pen' ? S.penFill : S.rectFill)
|
||||||
|
const fill = sh ? (sh.fillColor || sh.color || S.color) : (S.shapeFillColor || S.color)
|
||||||
|
let html = '<span class="iwb-opt-label">描边</span>'
|
||||||
|
+ `<input type="color" class="iwb-opt-color" data-shape-color="stroke" value="${stroke}" title="描边颜色(与左侧主色同步,吸管取色也写这里)">`
|
||||||
|
if (owner) {
|
||||||
|
html += '<span class="iwb-opt-label">填充</span>'
|
||||||
|
+ `<input type="color" class="iwb-opt-color${fillOn ? '' : ' is-off'}" data-shape-color="fill" data-fill-owner="${owner}" value="${fill}" title="填充颜色${fillOn ? '' : ';当前是描边模式,选色会自动切成实心'}">`
|
||||||
|
}
|
||||||
|
return html
|
||||||
|
}
|
||||||
|
|
||||||
|
function fillStyleHTML(owner, sh) {
|
||||||
|
// 选中对象时以它自己的 fill 为准:以前只看全局 S.rectFill,
|
||||||
|
// 选中一个已经实心的矩形,选项栏却高亮「描边」,按钮和画面反着来。
|
||||||
|
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>
|
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="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="fill" data-fill-owner="${owner}" data-value="fill" title="实心填充 (Shift+X 切换)">实心</button>`
|
||||||
}
|
}
|
||||||
|
|
||||||
const SHAPE_NAMES = { rect: '矩形', circle: '圆形', arrow: '箭头', pen: '钢笔路径' }
|
const SHAPE_NAMES = { rect: '矩形', circle: '圆形', arrow: '箭头', pen: '钢笔路径' }
|
||||||
@@ -999,11 +1024,12 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
return {
|
return {
|
||||||
fontWeight: String(pick('fontWeight', 'textWeight', 'bold')),
|
fontWeight: String(pick('fontWeight', 'textWeight', 'bold')),
|
||||||
align: pick('align', 'textAlign', 'left'),
|
align: pick('align', 'textAlign', 'left'),
|
||||||
lineHeight: Number(pick('lineHeight', 'textLineHeight', 1.25)) || 1.25,
|
lineHeight: Number(pick('lineHeight', 'textLineHeight', TEXT_LINE_HEIGHT)) || TEXT_LINE_HEIGHT,
|
||||||
strokeWidth: Math.max(0, Number(pick('strokeWidth', 'textStrokeWidth', 0)) || 0),
|
strokeWidth: Math.max(0, Number(pick('strokeWidth', 'textStrokeWidth', TEXT_DEFAULTS.strokeWidth)) || 0),
|
||||||
strokeColor: pick('strokeColor', 'textStrokeColor', '#ffffff'),
|
strokeColor: pick('strokeColor', 'textStrokeColor', TEXT_DEFAULTS.strokeColor),
|
||||||
bgFill: !!pick('bgFill', 'textBgFill', false),
|
bgFill: !!pick('bgFill', 'textBgFill', TEXT_DEFAULTS.bgFill),
|
||||||
bgColor: pick('bgColor', 'textBgColor', '#000000')
|
bgColor: pick('bgColor', 'textBgColor', TEXT_DEFAULTS.bgColor),
|
||||||
|
bgAlpha: Number(pick('bgAlpha', 'textBgAlpha', TEXT_DEFAULTS.bgAlpha)) || TEXT_DEFAULTS.bgAlpha
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1021,9 +1047,9 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
<span class="iwb-opt-sep"></span>
|
<span class="iwb-opt-sep"></span>
|
||||||
<span class="iwb-opt-label">描边</span>
|
<span class="iwb-opt-label">描边</span>
|
||||||
<input type="number" class="iwb-opt-num" data-opt="textStrokeWidth" min="0" max="40" step="1" value="${Math.round(v.strokeWidth)}"><span class="iwb-opt-unit">px</span>
|
<input type="number" class="iwb-opt-num" data-opt="textStrokeWidth" min="0" max="40" step="1" value="${Math.round(v.strokeWidth)}"><span class="iwb-opt-unit">px</span>
|
||||||
<input type="color" class="iwb-opt-color" data-opt-color="strokeColor" value="${v.strokeColor}" title="描边颜色">
|
<input type="color" class="iwb-opt-color${v.strokeWidth > 0 ? '' : ' is-off'}" data-opt-color="strokeColor" value="${v.strokeColor}" title="描边颜色${v.strokeWidth > 0 ? '' : ';描边宽度是 0,选色会自动给 6px'}">
|
||||||
<button class="iwb-opt-btn${v.bgFill ? ' active' : ''}" data-opt-text="bgFill" data-value="${v.bgFill ? '0' : '1'}" title="给文字加一块半透明底色,压在花背景上也能看清">底色</button>
|
<button class="iwb-opt-btn${v.bgFill ? ' active' : ''}" data-opt-text="bgFill" data-value="${v.bgFill ? '0' : '1'}" title="给文字加一块底色,压在花背景上也能看清">底色</button>
|
||||||
<input type="color" class="iwb-opt-color" data-opt-color="bgColor" value="${v.bgColor}" title="底色颜色;选色会自动开启底色,不用先点左侧按钮">`
|
<input type="color" class="iwb-opt-color${v.bgFill ? '' : ' is-off'}" data-opt-color="bgColor" value="${v.bgColor}" style="--sw-a:${v.bgAlpha}" title="底色 ${Math.round(v.bgAlpha * 100)}% 不透明(色块按真实半透明显示);选色会自动开启底色">`
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 选择工具:只有选中了元素才出该元素的参数。
|
/** 选择工具:只有选中了元素才出该元素的参数。
|
||||||
@@ -1054,21 +1080,22 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
+ presetDots('shapeLineWidth', [1, 2, 3, 6, 10, 16, 24])
|
+ presetDots('shapeLineWidth', [1, 2, 3, 6, 10, 16, 24])
|
||||||
// 圆角只对矩形有意义(圆形本来就是圆的,箭头/钢笔没有这个概念)
|
// 圆角只对矩形有意义(圆形本来就是圆的,箭头/钢笔没有这个概念)
|
||||||
+ (t === 'rect' ? rangeOpt('shapeRadius', '圆角', 0, 200, Math.round(sh.radius || 0), 'px') : '')
|
+ (t === 'rect' ? rangeOpt('shapeRadius', '圆角', 0, 200, Math.round(sh.radius || 0), 'px') : '')
|
||||||
+ (t === 'arrow' ? '' : fillStyleHTML(owner))
|
// 描边色 / 填充色:箭头没有填充区域,只给描边色
|
||||||
|
+ shapeColorHTML(sh, t === 'arrow' ? null : owner)
|
||||||
|
+ (t === 'arrow' ? '' : fillStyleHTML(owner, sh))
|
||||||
+ (t === 'pen' && !sh.closed
|
+ (t === 'pen' && !sh.closed
|
||||||
? '<span class="iwb-opt-hint">这条钢笔路径未闭合,实心不生效;点回起点闭合后即可填充</span>'
|
? '<span class="iwb-opt-hint">这条钢笔路径未闭合,实心不生效;点回起点闭合后即可填充</span>'
|
||||||
: '')
|
: '')
|
||||||
+ selCmdHTML()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const text = getSelectedText()
|
const text = getSelectedText()
|
||||||
if (text) {
|
if (text) {
|
||||||
|
// v1.10:这里**不再**放「全选/反选/取消选区」那三个按钮。
|
||||||
|
// 用户反馈:选中一段文字时选项栏冒出选区命令,看着像「文字自带了一个选区」;
|
||||||
|
// 那三个命令操作的是像素选区(蚂蚁线),跟文字对象没关系,已归位到选区工具。
|
||||||
return `<span class="iwb-opt-current">已选中:文字</span>`
|
return `<span class="iwb-opt-current">已选中:文字</span>`
|
||||||
+ rangeOpt('textSize', '字号', 8, 400, Math.round(text.fontSize || S.textSize), 'px')
|
+ rangeOpt('textSize', '字号', 8, 400, Math.round(text.fontSize || S.textSize), 'px')
|
||||||
+ textStyleHTML(text)
|
+ textStyleHTML(text)
|
||||||
// 控件齐全时这一行很挤,说明文字必须排在按钮之后:
|
|
||||||
// 真放不下时宁可把 hint 滚出视野,也不能把「复制/取消选区」这些按钮顶没了
|
|
||||||
+ selCmdHTML()
|
|
||||||
+ '<span class="iwb-opt-hint">双击改内容 · 拖动手柄缩放</span>'
|
+ '<span class="iwb-opt-hint">双击改内容 · 拖动手柄缩放</span>'
|
||||||
}
|
}
|
||||||
// 选区命令是全局的,跟「有没有选中元素」无关:没选中时也必须能全选/反选/取消。
|
// 选区命令是全局的,跟「有没有选中元素」无关:没选中时也必须能全选/反选/取消。
|
||||||
@@ -1098,16 +1125,19 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
return rangeOpt('shapeLineWidth', '线宽', 1, 60, S.shapeLineWidth, '')
|
return rangeOpt('shapeLineWidth', '线宽', 1, 60, S.shapeLineWidth, '')
|
||||||
+ presetDots('shapeLineWidth', [1, 2, 3, 6, 10, 16, 24])
|
+ presetDots('shapeLineWidth', [1, 2, 3, 6, 10, 16, 24])
|
||||||
+ (tool === 'rect' ? rangeOpt('shapeRadius', '圆角', 0, 200, S.shapeRadius, 'px') : '')
|
+ (tool === 'rect' ? rangeOpt('shapeRadius', '圆角', 0, 200, S.shapeRadius, 'px') : '')
|
||||||
|
+ shapeColorHTML(null, 'rect')
|
||||||
+ fillStyleHTML('rect')
|
+ fillStyleHTML('rect')
|
||||||
}
|
}
|
||||||
if (tool === 'arrow') {
|
if (tool === 'arrow') {
|
||||||
return rangeOpt('shapeLineWidth', '线宽', 1, 60, S.shapeLineWidth, '')
|
return rangeOpt('shapeLineWidth', '线宽', 1, 60, S.shapeLineWidth, '')
|
||||||
+ presetDots('shapeLineWidth', [1, 2, 3, 6, 10, 16, 24])
|
+ presetDots('shapeLineWidth', [1, 2, 3, 6, 10, 16, 24])
|
||||||
|
+ shapeColorHTML(null, null)
|
||||||
+ '<span class="iwb-opt-hint">拖出箭头,松手完成</span>'
|
+ '<span class="iwb-opt-hint">拖出箭头,松手完成</span>'
|
||||||
}
|
}
|
||||||
if (tool === 'pen') {
|
if (tool === 'pen') {
|
||||||
return rangeOpt('shapeLineWidth', '线宽', 1, 60, S.shapeLineWidth, '')
|
return rangeOpt('shapeLineWidth', '线宽', 1, 60, S.shapeLineWidth, '')
|
||||||
+ presetDots('shapeLineWidth', [1, 2, 3, 6, 10, 16, 24])
|
+ presetDots('shapeLineWidth', [1, 2, 3, 6, 10, 16, 24])
|
||||||
|
+ shapeColorHTML(null, 'pen')
|
||||||
+ fillStyleHTML('pen')
|
+ fillStyleHTML('pen')
|
||||||
+ '<span class="iwb-opt-hint">逐点点击,点回起点闭合;闭合后可切换描边/实心</span>'
|
+ '<span class="iwb-opt-hint">逐点点击,点回起点闭合;闭合后可切换描边/实心</span>'
|
||||||
}
|
}
|
||||||
@@ -1117,15 +1147,19 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
+ '<span class="iwb-opt-hint">点画布输入文字,Enter 确认,Shift+Enter 换行</span>'
|
+ '<span class="iwb-opt-hint">点画布输入文字,Enter 确认,Shift+Enter 换行</span>'
|
||||||
}
|
}
|
||||||
if (tool === 'marquee') {
|
if (tool === 'marquee') {
|
||||||
|
// 选区命令归位(v1.10):全选/反选/取消选区属于「像素选区」,就该待在选区工具里,
|
||||||
|
// 而不是跟着文字/图形选中态到处跑。必须排在 hint 之前(hint 带 margin-left:auto)。
|
||||||
return `<span class="iwb-opt-label">形状</span>
|
return `<span class="iwb-opt-label">形状</span>
|
||||||
<button class="iwb-opt-btn${S.selectionKind === 'rect' ? ' active' : ''}" data-opt="shape" data-value="rect">矩形</button>
|
<button class="iwb-opt-btn${S.selectionKind === 'rect' ? ' active' : ''}" data-opt="shape" data-value="rect">矩形</button>
|
||||||
<button class="iwb-opt-btn${S.selectionKind === 'ellipse' ? ' active' : ''}" data-opt="shape" data-value="ellipse">椭圆</button>
|
<button class="iwb-opt-btn${S.selectionKind === 'ellipse' ? ' active' : ''}" data-opt="shape" data-value="ellipse">椭圆</button>
|
||||||
<label class="iwb-opt-label">羽化 <input type="number" class="iwb-opt-num" data-opt="feather" min="0" max="20" step="1" value="${S.selectionFeather}"> px</label>
|
<label class="iwb-opt-label">羽化 <input type="number" class="iwb-opt-num" data-opt="feather" min="0" max="20" step="1" value="${S.selectionFeather}"> px</label>`
|
||||||
<span class="iwb-opt-hint">${OPT_HINTS.marquee}</span>`
|
+ selCmdHTML()
|
||||||
|
+ `<span class="iwb-opt-hint">${OPT_HINTS.marquee}</span>`
|
||||||
}
|
}
|
||||||
if (tool === 'lasso') {
|
if (tool === 'lasso') {
|
||||||
return `<span class="iwb-opt-label">羽化 <input type="number" class="iwb-opt-num" data-opt="feather" min="0" max="20" step="1" value="${S.selectionFeather}"> px</span>
|
return `<span class="iwb-opt-label">羽化 <input type="number" class="iwb-opt-num" data-opt="feather" min="0" max="20" step="1" value="${S.selectionFeather}"> px</span>`
|
||||||
<span class="iwb-opt-hint">${OPT_HINTS.lasso}</span>`
|
+ selCmdHTML()
|
||||||
|
+ `<span class="iwb-opt-hint">${OPT_HINTS.lasso}</span>`
|
||||||
}
|
}
|
||||||
return `<span class="iwb-opt-current">当前工具:${TOOL_NAMES[tool] || tool}</span>
|
return `<span class="iwb-opt-current">当前工具:${TOOL_NAMES[tool] || tool}</span>
|
||||||
<span class="iwb-opt-hint">${OPT_HINTS[tool] || '选区工具按 M / L;Ctrl+J 复制选区,Delete 清除当前层'}</span>`
|
<span class="iwb-opt-hint">${OPT_HINTS[tool] || '选区工具按 M / L;Ctrl+J 复制选区,Delete 清除当前层'}</span>`
|
||||||
@@ -1201,9 +1235,28 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
btn.classList.toggle('active', String(sv[k]) === btn.dataset.value)
|
btn.classList.toggle('active', String(sv[k]) === btn.dataset.value)
|
||||||
})
|
})
|
||||||
body.querySelectorAll('[data-opt-color]').forEach(inp => {
|
body.querySelectorAll('[data-opt-color]').forEach(inp => {
|
||||||
if (document.activeElement === inp) return
|
const k = inp.dataset.optColor
|
||||||
const v = sv[inp.dataset.optColor]
|
if (document.activeElement !== inp) {
|
||||||
if (v && String(inp.value).toLowerCase() !== String(v).toLowerCase()) inp.value = v
|
const v = sv[k]
|
||||||
|
if (v && String(inp.value).toLowerCase() !== String(v).toLowerCase()) inp.value = v
|
||||||
|
}
|
||||||
|
// 「正在生效」态:描边宽度 0 时描边色没起作用,底色没开时底色没起作用。
|
||||||
|
// 三个色块长得一模一样是上一版最误导的地方 —— 用户会以为「字体颜色有三处」。
|
||||||
|
if (k === 'strokeColor') inp.classList.toggle('is-off', !(sv.strokeWidth > 0))
|
||||||
|
if (k === 'bgColor') inp.classList.toggle('is-off', !sv.bgFill)
|
||||||
|
})
|
||||||
|
// 矢量图形的描边/填充色块(选中对象读对象自己的值,没选中读新建默认值)
|
||||||
|
body.querySelectorAll('[data-shape-color]').forEach(inp => {
|
||||||
|
const kind = inp.dataset.shapeColor
|
||||||
|
const owner = inp.dataset.fillOwner === 'pen' ? 'pen' : 'rect'
|
||||||
|
const stroke = selShape ? (selShape.color || S.color) : S.color
|
||||||
|
const fill = selShape ? (selShape.fillColor || selShape.color || S.color) : (S.shapeFillColor || S.color)
|
||||||
|
const v = kind === 'fill' ? fill : stroke
|
||||||
|
if (document.activeElement !== inp && v && String(inp.value).toLowerCase() !== String(v).toLowerCase()) inp.value = v
|
||||||
|
if (kind === 'fill') {
|
||||||
|
const on = selShape ? !!selShape.fill : (owner === 'pen' ? S.penFill : S.rectFill)
|
||||||
|
inp.classList.toggle('is-off', !on)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1267,23 +1320,24 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
if (key === 'bgFill') value = raw === true || raw === 1 || raw === '1' || raw === 'true'
|
if (key === 'bgFill') value = raw === true || raw === 1 || raw === '1' || raw === 'true'
|
||||||
else if (key === 'lineHeight') value = clamp(Number(raw) || 125, 80, 300) / 100
|
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 === 'strokeWidth') value = clamp(Number(raw) || 0, 0, 40)
|
||||||
else if (key === 'strokeColor' || key === 'bgColor') value = String(raw || '#000000').toLowerCase()
|
else if (key === 'strokeColor' || key === 'bgColor') value = String(raw || TEXT_DEFAULTS.bgColor).toLowerCase()
|
||||||
else value = String(raw)
|
else value = String(raw)
|
||||||
|
|
||||||
S[stateKey] = value
|
S[stateKey] = value
|
||||||
|
// 「选了颜色就说明想用它」:描边宽度 0 / 底色没开的时候选色,画布上一点变化都没有,
|
||||||
|
// 会被当成「颜色坏了 / 被别的图层盖住」。顺手把开关打开,所见即所得。
|
||||||
|
if (key === 'strokeColor' && !(Number(S.textStrokeWidth) > 0)) S.textStrokeWidth = 6
|
||||||
|
if (key === 'bgColor' && !S.textBgFill) S.textBgFill = true
|
||||||
|
|
||||||
const t = getSelectedText()
|
const t = getSelectedText()
|
||||||
if (!t || t.locked) { textStyleSnapDone = false; return }
|
if (!t || t.locked) { textStyleSnapDone = false; syncOptionBar(); return }
|
||||||
if (committed || !textStyleSnapDone) { saveSnapshot('文字样式'); textStyleSnapDone = true }
|
if (committed || !textStyleSnapDone) { saveSnapshot('文字样式'); textStyleSnapDone = true }
|
||||||
t[key] = value
|
t[key] = value
|
||||||
// 只调颜色、没点「底色」开关时,画布上什么都不会变 —— 这是最容易被当成
|
if (key === 'strokeColor' && !(Number(t.strokeWidth) > 0)) t.strokeWidth = S.textStrokeWidth
|
||||||
// 「底色坏了 / 被别的颜色盖住」的路径。选了颜色就说明想用它,顺手把底色打开。
|
if (key === 'bgColor' && !t.bgFill) t.bgFill = true
|
||||||
if (key === 'bgColor' && !t.bgFill) {
|
|
||||||
t.bgFill = true
|
|
||||||
S.textBgFill = true
|
|
||||||
}
|
|
||||||
renderObjects()
|
renderObjects()
|
||||||
// 自动开启底色后按钮的 active 态与色块取值都要跟着刷新
|
// 自动打开描边/底色后,按钮 active 态与色块取值都要跟着刷新
|
||||||
if (key === 'bgColor') syncOptionBar()
|
if (key === 'bgColor' || key === 'strokeColor') syncOptionBar()
|
||||||
if (committed) textStyleSnapDone = false
|
if (committed) textStyleSnapDone = false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1299,6 +1353,35 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
if (committed) radiusSnapDone = false
|
if (committed) radiusSnapDone = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 形状描边色 / 填充色(v1.10)。
|
||||||
|
* 描边色不另存一份 —— 直接走 applyColorChange 写主色,左侧色板、吸管、
|
||||||
|
* 文字色、形状描边色四处因此永远同一个值(上一版的教训:同一个概念存两处必分叉)。
|
||||||
|
* 填充色写形状自己的 fillColor;还没切实心时选填充色顺手切实心(与文字底色同一逻辑)。 */
|
||||||
|
function applyShapeColor(kind, raw) {
|
||||||
|
const hex = String(raw || '').toLowerCase()
|
||||||
|
if (!/^#[0-9a-f]{6}$/.test(hex)) return
|
||||||
|
if (kind === 'stroke') {
|
||||||
|
applyColorChange(hex)
|
||||||
|
syncOptionBar()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
S.shapeFillColor = hex
|
||||||
|
rememberColor(hex)
|
||||||
|
const sh = getSelectedShape()
|
||||||
|
const owner = sh ? (sh.type === 'pen' ? 'pen' : 'rect') : (S.tool === 'pen' ? 'pen' : 'rect')
|
||||||
|
if (owner === 'pen') S.penFill = true
|
||||||
|
else S.rectFill = true
|
||||||
|
updateFillUI()
|
||||||
|
if (sh && !sh.locked) {
|
||||||
|
saveSnapshot('填充颜色')
|
||||||
|
// 未闭合的钢笔路径没有可填区域,保持描边(否则按钮亮着、画面没变化)
|
||||||
|
sh.fillColor = hex
|
||||||
|
sh.fill = owner === 'pen' ? !!sh.closed : true
|
||||||
|
renderObjects()
|
||||||
|
}
|
||||||
|
syncOptionBar()
|
||||||
|
}
|
||||||
|
|
||||||
/** 形状描边/实心:既改下次新建的默认值,也改当前选中的那个。
|
/** 形状描边/实心:既改下次新建的默认值,也改当前选中的那个。
|
||||||
* owner='rect' 作用于矩形/圆,owner='pen' 作用于钢笔闭合路径。 */
|
* owner='rect' 作用于矩形/圆,owner='pen' 作用于钢笔闭合路径。 */
|
||||||
function setShapeFill(fill, owner) {
|
function setShapeFill(fill, owner) {
|
||||||
@@ -1444,6 +1527,13 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
|||||||
syncOptionBar()
|
syncOptionBar()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
// 矢量图形的描边/填充色块(原生取色器关闭时才派发 change)
|
||||||
|
const shapeColorEl = e.target.closest ? e.target.closest('[data-shape-color]') : null
|
||||||
|
if (shapeColorEl) {
|
||||||
|
e.stopPropagation()
|
||||||
|
applyShapeColor(shapeColorEl.dataset.shapeColor, shapeColorEl.value)
|
||||||
|
return
|
||||||
|
}
|
||||||
setOptionFromControl(e.target, true)
|
setOptionFromControl(e.target, true)
|
||||||
})
|
})
|
||||||
body.addEventListener('click', (e) => {
|
body.addEventListener('click', (e) => {
|
||||||
@@ -1909,7 +1999,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, 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, 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)
|
||||||
|
|||||||
@@ -323,7 +323,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, 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, 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, align: t.align, lineHeight: t.lineHeight,
|
fontWeight: t.fontWeight, align: t.align, lineHeight: t.lineHeight,
|
||||||
@@ -337,8 +337,10 @@ import { toast } from './commands.js'
|
|||||||
textDefaults: {
|
textDefaults: {
|
||||||
weight: S.textWeight, align: S.textAlign, lineHeight: S.textLineHeight,
|
weight: S.textWeight, align: S.textAlign, lineHeight: S.textLineHeight,
|
||||||
strokeWidth: S.textStrokeWidth, strokeColor: S.textStrokeColor,
|
strokeWidth: S.textStrokeWidth, strokeColor: S.textStrokeColor,
|
||||||
bgFill: S.textBgFill, bgColor: S.textBgColor
|
bgFill: S.textBgFill, bgColor: S.textBgColor, bgAlpha: S.textBgAlpha
|
||||||
}, selectedShapeId: S.selectedShapeId,
|
},
|
||||||
|
// 矢量图形颜色:fillColor=null 表示跟随描边色(回归要能断言这条语义)
|
||||||
|
shapeColors: { stroke: S.color, fill: S.shapeFillColor || null }, selectedShapeId: S.selectedShapeId,
|
||||||
// 光标所在的图片坐标(状态栏同源):换算问题的第一现场证据
|
// 光标所在的图片坐标(状态栏同源):换算问题的第一现场证据
|
||||||
lastPos: S.lastPos ? { x: Math.round(S.lastPos.x), y: Math.round(S.lastPos.y) } : null,
|
lastPos: S.lastPos ? { x: Math.round(S.lastPos.x), y: Math.round(S.lastPos.y) } : null,
|
||||||
// 当前正在进行的拖拽类型:move 才是拖动本体,handle/rotate 说明点到了控制点
|
// 当前正在进行的拖拽类型:move 才是拖动本体,handle/rotate 说明点到了控制点
|
||||||
|
|||||||
@@ -208,14 +208,13 @@ import { isDrawableLayer } from '../vendor/layer-logic.js'
|
|||||||
ctx.save()
|
ctx.save()
|
||||||
ctx.strokeStyle = '#e8a735'
|
ctx.strokeStyle = '#e8a735'
|
||||||
ctx.lineWidth = 1.5 / viewScale()
|
ctx.lineWidth = 1.5 / viewScale()
|
||||||
ctx.setLineDash([6 / viewScale(), 3 / viewScale()])
|
// 图层/对象选中一律实线(虚线是像素选区的语义,见 objects.js 同处注释)
|
||||||
const corners = boxCorners(box.x, box.y, box.w, box.h, rot)
|
const corners = boxCorners(box.x, box.y, box.w, box.h, rot)
|
||||||
ctx.beginPath()
|
ctx.beginPath()
|
||||||
ctx.moveTo(corners[0][0], corners[0][1])
|
ctx.moveTo(corners[0][0], corners[0][1])
|
||||||
for (let i = 1; i < corners.length; i++) ctx.lineTo(corners[i][0], corners[i][1])
|
for (let i = 1; i < corners.length; i++) ctx.lineTo(corners[i][0], corners[i][1])
|
||||||
ctx.closePath()
|
ctx.closePath()
|
||||||
ctx.stroke()
|
ctx.stroke()
|
||||||
ctx.setLineDash([])
|
|
||||||
ctx.fillStyle = '#fff'
|
ctx.fillStyle = '#fff'
|
||||||
ctx.strokeStyle = '#e8a735'
|
ctx.strokeStyle = '#e8a735'
|
||||||
const pts = frameHandlePoints(box, rot)
|
const pts = frameHandlePoints(box, rot)
|
||||||
|
|||||||
@@ -418,14 +418,14 @@ import { isDrawableLayer } from '../vendor/layer-logic.js'
|
|||||||
octx.save()
|
octx.save()
|
||||||
octx.strokeStyle = '#e8a735'
|
octx.strokeStyle = '#e8a735'
|
||||||
octx.lineWidth = 1.5 / viewScale()
|
octx.lineWidth = 1.5 / viewScale()
|
||||||
octx.setLineDash([6 / viewScale(), 3 / viewScale()])
|
// v1.10:对象选中框用**实线**。虚线在 PS 语义里是「像素选区(蚂蚁线)」,
|
||||||
|
// 用户看到文字/图形外面一圈虚线会当成「莫名其妙多出来的选区」。
|
||||||
const corners = boxCorners(b.x, b.y, b.w, b.h, rot)
|
const corners = boxCorners(b.x, b.y, b.w, b.h, rot)
|
||||||
octx.beginPath()
|
octx.beginPath()
|
||||||
octx.moveTo(corners[0][0], corners[0][1])
|
octx.moveTo(corners[0][0], corners[0][1])
|
||||||
for (let i = 1; i < corners.length; i++) octx.lineTo(corners[i][0], corners[i][1])
|
for (let i = 1; i < corners.length; i++) octx.lineTo(corners[i][0], corners[i][1])
|
||||||
octx.closePath()
|
octx.closePath()
|
||||||
octx.stroke()
|
octx.stroke()
|
||||||
octx.setLineDash([])
|
|
||||||
const hs = 5.5 / viewScale()
|
const hs = 5.5 / viewScale()
|
||||||
octx.fillStyle = '#ffffff'
|
octx.fillStyle = '#ffffff'
|
||||||
octx.strokeStyle = '#e8a735'
|
octx.strokeStyle = '#e8a735'
|
||||||
@@ -475,14 +475,13 @@ import { isDrawableLayer } from '../vendor/layer-logic.js'
|
|||||||
octx.save()
|
octx.save()
|
||||||
octx.strokeStyle = '#e8a735'
|
octx.strokeStyle = '#e8a735'
|
||||||
octx.lineWidth = 1.5 / viewScale()
|
octx.lineWidth = 1.5 / viewScale()
|
||||||
octx.setLineDash([6 / viewScale(), 3 / viewScale()])
|
// 同上:对象选中是实线(虚线只留给像素选区的蚂蚁线)
|
||||||
const corners = boxCorners(b.x - 2 / viewScale(), b.y - 2 / viewScale(), b.w + 4 / viewScale(), b.h + 4 / viewScale(), rot)
|
const corners = boxCorners(b.x - 2 / viewScale(), b.y - 2 / viewScale(), b.w + 4 / viewScale(), b.h + 4 / viewScale(), rot)
|
||||||
octx.beginPath()
|
octx.beginPath()
|
||||||
octx.moveTo(corners[0][0], corners[0][1])
|
octx.moveTo(corners[0][0], corners[0][1])
|
||||||
for (let i = 1; i < corners.length; i++) octx.lineTo(corners[i][0], corners[i][1])
|
for (let i = 1; i < corners.length; i++) octx.lineTo(corners[i][0], corners[i][1])
|
||||||
octx.closePath()
|
octx.closePath()
|
||||||
octx.stroke()
|
octx.stroke()
|
||||||
octx.setLineDash([])
|
|
||||||
const hs = 5.5 / viewScale()
|
const hs = 5.5 / viewScale()
|
||||||
octx.fillStyle = '#ffffff'
|
octx.fillStyle = '#ffffff'
|
||||||
octx.strokeStyle = '#e8a735'
|
octx.strokeStyle = '#e8a735'
|
||||||
|
|||||||
@@ -7,6 +7,9 @@
|
|||||||
|
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
|
// text.js 是零依赖叶子模块,这里引它的默认值常量不会形成循环
|
||||||
|
import { TEXT_DEFAULTS } from './text.js'
|
||||||
|
|
||||||
export const ZOOM_MIN = 0.1
|
export const ZOOM_MIN = 0.1
|
||||||
export const ZOOM_MAX = 10
|
export const ZOOM_MAX = 10
|
||||||
export const ZOOM_STEP = 1.15
|
export const ZOOM_STEP = 1.15
|
||||||
@@ -39,15 +42,19 @@
|
|||||||
// 否则「调细画笔」会顺手把所有形状的描边一起改掉。
|
// 否则「调细画笔」会顺手把所有形状的描边一起改掉。
|
||||||
shapeLineWidth: 3, // 矩形/圆形/箭头/钢笔的描边粗细
|
shapeLineWidth: 3, // 矩形/圆形/箭头/钢笔的描边粗细
|
||||||
shapeRadius: 0, // 矩形圆角半径 px(v1.9,仅 rect 有意义)
|
shapeRadius: 0, // 矩形圆角半径 px(v1.9,仅 rect 有意义)
|
||||||
|
// v1.10:矢量图形的填充色。null = 跟随描边色(新画的就是「同色实心」,
|
||||||
|
// 换主色时整体跟着变),一旦单独选过填充色就固定下来(每形状自己存 fillColor)。
|
||||||
|
shapeFillColor: null,
|
||||||
textSize: 32, // 新建文字的字号 px
|
textSize: 32, // 新建文字的字号 px
|
||||||
// ---- v1.9 文字样式:这套是「新建文字」的默认值,每段文字自己存一份 ----
|
// ---- v1.9 文字样式:这套是「新建文字」的默认值,每段文字自己存一份 ----
|
||||||
textWeight: 'bold', // bold | normal | 900
|
textWeight: 'bold', // bold | normal | 900
|
||||||
textAlign: 'left', // left | center | right(多行时各行按块宽对齐)
|
textAlign: 'left', // left | center | right(多行时各行按块宽对齐)
|
||||||
textLineHeight: 1.25, // 行高倍数(1.25 = 老版单行高度,勿随意改)
|
textLineHeight: 1.25, // 行高倍数(1.25 = 老版单行高度,勿随意改)
|
||||||
textStrokeWidth: 0, // 描边宽度 px,0 = 无描边
|
textStrokeWidth: TEXT_DEFAULTS.strokeWidth, // 描边宽度 px,0 = 无描边
|
||||||
textStrokeColor: '#ffffff',
|
textStrokeColor: TEXT_DEFAULTS.strokeColor,
|
||||||
textBgFill: false, // 底色块
|
textBgFill: TEXT_DEFAULTS.bgFill, // 底色块
|
||||||
textBgColor: '#000000',
|
textBgColor: TEXT_DEFAULTS.bgColor, // 中性近黑,不再是纯黑 #000000
|
||||||
|
textBgAlpha: TEXT_DEFAULTS.bgAlpha, // 底色透明度(色块按这个不透明度显示,所见即所得)
|
||||||
// 最近使用颜色(最多 8 个,存 ctx.settings,跨会话保留)
|
// 最近使用颜色(最多 8 个,存 ctx.settings,跨会话保留)
|
||||||
recentColors: [],
|
recentColors: [],
|
||||||
// 图层系统
|
// 图层系统
|
||||||
|
|||||||
@@ -15,6 +15,23 @@
|
|||||||
/** 默认行高倍数:必须等于老版的 fontSize×1.25,否则单行文字的选中框会变高 */
|
/** 默认行高倍数:必须等于老版的 fontSize×1.25,否则单行文字的选中框会变高 */
|
||||||
export const TEXT_LINE_HEIGHT = 1.25
|
export const TEXT_LINE_HEIGHT = 1.25
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文字默认样式:**唯一的真相源**。
|
||||||
|
* 以前 '#ff4444' / '#ffffff' / '#000000' / 0.68 散落在 state.js、text.js、
|
||||||
|
* events.js 三处,改一处另两处不跟,界面上就会出现「同一个概念三种颜色」——
|
||||||
|
* 用户实测反馈「字体颜色有 3 个位置,那个黑色应该换成默认的参数」正是这么来的。
|
||||||
|
* 底色默认也不再是纯黑 #000000:纯黑在深色/花色底图上像抠了个洞,
|
||||||
|
* 而且和「文字色」看起来像是同一件事。改成中性近黑 #101014 + 68% 透明。
|
||||||
|
*/
|
||||||
|
export const TEXT_DEFAULTS = {
|
||||||
|
color: '#ff4444',
|
||||||
|
strokeWidth: 0,
|
||||||
|
strokeColor: '#ffffff',
|
||||||
|
bgFill: false,
|
||||||
|
bgColor: '#101014',
|
||||||
|
bgAlpha: 0.68
|
||||||
|
}
|
||||||
|
|
||||||
/** 底色块相对字号的 padding 系数 */
|
/** 底色块相对字号的 padding 系数 */
|
||||||
const BG_PAD_RATIO = 0.3
|
const BG_PAD_RATIO = 0.3
|
||||||
|
|
||||||
@@ -102,8 +119,8 @@
|
|||||||
const r = Math.min(m.pad + 2, Math.min(boxW, m.h + m.pad * 2) / 2)
|
const r = Math.min(m.pad + 2, Math.min(boxW, m.h + m.pad * 2) / 2)
|
||||||
// 0.55 在浅色/花色底图上偏透,用户容易以为「底色没生效」;0.68 既压得住底图,
|
// 0.55 在浅色/花色底图上偏透,用户容易以为「底色没生效」;0.68 既压得住底图,
|
||||||
// 也还看得见一点背景,是「垫一块板让字立起来」的常用手感。
|
// 也还看得见一点背景,是「垫一块板让字立起来」的常用手感。
|
||||||
ctx.globalAlpha = (t.opacity != null ? t.opacity : 1) * (t.bgAlpha == null ? 0.68 : t.bgAlpha)
|
ctx.globalAlpha = (t.opacity != null ? t.opacity : 1) * (t.bgAlpha == null ? TEXT_DEFAULTS.bgAlpha : t.bgAlpha)
|
||||||
ctx.fillStyle = t.bgColor || '#000000'
|
ctx.fillStyle = t.bgColor || TEXT_DEFAULTS.bgColor
|
||||||
const bx = t.x, by = t.y
|
const bx = t.x, by = t.y
|
||||||
const bw = boxW, bh = m.h + m.pad * 2
|
const bw = boxW, bh = m.h + m.pad * 2
|
||||||
ctx.beginPath()
|
ctx.beginPath()
|
||||||
@@ -132,10 +149,10 @@
|
|||||||
const y = t.y + m.pad + i * m.lh
|
const y = t.y + m.pad + i * m.lh
|
||||||
if (m.sw > 0) {
|
if (m.sw > 0) {
|
||||||
ctx.lineWidth = m.sw
|
ctx.lineWidth = m.sw
|
||||||
ctx.strokeStyle = t.strokeColor || '#ffffff'
|
ctx.strokeStyle = t.strokeColor || TEXT_DEFAULTS.strokeColor
|
||||||
ctx.strokeText(m.lines[i], ox, y)
|
ctx.strokeText(m.lines[i], ox, y)
|
||||||
}
|
}
|
||||||
ctx.fillStyle = t.color || '#ff4444'
|
ctx.fillStyle = t.color || TEXT_DEFAULTS.color
|
||||||
ctx.fillText(m.lines[i], ox, y)
|
ctx.fillText(m.lines[i], ox, y)
|
||||||
}
|
}
|
||||||
ctx.restore()
|
ctx.restore()
|
||||||
@@ -149,9 +166,9 @@
|
|||||||
align: alignOf(s),
|
align: alignOf(s),
|
||||||
lineHeight: Number(s.lineHeight) || TEXT_LINE_HEIGHT,
|
lineHeight: Number(s.lineHeight) || TEXT_LINE_HEIGHT,
|
||||||
strokeWidth: Math.max(0, Number(s.strokeWidth) || 0),
|
strokeWidth: Math.max(0, Number(s.strokeWidth) || 0),
|
||||||
strokeColor: s.strokeColor || '#ffffff',
|
strokeColor: s.strokeColor || TEXT_DEFAULTS.strokeColor,
|
||||||
bgFill: !!s.bgFill,
|
bgFill: !!s.bgFill,
|
||||||
bgColor: s.bgColor || '#000000',
|
bgColor: s.bgColor || TEXT_DEFAULTS.bgColor,
|
||||||
bgAlpha: s.bgAlpha == null ? 0.68 : Number(s.bgAlpha)
|
bgAlpha: s.bgAlpha == null ? TEXT_DEFAULTS.bgAlpha : Number(s.bgAlpha)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -180,6 +180,12 @@ import { rememberColor } from './recent-colors.js'
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** 按形状对象绘制(矩形/箭头),预览与最终渲染共用 */
|
/** 按形状对象绘制(矩形/箭头),预览与最终渲染共用 */
|
||||||
|
/** 形状描边色:每个形状自己存 color(v1.10 起选项栏可单独调) */
|
||||||
|
export function strokeOf(s) { return (s && s.color) || S.color }
|
||||||
|
|
||||||
|
/** 形状填充色:自己设过 fillColor 就用它,否则跟随描边色(同色实心是默认手感) */
|
||||||
|
export function fillOf(s) { return (s && s.fillColor) || strokeOf(s) }
|
||||||
|
|
||||||
export function drawShape(ctx, s) {
|
export function drawShape(ctx, s) {
|
||||||
ctx.save()
|
ctx.save()
|
||||||
ctx.globalAlpha = s.opacity != null ? s.opacity : 1
|
ctx.globalAlpha = s.opacity != null ? s.opacity : 1
|
||||||
@@ -191,23 +197,23 @@ import { rememberColor } from './recent-colors.js'
|
|||||||
ctx.rotate(rot * Math.PI / 180)
|
ctx.rotate(rot * Math.PI / 180)
|
||||||
ctx.translate(-cx, -cy)
|
ctx.translate(-cx, -cy)
|
||||||
}
|
}
|
||||||
ctx.strokeStyle = s.color
|
ctx.strokeStyle = strokeOf(s)
|
||||||
ctx.lineWidth = s.lw
|
ctx.lineWidth = s.lw
|
||||||
ctx.lineCap = 'round'
|
ctx.lineCap = 'round'
|
||||||
ctx.lineJoin = 'round'
|
ctx.lineJoin = 'round'
|
||||||
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 = s.color; 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() } 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)
|
||||||
if (radius > 0) {
|
if (radius > 0) {
|
||||||
ctx.beginPath()
|
ctx.beginPath()
|
||||||
roundRectPath(ctx, rx, ry, rw, rh, radius)
|
roundRectPath(ctx, rx, ry, rw, rh, radius)
|
||||||
if (s.fill) { ctx.fillStyle = s.color; ctx.fill() }
|
if (s.fill) { ctx.fillStyle = fillOf(s); ctx.fill() }
|
||||||
ctx.stroke()
|
ctx.stroke()
|
||||||
} else {
|
} else {
|
||||||
if (s.fill) { ctx.fillStyle = s.color; 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)
|
ctx.strokeRect(rx, ry, rw, rh)
|
||||||
}
|
}
|
||||||
} else if (s.type === 'circle') {
|
} else if (s.type === 'circle') {
|
||||||
@@ -215,10 +221,10 @@ import { rememberColor } from './recent-colors.js'
|
|||||||
const rw = Math.abs(s.x2 - s.x1), rh = Math.abs(s.y2 - s.y1)
|
const rw = Math.abs(s.x2 - s.x1), rh = Math.abs(s.y2 - s.y1)
|
||||||
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 = s.color; ctx.fill() }
|
if (s.fill) { ctx.fillStyle = fillOf(s); ctx.fill() }
|
||||||
ctx.stroke()
|
ctx.stroke()
|
||||||
} else {
|
} else {
|
||||||
ctx.fillStyle = s.color
|
ctx.fillStyle = strokeOf(s)
|
||||||
ctx.beginPath()
|
ctx.beginPath()
|
||||||
ctx.moveTo(s.x1, s.y1)
|
ctx.moveTo(s.x1, s.y1)
|
||||||
ctx.lineTo(s.x2, s.y2)
|
ctx.lineTo(s.x2, s.y2)
|
||||||
|
|||||||
+244
-168
@@ -9,7 +9,7 @@
|
|||||||
var __IWB_ANNOTATE_MANIFEST__ = {
|
var __IWB_ANNOTATE_MANIFEST__ = {
|
||||||
id: 'image-annotate',
|
id: 'image-annotate',
|
||||||
name: '标注 / 修图',
|
name: '标注 / 修图',
|
||||||
version: '1.9.1',
|
version: '1.10.0',
|
||||||
apiVersion: 1,
|
apiVersion: 1,
|
||||||
capabilities: ['commands', 'nodeActions', 'canvas', 'canvasWrite'],
|
capabilities: ['commands', 'nodeActions', 'canvas', 'canvasWrite'],
|
||||||
settings: {
|
settings: {
|
||||||
@@ -24,6 +24,131 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
(() => {
|
(() => {
|
||||||
|
// image-annotate/plugin/editor/text.js
|
||||||
|
var TEXT_LINE_HEIGHT = 1.25;
|
||||||
|
var TEXT_DEFAULTS = {
|
||||||
|
color: "#ff4444",
|
||||||
|
strokeWidth: 0,
|
||||||
|
strokeColor: "#ffffff",
|
||||||
|
bgFill: false,
|
||||||
|
bgColor: "#101014",
|
||||||
|
bgAlpha: 0.68
|
||||||
|
};
|
||||||
|
var BG_PAD_RATIO = 0.3;
|
||||||
|
var _measureCtx = null;
|
||||||
|
function measureCtx() {
|
||||||
|
if (!_measureCtx) {
|
||||||
|
const c = document.createElement("canvas");
|
||||||
|
c.width = 8;
|
||||||
|
c.height = 8;
|
||||||
|
_measureCtx = c.getContext("2d");
|
||||||
|
}
|
||||||
|
return _measureCtx;
|
||||||
|
}
|
||||||
|
function weightOf(t) {
|
||||||
|
const w = t && t.fontWeight;
|
||||||
|
return w == null || w === "" ? "bold" : String(w);
|
||||||
|
}
|
||||||
|
function fontOf(t) {
|
||||||
|
const size = Math.max(4, Number(t && t.fontSize) || 32);
|
||||||
|
return weightOf(t) + " " + size + "px sans-serif";
|
||||||
|
}
|
||||||
|
function textMetrics(t) {
|
||||||
|
const ctx = measureCtx();
|
||||||
|
const font = fontOf(t);
|
||||||
|
ctx.font = font;
|
||||||
|
const raw = (t && t.text) == null ? "" : String(t.text);
|
||||||
|
const lines = raw.split("\n");
|
||||||
|
const widths = lines.map((line) => ctx.measureText(line).width);
|
||||||
|
const size = Math.max(4, Number(t && t.fontSize) || 32);
|
||||||
|
const lh = size * (Number(t && t.lineHeight) || TEXT_LINE_HEIGHT);
|
||||||
|
const w = lines.length ? Math.max.apply(null, widths) : 0;
|
||||||
|
const pad = t && t.bgFill ? Math.round(size * BG_PAD_RATIO) : 0;
|
||||||
|
const sw = Math.max(0, Number(t && t.strokeWidth) || 0);
|
||||||
|
return { lines, widths, w, h: lh * lines.length, lh, pad, sw, font, size };
|
||||||
|
}
|
||||||
|
function textBox(t) {
|
||||||
|
const m = textMetrics(t);
|
||||||
|
const half = m.sw / 2;
|
||||||
|
return {
|
||||||
|
x: t.x - half,
|
||||||
|
y: t.y - half,
|
||||||
|
w: Math.max(m.w, 2) + m.pad * 2 + m.sw,
|
||||||
|
h: Math.max(m.h, 1) + m.pad * 2 + m.sw
|
||||||
|
};
|
||||||
|
}
|
||||||
|
function alignOf(t) {
|
||||||
|
const a = t && t.align;
|
||||||
|
return a === "center" || a === "right" ? a : "left";
|
||||||
|
}
|
||||||
|
function drawTextObject(ctx, t) {
|
||||||
|
const m = textMetrics(t);
|
||||||
|
ctx.save();
|
||||||
|
ctx.textBaseline = "top";
|
||||||
|
ctx.globalAlpha = t.opacity != null ? t.opacity : 1;
|
||||||
|
const b = textBox(t);
|
||||||
|
const rot = t.rotation || 0;
|
||||||
|
if (rot) {
|
||||||
|
const cx = b.x + b.w / 2;
|
||||||
|
const cy = b.y + b.h / 2;
|
||||||
|
ctx.translate(cx, cy);
|
||||||
|
ctx.rotate(rot * Math.PI / 180);
|
||||||
|
ctx.translate(-cx, -cy);
|
||||||
|
}
|
||||||
|
ctx.font = m.font;
|
||||||
|
const align = alignOf(t);
|
||||||
|
const boxW = m.w + m.pad * 2;
|
||||||
|
if (t.bgFill) {
|
||||||
|
const r = Math.min(m.pad + 2, Math.min(boxW, m.h + m.pad * 2) / 2);
|
||||||
|
ctx.globalAlpha = (t.opacity != null ? t.opacity : 1) * (t.bgAlpha == null ? TEXT_DEFAULTS.bgAlpha : t.bgAlpha);
|
||||||
|
ctx.fillStyle = t.bgColor || TEXT_DEFAULTS.bgColor;
|
||||||
|
const bx = t.x, by = t.y;
|
||||||
|
const bw = boxW, bh = m.h + m.pad * 2;
|
||||||
|
ctx.beginPath();
|
||||||
|
if (typeof ctx.roundRect === "function") {
|
||||||
|
ctx.roundRect(bx, by, bw, bh, r);
|
||||||
|
} else {
|
||||||
|
ctx.moveTo(bx + r, by);
|
||||||
|
ctx.arcTo(bx + bw, by, bx + bw, by + bh, r);
|
||||||
|
ctx.arcTo(bx + bw, by + bh, bx, by + bh, r);
|
||||||
|
ctx.arcTo(bx, by + bh, bx, by, r);
|
||||||
|
ctx.arcTo(bx, by, bx + bw, by, r);
|
||||||
|
ctx.closePath();
|
||||||
|
}
|
||||||
|
ctx.fill();
|
||||||
|
ctx.globalAlpha = t.opacity != null ? t.opacity : 1;
|
||||||
|
}
|
||||||
|
ctx.textAlign = align;
|
||||||
|
const left = t.x + m.pad;
|
||||||
|
const ox = align === "center" ? left + m.w / 2 : align === "right" ? left + m.w : left;
|
||||||
|
ctx.lineJoin = "round";
|
||||||
|
ctx.miterLimit = 2;
|
||||||
|
for (let i = 0; i < m.lines.length; i++) {
|
||||||
|
const y = t.y + m.pad + i * m.lh;
|
||||||
|
if (m.sw > 0) {
|
||||||
|
ctx.lineWidth = m.sw;
|
||||||
|
ctx.strokeStyle = t.strokeColor || TEXT_DEFAULTS.strokeColor;
|
||||||
|
ctx.strokeText(m.lines[i], ox, y);
|
||||||
|
}
|
||||||
|
ctx.fillStyle = t.color || TEXT_DEFAULTS.color;
|
||||||
|
ctx.fillText(m.lines[i], ox, y);
|
||||||
|
}
|
||||||
|
ctx.restore();
|
||||||
|
}
|
||||||
|
function newTextStyle(src) {
|
||||||
|
const s = src || {};
|
||||||
|
return {
|
||||||
|
fontWeight: weightOf(s),
|
||||||
|
align: alignOf(s),
|
||||||
|
lineHeight: Number(s.lineHeight) || TEXT_LINE_HEIGHT,
|
||||||
|
strokeWidth: Math.max(0, Number(s.strokeWidth) || 0),
|
||||||
|
strokeColor: s.strokeColor || TEXT_DEFAULTS.strokeColor,
|
||||||
|
bgFill: !!s.bgFill,
|
||||||
|
bgColor: s.bgColor || TEXT_DEFAULTS.bgColor,
|
||||||
|
bgAlpha: s.bgAlpha == null ? TEXT_DEFAULTS.bgAlpha : Number(s.bgAlpha)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
// image-annotate/plugin/editor/state.js
|
// image-annotate/plugin/editor/state.js
|
||||||
var ZOOM_MIN = 0.1;
|
var ZOOM_MIN = 0.1;
|
||||||
var ZOOM_MAX = 10;
|
var ZOOM_MAX = 10;
|
||||||
@@ -65,6 +190,9 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
// 矩形/圆形/箭头/钢笔的描边粗细
|
// 矩形/圆形/箭头/钢笔的描边粗细
|
||||||
shapeRadius: 0,
|
shapeRadius: 0,
|
||||||
// 矩形圆角半径 px(v1.9,仅 rect 有意义)
|
// 矩形圆角半径 px(v1.9,仅 rect 有意义)
|
||||||
|
// v1.10:矢量图形的填充色。null = 跟随描边色(新画的就是「同色实心」,
|
||||||
|
// 换主色时整体跟着变),一旦单独选过填充色就固定下来(每形状自己存 fillColor)。
|
||||||
|
shapeFillColor: null,
|
||||||
textSize: 32,
|
textSize: 32,
|
||||||
// 新建文字的字号 px
|
// 新建文字的字号 px
|
||||||
// ---- v1.9 文字样式:这套是「新建文字」的默认值,每段文字自己存一份 ----
|
// ---- v1.9 文字样式:这套是「新建文字」的默认值,每段文字自己存一份 ----
|
||||||
@@ -74,12 +202,15 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
// left | center | right(多行时各行按块宽对齐)
|
// left | center | right(多行时各行按块宽对齐)
|
||||||
textLineHeight: 1.25,
|
textLineHeight: 1.25,
|
||||||
// 行高倍数(1.25 = 老版单行高度,勿随意改)
|
// 行高倍数(1.25 = 老版单行高度,勿随意改)
|
||||||
textStrokeWidth: 0,
|
textStrokeWidth: TEXT_DEFAULTS.strokeWidth,
|
||||||
// 描边宽度 px,0 = 无描边
|
// 描边宽度 px,0 = 无描边
|
||||||
textStrokeColor: "#ffffff",
|
textStrokeColor: TEXT_DEFAULTS.strokeColor,
|
||||||
textBgFill: false,
|
textBgFill: TEXT_DEFAULTS.bgFill,
|
||||||
// 底色块
|
// 底色块
|
||||||
textBgColor: "#000000",
|
textBgColor: TEXT_DEFAULTS.bgColor,
|
||||||
|
// 中性近黑,不再是纯黑 #000000
|
||||||
|
textBgAlpha: TEXT_DEFAULTS.bgAlpha,
|
||||||
|
// 底色透明度(色块按这个不透明度显示,所见即所得)
|
||||||
// 最近使用颜色(最多 8 个,存 ctx.settings,跨会话保留)
|
// 最近使用颜色(最多 8 个,存 ctx.settings,跨会话保留)
|
||||||
recentColors: [],
|
recentColors: [],
|
||||||
// 图层系统
|
// 图层系统
|
||||||
@@ -662,6 +793,12 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
ctx.arcTo(x, y, x + w, y, rr);
|
ctx.arcTo(x, y, x + w, y, rr);
|
||||||
ctx.closePath();
|
ctx.closePath();
|
||||||
}
|
}
|
||||||
|
function strokeOf(s) {
|
||||||
|
return s && s.color || S.color;
|
||||||
|
}
|
||||||
|
function fillOf(s) {
|
||||||
|
return s && s.fillColor || strokeOf(s);
|
||||||
|
}
|
||||||
function drawShape(ctx, s) {
|
function drawShape(ctx, s) {
|
||||||
ctx.save();
|
ctx.save();
|
||||||
ctx.globalAlpha = s.opacity != null ? s.opacity : 1;
|
ctx.globalAlpha = s.opacity != null ? s.opacity : 1;
|
||||||
@@ -673,7 +810,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
ctx.rotate(rot * Math.PI / 180);
|
ctx.rotate(rot * Math.PI / 180);
|
||||||
ctx.translate(-cx, -cy);
|
ctx.translate(-cx, -cy);
|
||||||
}
|
}
|
||||||
ctx.strokeStyle = s.color;
|
ctx.strokeStyle = strokeOf(s);
|
||||||
ctx.lineWidth = s.lw;
|
ctx.lineWidth = s.lw;
|
||||||
ctx.lineCap = "round";
|
ctx.lineCap = "round";
|
||||||
ctx.lineJoin = "round";
|
ctx.lineJoin = "round";
|
||||||
@@ -685,7 +822,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
for (let i = 1; i < pts.length; i++) ctx.lineTo(pts[i].x, pts[i].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) ctx.closePath();
|
||||||
if (s.closed && s.fill) {
|
if (s.closed && s.fill) {
|
||||||
ctx.fillStyle = s.color;
|
ctx.fillStyle = fillOf(s);
|
||||||
ctx.fill();
|
ctx.fill();
|
||||||
}
|
}
|
||||||
ctx.stroke();
|
ctx.stroke();
|
||||||
@@ -697,13 +834,13 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
ctx.beginPath();
|
ctx.beginPath();
|
||||||
roundRectPath(ctx, rx, ry, rw, rh, radius);
|
roundRectPath(ctx, rx, ry, rw, rh, radius);
|
||||||
if (s.fill) {
|
if (s.fill) {
|
||||||
ctx.fillStyle = s.color;
|
ctx.fillStyle = fillOf(s);
|
||||||
ctx.fill();
|
ctx.fill();
|
||||||
}
|
}
|
||||||
ctx.stroke();
|
ctx.stroke();
|
||||||
} else {
|
} else {
|
||||||
if (s.fill) {
|
if (s.fill) {
|
||||||
ctx.fillStyle = s.color;
|
ctx.fillStyle = fillOf(s);
|
||||||
ctx.fillRect(rx, ry, rw, rh);
|
ctx.fillRect(rx, ry, rw, rh);
|
||||||
}
|
}
|
||||||
ctx.strokeRect(rx, ry, rw, rh);
|
ctx.strokeRect(rx, ry, rw, rh);
|
||||||
@@ -714,12 +851,12 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
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) {
|
if (s.fill) {
|
||||||
ctx.fillStyle = s.color;
|
ctx.fillStyle = fillOf(s);
|
||||||
ctx.fill();
|
ctx.fill();
|
||||||
}
|
}
|
||||||
ctx.stroke();
|
ctx.stroke();
|
||||||
} else {
|
} else {
|
||||||
ctx.fillStyle = s.color;
|
ctx.fillStyle = strokeOf(s);
|
||||||
ctx.beginPath();
|
ctx.beginPath();
|
||||||
ctx.moveTo(s.x1, s.y1);
|
ctx.moveTo(s.x1, s.y1);
|
||||||
ctx.lineTo(s.x2, s.y2);
|
ctx.lineTo(s.x2, s.y2);
|
||||||
@@ -990,123 +1127,6 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
}, 2600);
|
}, 2600);
|
||||||
}
|
}
|
||||||
|
|
||||||
// image-annotate/plugin/editor/text.js
|
|
||||||
var TEXT_LINE_HEIGHT = 1.25;
|
|
||||||
var BG_PAD_RATIO = 0.3;
|
|
||||||
var _measureCtx = null;
|
|
||||||
function measureCtx() {
|
|
||||||
if (!_measureCtx) {
|
|
||||||
const c = document.createElement("canvas");
|
|
||||||
c.width = 8;
|
|
||||||
c.height = 8;
|
|
||||||
_measureCtx = c.getContext("2d");
|
|
||||||
}
|
|
||||||
return _measureCtx;
|
|
||||||
}
|
|
||||||
function weightOf(t) {
|
|
||||||
const w = t && t.fontWeight;
|
|
||||||
return w == null || w === "" ? "bold" : String(w);
|
|
||||||
}
|
|
||||||
function fontOf(t) {
|
|
||||||
const size = Math.max(4, Number(t && t.fontSize) || 32);
|
|
||||||
return weightOf(t) + " " + size + "px sans-serif";
|
|
||||||
}
|
|
||||||
function textMetrics(t) {
|
|
||||||
const ctx = measureCtx();
|
|
||||||
const font = fontOf(t);
|
|
||||||
ctx.font = font;
|
|
||||||
const raw = (t && t.text) == null ? "" : String(t.text);
|
|
||||||
const lines = raw.split("\n");
|
|
||||||
const widths = lines.map((line) => ctx.measureText(line).width);
|
|
||||||
const size = Math.max(4, Number(t && t.fontSize) || 32);
|
|
||||||
const lh = size * (Number(t && t.lineHeight) || TEXT_LINE_HEIGHT);
|
|
||||||
const w = lines.length ? Math.max.apply(null, widths) : 0;
|
|
||||||
const pad = t && t.bgFill ? Math.round(size * BG_PAD_RATIO) : 0;
|
|
||||||
const sw = Math.max(0, Number(t && t.strokeWidth) || 0);
|
|
||||||
return { lines, widths, w, h: lh * lines.length, lh, pad, sw, font, size };
|
|
||||||
}
|
|
||||||
function textBox(t) {
|
|
||||||
const m = textMetrics(t);
|
|
||||||
const half = m.sw / 2;
|
|
||||||
return {
|
|
||||||
x: t.x - half,
|
|
||||||
y: t.y - half,
|
|
||||||
w: Math.max(m.w, 2) + m.pad * 2 + m.sw,
|
|
||||||
h: Math.max(m.h, 1) + m.pad * 2 + m.sw
|
|
||||||
};
|
|
||||||
}
|
|
||||||
function alignOf(t) {
|
|
||||||
const a = t && t.align;
|
|
||||||
return a === "center" || a === "right" ? a : "left";
|
|
||||||
}
|
|
||||||
function drawTextObject(ctx, t) {
|
|
||||||
const m = textMetrics(t);
|
|
||||||
ctx.save();
|
|
||||||
ctx.textBaseline = "top";
|
|
||||||
ctx.globalAlpha = t.opacity != null ? t.opacity : 1;
|
|
||||||
const b = textBox(t);
|
|
||||||
const rot = t.rotation || 0;
|
|
||||||
if (rot) {
|
|
||||||
const cx = b.x + b.w / 2;
|
|
||||||
const cy = b.y + b.h / 2;
|
|
||||||
ctx.translate(cx, cy);
|
|
||||||
ctx.rotate(rot * Math.PI / 180);
|
|
||||||
ctx.translate(-cx, -cy);
|
|
||||||
}
|
|
||||||
ctx.font = m.font;
|
|
||||||
const align = alignOf(t);
|
|
||||||
const boxW = m.w + m.pad * 2;
|
|
||||||
if (t.bgFill) {
|
|
||||||
const r = Math.min(m.pad + 2, Math.min(boxW, m.h + m.pad * 2) / 2);
|
|
||||||
ctx.globalAlpha = (t.opacity != null ? t.opacity : 1) * (t.bgAlpha == null ? 0.68 : t.bgAlpha);
|
|
||||||
ctx.fillStyle = t.bgColor || "#000000";
|
|
||||||
const bx = t.x, by = t.y;
|
|
||||||
const bw = boxW, bh = m.h + m.pad * 2;
|
|
||||||
ctx.beginPath();
|
|
||||||
if (typeof ctx.roundRect === "function") {
|
|
||||||
ctx.roundRect(bx, by, bw, bh, r);
|
|
||||||
} else {
|
|
||||||
ctx.moveTo(bx + r, by);
|
|
||||||
ctx.arcTo(bx + bw, by, bx + bw, by + bh, r);
|
|
||||||
ctx.arcTo(bx + bw, by + bh, bx, by + bh, r);
|
|
||||||
ctx.arcTo(bx, by + bh, bx, by, r);
|
|
||||||
ctx.arcTo(bx, by, bx + bw, by, r);
|
|
||||||
ctx.closePath();
|
|
||||||
}
|
|
||||||
ctx.fill();
|
|
||||||
ctx.globalAlpha = t.opacity != null ? t.opacity : 1;
|
|
||||||
}
|
|
||||||
ctx.textAlign = align;
|
|
||||||
const left = t.x + m.pad;
|
|
||||||
const ox = align === "center" ? left + m.w / 2 : align === "right" ? left + m.w : left;
|
|
||||||
ctx.lineJoin = "round";
|
|
||||||
ctx.miterLimit = 2;
|
|
||||||
for (let i = 0; i < m.lines.length; i++) {
|
|
||||||
const y = t.y + m.pad + i * m.lh;
|
|
||||||
if (m.sw > 0) {
|
|
||||||
ctx.lineWidth = m.sw;
|
|
||||||
ctx.strokeStyle = t.strokeColor || "#ffffff";
|
|
||||||
ctx.strokeText(m.lines[i], ox, y);
|
|
||||||
}
|
|
||||||
ctx.fillStyle = t.color || "#ff4444";
|
|
||||||
ctx.fillText(m.lines[i], ox, y);
|
|
||||||
}
|
|
||||||
ctx.restore();
|
|
||||||
}
|
|
||||||
function newTextStyle(src) {
|
|
||||||
const s = src || {};
|
|
||||||
return {
|
|
||||||
fontWeight: weightOf(s),
|
|
||||||
align: alignOf(s),
|
|
||||||
lineHeight: Number(s.lineHeight) || TEXT_LINE_HEIGHT,
|
|
||||||
strokeWidth: Math.max(0, Number(s.strokeWidth) || 0),
|
|
||||||
strokeColor: s.strokeColor || "#ffffff",
|
|
||||||
bgFill: !!s.bgFill,
|
|
||||||
bgColor: s.bgColor || "#000000",
|
|
||||||
bgAlpha: s.bgAlpha == null ? 0.68 : Number(s.bgAlpha)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// image-annotate/plugin/editor/snap.js
|
// image-annotate/plugin/editor/snap.js
|
||||||
var SNAP_SCREEN_PX = 6;
|
var SNAP_SCREEN_PX = 6;
|
||||||
var GUIDE_COLOR = "#ff2d95";
|
var GUIDE_COLOR = "#ff2d95";
|
||||||
@@ -1548,14 +1568,12 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
octx.save();
|
octx.save();
|
||||||
octx.strokeStyle = "#e8a735";
|
octx.strokeStyle = "#e8a735";
|
||||||
octx.lineWidth = 1.5 / viewScale();
|
octx.lineWidth = 1.5 / viewScale();
|
||||||
octx.setLineDash([6 / viewScale(), 3 / viewScale()]);
|
|
||||||
const corners = boxCorners(b.x, b.y, b.w, b.h, rot);
|
const corners = boxCorners(b.x, b.y, b.w, b.h, rot);
|
||||||
octx.beginPath();
|
octx.beginPath();
|
||||||
octx.moveTo(corners[0][0], corners[0][1]);
|
octx.moveTo(corners[0][0], corners[0][1]);
|
||||||
for (let i = 1; i < corners.length; i++) octx.lineTo(corners[i][0], corners[i][1]);
|
for (let i = 1; i < corners.length; i++) octx.lineTo(corners[i][0], corners[i][1]);
|
||||||
octx.closePath();
|
octx.closePath();
|
||||||
octx.stroke();
|
octx.stroke();
|
||||||
octx.setLineDash([]);
|
|
||||||
const hs = 5.5 / viewScale();
|
const hs = 5.5 / viewScale();
|
||||||
octx.fillStyle = "#ffffff";
|
octx.fillStyle = "#ffffff";
|
||||||
octx.strokeStyle = "#e8a735";
|
octx.strokeStyle = "#e8a735";
|
||||||
@@ -1600,14 +1618,12 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
octx.save();
|
octx.save();
|
||||||
octx.strokeStyle = "#e8a735";
|
octx.strokeStyle = "#e8a735";
|
||||||
octx.lineWidth = 1.5 / viewScale();
|
octx.lineWidth = 1.5 / viewScale();
|
||||||
octx.setLineDash([6 / viewScale(), 3 / viewScale()]);
|
|
||||||
const corners = boxCorners(b.x - 2 / viewScale(), b.y - 2 / viewScale(), b.w + 4 / viewScale(), b.h + 4 / viewScale(), rot);
|
const corners = boxCorners(b.x - 2 / viewScale(), b.y - 2 / viewScale(), b.w + 4 / viewScale(), b.h + 4 / viewScale(), rot);
|
||||||
octx.beginPath();
|
octx.beginPath();
|
||||||
octx.moveTo(corners[0][0], corners[0][1]);
|
octx.moveTo(corners[0][0], corners[0][1]);
|
||||||
for (let i = 1; i < corners.length; i++) octx.lineTo(corners[i][0], corners[i][1]);
|
for (let i = 1; i < corners.length; i++) octx.lineTo(corners[i][0], corners[i][1]);
|
||||||
octx.closePath();
|
octx.closePath();
|
||||||
octx.stroke();
|
octx.stroke();
|
||||||
octx.setLineDash([]);
|
|
||||||
const hs = 5.5 / viewScale();
|
const hs = 5.5 / viewScale();
|
||||||
octx.fillStyle = "#ffffff";
|
octx.fillStyle = "#ffffff";
|
||||||
octx.strokeStyle = "#e8a735";
|
octx.strokeStyle = "#e8a735";
|
||||||
@@ -2030,14 +2046,12 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
ctx.save();
|
ctx.save();
|
||||||
ctx.strokeStyle = "#e8a735";
|
ctx.strokeStyle = "#e8a735";
|
||||||
ctx.lineWidth = 1.5 / viewScale();
|
ctx.lineWidth = 1.5 / viewScale();
|
||||||
ctx.setLineDash([6 / viewScale(), 3 / viewScale()]);
|
|
||||||
const corners = boxCorners(box.x, box.y, box.w, box.h, rot);
|
const corners = boxCorners(box.x, box.y, box.w, box.h, rot);
|
||||||
ctx.beginPath();
|
ctx.beginPath();
|
||||||
ctx.moveTo(corners[0][0], corners[0][1]);
|
ctx.moveTo(corners[0][0], corners[0][1]);
|
||||||
for (let i = 1; i < corners.length; i++) ctx.lineTo(corners[i][0], corners[i][1]);
|
for (let i = 1; i < corners.length; i++) ctx.lineTo(corners[i][0], corners[i][1]);
|
||||||
ctx.closePath();
|
ctx.closePath();
|
||||||
ctx.stroke();
|
ctx.stroke();
|
||||||
ctx.setLineDash([]);
|
|
||||||
ctx.fillStyle = "#fff";
|
ctx.fillStyle = "#fff";
|
||||||
ctx.strokeStyle = "#e8a735";
|
ctx.strokeStyle = "#e8a735";
|
||||||
const pts = frameHandlePoints(box, rot);
|
const pts = frameHandlePoints(box, rot);
|
||||||
@@ -4498,6 +4512,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
x2: pos.x,
|
x2: pos.x,
|
||||||
y2: pos.y,
|
y2: pos.y,
|
||||||
color: S.color,
|
color: S.color,
|
||||||
|
fillColor: S.shapeFillColor,
|
||||||
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,
|
||||||
@@ -4688,6 +4703,8 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
x2: pos.x,
|
x2: pos.x,
|
||||||
y2: pos.y,
|
y2: pos.y,
|
||||||
color: S.color,
|
color: S.color,
|
||||||
|
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,
|
||||||
radius: S.tool === "rect" ? Math.max(0, S.shapeRadius) : 0,
|
radius: S.tool === "rect" ? Math.max(0, S.shapeRadius) : 0,
|
||||||
@@ -4902,11 +4919,22 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
<button type="button" class="iwb-editor-crop-cancel" data-action="cancelCrop" title="Esc">✗ 取消</button>
|
<button type="button" class="iwb-editor-crop-cancel" data-action="cancelCrop" title="Esc">✗ 取消</button>
|
||||||
<span class="iwb-opt-hint">拖出裁剪框;Enter 确认 · Esc 取消;裁剪后可 Ctrl+Z</span>`;
|
<span class="iwb-opt-hint">拖出裁剪框;Enter 确认 · Esc 取消;裁剪后可 Ctrl+Z</span>`;
|
||||||
}
|
}
|
||||||
function fillStyleHTML(owner) {
|
function shapeColorHTML(sh, owner) {
|
||||||
const fill = owner === "pen" ? S.penFill : S.rectFill;
|
const stroke = sh ? sh.color || S.color : S.color;
|
||||||
|
const fillOn = sh ? !!sh.fill : owner === "pen" ? S.penFill : S.rectFill;
|
||||||
|
const fill = sh ? sh.fillColor || sh.color || S.color : S.shapeFillColor || S.color;
|
||||||
|
let html = `<span class="iwb-opt-label">描边</span><input type="color" class="iwb-opt-color" data-shape-color="stroke" value="${stroke}" title="描边颜色(与左侧主色同步,吸管取色也写这里)">`;
|
||||||
|
if (owner) {
|
||||||
|
html += `<span class="iwb-opt-label">填充</span><input type="color" class="iwb-opt-color${fillOn ? "" : " is-off"}" data-shape-color="fill" data-fill-owner="${owner}" value="${fill}" title="填充颜色${fillOn ? "" : ";当前是描边模式,选色会自动切成实心"}">`;
|
||||||
|
}
|
||||||
|
return html;
|
||||||
|
}
|
||||||
|
function fillStyleHTML(owner, sh) {
|
||||||
|
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>
|
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="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="fill" data-fill-owner="${owner}" data-value="fill" title="实心填充 (Shift+X 切换)">实心</button>`;
|
||||||
}
|
}
|
||||||
var SHAPE_NAMES = { rect: "矩形", circle: "圆形", arrow: "箭头", pen: "钢笔路径" };
|
var SHAPE_NAMES = { rect: "矩形", circle: "圆形", arrow: "箭头", pen: "钢笔路径" };
|
||||||
var TEXT_STYLE_STATE_KEY = {
|
var TEXT_STYLE_STATE_KEY = {
|
||||||
@@ -4926,11 +4954,12 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
return {
|
return {
|
||||||
fontWeight: String(pick("fontWeight", "textWeight", "bold")),
|
fontWeight: String(pick("fontWeight", "textWeight", "bold")),
|
||||||
align: pick("align", "textAlign", "left"),
|
align: pick("align", "textAlign", "left"),
|
||||||
lineHeight: Number(pick("lineHeight", "textLineHeight", 1.25)) || 1.25,
|
lineHeight: Number(pick("lineHeight", "textLineHeight", TEXT_LINE_HEIGHT)) || TEXT_LINE_HEIGHT,
|
||||||
strokeWidth: Math.max(0, Number(pick("strokeWidth", "textStrokeWidth", 0)) || 0),
|
strokeWidth: Math.max(0, Number(pick("strokeWidth", "textStrokeWidth", TEXT_DEFAULTS.strokeWidth)) || 0),
|
||||||
strokeColor: pick("strokeColor", "textStrokeColor", "#ffffff"),
|
strokeColor: pick("strokeColor", "textStrokeColor", TEXT_DEFAULTS.strokeColor),
|
||||||
bgFill: !!pick("bgFill", "textBgFill", false),
|
bgFill: !!pick("bgFill", "textBgFill", TEXT_DEFAULTS.bgFill),
|
||||||
bgColor: pick("bgColor", "textBgColor", "#000000")
|
bgColor: pick("bgColor", "textBgColor", TEXT_DEFAULTS.bgColor),
|
||||||
|
bgAlpha: Number(pick("bgAlpha", "textBgAlpha", TEXT_DEFAULTS.bgAlpha)) || TEXT_DEFAULTS.bgAlpha
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
function textStyleHTML(t) {
|
function textStyleHTML(t) {
|
||||||
@@ -4945,9 +4974,9 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
<span class="iwb-opt-sep"></span>
|
<span class="iwb-opt-sep"></span>
|
||||||
<span class="iwb-opt-label">描边</span>
|
<span class="iwb-opt-label">描边</span>
|
||||||
<input type="number" class="iwb-opt-num" data-opt="textStrokeWidth" min="0" max="40" step="1" value="${Math.round(v.strokeWidth)}"><span class="iwb-opt-unit">px</span>
|
<input type="number" class="iwb-opt-num" data-opt="textStrokeWidth" min="0" max="40" step="1" value="${Math.round(v.strokeWidth)}"><span class="iwb-opt-unit">px</span>
|
||||||
<input type="color" class="iwb-opt-color" data-opt-color="strokeColor" value="${v.strokeColor}" title="描边颜色">
|
<input type="color" class="iwb-opt-color${v.strokeWidth > 0 ? "" : " is-off"}" data-opt-color="strokeColor" value="${v.strokeColor}" title="描边颜色${v.strokeWidth > 0 ? "" : ";描边宽度是 0,选色会自动给 6px"}">
|
||||||
<button class="iwb-opt-btn${v.bgFill ? " active" : ""}" data-opt-text="bgFill" data-value="${v.bgFill ? "0" : "1"}" title="给文字加一块半透明底色,压在花背景上也能看清">底色</button>
|
<button class="iwb-opt-btn${v.bgFill ? " active" : ""}" data-opt-text="bgFill" data-value="${v.bgFill ? "0" : "1"}" title="给文字加一块底色,压在花背景上也能看清">底色</button>
|
||||||
<input type="color" class="iwb-opt-color" data-opt-color="bgColor" value="${v.bgColor}" title="底色颜色;选色会自动开启底色,不用先点左侧按钮">`;
|
<input type="color" class="iwb-opt-color${v.bgFill ? "" : " is-off"}" data-opt-color="bgColor" value="${v.bgColor}" style="--sw-a:${v.bgAlpha}" title="底色 ${Math.round(v.bgAlpha * 100)}% 不透明(色块按真实半透明显示);选色会自动开启底色">`;
|
||||||
}
|
}
|
||||||
var SELCMD_SVGS = {
|
var SELCMD_SVGS = {
|
||||||
all: '<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" stroke-dasharray="3 2"><rect x="3.5" y="3.5" width="17" height="17" rx="1"/></svg>',
|
all: '<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" stroke-dasharray="3 2"><rect x="3.5" y="3.5" width="17" height="17" rx="1"/></svg>',
|
||||||
@@ -4965,12 +4994,12 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
if (t === "rect" || t === "circle" || t === "pen" || t === "arrow") {
|
if (t === "rect" || t === "circle" || t === "pen" || t === "arrow") {
|
||||||
const owner = t === "pen" ? "pen" : "rect";
|
const owner = t === "pen" ? "pen" : "rect";
|
||||||
const lw = Math.max(1, Math.round(sh.lw || S.shapeLineWidth));
|
const lw = Math.max(1, Math.round(sh.lw || S.shapeLineWidth));
|
||||||
return `<span class="iwb-opt-current">已选中:${SHAPE_NAMES[t] || t}</span>` + rangeOpt("shapeLineWidth", "线宽", 1, 60, lw, "") + presetDots("shapeLineWidth", [1, 2, 3, 6, 10, 16, 24]) + (t === "rect" ? rangeOpt("shapeRadius", "圆角", 0, 200, Math.round(sh.radius || 0), "px") : "") + (t === "arrow" ? "" : fillStyleHTML(owner)) + (t === "pen" && !sh.closed ? '<span class="iwb-opt-hint">这条钢笔路径未闭合,实心不生效;点回起点闭合后即可填充</span>' : "") + selCmdHTML();
|
return `<span class="iwb-opt-current">已选中:${SHAPE_NAMES[t] || t}</span>` + rangeOpt("shapeLineWidth", "线宽", 1, 60, lw, "") + presetDots("shapeLineWidth", [1, 2, 3, 6, 10, 16, 24]) + (t === "rect" ? rangeOpt("shapeRadius", "圆角", 0, 200, Math.round(sh.radius || 0), "px") : "") + shapeColorHTML(sh, t === "arrow" ? null : owner) + (t === "arrow" ? "" : fillStyleHTML(owner, sh)) + (t === "pen" && !sh.closed ? '<span class="iwb-opt-hint">这条钢笔路径未闭合,实心不生效;点回起点闭合后即可填充</span>' : "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const text = getSelectedText();
|
const text = getSelectedText();
|
||||||
if (text) {
|
if (text) {
|
||||||
return `<span class="iwb-opt-current">已选中:文字</span>` + rangeOpt("textSize", "字号", 8, 400, Math.round(text.fontSize || S.textSize), "px") + textStyleHTML(text) + selCmdHTML() + '<span class="iwb-opt-hint">双击改内容 · 拖动手柄缩放</span>';
|
return `<span class="iwb-opt-current">已选中:文字</span>` + rangeOpt("textSize", "字号", 8, 400, Math.round(text.fontSize || S.textSize), "px") + textStyleHTML(text) + '<span class="iwb-opt-hint">双击改内容 · 拖动手柄缩放</span>';
|
||||||
}
|
}
|
||||||
return `<span class="iwb-opt-current">当前工具:选择 / 移动</span>` + selCmdHTML() + '<span class="iwb-opt-hint">点中矩形/圆形/钢笔/文字后,这里出现它的描边、实心与粗细</span>';
|
return `<span class="iwb-opt-current">当前工具:选择 / 移动</span>` + selCmdHTML() + '<span class="iwb-opt-hint">点中矩形/圆形/钢笔/文字后,这里出现它的描边、实心与粗细</span>';
|
||||||
}
|
}
|
||||||
@@ -4986,13 +5015,13 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
<span class="iwb-opt-val" data-opt-val="brushOpacity">${Math.round(S.brushOpacity * 100)}%</span>` + presetDots("brushHardness", [0, 25, 50, 75, 100]);
|
<span class="iwb-opt-val" data-opt-val="brushOpacity">${Math.round(S.brushOpacity * 100)}%</span>` + presetDots("brushHardness", [0, 25, 50, 75, 100]);
|
||||||
}
|
}
|
||||||
if (tool === "rect" || tool === "circle") {
|
if (tool === "rect" || tool === "circle") {
|
||||||
return rangeOpt("shapeLineWidth", "线宽", 1, 60, S.shapeLineWidth, "") + presetDots("shapeLineWidth", [1, 2, 3, 6, 10, 16, 24]) + (tool === "rect" ? rangeOpt("shapeRadius", "圆角", 0, 200, S.shapeRadius, "px") : "") + fillStyleHTML("rect");
|
return rangeOpt("shapeLineWidth", "线宽", 1, 60, S.shapeLineWidth, "") + presetDots("shapeLineWidth", [1, 2, 3, 6, 10, 16, 24]) + (tool === "rect" ? rangeOpt("shapeRadius", "圆角", 0, 200, S.shapeRadius, "px") : "") + shapeColorHTML(null, "rect") + fillStyleHTML("rect");
|
||||||
}
|
}
|
||||||
if (tool === "arrow") {
|
if (tool === "arrow") {
|
||||||
return rangeOpt("shapeLineWidth", "线宽", 1, 60, S.shapeLineWidth, "") + presetDots("shapeLineWidth", [1, 2, 3, 6, 10, 16, 24]) + '<span class="iwb-opt-hint">拖出箭头,松手完成</span>';
|
return rangeOpt("shapeLineWidth", "线宽", 1, 60, S.shapeLineWidth, "") + presetDots("shapeLineWidth", [1, 2, 3, 6, 10, 16, 24]) + shapeColorHTML(null, null) + '<span class="iwb-opt-hint">拖出箭头,松手完成</span>';
|
||||||
}
|
}
|
||||||
if (tool === "pen") {
|
if (tool === "pen") {
|
||||||
return rangeOpt("shapeLineWidth", "线宽", 1, 60, S.shapeLineWidth, "") + presetDots("shapeLineWidth", [1, 2, 3, 6, 10, 16, 24]) + fillStyleHTML("pen") + '<span class="iwb-opt-hint">逐点点击,点回起点闭合;闭合后可切换描边/实心</span>';
|
return rangeOpt("shapeLineWidth", "线宽", 1, 60, S.shapeLineWidth, "") + presetDots("shapeLineWidth", [1, 2, 3, 6, 10, 16, 24]) + shapeColorHTML(null, "pen") + fillStyleHTML("pen") + '<span class="iwb-opt-hint">逐点点击,点回起点闭合;闭合后可切换描边/实心</span>';
|
||||||
}
|
}
|
||||||
if (tool === "text") {
|
if (tool === "text") {
|
||||||
return rangeOpt("textSize", "字号", 8, 400, S.textSize, "px") + textStyleHTML(null) + '<span class="iwb-opt-hint">点画布输入文字,Enter 确认,Shift+Enter 换行</span>';
|
return rangeOpt("textSize", "字号", 8, 400, S.textSize, "px") + textStyleHTML(null) + '<span class="iwb-opt-hint">点画布输入文字,Enter 确认,Shift+Enter 换行</span>';
|
||||||
@@ -5001,12 +5030,10 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
return `<span class="iwb-opt-label">形状</span>
|
return `<span class="iwb-opt-label">形状</span>
|
||||||
<button class="iwb-opt-btn${S.selectionKind === "rect" ? " active" : ""}" data-opt="shape" data-value="rect">矩形</button>
|
<button class="iwb-opt-btn${S.selectionKind === "rect" ? " active" : ""}" data-opt="shape" data-value="rect">矩形</button>
|
||||||
<button class="iwb-opt-btn${S.selectionKind === "ellipse" ? " active" : ""}" data-opt="shape" data-value="ellipse">椭圆</button>
|
<button class="iwb-opt-btn${S.selectionKind === "ellipse" ? " active" : ""}" data-opt="shape" data-value="ellipse">椭圆</button>
|
||||||
<label class="iwb-opt-label">羽化 <input type="number" class="iwb-opt-num" data-opt="feather" min="0" max="20" step="1" value="${S.selectionFeather}"> px</label>
|
<label class="iwb-opt-label">羽化 <input type="number" class="iwb-opt-num" data-opt="feather" min="0" max="20" step="1" value="${S.selectionFeather}"> px</label>` + selCmdHTML() + `<span class="iwb-opt-hint">${OPT_HINTS.marquee}</span>`;
|
||||||
<span class="iwb-opt-hint">${OPT_HINTS.marquee}</span>`;
|
|
||||||
}
|
}
|
||||||
if (tool === "lasso") {
|
if (tool === "lasso") {
|
||||||
return `<span class="iwb-opt-label">羽化 <input type="number" class="iwb-opt-num" data-opt="feather" min="0" max="20" step="1" value="${S.selectionFeather}"> px</span>
|
return `<span class="iwb-opt-label">羽化 <input type="number" class="iwb-opt-num" data-opt="feather" min="0" max="20" step="1" value="${S.selectionFeather}"> px</span>` + selCmdHTML() + `<span class="iwb-opt-hint">${OPT_HINTS.lasso}</span>`;
|
||||||
<span class="iwb-opt-hint">${OPT_HINTS.lasso}</span>`;
|
|
||||||
}
|
}
|
||||||
return `<span class="iwb-opt-current">当前工具:${TOOL_NAMES[tool] || tool}</span>
|
return `<span class="iwb-opt-current">当前工具:${TOOL_NAMES[tool] || tool}</span>
|
||||||
<span class="iwb-opt-hint">${OPT_HINTS[tool] || "选区工具按 M / L;Ctrl+J 复制选区,Delete 清除当前层"}</span>`;
|
<span class="iwb-opt-hint">${OPT_HINTS[tool] || "选区工具按 M / L;Ctrl+J 复制选区,Delete 清除当前层"}</span>`;
|
||||||
@@ -5073,9 +5100,25 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
btn.classList.toggle("active", String(sv[k]) === btn.dataset.value);
|
btn.classList.toggle("active", String(sv[k]) === btn.dataset.value);
|
||||||
});
|
});
|
||||||
body.querySelectorAll("[data-opt-color]").forEach((inp) => {
|
body.querySelectorAll("[data-opt-color]").forEach((inp) => {
|
||||||
if (document.activeElement === inp) return;
|
const k = inp.dataset.optColor;
|
||||||
const v = sv[inp.dataset.optColor];
|
if (document.activeElement !== inp) {
|
||||||
if (v && String(inp.value).toLowerCase() !== String(v).toLowerCase()) inp.value = v;
|
const v = sv[k];
|
||||||
|
if (v && String(inp.value).toLowerCase() !== String(v).toLowerCase()) inp.value = v;
|
||||||
|
}
|
||||||
|
if (k === "strokeColor") inp.classList.toggle("is-off", !(sv.strokeWidth > 0));
|
||||||
|
if (k === "bgColor") inp.classList.toggle("is-off", !sv.bgFill);
|
||||||
|
});
|
||||||
|
body.querySelectorAll("[data-shape-color]").forEach((inp) => {
|
||||||
|
const kind = inp.dataset.shapeColor;
|
||||||
|
const owner = inp.dataset.fillOwner === "pen" ? "pen" : "rect";
|
||||||
|
const stroke = selShape ? selShape.color || S.color : S.color;
|
||||||
|
const fill = selShape ? selShape.fillColor || selShape.color || S.color : S.shapeFillColor || S.color;
|
||||||
|
const v = kind === "fill" ? fill : stroke;
|
||||||
|
if (document.activeElement !== inp && v && String(inp.value).toLowerCase() !== String(v).toLowerCase()) inp.value = v;
|
||||||
|
if (kind === "fill") {
|
||||||
|
const on = selShape ? !!selShape.fill : owner === "pen" ? S.penFill : S.rectFill;
|
||||||
|
inp.classList.toggle("is-off", !on);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function updateStatusbar() {
|
function updateStatusbar() {
|
||||||
@@ -5132,12 +5175,15 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
if (key === "bgFill") value = raw === true || raw === 1 || raw === "1" || raw === "true";
|
if (key === "bgFill") value = raw === true || raw === 1 || raw === "1" || raw === "true";
|
||||||
else if (key === "lineHeight") value = clamp(Number(raw) || 125, 80, 300) / 100;
|
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 === "strokeWidth") value = clamp(Number(raw) || 0, 0, 40);
|
||||||
else if (key === "strokeColor" || key === "bgColor") value = String(raw || "#000000").toLowerCase();
|
else if (key === "strokeColor" || key === "bgColor") value = String(raw || TEXT_DEFAULTS.bgColor).toLowerCase();
|
||||||
else value = String(raw);
|
else value = String(raw);
|
||||||
S[stateKey] = value;
|
S[stateKey] = value;
|
||||||
|
if (key === "strokeColor" && !(Number(S.textStrokeWidth) > 0)) S.textStrokeWidth = 6;
|
||||||
|
if (key === "bgColor" && !S.textBgFill) S.textBgFill = true;
|
||||||
const t = getSelectedText();
|
const t = getSelectedText();
|
||||||
if (!t || t.locked) {
|
if (!t || t.locked) {
|
||||||
textStyleSnapDone = false;
|
textStyleSnapDone = false;
|
||||||
|
syncOptionBar();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (committed || !textStyleSnapDone) {
|
if (committed || !textStyleSnapDone) {
|
||||||
@@ -5145,12 +5191,10 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
textStyleSnapDone = true;
|
textStyleSnapDone = true;
|
||||||
}
|
}
|
||||||
t[key] = value;
|
t[key] = value;
|
||||||
if (key === "bgColor" && !t.bgFill) {
|
if (key === "strokeColor" && !(Number(t.strokeWidth) > 0)) t.strokeWidth = S.textStrokeWidth;
|
||||||
t.bgFill = true;
|
if (key === "bgColor" && !t.bgFill) t.bgFill = true;
|
||||||
S.textBgFill = true;
|
|
||||||
}
|
|
||||||
renderObjects();
|
renderObjects();
|
||||||
if (key === "bgColor") syncOptionBar();
|
if (key === "bgColor" || key === "strokeColor") syncOptionBar();
|
||||||
if (committed) textStyleSnapDone = false;
|
if (committed) textStyleSnapDone = false;
|
||||||
}
|
}
|
||||||
var radiusSnapDone = false;
|
var radiusSnapDone = false;
|
||||||
@@ -5168,6 +5212,29 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
renderObjects();
|
renderObjects();
|
||||||
if (committed) radiusSnapDone = false;
|
if (committed) radiusSnapDone = false;
|
||||||
}
|
}
|
||||||
|
function applyShapeColor(kind, raw) {
|
||||||
|
const hex = String(raw || "").toLowerCase();
|
||||||
|
if (!/^#[0-9a-f]{6}$/.test(hex)) return;
|
||||||
|
if (kind === "stroke") {
|
||||||
|
applyColorChange(hex);
|
||||||
|
syncOptionBar();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
S.shapeFillColor = hex;
|
||||||
|
rememberColor(hex);
|
||||||
|
const sh = getSelectedShape();
|
||||||
|
const owner = sh ? sh.type === "pen" ? "pen" : "rect" : S.tool === "pen" ? "pen" : "rect";
|
||||||
|
if (owner === "pen") S.penFill = true;
|
||||||
|
else S.rectFill = true;
|
||||||
|
updateFillUI();
|
||||||
|
if (sh && !sh.locked) {
|
||||||
|
saveSnapshot("填充颜色");
|
||||||
|
sh.fillColor = hex;
|
||||||
|
sh.fill = owner === "pen" ? !!sh.closed : true;
|
||||||
|
renderObjects();
|
||||||
|
}
|
||||||
|
syncOptionBar();
|
||||||
|
}
|
||||||
function setShapeFill(fill, owner) {
|
function setShapeFill(fill, owner) {
|
||||||
const isPen = owner === "pen";
|
const isPen = owner === "pen";
|
||||||
if (isPen) S.penFill = !!fill;
|
if (isPen) S.penFill = !!fill;
|
||||||
@@ -5293,6 +5360,12 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
syncOptionBar();
|
syncOptionBar();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const shapeColorEl = e.target.closest ? e.target.closest("[data-shape-color]") : null;
|
||||||
|
if (shapeColorEl) {
|
||||||
|
e.stopPropagation();
|
||||||
|
applyShapeColor(shapeColorEl.dataset.shapeColor, shapeColorEl.value);
|
||||||
|
return;
|
||||||
|
}
|
||||||
setOptionFromControl(e.target, true);
|
setOptionFromControl(e.target, true);
|
||||||
});
|
});
|
||||||
body.addEventListener("click", (e) => {
|
body.addEventListener("click", (e) => {
|
||||||
@@ -5746,7 +5819,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, 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, 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();
|
||||||
@@ -7715,7 +7788,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, 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, 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,
|
||||||
@@ -7746,8 +7819,11 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
strokeWidth: S.textStrokeWidth,
|
strokeWidth: S.textStrokeWidth,
|
||||||
strokeColor: S.textStrokeColor,
|
strokeColor: S.textStrokeColor,
|
||||||
bgFill: S.textBgFill,
|
bgFill: S.textBgFill,
|
||||||
bgColor: S.textBgColor
|
bgColor: S.textBgColor,
|
||||||
|
bgAlpha: S.textBgAlpha
|
||||||
},
|
},
|
||||||
|
// 矢量图形颜色:fillColor=null 表示跟随描边色(回归要能断言这条语义)
|
||||||
|
shapeColors: { stroke: S.color, fill: S.shapeFillColor || null },
|
||||||
selectedShapeId: S.selectedShapeId,
|
selectedShapeId: S.selectedShapeId,
|
||||||
// 光标所在的图片坐标(状态栏同源):换算问题的第一现场证据
|
// 光标所在的图片坐标(状态栏同源):换算问题的第一现场证据
|
||||||
lastPos: S.lastPos ? { x: Math.round(S.lastPos.x), y: Math.round(S.lastPos.y) } : null,
|
lastPos: S.lastPos ? { x: Math.round(S.lastPos.x), y: Math.round(S.lastPos.y) } : null,
|
||||||
@@ -7847,7 +7923,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// image-annotate/plugin/editor.css
|
// 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
|
// image-annotate/plugin/glue.js
|
||||||
function createGlue(ctx, css) {
|
function createGlue(ctx, css) {
|
||||||
|
|||||||
@@ -1724,13 +1724,15 @@ check('文字支持多行(Shift+Enter 换行,包围盒高 ≈ 两行)',
|
|||||||
// 选择工具在「未选中任何元素」时也必须露出全选/反选/取消三个图标,且只能有一组。
|
// 选择工具在「未选中任何元素」时也必须露出全选/反选/取消三个图标,且只能有一组。
|
||||||
// 它们曾被排在 margin-left:auto 的 hint 之后,被一路推到最右、滚出可视区,
|
// 它们曾被排在 margin-left:auto 的 hint 之后,被一路推到最右、滚出可视区,
|
||||||
// 表现就是「文字工具下有这三个按钮,切到选择工具就没了」。
|
// 表现就是「文字工具下有这三个按钮,切到选择工具就没了」。
|
||||||
|
// 清选中用「切到别的工具再切回来」:画布上早就有别的用例留下的图形,
|
||||||
|
// 靠「点空白」清选中会点到它们(点位随用例顺序变化,很容易变成假失败)。
|
||||||
|
await page.locator('.iwb-editor-tool[data-tool="brush"]').click()
|
||||||
|
await page.waitForTimeout(120)
|
||||||
await page.locator('.iwb-editor-tool[data-tool="select"]').click()
|
await page.locator('.iwb-editor-tool[data-tool="select"]').click()
|
||||||
const blankPt = await imgToScreen(60, 90)
|
|
||||||
await page.mouse.click(blankPt.x, blankPt.y)
|
|
||||||
await page.waitForTimeout(220)
|
await page.waitForTimeout(220)
|
||||||
const selIconNoSel = await page.locator('.iwb-editor-optionbar-body .iwb-opt-selcmd').count()
|
const selIconNoSel = await page.locator('.iwb-editor-optionbar-body .iwb-opt-selcmd').count()
|
||||||
check('选择工具未选中元素时仍有全选/反选/取消三个图标(且不重复)',
|
check('选择工具未选中元素时仍有全选/反选/取消三个图标(且不重复)',
|
||||||
selIconNoSel === 3, 'count=' + selIconNoSel)
|
selIconNoSel === 3, 'count=' + selIconNoSel + ' 选中=' + (await dbg()).selectedShapeId)
|
||||||
|
|
||||||
await page.locator('.iwb-editor-tool[data-tool="select"]').click()
|
await page.locator('.iwb-editor-tool[data-tool="select"]').click()
|
||||||
p0 = await imgToScreen(10, 12)
|
p0 = await imgToScreen(10, 12)
|
||||||
@@ -1802,6 +1804,83 @@ check('只选底色颜色就自动开启底色(不必先点开关)',
|
|||||||
'关前=' + bgOff + ' 改色后 bgFill=' + vdbg.texts[0].bgFill +
|
'关前=' + bgOff + ' 改色后 bgFill=' + vdbg.texts[0].bgFill +
|
||||||
' bgColor=' + vdbg.texts[0].bgColor + ' 按钮 active=' + bgBtnOn)
|
' bgColor=' + vdbg.texts[0].bgColor + ' 按钮 active=' + bgBtnOn)
|
||||||
|
|
||||||
|
// ---- v1.10:三个色块的「生效 / 未生效」语义 ----
|
||||||
|
// 用户反馈「字体颜色有 3 个位置,那个黑色应该换成默认的参数」:底色默认曾是纯黑 #000000,
|
||||||
|
// 关闭时也显示成一块死黑,看起来就像「又多了一个字体颜色」。现在默认值单点定义,
|
||||||
|
// 且没生效的色块显示为灰色斜纹(不再显示颜色本身),语义变成「这里还没有颜色」。
|
||||||
|
const colorMeta = await page.evaluate(() => {
|
||||||
|
const body = document.querySelector('.iwb-editor-optionbar-body')
|
||||||
|
const out = {}
|
||||||
|
body.querySelectorAll('[data-opt-color]').forEach(el => {
|
||||||
|
out[el.dataset.optColor] = { off: el.classList.contains('is-off'), value: el.value }
|
||||||
|
})
|
||||||
|
return { defaults: window.__iwbEditor.__debug().textDefaults, swatches: out }
|
||||||
|
})
|
||||||
|
check('文字底色默认不再是纯黑(默认值收口到 text.js,近黑 #101014 + 68% 透明)',
|
||||||
|
colorMeta.defaults.bgColor !== '#000000' && /^#[0-9a-f]{6}$/.test(colorMeta.defaults.bgColor) &&
|
||||||
|
Math.abs(colorMeta.defaults.bgAlpha - 0.68) < 1e-6,
|
||||||
|
JSON.stringify(colorMeta.defaults))
|
||||||
|
|
||||||
|
// 关掉底色 + 描边宽度归零 → 两个色块都应变成「未启用」
|
||||||
|
await page.locator('.iwb-editor-optionbar-body [data-opt-text="bgFill"]').click()
|
||||||
|
await page.evaluate(() => {
|
||||||
|
const el = document.querySelector('.iwb-editor-optionbar-body input[data-opt="textStrokeWidth"]')
|
||||||
|
el.value = '0'
|
||||||
|
el.dispatchEvent(new Event('input', { bubbles: true }))
|
||||||
|
el.dispatchEvent(new Event('change', { bubbles: true }))
|
||||||
|
})
|
||||||
|
await page.waitForTimeout(200)
|
||||||
|
const offStates = await page.evaluate(() => [...document.querySelectorAll('.iwb-editor-optionbar-body [data-opt-color]')]
|
||||||
|
.map(el => ({ k: el.dataset.optColor, off: el.classList.contains('is-off') })))
|
||||||
|
check('描边宽度为 0 / 底色关闭时,对应色块标记为「未启用」(不再显示颜色本身)',
|
||||||
|
offStates.length === 2 && offStates.every(o => o.off), JSON.stringify(offStates))
|
||||||
|
|
||||||
|
// 选区命令(全选/反选/取消)属于像素选区,必须待在选区工具里
|
||||||
|
await page.locator('.iwb-editor-tool[data-tool="marquee"]').click()
|
||||||
|
await page.waitForTimeout(160)
|
||||||
|
const marqueeIcons = await page.locator('.iwb-editor-optionbar-body .iwb-opt-selcmd').count()
|
||||||
|
await page.locator('.iwb-editor-tool[data-tool="lasso"]').click()
|
||||||
|
await page.waitForTimeout(160)
|
||||||
|
const lassoIcons = await page.locator('.iwb-editor-optionbar-body .iwb-opt-selcmd').count()
|
||||||
|
check('选区工具(矩形 / 套索)都有全选、反选、取消选区三个按钮',
|
||||||
|
marqueeIcons === 3 && lassoIcons === 3, 'marquee=' + marqueeIcons + ' lasso=' + lassoIcons)
|
||||||
|
|
||||||
|
await page.locator('.iwb-editor-tool[data-tool="select"]').click()
|
||||||
|
p0 = await imgToScreen(10, 12)
|
||||||
|
await page.mouse.click(p0.x, p0.y)
|
||||||
|
await page.waitForTimeout(220)
|
||||||
|
const textSelIcons = await page.locator('.iwb-editor-optionbar-body .iwb-opt-selcmd').count()
|
||||||
|
check('选中文字时选项栏不再冒出选区命令按钮(那三个命令跟文字对象无关)',
|
||||||
|
textSelIcons === 0, 'count=' + textSelIcons)
|
||||||
|
|
||||||
|
// 选中框必须是实线:虚线圈会被当成「莫名其妙多出来的像素选区」。
|
||||||
|
// 沿选中框顶边扫一行橙色像素,虚线(6/3)覆盖率约 0.6~0.7,实线接近 1。
|
||||||
|
const frameCoverage = await page.evaluate(() => {
|
||||||
|
const d = window.__iwbEditor.__debug()
|
||||||
|
const cv = document.querySelector('.iwb-editor-crop-overlay')
|
||||||
|
if (!d.selectedTextId) return { err: 'no-selected-text' }
|
||||||
|
if (!cv) return { err: 'no-overlay' }
|
||||||
|
const ctx = cv.getContext('2d')
|
||||||
|
const img = ctx.getImageData(0, 0, cv.width, cv.height).data
|
||||||
|
const W = cv.width
|
||||||
|
// 不按图片坐标换算:overlay 画布含 overlayPad 外扩,直接全画布扫,
|
||||||
|
// 找第一条「橙色连续段」,再量这一段的覆盖率 —— 实线接近 1,6/3 虚线约 0.6~0.7。
|
||||||
|
const isOrange = (i) => img[i + 3] > 60 && img[i] > 170 && img[i + 1] > 100 && img[i + 2] < 130
|
||||||
|
for (let y = 0; y < cv.height; y++) {
|
||||||
|
const base = y * W * 4
|
||||||
|
let first = -1, last = -1, n = 0
|
||||||
|
for (let x = 0; x < W; x++) {
|
||||||
|
if (isOrange(base + x * 4)) { if (first < 0) first = x; last = x; n++ }
|
||||||
|
}
|
||||||
|
if (n >= 20 && last - first >= 40) {
|
||||||
|
return { ratio: +(n / (last - first + 1)).toFixed(2), n, span: last - first + 1, y }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return { err: 'no-orange-row' }
|
||||||
|
})
|
||||||
|
check('对象选中框是实线(虚线的语义是像素选区,会把用户绕晕)',
|
||||||
|
!!frameCoverage && frameCoverage.ratio >= 0.85, JSON.stringify(frameCoverage))
|
||||||
|
|
||||||
// 吸附:画一个实心矩形,拖到画布中心附近应被精确吸到中心并出现参考线
|
// 吸附:画一个实心矩形,拖到画布中心附近应被精确吸到中心并出现参考线
|
||||||
await page.locator('.iwb-editor-tool[data-tool="rect"]').click()
|
await page.locator('.iwb-editor-tool[data-tool="rect"]').click()
|
||||||
await page.waitForTimeout(100)
|
await page.waitForTimeout(100)
|
||||||
@@ -1942,6 +2021,89 @@ check('选过的颜色进入「最近使用」并出现在色板弹层',
|
|||||||
|
|
||||||
// 复制到剪贴板:harness 跑在 about:blank(非安全上下文),
|
// 复制到剪贴板:harness 跑在 about:blank(非安全上下文),
|
||||||
// 这里只验「按钮存在 + 点击有明确反馈 + 不抛错」,真安全上下文由本地 http 探针覆盖
|
// 这里只验「按钮存在 + 点击有明确反馈 + 不抛错」,真安全上下文由本地 http 探针覆盖
|
||||||
|
// ---- v1.10:矢量图形也有描边色 / 填充色 ----
|
||||||
|
// 用户要求「把其他的矢量图形也加上描边与填充色属性,工具栏上加描边色设置」。
|
||||||
|
// 设计:描边色 = 主色(左侧色板 / 吸管 / 选项栏一个真相源),填充色独立存形状的
|
||||||
|
// fillColor,没单独设过就跟随描边色 —— 于是「切实心 = 同色实心」,不会突兀。
|
||||||
|
await page.locator('.iwb-editor-tool[data-tool="rect"]').click()
|
||||||
|
await page.waitForTimeout(120)
|
||||||
|
const shapeColorUI = await page.evaluate(() => {
|
||||||
|
const body = document.querySelector('.iwb-editor-optionbar-body')
|
||||||
|
return {
|
||||||
|
stroke: body.querySelectorAll('[data-shape-color="stroke"]').length,
|
||||||
|
fill: body.querySelectorAll('[data-shape-color="fill"]').length
|
||||||
|
}
|
||||||
|
})
|
||||||
|
check('矩形工具的选项栏就带描边色 / 填充色块(画之前就能定色)',
|
||||||
|
shapeColorUI.stroke === 1 && shapeColorUI.fill === 1, JSON.stringify(shapeColorUI))
|
||||||
|
|
||||||
|
pa = await imgToScreen(62, 6)
|
||||||
|
pb = await imgToScreen(90, 28)
|
||||||
|
await page.mouse.move(pa.x, pa.y)
|
||||||
|
await page.mouse.down()
|
||||||
|
await page.mouse.move(pb.x, pb.y, { steps: 6 })
|
||||||
|
await page.mouse.up()
|
||||||
|
await page.waitForTimeout(300)
|
||||||
|
const shapeFresh = await page.evaluate(() => {
|
||||||
|
const d = window.__iwbEditor.__debug()
|
||||||
|
return d.shapes[d.shapes.length - 1]
|
||||||
|
})
|
||||||
|
check('新建图形的填充默认「跟随描边色」(fillColor=null),不是写死某个填充色',
|
||||||
|
shapeFresh.fillColor === null, JSON.stringify({ fill: shapeFresh.fill, fillColor: shapeFresh.fillColor }))
|
||||||
|
|
||||||
|
// 数「目标颜色」的像素:矢量画布含 overlayPad 外扩,按图片坐标换算单点会采到别处,
|
||||||
|
// 直接全画布统计同色像素最稳(0 → 上千,量级差别足够断言)
|
||||||
|
const countColorInVec = (rgb, tol) => page.evaluate(({ rgb, tol }) => {
|
||||||
|
let n = 0
|
||||||
|
for (const cv of [...document.querySelectorAll('.iwb-editor-vec-canvas')]) {
|
||||||
|
const d = cv.getContext('2d').getImageData(0, 0, cv.width, cv.height).data
|
||||||
|
for (let i = 0; i < d.length; i += 4) {
|
||||||
|
if (d[i + 3] > 200 && Math.abs(d[i] - rgb[0]) < tol && Math.abs(d[i + 1] - rgb[1]) < tol && Math.abs(d[i + 2] - rgb[2]) < tol) n++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return n
|
||||||
|
}, { rgb, tol })
|
||||||
|
|
||||||
|
const greenBefore = await countColorInVec([34, 204, 85], 8)
|
||||||
|
await page.evaluate(() => {
|
||||||
|
const el = document.querySelector('.iwb-editor-optionbar-body [data-shape-color="fill"]')
|
||||||
|
el.value = '#22cc55'
|
||||||
|
el.dispatchEvent(new Event('change', { bubbles: true }))
|
||||||
|
})
|
||||||
|
await page.waitForTimeout(280)
|
||||||
|
const shapeFilled = await page.evaluate(() => {
|
||||||
|
const d = window.__iwbEditor.__debug()
|
||||||
|
const s = d.shapes[d.shapes.length - 1]
|
||||||
|
const body = document.querySelector('.iwb-editor-optionbar-body')
|
||||||
|
return {
|
||||||
|
fill: s.fill, fillColor: s.fillColor,
|
||||||
|
fillBtnOn: !!body.querySelector('[data-opt-toggle="fill"]').classList.contains('active'),
|
||||||
|
fillSwatchOff: body.querySelector('[data-shape-color="fill"]').classList.contains('is-off')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
const greenAfter = await countColorInVec([34, 204, 85], 8)
|
||||||
|
check('选填充色即自动切实心,画面上真的是这个颜色(不是只改了个字段)',
|
||||||
|
shapeFilled.fill === true && shapeFilled.fillColor === '#22cc55' && greenBefore === 0 && greenAfter > 200,
|
||||||
|
JSON.stringify(shapeFilled) + ' 绿色像素 ' + greenBefore + '→' + greenAfter)
|
||||||
|
check('填充色块随之变为「生效」态(不再是灰色斜纹)',
|
||||||
|
shapeFilled.fillSwatchOff === false && shapeFilled.fillBtnOn === true,
|
||||||
|
JSON.stringify({ off: shapeFilled.fillSwatchOff, btn: shapeFilled.fillBtnOn }))
|
||||||
|
|
||||||
|
await page.evaluate(() => {
|
||||||
|
const el = document.querySelector('.iwb-editor-optionbar-body [data-shape-color="stroke"]')
|
||||||
|
el.value = '#3388ff'
|
||||||
|
el.dispatchEvent(new Event('change', { bubbles: true }))
|
||||||
|
})
|
||||||
|
await page.waitForTimeout(280)
|
||||||
|
const shapeStroked = await page.evaluate(() => {
|
||||||
|
const d = window.__iwbEditor.__debug()
|
||||||
|
const s = d.shapes[d.shapes.length - 1]
|
||||||
|
return { shapeColor: s.color, mainColor: d.color }
|
||||||
|
})
|
||||||
|
check('改图形描边色 = 改主色(色板 / 吸管 / 选项栏不会各说各话)',
|
||||||
|
shapeStroked.shapeColor === '#3388ff' && shapeStroked.mainColor === '#3388ff',
|
||||||
|
JSON.stringify(shapeStroked))
|
||||||
|
|
||||||
const copyExists = await page.locator('[data-action="copyClipboard"]').count()
|
const copyExists = await page.locator('[data-action="copyClipboard"]').count()
|
||||||
await page.locator('[data-action="copyClipboard"]').click()
|
await page.locator('[data-action="copyClipboard"]').click()
|
||||||
await page.waitForTimeout(400)
|
await page.waitForTimeout(400)
|
||||||
|
|||||||
Reference in new issue
Block a user