openpencil/packages/docs/overview/features.md
Danila Poyarkov 6a3960a5d4
feat(code): link the Code tab to canvas layers and sync both ways (#805)
* feat(code): link code to canvas layers and underline design issues

Code in the Code tab and layers on the canvas were unrelated: finding the
element behind a layer, or the layer behind an element, meant reading names.

Generated Design JSX and Tailwind JSX report the layer behind each element
in the order elements open, and edited Design JSX keeps the source line of
every element through the sandbox and renderer, so hovering an element
highlights its layer, Cmd/Ctrl-click brings it into view without changing
the selection the code shows, and errors and warnings from the design check
are underlined on the property that causes them.

* feat(code): explain the Code tab when nothing is selected

With no selection the editor showed a starter frame that read like a real
layer. The tab now says it shows the selected layers' code and offers Write
JSX, which opens the editor focused on the starter template.

* refactor(code): group code-to-layer linking into its own domain

Layer link types, issue mapping, and the hover and reveal behavior move
from the Code panel and a component file into src/app/code/layers, with
useCodeLayers as the panel's entry point, so app code no longer imports
types from components.

* fix(code): underline off-scale gaps after the spacing rule renamed its property

* feat(code): mark the layer of the element around the cursor

Hover highlighting and ⌘-click reveal replaced by one model: the element
around the cursor marks its opening and closing tag names and outlines its
layer on the canvas while the editor has focus. ⌘-click also collided
with CodeMirror's add-a-cursor gesture. Read-only Tailwind JSX now takes a
cursor so it links the same way.

Leaving the editor now ends a live Design JSX edit as one undo step.
Before, canvas edits made after typing never reached the code until the
tab was reopened, and their undo entries landed before the edit's.

* feat(code): sync the Code tab and the canvas both ways by patching

Canvas edits now patch the Design JSX a person wrote instead of waiting
for them to leave the editor: each linked element remembers the layer as
Design JSX last wrote it, and a canvas change rewrites only the attributes,
text and child elements that differ from that base, as CodeMirror changes
that keep the cursor, comments, formatting and history. Attributes written
as expressions are never overwritten; the code marks them when the canvas
now differs. Untouched code is regenerated with a minimal text change.

Code edits update layers in place: the new render is reconciled into the
existing layers (reconcileRenderedLayers), which keep their ids, so links,
selection and canvas edits survive typing. Each edit is one coalesced undo
step, replacing the restore-and-rerender preview and the commit on blur.

* feat(code): patch reordered layers and aliased properties in edited code

Reordering layers on the canvas now moves their elements in code a person
wrote: each child element and the blank lines and comments above it form a
block kept as written, and the children are written again in the new
order, staying linked. Children that cannot move safely, such as a loop
between them, keep their order and are marked.

Properties accepted under several names now come from one alias table in
the Design JSX schema, which the renderer resolves through and the patcher
and issue underlines use, so a canvas change to `w` patches `width` where
the person wrote that, instead of adding a second attribute.

* feat(code): keep the cursor in moved code and patch values written in style

A reorder rewrites the children span in one change, which collapsed a
cursor or out-of-sync marker inside a moved element to the span's edge.
The patch now carries where each block moved and places selections and
markers inside it at their new position.

Properties the renderer also reads from style={{ … }} come from a table in
the Design JSX schema instead of a hand-written list, keeping the rule
that an attribute under any of its names wins. The patcher uses it to
update a value written in style where it is, as a number or a px string
as written; values the renderer cannot read, such as '50%', are marked.

The layer patcher is split by concern: syntax helpers, attribute and
style patches, child patches, out-of-sync state and transaction assembly.

* feat(code): show the code's layer on the canvas as a tinted box

The layer of the element around the cursor used the canvas hover slot, so
moving the pointer over the canvas replaced it and the two read the same.
It now has its own shared editor state, codeFocusNodeId, drawn as the hover
outline over a light tint in every pane: hover stays an outline and the
selection keeps its handles, without borrowing the dashed outlines that
already mean component sets, drag parents and ghosts.

* fix(code): write added and removed layers when a reorder cannot move the code

When children could not be moved, such as two written on one line, the
patch marked the order and returned before adding or removing elements,
so a layer created in the same change never reached the code. It now
marks the order and still writes additions and removals.

* refactor(design-jsx): format the rebased layer description and stroke aliases

* feat(code): mount the layer-linked code editor through useCodeMirror

Master moved the code editor onto the shared useCodeMirror composable.
Its layer links, issue underlines, canvas patches, minimal text updates,
autofocus and read-only cursor now sit on that composable instead of a
hand-mounted view.
2026-10-04 10:08:40 +00:00

6.4 KiB
Raw Blame History

Features

Figma .fig Files

Open and save native Figma files directly. The import/export pipeline uses the same Kiwi binary codec as Figma — 194 schema definitions, ~390 fields per node. Save with ⌘S, Save As with ⇧⌘S.

Copy & paste with Figma — select nodes in Figma, ⌘C, switch to OpenPencil, ⌘V. Fills, strokes, auto-layout, text, effects, corner radii, and vector networks are preserved. Works both ways.

Drawing & Editing

  • Shapes — Rectangle (R), Ellipse (O), Line (L), Polygon, Star
  • Pen tool — vector networks (not simple paths), bezier curves with tangent handles
  • Text — canvas-native editing with IME support, double-click to enter edit mode
  • Rich text — per-character bold (⌘B), italic (⌘I), underline (⌘U), strikethrough
  • Auto-layout — flexbox and CSS Grid via Yoga WASM: direction, gap, padding, justify, align, child sizing, grid tracks. ⇧A to toggle
  • Components — create (⌥⌘K), component sets (⇧⌘K), instances with override support, live sync
  • Variables — design tokens with collections, modes (Light/Dark), color/float/string/boolean types, variable binding
  • Sections — organizational containers with auto-adopting children and title pills

Properties Panel

Context-sensitive Design | Code | AI | Lint tabs:

  • Appearance — opacity, corner radius (uniform or per-corner), visibility
  • Fill — solid, gradient (linear/radial/angular/diamond), image
  • Stroke — color, weight, align (inside/center/outside), per-side weights, cap, join, dash
  • Effects — drop shadow, inner shadow, layer blur, background blur, foreground blur
  • Typography — font picker with virtual scroll and search, weight, size, alignment, style buttons
  • Layout — auto-layout controls when enabled
  • Export — scale, format (PNG/JPG/WEBP/SVG), live preview
  • Code — Design JSX and Tailwind JSX for the selection, with live two-way Design JSX editing that patches your code as layers change; the element around the cursor outlines its layer on the canvas, and design issues are underlined on the property that causes them
  • Lint — live design lint for the page or selection: low contrast, small touch targets, unbound colors, off-scale spacing, with issue markers on the canvas and one-click variable binding (Checking Designs)

Rendering

Skia (CanvasKit WASM) — the same rendering engine as Figma:

  • Gradient fills (linear, radial, angular, diamond)
  • Image fills with scale modes
  • Effects with per-node caching
  • Arc data (partial ellipses, donuts)
  • Viewport culling and paint reuse
  • Snap guides with rotation-aware alignment
  • Canvas rulers with selection badges
  • Hover highlight that follows actual geometry

Undo/Redo

Every operation is undoable — creation, deletion, moves, resizes, property changes, reparenting, layout changes, variable operations. Uses an inverse-command pattern. ⌘Z / ⇧⌘Z.

Multi-Page Documents

Add, delete, rename pages. Each page has independent viewport state. Double-click to rename inline.

Multi-File Tabs

Open multiple documents in tabs. ⌘T new tab, ⌘W close, ⌘O open file.

Export

  • Image — PNG, JPG, WEBP at configurable scale (0.5×–4×). Via panel, context menu, or ⇧⌘E
  • SVG — shapes, text with style runs, gradients, effects, blend modes
  • Tailwind JSX — HTML with Tailwind v4 utility classes, ready for React or Vue
  • Copy as — text, SVG, PNG (⇧⌘C), or JSX via context menu

CLI: openpencil export design.fig -f jsx --style tailwind

AI Chat

Press ⌘J to open the AI assistant. 90+ tools that can create shapes, set styles, manage layout, work with components and variables, run boolean operations, analyze design tokens, and export assets. Connect Anthropic, OpenAI, Google AI, OpenRouter, or any compatible endpoint.

Tool calls display as collapsible timeline entries. Visual verification — the assistant renders its work and checks it against your request. Full undo support for all AI mutations.

See AI Chat for setup and provider details.

MCP Server

Connect Claude Code, Cursor, Windsurf, or any MCP client to read and write .fig files headlessly. 90+ tools. Two transports: stdio and HTTP.

npm install -g @open-pencil/mcp
{
  "mcpServers": {
    "open-pencil": {
      "command": "openpencil-mcp"
    }
  }
}

See MCP Tools reference for the full tool list.

CLI

Inspect, export, and analyze .fig files from the terminal:

openpencil tree design.fig          # Node tree
openpencil find design.fig --type TEXT  # Search
openpencil export design.fig -f png     # Render
openpencil analyze colors design.fig    # Color audit
openpencil analyze clusters design.fig  # Repeated patterns
openpencil eval design.fig -c "..."     # Figma Plugin API

When the desktop app is running, omit the file to control the live editor via RPC:

openpencil tree                     # Live document
openpencil export -f png            # Screenshot canvas

All commands support --json. Install: npm install -g @open-pencil/cli (or bun add -g @open-pencil/cli).

Real-Time Collaboration

P2P via WebRTC — no server required. Share a link and edit together.

  • Live cursors with colored arrows and name pills
  • Presence avatars
  • Follow mode — click a peer to follow their viewport
  • Local persistence via IndexedDB
  • Secure room IDs via crypto.getRandomValues()

Desktop & Web

Desktop — Tauri v2, ~7 MB. macOS (signed & notarized), Windows, Linux. Native menus, offline, autosave.

Web — runs at app.openpencil.dev, installable as a PWA on mobile with touch-optimized UI.

Homebrew:

brew install --cask openpencil

Google Fonts Fallback

When a font isn't available locally, OpenPencil fetches it from Google Fonts automatically. No manual installation needed when opening .fig files with unfamiliar fonts.