Update plugin Imgbatch v0.1.6#173
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the plugin to version 0.1.6, introducing a local SVG icon system to replace external font dependencies and a new management dialog for rotation angle presets. It also improves user experience by preserving panel scroll positions during refreshes and fixes issues with resize alignment. Architecturally, it optimizes the publishing workflow with a dedicated CLI build script and a runtime-packages structure. The review feedback recommends centralizing the DEFAULT_ROTATE_PRESET_ANGLES constant to reduce duplication and unifying the normalizeRotatePresetAngles logic to ensure consistent and robust input validation across the application.
| ] | ||
| const SETTINGS_TOOL_ID = 'settings' | ||
| const PREVIEW_CACHE_LIMIT = 12 | ||
| const DEFAULT_ROTATE_PRESET_ANGLES = [-135, -90, -45, 0, 45, 90, 135, 180] |
| function normalizeRotatePresetAngles(value) { | ||
| const source = Array.isArray(value) && value.length ? value : DEFAULT_ROTATE_PRESET_ANGLES | ||
| const seen = new Set() | ||
| const next = [] | ||
| for (let index = 0; index < source.length; index += 1) { | ||
| const numeric = Math.max(-360, Math.min(360, Math.round(Number(source[index]) || 0))) | ||
| if (seen.has(numeric)) continue | ||
| seen.add(numeric) | ||
| next.push(numeric) | ||
| } | ||
| return next | ||
| } |
There was a problem hiding this comment.
此处的 normalizeRotatePresetAngles 函数实现与 main.js 中的版本不一致。当前实现使用 Number(...) || 0,这会将无效输入(如非数字字符串)静默转换为 0,可能导致预设列表中出现意外的 0°。建议统一使用 main.js 中更严谨的过滤逻辑(即跳过无效数值),并考虑将该函数提取为共享工具函数。
function normalizeRotatePresetAngles(value) {
const source = Array.isArray(value) && value.length ? value : DEFAULT_ROTATE_PRESET_ANGLES
const seen = new Set()
const next = []
for (let index = 0; index < source.length; index += 1) {
const numeric = Number(source[index])
if (!Number.isFinite(numeric)) continue
const angle = Math.max(-360, Math.min(360, Math.round(numeric)))
if (seen.has(angle)) continue
seen.add(angle)
next.push(angle)
}
return next
}
插件信息
本次变更
0.1.6runtime-packages携带运行时依赖,避免安装后缺少sharp导致本地图片处理不可用fork引入导致的执行失败问题截图 / 演示
自检清单
plugins/imgbatch/目录此 PR 由 ztools-plugin-cli 自动管理:每次
ztools publish在分支上追加一个 commit,PR 链接保持不变。