feat(image-vectorize): v0.2.1 精度可调 + 复制到剪贴板 + 高级默认展开
用户反馈三项: 1. 高级参数默认展开(不再藏起来),折叠按钮保留、展开状态记忆在 ctx.settings 2. 新增「复制 SVG」:一次写入 image/svg+xml + text/html + text/plain 三种口味, 粘到 Figma / Illustrator 直接是真矢量。Chrome 对可写 MIME 有白名单, 塞了不支持的类型会整次 write 失败,所以先 ClipboardItem.supports() 探测再逐级降级 3. 边缘精度可调:optTolerance 默认 0.2 → 0.05(三档 精细/标准/轻量), 大图降采样上限 2000 → 3000px(实测单色 3200px 96ms、灰度 4 层 3000px 179ms) 预览底部的说明改为胶囊提示(原 #75758a 裸文字在浅灰棋盘上几乎看不见), 面板间距压紧,高级区展开后整列参数在 980px 高下不用滚。 验证:本地 harness 38 项、真站 e2e 17 项(含真实剪贴板读回校验)全绿。
This commit is contained in:
1 parent
c4e4b15375
commit
d151de74a1
10 files changed
+367
-49
No files matched your search
@@ -1,7 +1,7 @@
|
||||
// 单色/灰度描摹 CLI(开发用,不进 CI):把真实素材丢进去,直接看参数效果。
|
||||
//
|
||||
// node image-vectorize/tools/trace-cli.mjs <图片> [--mode mono|gray] [--levels 3]
|
||||
// [--turd 3] [--alpha 1] [--invert] [--color #1a1a1a] [--threshold -1] [--out 目录]
|
||||
// [--turd 3] [--alpha 1] [--tol 0.1] [--invert] [--color #1a1a1a] [--threshold -1] [--out 目录]
|
||||
//
|
||||
// 产物:<out>/<name>-<mode><levels>.svg + 一张对比图 <out>/<name>-cmp.png(原图 / 结果 / 局部放大)。
|
||||
// 为什么走浏览器:PNG/JPEG 解码和 ImageData 语义都与线上一致,Node 里没有等价的零依赖解码器。
|
||||
@@ -31,13 +31,14 @@ if (!chromium) {
|
||||
|
||||
const argv = process.argv.slice(2)
|
||||
const files = []
|
||||
const opt = { mode: 'gray', levels: 3, turd: 3, alpha: 1, invert: false, color: '#1a1a1a', threshold: -1, out: '/tmp/vz-cli' }
|
||||
const opt = { mode: 'gray', levels: 3, turd: 3, alpha: 1, tol: 0.1, invert: false, color: '#1a1a1a', threshold: -1, out: '/tmp/vz-cli' }
|
||||
for (let i = 0; i < argv.length; i++) {
|
||||
const a = argv[i]
|
||||
if (a === '--mode') opt.mode = argv[++i]
|
||||
else if (a === '--levels') opt.levels = Number(argv[++i])
|
||||
else if (a === '--turd') opt.turd = Number(argv[++i])
|
||||
else if (a === '--alpha') opt.alpha = Number(argv[++i])
|
||||
else if (a === '--tol') opt.tol = Number(argv[++i])
|
||||
else if (a === '--invert') opt.invert = true
|
||||
else if (a === '--color') opt.color = argv[++i]
|
||||
else if (a === '--threshold') opt.threshold = Number(argv[++i])
|
||||
@@ -63,6 +64,7 @@ const params = {
|
||||
levels: opt.levels,
|
||||
turdSize: opt.turd,
|
||||
alphaMax: opt.alpha,
|
||||
optTolerance: opt.tol,
|
||||
invert: opt.invert,
|
||||
color: opt.color,
|
||||
threshold: opt.threshold,
|
||||
@@ -89,7 +91,7 @@ for (const file of files) {
|
||||
{ dataUrl: `data:${mime};base64,${b64}`, params }
|
||||
)
|
||||
const base = path.basename(file).replace(/\.[^.]+$/, '')
|
||||
const tag = opt.mode === 'mono' ? 'mono' : 'gray' + res.levels
|
||||
const tag = (opt.mode === 'mono' ? 'mono' : 'gray' + res.levels) + '-t' + opt.tol
|
||||
const svgPath = path.join(opt.out, `${base}-${tag}.svg`)
|
||||
fs.writeFileSync(svgPath, res.svg)
|
||||
console.log(
|
||||
|
||||
Reference in new issue
Block a user