openpencil/packages/docs/programmable/jsx-renderer.md
Danila Poyarkov 8404cee664
refactor(design-jsx): extract design JSX into its own package (#793)
* refactor(design-jsx): extract design JSX into its own package

Design JSX elements, helpers, schema, reference, and JSX export only need
the scene graph, yet lived in Core, so every consumer of the authoring API
pulled in the renderer, layout, and file formats.

@open-pencil/design-jsx now owns them and depends only on scene-graph. The
renderer takes icon lookup, SVG conversion, vector creation, and layout as
DesignJSXServices; Core binds its own and exports the bound renderJSX and
renderTree from @open-pencil/core/design-jsx.

* feat(design-jsx): export the JSX runtime for TSX authoring

The package already had a JSX runtime, but nothing exported it, so design
trees could only be written as function calls or JSX strings. Export
`./jsx-runtime` and `./jsx-dev-runtime` so `jsxImportSource` works, and make
`Fragment` produce the same empty-type node as `<>` in `renderJSX` strings.

* fix(design-jsx): render fragments nested in other elements

A fragment builds a node with an empty type, which only renderJSX expanded, and only at the root. Nested fragments and fragments passed to renderTree failed with 'Unknown element: <>'. Inline fragment children when trees are built, and share root expansion between renderTree and renderJSX.
2026-09-30 20:55:27 +04:00

2.5 KiB

title description
JSX Renderer Create editable designs using the same declarative authoring library as OpenPencil agents.

JSX Renderer

OpenPencil's design JSX creates scene nodes, not browser DOM. You can use readable component trees, JavaScript expressions, and reusable functions to construct editable designs.

Creating Designs

The render tool accepts JSX strings in AI chat and MCP. In application or headless library code, import Frame, Text, and other authoring exports from @open-pencil/design-jsx, then create nodes with renderTree or renderJSX from @open-pencil/core/design-jsx, which add icons, SVG conversion, and layout. To write the trees as TSX, set "jsxImportSource": "@open-pencil/design-jsx" with "jsx": "react-jsx" in tsconfig.json, or add a /** @jsxImportSource @open-pencil/design-jsx */ comment to the file. The scripting environment determines which APIs are exposed to eval; package exports are not automatically globals there.

The shared design-authoring reference contains executable examples, layout guidance, and the supported syntax inventory. It is generated from the same source used by chat, ACP, codegen prompts, and the installable agent skill.

Elements

Use frames and text for composition, shape nodes for artwork, and real components and instances for reusable editor content. A JavaScript function alone does not create component identity. See the element inventory.

Style Props

Use Hug/Fill and flex or grid for content-driven sizing. Bind semantic variables instead of copying values. See composition and layout, paint and text, and variables and components.

Exporting to JSX

openpencil export design.fig -f jsx                   # OpenPencil format
openpencil export design.fig -f jsx --style tailwind  # Tailwind classes

Exported OpenPencil JSX can be edited and rendered back into the document. Check supported features and actual rendering before claiming round-trip fidelity. See CLI exports.

Visual Diffing

JSX makes structural design changes reviewable as code. Use get_jsx and diff_jsx to inspect changes, then verify the actual rendered result; a clean structural diff does not prove visual equivalence.