* fix(docker): support multi-platform builds and fix monorepo paths

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* perf(renderer): cache pre-rasterized paragraph images to avoid per-frame glyph rasterization   (#76)

* fix(canvas): stabilize frame label size during zoom

  Draw frame labels in screen-space after the viewport transform
  restore, converting scene coords manually. Previously fontSize=12/zoom
  fed into Math.ceil caused integer-boundary jumps that made labels
  flicker during zoom. Also skip shadow rendering while actively
  zooming for smoother performance.

* perf(renderer): cache pre-rasterized paragraph images to avoid per-frame glyph rasterization

   - Add paraImageCache (SkImage, 128 MB LRU limit) keyed on the same key as paraCache
   - Use drawImageRect instead of drawParagraph on cache hit, skipping per-frame glyph shaping and rasterization
   - Fall back to direct drawParagraph only when off-screen surface creation (MakeSurface) fails
   - Extract _dpr getter to deduplicate device-pixel-ratio resolution logic across draw paths
   - Evict oldest entries when cache exceeds byte limit; delete SkImage on eviction and dispose()

* feat(cli): introduce OpenPencil CLI for terminal control of the design tool

- Added a new CLI application under `apps/cli` to manage OpenPencil from the terminal.
- Implemented commands for app control (`start`, `stop`, `status`), document operations (`open`, `save`, `get`, `selection`), and design manipulation (`design`, `import`).
- Enhanced documentation with usage instructions and platform support details.
- Updated build scripts to include CLI compilation and publishing processes.
- Introduced a new GitHub Actions workflow for publishing the CLI to npm.
- Updated existing workflows to integrate CLI build steps and ensure proper versioning across packages.

* docs: update README files to include CLI tool details and multi-platform code export

- Added CLI section to README files in multiple languages, detailing commands for terminal control of the design tool.
- Included instructions for global installation and usage examples for the CLI.
- Expanded documentation on multi-platform code export capabilities from a single `.op` file to various frameworks.
- Updated CLAUDE.md to reference the new CLI documentation and its integration with the design tool.

* chore(bun.lock): update package dependencies to specific versions

- Removed workspace references for several packages in the bun.lock file.
- Updated dependencies for `@zseven-w/pen-core`, `@zseven-w/pen-types`, `@zseven-w/pen-codegen`, `@zseven-w/pen-figma`, and `@zseven-w/pen-renderer` to version `0.5.1-beta.1`.
- Ensured consistency in dependency management across the project.

* fix(docker): add missing CLI package.json to build context

The Dockerfile was missing COPY for apps/cli/package.json, causing
bun install --frozen-lockfile to fail because the CLI workspace
dependency could not be resolved.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* feat: add unpublish script and enhance CLI publish workflow

- Introduced a new `unpublish` script to manage unpublishing of all @zseven-w packages from npm, with options for specific versions, all versions, or deprecation.
- Updated the GitHub Actions workflow to check if a version is already published before proceeding with the publish step, ensuring better error handling and preventing conflicts.
- Removed the fallback for npm publish commands to fail fast on errors, improving the reliability of the publishing process.

* chore(bun.lock): update package versions and configuration

- Bumped the configVersion from 0 to 1 in bun.lock.
- Updated several package dependencies to their latest versions, including:
  - @anthropic-ai/claude-agent-sdk to 0.2.81
  - @babel/helpers to 7.29.2
  - @babel/parser to 7.29.2
  - @babel/runtime to 7.29.2
  - @csstools/color-helpers to 6.0.2
  - @csstools/css-color-parser to 4.0.2
- Ensured consistency in dependency management across the project.

* docs: restore Feishu group QR code in Chinese README

* chore: update dependencies and add workspace references

- Added "h3" package with version "^2.0.1-rc.18" to bun.lock, package.json, and apps/web/package.json.
- Updated dependencies in multiple packages to use "workspace:*" for better management and consistency across the project.
- Ensured all relevant packages are aligned with the latest workspace structure.

* chore: update package versions in bun.lock and package.json

- Updated several @tanstack packages to their latest versions, including:
  - @tanstack/react-devtools to 0.10.0
  - @tanstack/react-router to 1.168.1
  - @tanstack/react-router-devtools to 1.166.11
  - @tanstack/react-router-ssr-query to 1.166.10
  - @tanstack/react-start to 1.167.2
  - @tanstack/router-plugin to 1.167.1
- Bumped @tanstack/devtools-vite to 0.6.0 in devDependencies.
- Mocked 'paper' module in security tests to prevent crashes in jsdom environment.

* chore: update CLI and MCP compile scripts to include package aliases

- Enhanced the `mcp:compile` and `cli:compile` scripts in `package.json` and `apps/cli/package.json` to include additional package aliases for better module resolution.
- This change improves the build process by ensuring that the correct paths are used for various dependencies.

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: leinaldo <60176594+leinaldo@users.noreply.github.com>
Co-authored-by: Fini <fini.yang@gmail.com>
This commit is contained in:
Kayshen Xu 2026-03-23 22:31:06 +08:00 committed by GitHub
parent b4d1d2a7bb
commit 370e51c0f7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 1178 additions and 1097 deletions

View file

@ -34,6 +34,15 @@ jobs:
id: version
run: echo "version=$(jq -r .version package.json)" >> "$GITHUB_OUTPUT"
- name: Check if version already published
run: |
VERSION=${{ steps.version.outputs.version }}
if npm view "@zseven-w/pen-types@${VERSION}" version 2>/dev/null; then
echo "::error::Version ${VERSION} already exists on npm. Aborting."
exit 1
fi
echo "Version ${VERSION} is not yet published. Proceeding."
- name: Replace workspace:* with version
run: |
VERSION=${{ steps.version.outputs.version }}
@ -61,45 +70,45 @@ jobs:
- name: Verify CLI build
run: node apps/cli/dist/openpencil-cli.cjs --version
# Publish in topological order
# Publish in topological order — fail fast on error
- name: Publish pen-types
run: npm publish --access public || true
run: npm publish --access public
working-directory: packages/pen-types
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Publish pen-core
run: npm publish --access public || true
run: npm publish --access public
working-directory: packages/pen-core
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Publish pen-codegen
run: npm publish --access public || true
run: npm publish --access public
working-directory: packages/pen-codegen
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Publish pen-figma
run: npm publish --access public || true
run: npm publish --access public
working-directory: packages/pen-figma
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Publish pen-renderer
run: npm publish --access public || true
run: npm publish --access public
working-directory: packages/pen-renderer
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Publish pen-sdk
run: npm publish --access public || true
run: npm publish --access public
working-directory: packages/pen-sdk
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Publish CLI
run: npm publish --access public || true
run: npm publish --access public
working-directory: apps/cli
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

View file

@ -11,6 +11,7 @@ COPY packages/pen-renderer/package.json packages/pen-renderer/
COPY packages/pen-sdk/package.json packages/pen-sdk/
COPY apps/web/package.json apps/web/
COPY apps/desktop/package.json apps/desktop/
COPY apps/cli/package.json apps/cli/
RUN bun install --frozen-lockfile
COPY . .
ENV NODE_OPTIONS="--max-old-space-size=4096"

View file

@ -365,6 +365,10 @@ bun run cli:compile # 编译 CLI 到 dist
</a>
— 提问、分享设计、提出功能建议。
**飞书交流群**
<img src="./screenshot/557517811-62010928-d91a-4223-bc10-9ee7a4fbf043.jpg" alt="飞书交流群" width="240" />
## Star History
<a href="https://star-history.com/#ZSeven-W/openpencil&Date">

View file

@ -15,6 +15,6 @@
"dist"
],
"scripts": {
"compile": "cd ../web && esbuild ../cli/src/index.ts --bundle --platform=node --target=node20 --outfile=../cli/dist/openpencil-cli.cjs --format=cjs --sourcemap --alias:@=src --define:import.meta.env={} --external:canvas --external:paper"
"compile": "cd ../web && esbuild ../cli/src/index.ts --bundle --platform=node --target=node20 --outfile=../cli/dist/openpencil-cli.cjs --format=cjs --sourcemap --alias:@=src --alias:@zseven-w/pen-types=../../packages/pen-types/src --alias:@zseven-w/pen-core=../../packages/pen-core/src --alias:@zseven-w/pen-codegen=../../packages/pen-codegen/src --alias:@zseven-w/pen-figma=../../packages/pen-figma/src --alias:@zseven-w/pen-renderer=../../packages/pen-renderer/src --alias:@zseven-w/pen-sdk=../../packages/pen-sdk/src --define:import.meta.env={} --external:canvas --external:paper"
}
}

View file

@ -2,5 +2,12 @@
"name": "@zseven-w/web",
"version": "0.5.1",
"private": true,
"type": "module"
"type": "module",
"dependencies": {
"@zseven-w/pen-types": "workspace:*",
"@zseven-w/pen-core": "workspace:*",
"@zseven-w/pen-codegen": "workspace:*",
"@zseven-w/pen-figma": "workspace:*",
"@zseven-w/pen-renderer": "workspace:*"
}
}

View file

@ -1,5 +1,16 @@
// @vitest-environment jsdom
import { describe, it, expect } from 'vitest'
import { describe, it, expect, vi } from 'vitest'
// paper.js self-initializes a Canvas 2D context on import, which crashes in
// jsdom. Mock it before any transitive import can trigger the real module.
vi.mock('paper', () => ({
default: {
PaperScope: class {},
setup: () => {},
project: { activeLayer: { removeChildren: () => {} } },
},
}))
import { parseSvgToNodes } from '@/utils/svg-parser'
// ---------------------------------------------------------------------------

2096
bun.lock

File diff suppressed because it is too large Load diff

View file

@ -21,7 +21,7 @@
"build": "cd apps/web && bun --bun vite build",
"preview": "cd apps/web && bun --bun vite preview",
"test": "cd apps/web && bun --bun vitest run --passWithNoTests",
"mcp:compile": "cd apps/web && esbuild src/mcp/server.ts --bundle --platform=node --target=node20 --outfile=../../out/mcp-server.cjs --format=cjs --sourcemap --alias:@=src --define:import.meta.env={} --external:canvas --external:paper",
"mcp:compile": "cd apps/web && esbuild src/mcp/server.ts --bundle --platform=node --target=node20 --outfile=../../out/mcp-server.cjs --format=cjs --sourcemap --alias:@=src --alias:@zseven-w/pen-types=../../packages/pen-types/src --alias:@zseven-w/pen-core=../../packages/pen-core/src --alias:@zseven-w/pen-codegen=../../packages/pen-codegen/src --alias:@zseven-w/pen-figma=../../packages/pen-figma/src --alias:@zseven-w/pen-renderer=../../packages/pen-renderer/src --alias:@zseven-w/pen-sdk=../../packages/pen-sdk/src --define:import.meta.env={} --external:canvas --external:paper",
"mcp:dev": "bun run apps/web/src/mcp/server.ts",
"electron:dev": "bun run apps/desktop/dev.ts",
"electron:compile": "esbuild apps/desktop/main.ts apps/desktop/preload.ts --bundle --platform=node --target=node20 --outdir=out/desktop --external:electron --format=cjs --out-extension:.js=.cjs --sourcemap",
@ -30,14 +30,16 @@
"electron:build:mac-x64": "BUILD_TARGET=electron bun --bun run build && bun run electron:compile && bun run mcp:compile && bun run cli:compile && npx electron-builder --config apps/desktop/electron-builder.yml --mac --x64",
"electron:build:mac-universal": "BUILD_TARGET=electron bun --bun run build && bun run electron:compile && bun run mcp:compile && bun run cli:compile && npx electron-builder --config apps/desktop/electron-builder.yml --mac --arm64 --x64",
"electron:build:mac-both": "bun run electron:build:mac-arm64 && bun run electron:build:mac-x64",
"cli:compile": "cd apps/web && esbuild ../cli/src/index.ts --bundle --platform=node --target=node20 --outfile=../cli/dist/openpencil-cli.cjs --format=cjs --sourcemap --alias:@=src --define:import.meta.env={} --external:canvas --external:paper",
"cli:compile": "cd apps/web && esbuild ../cli/src/index.ts --bundle --platform=node --target=node20 --outfile=../cli/dist/openpencil-cli.cjs --format=cjs --sourcemap --alias:@=src --alias:@zseven-w/pen-types=../../packages/pen-types/src --alias:@zseven-w/pen-core=../../packages/pen-core/src --alias:@zseven-w/pen-codegen=../../packages/pen-codegen/src --alias:@zseven-w/pen-figma=../../packages/pen-figma/src --alias:@zseven-w/pen-renderer=../../packages/pen-renderer/src --alias:@zseven-w/pen-sdk=../../packages/pen-sdk/src --define:import.meta.env={} --external:canvas --external:paper",
"cli:dev": "bun run apps/cli/src/index.ts",
"publish:beta": "bash scripts/publish-beta.sh",
"unpublish": "bash scripts/unpublish.sh",
"bump": "sh -c 'V=$0; [ -z \"$V\" ] && echo \"Usage: bun run bump <version>\" && exit 1; for f in package.json apps/*/package.json packages/*/package.json; do [ -f \"$f\" ] && jq --arg v \"$V\" \".version=\\$v\" \"$f\" > \"$f.tmp\" && mv \"$f.tmp\" \"$f\" && echo \"$f → $V\"; done'"
},
"dependencies": {
"@anthropic-ai/claude-agent-sdk": "^0.2.47",
"@anthropic-ai/sdk": "^0.77.0",
"h3": "^2.0.1-rc.18",
"@fontsource-variable/inter": "^5.2.8",
"@fontsource/dm-sans": "^5.2.8",
"@fontsource/inter": "^5.2.8",
@ -64,12 +66,12 @@
"@radix-ui/react-toggle": "^1.1.10",
"@radix-ui/react-tooltip": "^1.2.8",
"@tailwindcss/vite": "^4.1.18",
"@tanstack/react-devtools": "^0.7.0",
"@tanstack/react-router": "^1.132.0",
"@tanstack/react-router-devtools": "^1.132.0",
"@tanstack/react-router-ssr-query": "^1.131.7",
"@tanstack/react-start": "^1.132.0",
"@tanstack/router-plugin": "^1.132.0",
"@tanstack/react-devtools": "0.10.0",
"@tanstack/react-router": "1.168.1",
"@tanstack/react-router-devtools": "1.166.11",
"@tanstack/react-router-ssr-query": "1.166.10",
"@tanstack/react-start": "1.167.2",
"@tanstack/router-plugin": "1.167.1",
"canvaskit-wasm": "^0.40.0",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
@ -94,7 +96,7 @@
"zustand": "^5.0.11"
},
"devDependencies": {
"@tanstack/devtools-vite": "^0.3.11",
"@tanstack/devtools-vite": "0.6.0",
"@testing-library/dom": "^10.4.0",
"@testing-library/react": "^16.2.0",
"@types/node": "^22.10.2",

View file

@ -16,8 +16,8 @@
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@zseven-w/pen-types": "0.5.1-beta.1",
"@zseven-w/pen-core": "0.5.1-beta.1"
"@zseven-w/pen-types": "workspace:*",
"@zseven-w/pen-core": "workspace:*"
},
"devDependencies": {
"typescript": "^5.7.2"

View file

@ -16,7 +16,7 @@
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@zseven-w/pen-types": "0.5.1-beta.1",
"@zseven-w/pen-types": "workspace:*",
"nanoid": "^5.1.6",
"paper": "^0.12.18"
},

View file

@ -16,7 +16,7 @@
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@zseven-w/pen-types": "0.5.1-beta.1",
"@zseven-w/pen-types": "workspace:*",
"kiwi-schema": "^0.5.0",
"uzip": "^0.20201231.0",
"fzstd": "^0.1.1"

View file

@ -16,8 +16,8 @@
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@zseven-w/pen-types": "0.5.1-beta.1",
"@zseven-w/pen-core": "0.5.1-beta.1",
"@zseven-w/pen-types": "workspace:*",
"@zseven-w/pen-core": "workspace:*",
"rbush": "^4.0.1"
},
"peerDependencies": {

View file

@ -16,11 +16,11 @@
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@zseven-w/pen-types": "0.5.1-beta.1",
"@zseven-w/pen-core": "0.5.1-beta.1",
"@zseven-w/pen-codegen": "0.5.1-beta.1",
"@zseven-w/pen-figma": "0.5.1-beta.1",
"@zseven-w/pen-renderer": "0.5.1-beta.1"
"@zseven-w/pen-types": "workspace:*",
"@zseven-w/pen-core": "workspace:*",
"@zseven-w/pen-codegen": "workspace:*",
"@zseven-w/pen-figma": "workspace:*",
"@zseven-w/pen-renderer": "workspace:*"
},
"devDependencies": {
"typescript": "^5.7.2"

View file

@ -15,6 +15,15 @@ ROOT="$(cd "$(dirname "$0")/.." && pwd)"
BASE_VERSION=$(jq -r .version "$ROOT/package.json")
FORCE_NUM="${1:-}"
# --- Guard: block beta publish if release version already exists on npm ---
RELEASE_CHECK=$(npm view "@zseven-w/pen-types@${BASE_VERSION}" version 2>/dev/null || true)
if [ -n "$RELEASE_CHECK" ]; then
echo "ERROR: Release version ${BASE_VERSION} already exists on npm."
echo "Publishing a beta for an already-released version creates conflicting dependencies."
echo "Bump the version first (e.g. bun run bump 0.5.2), then publish beta."
exit 1
fi
# Packages in topological order
PACKAGES=(
packages/pen-types

74
scripts/unpublish.sh Executable file
View file

@ -0,0 +1,74 @@
#!/bin/bash
# Unpublish all @zseven-w packages from npm for a given version.
#
# Usage:
# bun run unpublish 0.5.1 # unpublish specific version from all packages
# bun run unpublish 0.5.1 --all # unpublish ALL versions of all packages
# bun run unpublish 0.5.1 --deprecate # deprecate instead of unpublish (fallback)
#
# Packages are removed in reverse topological order (dependents first, then dependencies)
# to avoid npm's "has dependent packages" rejection.
set -euo pipefail
VERSION="${1:-}"
FLAG="${2:-}"
if [ -z "$VERSION" ]; then
echo "Usage: bun run unpublish <version> [--all|--deprecate]"
echo ""
echo " <version> Version to unpublish (e.g. 0.5.1)"
echo " --all Unpublish ALL versions of every package"
echo " --deprecate Deprecate instead of unpublish"
exit 1
fi
# Reverse topological order: dependents first, then dependencies
PACKAGES=(
@zseven-w/openpencil
@zseven-w/pen-sdk
@zseven-w/pen-renderer
@zseven-w/pen-codegen
@zseven-w/pen-figma
@zseven-w/pen-core
@zseven-w/pen-types
)
FAILED=()
for pkg in "${PACKAGES[@]}"; do
if [ "$FLAG" = "--deprecate" ]; then
echo "Deprecating $pkg@$VERSION ..."
npm deprecate "${pkg}@${VERSION}" "this version has been deprecated, do not use" --force 2>&1 || {
echo " ⚠ Failed to deprecate $pkg@$VERSION"
FAILED+=("$pkg@$VERSION")
}
elif [ "$FLAG" = "--all" ]; then
echo "Unpublishing $pkg (all versions) ..."
npm unpublish "$pkg" --force 2>&1 || {
echo " ⚠ Failed to unpublish $pkg"
FAILED+=("$pkg")
}
else
echo "Unpublishing $pkg@$VERSION ..."
npm unpublish "${pkg}@${VERSION}" --force 2>&1 || {
echo " ⚠ Failed to unpublish $pkg@$VERSION (try --all to remove entire package)"
FAILED+=("$pkg@$VERSION")
}
fi
echo ""
done
echo "================================"
if [ ${#FAILED[@]} -eq 0 ]; then
echo "All packages processed successfully."
else
echo "Failed packages:"
for f in "${FAILED[@]}"; do
echo " - $f"
done
echo ""
echo "Tip: If unpublish fails due to dependent packages, use --all to remove entire packages,"
echo " or --deprecate as a fallback."
fi
echo "================================"