feat(image-annotate): v1.13.0 顶栏瘦身 / 视图按钮归位 / R·O·L 快捷键 / 填充色实时 / 图层解封

1. 顶栏删掉置顶/上移/下移/置底四个层级按钮(图层拖动 + Ctrl+]/[ 已覆盖),
   `.iwb-editor-commands` 整块移除,`updateLayerUI()` / `bindLayerOrderButtons()` 一并清除。
2. 「适应窗口 / 收起侧栏」移到工具栏 DOM 末尾 —— 工具栏是 shrink-to-fit 的
   absolute 居中容器,放最后天然就在最右,无需额外定位。
3. 快捷键:R 矩形、O 圆形、L 箭头;套索从 L 迁到 A(能力不丢),U 与 Shift+U 保留。
   键盘处理改为优先匹配 e.code,修掉中文输入法下 [ ] 变【】导致的失灵。
4. 原生 <input type="color"> 补接 input 事件做实时预览(skipHistory +
   nativeColorSnapped),change 才落一次可撤销提交 —— 拖一整轮色谱只记 1 步。
5. 原图不再钉底:planPanelOrder / updateSortTarget / onSortEnd / moveLayer /
   mergeUnits 五处解封,其他图层可拖到原图下方,面板提示同步更新。

回归:tools/harness.mjs 140 → 192 条全通;npm run validate 9/9。
This commit is contained in:
qiqi committed 2026-11-08 22:26:47 +08:00
1 parent 9c938887c1
commit 31866a2407
11 files changed
+847 -242

No files matched your search

+24 -27
View File
@@ -31,21 +31,10 @@ import { bindEvents } from './events.js'
<button class="iwb-editor-action" data-action="redo" title="重做 (Ctrl+Shift+Z)"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="23 4 23 10 17 10"/><path d="M20.49 15a9 9 0 1 1-2.12-9.36L23 10"/></svg></button>
<button class="iwb-editor-action iwb-editor-action-reset" data-action="reset" title="还原原图:删掉所有标注/图层,回到打开时的样子(Ctrl+Z 可撤销)"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 2v6h-6"/><path d="M3 12a9 9 0 0 1 15-6.7L21 8"/><path d="M3 22v-6h6"/><path d="M21 12a9 9 0 0 1-15 6.7L3 16"/></svg></button>
</div>
<span class="iwb-editor-divider"></span>
<!-- 顶栏命令带(v1.2.6):撤销/重做/还原 | 顺序 | 视图;图层新建/导入回图层面板标题栏 -->
<div class="iwb-editor-commands">
<div class="iwb-editor-cmdgroup" data-group="order" title="调整选中元素的图层顺序">
<button class="iwb-editor-layer-btn" data-layer="top" title="置顶:选中元素移到最上层 (Ctrl+Shift+])"><svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="4" y1="5" x2="20" y2="5"/><line x1="12" y1="19" x2="12" y2="5"/><polyline points="6 11 12 5 18 11"/></svg></button>
<button class="iwb-editor-layer-btn" data-layer="up" title="上移一层 (Ctrl+])"><svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="12" y1="19" x2="12" y2="5"/><polyline points="6 11 12 5 18 11"/></svg></button>
<button class="iwb-editor-layer-btn" data-layer="down" title="下移一层 (Ctrl+[)"><svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="12" y1="5" x2="12" y2="19"/><polyline points="6 13 12 19 18 13"/></svg></button>
<button class="iwb-editor-layer-btn" data-layer="bottom" title="置底:选中元素移到最下层 (Ctrl+Shift+[)"><svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="12" y1="5" x2="12" y2="19"/><polyline points="6 13 12 19 18 13"/><line x1="4" y1="19" x2="20" y2="19"/></svg></button>
</div>
<span class="iwb-editor-divider"></span>
<div class="iwb-editor-cmdgroup" data-group="view">
<button class="iwb-editor-action" data-action="zoomFit" title="适应窗口 (Ctrl+0)"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="9 3 3 3 3 9"/><polyline points="15 3 21 3 21 9"/><polyline points="3 15 3 21 9 21"/><polyline points="21 15 21 21 15 21"/></svg></button>
<button class="iwb-editor-action" data-action="togglePanels" title="收起 / 展开侧栏 (Tab)"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="4" width="18" height="16" rx="2"/><line x1="9" y1="4" x2="9" y2="20"/></svg></button>
</div>
</div>
<!-- 顶栏命令带已清空(v1.13):
四个「置顶/上移/下移/置底」按钮删除(图层面板可拖动 + Ctrl+]/[ 已覆盖);
「适应窗口 / 收起侧栏」搬到画布底部工具栏最右侧,离画布更近。
整个 .iwb-editor-commands 容器一并移除,不留一条空分隔线。 -->
<div class="iwb-editor-export-actions">
<div class="iwb-editor-export-settings-wrap">
@@ -130,20 +119,23 @@ import { bindEvents } from './events.js'
<button data-sel-cmd="sel.none" title="取消选区 (Esc / Ctrl+D)">取消</button>
</div>
<div class="iwb-editor-tools">
<!-- 颜色(v1.11):描边 + 填充 两个槽叠放在一个按钮位里(PS 式前/背景色)。
点哪个槽就调哪个:色板只有一套,写谁由 S.colorTarget 决定。
这样全项目只有「描边色 / 填充色」两个颜色概念,不再有第三个主色。
填充块在无填充时画斜杠,跟随描边色时带一个小三角角标。 -->
<!-- 颜色(v1.11 两格 → v1.12 文字三格):
形状下是「描边 + 填充」两格叠放在一个按钮位里(PS 式前/背景色);
文字下是「文字 / 描边 / 底色」三格横排 —— 文字对象天生就有三个颜色,
只给两格必然有一格无处安放(用户反馈「文本不支持描边与字体色切换」)。
点哪格就调哪格:色板只有一套,写谁由 S.colorTarget 决定。
关掉的那格画斜杠,跟随描边色的填充块带一个小三角角标。 -->
<div class="iwb-editor-color-pair" data-color-mode="single">
<button type="button" class="iwb-editor-color-btn" data-color-slot="stroke" data-action="toggleColorPop" aria-expanded="false" title="描边色:形状描边 / 画笔 / 文字都用它。点开色板调色"><i></i></button>
<button type="button" class="iwb-editor-color-btn" data-color-slot="fill" data-action="toggleColorPop" aria-expanded="false" title="填充色:形状内部颜色。点开色板调色,色板里可切换「无填充」"><i></i></button>
<button type="button" class="iwb-editor-color-btn" data-color-slot="bg" data-action="toggleColorPop" aria-expanded="false" title="文本框底色:垫在文字下面的一块半透明色板。点开调色,可选「无」"><i></i></button>
</div>
<span class="iwb-editor-divider"></span>
<button class="iwb-editor-tool" data-tool="select" title="选择/移动 (V):点击元素选中,拖拽移动,手柄调整大小,双击文字改内容"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 3l7.07 16.97 2.51-7.39 7.39-2.51L3 3z"/></svg></button>
<span class="iwb-editor-divider"></span>
<button class="iwb-editor-tool" data-tool="marquee" title="选框 (M):拖出矩形/椭圆选区,松手后旁边出现操作条;Shift+M 切换矩形/椭圆"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" stroke-dasharray="4 3"><rect x="3" y="4" width="18" height="16" rx="1"/></svg></button>
<button class="iwb-editor-tool" data-tool="lasso" title="套索 (L):按住拖动自由圈选,松手闭合"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4 12c0-4 3.6-7 8-7s8 3 8 7-3.6 7-8 7c-2 0-3.8-.6-5.2-1.6"/><path d="M6.8 17.4 4 20l1.2-3.2"/><circle cx="20" cy="19" r="2"/></svg></button>
<button class="iwb-editor-tool" data-tool="lasso" title="套索 (A):按住拖动自由圈选,松手闭合"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4 12c0-4 3.6-7 8-7s8 3 8 7-3.6 7-8 7c-2 0-3.8-.6-5.2-1.6"/><path d="M6.8 17.4 4 20l1.2-3.2"/><circle cx="20" cy="19" r="2"/></svg></button>
<button class="iwb-editor-tool active" data-tool="brush" title="画笔 (B):] 增大 / [ 减小笔刷;按住 Alt 临时吸色"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M17 3a2.85 2.83 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5Z"/><path d="m15 5 4 4"/></svg></button>
@@ -153,11 +145,11 @@ import { bindEvents } from './events.js'
<button class="iwb-editor-tool" data-tool="text" title="文字 (T)"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="4 7 4 3 20 3 20 7"/><line x1="9" y1="20" x2="15" y2="20"/><line x1="12" y1="3" x2="12" y2="20"/></svg></button>
<button class="iwb-editor-tool" data-tool="rect" title="矩形 (U):Shift+U 在矩形/圆形/箭头间循环"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="2"/></svg></button>
<button class="iwb-editor-tool" data-tool="rect" title="矩形 (R):Shift+U 在矩形/圆形/箭头间循环"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="2"/></svg></button>
<button class="iwb-editor-tool" data-tool="circle" title="圆形 (U):Shift+U 在矩形/圆形/箭头间循环"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="8"/></svg></button>
<button class="iwb-editor-tool" data-tool="circle" title="圆形 (O):Shift+U 在矩形/圆形/箭头间循环"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="8"/></svg></button>
<button class="iwb-editor-tool" data-tool="arrow" title="箭头 (U):Shift+U 在矩形/圆形/箭头间循环"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="5" y1="12" x2="19" y2="12"/><polyline points="12 5 19 12 12 19"/></svg></button>
<button class="iwb-editor-tool" data-tool="arrow" title="箭头 (L):Shift+U 在矩形/圆形/箭头间循环"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="5" y1="12" x2="19" y2="12"/><polyline points="12 5 19 12 12 19"/></svg></button>
<button class="iwb-editor-tool" data-tool="picker" title="吸管 (I):点击画布取色(悬停预览);选中形状/文字时取色直接改它的颜色,取完切回上一工具"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m2 22 1-1h3l9-9"/><path d="M3 21v-3l9-9"/><path d="m15 6 3.4-3.4a2.1 2.1 0 1 1 3 3L18 9l.4.4a2.1 2.1 0 1 1-3 3l-3.8-3.8a2.1 2.1 0 1 1 3-3Z"/></svg></button>
@@ -167,7 +159,11 @@ import { bindEvents } from './events.js'
<button class="iwb-editor-tool" data-tool="crop" title="裁剪 (C):参数在选项栏;Enter 确认 / Esc 取消"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M6.13 1L6 16a2 2 0 0 0 2 2h15"/><path d="M1 6.13L16 6a2 2 0 0 1 2 2v15"/></svg></button>
<!-- 视图快捷(v1.13):从顶栏搬过来,贴在工具条最右侧的「|」之后。
工具条本身是 shrink-to-fit 且居中,所以这一组天然就是「最右边」。 -->
<span class="iwb-editor-divider"></span>
<button class="iwb-editor-tool iwb-editor-view-btn" data-action="zoomFit" title="适应窗口 (Ctrl+0):整张图缩放到刚好放得下"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="9 3 3 3 3 9"/><polyline points="15 3 21 3 21 9"/><polyline points="3 15 3 21 9 21"/><polyline points="21 15 21 21 15 21"/></svg></button>
<button class="iwb-editor-tool iwb-editor-view-btn" data-action="togglePanels" title="收起 / 展开侧栏 (Tab)"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="4" width="18" height="16" rx="2"/><line x1="9" y1="4" x2="9" y2="20"/></svg></button>
</div>
</div>
<div class="iwb-editor-zoom-hint">滚轮缩放 · 抓手/空格/中键拖拽自由移动画布</div>
@@ -237,12 +233,13 @@ import { bindEvents } from './events.js'
必须挂在 modal 下、不能塞进 .iwb-editor-tools —— 工具栏是 overflow-x:auto,
canvas-wrap 是 overflow:clip,塞进去弹层会被直接裁掉;定位由 events.js 计算。 -->
<div class="iwb-editor-color-pop" hidden>
<!-- 弹层头部(v1.11):标明「现在调的是哪个颜色」,并可直接切换。
与工具栏那两个色块是同一组槽位,两边高亮完全一致。
「无」只对填充有意义:描边关掉会让形状彻底消失,不是用户要的。 -->
<!-- 弹层头部(v1.11 两格 → v1.12 文字三格):标明「现在调的是哪个颜色」,
并可直接切换。与工具栏那几个色块是同一组槽位,两边高亮完全一致。
「无」只对「可以没有」的颜色有意义:文字色没有无,描边/底色/填充才有。 -->
<div class="iwb-color-pop-head">
<button type="button" class="iwb-color-pop-tab active" data-color-slot="stroke" title="正在调描边色(形状描边 / 画笔 / 文字色)"><i></i><span class="iwb-color-pop-tab-label">描边</span></button>
<button type="button" class="iwb-color-pop-tab" data-color-slot="fill" title="正在调填充色(形状内部颜色)"><i></i><span class="iwb-color-pop-tab-label">填充</span></button>
<button type="button" class="iwb-color-pop-tab" data-color-slot="fill" title="正在调填充色(形状内部颜色 / 文字描边色)"><i></i><span class="iwb-color-pop-tab-label">填充</span></button>
<button type="button" class="iwb-color-pop-tab" data-color-slot="bg" hidden title="正在调文本框底色(垫在文字下面)"><i></i><span class="iwb-color-pop-tab-label">底色</span></button>
<button type="button" class="iwb-color-pop-none" data-color-none="1" title="无填充:形状内部透明,只留描边"><span></span>无</button>
</div>
<div class="iwb-color-pop-body">
+226 -76
View File
@@ -798,7 +798,6 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
updateBrushUI()
updateBrushParamUI()
updateFillUI()
updateLayerUI()
updateZoomUI()
hidePickerTip()
runtime.el.querySelectorAll('.iwb-editor-constraint-btn[data-ratio]').forEach(b => b.classList.remove('active'))
@@ -865,58 +864,112 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
}
}
/** 当前上下文里「填充」这个概念到底存不存在。
/** 当前颜色上下文(v1.12):决定工具栏给几格颜色、每格叫什么。
* 三类:
* text —— 文字:文字色 / 描边色 / 文本框底色,天生三个颜色
* shape —— 矩形/圆形/钢笔:描边色 + 填充色
* strokeOnly —— 画笔/橡皮/箭头/没选中任何东西:只有一格主色
* **全项目唯一**判断「现在有几个颜色」的地方,以后要加颜色只改这里。 */
function colorContext() {
const t = getSelectedText()
// 文字工具下即使还没落成对象,也是在调「下一段文字」的三个颜色
if (t || S.tool === 'text') return { kind: 'text', text: t || null }
const sh = getSelectedShape()
if (sh) return { kind: sh.type === 'arrow' ? 'strokeOnly' : 'shape', shape: sh }
if (S.tool === 'rect' || S.tool === 'circle' || S.tool === 'pen') return { kind: 'shape', shape: null }
return { kind: 'strokeOnly', shape: null }
}
/** 第二格(形状的填充 / 文字的描边)在当前上下文里到底存不存在。
* 箭头只有一条线没有内部;未闭合的钢笔路径也没有可填面积 —— 这两种情况
* 不该给填充色块,否则用户设了颜色画面上没有任何变化,又是一次「坏了」。 */
function fillSlotOn() {
const sh = getSelectedShape()
if (sh) return sh.type === 'rect' || sh.type === 'circle' || (sh.type === 'pen' && !!sh.closed)
return S.tool === 'rect' || S.tool === 'circle' || S.tool === 'pen'
const ctx = colorContext()
if (ctx.kind === 'text') return true
if (ctx.kind !== 'shape') return false
const sh = ctx.shape
if (!sh) return true
return sh.type === 'rect' || sh.type === 'circle' || (sh.type === 'pen' && !!sh.closed)
}
/** 描边 / 填充两个槽的显示值(v1.11)。
/** 文字的三个颜色槽(v1.12)。
* 文字对象本来就有三个颜色字段:color(文字本身)/ strokeColor(字的外描边)/
* bgColor(文本框底色)。上一版把它们硬塞进「描边 / 填充」两格,第二格其实是
* 形状的填充色,选中文字后点它没有任何反应 —— 用户说的「文本不支持描边与
* 字体色切换」就是这么来的。这里把三个颜色各自摆开,各自可点。 */
function textColorSlots(t) {
const color = (t ? t.color : S.color) || S.color
const strokeColor = ((t ? t.strokeColor : S.textStrokeColor) || TEXT_DEFAULTS.strokeColor)
const sw = Number(t ? t.strokeWidth : S.textStrokeWidth) || 0
const bgColor = ((t ? t.bgColor : S.textBgColor) || TEXT_DEFAULTS.bgColor)
const bgFill = !!(t ? t.bgFill : S.textBgFill)
const bgAlpha = Number(t
? (t.bgAlpha == null ? TEXT_DEFAULTS.bgAlpha : t.bgAlpha)
: S.textBgAlpha) || TEXT_DEFAULTS.bgAlpha
return {
mode: 'text',
stroke: color, fill: strokeColor, fillOn: sw > 0, follow: false,
bg: bgColor, bgOn: bgFill, bgAlpha,
strokeName: '文字', fillName: '描边', bgName: '底色'
}
}
/** 三个颜色槽的显示值(v1.11 起是两格,v1.12 起文字多一格底色)。
* **唯一的取值处**:工具栏色块、色板头部、hex、SV 调色器全从这里读,
* 避免「一个概念三种颜色」再次出现。
* 描边 = 主色(选中形状时读它自己的);填充 = 形状自己的 fillColor,
* 没单独设过(null)就跟随描边色,此时 follow=true。 */
* 文字:stroke=文字色 / fill=描边色 / bg=底色;
* 形状:stroke=描边色 / fill=填充色(没单独设过就跟随描边色,follow=true)。 */
export function colorSlots() {
const sh = getSelectedShape()
const ctx = colorContext()
if (ctx.kind === 'text') return textColorSlots(ctx.text)
const sh = ctx.shape
const stroke = (sh && sh.color) || S.color
const rawFill = sh ? (sh.fillColor || null) : S.shapeFillColor
const fillOn = sh
? (sh.type === 'pen' ? (!!sh.fill && !!sh.closed) : !!sh.fill)
: (S.tool === 'pen' ? !!S.penFill : !!S.rectFill)
return { stroke, fill: rawFill || stroke, fillOn, follow: !rawFill }
return {
mode: ctx.kind === 'shape' ? 'shape' : 'single',
stroke, fill: rawFill || stroke, fillOn, follow: !rawFill,
bg: null, bgOn: false, bgAlpha: 1,
strokeName: '描边', fillName: '填充', bgName: '底色'
}
}
/** 色板/hex/吸管要写的那一格颜色 */
function activeColor() {
const sl = colorSlots()
return S.colorTarget === 'fill' ? sl.fill : sl.stroke
if (S.colorTarget === 'bg') return sl.bg || sl.stroke
if (S.colorTarget === 'fill' && fillSlotOn()) return sl.fill || sl.stroke
return sl.stroke
}
export function updateColorUI() {
const sl = colorSlots()
const fillable = fillSlotOn()
// 当前上下文没有填充(切到画笔/文字/箭头,或选中了箭头):把「正在调填充」的状态
// 归位,否则工具栏会高亮一个已经隐藏的槽,色板也停在一个不存在的目标上。
if (!fillable && S.colorTarget === 'fill') S.colorTarget = 'stroke'
// 工具栏:两个槽都按真实值上色,填充关掉时画斜杠、跟随描边时带角标
const isText = sl.mode === 'text'
const second = isText ? true : fillSlotOn()
// 当前正在调的那一格在新上下文里不存在(比如调着「底色」时切回画笔),
// 就把目标归位,否则工具栏会高亮一个已经隐藏的格子,色板也停在不存在的目标上。
if (S.colorTarget !== 'stroke' && !second) S.colorTarget = 'stroke'
if (S.colorTarget === 'bg' && !isText) S.colorTarget = 'stroke'
// 工具栏:三格(文字)/ 两格(形状)/ 一格(只有主色)
const pair = runtime.el.querySelector('.iwb-editor-color-pair')
if (pair) pair.dataset.colorMode = fillable ? 'pair' : 'single'
if (pair) pair.dataset.colorMode = isText ? 'triple' : (second ? 'pair' : 'single')
const strokeBtn = runtime.el.querySelector('.iwb-editor-color-btn[data-color-slot="stroke"]')
const fillBtn = runtime.el.querySelector('.iwb-editor-color-btn[data-color-slot="fill"]')
// 同一个槽在不同工具下叫法不同:调文字时它改的是文字色,调画笔时是画笔色。
const bgBtn = runtime.el.querySelector('.iwb-editor-color-btn[data-color-slot="bg"]')
// 同一个格子在不同上下文里名字不同:文字下第一格是「文字色」,画笔下是「画笔色」。
// 一律写「描边」会让人在文字工具下以为这个颜色跟文字没关系。
const textCtx = S.tool === 'text' || (!!S.selectedTextId && S.tool === 'select')
const strokeName = textCtx ? '文字' : (S.tool === 'brush' || S.tool === 'eraser' ? '画笔' : '描边')
const strokeName = isText ? '文字' : (S.tool === 'brush' || S.tool === 'eraser' ? '画笔' : '描边')
if (strokeBtn) {
const dot = strokeBtn.querySelector('i')
if (dot) dot.style.backgroundColor = sl.stroke
strokeBtn.classList.toggle('active', S.colorTarget === 'stroke')
strokeBtn.title = fillable
? `描边色 ${sl.stroke.toUpperCase()}:形状描边也用这个值。点开色板调色`
: `${strokeName}色 ${sl.stroke.toUpperCase()}:点开色板调色`
strokeBtn.title = isText
? `文字色 ${String(sl.stroke).toUpperCase()}:改文字本身的颜色(右边「描边」是字的外描边)`
: (second
? `描边色 ${String(sl.stroke).toUpperCase()}:形状描边也用这个值。点开色板调色`
: `${strokeName}色 ${String(sl.stroke).toUpperCase()}:点开色板调色`)
const popEl = runtime.el.querySelector('.iwb-editor-color-pop')
strokeBtn.setAttribute('aria-expanded', String(!!(popEl && !popEl.hidden && S.colorTarget === 'stroke')))
}
@@ -926,26 +979,63 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
fillBtn.classList.toggle('is-none', !sl.fillOn)
fillBtn.classList.toggle('is-follow', sl.follow && sl.fillOn)
fillBtn.classList.toggle('active', S.colorTarget === 'fill')
fillBtn.title = !sl.fillOn
? '填充:无(形状内部透明)。点开色板选色即可填充'
: (sl.follow ? '填充色:跟随描边色 ' + sl.fill.toUpperCase() + ',点开可单独指定' : '填充色 ' + sl.fill.toUpperCase() + ',点开调色')
const fc = String(sl.fill).toUpperCase()
fillBtn.title = isText
? (sl.fillOn
? `文字描边色 ${fc}:沿字形外沿描一圈。点开调色,「无」= 去掉描边`
: '文字描边:无(描边宽度 0)。点开选色会自动给 6px 描边')
: (!sl.fillOn
? '填充:无(形状内部透明)。点开色板选色即可填充'
: (sl.follow ? '填充色:跟随描边色 ' + fc + ',点开可单独指定' : '填充色 ' + fc + ',点开调色'))
}
// 色板头部:两个 tab 与工具栏两个槽同步高亮,「无」只在调填充时出现
if (bgBtn) {
const dot = bgBtn.querySelector('i')
if (dot) {
dot.style.backgroundColor = sl.bg || 'transparent'
// 底色是半透明的:色块按真实不透明度显示,否则看起来像一块实心色
dot.style.opacity = sl.bgOn ? String(sl.bgAlpha) : ''
}
bgBtn.classList.toggle('is-none', !sl.bgOn)
bgBtn.classList.toggle('active', S.colorTarget === 'bg')
bgBtn.title = sl.bgOn
? `文本框底色 ${String(sl.bg || '').toUpperCase()}(${Math.round(sl.bgAlpha * 100)}% 不透明):垫在文字下面,「无」= 去掉底色`
: '文本框底色:无(透明)。点开选色会自动开启底色'
bgBtn.setAttribute('aria-expanded', String(!!(runtime.el.querySelector('.iwb-editor-color-pop:not([hidden])') && S.colorTarget === 'bg')))
}
// 色板头部:tab 与工具栏的格子一一对应,谁在调谁高亮
runtime.el.querySelectorAll('.iwb-color-pop-tab').forEach(tab => {
const isFill = tab.dataset.colorSlot === 'fill'
tab.classList.toggle('active', S.colorTarget === (isFill ? 'fill' : 'stroke'))
const slot = tab.dataset.colorSlot
const isFill = slot === 'fill'
const isBg = slot === 'bg'
tab.classList.toggle('active', S.colorTarget === slot)
const dot = tab.querySelector('i')
if (dot) dot.style.backgroundColor = isFill ? sl.fill : sl.stroke
if (dot) {
dot.style.backgroundColor = isBg ? (sl.bg || 'transparent') : (isFill ? sl.fill : sl.stroke)
if (isBg) dot.style.opacity = sl.bgOn ? String(sl.bgAlpha) : ''
}
const label = tab.querySelector('.iwb-color-pop-tab-label')
// 只有一根槽时,标题写「描边」会显得莫名其妙:这时它就是当前的唯一颜色
if (label) label.textContent = isFill ? '填充' : (fillable ? '描边' : strokeName)
if (isFill) { tab.classList.toggle('is-none', !sl.fillOn); tab.hidden = !fillable }
if (label) label.textContent = isBg ? '底色' : (isFill ? (isText ? '描边' : '填充') : strokeName)
tab.title = isBg
? '正在调文本框底色(垫在文字下面)'
: (isFill
? (isText ? '正在调文字描边色(沿字形外沿)' : '正在调填充色(形状内部颜色)')
: (isText ? '正在调文字色(文字本身的颜色)' : '正在调描边色'))
if (isFill) { tab.classList.toggle('is-none', !sl.fillOn); tab.hidden = !second }
if (isBg) { tab.classList.toggle('is-none', !sl.bgOn); tab.hidden = !isText }
})
// 「无」:形状 = 无填充;文字描边 = 描边宽度 0;文字底色 = 关掉底色块
// (文字色没有「无」—— 字没有颜色就等于把字删了,不该给这个按钮)
const noneBtn = runtime.el.querySelector('[data-color-none]')
if (noneBtn) {
const show = fillable && S.colorTarget === 'fill'
const onBg = S.colorTarget === 'bg' && isText
const onFill = S.colorTarget === 'fill' && second
const show = onBg || onFill
noneBtn.hidden = !show
noneBtn.classList.toggle('active', show && !sl.fillOn)
noneBtn.classList.toggle('active', show && (onBg ? !sl.bgOn : !sl.fillOn))
noneBtn.title = onBg
? '无底色:文字后面完全透明'
: (isText ? '无描边:把描边宽度置 0,只留文字本身' : '无填充:形状内部透明,只留描边')
}
const cur = activeColor()
@@ -994,13 +1084,6 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
if (b) b.classList.toggle('active', !!S.rectFill)
}
/** 图层按钮可用态:有选中元素才可用 */
export function updateLayerUI() {
const hasSel = !!(S.selectedTextId || S.selectedShapeId || S.layers.some(l => l.id === S.selectedLayerId && l.id !== 'base' && !l.locked))
runtime.el.querySelectorAll('.iwb-editor-layer-btn').forEach(b => {
b.disabled = !hasSel
})
}
// ============ 便利版 UI:就地选项栏 / 状态栏 / 更多菜单 ============
@@ -1176,7 +1259,7 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
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>'
+ '<span class="iwb-opt-hint">双击改内容 · 拖动手柄缩放 · 左上三格 = 文字色 / 描边 / 底色</span>'
}
// 选区命令是全局的,跟「有没有选中元素」无关:没选中时也必须能全选/反选/取消。
// 关键是必须排在 hint **之前** —— hint 带 margin-left:auto,放它后面会被一路
@@ -1440,6 +1523,56 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
if (committed) radiusSnapDone = false
}
let textColorSnapDone = false
/**
* 文字描边色 / 底色(v1.12):工具栏三格、色板 tab、色板调色器、吸管、推荐色
* 全部走这一条写回路径,与选项栏那两个原生色块(applyTextStyle)改的是同一份值。
* 与 applyTextStyle 分开的原因只有一个:色板里拖 SV 会每帧调用,需要
* skipHistory 支持(拖动开始由调用方拍一张快照,之后每帧只改对象)。
*/
function applyTextColor(key, color, opts) {
const skipHistory = !!(opts && opts.skipHistory)
const stateKey = TEXT_STYLE_STATE_KEY[key]
if (!stateKey) return
const hex = String(color || '').toLowerCase()
if (!/^#[0-9a-f]{6}$/.test(hex)) return
if (!skipHistory) rememberColor(hex)
S[stateKey] = hex
// 颜色选好了但画面上什么都不变(描边宽 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) {
if (!skipHistory && !textColorSnapDone) { saveSnapshot('文字颜色'); textColorSnapDone = true }
t[key] = hex
if (key === 'strokeColor' && !(Number(t.strokeWidth) > 0)) t.strokeWidth = S.textStrokeWidth
if (key === 'bgColor' && !t.bgFill) t.bgFill = true
renderObjects()
}
updateColorUI()
if (skipHistory) { syncOptionBarSoon(); return }
textColorSnapDone = false
syncOptionBar()
}
/** 「无」按钮(v1.11 起只管填充;v1.12 起按格子分派):
* 形状填充 → 内部透明;文字描边 → 描边宽度 0;文字底色 → 关掉底色块。
* 三种情况都只改开关,颜色留着不动 —— 下次点颜色还是它。 */
function applyColorNone() {
const sl = colorSlots()
if (sl.mode === 'text') {
if (S.colorTarget === 'bg') applyTextStyle('bgFill', '0', true)
else if (S.colorTarget === 'fill') applyTextStyle('strokeWidth', 0, true)
updateColorUI()
syncOptionBar()
return
}
applyShapeColor('none')
}
/** 形状描边色 / 填充色(v1.10;v1.11 起同时承接「无填充」)。
* 描边色不另存一份 —— 直接走 applyColorChange 写主色,左侧色板、吸管、
* 文字色、形状描边色四处因此永远同一个值(上一版的教训:同一个概念存两处必分叉)。
@@ -1498,6 +1631,16 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
* 「填充」只能从选项栏那个小色块改 —— 用户看到的就是「三个地方调色,
* 有一处跟别处不通」。现在按 S.colorTarget 分派,色板调到哪一格就是哪一格。 */
function applyPanelColor(color, opts) {
const sl = colorSlots()
// 文字:三格各自写自己的字段。第一格(文字色)就是主色,走 applyColorChange。
if (sl.mode === 'text') {
if (S.colorTarget === 'fill') { applyTextColor('strokeColor', color, opts); return }
if (S.colorTarget === 'bg') { applyTextColor('bgColor', color, opts); return }
applyColorChange(color, opts)
if (opts && opts.skipHistory) syncOptionBarSoon()
else syncOptionBar()
return
}
if (S.colorTarget === 'fill' && fillSlotOn()) { applyShapeColor('fill', color, opts); return }
if (S.colorTarget === 'fill') S.colorTarget = 'stroke' // 当前没有填充语义:退回描边,别让调色静默失效
applyColorChange(color, opts)
@@ -1505,9 +1648,9 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
else syncOptionBar()
}
/** 切换色板正在编辑哪一格(工具栏两个色块 / 色板头部两个 tab 共用) */
/** 切换色板正在编辑哪一格(工具栏色块 / 色板头部 tab 共用) */
function setColorTarget(slot) {
S.colorTarget = slot === 'fill' ? 'fill' : 'stroke'
S.colorTarget = slot === 'fill' ? 'fill' : (slot === 'bg' ? 'bg' : 'stroke')
updateColorUI()
}
@@ -1655,26 +1798,41 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
const body = root.querySelector('.iwb-editor-optionbar-body')
if (body) {
body.addEventListener('mousedown', (e) => e.stopPropagation())
// 原生 <input type="color"> 在系统取色器里连续拖色时只会派发 input,关闭取色器才派发 change。
// 以前只接 change,于是「取色器开着的整段时间画布一动不动,松手才变色」——用户说的
// 「填充色不能实时在矢量图形上显示颜色变化」就是这个(v1.13 修)。
// 现在:input = 实时预览(首帧拍一次快照,避免拖一路存几百张全画质快照),
// change = 收尾(补记「最近使用」、把选项栏刷干净)。
let nativeColorSnapped = false
const nativeColorOf = (t) => (t && t.closest ? (t.closest('[data-shape-color]') || t.closest('[data-opt-color]')) : null)
const applyNativeColor = (el, preview) => {
const isShape = el.hasAttribute('data-shape-color')
const key = isShape ? el.dataset.shapeColor : el.dataset.optColor
if (!nativeColorSnapped) {
const t = getSelectedText(), sh = getSelectedShape()
if ((t && !t.locked) || (sh && !sh.locked)) {
saveSnapshot(isShape ? '填充颜色' : '文字颜色')
nativeColorSnapped = true
}
}
// 预览阶段统一 skipHistory:快照已在上面拍过,不能每帧再拍
if (isShape) applyShapeColor(key, el.value, { skipHistory: true })
else applyTextColor(key, el.value, { skipHistory: true })
if (preview) { syncOptionBarSoon(); return }
if (nativeColorSnapped) rememberColor(String(el.value || '').toLowerCase())
nativeColorSnapped = false
syncOptionBar()
}
// 滑杆拖动中(input)与松手/失焦(change)走同一条写回路径,
// committed 只决定「要不要顺手记一步历史」,不影响参数生效。
body.addEventListener('input', (e) => setOptionFromControl(e.target, false))
body.addEventListener('input', (e) => {
const colorEl = nativeColorOf(e.target)
if (colorEl) { e.stopPropagation(); applyNativeColor(colorEl, true); return }
setOptionFromControl(e.target, false)
})
body.addEventListener('change', (e) => {
// 原生颜色框:拖动时只派发 input、关闭取色器才派发 change。
// 只认 change,保证「改一次颜色 = 一步撤销」,不在拖动途中连拍快照。
const colorEl = e.target.closest ? e.target.closest('[data-opt-color]') : null
if (colorEl) {
e.stopPropagation()
applyTextStyle(colorEl.dataset.optColor, colorEl.value, true)
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
}
const colorEl = nativeColorOf(e.target)
if (colorEl) { e.stopPropagation(); applyNativeColor(colorEl, false); return }
setOptionFromControl(e.target, true)
})
body.addEventListener('click', (e) => {
@@ -1785,7 +1943,6 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
bindColorPanel()
bindColorPalette()
bindFillToggle()
bindLayerOrderButtons()
bindZoomButtons()
bindHistoryActions()
bindLayerAddActions()
@@ -1841,7 +1998,7 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
function toggleColorPop(slot) {
const pop = runtime.el.querySelector('.iwb-editor-color-pop')
if (!pop) return
const want = slot === 'fill' ? 'fill' : 'stroke'
const want = slot === 'fill' ? 'fill' : (slot === 'bg' ? 'bg' : 'stroke')
if (!pop.hidden && S.colorTarget === want) { closeColorPop(); return }
S.colorTarget = want
if (pop.hidden) {
@@ -1887,7 +2044,7 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
const none = e.target.closest('[data-color-none]')
if (none) {
e.stopPropagation()
applyShapeColor('none')
applyColorNone()
return
}
})
@@ -2017,15 +2174,6 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
})
}
/** 图层顺序调节按钮(上移/下移/置顶/置底) */
function bindLayerOrderButtons() {
// 图层顺序调节
runtime.el.querySelectorAll('.iwb-editor-layer-btn').forEach(btn => {
btn.addEventListener('mousedown', (e) => e.stopPropagation())
btn.addEventListener('click', () => moveLayer(btn.dataset.layer))
})
}
/** 缩放按钮:缩小 / 放大 / 适应窗口 */
function bindZoomButtons() {
// 缩放按钮
@@ -2367,11 +2515,13 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
const key = String(e.key || '').toLowerCase()
// ================= PS 同款快捷键 =================
// 无修饰键:工具(V 移动 / M 选框 / L 套索 / B 画笔 / E 橡皮 / P 钢笔 / T 文字 / U 形状 / C 裁剪 / I 吸管 / H 抓手)
// 无修饰键:工具(V 移动 / M 选框 / A 套索 / B 画笔 / E 橡皮 / P 钢笔 / T 文字 / R 矩形 / O 圆形 / L 箭头 / C 裁剪 / I 吸管 / H 抓手)
// 数字键 1–0 的老映射已按 PS 习惯移除(PS 里数字键是图层不透明度)。
// v1.13 用户裁定:矩形 = R,圆形 = O,箭头 = L(原来的 L 是套索,套索改到 A)。
// U 保留为「同组循环」键:单独按仍是矩形,Shift+U 在 矩形/圆形/箭头 之间轮换。
const letterTools = {
v: 'select', m: 'marquee', l: 'lasso', b: 'brush', e: 'eraser', p: 'pen',
t: 'text', u: 'rect', c: 'crop', i: 'picker', h: 'hand'
v: 'select', m: 'marquee', a: 'lasso', l: 'arrow', b: 'brush', e: 'eraser', p: 'pen',
t: 'text', r: 'rect', o: 'circle', u: 'rect', c: 'crop', i: 'picker', h: 'hand'
}
if (!mod && !e.altKey && Object.prototype.hasOwnProperty.call(letterTools, key)) {
e.preventDefault()
+4 -1
View File
@@ -340,7 +340,10 @@ import { toast } from './commands.js'
bgFill: S.textBgFill, bgColor: S.textBgColor, bgAlpha: S.textBgAlpha
},
// 矢量图形颜色:fillColor=null 表示跟随描边色(回归要能断言这条语义)
shapeColors: { stroke: S.color, fill: S.shapeFillColor || null }, selectedShapeId: S.selectedShapeId,
shapeColors: { stroke: S.color, fill: S.shapeFillColor || null },
// 色板当前在调哪一格:stroke / fill / bg(文字上下文里 fill=描边、bg=底色)
colorTarget: S.colorTarget,
selectedShapeId: S.selectedShapeId,
// 光标所在的图片坐标(状态栏同源):换算问题的第一现场证据
lastPos: S.lastPos ? { x: Math.round(S.lastPos.x), y: Math.round(S.lastPos.y) } : null,
// 当前正在进行的拖拽类型:move 才是拖动本体,handle/rotate 说明点到了控制点
+16 -14
View File
@@ -614,7 +614,7 @@ export function setActiveLayer(id) {
const canRename = item.type === 'bitmap'
// 注意:整项不能用 HTML5 draggable —— 它会把子元素上的原生拖动一起接管,
// 不透明度滑杆因此「只能点、不能拖」。排序改由 bindLayerDragSort 自己实现。
const sortHint = item.id === 'base' ? '原图(固定在最底层)' : '拖动调整叠放顺序'
const sortHint = item.id === 'base' ? '原图(其他图层可以拖到它下面)' : '拖动调整叠放顺序'
html += `<div class="iwb-layer-item${activeClass}${multiClass}${visClass}" data-layer-id="${item.id}" data-layer-type="${item.type}">
<div class="iwb-layer-row">
<button class="iwb-layer-vis" data-vis-id="${item.id}" data-vis-type="${item.type}" title="${item.visible ? '隐藏' : '显示'}">${visSvg}</button>
@@ -669,9 +669,9 @@ export function setActiveLayer(id) {
ordered.push(u)
}
if (!ordered.length || byKey.size) return null
// 原图永远压在最底层:它被合进画面底图,跑到别的层上面只会让人以为图没了
const baseIdx = ordered.findIndex(u => u.obj.id === 'base')
if (baseIdx > 0) { const [b] = ordered.splice(baseIdx, 1); ordered.unshift(b) }
// v1.13:原图不再强制压在最底层(用户裁定「希望能移动到原图下方」)。
// 典型用法是垫一张纯色/背景层到原图底下。原图行本身仍不可拖(见 bindLayerDragSort),
// 但其他层可以任意穿过它 —— 顺序完全由面板说了算。
const before = units.map(u => u.obj.id).join('|')
return { ordered, changed: before !== ordered.map(u => u.obj.id).join('|') }
}
@@ -708,7 +708,7 @@ export function setActiveLayer(id) {
if (e.button !== 0 || _sortDrag) return
const item = e.target.closest('.iwb-layer-item')
if (!item || !list.contains(item)) return
if (item.dataset.layerId === 'base') return // 原图固定最底
if (item.dataset.layerId === 'base') return // 原图行不拖:它下面要不要垫层,拖别的层过去即可
// 控件、不透明度滑杆行、改名输入框都不参与排序:
// 否则滑杆刚按下就被判成「拖图层」,又回到只能点不能拖的老问题
if (e.target.closest('.iwb-layer-op-row, input, button, .iwb-layer-name-input')) return
@@ -755,11 +755,11 @@ export function setActiveLayer(id) {
if (d.y < lr.top + 18) list.scrollTop -= 8
else if (d.y > lr.bottom - 18) list.scrollTop += 8
// 落点:指针越过哪一行的中线,就把自己挪到那一行之前(原图永远最后)
// 落点:指针越过哪一行的中线,就把自己挪到那一行之前。
// v1.13 起不再把「原图」当固定锚点 —— 拖到原图下半区就真的落到它下面(垫背景层用)。
const rows = Array.from(list.querySelectorAll('.iwb-layer-item'))
const baseEl = rows.find(el => el.dataset.layerId === 'base') || null
const movable = rows.filter(el => el !== baseEl && el !== d.item)
let anchor = baseEl || null // 默认落到最底(原图之上)
const movable = rows.filter(el => el !== d.item)
let anchor = null // null = 落到最底(可能是原图之下)
for (const el of movable) {
const r = el.getBoundingClientRect()
if (d.y < r.top + r.height / 2) { anchor = el; break }
@@ -787,9 +787,8 @@ export function setActiveLayer(id) {
const rows = Array.from(d.list.querySelectorAll('.iwb-layer-item'))
const keyOf = (el) => el.dataset.layerType + ':' + el.dataset.layerId
const baseEl = rows.find(el => el.dataset.layerId === 'base') || null
const desc = rows.filter(el => el !== baseEl).map(keyOf)
if (baseEl) desc.push(keyOf(baseEl))
// v1.13:面板顺序就是最终顺序(原图可以被压在下面),不再把它补到末尾
const desc = rows.map(keyOf)
// 拖动即选中:拖完直接能在下面调不透明度/继续操作,不用再点一次
if (d.type === 'bitmap') {
@@ -1173,6 +1172,8 @@ export function setActiveLayer(id) {
const insertAt = all.slice(0, Math.max(lowIdx, 0)).filter(u => !chosenSet.has(u.obj)).length
let carrier
// 原图原来的 z:合并后要落回原位(v1.13 起原图不再被强制压到最底,不能 unshift)
const baseZ = baseUnit ? (baseUnit.obj.z || 0) : 0
if (baseUnit) {
carrier = baseUnit.obj
// 合并后它就是纯像素层:断掉 image/sourceCanvas,避免后续按原图重新重绘
@@ -1190,9 +1191,10 @@ export function setActiveLayer(id) {
carrier._bounds = undefined
composeUnitsInto(carrier, sorted)
for (const u of sorted) if (u.obj !== carrier) dropUnit(u)
// base 永远压在最底,其余层保持原有相对顺序
// 落回原图原来的叠放位置:低于它的层留在它下面(v1.13 允许原图上面压着别的层)
const rest = layerUnits().filter(u => u.obj !== carrier)
rest.unshift({ kind: 'bitmap', obj: carrier })
const at = rest.filter(u => (u.obj.z || 0) < baseZ).length
rest.splice(Math.min(at, rest.length), 0, { kind: 'bitmap', obj: carrier })
assignLayerZ(rest)
} else {
const canvas = createLayerCanvas()
+4 -6
View File
@@ -15,7 +15,7 @@ import { drawPlacementPreview } from './placement.js'
import { drawShape, setTool } from './tools.js'
import { saveSnapshot, snapshotState } from './history.js'
import { toast } from './commands.js'
import { renderOptionBar, updateLayerUI } from './events.js'
import { renderOptionBar } from './events.js'
import { fontOf, newTextStyle, textBox } from './text.js'
import { drawGuides } from './snap.js'
import { isDrawableLayer } from '../vendor/layer-logic.js'
@@ -251,12 +251,11 @@ import { isDrawableLayer } from '../vendor/layer-logic.js'
if (!sel) { toast('先在画布或图层面板选中要调整的元素', 'info'); return }
if (sel.obj.locked || sel.obj.id === 'base') return
const units = layerUnits()
// base 是锁定且不透明的底图,固定在最下层;任何元素都不许置底到它下面(否则等于消失)
const baseIdx = units.findIndex(u => u.obj.id === 'base')
if (baseIdx > 0) { const [b] = units.splice(baseIdx, 1); units.unshift(b) }
// v1.13:不再把原图钉在最底层 —— 「置底」可以真的沉到原图下面(垫背景层的常见用法)。
// 原图行本身仍不可参与(上面已 return),避免把底图整层挪走。
const from = units.findIndex(u => u.obj === sel.obj)
if (from < 0) return
const min = baseIdx >= 0 ? 1 : 0
const min = 0
let to
if (dir === 'up') to = Math.min(from + 1, units.length - 1)
else if (dir === 'down') to = Math.max(from - 1, min)
@@ -500,7 +499,6 @@ import { isDrawableLayer } from '../vendor/layer-logic.js'
const penShape = getPenEditingShape()
if (penShape) drawPenEditOverlay(penShape)
if (S.cropRect) drawCropPreview()
updateLayerUI()
}
// ============ 钢笔二次编辑(移动/添加/删除节点) ============