* fix(figma-api): lay out pending edits before geometry reads Scripts read x, y, width, height, transforms, and bounds as they were before the script ran until the tool finished and laid out its changes. Figma lays out on read, so a hugging parent reports its new size right after a child is added. The graph now records the scope of edits outside layout application, and the geometry getters lay that scope out first through the same runner tools use after a call. One recorder exists per graph; a new FigmaAPI starts it afresh because the editor lays out its own edits. * fix(layout): size each axis on its own, as Figma does Fill is stored on the child, as layoutGrow along the parent's primary axis and STRETCH across it, with a grid laid out like a row; primaryAxisSizing and counterAxisSizing only fix or hug. A shared layoutSizing helper in scene-graph reads and writes per-axis sizing, and layout, the Figma API, the properties panel, design JSX, DOM/CSS export, and .pen import use it. This fixes grid children filling both axes when set to fill one, auto-layout children that stretch but kept a fixed size, the Figma API writing Fill to a frame's own sizing (which .fig export dropped), and JSX and HTML exports losing grid and cross-axis fill. Behavior was checked against live Figma, and imported layouts were compared with the geometry stored in material3.fig and nuxtui.fig. * fix(layout): keep pending edits until laid out and opt out of inherited stretch A new FigmaAPI cleared the edits recorded on its graph, so after a script failed before its tool laid out its changes, the next script read stale geometry; edits now stay recorded until a read lays them out, and return to the record if that layout throws. Setting a child to Fixed or Hug across a parent that stretches every child left it filling; it now opts out with MIN, as frame presets do. |
||
|---|---|---|
| .. | ||
| scripts | ||
| src | ||
| tests | ||
| AGENTS.md | ||
| package.json | ||
| README.md | ||
| tsconfig.json | ||
| tsdown.config.ts | ||
@open-pencil/design-jsx
OpenPencil design JSX: build editable scene trees with <Frame>, <Text>, and the other elements, style them with paint and effect helpers and design variables, and export scene nodes back to JSX.
Set the JSX import source in tsconfig.json ("jsx": "react-jsx", "jsxImportSource": "@open-pencil/design-jsx") or per file:
/** @jsxImportSource @open-pencil/design-jsx */
import { renderTree } from '@open-pencil/core/design-jsx'
import { Frame, Text, solid } from '@open-pencil/design-jsx'
import { SceneGraph } from '@open-pencil/scene-graph'
const graph = new SceneGraph()
await renderTree(
graph,
<Frame w={320} p={16} fill={solid('#FFFFFF')}>
<Text>Hello</Text>
</Frame>
)
JSX written as a string, as agents and the MCP render tool send it, needs no build step:
import { renderJSX } from '@open-pencil/core/design-jsx'
await renderJSX(graph, '<Frame w={320} p={16} bg="#FFFFFF"><Text>Hello</Text></Frame>')
Components that behave as controls are written with Reka UI's element names, and export writes them back the same way:
<Switch.Root name="Switch" modelValue="State">
<Component name="State=Off" w={44} h={24}><Switch.Thumb x={2} y={2} w={20} h={20} /></Component>
<Component name="State=On" w={44} h={24}><Switch.Thumb x={22} y={2} w={20} h={20} /></Component>
</Switch.Root>
This package depends only on @open-pencil/scene-graph and @open-pencil/emit. Rendering needs icons, SVG conversion, and layout, which @open-pencil/core/design-jsx provides; other engines can supply their own through createDesignJSXRenderer(services).