bug: openpencil import never computes layout — children stay at (0,0)/100x100, design renders collapsed in CLI and app
What happened?
openpencil import writes the correct node tree and the correct styles, but never computes layout. Auto-layout frames are saved with every child still at the default (0, 0) / 100×100, so the design is unusable. It renders collapsed both headlessly and in the desktop app.
Platform
CLI
Steps to reproduce
demo.html:
<div style="width:390px;height:844px;background:#0b0f1a;display:flex;flex-direction:column;padding:24px;gap:16px">
<div style="font-size:28px;font-weight:700;color:#fff">D-claro</div>
<div style="background:#151b2b;border-radius:16px;padding:20px;color:#fff">Saldo disponible</div>
<button style="background:#2563eb;border-radius:12px;padding:14px;color:#fff">Enviar dinero</button>
</div>$ openpencil import demo.html -o demo.fig --json
{ "pages": 1, "rootElements": 1 }
$ openpencil tree demo.fig --jsonResult: the root frame is correct (390×844, layoutMode: "VERTICAL"), but every child reports the defaults:
{ "id": "0:5", "type": "FRAME", "x": 0, "y": 0, "width": 100, "height": 100 }Styles import correctly — only geometry is stale
openpencil node demo.fig --id 0:9 reports fill: #151B2B and radius: 16px, and the button reports fill: #2563EB / radius: 12px. So the CSS cascade is parsed fine; only positions and sizes were never computed.
Not a reporting artifact
openpencil export demo.fig -f pngrenders every layer stacked in the top-left corner.- Opening the same file in the desktop app (v0.15.1) shows the identical collapsed result on canvas.
- A
figma-API mutation throughopenpencil eval demo.fig -c "figma.getNodeById('0:4').itemSpacing = 16" -wdoes not reposition children — before, after, or once saved.
Root cause
computeAllLayouts / computeLayout live in @open-pencil/core/dist/layout.js, and the CLI never calls them: there are zero references to either symbol in @open-pencil/cli/dist/*.mjs.
Inside core they are invoked from design-jsx/renderer.js:50, canvas/renderer/fonts.js:100, editor/layout-runner.js, plus the clipboard / pages / snapshot paths — i.e. the JSX-render and editor paths only. The HTML/CSS import path never runs a layout pass.
Related symptom from the same gap
Export persists pre-layout coordinates for fill-sized children. Rendering the equivalent design through the documented JSX path (where layout is computed) gives x = 108.5 for a centred child, but the exported file stores 14:
| child sizing | in-memory x | x in exported .fig |
|---|---|---|
w="fill" (child layoutAlignSelf: "STRETCH") |
108.5 | 14 |
w={342} fixed |
108.5 | 109 |
Minimal repro is the same frame with and without w="fill". w={342} round-trips correctly. Because OpenPencil's own renderer trusts the stored coordinates instead of recomputing (per the gap above), the fill case visibly mis-centres its text. This is distinct from #134, which was about auto-layout children carrying absolute transforms; flagging it here since it stems from the same missing/trusted-layout problem.
Suggested fix
Run computeAllLayouts(graph, pageId) after HTML/CSS import, and consider a layout pass on document load so stored coordinates stay consistent for consumers that do not recompute.
Version
@open-pencil/[email protected], @open-pencil/[email protected] (npm latest), Windows 11, Node v24.14.1
Source: open-pencil/open-pencil