Commit graph

399 commits

Author SHA1 Message Date
Danila Poyarkov c3f5189f8f style: tighten import grouping
- Configure oxfmt custom import groups for workspace, app, package, and test aliases
- Keep type imports grouped with their matching source category instead of one global tail group
- Expand the format script to cover formatter config, Vite files, and scripts
2026-05-06 02:22:08 +03:00
Danila Poyarkov ddb1db8175 style: format imports 2026-05-06 02:16:37 +03:00
Danila Poyarkov 51eae14e4b chore(tests): remove targeted non-null assertions
- Add shared test helpers for required nodes and child ids
- Clean non-null assertions from noisy render, nudge, text undo, and fig roundtrip tests
- Enforce the non-null assertion ban for the cleaned test files
- Remove stale eslint disables around empty functions and broad mock transport typing
2026-05-06 01:14:50 +03:00
Danila Poyarkov 4d3e16c0a2 chore(lint): ban broad function types
- Add structural lint rules for broad Function usage and globalThis deletion outside tests
- Type design JSX component factories with an explicit callable signature
- Replace remaining broad Kiwi serialization test records with unknown values
2026-05-06 00:48:57 +03:00
Danila Poyarkov fae190a673 chore(lint): remove unsafe test casts
- Enforce explicit-any and TypeScript suppression bans in tests
- Remove remaining broad any casts from engine and e2e coverage
- Split markdown ambient declarations from typed browser globals
2026-05-06 00:42:45 +03:00
Danila Poyarkov aa07e833cb chore(lint): ban broad double casts project-wide
- Extend the as-unknown-as structural rule beyond app and Vue code
- Remove existing broad double casts from core and tests
- Replace the vector base64 helper and XPath facade casts with precise code paths
2026-05-06 00:29:23 +03:00
Danila Poyarkov 7f3eb532d8 fix(core): render gradient text fills
- Clip gradient paints through the shaped paragraph mask instead of reading only the paint color
- Cover the paragraph mask path and a headless red-to-blue text render

Fixes #246
2026-05-06 00:22:17 +03:00
Danila Poyarkov 768b527155 feat(core): add font fallback manifest 2026-05-05 21:35:12 +03:00
Danila Poyarkov 25ea361fd7
feat(app): cache downloaded fonts
- Add a downloaded font cache hook to FontManager
- Store Tauri font downloads under AppLocalData with manifest validation
- Prefer cached downloads before system font lookup on desktop
- Skip opt-in heavy .fig parsing tests in PR CI
2026-05-05 21:14:38 +03:00
Danila Poyarkov 9c11c5b075
refactor(core): centralize font loading
- Replace loose font service functions with a FontManager instance
- Route renderer provider lifecycle and font caches through the manager
- Request browser local font access from the font picker interaction
2026-05-05 18:59:54 +03:00
Tem-man 1e2df31636
fix(core): improve CJK font fallback loading
- Allow CJK fallback loading to use local variable system fonts
- Add Windows CJK fallback families
- Harden CanvasKit WASM asset resolution and serving
2026-05-05 18:39:39 +03:00
Joseph Cumines c69e3884cf
fix(core): critical codec and canvas fixes
- Deduplicate plugin data and relaunch data during .fig parsing/export
- Unify shared plugin data into the pluginData storage path
- Refactor shadow rendering and harden CanvasKit font provider teardown
- Expand engine and renderer coverage
2026-05-05 14:58:02 +03:00
Danila Poyarkov 93160b1bfb feat(ai): add DeepSeek as first-class provider
Use @ai-sdk/deepseek instead of openai-compatible, which properly
handles reasoning_content in conversation history. DeepSeek V4
requires reasoning_content on every assistant turn — the dedicated
provider backfills it automatically.

Adds DeepSeek V3 and R1 models to the provider list.
2026-05-04 11:48:45 +03:00
Danila Poyarkov ac15fb143b feat(io): add PDF export
Vector PDF output via jsPDF + svg2pdf.js (lazy-loaded, 124KB gzipped).
Reuses existing SVG export pipeline — text stays selectable, paths
stay sharp at any zoom.

- packages/core/src/io/formats/pdf/ — SVG→PDF conversion module
- export_pdf tool for MCP/AI
- PDF format in IO registry and app export panel
- CLI: bun open-pencil export file.fig --format pdf
2026-05-04 00:18:54 +03:00
Danila Poyarkov a2050a9860 feat(tools): add import_svg tool
Parse raw SVG markup and create vector nodes on the canvas.
Supports path, circle, ellipse, rect, line, polygon, polyline
with fill, stroke, stroke-width, viewBox sizing, and currentColor.
2026-05-03 23:59:21 +03:00
Danila Poyarkov 36f2990e78 refactor(vector): address PR #238 review issues
- Extract centerline algorithm to packages/core/src/vector/centerline.ts
  to stay under max-lines (index.ts 441 lines, centerline.ts 289 lines)
- Fix PathEffect.MakeDash leak: store reference and .delete() after use
- Add aria-label to dash toggle button with i18n (strokeDash)
- Read dash/gap values directly from dashPattern array in template
  instead of calling dashState() 4 times
- Add unit tests for fitCircleArc and isClosedThinCrescent
  (collinear, non-circular, annular wedge, rectangle, hexagon, open path)
2026-05-03 22:49:12 +03:00
TKman 6651d88b87 fix(vector): render dashPattern strokes correctly on closed crescents
Vector nodes with stroke.dashPattern were rendering as solid lines, and
even when the dash was applied through brute outline-stroke conversion,
closed crescent shapes (e.g. annular wedges) showed two parallel dashed
arcs instead of a single arc along the centerline.

Root cause:

- drawVectorPathStrokes converted stroke to a fill outline before drawing,
  leaving no place for PathEffect.MakeDash to apply.
- A closed crescent is a single closed path traced around both the outer
  and inner arcs, so dashing the path produces two visible arcs.

Fix:

- packages/core/src/canvas/scene.ts: in drawVectorPathStrokes, when the
  stroke has a dashPattern, skip the outline conversion and draw with
  strokePaint + PathEffect.MakeDash directly. In renderShapeUncached,
  dashed VECTOR nodes with a vectorNetwork now route through a new
  centerline path instead of the precomputed strokeGeometry.
- packages/core/src/vector/index.ts: new vectorNetworkToCenterlinePath.
  For closed thin crescents (cycle of even length where pairwise opposite
  vertex distance is small relative to perimeter and consistent), detect
  the two cap segments via vertex direction-change angles, split the
  cycle into outer/inner subchains, pair vertices by angle, and emit a
  smooth Path.addArc when the midpoints fit a circle (fitCircleArc with
  3-point construction + radius tolerance), falling back to a midpoint
  polyline otherwise. Open paths use the existing chain walk.

JSX prop wiring so users can author dashed Vectors:

- packages/core/src/design-jsx/tree.ts: add strokeDash?: number[] | boolean.
- packages/core/src/design-jsx/renderer.ts: applyStrokeOverrides reads
  strokeDash and writes Stroke.dashPattern; true expands to [w*2, w*2].
- packages/core/src/io/formats/jsx/export.ts: solidStroke serializes
  dashPattern back to strokeDash on JSX export.

Editor UI:

- src/components/properties/StrokeSection.vue: dash toggle button plus
  ScrubInputs for dash and gap length, writing strokes[0].dashPattern.

bun run check passes. Pre-existing test failures (drop shadow / auto
layout) are unrelated to this change and reproduce on a clean
upstream/master.
2026-05-03 22:44:42 +03:00
Danila Poyarkov b85805e9c7 chore: format sources with oxfmt 2026-05-03 21:03:40 +03:00
Danila Poyarkov 7199774177 feat(app): bind size fields to variables 2026-05-01 17:20:45 +03:00
Danila Poyarkov 17e2aa6cb5 perf(canvas): avoid scene recording during live edits 2026-04-30 18:29:51 +03:00
Danila Poyarkov 9bc9b5d5b0 fix(canvas): theme ruler colors 2026-04-30 17:50:20 +03:00
Danila Poyarkov e86dcb8225 fix(canvas): register default font provider 2026-04-30 15:24:54 +03:00
Danila Poyarkov 6545f20c53
Refactor architecture boundaries across core, app, and packages (#234)
* refactor(core): decompose editor factory and action modules

Split the monolithic editor factory and large action modules into focused
domain helpers:

- create.ts assembles context through bridge modules (clipboard,
  components, structure, undo) and delegates to graph-reads, graph-events,
  layout-runner, component-sync, and state factory
- structure.ts delegates to group, container-wrap, auto-layout-wrap,
  reorder, and state-toggle helpers
- selection.ts delegates to hit-test, overlays, container navigation,
  and read helpers
- clipboard.ts delegates to subtree-history, images, export, copy,
  fonts, and placement helpers
- shapes.ts delegates to pen actions and section-adopt
- components.ts delegates to focus and instances helpers
- alignment.ts delegates to flip-rotate helper
- text.ts uses explicit TextEditSession for snapshot comparison

New focused modules: nudge, variable-bindings, layout-mode,
page-viewports, tool-registry, color-space

Undo: history/position and history/snapshot helpers, hardened
batch/rollback with nested batch support and configurable limit

* refactor(core): split tool definitions by domain

Split the monolithic tool registry into domain-specific modules:

- read/ — selection, find, pages, fonts, components, nodes, query, jsx
- create/ — basic shapes, components, vector, JSX render
- modify/ — paint, effects, geometry, layout, state, text, update
- structure/ — basic, arrange, batch, hierarchy, replace, tree
- variables/ — bindings, collections, read, values
- vector/ — boolean, path, export, viewport
- analyze/ — colors, typography, spacing, clusters, diff, eval
- describe/ — summaries, tree, roles, layout-issues
- stock-photo/ — providers, requests, apply
- codegen/ — component-map, tokens

Split registry into core/extended tiers; refine schema and AI adapter

* refactor(core): restructure kiwi codec and instance overrides

Reorganize the Kiwi .fig codec into domain subdirectories:

- binary/ — codec, schema, protocol
- fig/ — file, import, parse (core, worker, transfer)
- node-change/ — convert, export-node, serialize, plugin-data
- instance-overrides/ — constraints, dsd, populate, props, resolve,
  symbol-overrides, symbol-props, sync, types

Vendored kiwi-schema/ left isolated

* refactor(core): split profiler, icons, IO, and add subpath exports

Profiler: speedscope-export, capture-session, hud-controller
Icons: api, svg, types, render, create-icons tool
IO: format registry and subpath exports
Canvas/color/text/vector: targeted cleanup

Add deliberate subpath exports: random, xpath, vector, color, canvas,
scene-graph, kiwi, design-jsx, io, tools, editor, layout, canvaskit,
profiler, text, lint, rpc, figma-api, constants

* refactor(vue): decompose canvas input, surface lifecycle, and controls

Canvas surface: gl-surface, kit-loader, render-loop, resize-observer

Canvas input handlers:
- move: drop-target, move-snap, duplicate-drag
- select: select-move, select-hover, select-hit
- resize: resize-rect, resize-vector, resize-start
- transform: rotation, marquee, pan, text-selection
- text-edit: navigation, clipboard, textarea lifecycle
- Shared: click-count, space-key, pan, pan-zoom, draw, raf-scheduler

Editor composition:
- commands split: actions, context, metadata, edit, selection, view
- menu-model split: command-groups, builders, types
- Gradient stop composable reuse in primitive root

Controls: fill, layout, typography, appearance, effects, stroke,
okhcl, prop-scrub, node-props, undo-batch, color-variable-binding
Variables/i18n/document/export helpers

Organize canvas, primitives, controls, editor, and variables into
cohesive module directories with package-local import aliases

Expose MenuActionNode/MenuSeparatorNode from public API

* refactor(app): split document IO, editor session, and automation bridge

Document IO: source-state, naming, writer, reload-source, reload-state,
imported-document, watch-targets, save-targets

Editor session: create, modules, types, accessors, computed, refs
Editor canvas: loader-overlay, collaboration-awareness,
context-selection, menu-actions, menu-model

Automation bridge: eval, tools, exports, files, selection, RPC fallback

AI/ACP: transport, map-update, permission, debug, chat effects/storage
Collab: awareness, graph-bindings, yjs-sync, follow, session, types
Shell keyboard: actions, bindings, clipboard, focus, nudging,
raw-events, registry, reserved, shortcuts, space-tool
Shell menu: app-menu, document-name, entry, files

Demo: colors, effects, helpers, section builders (components,
app-preview, effects, standalone, variables) — document.ts reduced
from 981 to 32 lines as pure orchestrator

Move app modules under src/app/ with organized domain structure:
editor, document, ai, collab, shell, automation, demo, tabs

* refactor(app): decompose UI components with provide/inject context

Split monolithic components using Reka UI-inspired namespace folders
with scoped provide/inject context — no prop drilling:

- CollabPanel/ — context, avatars, share, connected, join
- ColorPickerPanel/ — context, area, format, field groups, sliders
- MobileHud/ — context, action toast, tool badge, file menu, presence
- ProviderSettings/ — context, API key/type, endpoint, tokens, photos
- Toolbar/ — actions, types, desktop, mobile, tool button, flyout
- LayoutSection/ — types, auto-layout, flex, grid, padding, size, clip

Properties helpers: fill-okhcl adapter, fill-label, color-style-row
Menu: entry helpers, document-name rename, stale type removal

* refactor(mcp): split server into focused modules

- browser-rpc — WebSocket client management
- mcp-sessions — session lifecycle
- tool-output — response formatting
- tool-schema — Zod schema generation from ToolDefs
- jsx-preprocess — JSX source transformation
- result — result helpers
- tool-registration — MCP tool wiring
- auth — API key validation
- http-options — CORS/request handling
- stdio-bridge — stdio transport adapter

* refactor(cli): split analyze subcommands and shared helpers

- Analyze subcommands: clusters, colors, spacing, typography
- RPC data loading helper
- Migrate imports to targeted core subpath exports

* refactor(docs): split VitePress config and shared table component

Config helpers: sdk-sidebar, seo, labels, sidebars, locale-theme,
root-theme, locales

Shared SdkDataTable component replaces duplicated table markup in
SdkPropsTable, SdkEventsTable, and SdkSlotsTable

Update contributing and testing docs

* refactor(tauri): decompose desktop entrypoint

Split lib.rs into focused service modules:

- fig_container.rs — .fig archive/compression commands
- fonts.rs — font cache and system font enumeration
- menu.rs — native menu construction
- menu_events.rs — menu event dispatch and devtools toggle
- window.rs — main window show/focus lifecycle

* test: share domain test factories and migrate fixtures

New shared helpers:
- tests/helpers/scene.ts — makeSceneGraph factory
- tests/helpers/vector-network.ts — vertex/segment/network builders
- tests/helpers/fig-traversal.ts — all-node collection, type counts
- tests/helpers/undo.ts — undo test utilities
- tests/helpers/editor-history.ts — editor history test helpers

Migrate render, vector, fig-roundtrip, and undo tests to use shared
factories instead of inline fixture construction

* build: add structural lint rules, split vite config, update docs

Structural lint (oxlint.structure.json + lint/plugin.js):
- 20+ custom rules enforcing package boundaries, lifecycle patterns,
  naming conventions, and import discipline

Vite config split: raw-markdown, canvaskit-assets, pwa, server,
aliases, automation plugins

Remove legacy shims and utils superseded by SDK/core modules
Update AGENTS.md, CONTRIBUTING.md, eval-command docs, tsconfig

* fix(vue): normalize canvas directory casing and remove duplicate export

- Rename Canvas/ to canvas/ in git index to match #vue/canvas/* imports
  (PascalCase was correct for component primitives but canvas/ is a
  non-component domain directory)
- Remove duplicate ./random subpath export in core package.json

* fix: add #vue and #core Vite resolve aliases for dev server

* refactor(core): reduce remaining large modules

Split the remaining large core hotspots into cohesive domain modules while preserving public facades and behavior.

- Extract scene graph types, variables, node defaults, and vector-network helpers
- Decompose canvas renderer orchestration, state, paints, colors, lifecycle, labels, and delegated domain methods into renderer/ and labels/ subfolders
- Split Kiwi node-change, binary variable binding, layout, RPC, vector, JSX export, clipboard, design JSX, and Figma proxy helpers
- Replace collision-driven *Fn import aliases with namespace imports and enforce the pattern in lint

Validation:
- bun run check
- bun --filter @open-pencil/vue build
- bun run test:dupes

* fix(app): forward color input attrs

* fix(app): cover section drawing errors

* fix(editor): undo option-drag duplicates

* docs: document domain subfolder convention

* fix(app): handle undo redo on keydown

* refactor(app): dispatch shortcuts from keydown

* refactor: group prefixed domain modules

* refactor(app): use tinykeys for shortcuts

* refactor(core): group symbol override modules

* refactor(core): group fig kiwi container helper

* refactor(canvas): split overlay rendering modules

* refactor(vue): remove unused internal barrels

* fix(app): lay out demo components before instancing

* fix(app): restore demo badge spacing

* perf(canvas): split scene and overlay rendering

* refactor(vue): wrap wheel gesture lifecycle

* fix(canvas): wait for fonts before hiding loader

* docs: update unreleased changelog
2026-04-30 15:14:19 +03:00
Danila Poyarkov 60d765cb7c fix(canvas): shadow stroked shapes as strokes 2026-04-25 22:49:38 +03:00
Danila Poyarkov a42da8ab16 fix(kiwi): preserve input badge avatar swaps 2026-04-25 22:39:21 +03:00
Danila Poyarkov 6c6671bb7a fix(kiwi): resolve badge avatar overrides 2026-04-25 21:45:38 +03:00
Danila Poyarkov 4fbca976fd perf(kiwi): lazily populate opened fig pages 2026-04-25 21:24:55 +03:00
Danila Poyarkov 04b425f64c perf(kiwi): cache instance override resolution 2026-04-25 21:04:01 +03:00
Danila Poyarkov cfefc1fb4e fix(kiwi): preserve derived instance layout 2026-04-25 20:30:52 +03:00
Danila Poyarkov 63d3f2e0cb fix(kiwi): improve figma export fidelity 2026-04-25 15:57:15 +03:00
Danila Poyarkov 53a623e466 fix(canvas): clip vector inside stroke geometry 2026-04-25 13:36:39 +03:00
Danila Poyarkov 5f33f26756 fix(canvas): clip inside stroke geometry 2026-04-25 13:32:45 +03:00
Danila Poyarkov 3bccb69759 fix(canvas): use fig stroke geometry for shapes 2026-04-25 13:20:03 +03:00
Danila Poyarkov 3e52f762ff fix(kiwi): preserve flipped vector bounds 2026-04-25 13:14:20 +03:00
Danila Poyarkov 489f273e33 fix(kiwi): scale nested instance contents 2026-04-25 13:08:09 +03:00
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 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 ba414e1af7 Release v0.11.8 2026-04-23 16:15:37 +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 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 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 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 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 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