openpencil/packages/codegen
Danila Poyarkov 67dbd7156f
feat(design-jsx): export every property the renderer accepts (#814)
* feat(design-jsx): export every property the renderer accepts

JSX export wrote only part of a layer: one solid fill, one stroke
without its alignment, shadows as repeated attributes, background blurs
as layer blurs, and nothing for hidden children, constraints, size
limits, absolute positioning, vertical text alignment, masks, or
variable bindings. Rendering an export lost those properties, and JSX
diffs could not see changes to them.

The export now writes them, using paint and effect helper calls when a
shorthand cannot express a value exactly, and leaves out values the
renderer would infer, so ordinary output stays as it was. Prop values
can now hold objects, arrays, and helper calls, printed through
@open-pencil/codegen's builders, which gain a call expression. The
language gains `visible`, `locked`, `constraints` (Figma's constraints
object with lowercase values, as `blendMode` uses), `italic`,
`strokes`, `strokeWeights`, `strokeCap`, and `strokeJoin`, and now
applies `strokeAlign`, `strokeDash`, and the size limits, which it
accepted but ignored. Per-corner radii are written even when the
uniform radius is 0. A round-trip test renders each case's export and
checks the fields and that exporting again changes nothing.

* docs(fig): name the saved-glyph fixture by its repository path

The observation note linked the fixture with a relative path climbing four directories. Other notes name fixtures by their repository path, which reads the same from anywhere.

* fix(design-jsx): export the node-level dash pattern

A node's own dashPattern was not written, so a node dashed at node level
came back solid and the DOM/CSS export chose a solid border. It now
round-trips as a separate dashPattern prop; strokeDash stays the
stroke-local dash.
2026-10-03 15:40:21 +04:00
..
scripts refactor: print OpenPencil JSX export as syntax trees (#799) 2026-10-01 21:22:43 +04:00
src feat(design-jsx): export every property the renderer accepts (#814) 2026-10-03 15:40:21 +04:00
tests refactor: print OpenPencil JSX export as syntax trees (#799) 2026-10-01 21:22:43 +04:00
package.json refactor: print OpenPencil JSX export as syntax trees (#799) 2026-10-01 21:22:43 +04:00
README.md refactor: print OpenPencil JSX export as syntax trees (#799) 2026-10-01 21:22:43 +04:00
tsconfig.json refactor: print OpenPencil JSX export as syntax trees (#799) 2026-10-01 21:22:43 +04:00
tsdown.config.ts refactor: print OpenPencil JSX export as syntax trees (#799) 2026-10-01 21:22:43 +04:00

@open-pencil/codegen

Syntax-tree code generation for OpenPencil's exporters. Build JavaScript, TypeScript, and JSX as ESTree nodes and print them with esrap, instead of concatenating strings.

import { jsx } from '@open-pencil/codegen'

const card = jsx.element(
  'Card',
  [jsx.attribute('title', jsx.stringValue('Fish & chips'))],
  [jsx.text('Hello')],
  0,
  true
)
jsx.printJSX(card) // <Card title={"Fish & chips"}>Hello</Card>

jsx.stringValue and jsx.text keep a value as plain JSX only when JSX reads it back unchanged; anything with quotes, entities, braces, angle brackets, backslashes, or line breaks becomes a string literal.

es parses TypeScript templates, fills $name placeholders, and prints modules:

import { es } from '@open-pencil/codegen'

const module = es.fill(es.parseModule("export const title = '$title'"), {
  $title: es.string('Checkout')
})
es.printModule(module) // export const title = 'Checkout';