AI-native design editor. Open-source Figma alternative.
Sync specs & docs: canvas-native text editing, font-kit, variables dialog
Anton A S824193ab7a29
diff --git a/docs/development/roadmap.md b/docs/development/roadmap.mdindex db25bfa71..d242aeafa 100644--- a/docs/development/roadmap.md+++ b/docs/development/roadmap.md@@ -77,8 +77,14 @@ Components, instances, overrides, variables, collections, modes, image export.- Resizable left/right panels via reka-ui Splitter (persistent layout)- @/ import alias, shared types module (src/types.ts, src/global.d.ts)- Codebase lint-clean: 0 oxlint warnings, 0 tsgo type errors-- Variables: COLOR type with collections, modes, bindings, VariablesPanel, FillSection variable picker, .fig import+- Variables: COLOR type with collections, modes, bindings, FillSection variable picker, .fig import+- Variables dialog: TanStack Table with resizable columns, mode columns, collection tabs with rename, search, demo collections (Primitives/Semantic/Spacing), undo/redo for all variable operations- Image export: PNG/JPG/WEBP with ExportSection (scale, format, live preview), ⇧⌘E shortcut, context menu+- Canvas-native text editing: TextEditor class in core, phantom textarea, cursor/selection/word boundaries on canvas, caret blinking, selection highlights+- System font enumeration via font-kit Rust crate, OnceLock cache, preload on startup+- Font picker: virtual scroll (reka-ui ListboxVirtualizer), search filter, CSS font preview+- ColorInput component extraction, ColorPicker alpha slider checkerboard fix+- App identity: pencil icon, Cargo crate open_pencil, macOS Dock "OpenPencil"- Splash loader during WASM initialization**Remaining (deferred to Phase 6):**diff --git a/docs/guide/features.md b/docs/guide/features.mdindex d94525c51..632b60d8a 100644--- a/docs/guide/features.md+++ b/docs/guide/features.md@@ -31,11 +31,15 @@ Shift+A toggles auto-layout on a frame or wraps selected nodes.## Inline Text Editing-Text nodes use CanvasKit's Paragraph API for rendering with proper text shaping and line breaking. Double-click to edit inline with a textarea overlay. Supports font families, weights, sizes, and line height. System fonts are available via the Local Font Access API.+Canvas-native text editing — no DOM textarea overlay on screen. A `TextEditor` class in `@open-pencil/core` handles cursor positioning, text selection, word boundary detection, and line navigation using the CanvasKit Paragraph API (`getGlyphPositionAtCoordinate`, `getRectsForRange`, `getLineMetrics`). A hidden phantom textarea captures keyboard input, IME composition, and clipboard events.++Double-click a text node to enter edit mode. The canvas renders a blinking caret, translucent blue selection rectangles, and a blue outline around the node. Click and drag to select text, double-click a word to select it. Keyboard navigation with modifier support: <kbd>⌥</kbd><kbd>←</kbd>/<kbd>→</kbd> for word movement, <kbd>⌘</kbd><kbd>←</kbd>/<kbd>→</kbd> for line start/end, <kbd>⌥</kbd><kbd>⌫</kbd> for word delete, <kbd>⌘</kbd><kbd>⌫</kbd> for line delete. Shift extends selection. <kbd>Esc</kbd> or clicking outside commits the edit.++**Font picker** with virtual scroll (reka-ui ListboxVirtualizer), search filter, and CSS font preview — each font name renders in its own typeface. In Tauri, system fonts are enumerated via Rust `font-kit` crate (`list_system_fonts`/`load_system_font` commands) with OnceLock caching for instant picker access. In browser, the Local Font Access API is used when available.## Undo/Redo-Every operation is undoable. The system uses an inverse-command pattern — before applying any change, it snapshots affected fields. The snapshot becomes the inverse. ⌘Z undoes, ⇧⌘Z redoes.+Every operation is undoable — node creation/deletion, moves, resizes, property changes, reparenting, layout changes, and all variable operations (create/delete/rename variables, create/rename collections, color and value changes). The system uses an inverse-command pattern — before applying any change, it snapshots affected fields. The snapshot becomes the inverse. <kbd>⌘</kbd><kbd>Z</kbd> undoes, <kbd>⇧</kbd><kbd>⌘</kbd><kbd>Z</kbd> redoes.## Snap Guides@@ -63,7 +67,7 @@ Context-sensitive panel with sections:- **Fill** — solid/gradient/image type picker, gradient stop editor, hex input, opacity- **Stroke** — color, weight, opacity, cap, join, dash pattern- **Effects** — add/remove effects, type picker (drop shadow, inner shadow, layer blur, background blur, foreground blur), inline expanded controls (offset, blur, spread, color for shadows; blur radius for blurs), per-effect visibility toggle-- **Typography** — font family, weight, size, alignment+- **Typography** — font family (FontPicker with virtual scroll and search), weight, size, alignment- **Layout** — auto-layout controls when enabled- **Position** — alignment buttons, rotation, flip- **Export** — scale, format (PNG/JPG/WEBP), live preview, multi-export@@ -110,7 +114,11 @@ Components and instances display always-visible purple labels with a diamond ico## Variables-Design tokens as variables with collections and modes. Currently supports COLOR type with full UI — create color variables, organize them in collections (e.g., "Brand", "Semantic"), define modes (e.g., Light/Dark), and switch the active mode. Bind variables to fill colors via the variable picker in the Fill section — bound fills display a purple badge with the variable name and a detach button. Variables support alias chains (one variable references another) with cycle detection. Imported from .fig files. FLOAT, STRING, and BOOLEAN types are defined but don't have editing UI yet.+Design tokens as variables with collections and modes. Open the variables dialog from the Variables section in page properties (settings icon). The dialog uses TanStack Table (`@tanstack/vue-table`) with resizable columns — Name | Mode 1 | Mode 2 | ... — matching Figma's table layout. Collection tabs with double-click to rename, search bar, and "+ Create variable" button. Color variables show inline ColorInput with picker.++Supports COLOR type with full UI, FLOAT/STRING/BOOLEAN types defined. Organize variables in collections (e.g., "Primitives", "Semantic"), define modes (e.g., Light/Dark), switch active mode. Bind variables to fill colors via the variable picker in Fill — bound fills show a purple badge with the variable name and a detach button. Alias chains (one variable references another) with cycle detection. All variable operations are undoable: create/delete variable, create collection, rename, color change.++The demo document includes three collections: Primitives (9 colors with Light/Dark modes), Semantic (aliases to Primitives), and Spacing (8 number tokens with Default/Compact modes). Variables are bound to demo nodes for live preview.## Image Exportdiff --git a/docs/guide/figma-comparison.md b/docs/guide/figma-comparison.mdindex 5cf1afb7f..6da6a538f 100644--- a/docs/guide/figma-comparison.md+++ b/docs/guide/figma-comparison.md@@ -6,7 +6,7 @@ Feature-by-feature comparison of Figma Design capabilities with Open Pencil's cu✅ Supported — feature works end-to-end · 🟡 Partial — core behavior exists, some sub-features missing · 🔲 Not yet implemented:::-**Coverage:** 79 of 150 Figma feature items addressed — 64 ✅ fully supported, 15 🟡 partial, 71 🔲 not yet. Last updated: 2026-03-01.+**Coverage:** 79 of 150 Figma feature items addressed — 64 ✅ fully supported, 15 🟡 partial, 71 🔲 not yet. Last updated: 2026-03-01 (notes updated for text editing, fonts, variables).## Interface & Navigation@@ -78,10 +78,10 @@ Feature-by-feature comparison of Figma Design capabilities with Open Pencil's cu| Feature | Status | Notes ||---------|--------|-------|-| Text tool & inline editing | ✅ | T to create, double-click to edit, textarea overlay |+| Text tool & inline editing | ✅ | T to create, double-click to edit, canvas-native with phantom textarea, cursor/selection/word select, drag to select || Text rendering (Paragraph API) | ✅ | CanvasKit Paragraph for shaping, line-breaking, metrics |-| Font loading (system fonts) | ✅ | Inter default + Local Font Access API for system fonts |-| Font family & weight | ✅ | Font picker, weight selection in properties panel |+| Font loading (system fonts) | ✅ | Inter default, font-kit in Tauri with OnceLock cache + preloading, queryLocalFonts in browser |+| Font family & weight | ✅ | FontPicker with virtual scroll, search, CSS preview; weight selection in properties panel || Font size & line height | ✅ | Editable in typography section || Text alignment | 🟡 | Basic alignment; Figma has vertical alignment and auto-width/height modes || Text styles | 🔲 | Reusable named text style presets |@@ -159,7 +159,7 @@ Feature-by-feature comparison of Figma Design capabilities with Open Pencil's cu| Variants | 🔲 | Variant switching and property-based selection || Component properties | 🔲 | Boolean, text, instance swap properties || Override propagation | ✅ | Changes to main component propagate to all instances; overrides preserved |-| Variables (color, number, string, boolean) | 🟡 | COLOR fully implemented with UI, bindings, .fig import; FLOAT/STRING/BOOLEAN types defined but no editing UI |+| Variables (color, number, string, boolean) | 🟡 | COLOR full UI (dialog, TanStack Table, inline editing, undo/redo, demo collections); FLOAT/STRING/BOOLEAN defined but no editing UI || Variable collections & modes | 🟡 | Collections, modes, activeMode switching work; no variable-driven theming UI yet || Styles (color, text, effect, layout) | 🔲 | Reusable named style presets || Libraries (publish, share, update) | 🔲 | Shared component/style libraries |diff --git a/openspec/changes/archive/2026-03-01-sync-text-editing-fonts-variables-ui/.openspec.yaml b/openspec/changes/archive/2026-03-01-sync-text-editing-fonts-variables-ui/.openspec.yamlnew file mode 100644index 000000000..0b4defe0e--- /dev/null+++ b/openspec/changes/archive/2026-03-01-sync-text-editing-fonts-variables-ui/.openspec.yaml@@ -0,0 +1,2 @@+schema: spec-driven+created: 2026-03-01diff --git a/openspec/changes/archive/2026-03-01-sync-text-editing-fonts-variables-ui/design.md b/openspec/changes/archive/2026-03-01-sync-text-editing-fonts-variables-ui/design.mdnew file mode 100644index 000000000..8f9b8d580--- /dev/null+++ b/openspec/changes/archive/2026-03-01-sync-text-editing-fonts-variables-ui/design.md@@ -0,0 +1,22 @@+# Design: Sync text editing, system fonts, variables UI++## Approach+Documentation-only change. Update delta-specs for affected domains, then propagate to VitePress docs and comparison matrix.++## Affected spec domains++1. **text-editing** — major rewrite: textarea overlay → canvas-native editing with phantom textarea, TextEditor class in core, selection/caret rendering+2. **editor-ui** — VariablesPanel → VariablesDialog (TanStack Table, page properties entry point), FontPicker component, ColorInput extraction+3. **canvas-rendering** — text selection highlights and blinking caret drawn on canvas during editing+4. **desktop-app** — font-kit system font commands (list_system_fonts, load_system_font), app icon/name fixes+5. **undo-redo** — variable operations now undoable (create/delete/rename variable, create collection, rename collection, change color/value)+6. **scene-graph** — demo variable collections (primitives, semantic, spacing) validate multi-mode and alias features++## VitePress docs updates+- features.md: rewrite text editing section (canvas-native), add font picker details, update variables UI description+- figma-comparison.md: update Text tool row (canvas-native), Font loading (font-kit Tauri), Variables → more complete status+- roadmap.md: add text editing and fonts to Phase 4 delivered+- keyboard-shortcuts.md: no new shortcuts (existing ones still apply)++## Risks+- None — documentation only, no source changesdiff --git a/openspec/changes/archive/2026-03-01-sync-text-editing-fonts-variables-ui/proposal.md b/openspec/changes/archive/2026-03-01-sync-text-editing-fonts-variables-ui/proposal.mdnew file mode 100644index 000000000..b8404eccb--- /dev/null+++ b/openspec/changes/archive/2026-03-01-sync-text-editing-fonts-variables-ui/proposal.md@@ -0,0 +1,38 @@+# Proposal: Sync text editing, system fonts, variables UI++## Why+19 commits merged from master (adea7eb..33d3def) introduce three major feature areas that need specs, docs, and comparison matrix updates.++## What changed++### Canvas-native text editing (33d3def)+- TextEditor class in packages/core/src/text-editor.ts — cursor, selection, word boundaries, line navigation via CanvasKit Paragraph API (getGlyphPositionAtCoordinate, getRectsForRange)+- Renderer draws selection highlights (blue translucent rects) and blinking caret directly on canvas+- Phantom textarea (hidden off-screen) captures input, IME composition, clipboard, arrow keys, Home/End, word/line movement (⌥/⌘ modifiers)+- Replaces old visible textarea overlay approach+- use-text-edit.ts composable handles input/composition/clipboard/keyboard+- use-canvas-input.ts adds text selection drag + double-click word select+- editor.ts reworked startTextEditing/commitTextEdit to use TextEditor++### System font enumeration via font-kit (5ccae70, 326f5d1, 621e38e, 4e03d26)+- Rust: list_system_fonts and load_system_font Tauri commands using font-kit crate+- OnceLock cache in Rust for font list, preloaded on app startup+- TS font shim: Tauri path uses invoke() vs browser queryLocalFonts+- FontPicker component: reka-ui Listbox + PopoverRoot with virtual scroll, search filter, CSS font preview via registerFontFaces+- Extracted from TypographySection into standalone FontPicker.vue++### Variables dialog redesign (5c4c6d7 → 2054436, 10 commits)+- VariablesPanel → VariablesDialog (reka-ui Dialog + Tabs + Editable)+- VariablesSection in page properties panel (settings icon opens dialog)+- TanStack Table (@tanstack/vue-table) with resizable columns+- Table layout matches Figma: Name | Mode 1 | Mode 2 | ...+- ColorInput component extracted (swatch + hex, replaces duplication in PageSection, StrokeSection, EffectsSection, VariablesDialog)+- ColorPicker: alpha slider checkerboard fix+- Undo/redo for all variable operations (create/delete variable, create collection, rename, color change)+- Demo: 3 collections (Primitives Light/Dark, Semantic aliases, Spacing Default/Compact)+- Double-click to rename collection tabs++### Desktop app polish (88765bd, faf7ba6, f7d1d59)+- Pencil loader icon as Tauri app icon+- Cargo crate renamed to open_pencil, binary to OpenPencil+- macOS Dock name fix: open-pencil-app → OpenPencildiff --git a/openspec/changes/archive/2026-03-01-sync-text-editing-fonts-variables-ui/specs/canvas-rendering/spec.md b/openspec/changes/archive/2026-03-01-sync-text-editing-fonts-variables-ui/specs/canvas-rendering/spec.mdnew file mode 100644index 000000000..9671ea268--- /dev/null+++ b/openspec/changes/archive/2026-03-01-sync-text-editing-fonts-variables-ui/specs/canvas-rendering/spec.md@@ -0,0 +1,18 @@+# canvas-rendering Specification (delta)++## New Requirements++### Requirement: Text editing overlay rendering+During text editing, the renderer SHALL draw on the canvas: a blue outline around the text node bounds, translucent blue rectangles for the text selection range, and a blinking black caret at the cursor position. The caret SHALL blink at ~530ms intervals and become solid (non-blinking) immediately after any input. Selection rects and caret position are obtained from TextEditor via getSelectionRects() and getCaretRect().++#### Scenario: Caret rendering+- **WHEN** user is editing text with no selection+- **THEN** a blinking black caret is drawn at the cursor position within the text node++#### Scenario: Selection rendering+- **WHEN** user has selected a range of text during editing+- **THEN** translucent blue rectangles are drawn behind the selected text glyphs++#### Scenario: Blue outline during editing+- **WHEN** user is editing a text node+- **THEN** a blue outline is drawn around the text node bounds (at selection color)diff --git a/openspec/changes/archive/2026-03-01-sync-text-editing-fonts-variables-ui/specs/desktop-app/spec.md b/openspec/changes/archive/2026-03-01-sync-text-editing-fonts-variables-ui/specs/desktop-app/spec.mdnew file mode 100644index 000000000..83f3d9eab--- /dev/null+++ b/openspec/changes/archive/2026-03-01-sync-text-editing-fonts-variables-ui/specs/desktop-app/spec.md@@ -0,0 +1,32 @@+# desktop-app Specification (delta)++## New Requirements++### Requirement: System font commands via font-kit+The Tauri backend SHALL expose two Rust commands using the font-kit crate: `list_system_fonts` (returns all system font families with style names, cached via OnceLock) and `load_system_font` (loads font data by family + style name, with weight matching and fallback to first font in family). The TS font shim SHALL detect Tauri runtime and use invoke() instead of queryLocalFonts.++#### Scenario: List system fonts+- **WHEN** the frontend calls list_system_fonts via Tauri invoke+- **THEN** a sorted list of font families with styles is returned++#### Scenario: Load specific font style+- **WHEN** the frontend requests "Inter" "Bold" via load_system_font+- **THEN** the font data (ArrayBuffer) is returned and registered with the font provider++#### Scenario: Font list caching+- **WHEN** list_system_fonts is called multiple times+- **THEN** the result is cached (OnceLock) and returned instantly after the first call++### Requirement: CSS font face registration+System font faces SHALL be registered with document.fonts for CSS preview in the font picker. Each system font creates a FontFace pointing to local() source.++#### Scenario: Font preview in picker+- **WHEN** system fonts are loaded in Tauri+- **THEN** font faces are registered so CSS can render preview text in each font++### Requirement: App identity+The Cargo crate SHALL be named `open_pencil` and the binary `OpenPencil`. The macOS Dock SHALL display "OpenPencil". The app icon SHALL use the pencil loader icon.++#### Scenario: macOS Dock name+- **WHEN** the app is running on macOS+- **THEN** the Dock displays "OpenPencil" (not "open-pencil-app")diff --git a/openspec/changes/archive/2026-03-01-sync-text-editing-fonts-variables-ui/specs/editor-ui/spec.md b/openspec/changes/archive/2026-03-01-sync-text-editing-fonts-variables-ui/specs/editor-ui/spec.mdnew file mode 100644index 000000000..50298eafc--- /dev/null+++ b/openspec/changes/archive/2026-03-01-sync-text-editing-fonts-variables-ui/specs/editor-ui/spec.md@@ -0,0 +1,49 @@+# editor-ui Specification (delta)++## Modified Requirements++### Requirement: Variables panel (MODIFIED → Variables dialog)+The editor SHALL display a VariablesSection in the page-level properties panel showing variable/collection counts and a settings icon. Clicking the icon opens a VariablesDialog (reka-ui Dialog) with: collection tabs (reka-ui Tabs, double-click to rename), a TanStack Table (@tanstack/vue-table) with resizable columns (Name | Mode 1 | Mode 2 | ...), search bar, and a "+ Create variable" button. Color variables display inline ColorInput with picker. Variable names and values are editable inline (reka-ui Editable).++#### Scenario: Open variables dialog+- **WHEN** user clicks the settings icon in the Variables section of page properties+- **THEN** a dialog opens showing collection tabs and a variables table++#### Scenario: Rename collection+- **WHEN** user double-clicks a collection tab name+- **THEN** the tab becomes editable for renaming++#### Scenario: Resize table columns+- **WHEN** user drags a column border in the variables table header+- **THEN** the column width adjusts++#### Scenario: Search variables+- **WHEN** user types in the search bar in the variables dialog+- **THEN** only variables matching the search term are shown++## New Requirements++### Requirement: ColorInput component+A reusable ColorInput component SHALL display a color swatch with ColorPicker and an optional hex input. It SHALL replace duplicated color picker + hex input patterns in PageSection, StrokeSection, EffectsSection, and VariablesDialog.++#### Scenario: Color input with editing+- **WHEN** ColorInput is rendered with editable=true+- **THEN** a swatch with picker and an editable hex input are shown++#### Scenario: Color input read-only+- **WHEN** ColorInput is rendered with editable=false (default)+- **THEN** a swatch with picker and a read-only hex label are shown++### Requirement: ColorPicker alpha slider checkerboard+The ColorPicker alpha slider SHALL display a checkerboard background behind the transparent-to-color gradient, matching FillPicker's implementation.++#### Scenario: Alpha slider visual+- **WHEN** user opens a ColorPicker+- **THEN** the alpha slider shows a checkerboard pattern indicating transparency++### Requirement: Demo variable collections+The demo document SHALL include three variable collections demonstrating multi-mode and alias features: Primitives (Light/Dark modes, 9 color variables), Semantic (aliases to Primitives), and Spacing (Default/Compact modes, 8 number variables). Variables SHALL be bound to demo nodes.++#### Scenario: Demo loads with variables+- **WHEN** the demo document is created+- **THEN** three collections with variables and bindings are present in the scene graphdiff --git a/openspec/changes/archive/2026-03-01-sync-text-editing-fonts-variables-ui/specs/text-editing/spec.md b/openspec/changes/archive/2026-03-01-sync-text-editing-fonts-variables-ui/specs/text-editing/spec.mdnew file mode 100644index 000000000..301c057f1--- /dev/null+++ b/openspec/changes/archive/2026-03-01-sync-text-editing-fonts-variables-ui/specs/text-editing/spec.md@@ -0,0 +1,83 @@+# text-editing Specification (delta)++## Modified Requirements++### Requirement: Inline text editing (MODIFIED)+Double-clicking a text node SHALL enter canvas-native inline editing mode. A hidden phantom textarea (positioned off-screen, opacity 0) SHALL capture keyboard input, IME composition, and clipboard events. The canvas SHALL render the text directly using CanvasKit Paragraph API — no visible textarea overlay.++#### Scenario: Enter edit mode+- **WHEN** user double-clicks a text node+- **THEN** a phantom textarea is created off-screen and focused, the canvas renders text with a blinking caret++#### Scenario: IME composition+- **WHEN** user enters IME composition during text editing+- **THEN** the phantom textarea handles compositionstart/compositionend events and the composed text is inserted into the TextEditor++### Requirement: Font loading (MODIFIED)+The editor SHALL load Inter as the default font. In Tauri, system fonts SHALL be enumerated and loaded via Rust commands (list_system_fonts, load_system_font) using the font-kit crate. In browser, the Local Font Access API SHALL be used when available. Font list SHALL be preloaded on app startup (cached via OnceLock in Rust) so the picker is ready instantly.++#### Scenario: Default font+- **WHEN** a text node is created without specifying a font+- **THEN** the Inter font is used for rendering++#### Scenario: System fonts via Tauri+- **WHEN** the app runs as a Tauri desktop app+- **THEN** system fonts are enumerated via the font-kit Rust command and loaded via invoke()++#### Scenario: System fonts via browser+- **WHEN** the app runs in a browser with Local Font Access API+- **THEN** system fonts are enumerated via queryLocalFonts++#### Scenario: Font preloading+- **WHEN** the app starts+- **THEN** the font list is preloaded so the font picker opens without delay++## New Requirements++### Requirement: TextEditor class in core+A TextEditor class SHALL live in packages/core/src/text-editor.ts providing cursor positioning, text selection, word boundary detection, and line navigation using CanvasKit Paragraph API (getGlyphPositionAtCoordinate, getRectsForRange, getLineMetrics). It SHALL support: insert, backspace, delete, select all, select word, move left/right/up/down, move to line start/end, move word left/right, and extend selection with Shift.++#### Scenario: Cursor positioning+- **WHEN** user clicks inside a text node during editing+- **THEN** the cursor moves to the glyph position nearest to the click coordinates++#### Scenario: Word selection+- **WHEN** user double-clicks a word during text editing+- **THEN** the word is selected (from word boundary to word boundary)++#### Scenario: Line navigation+- **WHEN** user presses ⌘← during text editing+- **THEN** the cursor moves to the start of the current line++### Requirement: Font picker component+A FontPicker component SHALL provide font family selection with: reka-ui Listbox with virtual scroll (ListboxVirtualizer), search filter (ListboxFilter), CSS font preview (each row rendered in the font itself), and scroll-to-current behavior. Font faces are registered for CSS preview via registerFontFaces.++#### Scenario: Font picker search+- **WHEN** user types "Mono" in the font picker search+- **THEN** only font families containing "Mono" are shown++#### Scenario: Font preview+- **WHEN** user opens the font picker+- **THEN** each font family name is displayed in its own font face++### Requirement: Text editing keyboard navigation+The phantom textarea SHALL handle keyboard navigation with modifier support: ⌥← / ⌥→ (word movement), ⌘← / ⌘→ (line start/end), ⌘⌫ (delete to line start), ⌥⌫ (delete word), Shift extends selection for all movement keys. Cut (⌘X), Copy (⌘C), Paste (⌘V) SHALL use navigator.clipboard API.++#### Scenario: Word-level backspace+- **WHEN** user presses ⌥⌫ during text editing+- **THEN** the word before the cursor is deleted++#### Scenario: Copy selection+- **WHEN** user selects text and presses ⌘C+- **THEN** the selected text is copied to the clipboard++### Requirement: Text selection via mouse drag+Clicking inside a text node during editing SHALL position the cursor. Dragging SHALL extend the selection. Clicking outside the text node bounds SHALL commit the edit and exit editing mode.++#### Scenario: Drag to select+- **WHEN** user clicks and drags inside a text node during editing+- **THEN** the text between click start and current position is selected++#### Scenario: Click outside commits+- **WHEN** user clicks outside the editing text node+- **THEN** the text edit is committed and editing mode exitsdiff --git a/openspec/changes/archive/2026-03-01-sync-text-editing-fonts-variables-ui/specs/undo-redo/spec.md b/openspec/changes/archive/2026-03-01-sync-text-editing-fonts-variables-ui/specs/undo-redo/spec.mdnew file mode 100644index 000000000..8ad0be64b--- /dev/null+++ b/openspec/changes/archive/2026-03-01-sync-text-editing-fonts-variables-ui/specs/undo-redo/spec.md@@ -0,0 +1,18 @@+# undo-redo Specification (delta)++## Modified Requirements++### Requirement: All operations undoable (MODIFIED)+Undo/redo SHALL cover all editor operations including variable operations: create variable, delete variable, rename variable, create collection, rename collection, and change variable color/value. Each variable mutation pushes an undo entry with forward and inverse callbacks.++#### Scenario: Undo variable creation+- **WHEN** user creates a variable and presses ⌘Z+- **THEN** the variable is removed from the scene graph++#### Scenario: Undo variable rename+- **WHEN** user renames a variable and presses ⌘Z+- **THEN** the variable name reverts to the previous value++#### Scenario: Undo collection rename+- **WHEN** user renames a collection and presses ⌘Z+- **THEN** the collection name reverts to the previous valuediff --git a/openspec/changes/archive/2026-03-01-sync-text-editing-fonts-variables-ui/tasks.md b/openspec/changes/archive/2026-03-01-sync-text-editing-fonts-variables-ui/tasks.mdnew file mode 100644index 000000000..41a8e4094--- /dev/null+++ b/openspec/changes/archive/2026-03-01-sync-text-editing-fonts-variables-ui/tasks.md@@ -0,0 +1,25 @@+# Tasks: Sync text editing, system fonts, variables UI++Reference: 19 commits from master (adea7eb..33d3def).+Delta-specs in `openspec/changes/sync-text-editing-fonts-variables-ui/specs/` (text-editing, canvas-rendering, editor-ui, desktop-app, undo-redo).+Proposal: `proposal.md`, Design: `design.md` — validated and aligned with delta-specs.++## 1. Merge Delta-Specs into Main Specs++Each task merges ADDED and MODIFIED requirements from the delta-spec into the baseline. Untouched requirements in the baseline are preserved.++- [x] 1.1 Update `openspec/specs/text-editing/spec.md` — MODIFIED: "Inline text editing" (textarea overlay → canvas-native with phantom textarea), "Font loading" (add Tauri font-kit + preloading). ADDED: "TextEditor class in core", "Font picker component", "Text editing keyboard navigation", "Text selection via mouse drag"+- [x] 1.2 Update `openspec/specs/canvas-rendering/spec.md` — ADDED: "Text editing overlay rendering" (selection rects, blinking caret, blue outline)+- [x] 1.3 Update `openspec/specs/editor-ui/spec.md` — MODIFIED: "Variables panel" → "Variables dialog" (TanStack Table, page properties entry, collection tabs). ADDED: "ColorInput component", "ColorPicker alpha slider checkerboard", "Demo variable collections"+- [x] 1.4 Update `openspec/specs/desktop-app/spec.md` — ADDED: "System font commands via font-kit", "CSS font face registration", "App identity"+- [x] 1.5 Update `openspec/specs/undo-redo/spec.md` — MODIFIED: "All operations undoable" (add variable create/delete/rename, collection create/rename, color/value change)++## 2. Update VitePress Docs++- [x] 2.1 Update `docs/guide/features.md` — rewrite "Inline Text Editing" section (canvas-native, phantom textarea, TextEditor in core, cursor/selection/word boundaries, keyboard navigation with ⌥/⌘ modifiers), add font picker details (virtual scroll, search, CSS preview, font-kit in Tauri). Update Variables section (dialog with TanStack Table, mode columns, collection tabs, undo/redo for variable ops, demo collections with Light/Dark + aliases + spacing). Note: keep anchor `#inline-text-editing` unchanged or add redirect+- [x] 2.2 Update `docs/guide/figma-comparison.md` — specific row changes: "Text tool & inline editing" ✅ update notes (canvas-native, phantom textarea), "Font loading" ✅ update notes (font-kit + preloading in Tauri, queryLocalFonts in browser), "Variables" 🟡 update notes (dialog + TanStack Table + undo/redo + demo collections). Recount ✅/🟡/🔲 totals and update coverage line+- [x] 2.3 Update `docs/development/roadmap.md` — add to Phase 4 Delivered (currently ✅): canvas-native text editing with TextEditor, system font enumeration via font-kit, font picker with virtual scroll, variables dialog redesign (TanStack Table), variable undo/redo, ColorInput extraction, app icon and identity++## 3. Verify++- [x] 3.1 Run `bun run docs:build` — verify VitePress build passes, check no broken anchor warnings in outputdiff --git a/openspec/specs/canvas-rendering/spec.md b/openspec/specs/canvas-rendering/spec.mdindex 9bb7320be..002e33330 100644--- a/openspec/specs/canvas-rendering/spec.md+++ b/openspec/specs/canvas-rendering/spec.md@@ -190,3 +190,19 @@ The renderer SHALL distinguish between scene changes (increments sceneVersion +#### Scenario: Pan does not trigger export preview update- **WHEN** user pans the canvas- **THEN** sceneVersion does not change, so export preview is not re-rendered+++### Requirement: Text editing overlay rendering+During text editing, the renderer SHALL draw on the canvas: a blue outline around the text node bounds, translucent blue rectangles for the text selection range, and a blinking black caret at the cursor position. The caret SHALL blink at ~530ms intervals and become solid (non-blinking) immediately after any input. Selection rects and caret position are obtained from TextEditor via getSelectionRects() and getCaretRect().++#### Scenario: Caret rendering+- **WHEN** user is editing text with no selection+- **THEN** a blinking black caret is drawn at the cursor position within the text node++#### Scenario: Selection rendering+- **WHEN** user has selected a range of text during editing+- **THEN** translucent blue rectangles are drawn behind the selected text glyphs++#### Scenario: Blue outline during editing+- **WHEN** user is editing a text node+- **THEN** a blue outline is drawn around the text node bounds (at selection color)diff --git a/openspec/specs/desktop-app/spec.md b/openspec/specs/desktop-app/spec.mdindex 8b0aa74be..92baac799 100644--- a/openspec/specs/desktop-app/spec.md+++ b/openspec/specs/desktop-app/spec.md@@ -112,3 +112,32 @@ The project SHALL use a Bun workspace monorepo. The engine (scene-graph, rendere- **WHEN** @open-pencil/core is imported in a Bun/Node environment without browser APIs- **THEN** it loads successfully++### Requirement: System font commands via font-kit+The Tauri backend SHALL expose two Rust commands using the font-kit crate: `list_system_fonts` (returns all system font families with style names, cached via OnceLock) and `load_system_font` (loads font data by family + style name, with weight matching and fallback to first font in family). The TS font shim SHALL detect Tauri runtime and use invoke() instead of queryLocalFonts.++#### Scenario: List system fonts+- **WHEN** the frontend calls list_system_fonts via Tauri invoke+- **THEN** a sorted list of font families with styles is returned++#### Scenario: Load specific font style+- **WHEN** the frontend requests "Inter" "Bold" via load_system_font+- **THEN** the font data (ArrayBuffer) is returned and registered with the font provider++#### Scenario: Font list caching+- **WHEN** list_system_fonts is called multiple times+- **THEN** the result is cached (OnceLock) and returned instantly after the first call++### Requirement: CSS font face registration+System font faces SHALL be registered with document.fonts for CSS preview in the font picker. Each system font creates a FontFace pointing to local() source.++#### Scenario: Font preview in picker+- **WHEN** system fonts are loaded in Tauri+- **THEN** font faces are registered so CSS can render preview text in each font++### Requirement: App identity+The Cargo crate SHALL be named `open_pencil` and the binary `OpenPencil`. The macOS Dock SHALL display "OpenPencil". The app icon SHALL use the pencil loader icon.++#### Scenario: macOS Dock name+- **WHEN** the app is running on macOS+- **THEN** the Dock displays "OpenPencil" (not "open-pencil-app")diff --git a/openspec/specs/editor-ui/spec.md b/openspec/specs/editor-ui/spec.mdindex 8408e0de6..e67d19190 100644--- a/openspec/specs/editor-ui/spec.md+++ b/openspec/specs/editor-ui/spec.md@@ -201,16 +201,28 @@ The CanvasKit surface SHALL be recreated at most once per animation frame during- **WHEN** user drags a panel resize handle continuously- **THEN** the WebGL surface is recreated at most once per frame-### Requirement: Variables panel-The editor SHALL include a VariablesPanel toggled from the bottom of the layers sidebar. The panel uses reka-ui Tabs for collections and Editable for variable names/values. Users can create, rename, and delete variables and collections, switch modes, and set variable values per mode.+### Requirement: Variables dialog+The editor SHALL display a VariablesSection in the page-level properties panel showing variable/collection counts and a settings icon. Clicking the icon opens a VariablesDialog (reka-ui Dialog) with: collection tabs (reka-ui Tabs, double-click to rename), a TanStack Table (@tanstack/vue-table) with resizable columns (Name | Mode 1 | Mode 2 | ...), search bar, and a "+ Create variable" button. Color variables display inline ColorInput with picker. Variable names and values are editable inline (reka-ui Editable).-#### Scenario: Toggle variables panel-- **WHEN** user clicks the variables toggle in the layers sidebar-- **THEN** the VariablesPanel appears showing collections as tabs+#### Scenario: Open variables dialog+- **WHEN** user clicks the settings icon in the Variables section of page properties+- **THEN** a dialog opens showing collection tabs and a variables table++#### Scenario: Rename collection+- **WHEN** user double-clicks a collection tab name+- **THEN** the tab becomes editable for renaming++#### Scenario: Resize table columns+- **WHEN** user drags a column border in the variables table header+- **THEN** the column width adjusts++#### Scenario: Search variables+- **WHEN** user types in the search bar in the variables dialog+- **THEN** only variables matching the search term are shown#### Scenario: Edit variable value-- **WHEN** user clicks a variable value in the panel-- **THEN** an editable input allows changing the value for the active mode+- **WHEN** user clicks a variable value cell in the table+- **THEN** an editable input allows changing the value for that mode### Requirement: Fill section variable pickerThe fill section SHALL include a variable picker (reka-ui Popover + Combobox) to bind a color variable to a fill. Bound fills display a purple variable name badge with a detach button.@@ -244,3 +256,28 @@ The editor SHALL display a minimalist loading animation (centered logo + progres#### Scenario: Initial load- **WHEN** user opens the editor- **THEN** a splash loader is shown until CanvasKit WASM is loaded, then fades out++### Requirement: ColorInput component+A reusable ColorInput component SHALL display a color swatch with ColorPicker and an optional hex input. It SHALL replace duplicated color picker + hex input patterns in PageSection, StrokeSection, EffectsSection, and VariablesDialog.++#### Scenario: Color input with editing+- **WHEN** ColorInput is rendered with editable=true+- **THEN** a swatch with picker and an editable hex input are shown++#### Scenario: Color input read-only+- **WHEN** ColorInput is rendered with editable=false (default)+- **THEN** a swatch with picker and a read-only hex label are shown++### Requirement: ColorPicker alpha slider checkerboard+The ColorPicker alpha slider SHALL display a checkerboard background behind the transparent-to-color gradient, matching FillPicker's implementation.++#### Scenario: Alpha slider visual+- **WHEN** user opens a ColorPicker+- **THEN** the alpha slider shows a checkerboard pattern indicating transparency++### Requirement: Demo variable collections+The demo document SHALL include three variable collections demonstrating multi-mode and alias features: Primitives (Light/Dark modes, 9 color variables), Semantic (aliases to Primitives), and Spacing (Default/Compact modes, 8 number variables). Variables SHALL be bound to demo nodes.++#### Scenario: Demo loads with variables+- **WHEN** the demo document is created+- **THEN** three collections with variables and bindings are present in the scene graphdiff --git a/openspec/specs/text-editing/spec.md b/openspec/specs/text-editing/spec.mdindex 6cb363a0e..0d38d9bf1 100644--- a/openspec/specs/text-editing/spec.md+++ b/openspec/specs/text-editing/spec.md@@ -1,8 +1,10 @@# text-editing Specification## Purpose-Text creation and inline editing. Text tool (T), CanvasKit Paragraph API rendering, textarea overlay for editing, font loading (Inter default + system fonts via Local Font Access API), font weight support.+Text creation and canvas-native inline editing. Text tool (T), TextEditor class in core (cursor, selection, word boundaries, line navigation via CanvasKit Paragraph API), phantom textarea for input capture, font loading (Inter default + system fonts via font-kit in Tauri / Local Font Access API in browser), font picker with virtual scroll and CSS preview.+## Requirements+### Requirement: Text tool creates text nodesPressing T SHALL activate the text tool. Clicking on canvas SHALL create a new empty text node with cursor blinking.@@ -11,11 +13,52 @@ Pressing T SHALL activate the text tool. Clicking on canvas SHALL create a new e- **THEN** an empty text node is created at the click position with a visible cursor### Requirement: Inline text editing-Double-clicking a text node SHALL enter inline editing mode with a textarea overlay positioned over the canvas text. The canvas text and selection SHALL be hidden during editing.+Double-clicking a text node SHALL enter canvas-native inline editing mode. A hidden phantom textarea (positioned off-screen, opacity 0) SHALL capture keyboard input, IME composition, and clipboard events. The canvas SHALL render the text directly using CanvasKit Paragraph API — no visible textarea overlay.#### Scenario: Enter edit mode- **WHEN** user double-clicks a text node-- **THEN** a textarea overlay appears and the canvas-rendered text is hidden+- **THEN** a phantom textarea is created off-screen and focused, the canvas renders text with a blinking caret++#### Scenario: IME composition+- **WHEN** user enters IME composition during text editing+- **THEN** the phantom textarea handles compositionstart/compositionend events and the composed text is inserted into the TextEditor++### Requirement: TextEditor class in core+A TextEditor class SHALL live in packages/core/src/text-editor.ts providing cursor positioning, text selection, word boundary detection, and line navigation using CanvasKit Paragraph API (getGlyphPositionAtCoordinate, getRectsForRange, getLineMetrics). It SHALL support: insert, backspace, delete, select all, select word, move left/right/up/down, move to line start/end, move word left/right, and extend selection with Shift.++#### Scenario: Cursor positioning+- **WHEN** user clicks inside a text node during editing+- **THEN** the cursor moves to the glyph position nearest to the click coordinates++#### Scenario: Word selection+- **WHEN** user double-clicks a word during text editing+- **THEN** the word is selected (from word boundary to word boundary)++#### Scenario: Line navigation+- **WHEN** user presses ⌘← during text editing+- **THEN** the cursor moves to the start of the current line++### Requirement: Text editing keyboard navigation+The phantom textarea SHALL handle keyboard navigation with modifier support: ⌥← / ⌥→ (word movement), ⌘← / ⌘→ (line start/end), ⌘⌫ (delete to line start), ⌥⌫ (delete word), Shift extends selection for all movement keys. Cut (⌘X), Copy (⌘C), Paste (⌘V) SHALL use navigator.clipboard API.++#### Scenario: Word-level backspace+- **WHEN** user presses ⌥⌫ during text editing+- **THEN** the word before the cursor is deleted++#### Scenario: Copy selection+- **WHEN** user selects text and presses ⌘C+- **THEN** the selected text is copied to the clipboard++### Requirement: Text selection via mouse drag+Clicking inside a text node during editing SHALL position the cursor. Dragging SHALL extend the selection. Clicking outside the text node bounds SHALL commit the edit and exit editing mode.++#### Scenario: Drag to select+- **WHEN** user clicks and drags inside a text node during editing+- **THEN** the text between click start and current position is selected++#### Scenario: Click outside commits+- **WHEN** user clicks outside the editing text node+- **THEN** the text edit is committed and editing mode exits### Requirement: CanvasKit Paragraph API renderingText nodes SHALL be rendered using CanvasKit's Paragraph API for proper text shaping, line breaking, and font metrics.@@ -25,22 +68,41 @@ Text nodes SHALL be rendered using CanvasKit's Paragraph API for proper text sha- **THEN** the text wraps to multiple lines using Paragraph API layout### Requirement: Font loading-The editor SHALL load Inter as the default font. The Local Font Access API SHALL be used to enumerate and load system fonts when available.+The editor SHALL load Inter as the default font. In Tauri, system fonts SHALL be enumerated and loaded via Rust commands (list_system_fonts, load_system_font) using the font-kit crate. In browser, the Local Font Access API SHALL be used when available. Font list SHALL be preloaded on app startup (cached via OnceLock in Rust) so the picker is ready instantly.#### Scenario: Default font- **WHEN** a text node is created without specifying a font- **THEN** the Inter font is used for rendering-#### Scenario: System fonts-- **WHEN** the Local Font Access API is available-- **THEN** system fonts are enumerable in the font picker+#### Scenario: System fonts via Tauri+- **WHEN** the app runs as a Tauri desktop app+- **THEN** system fonts are enumerated via the font-kit Rust command and loaded via invoke()++#### Scenario: System fonts via browser+- **WHEN** the app runs in a browser with Local Font Access API+- **THEN** system fonts are enumerated via queryLocalFonts++#### Scenario: Font preloading+- **WHEN** the app starts+- **THEN** the font list is preloaded so the font picker opens without delay++### Requirement: Font picker component+A FontPicker component SHALL provide font family selection with: reka-ui Listbox with virtual scroll (ListboxVirtualizer), search filter (ListboxFilter), CSS font preview (each row rendered in the font itself), and scroll-to-current behavior. Font faces are registered for CSS preview via registerFontFaces.++#### Scenario: Font picker search+- **WHEN** user types "Mono" in the font picker search+- **THEN** only font families containing "Mono" are shown++#### Scenario: Font preview+- **WHEN** user opens the font picker+- **THEN** each font family name is displayed in its own font face### Requirement: Font weight support-Font weight SHALL be applied to both the CanvasKit text style and the textarea overlay during editing.+Font weight SHALL be applied to the CanvasKit text style during rendering.#### Scenario: Bold text rendering- **WHEN** a text node has fontWeight 700-- **THEN** both the canvas rendering and the editing overlay display bold text+- **THEN** the canvas rendering displays bold text### Requirement: Blue editing outlineA blue outline SHALL appear around a text node during editing to indicate edit mode.@@ -48,4 +110,3 @@ A blue outline SHALL appear around a text node during editing to indicate edit m#### Scenario: Edit mode indicator- **WHEN** user is editing a text node inline- **THEN** a blue outline is visible around the text node bounds-diff --git a/openspec/specs/undo-redo/spec.md b/openspec/specs/undo-redo/spec.mdindex 6044d22e1..c9ca0ca78 100644--- a/openspec/specs/undo-redo/spec.md+++ b/openspec/specs/undo-redo/spec.md@@ -15,7 +15,7 @@ The undo system SHALL use an inverse-command pattern where every operation recor- **THEN** the node moves back to the position after the original move### Requirement: All operations undoable-Undo/redo SHALL be wired into all editor operations: create, delete, move, resize, rotate, property changes, reparent, layout changes.+Undo/redo SHALL be wired into all editor operations: create, delete, move, resize, rotate, property changes, reparent, layout changes, and variable operations (create/delete variable, create collection, rename variable, rename collection, change variable color/value). Each variable mutation pushes an undo entry with forward and inverse callbacks.#### Scenario: Undo node creation- **WHEN** user creates a rectangle and presses ⌘Z@@ -25,3 +25,15 @@ Undo/redo SHALL be wired into all editor operations: create, delete, move, resiz- **WHEN** user changes a node's fill color from blue to red and presses ⌘Z- **THEN** the fill color reverts to blue+#### Scenario: Undo variable creation+- **WHEN** user creates a variable and presses ⌘Z+- **THEN** the variable is removed from the scene graph++#### Scenario: Undo variable rename+- **WHEN** user renames a variable and presses ⌘Z+- **THEN** the variable name reverts to the previous value++#### Scenario: Undo collection rename+- **WHEN** user renames a collection and presses ⌘Z+- **THEN** the collection name reverts to the previous value+