feat(image-annotate): v1.10.0 颜色语义统一、选中框改实线、选区命令归位、矢量图形补描边与填充
四个问题来自同一张界面截图,都是真缺陷。 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 (以前只看全局默认值,选中已实心的矩形却高亮「描边」,和画面反着来)。 顺带简化:文本样式与形状颜色共用同一套色块控件与 CSS,is-off 用斜纹 + 虚线边框;底色色块用 --sw-a 变量体现半透明。 harness 162 → 172 条全通(新增:默认色不写死、色块生效态、选区命令归位、 选中框实线覆盖率 ≥0.85、图形描边/填充色与实际像素);validate 9/9。 harness 自身两处改法:清选中改用「切到别的工具再切回」(画布上早有别的用例 留下的图形,点空白会点到它们);像素断言改成全画布统计同色像素 (矢量画布含 overlayPad 外扩,按图片坐标换算单点会采到别处)。
This commit is contained in:
1 parent
73a29715d3
commit
b63771f6e4
13 files changed
+654
-233
No files matched your search
@@ -1896,6 +1896,21 @@
|
||||
}
|
||||
.iwb-opt-color::-webkit-color-swatch-wrapper { padding: 2px; }
|
||||
.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 行,空的时候整块隐藏(不占位) */
|
||||
.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 { applyShapeHandle, beginPenEdit, beginShapeHandleDrag, beginTextRotate, beginTextScaleDrag, commitTextInput, deleteSelectedShape, deleteSelectedText, exitPenEdit, getPenEditingShape, getSelectedShape, getSelectedText, hideTextInput, hitAnyObject, hitPenEdgeInsert, hitPenPoint, hitShapeHandle, hitShapeLayer, hitTextHandle, hitTextLayer, hitTopmost, moveLayer, otherObjectBoxes, renderObjects, selectNeighborLayer, selectUnit, shapeBounds, showTextInput, textBounds } from './objects.js'
|
||||
import { snapMove } from './snap.js'
|
||||
import { TEXT_DEFAULTS, TEXT_LINE_HEIGHT } from './text.js'
|
||||
import { rememberColor } from './recent-colors.js'
|
||||
import { cancelImagePlacement, confirmImagePlacement, drawPlacementPreview, hitPlacementHandle, insidePlacementRect, resizePlacement } from './placement.js'
|
||||
import { close, copyResult, exportResult } from './index.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,
|
||||
x2: pos.x, y2: pos.y,
|
||||
color: S.color,
|
||||
fillColor: S.shapeFillColor,
|
||||
lw: Math.max(1, S.shapeLineWidth),
|
||||
lineWidth: Math.max(1, S.shapeLineWidth),
|
||||
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,
|
||||
x2: pos.x, y2: pos.y,
|
||||
color: S.color,
|
||||
fillColor: S.shapeFillColor, // null = 跟随描边色(改主色时整块跟着变)
|
||||
lw: Math.max(1, S.shapeLineWidth),
|
||||
fill: S.tool === 'rect' || S.tool === 'circle' ? !!S.rectFill : false,
|
||||
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=钢笔)。
|
||||
* 钢笔只在闭合路径上才有填充面积,但开关本身一直可点,便于先选后画。 */
|
||||
function fillStyleHTML(owner) {
|
||||
const fill = owner === 'pen' ? S.penFill : S.rectFill
|
||||
/** 矢量图形的描边色 / 填充色块(v1.10)。
|
||||
* 描边色就是主色 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>
|
||||
<button class="iwb-opt-btn${fill ? '' : ' active'}" data-opt-toggle="stroke" data-fill-owner="${owner}" data-value="stroke" title="描边 (Shift+X 切换)">描边</button>
|
||||
<button class="iwb-opt-btn${fill ? ' active' : ''}" data-opt-toggle="fill" data-fill-owner="${owner}" data-value="fill" title="实心 (Shift+X 切换)">实心</button>`
|
||||
<button class="iwb-opt-btn${fill ? '' : ' active'}" data-opt-toggle="stroke" data-fill-owner="${owner}" data-value="stroke" title="只描边 (Shift+X 切换)">描边</button>
|
||||
<button class="iwb-opt-btn${fill ? ' active' : ''}" data-opt-toggle="fill" data-fill-owner="${owner}" data-value="fill" title="实心填充 (Shift+X 切换)">实心</button>`
|
||||
}
|
||||
|
||||
const SHAPE_NAMES = { rect: '矩形', circle: '圆形', arrow: '箭头', pen: '钢笔路径' }
|
||||
@@ -999,11 +1024,12 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
||||
return {
|
||||
fontWeight: String(pick('fontWeight', 'textWeight', 'bold')),
|
||||
align: pick('align', 'textAlign', 'left'),
|
||||
lineHeight: Number(pick('lineHeight', 'textLineHeight', 1.25)) || 1.25,
|
||||
strokeWidth: Math.max(0, Number(pick('strokeWidth', 'textStrokeWidth', 0)) || 0),
|
||||
strokeColor: pick('strokeColor', 'textStrokeColor', '#ffffff'),
|
||||
bgFill: !!pick('bgFill', 'textBgFill', false),
|
||||
bgColor: pick('bgColor', 'textBgColor', '#000000')
|
||||
lineHeight: Number(pick('lineHeight', 'textLineHeight', TEXT_LINE_HEIGHT)) || TEXT_LINE_HEIGHT,
|
||||
strokeWidth: Math.max(0, Number(pick('strokeWidth', 'textStrokeWidth', TEXT_DEFAULTS.strokeWidth)) || 0),
|
||||
strokeColor: pick('strokeColor', 'textStrokeColor', TEXT_DEFAULTS.strokeColor),
|
||||
bgFill: !!pick('bgFill', 'textBgFill', TEXT_DEFAULTS.bgFill),
|
||||
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-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="color" class="iwb-opt-color" data-opt-color="strokeColor" value="${v.strokeColor}" title="描边颜色">
|
||||
<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.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>
|
||||
<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])
|
||||
// 圆角只对矩形有意义(圆形本来就是圆的,箭头/钢笔没有这个概念)
|
||||
+ (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
|
||||
? '<span class="iwb-opt-hint">这条钢笔路径未闭合,实心不生效;点回起点闭合后即可填充</span>'
|
||||
: '')
|
||||
+ selCmdHTML()
|
||||
}
|
||||
}
|
||||
const text = getSelectedText()
|
||||
if (text) {
|
||||
// v1.10:这里**不再**放「全选/反选/取消选区」那三个按钮。
|
||||
// 用户反馈:选中一段文字时选项栏冒出选区命令,看着像「文字自带了一个选区」;
|
||||
// 那三个命令操作的是像素选区(蚂蚁线),跟文字对象没关系,已归位到选区工具。
|
||||
return `<span class="iwb-opt-current">已选中:文字</span>`
|
||||
+ rangeOpt('textSize', '字号', 8, 400, Math.round(text.fontSize || S.textSize), 'px')
|
||||
+ textStyleHTML(text)
|
||||
// 控件齐全时这一行很挤,说明文字必须排在按钮之后:
|
||||
// 真放不下时宁可把 hint 滚出视野,也不能把「复制/取消选区」这些按钮顶没了
|
||||
+ selCmdHTML()
|
||||
+ '<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, '')
|
||||
+ 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') {
|
||||
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') {
|
||||
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>'
|
||||
}
|
||||
@@ -1117,15 +1147,19 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
||||
+ '<span class="iwb-opt-hint">点画布输入文字,Enter 确认,Shift+Enter 换行</span>'
|
||||
}
|
||||
if (tool === 'marquee') {
|
||||
// 选区命令归位(v1.10):全选/反选/取消选区属于「像素选区」,就该待在选区工具里,
|
||||
// 而不是跟着文字/图形选中态到处跑。必须排在 hint 之前(hint 带 margin-left:auto)。
|
||||
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 === '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>
|
||||
<span class="iwb-opt-hint">${OPT_HINTS.marquee}</span>`
|
||||
<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>`
|
||||
}
|
||||
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>
|
||||
<span class="iwb-opt-hint">${OPT_HINTS.lasso}</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>`
|
||||
}
|
||||
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>`
|
||||
@@ -1201,9 +1235,28 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
||||
btn.classList.toggle('active', String(sv[k]) === btn.dataset.value)
|
||||
})
|
||||
body.querySelectorAll('[data-opt-color]').forEach(inp => {
|
||||
if (document.activeElement === inp) return
|
||||
const v = sv[inp.dataset.optColor]
|
||||
if (v && String(inp.value).toLowerCase() !== String(v).toLowerCase()) inp.value = v
|
||||
const k = inp.dataset.optColor
|
||||
if (document.activeElement !== inp) {
|
||||
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'
|
||||
else if (key === 'lineHeight') value = clamp(Number(raw) || 125, 80, 300) / 100
|
||||
else if (key === 'strokeWidth') value = clamp(Number(raw) || 0, 0, 40)
|
||||
else if (key === 'strokeColor' || key === 'bgColor') value = String(raw || '#000000').toLowerCase()
|
||||
else if (key === 'strokeColor' || key === 'bgColor') value = String(raw || TEXT_DEFAULTS.bgColor).toLowerCase()
|
||||
else value = String(raw)
|
||||
|
||||
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()
|
||||
if (!t || t.locked) { textStyleSnapDone = false; return }
|
||||
if (!t || t.locked) { textStyleSnapDone = false; syncOptionBar(); return }
|
||||
if (committed || !textStyleSnapDone) { saveSnapshot('文字样式'); textStyleSnapDone = true }
|
||||
t[key] = value
|
||||
// 只调颜色、没点「底色」开关时,画布上什么都不会变 —— 这是最容易被当成
|
||||
// 「底色坏了 / 被别的颜色盖住」的路径。选了颜色就说明想用它,顺手把底色打开。
|
||||
if (key === 'bgColor' && !t.bgFill) {
|
||||
t.bgFill = true
|
||||
S.textBgFill = true
|
||||
}
|
||||
if (key === 'strokeColor' && !(Number(t.strokeWidth) > 0)) t.strokeWidth = S.textStrokeWidth
|
||||
if (key === 'bgColor' && !t.bgFill) t.bgFill = true
|
||||
renderObjects()
|
||||
// 自动开启底色后按钮的 active 态与色块取值都要跟着刷新
|
||||
if (key === 'bgColor') syncOptionBar()
|
||||
// 自动打开描边/底色后,按钮 active 态与色块取值都要跟着刷新
|
||||
if (key === 'bgColor' || key === 'strokeColor') syncOptionBar()
|
||||
if (committed) textStyleSnapDone = false
|
||||
}
|
||||
|
||||
@@ -1299,6 +1353,35 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
||||
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' 作用于钢笔闭合路径。 */
|
||||
function setShapeFill(fill, owner) {
|
||||
@@ -1444,6 +1527,13 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
||||
syncOptionBar()
|
||||
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)
|
||||
})
|
||||
body.addEventListener('click', (e) => {
|
||||
@@ -1909,7 +1999,7 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
||||
function commitPenPath() {
|
||||
if (!S.penPath || S.penPath.pts.length < 2) { S.penPath = null; renderObjects(); return }
|
||||
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 下双击
|
||||
S.shapeLayers.push(shape); S.penPath = null; renderObjects(); renderLayerPanel()
|
||||
finishCreateTool('shape', shape.id)
|
||||
|
||||
@@ -323,7 +323,7 @@ import { toast } from './commands.js'
|
||||
opacity: l.opacity == null ? 1 : l.opacity,
|
||||
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 => ({
|
||||
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,
|
||||
@@ -337,8 +337,10 @@ import { toast } from './commands.js'
|
||||
textDefaults: {
|
||||
weight: S.textWeight, align: S.textAlign, lineHeight: S.textLineHeight,
|
||||
strokeWidth: S.textStrokeWidth, strokeColor: S.textStrokeColor,
|
||||
bgFill: S.textBgFill, bgColor: S.textBgColor
|
||||
}, selectedShapeId: S.selectedShapeId,
|
||||
bgFill: S.textBgFill, bgColor: S.textBgColor, bgAlpha: S.textBgAlpha
|
||||
},
|
||||
// 矢量图形颜色: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,
|
||||
// 当前正在进行的拖拽类型:move 才是拖动本体,handle/rotate 说明点到了控制点
|
||||
|
||||
@@ -208,14 +208,13 @@ import { isDrawableLayer } from '../vendor/layer-logic.js'
|
||||
ctx.save()
|
||||
ctx.strokeStyle = '#e8a735'
|
||||
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)
|
||||
ctx.beginPath()
|
||||
ctx.moveTo(corners[0][0], corners[0][1])
|
||||
for (let i = 1; i < corners.length; i++) ctx.lineTo(corners[i][0], corners[i][1])
|
||||
ctx.closePath()
|
||||
ctx.stroke()
|
||||
ctx.setLineDash([])
|
||||
ctx.fillStyle = '#fff'
|
||||
ctx.strokeStyle = '#e8a735'
|
||||
const pts = frameHandlePoints(box, rot)
|
||||
|
||||
@@ -418,14 +418,14 @@ import { isDrawableLayer } from '../vendor/layer-logic.js'
|
||||
octx.save()
|
||||
octx.strokeStyle = '#e8a735'
|
||||
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)
|
||||
octx.beginPath()
|
||||
octx.moveTo(corners[0][0], corners[0][1])
|
||||
for (let i = 1; i < corners.length; i++) octx.lineTo(corners[i][0], corners[i][1])
|
||||
octx.closePath()
|
||||
octx.stroke()
|
||||
octx.setLineDash([])
|
||||
const hs = 5.5 / viewScale()
|
||||
octx.fillStyle = '#ffffff'
|
||||
octx.strokeStyle = '#e8a735'
|
||||
@@ -475,14 +475,13 @@ import { isDrawableLayer } from '../vendor/layer-logic.js'
|
||||
octx.save()
|
||||
octx.strokeStyle = '#e8a735'
|
||||
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)
|
||||
octx.beginPath()
|
||||
octx.moveTo(corners[0][0], corners[0][1])
|
||||
for (let i = 1; i < corners.length; i++) octx.lineTo(corners[i][0], corners[i][1])
|
||||
octx.closePath()
|
||||
octx.stroke()
|
||||
octx.setLineDash([])
|
||||
const hs = 5.5 / viewScale()
|
||||
octx.fillStyle = '#ffffff'
|
||||
octx.strokeStyle = '#e8a735'
|
||||
|
||||
@@ -7,6 +7,9 @@
|
||||
|
||||
'use strict'
|
||||
|
||||
// text.js 是零依赖叶子模块,这里引它的默认值常量不会形成循环
|
||||
import { TEXT_DEFAULTS } from './text.js'
|
||||
|
||||
export const ZOOM_MIN = 0.1
|
||||
export const ZOOM_MAX = 10
|
||||
export const ZOOM_STEP = 1.15
|
||||
@@ -39,15 +42,19 @@
|
||||
// 否则「调细画笔」会顺手把所有形状的描边一起改掉。
|
||||
shapeLineWidth: 3, // 矩形/圆形/箭头/钢笔的描边粗细
|
||||
shapeRadius: 0, // 矩形圆角半径 px(v1.9,仅 rect 有意义)
|
||||
// v1.10:矢量图形的填充色。null = 跟随描边色(新画的就是「同色实心」,
|
||||
// 换主色时整体跟着变),一旦单独选过填充色就固定下来(每形状自己存 fillColor)。
|
||||
shapeFillColor: null,
|
||||
textSize: 32, // 新建文字的字号 px
|
||||
// ---- v1.9 文字样式:这套是「新建文字」的默认值,每段文字自己存一份 ----
|
||||
textWeight: 'bold', // bold | normal | 900
|
||||
textAlign: 'left', // left | center | right(多行时各行按块宽对齐)
|
||||
textLineHeight: 1.25, // 行高倍数(1.25 = 老版单行高度,勿随意改)
|
||||
textStrokeWidth: 0, // 描边宽度 px,0 = 无描边
|
||||
textStrokeColor: '#ffffff',
|
||||
textBgFill: false, // 底色块
|
||||
textBgColor: '#000000',
|
||||
textStrokeWidth: TEXT_DEFAULTS.strokeWidth, // 描边宽度 px,0 = 无描边
|
||||
textStrokeColor: TEXT_DEFAULTS.strokeColor,
|
||||
textBgFill: TEXT_DEFAULTS.bgFill, // 底色块
|
||||
textBgColor: TEXT_DEFAULTS.bgColor, // 中性近黑,不再是纯黑 #000000
|
||||
textBgAlpha: TEXT_DEFAULTS.bgAlpha, // 底色透明度(色块按这个不透明度显示,所见即所得)
|
||||
// 最近使用颜色(最多 8 个,存 ctx.settings,跨会话保留)
|
||||
recentColors: [],
|
||||
// 图层系统
|
||||
|
||||
@@ -15,6 +15,23 @@
|
||||
/** 默认行高倍数:必须等于老版的 fontSize×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 系数 */
|
||||
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)
|
||||
// 0.55 在浅色/花色底图上偏透,用户容易以为「底色没生效」;0.68 既压得住底图,
|
||||
// 也还看得见一点背景,是「垫一块板让字立起来」的常用手感。
|
||||
ctx.globalAlpha = (t.opacity != null ? t.opacity : 1) * (t.bgAlpha == null ? 0.68 : t.bgAlpha)
|
||||
ctx.fillStyle = t.bgColor || '#000000'
|
||||
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()
|
||||
@@ -132,10 +149,10 @@
|
||||
const y = t.y + m.pad + i * m.lh
|
||||
if (m.sw > 0) {
|
||||
ctx.lineWidth = m.sw
|
||||
ctx.strokeStyle = t.strokeColor || '#ffffff'
|
||||
ctx.strokeStyle = t.strokeColor || TEXT_DEFAULTS.strokeColor
|
||||
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.restore()
|
||||
@@ -149,9 +166,9 @@
|
||||
align: alignOf(s),
|
||||
lineHeight: Number(s.lineHeight) || TEXT_LINE_HEIGHT,
|
||||
strokeWidth: Math.max(0, Number(s.strokeWidth) || 0),
|
||||
strokeColor: s.strokeColor || '#ffffff',
|
||||
strokeColor: s.strokeColor || TEXT_DEFAULTS.strokeColor,
|
||||
bgFill: !!s.bgFill,
|
||||
bgColor: s.bgColor || '#000000',
|
||||
bgAlpha: s.bgAlpha == null ? 0.68 : Number(s.bgAlpha)
|
||||
bgColor: s.bgColor || TEXT_DEFAULTS.bgColor,
|
||||
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) {
|
||||
ctx.save()
|
||||
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.translate(-cx, -cy)
|
||||
}
|
||||
ctx.strokeStyle = s.color
|
||||
ctx.strokeStyle = strokeOf(s)
|
||||
ctx.lineWidth = s.lw
|
||||
ctx.lineCap = 'round'
|
||||
ctx.lineJoin = 'round'
|
||||
if (s.type === 'pen') {
|
||||
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') {
|
||||
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)
|
||||
if (radius > 0) {
|
||||
ctx.beginPath()
|
||||
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()
|
||||
} 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)
|
||||
}
|
||||
} 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)
|
||||
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)
|
||||
if (s.fill) { ctx.fillStyle = s.color; ctx.fill() }
|
||||
if (s.fill) { ctx.fillStyle = fillOf(s); ctx.fill() }
|
||||
ctx.stroke()
|
||||
} else {
|
||||
ctx.fillStyle = s.color
|
||||
ctx.fillStyle = strokeOf(s)
|
||||
ctx.beginPath()
|
||||
ctx.moveTo(s.x1, s.y1)
|
||||
ctx.lineTo(s.x2, s.y2)
|
||||
|
||||
Reference in new issue
Block a user