mirror of
https://github.com/ZSeven-W/openpencil.git
synced 2026-06-01 03:14:29 +07:00
* fix(ai): add icon name aliases and fix multi-path SVG concatenation Add 55+ common icon name aliases (burger→hamburger, sushi→fish, etc.) to both client icon-resolver and server icon API for robust AI-generated icon resolution. Register Lucide's own aliases for broader coverage. Fix SVG path concatenation bug where joining multiple <path> d-values caused incorrect rendering — a standalone <path> treats initial lowercase "m" as absolute, but after concatenation it becomes relative to the previous sub-path endpoint. Now ensures each sub-path starts with absolute "M". Add tryAsyncIconFontResolution for icon_font nodes that miss local lookup — fetches from server API, caches result, and triggers canvas re-render. * fix(canvas): preserve badge/overlay absolute positioning in auto-layout Add isBadgeOverlayNode() detector for badge, indicator, notification-dot, and overlay nodes. These nodes now retain their x/y coordinates instead of being stripped by layout sanitization. Update computeLayoutPositions to exclude badge nodes from the layout flow — they keep absolute positioning and render on top (prepended for correct z-order in reverse iteration). * fix(ai): prevent duplicate canvas objects and fix emoji-to-icon pipeline Streaming path: add ensureUniqueNodeIds before inserting nodes to prevent ID collisions across multiple AI generations. Track newly inserted IDs so subsequent streaming nodes don't collide either. Canvas sync: deduplicate Fabric objects sharing the same penNodeId — keep only the one tracked in objMap, remove stale duplicates. Badge nodes: use shared isBadgeOverlayNode() for z-order insertion and skip x/y stripping in layout parents. Fix emoji-to-icon pipeline: re-run applyIconPathResolution after applyNoEmojiIconHeuristic converts emoji text nodes to path nodes, so the icon resolver can match by name (e.g. "Pizza Emoji Path" → pizza). * fix(canvas): add async icon resolution fallback for icon_font nodes When lookupIconByName fails locally, queue tryAsyncIconFontResolution to fetch from server API. Cache result in ICON_PATH_MAP and trigger canvas re-render via store update. Store iconFontName and iconStyle on Fabric object for sync tracking. * fix(ai): strengthen emoji ban in prompts and improve orchestrator defaults Update all AI prompts to explicitly ban emoji characters with concrete examples and redirect to icon_font nodes instead of the previously incorrect "path nodes" guidance. Add z-order rule to orchestrator prompt: overlay elements must come before content they overlap. Add padding support to OrchestratorPlan rootFrame type. Default mobile root frame gap to 16 for consistent spacing. * feat(electron): add publisher name to Windows build configuration Updated the `electron-builder.yml` to include a publisher name for Windows builds, enhancing the identification of the application during installation. Additionally, revised the README files across multiple languages to reflect the new project description and features, emphasizing OpenPencil as the world's first AI-native open-source vector design tool with concurrent agent teams and design-as-code capabilities. --------- Co-authored-by: Fini <fini.yang@gmail.com>
138 lines
3.7 KiB
TypeScript
138 lines
3.7 KiB
TypeScript
/**
|
|
* Electron development workflow orchestrator.
|
|
*
|
|
* 1. Start Vite dev server (bun run dev)
|
|
* 2. Wait for it to be ready on port 3000
|
|
* 3. Compile electron/ with esbuild
|
|
* 4. Launch Electron pointing at the dev server
|
|
*/
|
|
|
|
import { spawn, execSync, type ChildProcess } from 'node:child_process'
|
|
import { build } from 'esbuild'
|
|
import { join } from 'node:path'
|
|
|
|
const ROOT = join(import.meta.dirname, '..')
|
|
const VITE_DEV_PORT = 3000
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Helpers
|
|
// ---------------------------------------------------------------------------
|
|
|
|
async function waitForServer(
|
|
url: string,
|
|
timeoutMs = 30_000,
|
|
): Promise<void> {
|
|
const start = Date.now()
|
|
while (Date.now() - start < timeoutMs) {
|
|
try {
|
|
const res = await fetch(url)
|
|
if (res.ok || res.status < 500) return
|
|
} catch {
|
|
// server not ready yet
|
|
}
|
|
await new Promise((r) => setTimeout(r, 500))
|
|
}
|
|
throw new Error(`Timeout waiting for ${url}`)
|
|
}
|
|
|
|
async function compileElectron(): Promise<void> {
|
|
const common: Parameters<typeof build>[0] = {
|
|
platform: 'node',
|
|
bundle: true,
|
|
sourcemap: true,
|
|
external: ['electron'],
|
|
target: 'node20',
|
|
outdir: join(ROOT, 'electron-dist'),
|
|
outExtension: { '.js': '.cjs' },
|
|
format: 'cjs' as const,
|
|
}
|
|
|
|
await Promise.all([
|
|
build({
|
|
...common,
|
|
entryPoints: [join(ROOT, 'electron', 'main.ts')],
|
|
}),
|
|
build({
|
|
...common,
|
|
entryPoints: [join(ROOT, 'electron', 'preload.ts')],
|
|
}),
|
|
])
|
|
|
|
console.log('[electron-dev] Electron files compiled')
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Main
|
|
// ---------------------------------------------------------------------------
|
|
|
|
async function main(): Promise<void> {
|
|
// 1. Start Vite dev server
|
|
console.log('[electron-dev] Starting Vite dev server...')
|
|
const vite = spawn('bun', ['--bun', 'run', 'dev'], {
|
|
cwd: ROOT,
|
|
stdio: 'inherit',
|
|
env: { ...process.env },
|
|
})
|
|
|
|
// Ensure cleanup on exit
|
|
const cleanup = () => {
|
|
if (process.platform === 'win32' && vite.pid) {
|
|
// SIGTERM is unreliable on Windows; use taskkill for proper tree-kill
|
|
try {
|
|
execSync(`taskkill /pid ${vite.pid} /T /F`, { stdio: 'ignore' })
|
|
} catch { /* ignore */ }
|
|
} else {
|
|
vite.kill()
|
|
}
|
|
process.exit()
|
|
}
|
|
process.on('SIGINT', cleanup)
|
|
process.on('SIGTERM', cleanup)
|
|
|
|
// 2. Wait for Vite to be ready
|
|
console.log(`[electron-dev] Waiting for Vite on port ${VITE_DEV_PORT}...`)
|
|
await waitForServer(`http://localhost:${VITE_DEV_PORT}`)
|
|
console.log('[electron-dev] Vite is ready')
|
|
|
|
// 3. Compile MCP server + Electron files
|
|
console.log('[electron-dev] Compiling MCP server...')
|
|
await build({
|
|
platform: 'node',
|
|
bundle: true,
|
|
sourcemap: true,
|
|
target: 'node20',
|
|
format: 'cjs',
|
|
entryPoints: [join(ROOT, 'src', 'mcp', 'server.ts')],
|
|
outfile: join(ROOT, 'dist', 'mcp-server.cjs'),
|
|
alias: { '@': join(ROOT, 'src') },
|
|
define: { 'import.meta.env': '{}' },
|
|
})
|
|
console.log('[electron-dev] MCP server compiled')
|
|
|
|
await compileElectron()
|
|
|
|
// 4. Launch Electron
|
|
console.log('[electron-dev] Starting Electron...')
|
|
const electronBin = join(ROOT, 'node_modules', '.bin', 'electron')
|
|
const electron = spawn(electronBin, [join(ROOT, 'electron-dist', 'main.cjs')], {
|
|
cwd: ROOT,
|
|
stdio: 'inherit',
|
|
env: { ...process.env },
|
|
}) as ChildProcess
|
|
|
|
electron.on('exit', () => {
|
|
if (process.platform === 'win32' && vite.pid) {
|
|
try {
|
|
execSync(`taskkill /pid ${vite.pid} /T /F`, { stdio: 'ignore' })
|
|
} catch { /* ignore */ }
|
|
} else {
|
|
vite.kill()
|
|
}
|
|
process.exit()
|
|
})
|
|
}
|
|
|
|
main().catch((err) => {
|
|
console.error(err)
|
|
process.exit(1)
|
|
})
|