Commit graph

1125 commits

Author SHA1 Message Date
Danila Poyarkov cf416e6ceb fix(io): parse fig files off the main thread 2026-04-25 12:26:39 +03:00
Danila Poyarkov 317b3469df fix(kiwi): resolve Figma variable aliases 2026-04-25 12:21:35 +03:00
Danila Poyarkov 006e143525 fix(canvas): render size badge in screen space so it doesn't scale with zoom
The selection size pill was drawn in local node space after
canvas.concat(worldMatrix * viewMatrix), causing it to scale
with the canvas zoom. Now computed in screen coordinates like
the multi-selection badge.
2026-04-23 20:34:41 +03:00
Danila Poyarkov d5b63682c4 chore: commit Cargo.lock with fix-path-env dependency 2026-04-23 20:07:12 +03:00
Danila Poyarkov 44f24fa72e fix(undo): call requestRender after undo
undoAction was missing requestRender, unlike redoAction. Added
E2E test: 3 duplicates then 3 undos verifies all are reversed.
2026-04-23 20:03:11 +03:00
Danila Poyarkov 668309a557 fix(clipboard): catch invalid kiwi data in parseFigmaClipboard
Non-Figma clipboard content (plain text, images) matched the figmeta
regex but failed at decodeMessage, flooding the console with unhandled
promise rejections on every paste.
2026-04-23 19:51:42 +03:00
Danila Poyarkov 35f3bb7f54 ci: create GitHub releases as drafts
Auto-generated release notes from CHANGELOG.md are often wrong.
Create as draft so the changelog section can be reviewed and
pasted manually before publishing.
2026-04-23 17:16:58 +03:00
Danila Poyarkov ba414e1af7 Release v0.11.8 2026-04-23 16:15:37 +03:00
Danila Poyarkov 8b5e372953 fix(tauri): use navigator.platform for Windows detection in MCP spawn
navigator.userAgent may not contain 'Windows' in all WebView2
contexts. navigator.platform.includes('Win') is more reliable.

Verified working on Windows x64 VM — MCP server spawns via
cmd /c and connects successfully.
2026-04-23 16:01:11 +03:00
Danila Poyarkov 1bf19fff59 fix(app): inline Tauri detection in EditorView
IS_TAURI is evaluated at module load time and may be false if
__TAURI_INTERNALS__ isn't injected yet. This prevented the
automation WebSocket from connecting on Windows and some Linux
configurations.
2026-04-23 14:37:33 +03:00
Danila Poyarkov 8c643298f3 Revert "debug: add MCP spawn logging, revert cmd approach"
This reverts commit 663e1018e7.
2026-04-23 14:05:19 +03:00
Danila Poyarkov efd1ef2ba6 Revert "debug: localStorage MCP debug"
This reverts commit c9a18c9094.
2026-04-23 14:05:19 +03:00
Danila Poyarkov c9a18c9094 debug: localStorage MCP debug 2026-04-23 14:04:09 +03:00
Danila Poyarkov 663e1018e7 debug: add MCP spawn logging, revert cmd approach 2026-04-23 13:58:53 +03:00
Danila Poyarkov 5b50b1f514 fix(automation): inline Tauri detection in spawnMCPIfNeeded
IS_TAURI is evaluated at module load time and can be false if
__TAURI_INTERNALS__ isn't injected yet. Check at call time instead.
2026-04-23 13:36:19 +03:00
Danila Poyarkov fbf582a493 fix(tauri): fix MCP server spawn on Windows and PATH on macOS
- Windows: npm installs .cmd wrappers, not direct executables. Spawn
  via 'cmd /c openpencil-mcp-http' on Windows to resolve .cmd files.
- macOS/Linux: add fix-path-env-rs to inherit shell PATH in GUI apps.
- Add 'cmd' to shell spawn capabilities for Windows.

Fixes #226
2026-04-23 13:20:58 +03:00
Danila Poyarkov 1f073859c9 fix(tauri): fix PATH not inherited by GUI app on macOS/Linux
macOS GUI apps don't inherit shell PATH from .bashrc/.zshrc, so
openpencil-mcp-http installed via bun/npm/nvm couldn't be found.
Added fix-path-env-rs which reads /etc/paths and shell config
to populate PATH before spawning child processes.

Fixes #226
2026-04-23 11:57:38 +03:00
Danila Poyarkov d25d80083b fix(vue): resolve unexported subpath import breaking npm consumers
- Export getAbsolutePositionFull from @open-pencil/core/canvas subpath
- Update vue import from @open-pencil/core/canvas/coordinate to @open-pencil/core/canvas
- Formatting fixes from oxfmt in pen/convert.ts, pen/read.ts, figma-factory.ts
2026-04-22 21:11:53 +03:00
Danila Poyarkov f3dbf2c271 Release v0.11.7 2026-04-22 20:31:33 +03:00
Danila Poyarkov 14325280d9 docs(i18n): translate all missing pages to 6 languages
- 78 SDK pages per language (components, composables, advanced API,
  guides, architecture, getting-started)
- vector-edit.md user guide page (5 languages)
- Update stale ru/programmable/cli/inspecting.md
- Fix YAML frontmatter quoting for colons in descriptions

474 files, 0 missing pages across de/es/fr/it/pl/ru.
VitePress build verified — all 546 SDK pages render.
2026-04-22 18:35:22 +03:00
Danila Poyarkov 51213d014e docs: update README and AGENTS.md for new features
- Update tool count from 90 to 100+
- Document OPENPENCIL_MCP_ROOT env var for file path scoping
- Document MCP-only tools, export path param, and prompt markdown files
  in AGENTS.md
2026-04-22 18:12:15 +03:00
Danila Poyarkov d2d6a89448 fix(lint): resolve all linting warnings and errors
- scene-graph: replace non-null assertion with guard
- figma-api: console.log → console.warn for notify()
- editor/nodes: replace non-null assertion with guard
- automation/server: console.log → console.debug
- mcp/stdio: proper Buffer/ArrayBuffer/Buffer[] UTF-8 decoding
- design-jsx/render: suppress no-implied-eval for Function constructor

0 warnings, 0 errors.
2026-04-22 18:01:52 +03:00
Danila Poyarkov 84c5e0dded docs: update changelog 2026-04-22 17:53:32 +03:00
Danila Poyarkov 1d5558ddc3 feat: JSX reference, multi-root JSX, prompts as markdown files
- Move CODEGEN_PROMPT to codegen.md, loaded via raw-md bundler plugin
- Add JSX_REFERENCE as jsx-reference.md with full prop/tag/example docs
- Copy JSX Reference button (book icon) in Code panel header
- Multi-root JSX: try parsing as-is, wrap in fragment on failure
- Component and Instance tag aliases in JSX renderer
- renderJSX returns RenderResult[] to support fragments
- raw-md plugin for both tsdown and Vite

Co-authored-by: sld0Ant <sld0Ant@users.noreply.github.com>
2026-04-22 17:51:41 +03:00
Danila Poyarkov d692953d62 test: fix pre-existing failures and add coverage for new features
- Fix mcp-stdio.test.ts: defer heavy SDK imports to avoid describe()
  registration race when running full suite
- Fix mcp-server.test.ts: add server.close() to properly clean up
  sessions and pending requests between tests (eliminates 8 unhandled
  errors)
- Add mcp-path-scoping tests: path traversal, sibling dir, root prefix
  trick, valid paths
- Add editor-store-path tests: setPlannedFilePath with Unix/Windows
  paths
- Add MCP server tests: open_file/new_document registered when mcpRoot
  is set, absent when null

0 fail, 0 errors, 1108 pass
2026-04-22 17:20:09 +03:00
Danila Poyarkov b502b43c4d feat(mcp): add open_file, new_document tools and disk export via path param
- open_file: opens a .fig/.pen from disk into a new tab via MCP
- new_document: creates an empty doc with optional save path
- export_image, export_svg, get_jsx: optional path param writes output
  to disk instead of returning base64/string (avoids flooding AI context)
- OPENPENCIL_MCP_ROOT env var scopes all file paths (defaults to cwd)
- setPlannedFilePath + startWatchingCurrentFile on editor store
- Extract openFileFromPath helper in use-menu.ts
- Add fs:allow-mkdir and scoped fs:allow-watch Tauri capabilities
- Better 'app not connected' error in stdio — instructs agent to stop

Co-authored-by: Jais Pedersen <jais@pedersens.net>
2026-04-22 17:05:54 +03:00
Danila Poyarkov a46d63916c fix(chat): fix provider settings popover not appearing
The Tip (Tooltip) wrapper around PopoverTrigger caused floating-ui
to miscalculate the popover position as translate(0px, -200%),
rendering it off-screen. Replaced with a plain title attribute
for the hover hint.

Fixes #218
2026-04-22 16:52:36 +03:00
Danila Poyarkov d0b5c51c5a fix(tools): set_font_range now produces valid style runs
- Use applyStyleToRange from text/style-runs.ts instead of naively
  appending runs (which created overlaps and invalid state)
- Apply fontWeight from style name (e.g. 'Bold' → 700)
- Apply color as fills on the style override
- Previously the color param was accepted but silently ignored

Fixes #214
2026-04-22 16:01:03 +03:00
Danila Poyarkov 5c0262fa80 docs: update changelog 2026-04-22 15:53:07 +03:00
Danila Poyarkov 99c5e7b609 fix(app): show toast when MCP server fails to start
Previously the error was silently caught with console.error, leaving
Windows users with no indication why the automation bridge was missing.
Now shows a visible toast with install instructions.
2026-04-22 15:51:26 +03:00
Danila Poyarkov 3eeea4203c fix(mcp): explicitly list entry points in tsconfig
tsgo with `include: ["src"]` sometimes skips standalone entry points
like stdio.ts that aren't imported by other files. This caused the
published npm package to be missing dist/stdio.js, breaking the
`openpencil-mcp` stdio binary.

Fixes #224 (npm publish issue)
2026-04-22 15:49:18 +03:00
Danila Poyarkov 10921d1b58 feat: JSX absolute positioning + MCP tools/list_changed on app connect
JSX renderer: support position="absolute", top, and left props for
placing children inside auto-layout containers without breaking flow.

MCP server: send notifications/tools/list_changed when the desktop
app connects or disconnects, so MCP clients can refresh their tool
list instead of discovering disconnection per-call.

Addresses #208 (findings 2 and 5)
2026-04-22 15:40:19 +03:00
Danila Poyarkov 7513399fce fix(mcp): coerce string-encoded numbers in tool parameters
MCP clients often serialize numeric arguments as JSON strings.
Previously this caused validation errors on tools like node_move.
Now both the MCP server (zod) and AI adapter (valibot) coerce
string-encoded numbers to numbers, rejecting only genuinely
non-numeric values like 'abc'.

Fixes #207
2026-04-22 14:40:11 +03:00
Danila Poyarkov ab1ff69f99 fix(vector): validate VectorNetwork input in create_vector
create_vector now validates the path JSON before accepting it:
checks vertices have numeric coordinates and segment indices are
in range. Returns a clear error message instead of silently
creating a malformed node that crashes on save.

The scene graph also normalizes vectorNetwork on updateNode as
a safety net for other code paths.
2026-04-22 14:35:25 +03:00
Danila Poyarkov 3727fa19d0 test(vector): add normalizeVectorNetwork tests
Cover missing tangent defaults, partial tangent, and encode/decode
round-trip for segments created without tangent handles.
2026-04-22 14:31:49 +03:00
Danila Poyarkov 66b2e7c487 fix(vector): default missing tangents to {x:0, y:0} in create_vector
Vectors created via MCP with straight-line segments (no tangent
handles) crashed the .fig serializer on save. Segments without
tangentStart/tangentEnd are now normalized to zero vectors at
creation time, producing straight line segments as intended.

Fixes #206
2026-04-22 14:29:25 +03:00
Danila Poyarkov 405a3f2ecf fix(vue): show Create Instance instead of Create Component for components
When right-clicking a component, the context menu now shows
'Create Instance' instead of 'Create Component'. Previously both
were shown simultaneously.
2026-04-22 14:21:18 +03:00
Danila Poyarkov 3a2a3865f4 fix(vue): enable Create Instance menu item for components
The disabled flag was inverted — the manually constructed menu item
used `!commandMenuItem(...).disabled` which made the item disabled
when the command was enabled, and vice versa. Replaced with a direct
commandMenuItem() call which handles label, disabled, and action
correctly.

Fixes #223
2026-04-22 14:16:14 +03:00
Danila Poyarkov e23b3f0ce1 feat(layout): use opentype.js for accurate headless text measurement
estimateTextSize() now tries opentype.js per-glyph advance widths
before falling back to the rough 0.6 × fontSize × charCount heuristic.
Since font data is already cached via loadFont(), this gives accurate
variable-width measurement for any loaded font — no CanvasKit needed.

Parsed opentype.js Font objects are cached per family+style to avoid
reparsing on every layout pass.
2026-04-22 14:11:36 +03:00
Danila Poyarkov 226542cfcf fix(layout): use stored .fig dimensions for headless text measurement
The estimateTextSize() fallback (fontSize × 0.6 × charCount) produced
wildly inaccurate results, causing 26K node mismatches on material3.fig.
Nodes imported from .fig files already carry Figma's computed dimensions —
use those instead. Falls back to the estimate only for newly-created
nodes with the 100×100 default size.

Reduces headless layout mismatches by ~56% (26,299 → ~11,669), with
TEXT node mismatches dropping 92%.

Fixes #212

Co-authored-by: Alexander Bonin <3462438+alex4o@users.noreply.github.com>
2026-04-22 14:00:07 +03:00
Danila Poyarkov c2a43234a3 fix(cli): remove inline examples from query description
The multi-line description caused citty to pad every other command's
row to the same height, creating huge vertical gaps in --help output.

Fixes #219
2026-04-22 13:53:03 +03:00
Danila Poyarkov 125240aa1b docs: update changelog with unreleased changes 2026-04-22 13:48:39 +03:00
Danila Poyarkov 44484050e2 fix(canvas): make canvas focusable so Backspace works after click
The canvas had no tabindex, so clicking on it didn't move focus away
from previously focused input elements. When document.activeElement
was still an input/textarea (e.g. from a panel interaction), the
keyboard shortcut guard treated Backspace as blocked by an active
input — making it impossible to delete selected nodes via the canvas.

- Add tabindex="-1" + outline-none to the canvas element
- Explicitly focus canvas on mousedown (except during text editing)

Fixes #220
2026-04-22 13:45:23 +03:00
Danila Poyarkov 776d8969d4 fix(app): support cmd/ctrl+click for layers panel multi-select
Previously only Shift+click toggled additive selection in the layers
panel. Cmd+click (macOS) and Ctrl+click (Windows/Linux) had no effect
beyond replacing the selection with a single layer.

Treat Shift, Cmd, and Ctrl modifiers equally as additive toggle, matching
common design tool conventions (Figma, Sketch).

Co-authored-by: TKman <102001532+greekr4@users.noreply.github.com>
2026-04-22 13:28:25 +03:00
Danila Poyarkov 4721fa0635 fix(build): bump PWA precache limit for canvaskit-webgpu
The WebGPU canvaskit.wasm grew to 9.7 MB, exceeding the previous 8 MB
workbox precache limit. Bump to 12 MB.
2026-04-22 13:28:25 +03:00
Joseph Cumines c38223a700
fix(tauri): correctly configure NSAllowsLocalNetworking
Fixes #213
2026-04-22 13:01:38 +03:00
Chris Gliddon 0f875eee46
feat(canvas): default canvas bg to dark on prefers-color-scheme: dark (#205)
A user on a dark OS who launches OpenPencil currently gets a pure-white
canvas flash into their dark desktop every time — visually jarring and
eye-straining in low light. Upstream has no theme system at all, so
this change defers to the OS `prefers-color-scheme` for newly-created
pages only.

Changes:

- Add `CANVAS_BG_COLOR_DARK` (#2c2c2c, matching Figma's dark-mode
  canvas) next to the existing light `CANVAS_BG_COLOR`.
- Add `getDefaultCanvasBgColor()` helper that reads
  `matchMedia('(prefers-color-scheme: dark)')` once per call.
- Use the helper in `editor/create.ts` (initial editor state) and
  `editor/pages.ts` (page-switch reset). Both are new-page
  initializers.

Deliberately untouched:

- `io/formats/fig/export.ts` still writes the static light
  `CANVAS_BG_COLOR` as the page `backgroundColor`. If a dark-theme
  user's exports forced darkness on recipients, files wouldn't be
  portable. The serialization path stays neutral.
- `canvas/renderer.ts` default — only a fallback when state is
  missing `pageColor`; effectively dead once `create.ts` runs.
- Per-page ColorInput in `PageSection.vue` remains the manual
  override for any user preference.

Companion colors (rulers, selection, snap) were already dark-
friendly values and need no adjustment — rulers become slightly more
legible on dark canvas than they were on light.

Tested on Arch + KDE Plasma (dark) + WebKit2GTK 2.52 + Mesa 26:
new pages render ~#2c2c2c, switching to light OS theme flips back
to #f5f5f5 on next launch, saved-and-reopened files keep the light
export value (confirming the serialization boundary).
2026-04-20 11:44:50 +03:00
Anton Soldatov 029c3637a1
Fix tab order and keyboard handling in inspector panel (#191)
* fix(a11y): tab order in inspector panel follows visual layout

- ScrubInput gets tabindex=0 so Tab reaches it; on focus it enters
  edit mode and transfers focus to the inner <input>
- All inspector buttons get explicit tabindex=0 to follow DOM order
- Tab flow: align buttons → X → Y → W → H → rotation → flip/rotate →
  opacity → corner radius → ...

Closes #180

* fix(inspector): apply ScrubInput value live while typing

* fix(keyboard): block shortcuts while ScrubInput is focused

- Detect scrub input focus via closest() in isEditing() guard
- Add isScrubInputFocused() check in plain() so tool shortcuts,
  Backspace, Enter etc. don't fire while typing in inspector fields

* fix(inspector): use reactive state for ScrubInput focus, remove redundant tabindex on buttons

- Surface editing state from ScrubInputRoot via editing-change emit
- Track scrubInputFocused in editor store instead of querying DOM
- Remove no-op tabindex="0" from all <button> elements
- Keep tabindex on ScrubInput wrapper <div> (actual tab order fix)

---------

Co-authored-by: Danila Poyarkov <dev@dannote.net>
2026-04-16 10:14:16 +03:00
Lay Flags 7ae97935e2
fix(layout): resolve design token variables before passing to yoga-layout (#202)
* fix(layout): resolve design token variables before passing to yoga-layout

applyPadding() and applyAutoLayout() passed variable references like
$--spacing-lg directly to yoga-layout's setPadding()/setGap() which
expects numeric values, causing a crash.

Now resolves variable references via ctx.resolveNumber() before
assignment, following the same pattern already used by parseSize()
and applyCornerRadius() in the same file.

Fixes open-pencil/open-pencil#201

* test(layout): add regression tests for variable padding/gap resolution (#201)
2026-04-16 10:11:28 +03:00
Chris Gliddon 2cb32cfb00
feat(mcp): add list_available_fonts tool for font discovery (#210)
* feat(mcp): add list_available_fonts tool for font discovery

The existing list_fonts tool reports only fonts currently used in the
current page (it walks every TEXT node and groups by fontFamily).
Agents authoring new text have no way to discover what fonts the host
can render — they have to guess and hope set_font succeeds.

This adds list_available_fonts, which returns the set of font
families the host advertises. On desktop this is the system fonts
font-kit enumerates plus any bundled fonts the host registers; in
non-desktop runtimes that don't expose enumeration, it returns an
empty list with an explanatory note rather than throwing.

The optional `family` filter mirrors list_fonts for a substring
search, so agents can do `list_available_fonts({family: "mono"})` to
narrow before set_font.

Wired through:
- packages/core/src/figma-api/index.ts: adds optional
  listAvailableFontFamilies hook on FigmaAPI (same pattern as
  exportImage). Optional so non-desktop hosts aren't forced to
  implement it.
- packages/core/src/tools/read.ts: defines the tool.
- packages/core/src/tools/registry.ts: registers it in CORE_TOOLS so
  the MCP server advertises it.
- src/automation/figma-factory.ts: provides the desktop
  implementation by delegating to engine/fonts.ts#listFamilies which
  already wraps the Tauri list_system_fonts sidecar.

* refactor(mcp): reshape to listAvailableFontsAsync matching Figma API

Per review feedback on #210: FigmaAPI mirrors the Figma Plugin API, and
Figma already exposes figma.listAvailableFontsAsync(): Promise<Font[]>
where Font = { fontName: { family, style } }. Replacing the custom
listAvailableFontFamilies hook with the Figma-shaped method means eval'd
plugin code and any future plugin-compat layer get font enumeration for
free. Follows the same pattern as loadFontAsync on FigmaAPI.

- packages/core/src/figma-api/proxy.ts: export FigmaFont type
  ({ fontName: FigmaFontName }) alongside FigmaFontName.
- packages/core/src/figma-api/index.ts: drop optional
  listAvailableFontFamilies; add listAvailableFontsAsync() as a real
  method (non-optional) with a safe [] default, mirroring loadFontAsync.
- packages/core/src/tools/read.ts: list_available_fonts execute() now
  consumes Font[] and dedupes families via a Set. Drops the
  host-capability fallback note — the new method always returns an
  array, so a non-desktop host just yields {count: 0, fonts: []}.
- src/engine/fonts.ts: add listFonts() returning TauriFontFamily[]
  ({family, styles[]}) so the factory can emit one Font per (family,
  style) pair.
- src/automation/figma-factory.ts: override listAvailableFontsAsync,
  flattening {family, styles[]}[] to Font[].
- oxlint.json: add listFonts to the engine/fonts allowlist.

Tool public shape unchanged (still returns {count, fonts: string[]})
so agents calling list_available_fonts see no change.

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

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 09:56:33 +03:00