AI-native design editor. Open-source Figma alternative.
Add text props (lineHeight, letterSpacing, textCase, textDecoration, maxLines), spacing checks, update prompt
Anton A S633469f61fe8
diff --git a/packages/core/src/render/export-jsx.ts b/packages/core/src/render/export-jsx.tsindex 7a6fbbf5d..5d9eb411c 100644--- a/packages/core/src/render/export-jsx.ts+++ b/packages/core/src/render/export-jsx.ts@@ -359,6 +359,12 @@ function collectTextNodeProps(node: SceneNode, props: [string, unknown][]): voidif (node.textAlignHorizontal !== 'LEFT') {props.push(['textAlign', node.textAlignHorizontal.toLowerCase()])}+ if (node.lineHeight != null) props.push(['lineHeight', node.lineHeight])+ if (node.letterSpacing !== 0) props.push(['letterSpacing', node.letterSpacing])+ if (node.textDecoration !== 'NONE') props.push(['textDecoration', node.textDecoration.toLowerCase()])+ if (node.textCase !== 'ORIGINAL') props.push(['textCase', node.textCase.toLowerCase()])+ if (node.maxLines != null) props.push(['maxLines', node.maxLines])+ if (node.textTruncation === 'ENDING' && node.maxLines == null) props.push(['truncate', true])const textColor = solidFillColor(node.fills)if (textColor) {const bgIdx = props.findIndex(([k]) => k === 'bg')diff --git a/packages/core/src/render/renderer.ts b/packages/core/src/render/renderer.tsindex ae6c567ea..811522aee 100644--- a/packages/core/src/render/renderer.ts+++ b/packages/core/src/render/renderer.ts@@ -388,6 +388,18 @@ function applyTextOverrides(o.fills = [colorToFill(props.color)]}+ if (props.lineHeight !== undefined) o.lineHeight = props.lineHeight as number+ if (props.letterSpacing !== undefined) o.letterSpacing = props.letterSpacing as number+ if (props.textDecoration !== undefined) o.textDecoration = (props.textDecoration as string).toUpperCase() as SceneNode['textDecoration']+ if (props.textCase !== undefined) o.textCase = (props.textCase as string).toUpperCase() as SceneNode['textCase']+ if (props.maxLines !== undefined) {+ o.maxLines = props.maxLines as number+ o.textTruncation = 'ENDING'+ }+ if (props.truncate) {+ o.textTruncation = 'ENDING'+ }+if (props.textAlign) {o.textAlignHorizontal = TEXT_ALIGN_MAP[props.textAlign as string] ?? 'LEFT'}diff --git a/packages/core/src/tools/describe.ts b/packages/core/src/tools/describe.tsindex b3c820bce..d18cd94d4 100644--- a/packages/core/src/tools/describe.ts+++ b/packages/core/src/tools/describe.ts@@ -376,6 +376,60 @@ function detectTypographyIssues(node: SceneNode, graph: SceneGraph, issues: Desc}}+const SPACING_GRID = 4++function detectSpacingIssues(node: SceneNode, graph: SceneGraph, gridSize: number, issues: DescribeIssue[]): void {+ if (node.layoutMode === 'NONE') return++ const children = node.childIds+ .map((id) => graph.getNode(id))+ .filter((c): c is SceneNode => c != null && c.visible && c.layoutPositioning !== 'ABSOLUTE')++ // Padding larger than gap inside same container looks wrong+ const minPad = Math.min(node.paddingTop, node.paddingRight, node.paddingBottom, node.paddingLeft)+ if (node.itemSpacing > 0 && minPad > 0 && node.itemSpacing > minPad * 2) {+ issues.push({+ message: `Gap ${node.itemSpacing} is much larger than padding ${minPad} in "${node.name}"`,+ suggestion: 'Gap should usually be ≤ padding'+ })+ }++ // Off-grid spacing values+ const spacingValues = [node.itemSpacing, node.paddingTop, node.paddingRight, node.paddingBottom, node.paddingLeft]+ .filter((v) => v > 0)+ for (const v of spacingValues) {+ if (v % SPACING_GRID !== 0) {+ const nearest = Math.round(v / SPACING_GRID) * SPACING_GRID+ issues.push({+ message: `Spacing value ${v} in "${node.name}" is not on ${SPACING_GRID}px grid`,+ suggestion: `Use ${nearest}`+ })+ break+ }+ }++ // Inconsistent padding/gap among sibling containers of similar role+ const flexChildren = children.filter((c) => c.layoutMode !== 'NONE')+ if (flexChildren.length >= 2) {+ const paddings = flexChildren.map((c) => c.paddingTop + c.paddingRight + c.paddingBottom + c.paddingLeft)+ const gaps = flexChildren.map((c) => c.itemSpacing)+ const uniquePads = new Set(paddings)+ const uniqueGaps = new Set(gaps.filter((g) => g > 0))+ if (uniquePads.size > 2) {+ issues.push({+ message: `Inconsistent padding across sibling containers in "${node.name}" (${[...uniquePads].join(', ')})`,+ suggestion: 'Use the same padding for similar containers'+ })+ }+ if (uniqueGaps.size > 2) {+ issues.push({+ message: `Inconsistent gaps across sibling containers in "${node.name}" (${[...uniqueGaps].join(', ')})`,+ suggestion: 'Use the same gap for similar containers'+ })+ }+ }+}+function detectIssues(node: SceneNode, gridSize: number, graph: SceneGraph): DescribeIssue[] {const issues: DescribeIssue[] = []detectStructuralIssues(node, gridSize, issues)@@ -383,6 +437,7 @@ function detectIssues(node: SceneNode, gridSize: number, graph: SceneGraph): DesdetectLayoutIssues(node, graph, issues)detectRadiusIssues(node, graph, issues)detectTypographyIssues(node, graph, issues)+ detectSpacingIssues(node, graph, gridSize, issues)return issues}diff --git a/src/ai/system-prompt.md b/src/ai/system-prompt.mdindex 80251858a..3ba774fd8 100644--- a/src/ai/system-prompt.md+++ b/src/ai/system-prompt.md@@ -8,15 +8,21 @@ Available elements: Frame, Text, Rectangle, Ellipse, Line, Star, Polygon, Group,All styling is done via props — there is no `style` attribute, no `className`, no CSS. Colors are hex only (#RRGGBB or #RRGGBBAA).-## Reference+## Complete props reference-**Sizing:** w={px}, h={px}, w="hug" (shrink-to-fit, default), w="fill" (stretch, requires flex parent), grow={N} (flex-grow, requires flex parent with fixed size on that axis).+These are ALL available props. Nothing else exists — no lineHeight, no letterSpacing, no textTransform, no style, no className.-**Layout:** flex="row"|"col" enables auto-layout with gap={N}, justify, items, padding (p, px, py, pt/pr/pb/pl). Without flex, children use absolute x/y coordinates. Grid: grid, columns, rows, columnGap, rowGap, colStart/rowStart/colSpan/rowSpan.+**Position:** x={N}, y={N} — only works without auto-layout parent. Setting x/y inside flex makes the child absolute-positioned.-**Appearance:** bg="#hex", stroke="#hex", strokeWidth={N}, rounded={N} (also per-corner: roundedTL/TR/BL/BR), cornerSmoothing={0-1}, opacity={0-1}, rotate={deg}, blendMode, overflow="hidden", shadow="offX offY blur #color", blur={N}.+**Sizing:** w={N}, h={N} (fixed px), w="hug"/h="hug" (shrink-to-fit, default), w="fill"/h="fill" (stretch, requires flex parent), grow={N} (flex-grow, requires flex parent with fixed size on that axis), minW={N}, maxW={N}.-**Text:** `<Text size={N} weight="bold"|"medium"|{N} color="#hex" font="Family" textAlign="left"|"center"|"right">content</Text>`. Text auto-sizes — don't set w/h unless you need wrapping (then set only w). ⚠ Text without `color` is invisible — always set `color="#hex"` on every Text element.+**Layout:** flex="row"|"col" enables auto-layout. gap={N}, wrap, rowGap={N}. justify="start"|"end"|"center"|"between"|"evenly". items="start"|"end"|"center"|"stretch". Padding: p={N}, px={N}, py={N}, pt/pr/pb/pl={N}. Grid: grid, columns="1fr 1fr", rows="1fr", columnGap={N}, rowGap={N}, colStart={N}, rowStart={N}, colSpan={N}, rowSpan={N}.++**Appearance:** bg="#hex", stroke="#hex", strokeWidth={N}, rounded={N}, roundedTL/TR/BL/BR={N}, cornerSmoothing={0-1}, opacity={0-1}, rotate={deg}, blendMode="multiply"|"screen"|etc, overflow="hidden", shadow="offX offY blur #color", blur={N}.++**Text (only on `<Text>`):** size={N}, weight="bold"|"medium"|{N}, color="#hex", font="Family", textAlign="left"|"center"|"right"|"justified", lineHeight={N} (px), letterSpacing={N} (px), textDecoration="underline"|"strikethrough", textCase="upper"|"lower"|"title", maxLines={N} (truncates with ellipsis), truncate (ellipsis without line limit). ⚠ Text without `color` has no fill — invisible. Always set `color="#hex"`.++**Shapes:** points={N} (Star/Polygon vertex count), innerRadius={N} (Star inner radius ratio).**Identity:** name="string" for the layers panel.@@ -48,6 +54,20 @@ Size hierarchy: cards/modals 16–24, buttons/inputs 8–12, chips/badges 4–8Elements flush against parent edge (no padding on that side) match parent's radius on the touching corners: `roundedTL={20} roundedTR={20} roundedBL={0} roundedBR={0}`.+## Spacing and visual rhythm++**Before rendering, decide the spacing scale and stick to it for the entire design.** Pick values from the 4px grid: 4, 8, 12, 16, 20, 24, 32, 48. Do not invent arbitrary numbers — every gap and padding must come from this set.++Hierarchy of spacing (Gestalt proximity): inside a group < between groups < between sections. If elements within a row use gap={8}, rows should be spaced at 12–16, and sections at 20–32.++Padding scales with element size: chips py={4} px={8}, buttons py={10} px={20}, cards p={16}–{24}, page containers p={24}–{48}. Padding is usually ≥ gap inside the same container.++Vertical padding looks larger than horizontal at equal values. Compensate: buttons py={10} px={20}, cards py={20} px={24}.++Dividers replace vertical space — don't add a full gap on both sides of a divider.++**Consistency rule**: once you pick padding={20} for cards, ALL cards in the design use 20. Once you pick gap={12} for detail rows, ALL detail rows use 12. Never mix 14 and 16, or 10 and 12 for the same element type.+## Chunking large designsKeep each `render` under ~40 elements. For bigger designs:@@ -85,9 +105,7 @@ Subtle UI elements on dark surfaces: at least ~20% alpha for fills, ~25% for bor### Line height-- Headings (display, H1–H3): 1.1–1.2× font size — tight-- Body text, descriptions: 1.4–1.6× — readable-- Single-line labels, buttons, chips: 1.0–1.2× — compact+Control with `lineHeight={N}` (in px, not multiplier). Headings: ~1.1–1.2× font size (e.g. size={24} lineHeight={29}). Body text: ~1.4–1.6× (e.g. size={14} lineHeight={21}). Single-line labels and buttons: omit lineHeight (auto).### Line length@@ -99,7 +117,7 @@ Space after heading ≈ 0.5–1× heading font size. Space between body paragrap### Uppercase-Only for overlines and small labels (10–12px). Always pair with bold/medium weight. Never for body text or headings larger than 13px.+Only for overlines and small labels (10–12px). Write the text content in uppercase manually — there is no textTransform prop. Always pair with bold/medium weight. Never for body text or headings larger than 13px.### Alignmentdiff --git a/tests/engine/render.test.ts b/tests/engine/render.test.tsindex 2a14ce0fe..19491bec4 100644--- a/tests/engine/render.test.ts+++ b/tests/engine/render.test.ts@@ -7,6 +7,7 @@ import {renderTreeNode,computeLayout,computeAllLayouts,+ sceneNodeToJSX,Frame,Text,Rectangle,@@ -666,3 +667,78 @@ describe('grid layout rendering', () => {expect(grid.height).toBe(460)})})++describe('text props round-trip', () => {+ it('lineHeight renders and exports', async () => {+ const g = createGraph()+ const result = await renderJSX(g, '<Text color="#000" lineHeight={24}>Hello</Text>')+ const n = g.getNode(result.id)!+ expect(n.lineHeight).toBe(24)+ const jsx = sceneNodeToJSX(n.id, g)+ expect(jsx).toContain('lineHeight={24}')+ })++ it('letterSpacing renders and exports', async () => {+ const g = createGraph()+ const result = await renderJSX(g, '<Text color="#000" letterSpacing={2}>Spaced</Text>')+ const n = g.getNode(result.id)!+ expect(n.letterSpacing).toBe(2)+ const jsx = sceneNodeToJSX(n.id, g)+ expect(jsx).toContain('letterSpacing={2}')+ })++ it('textDecoration renders and exports', async () => {+ const g = createGraph()+ const result = await renderJSX(g, '<Text color="#000" textDecoration="underline">Link</Text>')+ const n = g.getNode(result.id)!+ expect(n.textDecoration).toBe('UNDERLINE')+ const jsx = sceneNodeToJSX(n.id, g)+ expect(jsx).toContain('textDecoration="underline"')+ })++ it('textCase renders and exports', async () => {+ const g = createGraph()+ const result = await renderJSX(g, '<Text color="#000" textCase="upper">label</Text>')+ const n = g.getNode(result.id)!+ expect(n.textCase).toBe('UPPER')+ const jsx = sceneNodeToJSX(n.id, g)+ expect(jsx).toContain('textCase="upper"')+ })++ it('maxLines renders with truncation', async () => {+ const g = createGraph()+ const result = await renderJSX(g, '<Text color="#000" maxLines={2}>Long text here</Text>')+ const n = g.getNode(result.id)!+ expect(n.maxLines).toBe(2)+ expect(n.textTruncation).toBe('ENDING')+ const jsx = sceneNodeToJSX(n.id, g)+ expect(jsx).toContain('maxLines={2}')+ })++ it('truncate without maxLines', async () => {+ const g = createGraph()+ const result = await renderJSX(g, '<Text color="#000" truncate>Overflow</Text>')+ const n = g.getNode(result.id)!+ expect(n.textTruncation).toBe('ENDING')+ const jsx = sceneNodeToJSX(n.id, g)+ expect(jsx).toContain('truncate')+ })++ it('defaults omit text props', async () => {+ const g = createGraph()+ const result = await renderJSX(g, '<Text color="#000">Plain</Text>')+ const n = g.getNode(result.id)!+ expect(n.lineHeight).toBeNull()+ expect(n.letterSpacing).toBe(0)+ expect(n.textDecoration).toBe('NONE')+ expect(n.textCase).toBe('ORIGINAL')+ expect(n.maxLines).toBeNull()+ const jsx = sceneNodeToJSX(n.id, g)+ expect(jsx).not.toContain('lineHeight')+ expect(jsx).not.toContain('letterSpacing')+ expect(jsx).not.toContain('textDecoration')+ expect(jsx).not.toContain('textCase')+ expect(jsx).not.toContain('maxLines')+ expect(jsx).not.toContain('truncate')+ })+})