perf: 缩略图 640/0.72 + 旧缓存清理;封面逻辑抽离;补 2 条测试 v3.26.34

This commit is contained in:
qiqi committed 2026-11-22 14:52:38 +08:00
1 parent 4b70e4029f
commit b3cbfe82f8
21 files changed
+315 -77

No files matched your search

+2 -1
View File
@@ -48,7 +48,8 @@ const NUMERIC = [
['W_OBJURL_MAX', appJs, 50],
['W_BLOBREF_MAX', appJs, 50],
['DISPLAY_THUMB_CACHE_MAX', appJs, 300],
['DISPLAY_THUMB_MAX', appJs, 768],
// v3.26.34:缩略图 640px(768 时单张 500~900KB)
['DISPLAY_THUMB_MAX', appJs, 640],
['outThumbCacheMax', appJs, 400],
['W_MAX_LOADED_BOARDS', appJs, 2],
['W_SESSION_MAX', sessStore, 5],
+1
View File
@@ -31,6 +31,7 @@
"IWBPluginGroupLib",
"IWBPluginHost",
"IWBPluginPromptLib",
"IWBPromptCover",
"IWBProviderPing",
"IWBResultImg",
"IWBRuntimeBoundary",
+2 -1
View File
@@ -102,5 +102,6 @@
"ui-backup-modal.js",
"ui-connect-menu.js",
"ui-gen-config-panel.js",
"canvas-webview.js"
"canvas-webview.js",
"image-prompt-cover.js"
]
+96
View File
@@ -0,0 +1,96 @@
// 提示词封面编码(v3.26.34 抽到 src/image-prompt-cover.js):
// ① WebP 可用 ⇒ 用 WebP;
// ② WebP 不可用 ⇒ 用 JPEG(PNG 回退会导致 448px 仍 300KB);
// ③ 两者都不可用 ⇒ 原图兜底;
// ④ coverUrl:dataURL 直出、老引用走异步解析。
const assert = require('assert')
const fs = require('fs')
const path = require('path')
const src = fs.readFileSync(path.join(__dirname, '..', 'src', 'image-prompt-cover.js'), 'utf8')
const sandbox = {}
new Function('window', src)(sandbox)
const { create } = sandbox.IWBPromptCover
const SRC = 'data:image/png;base64,AAAA'
const WEBP = 'data:image/webp;base64,' + 'W'.repeat(200)
const JPEG = 'data:image/jpeg;base64,' + 'J'.repeat(300)
const PNG = 'data:image/png;base64,' + 'P'.repeat(900)
;(async () => {
// ① WebP 可用 → 一次调用即返回 webp,不再尝试 jpeg
{
const calls = []
const api = create({
compress: async (s, c) => { calls.push(c.format); return c.format === 'webp' ? WEBP : JPEG },
resolve: async () => '',
})
const r = await api.put(SRC)
assert.strictEqual(r.ok, true)
assert.ok(r.ref.indexOf('data:image/webp') === 0, '应优先用 WebP,实际 ' + r.ref.slice(0, 24))
assert.deepStrictEqual(calls, ['webp'], 'WebP 成功时不应再编码 JPEG,实际 ' + calls.join(','))
}
// ② WebP 不可用(返回空)→ 落 JPEG
{
const calls = []
const api = create({
compress: async (s, c) => { calls.push(c.format); return c.format === 'webp' ? '' : JPEG },
resolve: async () => '',
})
const r = await api.put(SRC)
assert.ok(r.ref.indexOf('data:image/jpeg') === 0, 'WebP 不可用时应落 JPEG,实际 ' + r.ref.slice(0, 24))
assert.deepStrictEqual(calls, ['webp', 'jpeg'])
}
// ③ 编码器两种格式都退回 PNG → 若 JPEG 更小则取 JPEG(这就是 448px PNG 300KB 的修复点)
{
const api = create({
compress: async (s, c) => (c.format === 'webp' ? PNG : JPEG),
resolve: async () => '',
})
const r = await api.put(SRC)
assert.ok(r.ref.indexOf('data:image/jpeg') === 0, 'PNG 回退时应改用更小的 JPEG,实际 ' + r.ref.slice(0, 24))
assert.ok(r.ref.length < PNG.length, '结果应比 PNG 小')
}
// ④ 全部编码失败 → 原图兜底(不丢封面)
{
const api = create({ compress: async () => '', resolve: async () => '' })
const r = await api.put(SRC)
assert.strictEqual(r.ok, true)
assert.strictEqual(r.ref, SRC, '编码全失败时应保留原图')
}
// ⑤ 非 dataURL 输入 → 明确失败
{
const api = create({ compress: async () => WEBP, resolve: async () => '' })
const r = await api.put('https://example.com/a.png')
assert.strictEqual(r.ok, false, '外链不应被当作封面保存')
}
// ⑥ coverUrl:dataURL 直出,不触发 resolve
{
let resolved = 0
const api = create({ compress: async () => '', resolve: async () => { resolved++; return 'blob:x' } })
const r = await api.url(WEBP)
assert.strictEqual(r.ok, true)
assert.strictEqual(r.url, WEBP)
assert.strictEqual(resolved, 0, 'dataURL 不应走引用解析')
const r2 = await api.url({ __blob: 'imgblob_1' })
assert.strictEqual(r2.url, 'blob:x', '老引用应异步解析')
assert.strictEqual(resolved, 1)
}
// ⑦ 节点宽度映射(比例不定)
{
const api = create({ compress: async () => '', resolve: async () => '' })
assert.strictEqual(api.nodeWidthForAspect(2.2), 420)
assert.strictEqual(api.nodeWidthForAspect(1.6), 340)
assert.strictEqual(api.nodeWidthForAspect(1), 280)
assert.strictEqual(api.nodeWidthForAspect(0.7), 230)
assert.strictEqual(api.nodeWidthForAspect(0.45), 200)
}
console.log('image-prompt-cover checks passed(WebP优先 / JPEG兜底 / PNG回退取小 / 原图兜底 / 直出与引用 / 比例定宽)')
})()
+37
View File
@@ -0,0 +1,37 @@
// 插件通用灰由主题派生(v3.26.20):亮/暗都要有值、暗色必须更暗、且保持中性灰(不带蓝调)。
const assert = require('assert')
const fs = require('fs')
const path = require('path')
const src = fs.readFileSync(path.join(__dirname, '..', 'src', 'theme-tokens.js'), 'utf8')
const sandbox = {}
new Function('window', src)(sandbox)
const T = sandbox.IWBThemeTokens
assert.ok(T && typeof T.derive === 'function', 'theme-tokens 应导出 derive')
const light = T.derive(T.DEFAULTS, false)
const dark = T.derive(T.DEFAULTS, true)
const KEYS = ['pluginSurface', 'pluginCard', 'pluginInset', 'pluginHover']
function rgb (hex) {
const s = String(hex).trim()
assert.ok(/^#[0-9a-f]{6}$/i.test(s), '应为 6 位 hex,实际 ' + s)
return { r: parseInt(s.slice(1, 3), 16), g: parseInt(s.slice(3, 5), 16), b: parseInt(s.slice(5, 7), 16) }
}
const lum = (hex) => { const c = rgb(hex); return 0.2126 * c.r + 0.7152 * c.g + 0.0722 * c.b }
for (const k of KEYS) {
assert.ok(light[k], '亮色缺少 ' + k)
assert.ok(dark[k], '暗色缺少 ' + k)
assert.ok(lum(dark[k]) < lum(light[k]), k + ' 暗色应比亮色更暗:' + dark[k] + ' vs ' + light[k])
// 中性灰:通道极差 <= 3(防止又混进蓝调 e3e7ea)
const c = rgb(light[k])
const spread = Math.max(c.r, c.g, c.b) - Math.min(c.r, c.g, c.b)
assert.ok(spread <= 3, k + ' 亮色应为中性灰(通道差 ' + spread + '),实际 ' + light[k])
}
// 卡片必须比内嵌块更亮(层次:卡片 > 面板 > 内嵌)
assert.ok(lum(light.pluginCard) >= lum(light.pluginSurface), '卡片不应比面板更暗')
assert.ok(lum(light.pluginSurface) >= lum(light.pluginInset), '面板不应比内嵌块更暗')
console.log('theme plugin tokens checks passed(亮/暗派生 / 暗色更暗 / 中性灰 / 层次正确)')