fix(image-annotate): 1.1.2 输出预设收口(JPG 自动白底、边长/体积控件、maxKB 只属电商预设、下载与还原后摘要刷新)
This commit is contained in:
1 parent
9a0f5bab69
commit
a4e89f5f8b
9 files changed
+312
-47
No files matched your search
@@ -35,7 +35,13 @@
|
||||
侧栏一键收起、粘贴图片一步落层。数字键 1–0 保留,新增 `M/L/V/B/E/T/C` 与
|
||||
`Ctrl+A / J / X / D`、`Ctrl+Shift+I`、`Esc`、`Delete`。浮动条 / 右键 / 快捷键三入口共用同一命令层。
|
||||
- 输出:一次一个结果;「透明 PNG / 白底 JPG」是单选开关,不默认产两个文件;预设存 `ctx.settings`。
|
||||
- 测试:`node image-annotate/tools/harness.mjs`(合成宿主,发布前,27 项);
|
||||
- **v1.1.2**:JPG 没有 alpha 通道,选 JPG 时背景自动收敛为白底并禁用「透明」按钮,
|
||||
摘要/状态与文件三者一致(此前会显示透明却输出白底)。
|
||||
- **v1.1.2**:「电商方图」预设补齐 **边长**(750/800/1000/1200)与 **体积上限**(不限/300/500/800KB)两个控件,
|
||||
两者只在电商预设下可见;`≤KB` 也只在该预设下参与降质 —— 切回「原尺寸」会把 `maxKB` 写回 0,
|
||||
不会因为宿主里残留的 `exportMaxKB` 让限制「复活」或让原尺寸偷偷降质。
|
||||
- **v1.1.2**:下载后与「还原原图(尺寸复位)」后都会走统一重绘,摘要里的尺寸和「上次输出 …KB」即时更新。
|
||||
- 测试:`node image-annotate/tools/harness.mjs`(合成宿主,发布前,54 项);
|
||||
`node image-annotate/tools/e2e-site.mjs`(真站 CSP/SRI,发布后)。
|
||||
|
||||
## 入口
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@iwb-plugin/image-annotate",
|
||||
"private": true,
|
||||
"version": "1.1.1",
|
||||
"version": "1.1.2",
|
||||
"description": "IWB 插件:图片标注 / 修图(编辑器移植自 iwb-plaus 扩展,纯 Canvas 2D)",
|
||||
"ibwPlugin": {
|
||||
"id": "image-annotate",
|
||||
|
||||
@@ -1476,3 +1476,12 @@
|
||||
.iwb-editor-export-actions .iwb-editor-btn-cancel { display: none; }
|
||||
}
|
||||
|
||||
|
||||
/* 输出设置:按预设显示的行(尺寸/体积只属于电商方图)
|
||||
注意 `.iwb-editor-export-row` 是 display:flex,会盖掉 UA 的 [hidden]{display:none},
|
||||
必须显式 !important,否则 JS 设 hidden 后行还留在面板里。 */
|
||||
.iwb-editor-export-row[hidden] { display: none !important; }
|
||||
.iwb-editor-export-settings [data-export-key]:disabled {
|
||||
opacity: 0.32; cursor: not-allowed; text-decoration: line-through;
|
||||
}
|
||||
.iwb-editor-export-settings [data-export-key]:disabled:hover { background: #313244; }
|
||||
@@ -81,7 +81,7 @@ import { bindEvents } from './events.js'
|
||||
<div class="iwb-editor-export-settings">
|
||||
<div class="iwb-editor-export-row"><span>预设</span>
|
||||
<button data-export-key="preset" data-export-value="original">原尺寸</button>
|
||||
<button data-export-key="preset" data-export-value="ecom800">电商 800² ≤500KB</button>
|
||||
<button data-export-key="preset" data-export-value="ecom800">电商方图</button>
|
||||
</div>
|
||||
<div class="iwb-editor-export-row"><span>格式</span>
|
||||
<button data-export-key="format" data-export-value="png">PNG</button>
|
||||
@@ -92,6 +92,18 @@ import { bindEvents } from './events.js'
|
||||
<button data-export-key="bg" data-export-value="transparent">透明</button>
|
||||
<button data-export-key="bg" data-export-value="white">白底</button>
|
||||
</div>
|
||||
<div class="iwb-editor-export-row" data-export-when="ecom800"><span>边长</span>
|
||||
<button data-export-key="size" data-export-value="750">750</button>
|
||||
<button data-export-key="size" data-export-value="800">800</button>
|
||||
<button data-export-key="size" data-export-value="1000">1000</button>
|
||||
<button data-export-key="size" data-export-value="1200">1200</button>
|
||||
</div>
|
||||
<div class="iwb-editor-export-row" data-export-when="ecom800" title="商品图体积上限(仅对 JPG / WebP 生效,PNG 无法降质)"><span>≤KB</span>
|
||||
<button data-export-key="maxKB" data-export-value="0">不限</button>
|
||||
<button data-export-key="maxKB" data-export-value="300">300</button>
|
||||
<button data-export-key="maxKB" data-export-value="500">500</button>
|
||||
<button data-export-key="maxKB" data-export-value="800">800</button>
|
||||
</div>
|
||||
<div class="iwb-editor-export-note">一次只输出一个结果;设置会记住</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -27,6 +27,20 @@ import { toast } from './commands.js'
|
||||
|
||||
function settings() { return S.callbacks && S.callbacks.settings }
|
||||
|
||||
/** 实际输出背景:JPG 没有 alpha 通道,选「透明」也必须落白底。
|
||||
* 整条输出链(画布、摘要、状态)统一读这里,避免「按钮显示透明、文件是白底」。 */
|
||||
export function effectiveBg(o) {
|
||||
o = o || S.exportOptions || DEFAULT_EXPORT
|
||||
return (o.bg === 'white' || o.format === 'jpeg') ? 'white' : 'transparent'
|
||||
}
|
||||
|
||||
/** 当前输出设置的派生签名:判断「上次输出」是否还代表现在这套设置 */
|
||||
function exportSignature(o) {
|
||||
o = o || S.exportOptions || DEFAULT_EXPORT
|
||||
const ecom = o.preset === 'ecom800'
|
||||
return [o.preset, o.format, ecom ? o.size : 'orig', effectiveBg(o), ecom ? o.maxKB : 0].join(':')
|
||||
}
|
||||
|
||||
export function loadExportOptions() {
|
||||
const st = settings()
|
||||
const get = (k, d) => {
|
||||
@@ -36,43 +50,99 @@ import { toast } from './commands.js'
|
||||
}
|
||||
return v
|
||||
}
|
||||
const preset = get('preset', DEFAULT_EXPORT.preset) === 'ecom800' ? 'ecom800' : 'original'
|
||||
const format = ['png', 'jpeg', 'webp'].indexOf(get('format', DEFAULT_EXPORT.format)) >= 0 ? get('format', DEFAULT_EXPORT.format) : 'png'
|
||||
// 体积上限 / 边长只属于电商方图预设。原尺寸分支不继承上一次留下的限制,
|
||||
// 否则宿主里残留的 exportMaxKB 会让「原尺寸」也偷偷降质。
|
||||
// null 表示从未设置过(走默认 500),0 表示用户显式选了「不限」——两者必须区分。
|
||||
const rawMax = get('maxKB', null)
|
||||
const rawSize = get('size', null)
|
||||
S.exportOptions = {
|
||||
preset: get('preset', DEFAULT_EXPORT.preset) === 'ecom800' ? 'ecom800' : 'original',
|
||||
format: ['png', 'jpeg', 'webp'].indexOf(get('format', DEFAULT_EXPORT.format)) >= 0 ? get('format', DEFAULT_EXPORT.format) : 'png',
|
||||
bg: get('bg', DEFAULT_EXPORT.bg) === 'white' ? 'white' : 'transparent',
|
||||
maxKB: Math.max(0, Number(get('maxKB', 0)) || 0),
|
||||
size: Math.max(64, Number(get('size', 800)) || 800)
|
||||
preset: preset,
|
||||
format: format,
|
||||
// JPG 下背景直接收敛到白底,状态本身自洽,不靠 UI 撒谎
|
||||
bg: format === 'jpeg' ? 'white' : (get('bg', DEFAULT_EXPORT.bg) === 'white' ? 'white' : 'transparent'),
|
||||
maxKB: preset === 'ecom800' ? (rawMax === null ? 500 : Math.max(0, Number(rawMax) || 0)) : 0,
|
||||
size: Math.max(64, Number(rawSize === null ? 800 : rawSize) || 800)
|
||||
}
|
||||
if (S.exportOptions.preset === 'ecom800' && !S.exportOptions.maxKB) S.exportOptions.maxKB = 500
|
||||
renderExportUI()
|
||||
}
|
||||
|
||||
export function setExportOption(key, value) {
|
||||
if (!S.exportOptions) loadExportOptions()
|
||||
S.exportOptions[key] = value
|
||||
if (key === 'preset' && value === 'ecom800') S.exportOptions.maxKB = 500
|
||||
if (key === 'preset' && value === 'original') S.exportOptions.maxKB = 0
|
||||
const o = S.exportOptions
|
||||
const st = settings()
|
||||
if (st && typeof st.set === 'function') {
|
||||
try { st.set(SETTINGS_KEY[key], value) } catch (e) { /* ignore */ }
|
||||
const persist = (k, v) => {
|
||||
if (st && typeof st.set === 'function') { try { st.set(SETTINGS_KEY[k], v) } catch (e) { /* ignore */ } }
|
||||
}
|
||||
if (key === 'preset') {
|
||||
o.preset = value === 'ecom800' ? 'ecom800' : 'original'
|
||||
o.maxKB = o.preset === 'ecom800' ? 500 : 0
|
||||
persist('preset', o.preset)
|
||||
// maxKB 必须一起写回:只改内存的话,下次打开会被旧的 exportMaxKB 让限制「复活」
|
||||
persist('maxKB', o.maxKB)
|
||||
} else if (key === 'format') {
|
||||
o.format = ['png', 'jpeg', 'webp'].indexOf(value) >= 0 ? value : 'png'
|
||||
persist('format', o.format)
|
||||
if (o.format === 'jpeg' && o.bg !== 'white') {
|
||||
o.bg = 'white'
|
||||
persist('bg', 'white')
|
||||
toast('JPG 不支持透明背景,已切换为白底', 'info')
|
||||
}
|
||||
} else if (key === 'bg') {
|
||||
if (o.format === 'jpeg') { renderExportUI(); return } // 按钮已禁用,这里兜底
|
||||
o.bg = value === 'white' ? 'white' : 'transparent'
|
||||
persist('bg', o.bg)
|
||||
} else if (key === 'maxKB') {
|
||||
o.maxKB = Math.max(0, Number(value) || 0)
|
||||
persist('maxKB', o.maxKB)
|
||||
} else if (key === 'size') {
|
||||
o.size = Math.max(64, Number(value) || 800)
|
||||
persist('size', o.size)
|
||||
}
|
||||
renderExportUI()
|
||||
}
|
||||
|
||||
/** 顶栏输出设置面板:按钮态 + 预设摘要 */
|
||||
/** 顶栏输出设置面板:按钮态 + 预设摘要(摘要必须反映「实际会输出什么」) */
|
||||
export function renderExportUI() {
|
||||
const o = S.exportOptions || DEFAULT_EXPORT
|
||||
const root = runtime.el
|
||||
if (!root) return
|
||||
const ecom = o.preset === 'ecom800'
|
||||
const jpg = o.format === 'jpeg'
|
||||
|
||||
root.querySelectorAll('[data-export-key]').forEach(btn => {
|
||||
const on = String(o[btn.dataset.exportKey]) === String(btn.dataset.exportValue)
|
||||
btn.classList.toggle('active', on)
|
||||
btn.setAttribute('aria-pressed', String(on))
|
||||
})
|
||||
// JPG 无 alpha 通道:透明按钮禁用并给出原因,而不是留着高亮却悄悄输出白底
|
||||
root.querySelectorAll('[data-export-key="bg"]').forEach(btn => {
|
||||
const blocked = jpg && btn.dataset.exportValue === 'transparent'
|
||||
btn.disabled = blocked
|
||||
if (blocked) btn.title = 'JPG 不支持透明背景,已自动使用白底'
|
||||
else btn.removeAttribute('title')
|
||||
})
|
||||
// 边长 / 体积上限只在电商方图预设下有意义
|
||||
root.querySelectorAll('[data-export-when="ecom800"]').forEach(row => { row.hidden = !ecom })
|
||||
|
||||
const summary = root.querySelector('.iwb-editor-export-summary')
|
||||
if (summary) summary.textContent = o.preset === 'ecom800'
|
||||
? (o.size + '×' + o.size + ' · ' + o.format.toUpperCase() + (o.maxKB ? ' · ≤' + o.maxKB + 'KB' : ''))
|
||||
: ('原尺寸 ' + S.imgW + '×' + S.imgH + ' · ' + o.format.toUpperCase())
|
||||
if (summary) {
|
||||
const size = ecom ? (o.size + '×' + o.size) : ('原尺寸 ' + S.imgW + '×' + S.imgH)
|
||||
const limit = ecom && o.maxKB ? (' · ≤' + o.maxKB + 'KB') : ''
|
||||
const bg = effectiveBg(o) === 'white' ? '白底' : '透明'
|
||||
// jpeg 的 MIME 名是 JPEG,但对用户就说 JPG
|
||||
const fmt = o.format === 'jpeg' ? 'JPG' : o.format === 'webp' ? 'WebP' : 'PNG'
|
||||
summary.textContent = size + ' · ' + fmt + ' · ' + bg + limit
|
||||
}
|
||||
// 「上次输出」只在当前这套设置确实产过结果时才报,否则会误导
|
||||
const note = root.querySelector('.iwb-editor-export-note')
|
||||
if (note) {
|
||||
const le = S.lastExport
|
||||
note.textContent = (le && le.signature === exportSignature(o))
|
||||
? ('上次输出 ' + le.width + '×' + le.height + ' · ' + Math.max(1, Math.round(le.bytes / 1024)) + 'KB')
|
||||
: '一次只输出一个结果;设置会记住'
|
||||
}
|
||||
}
|
||||
|
||||
/** 事件委托:输出设置面板(下拉容器常驻 DOM,展开由 CSS class 控制) */
|
||||
@@ -107,6 +177,7 @@ import { toast } from './commands.js'
|
||||
/** 合成 → 尺寸/背景处理。返回结果画布(调用方负责释放) */
|
||||
export function buildOutputCanvas() {
|
||||
const o = S.exportOptions || DEFAULT_EXPORT
|
||||
const white = effectiveBg(o) === 'white'
|
||||
const src = getCompositeCanvas()
|
||||
let out = src
|
||||
if (o.preset === 'ecom800') {
|
||||
@@ -115,14 +186,14 @@ import { toast } from './commands.js'
|
||||
c.width = size
|
||||
c.height = size
|
||||
const cx = c.getContext('2d')
|
||||
if (o.bg === 'white' || o.format === 'jpeg') { cx.fillStyle = '#ffffff'; cx.fillRect(0, 0, size, size) }
|
||||
if (white) { cx.fillStyle = '#ffffff'; cx.fillRect(0, 0, size, size) }
|
||||
const long = Math.max(S.imgW, S.imgH) || 1
|
||||
const k = (size * 0.8) / long // 商品长边占比 80%(640px / 800px)
|
||||
const w = S.imgW * k, h = S.imgH * k
|
||||
cx.drawImage(src, (size - w) / 2, (size - h) / 2, w, h)
|
||||
src.width = 0; src.height = 0
|
||||
out = c
|
||||
} else if (o.bg === 'white' || o.format === 'jpeg') {
|
||||
} else if (white) {
|
||||
const c = document.createElement('canvas')
|
||||
c.width = S.imgW
|
||||
c.height = S.imgH
|
||||
@@ -164,7 +235,8 @@ import { toast } from './commands.js'
|
||||
export async function encodeOutput(canvas) {
|
||||
const o = S.exportOptions || DEFAULT_EXPORT
|
||||
const mime = o.format === 'jpeg' ? 'image/jpeg' : o.format === 'webp' ? 'image/webp' : 'image/png'
|
||||
const limit = o.maxKB > 0 ? o.maxKB * 1024 : 0
|
||||
// ≤KB 只在电商方图预设下约束;「原尺寸 + 残留 maxKB」不应偷偷降质
|
||||
const limit = (o.preset === 'ecom800' && o.maxKB > 0) ? o.maxKB * 1024 : 0
|
||||
let blob = await toBlob(canvas, mime, 0.92)
|
||||
if (limit && blob.size > limit) {
|
||||
if (o.format === 'png') {
|
||||
@@ -186,7 +258,18 @@ import { toast } from './commands.js'
|
||||
const canvas = buildOutputCanvas()
|
||||
try {
|
||||
const blob = await encodeOutput(canvas)
|
||||
const info = { bytes: blob.size, width: canvas.width, height: canvas.height, format: S.exportOptions.format, preset: S.exportOptions.preset }
|
||||
const o = S.exportOptions || DEFAULT_EXPORT
|
||||
const info = {
|
||||
bytes: blob.size,
|
||||
width: canvas.width,
|
||||
height: canvas.height,
|
||||
format: o.format,
|
||||
bg: effectiveBg(o),
|
||||
preset: o.preset,
|
||||
maxKB: o.preset === 'ecom800' ? o.maxKB : 0,
|
||||
// 记下产出时用的设置指纹,UI 才能判断「上次输出」是否还代表当前设置
|
||||
signature: exportSignature(o)
|
||||
}
|
||||
S.lastExport = info
|
||||
return { blob, info }
|
||||
} finally {
|
||||
|
||||
@@ -289,6 +289,9 @@ import { toast } from './commands.js'
|
||||
S.redoStack = []
|
||||
clearAllEditState()
|
||||
updateAllUI()
|
||||
// 尺寸变了就必须走统一重绘出口:输出摘要/状态栏读 S.imgW/imgH,
|
||||
// clearAllEditState 只清选区不停止蚂蚁线 rAF(唯一停止点是 renderAll/clearMarquee)
|
||||
if (S.renderAll) S.renderAll()
|
||||
toast('已还原为原图(裁剪后的画布尺寸已复位)', 'success')
|
||||
return
|
||||
}
|
||||
|
||||
@@ -244,7 +244,12 @@ import { toast } from './commands.js'
|
||||
if (S.placingImage) cancelImagePlacement()
|
||||
try {
|
||||
const { blob } = await prepareOutput()
|
||||
if (mode === 'download') { downloadBlob(blob); return }
|
||||
if (mode === 'download') {
|
||||
downloadBlob(blob)
|
||||
// download 不关编辑器:必须走一次统一重绘,摘要的「上次输出 …KB」才会更新
|
||||
if (S.renderAll) S.renderAll()
|
||||
return
|
||||
}
|
||||
if (S.callbacks && S.callbacks.onResult) S.callbacks.onResult(blob, mode)
|
||||
close('done')
|
||||
} catch (e) {
|
||||
|
||||
+109
-21
@@ -9,7 +9,7 @@
|
||||
var __IWB_ANNOTATE_MANIFEST__ = {
|
||||
id: 'image-annotate',
|
||||
name: '标注 / 修图',
|
||||
version: '1.1.1',
|
||||
version: '1.1.2',
|
||||
apiVersion: 1,
|
||||
capabilities: ['commands', 'nodeActions', 'canvas', 'canvasWrite'],
|
||||
settings: {
|
||||
@@ -1648,7 +1648,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
||||
<div class="iwb-editor-export-settings">
|
||||
<div class="iwb-editor-export-row"><span>预设</span>
|
||||
<button data-export-key="preset" data-export-value="original">原尺寸</button>
|
||||
<button data-export-key="preset" data-export-value="ecom800">电商 800² ≤500KB</button>
|
||||
<button data-export-key="preset" data-export-value="ecom800">电商方图</button>
|
||||
</div>
|
||||
<div class="iwb-editor-export-row"><span>格式</span>
|
||||
<button data-export-key="format" data-export-value="png">PNG</button>
|
||||
@@ -1659,6 +1659,18 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
||||
<button data-export-key="bg" data-export-value="transparent">透明</button>
|
||||
<button data-export-key="bg" data-export-value="white">白底</button>
|
||||
</div>
|
||||
<div class="iwb-editor-export-row" data-export-when="ecom800"><span>边长</span>
|
||||
<button data-export-key="size" data-export-value="750">750</button>
|
||||
<button data-export-key="size" data-export-value="800">800</button>
|
||||
<button data-export-key="size" data-export-value="1000">1000</button>
|
||||
<button data-export-key="size" data-export-value="1200">1200</button>
|
||||
</div>
|
||||
<div class="iwb-editor-export-row" data-export-when="ecom800" title="商品图体积上限(仅对 JPG / WebP 生效,PNG 无法降质)"><span>≤KB</span>
|
||||
<button data-export-key="maxKB" data-export-value="0">不限</button>
|
||||
<button data-export-key="maxKB" data-export-value="300">300</button>
|
||||
<button data-export-key="maxKB" data-export-value="500">500</button>
|
||||
<button data-export-key="maxKB" data-export-value="800">800</button>
|
||||
</div>
|
||||
<div class="iwb-editor-export-note">一次只输出一个结果;设置会记住</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -5302,6 +5314,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
||||
S.redoStack = [];
|
||||
clearAllEditState();
|
||||
updateAllUI();
|
||||
if (S.renderAll) S.renderAll();
|
||||
toast("已还原为原图(裁剪后的画布尺寸已复位)", "success");
|
||||
return;
|
||||
}
|
||||
@@ -5403,6 +5416,15 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
||||
function settings() {
|
||||
return S.callbacks && S.callbacks.settings;
|
||||
}
|
||||
function effectiveBg(o) {
|
||||
o = o || S.exportOptions || DEFAULT_EXPORT;
|
||||
return o.bg === "white" || o.format === "jpeg" ? "white" : "transparent";
|
||||
}
|
||||
function exportSignature(o) {
|
||||
o = o || S.exportOptions || DEFAULT_EXPORT;
|
||||
const ecom = o.preset === "ecom800";
|
||||
return [o.preset, o.format, ecom ? o.size : "orig", effectiveBg(o), ecom ? o.maxKB : 0].join(":");
|
||||
}
|
||||
function loadExportOptions() {
|
||||
const st = settings();
|
||||
const get = (k, d) => {
|
||||
@@ -5416,27 +5438,58 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
||||
}
|
||||
return v;
|
||||
};
|
||||
const preset = get("preset", DEFAULT_EXPORT.preset) === "ecom800" ? "ecom800" : "original";
|
||||
const format = ["png", "jpeg", "webp"].indexOf(get("format", DEFAULT_EXPORT.format)) >= 0 ? get("format", DEFAULT_EXPORT.format) : "png";
|
||||
const rawMax = get("maxKB", null);
|
||||
const rawSize = get("size", null);
|
||||
S.exportOptions = {
|
||||
preset: get("preset", DEFAULT_EXPORT.preset) === "ecom800" ? "ecom800" : "original",
|
||||
format: ["png", "jpeg", "webp"].indexOf(get("format", DEFAULT_EXPORT.format)) >= 0 ? get("format", DEFAULT_EXPORT.format) : "png",
|
||||
bg: get("bg", DEFAULT_EXPORT.bg) === "white" ? "white" : "transparent",
|
||||
maxKB: Math.max(0, Number(get("maxKB", 0)) || 0),
|
||||
size: Math.max(64, Number(get("size", 800)) || 800)
|
||||
preset,
|
||||
format,
|
||||
// JPG 下背景直接收敛到白底,状态本身自洽,不靠 UI 撒谎
|
||||
bg: format === "jpeg" ? "white" : get("bg", DEFAULT_EXPORT.bg) === "white" ? "white" : "transparent",
|
||||
maxKB: preset === "ecom800" ? rawMax === null ? 500 : Math.max(0, Number(rawMax) || 0) : 0,
|
||||
size: Math.max(64, Number(rawSize === null ? 800 : rawSize) || 800)
|
||||
};
|
||||
if (S.exportOptions.preset === "ecom800" && !S.exportOptions.maxKB) S.exportOptions.maxKB = 500;
|
||||
renderExportUI();
|
||||
}
|
||||
function setExportOption(key, value) {
|
||||
if (!S.exportOptions) loadExportOptions();
|
||||
S.exportOptions[key] = value;
|
||||
if (key === "preset" && value === "ecom800") S.exportOptions.maxKB = 500;
|
||||
if (key === "preset" && value === "original") S.exportOptions.maxKB = 0;
|
||||
const o = S.exportOptions;
|
||||
const st = settings();
|
||||
if (st && typeof st.set === "function") {
|
||||
try {
|
||||
st.set(SETTINGS_KEY[key], value);
|
||||
} catch (e) {
|
||||
const persist = (k, v) => {
|
||||
if (st && typeof st.set === "function") {
|
||||
try {
|
||||
st.set(SETTINGS_KEY[k], v);
|
||||
} catch (e) {
|
||||
}
|
||||
}
|
||||
};
|
||||
if (key === "preset") {
|
||||
o.preset = value === "ecom800" ? "ecom800" : "original";
|
||||
o.maxKB = o.preset === "ecom800" ? 500 : 0;
|
||||
persist("preset", o.preset);
|
||||
persist("maxKB", o.maxKB);
|
||||
} else if (key === "format") {
|
||||
o.format = ["png", "jpeg", "webp"].indexOf(value) >= 0 ? value : "png";
|
||||
persist("format", o.format);
|
||||
if (o.format === "jpeg" && o.bg !== "white") {
|
||||
o.bg = "white";
|
||||
persist("bg", "white");
|
||||
toast("JPG 不支持透明背景,已切换为白底", "info");
|
||||
}
|
||||
} else if (key === "bg") {
|
||||
if (o.format === "jpeg") {
|
||||
renderExportUI();
|
||||
return;
|
||||
}
|
||||
o.bg = value === "white" ? "white" : "transparent";
|
||||
persist("bg", o.bg);
|
||||
} else if (key === "maxKB") {
|
||||
o.maxKB = Math.max(0, Number(value) || 0);
|
||||
persist("maxKB", o.maxKB);
|
||||
} else if (key === "size") {
|
||||
o.size = Math.max(64, Number(value) || 800);
|
||||
persist("size", o.size);
|
||||
}
|
||||
renderExportUI();
|
||||
}
|
||||
@@ -5444,13 +5497,35 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
||||
const o = S.exportOptions || DEFAULT_EXPORT;
|
||||
const root = runtime.el;
|
||||
if (!root) return;
|
||||
const ecom = o.preset === "ecom800";
|
||||
const jpg = o.format === "jpeg";
|
||||
root.querySelectorAll("[data-export-key]").forEach((btn) => {
|
||||
const on = String(o[btn.dataset.exportKey]) === String(btn.dataset.exportValue);
|
||||
btn.classList.toggle("active", on);
|
||||
btn.setAttribute("aria-pressed", String(on));
|
||||
});
|
||||
root.querySelectorAll('[data-export-key="bg"]').forEach((btn) => {
|
||||
const blocked = jpg && btn.dataset.exportValue === "transparent";
|
||||
btn.disabled = blocked;
|
||||
if (blocked) btn.title = "JPG 不支持透明背景,已自动使用白底";
|
||||
else btn.removeAttribute("title");
|
||||
});
|
||||
root.querySelectorAll('[data-export-when="ecom800"]').forEach((row) => {
|
||||
row.hidden = !ecom;
|
||||
});
|
||||
const summary = root.querySelector(".iwb-editor-export-summary");
|
||||
if (summary) summary.textContent = o.preset === "ecom800" ? o.size + "×" + o.size + " · " + o.format.toUpperCase() + (o.maxKB ? " · ≤" + o.maxKB + "KB" : "") : "原尺寸 " + S.imgW + "×" + S.imgH + " · " + o.format.toUpperCase();
|
||||
if (summary) {
|
||||
const size = ecom ? o.size + "×" + o.size : "原尺寸 " + S.imgW + "×" + S.imgH;
|
||||
const limit = ecom && o.maxKB ? " · ≤" + o.maxKB + "KB" : "";
|
||||
const bg = effectiveBg(o) === "white" ? "白底" : "透明";
|
||||
const fmt = o.format === "jpeg" ? "JPG" : o.format === "webp" ? "WebP" : "PNG";
|
||||
summary.textContent = size + " · " + fmt + " · " + bg + limit;
|
||||
}
|
||||
const note = root.querySelector(".iwb-editor-export-note");
|
||||
if (note) {
|
||||
const le = S.lastExport;
|
||||
note.textContent = le && le.signature === exportSignature(o) ? "上次输出 " + le.width + "×" + le.height + " · " + Math.max(1, Math.round(le.bytes / 1024)) + "KB" : "一次只输出一个结果;设置会记住";
|
||||
}
|
||||
}
|
||||
function bindExportUI() {
|
||||
const root = runtime.el;
|
||||
@@ -5481,6 +5556,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
||||
}
|
||||
function buildOutputCanvas() {
|
||||
const o = S.exportOptions || DEFAULT_EXPORT;
|
||||
const white = effectiveBg(o) === "white";
|
||||
const src = getCompositeCanvas();
|
||||
let out = src;
|
||||
if (o.preset === "ecom800") {
|
||||
@@ -5489,7 +5565,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
||||
c.width = size;
|
||||
c.height = size;
|
||||
const cx = c.getContext("2d");
|
||||
if (o.bg === "white" || o.format === "jpeg") {
|
||||
if (white) {
|
||||
cx.fillStyle = "#ffffff";
|
||||
cx.fillRect(0, 0, size, size);
|
||||
}
|
||||
@@ -5500,7 +5576,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
||||
src.width = 0;
|
||||
src.height = 0;
|
||||
out = c;
|
||||
} else if (o.bg === "white" || o.format === "jpeg") {
|
||||
} else if (white) {
|
||||
const c = document.createElement("canvas");
|
||||
c.width = S.imgW;
|
||||
c.height = S.imgH;
|
||||
@@ -5547,7 +5623,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
||||
async function encodeOutput(canvas) {
|
||||
const o = S.exportOptions || DEFAULT_EXPORT;
|
||||
const mime = o.format === "jpeg" ? "image/jpeg" : o.format === "webp" ? "image/webp" : "image/png";
|
||||
const limit = o.maxKB > 0 ? o.maxKB * 1024 : 0;
|
||||
const limit = o.preset === "ecom800" && o.maxKB > 0 ? o.maxKB * 1024 : 0;
|
||||
let blob = await toBlob(canvas, mime, 0.92);
|
||||
if (limit && blob.size > limit) {
|
||||
if (o.format === "png") {
|
||||
@@ -5567,7 +5643,18 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
||||
const canvas = buildOutputCanvas();
|
||||
try {
|
||||
const blob = await encodeOutput(canvas);
|
||||
const info = { bytes: blob.size, width: canvas.width, height: canvas.height, format: S.exportOptions.format, preset: S.exportOptions.preset };
|
||||
const o = S.exportOptions || DEFAULT_EXPORT;
|
||||
const info = {
|
||||
bytes: blob.size,
|
||||
width: canvas.width,
|
||||
height: canvas.height,
|
||||
format: o.format,
|
||||
bg: effectiveBg(o),
|
||||
preset: o.preset,
|
||||
maxKB: o.preset === "ecom800" ? o.maxKB : 0,
|
||||
// 记下产出时用的设置指纹,UI 才能判断「上次输出」是否还代表当前设置
|
||||
signature: exportSignature(o)
|
||||
};
|
||||
S.lastExport = info;
|
||||
return { blob, info };
|
||||
} finally {
|
||||
@@ -5781,6 +5868,7 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
||||
const { blob } = await prepareOutput();
|
||||
if (mode === "download") {
|
||||
downloadBlob(blob);
|
||||
if (S.renderAll) S.renderAll();
|
||||
return;
|
||||
}
|
||||
if (S.callbacks && S.callbacks.onResult) S.callbacks.onResult(blob, mode);
|
||||
@@ -5837,7 +5925,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) {
|
||||
|
||||
@@ -96,7 +96,7 @@ const boot = await page.evaluate((png) => {
|
||||
window.__commands['annotate-selected'].run().catch(() => {})
|
||||
return { version: window.__manifest.version, settingsSchema: Object.keys(window.__manifest.settings || {}) }
|
||||
}, PNG)
|
||||
check('产物可执行(循环打包未炸)', boot.version === '1.1.1', 'version=' + boot.version)
|
||||
check('产物可执行(循环打包未炸)', boot.version === '1.1.2', 'version=' + boot.version)
|
||||
check('manifest 声明输出预设设置项', boot.settingsSchema.includes('exportPreset') && boot.settingsSchema.includes('panelsCollapsed'), boot.settingsSchema.join(','))
|
||||
|
||||
await page.locator('#iwb-editor-overlay').waitFor({ state: 'visible', timeout: 15000 })
|
||||
@@ -211,12 +211,58 @@ const exported = await poll(async () => (await dbg()).lastExport)
|
||||
check('下载只产一个结果:800×800 且 ≤500KB、编辑器不关闭',
|
||||
Boolean(exported && exported.width === 800 && exported.height === 800 && exported.bytes <= 500 * 1024 &&
|
||||
await page.locator('#iwb-editor-overlay').isVisible()), JSON.stringify(exported))
|
||||
// 输出面板的可见性/文案探针:面板收起时子元素 display 不在布局里,
|
||||
// 所以统一读 textContent 而不是 innerText(后者对隐藏元素返回空串)。
|
||||
const summaryText = () => page.locator('.iwb-editor-export-summary').textContent()
|
||||
const noteText = () => page.locator('.iwb-editor-export-note').textContent()
|
||||
const ecomRowsVisible = () => page.evaluate(() => {
|
||||
const rows = Array.from(document.querySelectorAll('[data-export-when="ecom800"]'))
|
||||
return rows.length >= 2 && rows.every(r => !r.hidden)
|
||||
})
|
||||
|
||||
check('电商预设:摘要写明尺寸/格式/背景/体积上限',
|
||||
/800×800/.test(await summaryText()) && /≤500KB/.test(await summaryText()) && /透明/.test(await summaryText()),
|
||||
await summaryText())
|
||||
await page.locator('[data-action="toggleExportSettings"]').click() // 上一步点「下载」会自动收起面板
|
||||
check('电商预设:边长与体积控件可见', await ecomRowsVisible())
|
||||
|
||||
await page.locator('[data-export-key="format"][data-export-value="jpeg"]').click()
|
||||
await page.locator('[data-export-key="bg"][data-export-value="white"]').click()
|
||||
const afterJpg = await dbg()
|
||||
check('选 JPG:背景自动收敛为白底并写回 settings(不再「显示透明、实际白底」)',
|
||||
afterJpg.exportOptions.bg === 'white' &&
|
||||
(await page.evaluate(() => window.__settings.exportBg)) === 'white' &&
|
||||
(await page.locator('[data-export-key="bg"][data-export-value="transparent"]').isDisabled()) === true,
|
||||
JSON.stringify(afterJpg.exportOptions))
|
||||
check('JPG 摘要显示白底', /白底/.test(await summaryText()), await summaryText())
|
||||
await page.locator('[data-action="download"]').click()
|
||||
const jpg = await poll(async () => { const d = await dbg(); return d.lastExport && d.lastExport.format === 'jpeg' ? d.lastExport : false })
|
||||
check('格式/背景切换生效(JPG + 白底)', Boolean(jpg) && (await dbg()).exportOptions.bg === 'white', JSON.stringify(jpg))
|
||||
check('格式/背景切换生效(JPG + 白底)', Boolean(jpg) && jpg.bg === 'white', JSON.stringify(jpg))
|
||||
check('下载后摘要记录上次输出(尺寸 + 体积)',
|
||||
/上次输出 800×800/.test(await noteText()), await noteText())
|
||||
|
||||
// 边长 / 体积上限:原来只有计算没有控件,改完必须能真的改到并生效
|
||||
await page.locator('[data-action="toggleExportSettings"]').click()
|
||||
await page.locator('[data-export-key="size"][data-export-value="1000"]').click()
|
||||
await page.locator('[data-export-key="maxKB"][data-export-value="300"]').click()
|
||||
const optSized = (await dbg()).exportOptions
|
||||
check('边长/体积控件可改并持久化到 ctx.settings',
|
||||
optSized.size === 1000 && optSized.maxKB === 300 &&
|
||||
(await page.evaluate(() => window.__settings.exportSize)) === 1000 &&
|
||||
(await page.evaluate(() => window.__settings.exportMaxKB)) === 300, JSON.stringify(optSized))
|
||||
await page.locator('[data-action="download"]').click()
|
||||
const sized = await poll(async () => { const d = await dbg(); return d.lastExport && d.lastExport.width === 1000 ? d.lastExport : false })
|
||||
check('边长生效:输出 1000×1000 且体积 ≤300KB',
|
||||
Boolean(sized) && sized.width === 1000 && sized.bytes <= 300 * 1024, JSON.stringify(sized))
|
||||
|
||||
await page.locator('[data-action="toggleExportSettings"]').click()
|
||||
await page.locator('[data-export-key="preset"][data-export-value="original"]').click()
|
||||
const optOriginal = (await dbg()).exportOptions
|
||||
check('切回原尺寸:maxKB 归零并写回 settings(重开不会让限制「复活」)',
|
||||
optOriginal.preset === 'original' && optOriginal.maxKB === 0 &&
|
||||
(await page.evaluate(() => window.__settings.exportMaxKB)) === 0, JSON.stringify(optOriginal))
|
||||
check('原尺寸下边长/体积控件隐藏', (await ecomRowsVisible()) === false)
|
||||
check('原尺寸摘要显示实际像素尺寸', /原尺寸 96×64/.test(await summaryText()), await summaryText())
|
||||
await page.locator('[data-action="toggleExportSettings"]').click() // 收起,恢复后续用例的初始态
|
||||
|
||||
// ---------- 选区与裁剪互斥 ----------
|
||||
await page.locator('.iwb-editor-tool[data-tool="crop"]').click()
|
||||
@@ -390,6 +436,19 @@ check('裁剪后 Delete 不按旧 bbox 误擦(层数不变、底图仍有像
|
||||
afterCropDelete.layers.length === cropped.layers.length && (await pixel(5, 5)).base[3] > 0 &&
|
||||
afterCropDelete.selection === null)
|
||||
|
||||
// ---- 还原原图的「尺寸复位」分支:必须走统一重绘,摘要/蚂蚁线才跟着走 ----
|
||||
// (该分支会 setupCanvas + 清历史,此前只调 updateAllUI,摘要停留在裁剪后尺寸)
|
||||
const cropSummary = await summaryText()
|
||||
await page.locator('[data-action="reset"]').click()
|
||||
const restoredDoc = await dbg()
|
||||
const restoredSummary = await summaryText()
|
||||
check('还原原图复位尺寸后:输出摘要即时跟随(不停留在裁剪后尺寸)',
|
||||
restoredDoc.doc.w === 96 && restoredDoc.doc.h === 64 &&
|
||||
/原尺寸 96×64/.test(restoredSummary) && cropSummary !== restoredSummary,
|
||||
cropSummary + ' → ' + restoredSummary)
|
||||
check('还原原图复位尺寸后蚂蚁线已停、选区已清',
|
||||
restoredDoc.ants === false && !restoredDoc.selection)
|
||||
|
||||
// ---- Fix4:点「退出」必须结算宿主 Promise(glue.openEditor → onClose) ----
|
||||
await page.locator('[data-action="cancel"]').click()
|
||||
const openState = await poll(async () => page.evaluate(() => window.__openState))
|
||||
|
||||
Reference in new issue
Block a user