Files
iwb-plugins-desktop/image-vectorize/tools/bundle-engine.mjs
T
qiqi c4e4b15375 feat(image-vectorize): v0.2 换 potrace 引擎,只做单色/灰度
用户裁定「只要单色/灰度就够」后重做:VTracer(彩色分层 wasm)换成 potrace
(纯 JS,Inkscape 同款内核)。文字笔画完整、turdSize 去掉毛刺、灰度层数 2–5。

- 纯 JS ⇒ 不需要宿主放宽 CSP;插件 238KB → 116KB
- 自带 potrace 移植(GPL-2.0,去 jimp 依赖,改吃 ImageData),License 随目录
- 灰度阈值自己按等像素量分位算(上游 steps:5 要 28s,这里几十 ms),
  并处理「主背景峰要排除」「切点必须严格递增」两个坑
- 新增 tools/trace-cli.mjs:拿真实素材直接跑参数、出对比图
- harness 重写 32 项(含「无 wasm-unsafe-eval 的 CSP 下跑通」反向锁);真站 e2e 13 项
2026-11-05 07:57:18 +08:00

38 lines
1.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 引擎单文件打包(开发用):把 plugin/engine.js + potrace 打成 IIFE 全局 VZEngine,便于在
// 浏览器里直接跑参数实验(tools/trace-cli.mjs 用它)。发布不走这里 —— 发布走根目录
// scripts/build-plugin.mjs(esbuild → 单文件 IIFE 插件)。
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import { createRequire } from 'node:module'
const HERE = path.dirname(fileURLToPath(import.meta.url))
const PLUGIN = path.resolve(HERE, '../plugin')
const HOST_REPO = '/Users/qiqi/open/github/image-workbench-web'
const REPO = path.resolve(HERE, '../..')
export function esbuildModule() {
for (const base of [HOST_REPO, REPO, process.cwd()]) {
try {
return createRequire(path.join(base, 'package.json'))('esbuild')
} catch {
/* 试下一个 */
}
}
throw new Error('找不到 esbuild(宿主仓 node_modules 里应该有)')
}
export function bundleEngine(outfile = '/tmp/vz-engine.bundle.js') {
const esbuild = esbuildModule()
esbuild.buildSync({
entryPoints: [path.join(PLUGIN, 'engine.js')],
bundle: true,
format: 'iife',
globalName: 'VZEngine',
platform: 'browser',
target: ['chrome110'],
outfile,
logLevel: 'error',
})
return outfile
}