openpencil/packages/pen-react
Kayshen Xu e0b606833b V0.7.3 (#111)
* fix(ai): stop white section bands on dark-themed pages

- role-resolver: skip fixSectionAlternation when parent fill luminance < 0.5, so we no longer paint #FFFFFF/#F8FAFC over a dark root
- strip-redundant-section-fills: add SAFE_LIGHT_HEXES so stale whites from earlier runs (or weak-model hedges) are cleaned up on the sink side
- regression tests for both layers

* feat(ai): design.md-driven background + sidebar color pipeline

- orchestrator-sidebar-color: extract sidebar surface picker; prefer design.md palette role (sidebar/panel/surface) over catalog style-guide legacy cell
- orchestrator-planning: force rootFrame fill from design.md background when a user spec is provided, so sections don't inherit a bright catalog default
- orchestrator-prompt-optimizer: infer design.md background + neutral theme fallback for sub-agent prompts
- orchestrator-sub-agent / ai-prompts: tell sub-agents to leave section root fills unset when design.md drives the palette
- design-md-style-policy: surface-colors policy block keeps MCP and web pipeline aligned
- add planning + prompt-optimizer regression tests

* chore: ignore .omx/ directory

* Enable local OS fonts with vector rendering and proper permission handling (#110)

* docs(readme): update cover screenshot

* fix(renderer): enable local OS fonts with vector rendering and proper permission handling

* test(renderer): refactoring names and creating vi.stubGlobal for the navigator as it's not available in the test environment.

---------

Co-authored-by: Fini <fini.yang@gmail.com>
Co-authored-by: Daniel Chettiar <danielc@snapwork.com>

* feat(types): add AppendContext and SubTask.existingSectionLabels

* feat(ai): add detectAppendIntent for continue/append prompts

* feat(ai): detect append intent before generate_design dispatch

* feat(ai): add applyAppendContextToPlan helper

* feat(ai): reuse existing content-root in append mode

* feat(ai): sub-agent APPEND MODE preamble for existing siblings

* docs(ai): teach horizontal scroll card-row pattern

* chore(ai): enable incremental-add skill in generation phase

* fix(canvas): render synchronously on resize to prevent white flash

Setting canvas.width/height clears the pixel buffer to transparent.
resize() previously only marked dirty, leaving the canvas transparent
until the next RAF and showing the container bg-muted through for one
frame whenever the flex layout shifted (e.g. RightPanel mount on first
selection after idle). Rendering inline after recreateSurface fills
the new surface before the browser paints, closing that window.

* style: apply oxfmt formatting drift across web and renderer files

Non-semantic line-break and wrapping adjustments picked up by oxfmt.
No behavior changes.

* fix(mcp): run codex via shell on Windows to handle .cmd shims

Since Node 18.20/20.12 (CVE-2024-27980) execFileSync refuses to spawn
.cmd/.bat files directly and throws EINVAL. On Windows route through
execSync with shell resolution so PATHEXT picks whichever shim exists
(codex.exe / codex.cmd / codex.ps1).

* feat(editor): anchor paste to selected container or sibling

Pressing Cmd/Ctrl+V now inserts pasted nodes into the selected
container (if it can hold children) or immediately after the selected
node as a sibling, falling back to the root when nothing is selected.
Previously every paste landed at document root, which broke expected
behavior when working inside nested frames.

* docs(ai): expand horizontal scroll card-row example in overflow skill

Flesh out the inline JSON example so the generation-phase skill shows
the full clipContent + nested fit_content row pattern, instead of a
truncated snippet that left model output inconsistent.

* style(lint): clear 7 oxlint warnings from recent commits

- orchestrator-planning.test.ts: narrow fill-array type to
  Array<{...}> | undefined and use ?.[0] instead of unchecked [0]
  so optional chain does not throw on short-circuit
- mcp-install.ts: drop `?? {}` fallbacks when spreading
  config.mcpServers; spread of undefined in an object literal
  is a no-op (ES2018+)

* style(lint): clear remaining 15 oxlint warnings across repo

Removes pre-existing warnings not related to any single feature:

- no-useless-fallback-in-spread (6): drop `?? {}` when spreading
  possibly-undefined records (document-store-variable-actions,
  pen-mcp/tools/{variables,theme-presets}, variable-theme-manager)
- no-useless-spread (2): replace `[...iterable]` with `Array.from`
  in for-of snapshots (document-events, agent-indicator), keeping
  the re-entry-safe copy intent explicit
- no-control-regex (2): use `\P{ASCII}` unicode property escape
  instead of `[^\x00-\x7F]` to express "non-ASCII" without
  referencing U+0000 (opencode clients)
- no-new-array (1): `Array.from({ length }, () => '..')` in
  document-assets
- no-unused-vars (3): drop unused catch params (agent.ts,
  code-generation-pipeline) and unused globSync import
  (patch-srvx-bun)
- no-useless-escape (1): `[[{]` instead of `[\[{]` in
  chat-message-content regex

---------

Co-authored-by: Fini <fini.yang@gmail.com>
Co-authored-by: Daniel Chettiar <74943095+1MochaChan1@users.noreply.github.com>
Co-authored-by: Daniel Chettiar <danielc@snapwork.com>
2026-04-15 22:19:12 +08:00
..
src V0.7.0 (#95) 2026-04-11 23:25:13 +08:00
CLAUDE.md V0.7.1 (#102) 2026-04-13 21:30:23 +08:00
LICENSE V0.7.1 (#102) 2026-04-13 21:30:23 +08:00
package.json V0.7.3 (#111) 2026-04-15 22:19:12 +08:00
README.md V0.7.1 (#102) 2026-04-13 21:30:23 +08:00
tsconfig.json V0.7.0 (#95) 2026-04-11 23:25:13 +08:00

@zseven-w/pen-react

React UI SDK for OpenPencil — a complete set of hooks, components, and panels to build a design editor with React.

Install

npm install @zseven-w/pen-react
# or
bun add @zseven-w/pen-react

Peer dependencies: react@^19, react-dom@^19, @radix-ui/react-* (popover, select, separator, slider, switch, toggle, tooltip)

Overview

pen-react wraps @zseven-w/pen-engine into idiomatic React: a context provider, 10 semantic hooks, and 39 ready-to-use components covering the full editor UI.

<DesignProvider>
  <CoreToolbar />
  <DesignCanvas />
  <LayerPanel />
  <PropertyPanel />
  <PageTabs />
  <StatusBar />
</DesignProvider>

Quick Start

import {
  DesignProvider,
  DesignCanvas,
  CoreToolbar,
  LayerPanel,
  PropertyPanel,
} from '@zseven-w/pen-react';

function Editor() {
  return (
    <DesignProvider initialDocument={myDoc}>
      <div className="flex h-screen">
        <LayerPanel />
        <div className="flex flex-col flex-1">
          <CoreToolbar />
          <DesignCanvas className="flex-1" />
        </div>
        <PropertyPanel />
      </div>
    </DesignProvider>
  );
}

Hooks

All hooks subscribe to the engine and re-render on change:

import {
  useDesignEngine,
  useDocument,
  useSelection,
  useViewport,
  useActiveTool,
  useHistory,
  useActiveNode,
  useActivePage,
  useHover,
  useVariables,
} from '@zseven-w/pen-react';

function Inspector() {
  const node = useActiveNode(); // PenNode | null
  const selection = useSelection(); // string[]
  const { canUndo, undo } = useHistory();
  const viewport = useViewport(); // { zoom, panX, panY }
  const tool = useActiveTool(); // ToolType
  const doc = useDocument(); // PenDocument
  const page = useActivePage(); // PenPage
  const hoverId = useHover(); // string | null
  const variables = useVariables(); // VariableDefinition[]
  const engine = useDesignEngine(); // DesignEngine (escape hatch)

  return <div>Selected: {selection.length} nodes</div>;
}

Provider

Uncontrolled mode

Engine owns the document. Good for standalone editors:

<DesignProvider initialDocument={doc}>{children}</DesignProvider>

Controlled mode

Parent owns the document. Good for integration into existing state:

<DesignProvider document={doc} onDocumentChange={(newDoc) => setDoc(newDoc)}>
  {children}
</DesignProvider>

Echo-loop prevention is built in — onDocumentChange won't fire for changes that originated from the parent.

Components

Canvas

Component Description
DesignCanvas GPU-rendered canvas with CanvasKit/Skia. Handles zoom, pan, resize, and all interactions.
<DesignCanvas
  className="w-full h-full"
  onReady={(engine) => console.log('Canvas ready')}
  loadingFallback={<Spinner />}
/>

Toolbar

Component Description
CoreToolbar Main tool selection bar (select, frame, shapes, text, pen, image)
ToolButton Individual tool button with icon + active state
ShapeToolDropdown Dropdown for shape tools (rectangle, ellipse, polygon, line)
BooleanToolbar Union, subtract, intersect, exclude operations

Panels

Component Description
LayerPanel Hierarchical tree view with drag-and-drop reordering
LayerItem Single layer row — collapse, visibility, lock, rename
LayerContextMenu Right-click menu: copy, paste, delete, group, z-order
PropertyPanel Tabbed property inspector for the selected node
PageTabs Multi-page tab bar with add/rename/reorder/delete
StatusBar Bottom bar with zoom, coordinates, node count

Property Sections

Drop these into your own property panel or use PropertyPanel which includes all of them:

Section Edits
SizeSection x, y, width, height, rotation, constraints
FillSection Solid color, linear/radial gradient
StrokeSection Color, thickness, dash pattern, cap, join
TextSection Font family, size, weight, color, alignment
TextLayoutSection Line height, letter spacing, paragraph spacing
CornerRadiusSection Uniform or per-corner border radius
EffectsSection Drop shadow, inner shadow, blur
LayoutSection Auto-layout direction, gap, justify, align
LayoutPaddingSection Uniform or per-side padding
AppearanceSection Opacity, blend mode
IconSection Icon name picker (Lucide icons)
ImageSection Image source, fit mode
ExportSection Code generation target (React, HTML, Vue, etc.)

Shared UI

Component Description
ColorPicker Color input with swatch palette and hex input
NumberInput Numeric field with drag-to-adjust and arrow keys
SectionHeader Collapsible section header with title + actions
FontPicker Font family selector with preview
VariablePicker Design variable reference picker ($primary, etc.)
IconPickerDialog Modal icon browser with search and categories

UI Store

Ephemeral UI state (panel open/close, drag state) managed by Zustand — separate from engine state:

import { useUIStore } from '@zseven-w/pen-react';

const { layerPanelOpen, toggleLayerPanel } = useUIStore();

Styling

Components use Tailwind CSS + CVA for variant styling, and Radix UI primitives for accessibility. Override styles via className props or Tailwind's design token system.

License

MIT