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
+472
-9
@@ -9,7 +9,7 @@
|
||||
var __IWB_ANNOTATE_MANIFEST__ = {
|
||||
id: 'image-annotate',
|
||||
name: '标注 / 修图',
|
||||
version: '1.14.1',
|
||||
version: '1.15.0',
|
||||
apiVersion: 1,
|
||||
capabilities: ['commands', 'nodeActions', 'canvas', 'canvasWrite'],
|
||||
settings: {
|
||||
@@ -210,6 +210,10 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
||||
// 拖强度滑杆时一律从 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,
|
||||
@@ -356,6 +360,10 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
||||
// 轻量交互状态机: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
|
||||
@@ -2214,6 +2222,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
||||
renderLayerPanel();
|
||||
renderObjects();
|
||||
if (S.renderFxPanel) S.renderFxPanel();
|
||||
if (S.renderAdjustPanel) S.renderAdjustPanel();
|
||||
}
|
||||
function addBitmapLayer(img) {
|
||||
placeImageDirectly(img);
|
||||
@@ -3629,6 +3638,19 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
||||
<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">
|
||||
@@ -3829,7 +3851,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
||||
},
|
||||
boost: {
|
||||
label: "增强",
|
||||
hint: "提亮并略加对比,适合发灰的截图",
|
||||
hint: "提亮并加对比,适合发灰的截图",
|
||||
param: "强度",
|
||||
unit: "%",
|
||||
min: 0,
|
||||
@@ -3839,7 +3861,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
||||
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) + ")");
|
||||
filterCanvas(canvas, "brightness(" + (1 + 0.4 * k).toFixed(3) + ") contrast(" + (1 + 0.25 * k).toFixed(3) + ") saturate(" + (1 + 0.2 * k).toFixed(3) + ")");
|
||||
}
|
||||
},
|
||||
contrast: {
|
||||
@@ -3854,7 +3876,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
||||
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: {
|
||||
@@ -4087,6 +4109,380 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
||||
return true;
|
||||
}
|
||||
|
||||
// image-annotate/plugin/editor/adjust.js
|
||||
var PREVIEW_SIDE = 900;
|
||||
var 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 }
|
||||
];
|
||||
var ADJUST_KEYS = ADJUST_DEFS.map((d) => d.key);
|
||||
function zeroAdjust() {
|
||||
const o = {};
|
||||
for (const k of ADJUST_KEYS) o[k] = 0;
|
||||
return o;
|
||||
}
|
||||
function isNeutral(p) {
|
||||
if (!p) return true;
|
||||
for (const k of ADJUST_KEYS) if (p[k]) return false;
|
||||
return true;
|
||||
}
|
||||
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);
|
||||
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.14;
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
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);
|
||||
}
|
||||
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) {
|
||||
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 = void 0;
|
||||
S.pickerComposite = null;
|
||||
}
|
||||
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;
|
||||
}
|
||||
var sourceCache = /* @__PURE__ */ 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 };
|
||||
}
|
||||
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;
|
||||
}
|
||||
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() * 1e3),
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
function adjustDirty() {
|
||||
return Boolean(S.adjust && S.adjust.source && !isNeutral(S.adjust.params));
|
||||
}
|
||||
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();
|
||||
}
|
||||
function renderAdjustPanel() {
|
||||
if (!runtime.el) return;
|
||||
const sec = runtime.el.querySelector(".iwb-editor-adj");
|
||||
if (!sec) return;
|
||||
const layer = adjustTarget();
|
||||
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));
|
||||
});
|
||||
}
|
||||
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();
|
||||
}
|
||||
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();
|
||||
}
|
||||
|
||||
// image-annotate/plugin/editor/events.js
|
||||
var MOUSE_DOWN_HANDLERS = {
|
||||
select: onSelectMouseDown,
|
||||
@@ -5603,6 +5999,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
||||
const root = runtime.el;
|
||||
if (!root || root.dataset.liteBound === "1") return;
|
||||
root.dataset.liteBound = "1";
|
||||
mountAdjustPanel();
|
||||
const closeMenus = () => {
|
||||
const panel = root.querySelector(".iwb-editor-export-settings");
|
||||
if (panel) panel.classList.remove("open");
|
||||
@@ -5610,6 +6007,12 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
||||
if (toggle) toggle.setAttribute("aria-expanded", "false");
|
||||
};
|
||||
root.addEventListener("click", (e) => {
|
||||
const adjReset = e.target.closest("[data-adj-reset]");
|
||||
if (adjReset) {
|
||||
e.stopPropagation();
|
||||
if (!adjReset.disabled) resetAdjust();
|
||||
return;
|
||||
}
|
||||
const fxBtn = e.target.closest("[data-fx]");
|
||||
if (fxBtn) {
|
||||
e.stopPropagation();
|
||||
@@ -5634,17 +6037,66 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
||||
});
|
||||
});
|
||||
const fxRangeOf = (e) => e.target && e.target.closest ? e.target.closest(".iwb-editor-fx-range") : null;
|
||||
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);
|
||||
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);
|
||||
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");
|
||||
if (body) {
|
||||
@@ -7438,6 +7890,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
||||
}
|
||||
pushHistory(S.redoStack, snapshotState());
|
||||
restoreState(S.history.pop());
|
||||
if (S.onHistoryRestore) S.onHistoryRestore();
|
||||
if (S.renderAll) S.renderAll();
|
||||
}
|
||||
function redo() {
|
||||
@@ -7449,6 +7902,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
||||
}
|
||||
pushHistory(S.history, snapshotState());
|
||||
restoreState(S.redoStack.pop());
|
||||
if (S.onHistoryRestore) S.onHistoryRestore();
|
||||
if (S.renderAll) S.renderAll();
|
||||
}
|
||||
function restoreAll() {
|
||||
@@ -7888,6 +8342,8 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
||||
S.renderAll = renderAll;
|
||||
S.positionFloating = positionFloating;
|
||||
S.renderFxPanel = renderFxPanel;
|
||||
S.renderAdjustPanel = renderAdjustPanel;
|
||||
S.onHistoryRestore = onHistoryRestore;
|
||||
try {
|
||||
const img = await loadImage(options.imageBase64);
|
||||
S.imgW = img.naturalWidth || img.width;
|
||||
@@ -7988,6 +8444,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
||||
renderObjects();
|
||||
renderLayerPanel();
|
||||
renderFxPanel();
|
||||
renderAdjustPanel();
|
||||
renderOptionBar();
|
||||
updateStatusbar();
|
||||
renderExportUI();
|
||||
@@ -8193,6 +8650,12 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
||||
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,
|
||||
@@ -8265,7 +8728,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
||||
};
|
||||
|
||||
// image-annotate/plugin/editor.css
|
||||
var editor_default = '/* IWB 鲜艺抠图节点 - 注入样式 */\n\n/* 抠图按钮 */\n.iwb-cutout-btn {\n cursor: pointer;\n opacity: 0.7;\n transition: opacity 0.15s, transform 0.15s;\n}\n\n.iwb-cutout-btn:hover {\n opacity: 1;\n transform: scale(1.15);\n}\n\n.iwb-cutout-btn svg {\n width: 14px;\n height: 14px;\n display: block;\n}\n\n/* 正在处理中的按钮状态 */\n.iwb-cutout-btn.processing {\n animation: iwb-cutout-pulse 1s infinite;\n pointer-events: none;\n}\n\n@keyframes iwb-cutout-pulse {\n 0%, 100% { opacity: 0.4; }\n 50% { opacity: 1; }\n}\n\n/* 全屏遮罩 */\n.iwb-cutout-overlay {\n position: fixed;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n background: rgba(0, 0, 0, 0.25);\n display: none;\n align-items: center;\n justify-content: center;\n flex-direction: column;\n gap: 12px;\n z-index: 999999;\n pointer-events: all;\n backdrop-filter: blur(2px);\n}\n\n/* 自定义按钮提示(挂在 body,最高层级,不会被图片遮挡) */\n#iwb-cutout-tip {\n position: fixed;\n z-index: 2147483647;\n background: rgba(30, 30, 46, 0.95);\n color: #fff;\n padding: 5px 10px;\n border-radius: 6px;\n font-size: 12px;\n line-height: 1.5;\n white-space: nowrap;\n pointer-events: none;\n display: none;\n box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);\n border: 1px solid rgba(255, 255, 255, 0.14);\n font-family: system-ui, -apple-system, "Segoe UI", sans-serif;\n max-width: 320px;\n white-space: normal;\n word-break: break-all;\n}\n\n/* 加载动画 */\n.iwb-cutout-spinner {\n width: 48px;\n height: 48px;\n border: 4px solid rgba(255, 255, 255, 0.3);\n border-top-color: #e8a735;\n border-radius: 50%;\n animation: iwb-cutout-spin 0.8s linear infinite;\n}\n\n@keyframes iwb-cutout-spin {\n to { transform: rotate(360deg); }\n}\n\n/* 遮罩文字 */\n.iwb-cutout-text {\n color: #fff;\n font-size: 14px;\n font-weight: 500;\n text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);\n background: rgba(0, 0, 0, 0.6);\n padding: 8px 16px;\n border-radius: 6px;\n}\n\n/* Toast 提示 */\n.iwb-cutout-toast {\n position: fixed;\n bottom: 24px;\n left: 50%;\n transform: translateX(-50%);\n padding: 10px 20px;\n border-radius: 8px;\n font-size: 13px;\n font-weight: 500;\n z-index: 999999;\n transition: opacity 0.3s;\n box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);\n display: none;\n max-width: 400px;\n}\n\n.iwb-cutout-toast-success {\n background: #1a7f37;\n color: #fff;\n}\n\n.iwb-cutout-toast-error {\n background: #cf222e;\n color: #fff;\n}\n\n.iwb-cutout-toast-info {\n background: #1f6feb;\n color: #fff;\n}\n\n/* 白底按钮 */\n.iwb-whitebg-btn {\n cursor: pointer;\n opacity: 0.7;\n transition: opacity 0.15s, transform 0.15s;\n}\n.iwb-whitebg-btn:hover { opacity: 1; transform: scale(1.15); }\n.iwb-whitebg-btn svg { width: 14px; height: 14px; display: block; }\n.iwb-whitebg-btn.processing { animation: iwb-cutout-pulse 1s infinite; pointer-events: none; }\n\n/* 编辑按钮 */\n.iwb-editor-btn-icon {\n cursor: pointer;\n opacity: 0.7;\n transition: opacity 0.15s, transform 0.15s;\n}\n.iwb-editor-btn-icon:hover { opacity: 1; transform: scale(1.15); }\n.iwb-editor-btn-icon svg { width: 14px; height: 14px; display: block; }\n\n/* ==================== 图片编辑器 ==================== */\n\n.iwb-editor-overlay {\n position: fixed;\n top: 0; left: 0;\n width: 100%; height: 100%;\n background: rgba(0, 0, 0, 0.6);\n display: none;\n align-items: center;\n justify-content: center;\n z-index: 999998;\n backdrop-filter: blur(3px);\n}\n\n.iwb-editor-modal {\n background: #1e1e2e;\n border-radius: 0;\n box-shadow: none;\n display: flex;\n flex-direction: column;\n width: 100vw;\n height: 100vh;\n max-width: none;\n max-height: none;\n overflow: visible;\n}\n\n/* 新增:主区域(画布 + 图层面板)flex 布局 */\n.iwb-editor-main {\n display: flex;\n flex: 1 1 auto;\n min-height: 0;\n overflow: visible;\n}\n\n.iwb-editor-header {\n display: flex;\n align-items: center;\n gap: 12px;\n padding: 10px 16px;\n background: #181825;\n border-bottom: 1px solid #313244;\n flex-wrap: nowrap;\n}\n.iwb-editor-header > .iwb-editor-tools {\n position: absolute;\n left: 12px;\n top: 68px;\n width: 44px;\n flex-direction: column;\n padding: 6px;\n background: #181825;\n border: 1px solid #313244;\n border-radius: 8px;\n z-index: 20;\n}\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action { position: static; }\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action[data-action="undo"],\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action[data-action="redo"],\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action[data-action="reset"],\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action[data-action="restore"] {\n position: absolute;\n top: -54px;\n left: auto;\n}\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action[data-action="undo"] { right: 154px; }\n.iwb-editor-header > .iwb-edLine truncated
|
||||
var editor_default = '/* IWB 鲜艺抠图节点 - 注入样式 */\n\n/* 抠图按钮 */\n.iwb-cutout-btn {\n cursor: pointer;\n opacity: 0.7;\n transition: opacity 0.15s, transform 0.15s;\n}\n\n.iwb-cutout-btn:hover {\n opacity: 1;\n transform: scale(1.15);\n}\n\n.iwb-cutout-btn svg {\n width: 14px;\n height: 14px;\n display: block;\n}\n\n/* 正在处理中的按钮状态 */\n.iwb-cutout-btn.processing {\n animation: iwb-cutout-pulse 1s infinite;\n pointer-events: none;\n}\n\n@keyframes iwb-cutout-pulse {\n 0%, 100% { opacity: 0.4; }\n 50% { opacity: 1; }\n}\n\n/* 全屏遮罩 */\n.iwb-cutout-overlay {\n position: fixed;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n background: rgba(0, 0, 0, 0.25);\n display: none;\n align-items: center;\n justify-content: center;\n flex-direction: column;\n gap: 12px;\n z-index: 999999;\n pointer-events: all;\n backdrop-filter: blur(2px);\n}\n\n/* 自定义按钮提示(挂在 body,最高层级,不会被图片遮挡) */\n#iwb-cutout-tip {\n position: fixed;\n z-index: 2147483647;\n background: rgba(30, 30, 46, 0.95);\n color: #fff;\n padding: 5px 10px;\n border-radius: 6px;\n font-size: 12px;\n line-height: 1.5;\n white-space: nowrap;\n pointer-events: none;\n display: none;\n box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);\n border: 1px solid rgba(255, 255, 255, 0.14);\n font-family: system-ui, -apple-system, "Segoe UI", sans-serif;\n max-width: 320px;\n white-space: normal;\n word-break: break-all;\n}\n\n/* 加载动画 */\n.iwb-cutout-spinner {\n width: 48px;\n height: 48px;\n border: 4px solid rgba(255, 255, 255, 0.3);\n border-top-color: #e8a735;\n border-radius: 50%;\n animation: iwb-cutout-spin 0.8s linear infinite;\n}\n\n@keyframes iwb-cutout-spin {\n to { transform: rotate(360deg); }\n}\n\n/* 遮罩文字 */\n.iwb-cutout-text {\n color: #fff;\n font-size: 14px;\n font-weight: 500;\n text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);\n background: rgba(0, 0, 0, 0.6);\n padding: 8px 16px;\n border-radius: 6px;\n}\n\n/* Toast 提示 */\n.iwb-cutout-toast {\n position: fixed;\n bottom: 24px;\n left: 50%;\n transform: translateX(-50%);\n padding: 10px 20px;\n border-radius: 8px;\n font-size: 13px;\n font-weight: 500;\n z-index: 999999;\n transition: opacity 0.3s;\n box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);\n display: none;\n max-width: 400px;\n}\n\n.iwb-cutout-toast-success {\n background: #1a7f37;\n color: #fff;\n}\n\n.iwb-cutout-toast-error {\n background: #cf222e;\n color: #fff;\n}\n\n.iwb-cutout-toast-info {\n background: #1f6feb;\n color: #fff;\n}\n\n/* 白底按钮 */\n.iwb-whitebg-btn {\n cursor: pointer;\n opacity: 0.7;\n transition: opacity 0.15s, transform 0.15s;\n}\n.iwb-whitebg-btn:hover { opacity: 1; transform: scale(1.15); }\n.iwb-whitebg-btn svg { width: 14px; height: 14px; display: block; }\n.iwb-whitebg-btn.processing { animation: iwb-cutout-pulse 1s infinite; pointer-events: none; }\n\n/* 编辑按钮 */\n.iwb-editor-btn-icon {\n cursor: pointer;\n opacity: 0.7;\n transition: opacity 0.15s, transform 0.15s;\n}\n.iwb-editor-btn-icon:hover { opacity: 1; transform: scale(1.15); }\n.iwb-editor-btn-icon svg { width: 14px; height: 14px; display: block; }\n\n/* ==================== 图片编辑器 ==================== */\n\n.iwb-editor-overlay {\n position: fixed;\n top: 0; left: 0;\n width: 100%; height: 100%;\n background: rgba(0, 0, 0, 0.6);\n display: none;\n align-items: center;\n justify-content: center;\n z-index: 999998;\n backdrop-filter: blur(3px);\n}\n\n.iwb-editor-modal {\n background: #1e1e2e;\n border-radius: 0;\n box-shadow: none;\n display: flex;\n flex-direction: column;\n width: 100vw;\n height: 100vh;\n max-width: none;\n max-height: none;\n overflow: visible;\n}\n\n/* 新增:主区域(画布 + 图层面板)flex 布局 */\n.iwb-editor-main {\n display: flex;\n flex: 1 1 auto;\n min-height: 0;\n overflow: visible;\n}\n\n.iwb-editor-header {\n display: flex;\n align-items: center;\n gap: 12px;\n padding: 10px 16px;\n background: #181825;\n border-bottom: 1px solid #313244;\n flex-wrap: nowrap;\n}\n.iwb-editor-header > .iwb-editor-tools {\n position: absolute;\n left: 12px;\n top: 68px;\n width: 44px;\n flex-direction: column;\n padding: 6px;\n background: #181825;\n border: 1px solid #313244;\n border-radius: 8px;\n z-index: 20;\n}\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action { position: static; }\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action[data-action="undo"],\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action[data-action="redo"],\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action[data-action="reset"],\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action[data-action="restore"] {\n position: absolute;\n top: -54px;\n left: auto;\n}\n.iwb-editor-header > .iwb-editor-tools .iwb-editor-action[data-action="undo"] { right: 154px; }\n.iwb-editor-header > .iwb-edLine truncated
|
||||
|
||||
// image-annotate/plugin/glue.js
|
||||
function createGlue(ctx, css) {
|
||||
|
||||
Reference in new issue
Block a user