feat(image-annotate): v1.15.0 右侧栏「图片调节」11 项 + 快速效果强度修正
用户要「添加基本的图片调节能力到右边栏,同时优化现在的效果,效果现在弱了一些」。 ## 图片调节(新 adjust.js,作用于当前位图图层,默认原图) 曝光 ±100(±2EV)/ 明度 / 对比度 / 阴影 / 高光 / 色相 ±180° / 饱和度 / 温度 / 色调 / 锐度 / 清晰度,单行紧凑布局(240px 侧栏 11 项只占约 240px 高)。 拖滑杆实时预览、松手精细、双击归零、右上全部复位。 ## 为什么走 getImageData 而不是 ctx.filter CSS filter 只有 brightness/contrast/saturate/hue-rotate/blur,做不到: 阴影/高光(要按亮度开软蒙版分区)、白平衡(要 R/B、G/M 通道分别增益)、 锐化(要 USM 卷积)。所以只能逐像素。 ## 性能:拖动降到 900 长边预览,松手才全量 实测全量耗时(边长 / 像素 / 毫秒):800²/0.6M/6.7 · 1200²/1.4M/12.8 · 2000²/4.0M/36.8 · 4000²/16M/144.6。 4000×3000 实测:纯调色全量 64ms;叠锐度 287ms;叠清晰度 343ms; 首次(建 source + preview 缓存)256ms。锐度默认 0,不主动拉就不走 USM。 ## 两个必须守住的坑(都写成用例了) 1. 不叠加:source 存调节前像素,每次从它重算;每层 sourceCache 另存,切层往返 也不会拿「调过的像素」当新基准。 2. 撤销后归零:历史只存像素快照、不存调节基准。撤销还原了像素而滑块还停 +80 的话, 再拖一次就从错误基准算,等于调两遍。规则:撤销一步 = 调整作废、滑块归零、基准重拍。 ## 效果强度 「增强」原 brightness(1.12) contrast(1.1) saturate(1.06),截图对比几乎看不出变化 —— 这就是用户说的「效果弱」。改 1.4 / 1.25 / 1.2;「高对比」contrast 1.4 → 1.6。 回归:harness 199 → 208 全通(新增 9 条),validate 9/9。 踩到的用例坑:① 前面效果用例把原图栅格化并隐藏,调色要先用「还原原图」回到单层; ② 历史栈有容量上限,push 到底后「进一条淘汰一条」,长度永远不变,数标签次数才准。
This commit is contained in:
1 parent
1dc423c025
commit
240d02684a
14 files changed
+1357
-17
No files matched your search
@@ -1946,6 +1946,76 @@
|
||||
.iwb-editor-fx-range:disabled::-moz-range-thumb { background: #585b70; }
|
||||
.iwb-editor-fx-range:focus-visible { outline: 2px solid #89b4fa; outline-offset: 2px; }
|
||||
|
||||
/* ================================================================
|
||||
v1.15:图片调节面板
|
||||
11 项挤在 240px 侧栏里,必须单行紧凑:名称 46 / 滑杆 flex / 数值 36。
|
||||
调过的项把名称染成橙色 —— 一屏 11 项,不标出来根本看不出哪几项被动过。
|
||||
================================================================ */
|
||||
.iwb-editor-adj {
|
||||
display: flex; flex-direction: column; gap: 7px;
|
||||
padding: 9px 10px 8px; border-radius: 10px;
|
||||
background: #1e1e2c; border: 1px solid #2f2f42;
|
||||
}
|
||||
.iwb-editor-adj-head {
|
||||
display: flex; align-items: center; gap: 6px;
|
||||
}
|
||||
.iwb-editor-adj-title {
|
||||
font-size: 11.5px; font-weight: 600; color: #cdd6f4; flex: 0 0 auto;
|
||||
}
|
||||
.iwb-editor-adj-target {
|
||||
font-size: 10px; color: #7f87a3; flex: 1 1 auto;
|
||||
overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
|
||||
}
|
||||
.iwb-editor-adj-reset {
|
||||
flex: 0 0 auto; padding: 2px 7px; border-radius: 5px;
|
||||
background: #26263a; border: 1px solid #3a3a52; color: #b9c0d8;
|
||||
font: 500 10px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", sans-serif;
|
||||
cursor: pointer; transition: background 0.12s ease, color 0.12s ease;
|
||||
}
|
||||
.iwb-editor-adj-reset:hover:not(:disabled) { background: #33334c; color: #f3dcb0; border-color: #e8a735; }
|
||||
.iwb-editor-adj-reset:disabled { opacity: 0.4; cursor: default; }
|
||||
.iwb-editor-adj.is-dirty .iwb-editor-adj-title { color: #e8a735; }
|
||||
.iwb-editor-adj-list { display: flex; flex-direction: column; gap: 1px; }
|
||||
.iwb-editor-adj-row {
|
||||
display: grid; grid-template-columns: 46px 1fr 36px;
|
||||
align-items: center; gap: 6px; padding: 1px 0;
|
||||
}
|
||||
.iwb-editor-adj-name {
|
||||
font-size: 10px; color: #b9c0d8; white-space: nowrap;
|
||||
cursor: pointer; user-select: none; overflow: hidden; text-overflow: ellipsis;
|
||||
}
|
||||
.iwb-editor-adj-row.is-set .iwb-editor-adj-name { color: #e8a735; }
|
||||
.iwb-editor-adj-range {
|
||||
-webkit-appearance: none; appearance: none;
|
||||
width: 100%; height: 14px; margin: 0; background: transparent; cursor: pointer;
|
||||
}
|
||||
.iwb-editor-adj-range::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: #313244; }
|
||||
.iwb-editor-adj-range::-webkit-slider-thumb {
|
||||
-webkit-appearance: none; appearance: none;
|
||||
width: 11px; height: 11px; margin-top: -3.5px; border-radius: 50%;
|
||||
background: #e8a735; border: 1px solid #1e1e2c;
|
||||
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
|
||||
}
|
||||
.iwb-editor-adj-range::-moz-range-track { height: 4px; border-radius: 2px; background: #313244; }
|
||||
.iwb-editor-adj-range::-moz-range-thumb {
|
||||
width: 11px; height: 11px; border-radius: 50%; background: #e8a735; border: 1px solid #1e1e2c;
|
||||
}
|
||||
.iwb-editor-adj-range:focus-visible { outline: 2px solid #89b4fa; outline-offset: 2px; }
|
||||
.iwb-editor-adj-val {
|
||||
width: 36px; padding: 1px 2px; text-align: center;
|
||||
background: #26263a; border: 1px solid #3a3a52; border-radius: 4px;
|
||||
color: #cdd6f4; font: 500 10px/1.4 -apple-system, BlinkMacSystemFont, "PingFang SC", sans-serif;
|
||||
font-variant-numeric: tabular-nums;
|
||||
-moz-appearance: textfield;
|
||||
}
|
||||
.iwb-editor-adj-val::-webkit-outer-spin-button,
|
||||
.iwb-editor-adj-val::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
|
||||
.iwb-editor-adj-val:focus { outline: none; border-color: #89b4fa; }
|
||||
.iwb-editor-adj-row.is-set .iwb-editor-adj-val { color: #f3dcb0; border-color: #4a4433; }
|
||||
.iwb-editor-adj-tip {
|
||||
margin: 0; font-size: 9.5px; line-height: 1.4; color: #6c7390;
|
||||
}
|
||||
|
||||
/* ================================================================
|
||||
v1.6:图层面板多选(⌘/Ctrl 点击)+ 合并按钮
|
||||
多选用青色侧条与单选(橙色 #e8a735)区分:一个图层可以「被选中但不在合并集合里」,
|
||||
|
||||
@@ -0,0 +1,505 @@
|
||||
/* adjust.js - 图片调节(v1.15)
|
||||
*
|
||||
* 和 effects.js 的分工:
|
||||
* effects.js = 一键效果(反白/灰度/马赛克……),语义是「换成另一种图」;
|
||||
* adjust.js = 连续调色(曝光/对比度/白平衡……),语义是「把这张图调好看」。
|
||||
* 两者都作用在当前位图图层,都保留 source 只重算不叠加。
|
||||
*
|
||||
* === 为什么不用 ctx.filter ===
|
||||
* CSS filter 只有 brightness/contrast/saturate/hue-rotate/blur 这几种全局线性变换,做不到:
|
||||
* · 阴影 / 高光 —— 需要按亮度做软蒙版分区提亮压暗;
|
||||
* · 白平衡温度 / 色调 —— 需要 R/B、G/M 通道分别增益;
|
||||
* · 锐度 / 清晰度 —— USM 反遮罩,需要卷积。
|
||||
* 所以走 getImageData 逐像素。代价是耗时随像素数线性增长(实测):
|
||||
* 800² 6.7ms · 1200² 12.8ms · 2000² 36.8ms · 4000² 144.6ms
|
||||
* 因此拖动滑杆时用「降采样预览」(长边 ≤ PREVIEW_SIDE,一张小图反复算),
|
||||
* 松手(change)才用原尺寸算一次。这是 PS 的常规做法,观感上只在松手瞬间有一帧停顿。
|
||||
*
|
||||
* === 非破坏性怎么保证 ===
|
||||
* S.adjust.source 存「开始调节前」的原尺寸像素,preview 存它的降采样副本。
|
||||
* 每次参数变化都从 source 重算,绝不在上一次结果上叠加 —— 否则来回拖滑杆会
|
||||
* 层层累积、越拖越糊(effects.js 里同样的坑,注释里记过)。
|
||||
*/
|
||||
|
||||
'use strict'
|
||||
|
||||
import { S, runtime } from './state.js'
|
||||
import { saveSnapshot } from './history.js'
|
||||
import { getActiveLayer, renderLayerPanel } from './layers.js'
|
||||
import { needsPixelSnapshot } from '../vendor/layer-logic.js'
|
||||
import { toast } from './commands.js'
|
||||
|
||||
/** 拖动预览用的最长边:0.6M 像素,实测 6.7ms,够 60fps */
|
||||
const PREVIEW_SIDE = 900
|
||||
/** 图本身小于这个边长就无需降采样,直接全量算 */
|
||||
const DIRECT_SIDE = 1100
|
||||
|
||||
/**
|
||||
* 参数表。范围按「拉满要有明显变化」定,不是摆设:
|
||||
* 曝光 ±100 = ±2 档(×4 / ÷4),对比度 ±100 = 0~2 倍,饱和度 ±100 = 0~2 倍。
|
||||
* 上一版快速效果「增强」拉满只有 brightness(1.12),用户反馈「效果弱」就是这么来的。
|
||||
*/
|
||||
export const ADJUST_DEFS = [
|
||||
{ key: 'exposure', label: '曝光', min: -100, max: 100, step: 1, def: 0 },
|
||||
{ key: 'brightness', label: '明度', min: -100, max: 100, step: 1, def: 0 },
|
||||
{ key: 'contrast', label: '对比度', min: -100, max: 100, step: 1, def: 0 },
|
||||
{ key: 'shadows', label: '阴影', min: -100, max: 100, step: 1, def: 0 },
|
||||
{ key: 'highlights', label: '高光', min: -100, max: 100, step: 1, def: 0 },
|
||||
{ key: 'hue', label: '色相', min: -180, max: 180, step: 1, def: 0, suffix: '°' },
|
||||
{ key: 'saturation', label: '饱和度', min: -100, max: 100, step: 1, def: 0 },
|
||||
{ key: 'temp', label: '温度', title: '白平衡温度:往右偏暖(黄),往左偏冷(蓝)', min: -100, max: 100, step: 1, def: 0 },
|
||||
{ key: 'tint', label: '色调', title: '白平衡色调:往右偏品红,往左偏绿', min: -100, max: 100, step: 1, def: 0 },
|
||||
{ key: 'sharpen', label: '锐度', min: 0, max: 100, step: 1, def: 0 },
|
||||
{ key: 'clarity', label: '清晰度', min: -100, max: 100, step: 1, def: 0 }
|
||||
]
|
||||
|
||||
export const ADJUST_KEYS = ADJUST_DEFS.map(d => d.key)
|
||||
|
||||
export function zeroAdjust() {
|
||||
const o = {}
|
||||
for (const k of ADJUST_KEYS) o[k] = 0
|
||||
return o
|
||||
}
|
||||
|
||||
/** 全部参数都是 0 = 没调过,直接跳过整趟像素运算 */
|
||||
export function isNeutral(p) {
|
||||
if (!p) return true
|
||||
for (const k of ADJUST_KEYS) if (p[k]) return false
|
||||
return true
|
||||
}
|
||||
|
||||
/** 调节目标:当前活跃位图图层;没有就退回「原图」(与 effects.js 同规则) */
|
||||
function adjustTarget() {
|
||||
const active = getActiveLayer()
|
||||
if (active) return active
|
||||
return S.layers.find(l => l.id === 'base') || null
|
||||
}
|
||||
|
||||
function copyCanvas(src, maxSide) {
|
||||
const w0 = src.width, h0 = src.height
|
||||
let w = w0, h = h0
|
||||
if (maxSide && Math.max(w0, h0) > maxSide) {
|
||||
const k = maxSide / Math.max(w0, h0)
|
||||
w = Math.max(1, Math.round(w0 * k))
|
||||
h = Math.max(1, Math.round(h0 * k))
|
||||
}
|
||||
const c = document.createElement('canvas')
|
||||
c.width = w
|
||||
c.height = h
|
||||
const ctx = c.getContext('2d', { willReadFrequently: true })
|
||||
ctx.imageSmoothingEnabled = true
|
||||
ctx.imageSmoothingQuality = 'high'
|
||||
ctx.drawImage(src, 0, 0, w, h)
|
||||
return c
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------- 像素调色 */
|
||||
|
||||
/**
|
||||
* 逐像素处理。顺序有讲究:
|
||||
* 白平衡 → 曝光 → 阴影/高光 → 对比度 → 饱和度 → 色相
|
||||
* 先修色偏再谈明暗,先把动态范围拉开再调饱和,否则「先加饱和后压对比」会把
|
||||
* 颜色压成一片灰。色相放最后,因为它作用在已经很干净的色相上。
|
||||
*/
|
||||
function adjustPixels(ctx, w, h, p) {
|
||||
const img = ctx.getImageData(0, 0, w, h)
|
||||
const d = img.data
|
||||
|
||||
const ev = p.exposure ? Math.pow(2, p.exposure / 50) : 1
|
||||
const add = (p.brightness / 100) * 0.45
|
||||
const con = 1 + p.contrast / 100
|
||||
const sh = p.shadows / 100
|
||||
const hi = p.highlights / 100
|
||||
const sat = 1 + p.saturation / 100
|
||||
const wbR = 1 + p.temp / 250 + p.tint / 500
|
||||
const wbG = 1 - p.tint / 400
|
||||
const wbB = 1 - p.temp / 250 + p.tint / 500
|
||||
const wb = Boolean(p.temp || p.tint)
|
||||
const needSh = Boolean(sh)
|
||||
const needHi = Boolean(hi)
|
||||
const needCon = Boolean(p.contrast)
|
||||
const needSat = Boolean(p.saturation)
|
||||
const needHue = Boolean(p.hue)
|
||||
|
||||
// 色相旋转矩阵(与 CSS hue-rotate 同一套系数),预算好避免每像素算三角函数
|
||||
let h0 = 0, h1 = 0, h2 = 0, h3 = 0, h4 = 0, h5 = 0, h6 = 0, h7 = 0, h8 = 0
|
||||
if (needHue) {
|
||||
const a = (p.hue * Math.PI) / 180
|
||||
const c = Math.cos(a), s = Math.sin(a)
|
||||
h0 = 0.213 + c * 0.787 - s * 0.213
|
||||
h1 = 0.715 - c * 0.715 - s * 0.715
|
||||
h2 = 0.072 - c * 0.072 + s * 0.928
|
||||
h3 = 0.213 - c * 0.213 + s * 0.143
|
||||
h4 = 0.715 + c * 0.285 + s * 0.140
|
||||
h5 = 0.072 - c * 0.072 - s * 0.283
|
||||
h6 = 0.213 - c * 0.213 - s * 0.787
|
||||
h7 = 0.715 - c * 0.715 + s * 0.715
|
||||
h8 = 0.072 + c * 0.928 + s * 0.072
|
||||
}
|
||||
|
||||
// 全部为 0 的短路:只做一次遍历判断,省掉逐像素分支
|
||||
const trivial = !wb && !p.exposure && !add && !needSh && !needHi && !needCon && !needSat && !needHue
|
||||
if (trivial) return
|
||||
|
||||
for (let i = 0; i < d.length; i += 4) {
|
||||
let r = d[i] / 255, g = d[i + 1] / 255, b = d[i + 2] / 255
|
||||
|
||||
if (wb) { r *= wbR; g *= wbG; b *= wbB }
|
||||
if (ev !== 1) { r *= ev; g *= ev; b *= ev }
|
||||
if (add) { r += add; g += add; b += add }
|
||||
|
||||
// 阴影/高光:按当前亮度给一个软蒙版。阴影权重 (1-l)²,高光 l²,
|
||||
// 这样中间调几乎不动,只有暗部/亮部两端被推 —— 硬阈值会在边界留下可见台阶。
|
||||
if (needSh || needHi) {
|
||||
const l = 0.2126 * r + 0.7152 * g + 0.0722 * b
|
||||
if (needSh) {
|
||||
const m = (1 - l) * (1 - l) * sh * 0.85
|
||||
r += m; g += m; b += m
|
||||
}
|
||||
if (needHi) {
|
||||
const m = l * l * hi * 0.85
|
||||
r += m; g += m; b += m
|
||||
}
|
||||
}
|
||||
|
||||
if (needCon) {
|
||||
r = (r - 0.5) * con + 0.5
|
||||
g = (g - 0.5) * con + 0.5
|
||||
b = (b - 0.5) * con + 0.5
|
||||
}
|
||||
|
||||
if (needSat) {
|
||||
const l = 0.2126 * r + 0.7152 * g + 0.0722 * b
|
||||
r = l + (r - l) * sat
|
||||
g = l + (g - l) * sat
|
||||
b = l + (b - l) * sat
|
||||
}
|
||||
|
||||
if (needHue) {
|
||||
const nr = h0 * r + h1 * g + h2 * b
|
||||
const ng = h3 * r + h4 * g + h5 * b
|
||||
const nb = h6 * r + h7 * g + h8 * b
|
||||
r = nr; g = ng; b = nb
|
||||
}
|
||||
|
||||
d[i] = r <= 0 ? 0 : (r >= 1 ? 255 : r * 255)
|
||||
d[i + 1] = g <= 0 ? 0 : (g >= 1 ? 255 : g * 255)
|
||||
d[i + 2] = b <= 0 ? 0 : (b >= 1 ? 255 : b * 255)
|
||||
}
|
||||
ctx.putImageData(img, 0, 0)
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------- 锐化 */
|
||||
|
||||
/**
|
||||
* USM 反遮罩:result = src + (src - blur) * amount。
|
||||
* 锐度用 1px 半径(找边缘),清晰度用更大的半径 + 更低强度(找中间调的体积感)。
|
||||
* 降采样预览时半径要跟着缩放,否则 900px 的预览用 1px 和原图 1px 视觉上不是一回事。
|
||||
*/
|
||||
function unsharp(canvas, radius, amount) {
|
||||
if (!(amount > 0)) return
|
||||
const w = canvas.width, h = canvas.height
|
||||
const blur = document.createElement('canvas')
|
||||
blur.width = w
|
||||
blur.height = h
|
||||
const bc = blur.getContext('2d', { willReadFrequently: true })
|
||||
bc.filter = 'blur(' + radius.toFixed(2) + 'px)'
|
||||
bc.drawImage(canvas, 0, 0)
|
||||
|
||||
const ctx = canvas.getContext('2d', { willReadFrequently: true })
|
||||
const src = ctx.getImageData(0, 0, w, h)
|
||||
const bl = bc.getImageData(0, 0, w, h)
|
||||
const a = src.data, b = bl.data
|
||||
for (let i = 0; i < a.length; i += 4) {
|
||||
// 透明像素不参与(位图层的空白区域),否则边缘会被锐出一圈黑边
|
||||
if (a[i + 3] === 0) continue
|
||||
for (let c = 0; c < 3; c++) {
|
||||
const v = a[i + c] + (a[i + c] - b[i + c]) * amount
|
||||
a[i + c] = v <= 0 ? 0 : (v >= 255 ? 255 : v)
|
||||
}
|
||||
}
|
||||
ctx.putImageData(src, 0, 0)
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------- 渲染 */
|
||||
|
||||
/** 把参数应用到一张画布上(画布尺寸决定锐化半径的缩放) */
|
||||
function paint(canvas, p, refSide) {
|
||||
const ctx = canvas.getContext('2d', { willReadFrequently: true })
|
||||
adjustPixels(ctx, canvas.width, canvas.height, p)
|
||||
|
||||
const k = Math.max(canvas.width, canvas.height) / (refSide || Math.max(canvas.width, canvas.height))
|
||||
if (p.sharpen > 0) unsharp(canvas, Math.max(0.6, 1 * k), (p.sharpen / 100) * 1.1)
|
||||
if (p.clarity) {
|
||||
// 负清晰度 = 柔化中间调,同样走 USM,只是 amount 为负
|
||||
unsharp(canvas, Math.max(1.5, 6 * k), (p.clarity / 100) * 0.55)
|
||||
}
|
||||
}
|
||||
|
||||
function blit(target, src) {
|
||||
const ctx = target.getContext('2d')
|
||||
ctx.save()
|
||||
ctx.setTransform(1, 0, 0, 1, 0, 0)
|
||||
ctx.globalAlpha = 1
|
||||
ctx.globalCompositeOperation = 'copy'
|
||||
ctx.filter = 'none'
|
||||
ctx.imageSmoothingEnabled = true
|
||||
ctx.imageSmoothingQuality = 'high'
|
||||
ctx.drawImage(src, 0, 0, target.width, target.height)
|
||||
ctx.restore()
|
||||
target._bounds = undefined
|
||||
S.pickerComposite = null
|
||||
}
|
||||
|
||||
/**
|
||||
* 从 source 重算并写回目标层。
|
||||
* preview=true 走降采样:拖动滑杆时只要「看得出往哪边变」,不需要像素级准确。
|
||||
*/
|
||||
function renderAdjust(preview) {
|
||||
const st = S.adjust
|
||||
if (!st || !st.source) return false
|
||||
const target = S.layers.find(l => l.id === st.layerId)
|
||||
if (!target) return false
|
||||
|
||||
const src = preview && st.previewCanvas ? st.previewCanvas : st.source
|
||||
const work = copyCanvas(src)
|
||||
paint(work, st.params, Math.max(st.source.width, st.source.height))
|
||||
blit(target.canvas, work)
|
||||
return true
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------- 对外 */
|
||||
|
||||
/**
|
||||
* 每层的「调节前基准像素」缓存。
|
||||
* 为什么需要它:A 层调过 → 切到 B 层调 → 切回 A 层再调。此时 A 的 canvas 里已经
|
||||
* 是调节后的像素,若拿它当新基准,第二次调整就叠在第一次结果上(来回拖会越调越脏,
|
||||
* effects.js 注释里记过同样的坑)。缓存不进图层对象,因此不会被历史快照深拷贝。
|
||||
*/
|
||||
const sourceCache = new Map()
|
||||
|
||||
function captureFor(layer) {
|
||||
const hit = sourceCache.get(layer.id)
|
||||
if (hit) return hit
|
||||
const rec = {
|
||||
source: copyCanvas(layer.canvas, 0),
|
||||
previewCanvas: copyCanvas(layer.canvas, PREVIEW_SIDE)
|
||||
}
|
||||
sourceCache.set(layer.id, rec)
|
||||
return rec
|
||||
}
|
||||
|
||||
/** 切换调节目标:旧层基准入缓存,新层取缓存或现拍,参数按层恢复 */
|
||||
function switchTarget(layer) {
|
||||
const st = S.adjust
|
||||
if (st && st.layerId && st.source) {
|
||||
sourceCache.set(st.layerId, { source: st.source, previewCanvas: st.previewCanvas })
|
||||
}
|
||||
const rec = captureFor(layer)
|
||||
S.adjust = {
|
||||
layerId: layer.id,
|
||||
source: rec.source,
|
||||
previewCanvas: rec.previewCanvas,
|
||||
params: layer.adjustParams ? { ...layer.adjustParams } : zeroAdjust()
|
||||
}
|
||||
}
|
||||
|
||||
/** 参数写回图层对象:切层回来能显示「这层调成了什么样」 */
|
||||
function persistParams() {
|
||||
const st = S.adjust
|
||||
if (!st || !st.layerId || !st.params) return
|
||||
const layer = S.layers.find(l => l.id === st.layerId)
|
||||
if (layer) layer.adjustParams = { ...st.params }
|
||||
}
|
||||
|
||||
/** 确保当前目标层有一份可重算的基准像素 */
|
||||
export function ensureAdjustTarget() {
|
||||
let layer = adjustTarget()
|
||||
if (!layer) { toast('没有可调节的图层'); return null }
|
||||
if (layer.visible === false) {
|
||||
toast('「' + layer.name + '」已隐藏,先显示再调节')
|
||||
return null
|
||||
}
|
||||
|
||||
if (!needsPixelSnapshot(layer)) layer = rasterizeForAdjust(layer)
|
||||
if (!layer) { toast('栅格化失败,调节未应用'); return null }
|
||||
|
||||
if (!S.adjust || S.adjust.layerId !== layer.id || !S.adjust.source) switchTarget(layer)
|
||||
return layer
|
||||
}
|
||||
|
||||
/** 导入图片层原地改像素会被下次重绘冲掉 —— 先复制一层普通位图(与 effects.js 同策略) */
|
||||
function rasterizeForAdjust(layer) {
|
||||
const canvas = document.createElement('canvas')
|
||||
canvas.width = S.imgW
|
||||
canvas.height = S.imgH
|
||||
const ctx = canvas.getContext('2d', { willReadFrequently: true })
|
||||
ctx.drawImage(layer.canvas, 0, 0)
|
||||
|
||||
const copy = {
|
||||
id: 'adj' + Date.now() + Math.floor(Math.random() * 1000),
|
||||
name: layer.name + ' · 调节',
|
||||
canvas, ctx,
|
||||
opacity: layer.opacity == null ? 1 : layer.opacity,
|
||||
visible: true, locked: false,
|
||||
x: 0, y: 0, w: S.imgW, h: S.imgH,
|
||||
rotation: 0,
|
||||
z: (layer.z || 0) + 0.5
|
||||
}
|
||||
S.layers.push(copy)
|
||||
layer.visible = false
|
||||
if (S.selectedLayerId === layer.id) S.selectedLayerId = copy.id
|
||||
S.activeLayerId = copy.id
|
||||
renderLayerPanel()
|
||||
return copy
|
||||
}
|
||||
|
||||
/** 参数变了:重算并画到画布上。preview=true 用降采样 */
|
||||
export function applyAdjust(preview) {
|
||||
if (!S.adjust || !S.adjust.source) return false
|
||||
const ok = renderAdjust(Boolean(preview))
|
||||
if (ok) {
|
||||
persistParams()
|
||||
if (S.renderAll) S.renderAll()
|
||||
}
|
||||
renderAdjustPanel()
|
||||
return ok
|
||||
}
|
||||
|
||||
/** 单个参数变化 */
|
||||
export function setAdjustValue(key, value, preview) {
|
||||
const st = S.adjust
|
||||
if (!st || !st.source) return false
|
||||
const def = ADJUST_DEFS.find(d => d.key === key)
|
||||
if (!def) return false
|
||||
const v = Math.min(def.max, Math.max(def.min, Number(value) || 0))
|
||||
st.params[key] = v
|
||||
applyAdjust(preview)
|
||||
return true
|
||||
}
|
||||
|
||||
/** 复位:单条 or 全部 */
|
||||
export function resetAdjust(key) {
|
||||
const st = S.adjust
|
||||
if (!st || !st.source) return false
|
||||
saveSnapshot('调节复位')
|
||||
if (key) st.params[key] = 0
|
||||
else st.params = zeroAdjust()
|
||||
applyAdjust(false)
|
||||
syncAdjustControls()
|
||||
return true
|
||||
}
|
||||
|
||||
/** 有没有调过(用于「复位」按钮的可用态与标题提示) */
|
||||
export function adjustDirty() {
|
||||
return Boolean(S.adjust && S.adjust.source && !isNeutral(S.adjust.params))
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------- UI */
|
||||
|
||||
/**
|
||||
* 按 ADJUST_DEFS 生成 11 行控件,只做一次(面板是静态的,之后只改 value / 类名)。
|
||||
* 单行紧凑布局:名称 46px + 滑杆 flex + 数值 36px —— 240px 侧栏里 11 项只占约 240px 高,
|
||||
* 不需要把侧栏撑成一整屏滚动。
|
||||
*/
|
||||
export function mountAdjustPanel() {
|
||||
if (!runtime.el) return
|
||||
const list = runtime.el.querySelector('.iwb-editor-adj-list')
|
||||
if (!list || list.childElementCount) return
|
||||
list.innerHTML = ADJUST_DEFS.map(d => `
|
||||
<div class="iwb-editor-adj-row" data-adj="${d.key}">
|
||||
<span class="iwb-editor-adj-name" title="${d.title || d.label}${d.suffix ? '' : ''}(双击归零)">${d.label}</span>
|
||||
<input type="range" class="iwb-editor-adj-range" min="${d.min}" max="${d.max}" step="${d.step}" value="${d.def}" aria-label="${d.title || d.label}">
|
||||
<input type="number" class="iwb-editor-adj-val" min="${d.min}" max="${d.max}" step="${d.step}" value="${d.def}" aria-label="${d.title || d.label}数值">
|
||||
</div>`).join('')
|
||||
renderAdjustPanel()
|
||||
}
|
||||
|
||||
/** 面板里的 target 层名 + 复位按钮可用态 */
|
||||
export function renderAdjustPanel() {
|
||||
if (!runtime.el) return
|
||||
const sec = runtime.el.querySelector('.iwb-editor-adj')
|
||||
if (!sec) return
|
||||
const layer = adjustTarget()
|
||||
|
||||
// 目标层被切走:面板跟着换到新层(参数按层恢复、新的基准),旧层的像素不动。
|
||||
// 必须在这里兜住 —— 图层切换走的是 layers.js,那边不能 import 本模块(会形成循环)。
|
||||
if (layer && S.adjust && S.adjust.layerId && S.adjust.layerId !== layer.id) {
|
||||
switchTarget(layer)
|
||||
syncAdjustControls()
|
||||
return
|
||||
}
|
||||
|
||||
const nameEl = sec.querySelector('.iwb-editor-adj-target')
|
||||
if (nameEl) {
|
||||
const name = layer ? layer.name : '无图层'
|
||||
nameEl.textContent = name
|
||||
nameEl.title = layer ? '调节作用于「' + name + '」' : '没有可调节的位图图层'
|
||||
}
|
||||
const dirty = adjustDirty()
|
||||
sec.classList.toggle('is-dirty', dirty)
|
||||
const reset = sec.querySelector('[data-adj-reset="all"]')
|
||||
if (reset) reset.disabled = !dirty
|
||||
sec.querySelectorAll('.iwb-editor-adj-row').forEach(row => {
|
||||
const k = row.dataset.adj
|
||||
const v = S.adjust && S.adjust.params ? S.adjust.params[k] || 0 : 0
|
||||
row.classList.toggle('is-set', Boolean(v))
|
||||
})
|
||||
}
|
||||
|
||||
/** 把 S.adjust.params 写回所有滑杆与数值框(复位后调用) */
|
||||
export function syncAdjustControls() {
|
||||
if (!runtime.el) return
|
||||
const sec = runtime.el.querySelector('.iwb-editor-adj')
|
||||
if (!sec || !S.adjust || !S.adjust.params) return
|
||||
sec.querySelectorAll('.iwb-editor-adj-row').forEach(row => {
|
||||
const k = row.dataset.adj
|
||||
const v = S.adjust.params[k] || 0
|
||||
const range = row.querySelector('.iwb-editor-adj-range')
|
||||
const val = row.querySelector('.iwb-editor-adj-val')
|
||||
if (range) range.value = String(v)
|
||||
if (val) val.value = String(v)
|
||||
})
|
||||
renderAdjustPanel()
|
||||
}
|
||||
|
||||
/** 进入编辑器 / 切换目标层时重建基准 */
|
||||
export function refreshAdjustTarget() {
|
||||
// 只在目标层真的变了才重置基准,否则每次重绘都丢参数
|
||||
const layer = adjustTarget()
|
||||
if (!layer) return
|
||||
const st = S.adjust
|
||||
if (st.source && st.layerId === layer.id) return
|
||||
S.adjust = { layerId: null, source: null, previewCanvas: null, params: zeroAdjust() }
|
||||
renderAdjustPanel()
|
||||
syncAdjustControls()
|
||||
}
|
||||
|
||||
/**
|
||||
* 撤销 / 重做之后。
|
||||
*
|
||||
* 为什么必须归零:调整是「写进像素」的破坏性操作,历史里只存了像素快照,没存
|
||||
* 「调节前的基准」。撤销把像素还原了,但 source 对应的已经不是这个状态 —— 留着
|
||||
* 旧参数只会出现「滑块显示 +80、画面其实没调」。更糟的是下一次拖动会从错误的
|
||||
* 基准重算,等于把调整叠加两遍。
|
||||
*
|
||||
* 所以规则很简单也很可预测:**撤销一步 = 调整作废,滑块归零,基准重拍当前像素**。
|
||||
* 想再调就从现在这张画面上重新调。
|
||||
*/
|
||||
export function onHistoryRestore() {
|
||||
sourceCache.clear()
|
||||
const layer = adjustTarget()
|
||||
if (!layer) {
|
||||
S.adjust = { layerId: null, source: null, previewCanvas: null, params: zeroAdjust() }
|
||||
syncAdjustControls()
|
||||
return
|
||||
}
|
||||
if (layer.adjustParams) delete layer.adjustParams
|
||||
S.adjust = {
|
||||
layerId: layer.id,
|
||||
source: copyCanvas(layer.canvas, 0),
|
||||
previewCanvas: copyCanvas(layer.canvas, PREVIEW_SIDE),
|
||||
params: zeroAdjust()
|
||||
}
|
||||
syncAdjustControls()
|
||||
}
|
||||
@@ -171,6 +171,19 @@ import { bindEvents } from './events.js'
|
||||
<aside class="iwb-editor-left">
|
||||
<!-- 调色板已迁到工具栏弹层(v1.3,用户裁定 2026-11-05):
|
||||
侧栏只留快速效果 + 缩放;色板 DOM 在 modal 末尾的 .iwb-editor-color-pop -->
|
||||
<!-- 图片调节(v1.15):连续调色,作用于当前位图图层(默认原图)。
|
||||
行由 adjust.js#mountAdjustPanel() 按 ADJUST_DEFS 生成 —— 参数表只维护一份,
|
||||
不在 DOM 里再抄一遍(这个项目已经因为「同一个概念两处各写一份」栽过几次)。
|
||||
和下方「快速效果」的分工:这里是精细连续调,那边是一键换风格。 -->
|
||||
<section class="iwb-editor-adj">
|
||||
<div class="iwb-editor-adj-head">
|
||||
<span class="iwb-editor-adj-title">图片调节</span>
|
||||
<span class="iwb-editor-adj-target" title="调节作用于当前位图图层">原图</span>
|
||||
<button type="button" class="iwb-editor-adj-reset" data-adj-reset="all" disabled title="把所有调节项归零(Ctrl+Z 可撤销)">复位</button>
|
||||
</div>
|
||||
<div class="iwb-editor-adj-list"></div>
|
||||
<p class="iwb-editor-adj-tip">拖动实时预览,松手出精细结果 · 双击滑杆归零</p>
|
||||
</section>
|
||||
<!-- 快速效果(v1.4):作用于当前位图图层,点一下就应用,Ctrl+Z 撤销。
|
||||
目标层名由 effects.js 的 updateFxTargetLabel() 实时刷新。 -->
|
||||
<section class="iwb-editor-fx">
|
||||
|
||||
+6
-3
@@ -54,12 +54,15 @@ import { toast } from './commands.js'
|
||||
render: (canvas, v) => { if (v > 0) filterCanvas(canvas, 'grayscale(' + (v / 100) + ')') }
|
||||
},
|
||||
boost: {
|
||||
label: '增强', hint: '提亮并略加对比,适合发灰的截图',
|
||||
label: '增强', hint: '提亮并加对比,适合发灰的截图',
|
||||
param: '强度', unit: '%', min: 0, max: 100, step: 1, def: () => 100,
|
||||
render: (canvas, v) => {
|
||||
if (v <= 0) return
|
||||
const k = v / 100
|
||||
filterCanvas(canvas, 'brightness(' + (1 + 0.12 * k).toFixed(3) + ') contrast(' + (1 + 0.1 * k).toFixed(3) + ') saturate(' + (1 + 0.06 * k).toFixed(3) + ')')
|
||||
// v1.15:旧系数 1+0.12k / 1+0.1k / 1+0.06k 拉满只有 1.12 倍亮度,肉眼看不出变化
|
||||
// (用户反馈「效果现在弱了一些」)。现在拉满 = 1.4 倍亮度 / 1.25 倍对比 / 1.2 倍饱和,
|
||||
// 对应「一眼能看出变亮变通透」,但仍然不过曝 —— 再往上压会先把高光切掉。
|
||||
filterCanvas(canvas, 'brightness(' + (1 + 0.4 * k).toFixed(3) + ') contrast(' + (1 + 0.25 * k).toFixed(3) + ') saturate(' + (1 + 0.2 * k).toFixed(3) + ')')
|
||||
}
|
||||
},
|
||||
contrast: {
|
||||
@@ -68,7 +71,7 @@ import { toast } from './commands.js'
|
||||
render: (canvas, v) => {
|
||||
if (v <= 0) return
|
||||
const k = v / 100
|
||||
filterCanvas(canvas, 'grayscale(' + k.toFixed(3) + ') contrast(' + (1 + 1.4 * k).toFixed(3) + ')')
|
||||
filterCanvas(canvas, 'grayscale(' + k.toFixed(3) + ') contrast(' + (1 + 1.6 * k).toFixed(3) + ')')
|
||||
}
|
||||
},
|
||||
soft: {
|
||||
|
||||
@@ -24,6 +24,7 @@ import { close, copyResult, exportResult } from './index.js'
|
||||
import { loadImage } from './dom.js'
|
||||
import { pushHistory, redo, resetDraw, restoreOriginal, restoreAll, saveSnapshot, snapshotState, undo } from './history.js'
|
||||
import { applyQuickEffect, setEffectValue } from './effects.js'
|
||||
import { applyAdjust, ensureAdjustTarget, mountAdjustPanel, resetAdjust, setAdjustValue, syncAdjustControls } from './adjust.js'
|
||||
import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
||||
|
||||
|
||||
@@ -1775,6 +1776,9 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
||||
if (!root || root.dataset.liteBound === '1') return
|
||||
root.dataset.liteBound = '1'
|
||||
|
||||
// 图片调节面板的行由参数表生成(只做一次),DOM 里只留空容器
|
||||
mountAdjustPanel()
|
||||
|
||||
const closeMenus = () => {
|
||||
const panel = root.querySelector('.iwb-editor-export-settings')
|
||||
if (panel) panel.classList.remove('open')
|
||||
@@ -1785,6 +1789,13 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
||||
// 选区命令(全选/反选/取消)在「选择」工具的选项栏里,与竖工具条时代一样走根级事件委托:
|
||||
// 三个按钮不切换工具,只调命令层(与快捷键、右键菜单同一条路径)。
|
||||
root.addEventListener('click', (e) => {
|
||||
// 图片调节「复位」:所有项归零,同时拍一步历史(resetAdjust 内部做)
|
||||
const adjReset = e.target.closest('[data-adj-reset]')
|
||||
if (adjReset) {
|
||||
e.stopPropagation()
|
||||
if (!adjReset.disabled) resetAdjust()
|
||||
return
|
||||
}
|
||||
// 快速效果(侧栏):点一下即应用,目标层与撤销由 effects.js 负责
|
||||
const fxBtn = e.target.closest('[data-fx]')
|
||||
if (fxBtn) {
|
||||
@@ -1814,17 +1825,71 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js'
|
||||
// 快速效果强度滑杆(v1.8):input 只改像素与该行数字 —— 拖动中每帧重建图层面板会闪,
|
||||
// 缩略图与状态栏交给松开时的 renderAll。用 class 精确匹配,别误伤图层不透明度滑杆。
|
||||
const fxRangeOf = (e) => (e.target && e.target.closest ? e.target.closest('.iwb-editor-fx-range') : null)
|
||||
|
||||
// 图片调节(v1.15):滑杆与数值框共用一条写回路径。
|
||||
// 历史粒度 = 一次拖动一步:第一次 input 拍快照,change 后复位标志(否则整段拖动会
|
||||
// 留下几十步历史,Ctrl+Z 要点半天才回到调之前)。
|
||||
let adjSnapDone = false
|
||||
const adjRowOf = (el) => (el && el.closest ? el.closest('.iwb-editor-adj-row') : null)
|
||||
const adjBegin = () => {
|
||||
if (S.adjust && S.adjust.source) return true
|
||||
return Boolean(ensureAdjustTarget())
|
||||
}
|
||||
const adjSyncTwin = (row, el) => {
|
||||
const range = row.querySelector('.iwb-editor-adj-range')
|
||||
const num = row.querySelector('.iwb-editor-adj-val')
|
||||
if (!range || !num) return
|
||||
if (el === range) num.value = range.value
|
||||
else range.value = String(Number(num.value) || 0)
|
||||
}
|
||||
|
||||
root.addEventListener('input', (e) => {
|
||||
const range = fxRangeOf(e)
|
||||
if (!range) return
|
||||
if (range) {
|
||||
e.stopPropagation()
|
||||
setEffectValue(parseFloat(range.value))
|
||||
return
|
||||
}
|
||||
const adj = e.target.closest ? (e.target.closest('.iwb-editor-adj-range') || e.target.closest('.iwb-editor-adj-val')) : null
|
||||
if (!adj) return
|
||||
const row = adjRowOf(adj)
|
||||
if (!row) return
|
||||
e.stopPropagation()
|
||||
setEffectValue(parseFloat(range.value))
|
||||
if (!adjBegin()) return
|
||||
if (!adjSnapDone) { saveSnapshot('图片调节'); adjSnapDone = true }
|
||||
adjSyncTwin(row, adj)
|
||||
// preview=true:降采样算(长边 900 以内),拖动时不拖慢帧率
|
||||
setAdjustValue(row.dataset.adj, adj.value, true)
|
||||
})
|
||||
root.addEventListener('change', (e) => {
|
||||
const range = fxRangeOf(e)
|
||||
if (!range) return
|
||||
if (range) {
|
||||
e.stopPropagation()
|
||||
if (S.renderAll) S.renderAll()
|
||||
return
|
||||
}
|
||||
const adj = e.target.closest ? (e.target.closest('.iwb-editor-adj-range') || e.target.closest('.iwb-editor-adj-val')) : null
|
||||
if (!adj) return
|
||||
const row = adjRowOf(adj)
|
||||
if (!row) return
|
||||
e.stopPropagation()
|
||||
if (S.renderAll) S.renderAll()
|
||||
if (!S.adjust || !S.adjust.source) return
|
||||
adjSyncTwin(row, adj)
|
||||
// 松手:用原尺寸算一次,出精细结果(大图这一段会有几十~一百多 ms 的停顿,正常)
|
||||
setAdjustValue(row.dataset.adj, adj.value, false)
|
||||
adjSnapDone = false
|
||||
})
|
||||
// 双击名称或滑杆 = 该项归零(截图那种调色面板的通用手势)
|
||||
root.addEventListener('dblclick', (e) => {
|
||||
const hit = e.target.closest ? (e.target.closest('.iwb-editor-adj-name') || e.target.closest('.iwb-editor-adj-range')) : null
|
||||
if (!hit) return
|
||||
const row = adjRowOf(hit)
|
||||
if (!row) return
|
||||
e.stopPropagation()
|
||||
if (!S.adjust || !S.adjust.source) return
|
||||
saveSnapshot('调节归零')
|
||||
setAdjustValue(row.dataset.adj, 0, false)
|
||||
syncAdjustControls()
|
||||
})
|
||||
|
||||
const body = root.querySelector('.iwb-editor-optionbar-body')
|
||||
|
||||
@@ -266,6 +266,7 @@ import { toast } from './commands.js'
|
||||
if (S.history.length === 0) { toast('没有可撤销的操作'); return }
|
||||
pushHistory(S.redoStack, snapshotState())
|
||||
restoreState(S.history.pop())
|
||||
if (S.onHistoryRestore) S.onHistoryRestore()
|
||||
if (S.renderAll) S.renderAll()
|
||||
}
|
||||
|
||||
@@ -275,6 +276,7 @@ import { toast } from './commands.js'
|
||||
if (S.redoStack.length === 0) { toast('没有可重做的操作'); return }
|
||||
pushHistory(S.history, snapshotState())
|
||||
restoreState(S.redoStack.pop())
|
||||
if (S.onHistoryRestore) S.onHistoryRestore()
|
||||
if (S.renderAll) S.renderAll()
|
||||
}
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@ import { updateAllUI, bindLiteUI, renderOptionBar, updateStatusbar } from './eve
|
||||
import { disposeSelection, renderSelection, selectionInfo, syncAnts, registerSelectionCommands } from './selection.js'
|
||||
import { bindFloating, positionFloating, hideSelectionContext } from './floating.js'
|
||||
import { renderFxPanel } from './effects.js'
|
||||
import { onHistoryRestore as onAdjustHistoryRestore, renderAdjustPanel } from './adjust.js'
|
||||
import { loadExportOptions, prepareOutput, downloadBlob, copyBlobToClipboard, bindExportUI, renderExportUI } from './export.js'
|
||||
import { loadRecentColors } from './recent-colors.js'
|
||||
import { toast } from './commands.js'
|
||||
@@ -50,6 +51,9 @@ import { toast } from './commands.js'
|
||||
S.renderAll = renderAll
|
||||
S.positionFloating = positionFloating
|
||||
S.renderFxPanel = renderFxPanel
|
||||
S.renderAdjustPanel = renderAdjustPanel
|
||||
// 撤销/重做后调节参数必须归零(详见 adjust.js#onHistoryRestore 的注释)
|
||||
S.onHistoryRestore = onAdjustHistoryRestore
|
||||
|
||||
try {
|
||||
const img = await loadImage(options.imageBase64)
|
||||
@@ -154,6 +158,8 @@ import { toast } from './commands.js'
|
||||
renderObjects()
|
||||
renderLayerPanel()
|
||||
renderFxPanel()
|
||||
// 调节面板跟着图层走:新建/切换/删除图层都要刷新 target 与滑块值
|
||||
renderAdjustPanel()
|
||||
renderOptionBar()
|
||||
updateStatusbar()
|
||||
renderExportUI()
|
||||
@@ -373,6 +379,12 @@ import { toast } from './commands.js'
|
||||
lastExport: S.lastExport ? { ...S.lastExport } : null,
|
||||
// 快速效果的可重调状态:hasSource=false 表示还没点过效果(滑杆应置灰)
|
||||
fx: { key: S.fx.key, value: S.fx.value, layerId: S.fx.layerId, hasSource: Boolean(S.fx.source) },
|
||||
// v1.15 图片调节:params 是 11 项当前值,hasSource 决定面板是否可用
|
||||
adjust: {
|
||||
layerId: S.adjust ? S.adjust.layerId : null,
|
||||
hasSource: Boolean(S.adjust && S.adjust.source),
|
||||
params: S.adjust && S.adjust.params ? { ...S.adjust.params } : null
|
||||
},
|
||||
interaction: S.interaction,
|
||||
ants: !!S._antFrame,
|
||||
view: S.viewX !== null ? [Math.round(S.viewX), Math.round(S.viewY)] : null,
|
||||
|
||||
@@ -334,6 +334,8 @@ export function setActiveLayer(id) {
|
||||
// 否则用户会在新层上拖出一个属于旧层的像素结果(v1.8)。
|
||||
// 走注入而不是直接 import effects.js —— 后者已经 import 本模块,硬连会成环。
|
||||
if (S.renderFxPanel) S.renderFxPanel()
|
||||
// 图片调节面板同样按「当前层」走:切层后 target 名与滑块值都要换成新层的
|
||||
if (S.renderAdjustPanel) S.renderAdjustPanel()
|
||||
}
|
||||
|
||||
/** 添加位图图层(导入图片)— 便利版:一步落层,不再需要 Enter 二次确认
|
||||
|
||||
@@ -36,6 +36,10 @@
|
||||
// 拖强度滑杆时一律从 source 重算,绝不在上一次结果上叠加(否则来回拖会越拖越糊)。
|
||||
// layerId 用于判断源是否还对得上当前目标层:切层后滑杆自动置灰,切回即恢复。
|
||||
fx: { key: null, value: 0, layerId: null, source: null },
|
||||
// v1.15 图片调节:连续调色(曝光/对比度/白平衡…)。source 是原尺寸基准,
|
||||
// previewCanvas 是它的降采样副本 —— 拖动滑杆用小的算(6.7ms),松手才用原图算(几十~上百 ms)。
|
||||
// 两者都只做「输入」,结果永远从基准重算,不在上一次结果上叠加。
|
||||
adjust: { layerId: null, source: null, previewCanvas: null, params: null },
|
||||
rectFill: false, // 矩形/圆形是否实心填充
|
||||
penFill: true, // 钢笔闭合路径是否实心填充(只对闭合路径有意义)
|
||||
// v1.2 工具参数解耦:形状线宽与文字字号不再借用画笔粗细,
|
||||
@@ -136,6 +140,10 @@
|
||||
exportOptions: null, // { preset, format, bg, maxKB, size },来自 ctx.settings
|
||||
interaction: 'idle', // 轻量交互状态机:idle | marquee | lasso | placing | cropping
|
||||
renderAll: null, // 由 index.js 注入的统一重绘出口
|
||||
// 撤销/重做后由 history.js 调用:调节基准与参数必须跟着历史走,
|
||||
// 否则「撤销把像素还原了、滑杆还显示 +80」—— 参数与画面对不上,再拖一次就叠加。
|
||||
// 用回调而不是直接 import,避免 history ↔ adjust 循环依赖。
|
||||
onHistoryRestore: null,
|
||||
guides: null, // 拖动吸附参考线(图片坐标,松手清空):[{axis:'x'|'y', at, from, to}]
|
||||
lastExport: null // 观测口:{ bytes, width, height, format, preset }
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user