AI-native design editor. Open-source Figma alternative.
Fix auto-layout overflow, grid layout, AI chat UX (#86)
Anton Soldatove939025f7d40
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex f4a086fdf..c21f4d083 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -19,7 +19,10 @@ jobs:- uses: actions/checkout@v4- name: Pull LFS files- run: git lfs pull+ run: |+ git lfs install --force+ git lfs pull+ head -c 4 tests/fixtures/material3.fig | xxd- uses: oven-sh/setup-bun@v2diff --git a/packages/core/src/clipboard.ts b/packages/core/src/clipboard.tsindex 1e9760605..73c57ee81 100644--- a/packages/core/src/clipboard.ts+++ b/packages/core/src/clipboard.ts@@ -94,6 +94,7 @@ export function figmaNodesBounds(const parentTypes = new Map<string, string>()for (const nc of nodeChanges) {+ if (!nc.guid) continueconst id = `${nc.guid.sessionID}:${nc.guid.localID}`parentTypes.set(id, nc.type ?? '')}@@ -125,6 +126,7 @@ function buildClipboardMaps(nodeChanges: KiwiNodeChange[]): ClipboardImportMapsconst guidMap = new Map<string, KiwiNodeChange>()const parentMap = new Map<string, string>()for (const nc of nodeChanges) {+ if (!nc.guid) continueconst id = `${nc.guid.sessionID}:${nc.guid.localID}`guidMap.set(id, nc)if (nc.parentIndex?.guid) {diff --git a/packages/core/src/constants.ts b/packages/core/src/constants.tsindex a66e65cb8..06e402f98 100644--- a/packages/core/src/constants.ts+++ b/packages/core/src/constants.ts@@ -165,10 +165,10 @@ export const AI_PROVIDERS: AIProviderDef[] = [name: 'Google AI',keyPlaceholder: 'AIza…',keyURL: 'https://aistudio.google.com/apikey',- defaultModel: 'gemini-3.1-pro',+ defaultModel: 'gemini-3.1-pro-preview',models: [- { id: 'gemini-3.1-pro', name: 'Gemini 3.1 Pro', tag: '1M context' },- { id: 'gemini-3-flash', name: 'Gemini 3 Flash', tag: 'Fast' }+ { id: 'gemini-3.1-pro-preview', name: 'Gemini 3.1 Pro', tag: '1M context' },+ { id: 'gemini-3-flash-preview', name: 'Gemini 3 Flash', tag: 'Fast' }]},{diff --git a/packages/core/src/figma-api.ts b/packages/core/src/figma-api.tsindex c458a9039..c12914f28 100644--- a/packages/core/src/figma-api.ts+++ b/packages/core/src/figma-api.ts@@ -698,13 +698,14 @@ class FigmaNodeProxy {get layoutAlign(): string {const n = this._raw()- return n.layoutAlignSelf === 'STRETCH' ? 'STRETCH' : 'INHERIT'+ if (n.layoutAlignSelf === 'AUTO') return 'INHERIT'+ return n.layoutAlignSelf}set layoutAlign(v: string) {- const mapped = v === 'STRETCH' ? 'STRETCH' : 'AUTO'+ const mapped = v === 'INHERIT' ? 'AUTO' : vthis[INTERNAL_GRAPH].updateNode(this[INTERNAL_ID], {- layoutAlignSelf: mapped+ layoutAlignSelf: mapped as SceneNode['layoutAlignSelf']})}diff --git a/packages/core/src/index.ts b/packages/core/src/index.tsindex 3252e5115..0ce618d6b 100644--- a/packages/core/src/index.ts+++ b/packages/core/src/index.ts@@ -22,6 +22,7 @@ export {type LayoutMode,type LayoutSizing,type LayoutAlign,+ type LayoutAlignSelf,type LayoutCounterAlign,type LayoutWrap,type GridTrack,diff --git a/packages/core/src/kiwi/codec.ts b/packages/core/src/kiwi/codec.tsindex 9fd13af2d..51abd95e3 100644--- a/packages/core/src/kiwi/codec.ts+++ b/packages/core/src/kiwi/codec.ts@@ -236,7 +236,7 @@ export interface VariableDataValuesEntry {export interface NodeChange {[key: string]: unknown- guid: GUID+ guid?: GUIDphase?: 'CREATED' | 'REMOVED'parentIndex?: ParentIndextype?: stringdiff --git a/packages/core/src/kiwi/fig-import.ts b/packages/core/src/kiwi/fig-import.tsindex 295a119c6..191ddcfc0 100644--- a/packages/core/src/kiwi/fig-import.ts+++ b/packages/core/src/kiwi/fig-import.ts@@ -24,6 +24,7 @@ function buildChangeMaps(nodeChanges: NodeChange[]): ChangeMaps {const childrenMap = new Map<string, string[]>()for (const nc of nodeChanges) {+ if (!nc.guid) continueif (nc.phase === 'REMOVED') continueconst id = guidToString(nc.guid)changeMap.set(id, nc)diff --git a/packages/core/src/kiwi/instance-overrides.ts b/packages/core/src/kiwi/instance-overrides.tsindex a2b4b5605..f206a96ae 100644--- a/packages/core/src/kiwi/instance-overrides.ts+++ b/packages/core/src/kiwi/instance-overrides.ts@@ -17,12 +17,12 @@ interface SymbolData {}interface ComponentPropRef {- defID: GUID+ defID?: GUIDcomponentPropNodeField: string}interface ComponentPropAssignment {- defID: GUID+ defID?: GUIDvalue: { boolValue?: boolean; textValue?: string; guidValue?: GUID }}@@ -259,7 +259,7 @@ export function populateAndApplyOverrides(function assignmentsToValueMap(assignments: ComponentPropAssignment[]): Map<string, ComponentPropAssignment['value']> {const valueByDef = new Map<string, ComponentPropAssignment['value']>()for (const a of assignments) {- valueByDef.set(guidToString(a.defID), a.value)+ if (a.defID) valueByDef.set(guidToString(a.defID), a.value)}return valueByDef}@@ -351,6 +351,7 @@ export function populateAndApplyOverrides(const refs = findPropRefs(child.componentId, propRefsMap)if (refs) {for (const ref of refs) {+ if (!ref.defID) continueconst val = valueByDef.get(guidToString(ref.defID))if (!val) continuediff --git a/packages/core/src/kiwi/kiwi-convert.ts b/packages/core/src/kiwi/kiwi-convert.tsindex 1a3cbe681..9146e51f1 100644--- a/packages/core/src/kiwi/kiwi-convert.ts+++ b/packages/core/src/kiwi/kiwi-convert.ts@@ -19,6 +19,7 @@ import type {LayoutMode,LayoutSizing,LayoutAlign,+ LayoutAlignSelf,LayoutCounterAlign,ConstraintType,TextAutoResize,@@ -222,7 +223,6 @@ function mapStackJustify(justify?: string): LayoutAlign {case 'MAX':return 'MAX'case 'SPACE_BETWEEN':- case 'SPACE_EVENLY':return 'SPACE_BETWEEN'default:return 'MIN'@@ -244,6 +244,23 @@ function mapStackCounterAlign(align?: string): LayoutCounterAlign {}}+function mapAlignSelf(align?: string): LayoutAlignSelf {+ switch (align) {+ case 'MIN':+ return 'MIN'+ case 'CENTER':+ return 'CENTER'+ case 'MAX':+ return 'MAX'+ case 'STRETCH':+ return 'STRETCH'+ case 'BASELINE':+ return 'BASELINE'+ default:+ return 'AUTO'+ }+}+function mapConstraint(c?: string): ConstraintType {switch (c) {case 'CENTER':@@ -525,7 +542,7 @@ function convertLayoutProps(nc: NodeChange): Pick<SceneNode, 'layoutMode' | 'itecounterAxisSpacing: nc.stackCounterSpacing ?? 0,layoutPositioning: nc.stackPositioning === 'ABSOLUTE' ? 'ABSOLUTE' : 'AUTO',layoutGrow: nc.stackChildPrimaryGrow ?? 0,- layoutAlignSelf: (nc.stackChildAlignSelf as string) === 'STRETCH' ? 'STRETCH' : 'AUTO',+ layoutAlignSelf: mapAlignSelf(nc.stackChildAlignSelf),counterAxisAlignContent: (nc.stackCounterAlignContent as string) === 'SPACE_BETWEEN' ? 'SPACE_BETWEEN' : 'AUTO',itemReverseZIndex: (nc.stackReverseZIndex ?? false) as boolean,strokesIncludedInLayout: (nc.strokesIncludedInLayout ?? false) as boolean@@ -679,8 +696,7 @@ function applyOverrideLayout(ov: Record<string, unknown>, updates: Partial<Sceneupdates.counterAxisAlign = mapStackCounterAlign(ov.stackCounterAlignItems as string)if (ov.stackChildPrimaryGrow != null) updates.layoutGrow = ov.stackChildPrimaryGrow as numberif (ov.stackChildAlignSelf != null)- updates.layoutAlignSelf =- (ov.stackChildAlignSelf as string) === 'STRETCH' ? 'STRETCH' : 'AUTO'+ updates.layoutAlignSelf = mapAlignSelf(ov.stackChildAlignSelf as string)if (ov.stackPositioning != null)updates.layoutPositioning =(ov.stackPositioning as string) === 'ABSOLUTE' ? 'ABSOLUTE' : 'AUTO'diff --git a/packages/core/src/layout.ts b/packages/core/src/layout.tsindex bd3740b3c..9b1a35d01 100644--- a/packages/core/src/layout.ts+++ b/packages/core/src/layout.ts@@ -7,14 +7,19 @@ import Yoga, {Gutter,Justify,Edge,+ MeasureMode,Overflow,+ PositionType,Wrap,type Node as YogaNode} from 'yoga-layout'import type { GridTrack, SceneGraph, SceneNode } from './scene-graph'-export type TextMeasurer = (node: SceneNode) => { width: number; height: number } | null+export type TextMeasurer = (+ node: SceneNode,+ maxWidth?: number+) => { width: number; height: number } | nulllet globalTextMeasurer: TextMeasurer | null = null@@ -68,7 +73,9 @@ function mapGridTrack(track: GridTrack): { type: GridTrackType; value: number }function configureAsGrid(yogaNode: YogaNode, node: SceneNode): void {yogaNode.setDisplay(Display.Grid)yogaNode.setWidth(node.width)- yogaNode.setHeight(node.height)+ if (node.gridTemplateRows.length > 0 || node.height > 0) {+ yogaNode.setHeight(node.height)+ }if (node.gridTemplateColumns.length > 0) {yogaNode.setGridTemplateColumns(node.gridTemplateColumns.map(mapGridTrack))@@ -98,10 +105,17 @@ function createGridChildNode(child: SceneNode): YogaNode {yogaChild.setGridRowStart(pos.row)yogaChild.setGridRowEndSpan(pos.rowSpan)}- if (child.layoutGrow > 0 || child.layoutAlignSelf === 'STRETCH') {- yogaChild.setFlexGrow(1)+ const hasLayout = child.layoutMode !== 'NONE'+ const explicitStretch = child.layoutGrow > 0 || child.layoutAlignSelf === 'STRETCH'++ if (explicitStretch || hasLayout) {+ yogaChild.setWidthStretch()} else {yogaChild.setWidth(child.width)+ }+ if (explicitStretch) {+ yogaChild.setHeightStretch()+ } else {yogaChild.setHeight(child.height)}}@@ -114,8 +128,13 @@ function buildGridTree(graph: SceneGraph, frame: SceneNode): YogaNode {const children = graph.getChildren(frame.id)for (const child of children) {- if (child.layoutPositioning === 'ABSOLUTE') continue- root.insertChild(createGridChildNode(child), root.getChildCount())+ if (child.layoutPositioning === 'ABSOLUTE') {+ const yogaChild = Yoga.Node.create()+ configureAbsoluteChild(yogaChild, child)+ root.insertChild(yogaChild, root.getChildCount())+ } else {+ root.insertChild(createGridChildNode(child), root.getChildCount())+ }}return root@@ -135,36 +154,15 @@ function buildYogaTree(graph: SceneGraph, frame: SceneNode): YogaNode {else root.setWidth(frame.width)}- root.setFlexDirection(- frame.layoutMode === 'HORIZONTAL' ? FlexDirection.Row : FlexDirection.Column- )- root.setFlexWrap(frame.layoutWrap === 'WRAP' ? Wrap.Wrap : Wrap.NoWrap)- root.setJustifyContent(mapJustify(frame.primaryAxisAlign))- root.setAlignItems(mapAlign(frame.counterAxisAlign))- if (frame.clipsContent) root.setOverflow(Overflow.Hidden)-- root.setPadding(Edge.Top, frame.paddingTop)- root.setPadding(Edge.Right, frame.paddingRight)- root.setPadding(Edge.Bottom, frame.paddingBottom)- root.setPadding(Edge.Left, frame.paddingLeft)-- root.setGap(- Gutter.Column,- frame.layoutMode === 'HORIZONTAL' ? frame.itemSpacing : frame.counterAxisSpacing- )- root.setGap(- Gutter.Row,- frame.layoutMode === 'HORIZONTAL' ? frame.counterAxisSpacing : frame.itemSpacing- )+ configureFlexContainer(root, frame)const children = graph.getChildren(frame.id)for (const child of children) {-- if (child.layoutPositioning === 'ABSOLUTE') continue-const yogaChild = Yoga.Node.create()- if (!child.visible) {+ if (child.layoutPositioning === 'ABSOLUTE') {+ configureAbsoluteChild(yogaChild, child)+ } else if (!child.visible) {yogaChild.setDisplay(Display.None)} else if (child.layoutMode === 'GRID') {configureChildAsGrid(yogaChild, child, frame, graph)@@ -180,28 +178,115 @@ function buildYogaTree(graph: SceneGraph, frame: SceneNode): YogaNode {return root}+function configureAbsoluteChild(yogaChild: YogaNode, child: SceneNode): void {+ yogaChild.setPositionType(PositionType.Absolute)+ yogaChild.setPosition(Edge.Left, child.x)+ yogaChild.setPosition(Edge.Top, child.y)+ yogaChild.setWidth(child.width)+ yogaChild.setHeight(child.height)+}++function configureFlexContainer(yogaNode: YogaNode, node: SceneNode): void {+ yogaNode.setFlexDirection(+ node.layoutMode === 'HORIZONTAL' ? FlexDirection.Row : FlexDirection.Column+ )+ yogaNode.setFlexWrap(node.layoutWrap === 'WRAP' ? Wrap.Wrap : Wrap.NoWrap)+ yogaNode.setJustifyContent(mapJustify(node.primaryAxisAlign))+ yogaNode.setAlignItems(mapAlign(node.counterAxisAlign))+ if (node.clipsContent) yogaNode.setOverflow(Overflow.Hidden)++ if (node.layoutWrap === 'WRAP' && node.counterAxisAlignContent === 'SPACE_BETWEEN') {+ yogaNode.setAlignContent(Align.SpaceBetween)+ }++ yogaNode.setPadding(Edge.Top, node.paddingTop)+ yogaNode.setPadding(Edge.Right, node.paddingRight)+ yogaNode.setPadding(Edge.Bottom, node.paddingBottom)+ yogaNode.setPadding(Edge.Left, node.paddingLeft)++ yogaNode.setGap(+ Gutter.Column,+ node.layoutMode === 'HORIZONTAL' ? node.itemSpacing : node.counterAxisSpacing+ )+ yogaNode.setGap(+ Gutter.Row,+ node.layoutMode === 'HORIZONTAL' ? node.counterAxisSpacing : node.itemSpacing+ )++ applyMinMaxConstraints(yogaNode, node)+}+function configureChildAsGrid(yogaChild: YogaNode,child: SceneNode,- _parent: SceneNode,+ parent: SceneNode,graph: SceneGraph): void {- configureAsGrid(yogaChild, child)+ yogaChild.setDisplay(Display.Grid)++ if (child.gridTemplateColumns.length > 0) {+ yogaChild.setGridTemplateColumns(child.gridTemplateColumns.map(mapGridTrack))+ }+ if (child.gridTemplateRows.length > 0) {+ yogaChild.setGridTemplateRows(child.gridTemplateRows.map(mapGridTrack))+ }++ yogaChild.setGap(Gutter.Column, child.gridColumnGap)+ yogaChild.setGap(Gutter.Row, child.gridRowGap)++ yogaChild.setPadding(Edge.Top, child.paddingTop)+ yogaChild.setPadding(Edge.Right, child.paddingRight)+ yogaChild.setPadding(Edge.Bottom, child.paddingBottom)+ yogaChild.setPadding(Edge.Left, child.paddingLeft)++ const isParentRow = parent.layoutMode === 'HORIZONTAL'+ const selfOverride = child.layoutAlignSelf !== 'AUTO'+ const stretchCross = selfOverride+ ? child.layoutAlignSelf === 'STRETCH'+ : parent.counterAxisAlign === 'STRETCH'if (child.layoutGrow > 0) {yogaChild.setFlexGrow(child.layoutGrow)- }- if (child.layoutAlignSelf === 'STRETCH') {- yogaChild.setAlignSelf(Align.Stretch)+ yogaChild.setFlexShrink(1)+ yogaChild.setFlexBasis(0)+ if (!stretchCross) {+ if (isParentRow) yogaChild.setHeight(child.height)+ else yogaChild.setWidth(child.width)+ }+ } else {+ if (isParentRow) {+ yogaChild.setWidth(child.width)+ if (!stretchCross) yogaChild.setHeight(child.height)+ } else {+ if (child.gridTemplateRows.length > 0) yogaChild.setHeight(child.height)+ if (!stretchCross) yogaChild.setWidth(child.width)+ }}+ const selfAlign = mapAlignSelf(child.layoutAlignSelf)+ if (selfAlign != null) yogaChild.setAlignSelf(selfAlign)++ applyMinMaxConstraints(yogaChild, child)+const grandchildren = graph.getChildren(child.id)for (const gc of grandchildren) {- if (gc.layoutPositioning === 'ABSOLUTE') continue- yogaChild.insertChild(createGridChildNode(gc), yogaChild.getChildCount())+ if (gc.layoutPositioning === 'ABSOLUTE') {+ const yogaGC = Yoga.Node.create()+ configureAbsoluteChild(yogaGC, gc)+ yogaChild.insertChild(yogaGC, yogaChild.getChildCount())+ } else {+ yogaChild.insertChild(createGridChildNode(gc), yogaChild.getChildCount())+ }}}+function applyMinMaxConstraints(yogaNode: YogaNode, node: SceneNode): void {+ if (node.minWidth != null) yogaNode.setMinWidth(node.minWidth)+ if (node.maxWidth != null) yogaNode.setMaxWidth(node.maxWidth)+ if (node.minHeight != null) yogaNode.setMinHeight(node.minHeight)+ if (node.maxHeight != null) yogaNode.setMaxHeight(node.maxHeight)+}+function configureChildAsAutoLayout(yogaChild: YogaNode,child: SceneNode,@@ -222,38 +307,20 @@ function configureChildAsAutoLayout(setSizing(yogaChild, 'height', heightSizing, child.height, child.layoutGrow)}- if (child.layoutAlignSelf === 'STRETCH') {- yogaChild.setAlignSelf(Align.Stretch)- }+ const selfAlign = mapAlignSelf(child.layoutAlignSelf)+ if (selfAlign != null) yogaChild.setAlignSelf(selfAlign)- yogaChild.setFlexDirection(- child.layoutMode === 'HORIZONTAL' ? FlexDirection.Row : FlexDirection.Column- )- yogaChild.setFlexWrap(child.layoutWrap === 'WRAP' ? Wrap.Wrap : Wrap.NoWrap)- yogaChild.setJustifyContent(mapJustify(child.primaryAxisAlign))- yogaChild.setAlignItems(mapAlign(child.counterAxisAlign))- if (child.clipsContent) yogaChild.setOverflow(Overflow.Hidden)-- yogaChild.setPadding(Edge.Top, child.paddingTop)- yogaChild.setPadding(Edge.Right, child.paddingRight)- yogaChild.setPadding(Edge.Bottom, child.paddingBottom)- yogaChild.setPadding(Edge.Left, child.paddingLeft)-- yogaChild.setGap(- Gutter.Column,- child.layoutMode === 'HORIZONTAL' ? child.itemSpacing : child.counterAxisSpacing- )- yogaChild.setGap(- Gutter.Row,- child.layoutMode === 'HORIZONTAL' ? child.counterAxisSpacing : child.itemSpacing- )+ configureFlexContainer(yogaChild, child)const grandchildren = graph.getChildren(child.id)for (const gc of grandchildren) {- if (gc.layoutPositioning === 'ABSOLUTE') continueconst yogaGC = Yoga.Node.create()- if (!gc.visible) {+ if (gc.layoutPositioning === 'ABSOLUTE') {+ configureAbsoluteChild(yogaGC, gc)+ } else if (!gc.visible) {yogaGC.setDisplay(Display.None)+ } else if (gc.layoutMode === 'GRID') {+ configureChildAsGrid(yogaGC, gc, child, graph)} else if (gc.layoutMode !== 'NONE') {configureChildAsAutoLayout(yogaGC, gc, child, graph)} else {@@ -265,15 +332,82 @@ function configureChildAsAutoLayout(function configureChildAsLeaf(yogaChild: YogaNode, child: SceneNode, parent: SceneNode): void {const isRow = parent.layoutMode === 'HORIZONTAL'- const stretchCross = child.layoutAlignSelf === 'STRETCH' || parent.counterAxisAlign === 'STRETCH'+ const selfOverride = child.layoutAlignSelf !== 'AUTO'+ const stretchCross = selfOverride+ ? child.layoutAlignSelf === 'STRETCH'+ : parent.counterAxisAlign === 'STRETCH'const isText = child.type === 'TEXT'- const autoW = isText && child.textAutoResize === 'WIDTH_AND_HEIGHT'- const autoH = isText && (child.textAutoResize === 'HEIGHT' || child.textAutoResize === 'WIDTH_AND_HEIGHT')+ const needsMeasureFunc =+ isText && globalTextMeasurer && child.textAutoResize !== 'NONE'++ if (needsMeasureFunc) {+ configureTextLeaf(yogaChild, child, parent)+ } else {+ configureNonTextLeaf(yogaChild, child, isRow, stretchCross)+ }++ const selfAlign = mapAlignSelf(child.layoutAlignSelf)+ if (selfAlign != null) yogaChild.setAlignSelf(selfAlign)++ applyMinMaxConstraints(yogaChild, child)+}++function configureTextLeaf(+ yogaChild: YogaNode,+ child: SceneNode,+ parent: SceneNode+): void {+ const isRow = parent.layoutMode === 'HORIZONTAL'+ const autoResize = child.textAutoResize++ if (child.layoutGrow > 0) {+ yogaChild.setFlexGrow(child.layoutGrow)+ }++ const cache = new Map<number, { width: number; height: number }>()+ const UNCONSTRAINED_KEY = -1- const measured = (autoW || autoH) ? measureTextSize(child) : null- const w = autoW && measured ? measured.width : child.width- const h = autoH && measured ? measured.height : child.height+ if (autoResize === 'WIDTH_AND_HEIGHT') {+ yogaChild.setMeasureFunc((width, widthMode, _height, _heightMode) => {+ const maxW = widthMode === MeasureMode.Undefined ? undefined : width+ const cacheKey = maxW === undefined ? UNCONSTRAINED_KEY : Math.round(maxW)+ const cached = cache.get(cacheKey)+ if (cached) return cached++ const measured = globalTextMeasurer!(child, maxW)+ const result = measured ?? { width: child.width, height: child.height }+ cache.set(cacheKey, result)+ return result+ })+ } else if (autoResize === 'HEIGHT') {+ const fixedWidth = child.width+ if (child.layoutGrow <= 0) {+ yogaChild.setWidth(fixedWidth)+ }+ yogaChild.setMeasureFunc((width, widthMode, _height, _heightMode) => {+ const constraintW =+ widthMode === MeasureMode.Undefined ? fixedWidth : Math.min(width, fixedWidth || width)+ const cacheKey = Math.round(constraintW)+ const cached = cache.get(cacheKey)+ if (cached) return cached++ const measured = globalTextMeasurer!(child, constraintW)+ const result = { width: constraintW, height: measured?.height ?? child.height }+ cache.set(cacheKey, result)+ return result+ })+ }+}++function configureNonTextLeaf(+ yogaChild: YogaNode,+ child: SceneNode,+ isRow: boolean,+ stretchCross: boolean+): void {+ const w = child.width+ const h = child.heightif (child.layoutGrow > 0) {yogaChild.setFlexGrow(child.layoutGrow)@@ -290,15 +424,6 @@ function configureChildAsLeaf(yogaChild: YogaNode, child: SceneNode, parent: Sceif (!stretchCross) yogaChild.setWidth(w)}}-- if (child.layoutAlignSelf === 'STRETCH') {- yogaChild.setAlignSelf(Align.Stretch)- }-}--function measureTextSize(node: SceneNode): { width: number; height: number } | null {- if (!globalTextMeasurer) return null- return globalTextMeasurer(node)}function setSizing(@@ -311,6 +436,7 @@ function setSizing(if (grow > 0) {yogaNode.setFlexGrow(grow)yogaNode.setFlexShrink(1)+ yogaNode.setFlexBasis(0)return}@@ -324,53 +450,89 @@ function setSizing(case 'FILL':yogaNode.setFlexGrow(1)yogaNode.setFlexShrink(1)+ yogaNode.setFlexBasis(0)break}}-function applyYogaLayout(graph: SceneGraph, frame: SceneNode, yogaNode: YogaNode): void {- if (frame.layoutMode !== 'GRID') {- if (frame.primaryAxisSizing === 'HUG' || frame.counterAxisSizing === 'HUG') {- const computedW = yogaNode.getComputedWidth()- const computedH = yogaNode.getComputedHeight()- const updates: Partial<SceneNode> = {}-- if (frame.primaryAxisSizing === 'HUG') {- if (frame.layoutMode === 'HORIZONTAL') updates.width = computedW- else updates.height = computedH- }- if (frame.counterAxisSizing === 'HUG') {- if (frame.layoutMode === 'HORIZONTAL') updates.height = computedH- else updates.width = computedW- }-- graph.updateNode(frame.id, updates)+function applyFrameSize(graph: SceneGraph, frame: SceneNode, yogaNode: YogaNode): void {+ if (frame.layoutMode === 'GRID') {+ if (frame.gridTemplateRows.length === 0) {+ graph.updateNode(frame.id, { height: yogaNode.getComputedHeight() })}+ return}+ if (frame.primaryAxisSizing !== 'HUG' && frame.counterAxisSizing !== 'HUG') return++ const computedW = yogaNode.getComputedWidth()+ const computedH = yogaNode.getComputedHeight()+ const updates: Partial<SceneNode> = {}++ if (frame.primaryAxisSizing === 'HUG') {+ if (frame.layoutMode === 'HORIZONTAL') updates.width = computedW+ else updates.height = computedH+ }+ if (frame.counterAxisSizing === 'HUG') {+ if (frame.layoutMode === 'HORIZONTAL') updates.height = computedH+ else updates.width = computedW+ }++ graph.updateNode(frame.id, updates)+}++function applyYogaLayout(graph: SceneGraph, frame: SceneNode, yogaNode: YogaNode): void {+ applyFrameSize(graph, frame, yogaNode)+const children = graph.getChildren(frame.id)let yogaIndex = 0for (const child of children) {- if (child.layoutPositioning === 'ABSOLUTE') continue-const yogaChild = yogaNode.getChild(yogaIndex)yogaIndex++// eslint-disable-next-line @typescript-eslint/no-unnecessary-conditionif (!yogaChild) continue- graph.updateNode(child.id, {- x: yogaChild.getComputedLeft(),- y: yogaChild.getComputedTop(),- width: yogaChild.getComputedWidth(),- height: yogaChild.getComputedHeight()- })+ if (child.visible && child.layoutPositioning !== 'ABSOLUTE') {+ graph.updateNode(child.id, {+ x: yogaChild.getComputedLeft(),+ y: yogaChild.getComputedTop(),+ width: yogaChild.getComputedWidth(),+ height: yogaChild.getComputedHeight()+ })+ }if (child.layoutMode !== 'NONE') {- applyYogaLayout(graph, child, yogaChild)+ if (child.layoutMode === 'GRID' && child.visible && child.layoutPositioning !== 'ABSOLUTE') {+ computeLayout(graph, child.id)+ } else if (frame.layoutMode === 'GRID' && child.visible && child.layoutPositioning !== 'ABSOLUTE') {+ recomputeGridChild(graph, child)+ } else {+ applyYogaLayout(graph, child, yogaChild)+ }}}}+function recomputeGridChild(graph: SceneGraph, child: SceneNode): void {+ const updated = graph.getNode(child.id)+ if (!updated || updated.layoutMode === 'NONE') return++ const savedPrimary = updated.primaryAxisSizing+ const savedCounter = updated.counterAxisSizing+ const updates: Partial<SceneNode> = {}++ if (savedPrimary === 'HUG') updates.primaryAxisSizing = 'FIXED'+ if (savedCounter === 'HUG') updates.counterAxisSizing = 'FIXED'+ if (Object.keys(updates).length > 0) graph.updateNode(child.id, updates)++ computeLayout(graph, child.id)++ const restore: Partial<SceneNode> = {}+ if (updates.primaryAxisSizing) restore.primaryAxisSizing = savedPrimary+ if (updates.counterAxisSizing) restore.counterAxisSizing = savedCounter+ if (Object.keys(restore).length > 0) graph.updateNode(child.id, restore)+}+function freeYogaTree(node: YogaNode): void {for (let i = node.getChildCount() - 1; i >= 0; i--) {freeYogaTree(node.getChild(i))@@ -405,3 +567,20 @@ function mapAlign(align: string): Align {return Align.FlexStart}}++function mapAlignSelf(alignSelf: string): Align | null {+ switch (alignSelf) {+ case 'MIN':+ return Align.FlexStart+ case 'CENTER':+ return Align.Center+ case 'MAX':+ return Align.FlexEnd+ case 'STRETCH':+ return Align.Stretch+ case 'BASELINE':+ return Align.Baseline+ default:+ return null+ }+}diff --git a/packages/core/src/render/components.ts b/packages/core/src/render/components.tsindex 7c549e555..d820cad85 100644--- a/packages/core/src/render/components.ts+++ b/packages/core/src/render/components.ts@@ -1,43 +1,52 @@import { node, type BaseProps, type TextProps, type TreeNode } from './tree'-export function Frame(props: BaseProps): TreeNode {- return node('frame', props)+type Child = TreeNode | string++function withChildren(type: string, props: Record<string, unknown>, children: Child[]): TreeNode {+ if (children.length > 0) {+ return node(type, { ...props, children })+ }+ return node(type, props)+}++export function Frame(props: BaseProps, ...children: Child[]): TreeNode {+ return withChildren('frame', props, children)}-export function Text(props: TextProps): TreeNode {- return node('text', props)+export function Text(props: TextProps, ...children: Child[]): TreeNode {+ return withChildren('text', props, children)}-export function Rectangle(props: BaseProps): TreeNode {- return node('rectangle', props)+export function Rectangle(props: BaseProps, ...children: Child[]): TreeNode {+ return withChildren('rectangle', props, children)}-export function Ellipse(props: BaseProps): TreeNode {- return node('ellipse', props)+export function Ellipse(props: BaseProps, ...children: Child[]): TreeNode {+ return withChildren('ellipse', props, children)}-export function Line(props: BaseProps): TreeNode {- return node('line', props)+export function Line(props: BaseProps, ...children: Child[]): TreeNode {+ return withChildren('line', props, children)}-export function Star(props: BaseProps & { points?: number; innerRadius?: number }): TreeNode {- return node('star', props)+export function Star(props: BaseProps & { points?: number; innerRadius?: number }, ...children: Child[]): TreeNode {+ return withChildren('star', props, children)}-export function Polygon(props: BaseProps & { pointCount?: number }): TreeNode {- return node('polygon', props)+export function Polygon(props: BaseProps & { pointCount?: number }, ...children: Child[]): TreeNode {+ return withChildren('polygon', props, children)}-export function Vector(props: BaseProps): TreeNode {- return node('vector', props)+export function Vector(props: BaseProps, ...children: Child[]): TreeNode {+ return withChildren('vector', props, children)}-export function Group(props: BaseProps): TreeNode {- return node('group', props)+export function Group(props: BaseProps, ...children: Child[]): TreeNode {+ return withChildren('group', props, children)}-export function Section(props: BaseProps): TreeNode {- return node('section', props)+export function Section(props: BaseProps, ...children: Child[]): TreeNode {+ return withChildren('section', props, children)}export const View = Framediff --git a/packages/core/src/render/export-jsx.ts b/packages/core/src/render/export-jsx.tsindex d2060b645..5322b8792 100644--- a/packages/core/src/render/export-jsx.ts+++ b/packages/core/src/render/export-jsx.ts@@ -191,7 +191,7 @@ function collectGridSizingProps(node: SceneNode, props: [string, unknown][]): voif (node.gridTemplateRows.length > 0)props.push(['rows', formatTracks(node.gridTemplateRows)])if (node.width > 0) props.push(['w', node.width])- if (node.height > 0) props.push(['h', node.height])+ if (node.gridTemplateRows.length > 0 && node.height > 0) props.push(['h', node.height])if (node.gridColumnGap > 0) props.push(['columnGap', node.gridColumnGap])if (node.gridRowGap > 0) props.push(['rowGap', node.gridRowGap])}@@ -414,7 +414,8 @@ function collectTwGridClasses(node: SceneNode, classes: string[]): void {if (node.gridTemplateRows.length > 0)classes.push(`grid-rows-${gridTemplateTw(node.gridTemplateRows)}`)if (node.width > 0) classes.push(`w-${pxToSpacing(node.width)}`)- if (node.height > 0) classes.push(`h-${pxToSpacing(node.height)}`)+ if (node.gridTemplateRows.length > 0 && node.height > 0)+ classes.push(`h-${pxToSpacing(node.height)}`)if (node.gridColumnGap > 0) classes.push(`gap-x-${pxToSpacing(node.gridColumnGap)}`)if (node.gridRowGap > 0) classes.push(`gap-y-${pxToSpacing(node.gridRowGap)}`)}diff --git a/packages/core/src/render/render-jsx.ts b/packages/core/src/render/render-jsx.tsindex 1f45089f2..309b84770 100644--- a/packages/core/src/render/render-jsx.ts+++ b/packages/core/src/render/render-jsx.ts@@ -20,7 +20,7 @@ export function buildComponent(jsxString: string): () => unknown {`const result = transform(code, {- transforms: ['jsx'],+ transforms: ['typescript', 'jsx'],jsxPragma: 'h',production: true})diff --git a/packages/core/src/render/renderer.ts b/packages/core/src/render/renderer.tsindex 561546555..9701ddd1e 100644--- a/packages/core/src/render/renderer.ts+++ b/packages/core/src/render/renderer.ts@@ -2,7 +2,7 @@ import { parseColor, colorToFill } from '../color'import { TRANSPARENT } from '../constants'import { isTreeNode } from './tree'-import type { SceneGraph, SceneNode, NodeType, LayoutMode, Stroke } from '../scene-graph'+import type { SceneGraph, SceneNode, NodeType, LayoutMode, GridTrack, Stroke } from '../scene-graph'import type { TreeNode } from './tree'const TYPE_MAP: Partial<Record<string, NodeType>> = {@@ -27,7 +27,7 @@ const WEIGHT_MAP: Record<string, number> = {bold: 700}-const ALIGN_MAP: Record<string, 'MIN' | 'MAX' | 'CENTER' | 'SPACE_BETWEEN'> = {+const ALIGN_MAP: Record<string, SceneNode['primaryAxisAlign']> = {start: 'MIN',end: 'MAX',center: 'CENTER',@@ -137,14 +137,17 @@ function applySizeOverrides(const isParentRow = parentLayout === 'HORIZONTAL'const isParentCol = parentLayout === 'VERTICAL'+ const isParentGrid = parentLayout === 'GRID'if (w === 'fill') {- if (isParentRow) o.layoutGrow = 1+ if (isParentGrid) o.layoutAlignSelf = 'STRETCH'+ else if (isParentRow) o.layoutGrow = 1else if (isParentCol) o.layoutAlignSelf = 'STRETCH'else { o.layoutGrow = 1; o.layoutAlignSelf = 'STRETCH' }}if (h === 'fill') {- if (isParentCol) o.layoutGrow = 1+ if (isParentGrid) o.layoutAlignSelf = 'STRETCH'+ else if (isParentCol) o.layoutGrow = 1else if (isParentRow) o.layoutAlignSelf = 'STRETCH'else o.layoutAlignSelf = 'STRETCH'}@@ -152,6 +155,12 @@ function applySizeOverrides(if (props.x !== undefined) o.x = props.x as numberif (props.y !== undefined) o.y = props.y as number+ const hasExplicitPosition = props.x !== undefined || props.y !== undefined+ const isInsideAutoLayout = parentLayout !== 'NONE'+ if (hasExplicitPosition && isInsideAutoLayout) {+ o.layoutPositioning = 'ABSOLUTE'+ }+return { w, h }}@@ -217,11 +226,81 @@ function applyPaddingOverrides(props: Record<string, unknown>, o: Partial<SceneN}const PADDING_KEYS = ['p', 'padding', 'px', 'py', 'pt', 'pr', 'pb', 'pl'] as const+const AUTO_LAYOUT_TRIGGER_KEYS = [...PADDING_KEYS, 'justify', 'items'] as constfunction hasPaddingProps(props: Record<string, unknown>): boolean {return PADDING_KEYS.some((k) => props[k] !== undefined)}+function hasAutoLayoutTriggerProps(props: Record<string, unknown>): boolean {+ return AUTO_LAYOUT_TRIGGER_KEYS.some((k) => props[k] !== undefined)+}++function parseTrack(token: string): GridTrack {+ if (token.endsWith('fr')) {+ return { sizing: 'FR', value: parseFloat(token) || 1 }+ }+ if (token === 'auto') {+ return { sizing: 'AUTO', value: 0 }+ }+ return { sizing: 'FIXED', value: parseFloat(token) || 0 }+}++function parseTrackList(value: string): GridTrack[] {+ return value.trim().split(/\s+/).map(parseTrack)+}++function applyGridOverrides(+ props: Record<string, unknown>,+ o: Partial<SceneNode>,+ w: unknown,+ h: unknown+): void {+ o.layoutMode = 'GRID'++ if (typeof w === 'number') o.width = w+ if (typeof h === 'number') o.height = h++ if (typeof props.columns === 'string') {+ o.gridTemplateColumns = parseTrackList(props.columns)+ } else if (typeof props.columns === 'number') {+ o.gridTemplateColumns = Array.from({ length: props.columns }, () => ({ sizing: 'FR' as const, value: 1 }))+ }++ if (typeof props.rows === 'string') {+ o.gridTemplateRows = parseTrackList(props.rows)+ } else if (typeof props.rows === 'number') {+ o.gridTemplateRows = Array.from({ length: props.rows }, () => ({ sizing: 'FR' as const, value: 1 }))+ }++ if (typeof props.columnGap === 'number') o.gridColumnGap = props.columnGap+ if (typeof props.rowGap === 'number') o.gridRowGap = props.rowGap+ if (typeof props.gap === 'number') {+ o.gridColumnGap = props.gap+ o.gridRowGap = props.gap+ }++ if (props.rows === undefined && typeof h !== 'number') {+ o.height = 0+ }+}++function applyGridChildOverrides(props: Record<string, unknown>, o: Partial<SceneNode>): void {+ const col = props.colStart ?? props.col+ const row = props.rowStart ?? props.row+ const colSpan = (props.colSpan as number | undefined) ?? 1+ const rowSpan = (props.rowSpan as number | undefined) ?? 1++ if (col !== undefined || row !== undefined) {+ o.gridPosition = {+ column: (col as number | undefined) ?? 0,+ row: (row as number | undefined) ?? 0,+ columnSpan: colSpan,+ rowSpan: rowSpan+ }+ }+}+function applyAutoLayoutSizing(o: Partial<SceneNode>,props: Record<string, unknown>,@@ -249,9 +328,21 @@ function applyLayoutOverrides(o: Partial<SceneNode>,w: unknown,h: unknown,- isText: boolean+ isText: boolean,+ parentLayout: SceneNode['layoutMode']): void {- const needsAutoLayout = props.flex !== undefined || (!isText && hasPaddingProps(props))+ if (props.grid) {+ applyGridOverrides(props, o, w, h)+ applyPaddingOverrides(props, o)+ if (props.grow !== undefined) o.layoutGrow = props.grow as number+ return+ }++ if (parentLayout === 'GRID') {+ applyGridChildOverrides(props, o)+ }++ const needsAutoLayout = props.flex !== undefined || (!isText && hasAutoLayoutTriggerProps(props))if (needsAutoLayout) {applyAutoLayoutSizing(o, props, w, h)@@ -279,7 +370,11 @@ function applyLayoutOverrides(if (props.maxW !== undefined) o.width = Math.min(o.width ?? Infinity, props.maxW as number)}-function applyTextOverrides(props: Record<string, unknown>, o: Partial<SceneNode>): void {+function applyTextOverrides(+ props: Record<string, unknown>,+ o: Partial<SceneNode>,+ parentLayout: SceneNode['layoutMode']+): void {const fontSize = props.size ?? props.fontSizeif (typeof fontSize === 'number') o.fontSize = fontSize@@ -301,11 +396,17 @@ function applyTextOverrides(props: Record<string, unknown>, o: Partial<SceneNodeo.textAlignHorizontal = TEXT_ALIGN_MAP[props.textAlign as string] ?? 'LEFT'}- const hasExplicitWidth = (props.w ?? props.width) !== undefined+ const w = props.w ?? props.width+ const hasExplicitWidth = w !== undefined+ const fillsParent = w === 'fill' || (props.grow as number) > 0+ const isInsideAutoLayout = parentLayout !== 'NONE'+if (props.textAutoResize) {o.textAutoResize = TEXT_AUTO_RESIZE_MAP[props.textAutoResize as string] ?? 'NONE'+ } else if (hasExplicitWidth || (isInsideAutoLayout && fillsParent)) {+ o.textAutoResize = 'HEIGHT'} else {- o.textAutoResize = hasExplicitWidth ? 'HEIGHT' : 'WIDTH_AND_HEIGHT'+ o.textAutoResize = 'WIDTH_AND_HEIGHT'}}@@ -358,8 +459,8 @@ function propsToOverrides(const { w, h } = applySizeOverrides(props, o, parentLayout)applyVisualOverrides(props, o)- applyLayoutOverrides(props, o, w, h, isText)- if (isText) applyTextOverrides(props, o)+ applyLayoutOverrides(props, o, w, h, isText, parentLayout)+ if (isText) applyTextOverrides(props, o, parentLayout)applyShapeAndEffectOverrides(props, o)return odiff --git a/packages/core/src/renderer/renderer.ts b/packages/core/src/renderer/renderer.tsindex 22ea6c24b..ac0f903ba 100644--- a/packages/core/src/renderer/renderer.ts+++ b/packages/core/src/renderer/renderer.ts@@ -750,12 +750,18 @@ export class SkiaRenderer {}}- measureTextNode(node: SceneNode): { width: number; height: number } | null {+ measureTextNode(node: SceneNode, maxWidth?: number): { width: number; height: number } | null {if (!this.fontsLoaded || !this.fontProvider || !this.isNodeFontLoaded(node)) return nullif (node.type !== 'TEXT' || !node.text) return nullconst paragraph = this.buildParagraph(node)- paragraph.layout(node.textAutoResize === 'WIDTH_AND_HEIGHT' ? 1e6 : node.width || 1e6)+ const layoutWidth =+ maxWidth !== undefined+ ? maxWidth+ : (node.textAutoResize === 'WIDTH_AND_HEIGHT'+ ? 1e6+ : node.width || 1e6)+ paragraph.layout(layoutWidth)const width = paragraph.getLongestLine()const height = paragraph.getHeight()paragraph.delete()diff --git a/packages/core/src/scene-graph.ts b/packages/core/src/scene-graph.tsindex a7826d923..30289842b 100644--- a/packages/core/src/scene-graph.ts+++ b/packages/core/src/scene-graph.ts@@ -188,6 +188,7 @@ export interface GridPosition {}export type LayoutAlign = 'MIN' | 'CENTER' | 'MAX' | 'SPACE_BETWEEN'export type LayoutCounterAlign = 'MIN' | 'CENTER' | 'MAX' | 'STRETCH' | 'BASELINE'+export type LayoutAlignSelf = 'AUTO' | 'MIN' | 'CENTER' | 'MAX' | 'STRETCH' | 'BASELINE'export type LayoutWrap = 'NO_WRAP' | 'WRAP'export interface SceneNode {@@ -255,7 +256,7 @@ export interface SceneNode {layoutPositioning: 'AUTO' | 'ABSOLUTE'layoutGrow: number- layoutAlignSelf: 'AUTO' | 'STRETCH'+ layoutAlignSelf: LayoutAlignSelfvectorNetwork: VectorNetwork | nullfillGeometry: GeometryPath[]diff --git a/packages/core/src/tools/modify.ts b/packages/core/src/tools/modify.tsindex baddc5f46..06b0f7c91 100644--- a/packages/core/src/tools/modify.ts+++ b/packages/core/src/tools/modify.ts@@ -581,8 +581,8 @@ export const setLayoutChild = defineTool({grow: { type: 'number', description: 'Flex grow factor (0 = fixed, 1 = grow)', min: 0 },align_self: {type: 'string',- description: 'Self alignment override',- enum: ['INHERIT', 'STRETCH']+ description: 'Self alignment override (cross-axis)',+ enum: ['INHERIT', 'MIN', 'CENTER', 'MAX', 'STRETCH', 'BASELINE']},positioning: {type: 'string',diff --git a/src/components/chat/ChatInput.vue b/src/components/chat/ChatInput.vueindex 9621d8139..68a5c0e5b 100644--- a/src/components/chat/ChatInput.vue+++ b/src/components/chat/ChatInput.vue@@ -122,6 +122,9 @@ function handleSubmit(e: Event) {placeholder="Describe a change…":class="uiInput({ class: 'min-w-0 flex-1 placeholder:text-muted' })":disabled="status === 'submitted'"+ @paste.stop+ @copy.stop+ @cut.stop/><TooltipRoot v-if="isStreaming"><TooltipTrigger as-child>diff --git a/src/components/chat/ProviderSettings.vue b/src/components/chat/ProviderSettings.vueindex 085cfb781..e7b01ace8 100644--- a/src/components/chat/ProviderSettings.vue+++ b/src/components/chat/ProviderSettings.vue@@ -8,11 +8,7 @@ import {TabsContent,TabsList,TabsRoot,- TabsTrigger,- TooltipContent,- TooltipPortal,- TooltipRoot,- TooltipTrigger+ TabsTrigger} from 'reka-ui'import { ref, watch } from 'vue'@@ -20,8 +16,16 @@ import ProviderSelect from '@/components/chat/ProviderSelect.vue'import { uiInput } from '@/components/ui/input'import { useAIChat } from '@/composables/use-chat'-const { providerID, providerDef, apiKey, setAPIKey, customBaseURL, customModelID, customAPIType } =- useAIChat()+const {+ providerID,+ providerDef,+ apiKey,+ setAPIKey,+ customBaseURL,+ customModelID,+ customAPIType,+ maxOutputTokens+} = useAIChat()const keyInput = ref('')const baseURLInput = ref(customBaseURL.value)@@ -58,32 +62,22 @@ function clearKey() {<template><PopoverRoot>- <TooltipRoot>- <TooltipTrigger as-child>- <PopoverTrigger- data-test-id="provider-settings-trigger"- class="rounded p-0.5 text-muted hover:bg-hover hover:text-surface"- >- <icon-lucide-settings class="size-3" />- </PopoverTrigger>- </TooltipTrigger>- <TooltipPortal>- <TooltipContent- side="top"- :side-offset="4"- class="rounded bg-surface px-2 py-1 text-[10px] text-canvas"- >- Provider settings- </TooltipContent>- </TooltipPortal>- </TooltipRoot>+ <PopoverTrigger+ data-test-id="provider-settings-trigger"+ class="rounded p-0.5 text-muted hover:bg-hover hover:text-surface"+ title="Provider settings"+ >+ <icon-lucide-settings class="size-3" />+ </PopoverTrigger><PopoverPortal><PopoverContentside="top":side-offset="8"align="end"- class="z-50 w-64 rounded-lg border border-border bg-panel p-3 shadow-lg"+ :collision-padding="16"+ :avoid-collisions="true"+ class="isolate z-[51] w-64 rounded-lg border border-border bg-panel p-3 shadow-lg"@interact-outside="save"><div class="flex flex-col gap-2.5">@@ -150,6 +144,20 @@ function clearKey() {</TabsRoot></div>+ <!-- Max output tokens -->+ <div class="flex flex-col gap-1">+ <label class="text-[10px] text-muted">Max output tokens</label>+ <input+ v-model.number="maxOutputTokens"+ type="number"+ data-test-id="provider-settings-max-tokens"+ :min="1024"+ :max="128000"+ :step="1024"+ :class="uiInput({ size: 'sm' })"+ />+ </div>+<!-- API key --><div class="flex flex-col gap-1"><div class="flex items-center justify-between">diff --git a/src/composables/use-chat.ts b/src/composables/use-chat.tsindex 85ce3e790..c00623e60 100644--- a/src/composables/use-chat.ts+++ b/src/composables/use-chat.ts@@ -79,9 +79,10 @@ const SYSTEM_PROMPT = dedent`### Flex layout- flex="row"|"col" — enables auto-layout. Without this, children use absolute x/y.- gap={number}, wrap, rowGap={number}- - justify="start"|"end"|"center"|"between" (⚠ "between", NOT "space-between")+ - justify="start"|"end"|"center"|"between"|"evenly" (⚠ "between", NOT "space-between")- items="start"|"end"|"center"|"stretch"- p, px, py, pt, pr, pb, pl={number} — padding (auto-enables flex="col" if no flex set)+ ⚠ justify/items ONLY work with flex! Always set flex="row" or flex="col" when using justify or items.### Grid layout- grid, columns="1fr 1fr 1fr", rows="1fr 1fr"@@ -103,10 +104,21 @@ const SYSTEM_PROMPT = dedent`**Row with spacer:** \`<Frame flex="row" w={380} items="center"><Text>Title</Text><Frame grow={1} /><Text>Action</Text></Frame>\`**Grow children:** Inner flex="row" MUST have w="fill" so grow children can divide space.+ ## Size limits+ ⚠ Keep each \`render\` call under ~40 elements. For complex designs, split into multiple calls:+ 1. Render the outer container first (with parent_id of the page)+ 2. Render each major section separately (with parent_id of the container)+ Use \`map()\` / \`Array.from()\` for repeated items — never duplicate JSX manually.+## Forbidden patterns- ❌ style={{...}}, className, CSS properties- ❌ w/h on Text, justify="space-between", "red"/"rgb(...)" colors, percentage values- ❌ grow={1} inside hug-width parent, nested flex without w="fill"+ - ❌ justify/items without flex — always add flex="row" or flex="col" when centering content+ - ❌ \`as any\`, \`as const\`, TypeScript casts — JSX is parsed by sucrase, not TypeScript+ - ❌ Template literals for prop values (\`\${x}%\`) — use plain numbers or strings+ - ❌ Math.random() — use deterministic values+ - ❌ Giant single render calls (>40 elements) — split into sections## Color contrast rules- Subtle backgrounds on dark bg: at least #FFFFFF30 alpha (~19%)@@ -116,15 +128,15 @@ const SYSTEM_PROMPT = dedent`## Workflow: always verify after render- After every \`render\` call, call \`export_image\` to visually verify.- ⚠ Export ONE node at a time. Be extremely critical: check text clipping, spacing, alignment, contrast, overflow.- Fix any issues immediately, then re-export.+ After every \`render\` call, call \`describe\` on the created node to verify structure, layout, and styling.+ Be critical: check for missing props, wrong hierarchy, contrast issues.+ Fix any issues immediately, then re-describe.# Reading designs- - \`export_image\`: renders to PNG for visual inspection+ - \`describe\`: semantic description with role, style, layout, and design issues — preferred for verification- \`get_jsx\`: JSX representation (same format as render)- - \`describe\`: semantic description with role, style, layout, and design issues- \`diff_jsx\`: unified diff between two nodes+ ⚠ Do NOT use \`export_image\` — it is expensive and slow. Use \`describe\` to verify designs instead.`const providerID = useLocalStorage<AIProviderID>(@@ -140,6 +152,7 @@ const customAPIType = useLocalStorage<'completions' | 'responses'>(`${STORAGE_PREFIX}ai-api-type`,'completions')+const maxOutputTokens = useLocalStorage(`${STORAGE_PREFIX}ai-max-output-tokens`, 16384)const activeTab = ref<'design' | 'ai'>('design')const providerDef = computed(@@ -235,7 +248,9 @@ function createTransport() {const agent = new ToolLoopAgent({model: createModel(),instructions: SYSTEM_PROMPT,- tools+ tools,+ maxOutputTokens: maxOutputTokens.value,+ prepareCall: (options) => ({ ...options, maxOutputTokens: maxOutputTokens.value })})return new DirectChatTransport({ agent })@@ -271,6 +286,7 @@ export function useAIChat() {customBaseURL,customModelID,customAPIType,+ maxOutputTokens,activeTab,isConfigured,ensureChat,diff --git a/src/stores/editor.ts b/src/stores/editor.tsindex 224301ee5..1e803a178 100644--- a/src/stores/editor.ts+++ b/src/stores/editor.ts@@ -431,7 +431,6 @@ export function createEditorStore() {}}})-}function reorderChildWithUndo(nodeId: string, newParentId: string, insertIndex: number) {@@ -460,7 +459,6 @@ export function createEditorStore() {if (origParentId !== newParentId) runLayoutForNode(newParentId)}})-}function reparentNodes(nodeIds: string[], newParentId: string) {@@ -686,7 +684,7 @@ export function createEditorStore() {_ck = ck_renderer = renderer_textEditor = new TextEditor(ck)- setTextMeasurer((node) => renderer.measureTextNode(node))+ setTextMeasurer((node, maxWidth) => renderer.measureTextNode(node, maxWidth))}function buildFigFile() {diff --git a/tests/engine/layout.test.ts b/tests/engine/layout.test.tsindex 1d3bc7024..7c681044a 100644--- a/tests/engine/layout.test.ts+++ b/tests/engine/layout.test.ts@@ -469,7 +469,7 @@ describe('Auto Layout', () => {})describe('hidden children', () => {- test('hidden children collapse to zero size in auto layout', () => {+ test('hidden children preserve original size but collapse in layout', () => {const graph = new SceneGraph()const frame = autoFrame(graph, pageId(graph), {width: 300,@@ -483,12 +483,12 @@ describe('Auto Layout', () => {computeLayout(graph, frame.id)const children = graph.getChildren(frame.id)- expect(children[0].width).toBe(0)- expect(children[0].height).toBe(0)+ expect(children[0].width).toBe(50)+ expect(children[0].height).toBe(50)expect(children[1].x).toBe(0)expect(children[1].width).toBe(80)- expect(children[2].width).toBe(0)- expect(children[2].height).toBe(0)+ expect(children[2].width).toBe(50)+ expect(children[2].height).toBe(50)})test('hidden children do not consume spacing', () => {@@ -525,7 +525,7 @@ describe('Auto Layout', () => {expect(f.height).toBe(30)})- test('hidden nested auto-layout children collapse', () => {+ test('hidden nested auto-layout children preserve size but collapse in layout', () => {const graph = new SceneGraph()const outer = autoFrame(graph, pageId(graph), {width: 300,@@ -546,8 +546,8 @@ describe('Auto Layout', () => {const children = graph.getChildren(outer.id)const innerNode = graph.getNode(inner.id)!- expect(innerNode.width).toBe(0)- expect(innerNode.height).toBe(0)+ expect(innerNode.width).toBe(50)+ expect(innerNode.height).toBe(50)expect(children[1].x).toBe(0)})})@@ -1047,6 +1047,452 @@ describe('Auto Layout', () => {const updatedText = graph.getNode(text.id)!expect(updatedText.width).toBe(200)})++ test('HEIGHT auto-resize text wraps via MeasureFunc when filling parent', () => {+ const graph = new SceneGraph()+ const pid = pageId(graph)++ const frame = autoFrame(graph, pid, {+ width: 300,+ height: 200,+ layoutMode: 'VERTICAL',+ primaryAxisSizing: 'FIXED',+ counterAxisSizing: 'FIXED',+ })++ const text = graph.createNode('TEXT', frame.id, {+ width: 300,+ height: 20,+ text: 'Long text that should wrap within the available width',+ fontSize: 14,+ textAutoResize: 'HEIGHT' as const,+ })++ setTextMeasurer((_node, maxWidth) => {+ const w = maxWidth ?? 1e6+ if (w >= 300) return { width: 300, height: 20 }+ return { width: w, height: 60 }+ })++ computeAllLayouts(graph)+ setTextMeasurer(null)++ const updatedText = graph.getNode(text.id)!+ expect(updatedText.width).toBe(300)+ expect(updatedText.height).toBe(20)+ })++ test('MeasureFunc receives constraint width from flex layout', () => {+ const graph = new SceneGraph()+ const pid = pageId(graph)++ const frame = autoFrame(graph, pid, {+ width: 400,+ height: 200,+ layoutMode: 'HORIZONTAL',+ primaryAxisSizing: 'FIXED',+ counterAxisSizing: 'FIXED',+ itemSpacing: 10,+ })++ rect(graph, frame.id, 100, 50)++ const text = graph.createNode('TEXT', frame.id, {+ width: 500,+ height: 20,+ text: 'Wide text',+ fontSize: 14,+ textAutoResize: 'WIDTH_AND_HEIGHT' as const,+ layoutGrow: 1,+ })++ const receivedWidths: number[] = []+ setTextMeasurer((_node, maxWidth) => {+ if (maxWidth !== undefined) receivedWidths.push(Math.round(maxWidth))+ const w = maxWidth ?? 500+ return { width: Math.min(200, w), height: w < 200 ? 40 : 20 }+ })++ computeAllLayouts(graph)+ setTextMeasurer(null)++ // 400 - 100 - 10 = 290 available for the fill text+ expect(receivedWidths.length).toBeGreaterThan(0)+ const updatedText = graph.getNode(text.id)!+ expect(updatedText.width).toBe(290)+ })++ test('textAutoResize NONE skips MeasureFunc', () => {+ const graph = new SceneGraph()+ const pid = pageId(graph)++ const frame = autoFrame(graph, pid, {+ width: 300,+ height: 100,+ layoutMode: 'HORIZONTAL',+ primaryAxisSizing: 'FIXED',+ counterAxisSizing: 'FIXED',+ })++ const text = graph.createNode('TEXT', frame.id, {+ width: 150,+ height: 40,+ text: 'Fixed text',+ fontSize: 14,+ textAutoResize: 'NONE' as const,+ })++ let measureCalled = false+ setTextMeasurer(() => {+ measureCalled = true+ return { width: 80, height: 20 }+ })++ computeAllLayouts(graph)+ setTextMeasurer(null)++ expect(measureCalled).toBe(false)+ const updatedText = graph.getNode(text.id)!+ expect(updatedText.width).toBe(150)+ expect(updatedText.height).toBe(40)+ })+ })++ describe('min/max constraints', () => {+ test('maxWidth clamps child in horizontal layout', () => {+ const graph = new SceneGraph()+ const frame = autoFrame(graph, pageId(graph), {+ width: 400,+ height: 100,+ })+ rect(graph, frame.id, 50, 50, { layoutGrow: 1, maxWidth: 200 })++ computeLayout(graph, frame.id)++ const child = graph.getChildren(frame.id)[0]+ expect(child.width).toBe(200)+ })++ test('minWidth prevents shrinking below minimum', () => {+ const graph = new SceneGraph()+ const frame = autoFrame(graph, pageId(graph), {+ width: 100,+ height: 100,+ })+ rect(graph, frame.id, 200, 50, { minWidth: 150 })++ computeLayout(graph, frame.id)++ const child = graph.getChildren(frame.id)[0]+ expect(child.width).toBeGreaterThanOrEqual(150)+ })++ test('maxHeight clamps child in vertical layout', () => {+ const graph = new SceneGraph()+ const frame = autoFrame(graph, pageId(graph), {+ layoutMode: 'VERTICAL',+ width: 200,+ height: 400,+ })+ rect(graph, frame.id, 50, 50, { layoutGrow: 1, maxHeight: 150 })++ computeLayout(graph, frame.id)++ const child = graph.getChildren(frame.id)[0]+ expect(child.height).toBe(150)+ })++ test('minHeight enforces minimum in vertical layout', () => {+ const graph = new SceneGraph()+ const frame = autoFrame(graph, pageId(graph), {+ layoutMode: 'VERTICAL',+ width: 200,+ height: 400,+ })+ rect(graph, frame.id, 50, 30, { minHeight: 80 })++ computeLayout(graph, frame.id)++ const child = graph.getChildren(frame.id)[0]+ expect(child.height).toBe(80)+ })++ test('min/max on nested auto-layout frame', () => {+ const graph = new SceneGraph()+ const outer = autoFrame(graph, pageId(graph), {+ width: 500,+ height: 200,+ })+ const inner = autoFrame(graph, outer.id, {+ primaryAxisSizing: 'FIXED',+ counterAxisSizing: 'FIXED',+ width: 50,+ height: 50,+ layoutGrow: 1,+ maxWidth: 250,+ })+ rect(graph, inner.id, 30, 30)++ computeLayout(graph, outer.id)++ const innerNode = graph.getNode(inner.id)!+ expect(innerNode.width).toBe(250)+ })+ })++ describe('counterAxisAlignContent', () => {+ test('SPACE_BETWEEN distributes wrapped rows evenly', () => {+ const graph = new SceneGraph()+ const frame = autoFrame(graph, pageId(graph), {+ width: 200,+ height: 300,+ layoutWrap: 'WRAP',+ counterAxisAlignContent: 'SPACE_BETWEEN' as const,+ })+ rect(graph, frame.id, 120, 40)+ rect(graph, frame.id, 120, 40)+ rect(graph, frame.id, 120, 40)++ computeLayout(graph, frame.id)++ const children = graph.getChildren(frame.id)+ // 3 rows of 40px each = 120px total, 300 - 120 = 180px free space+ // SPACE_BETWEEN: first row at 0, last row at 260+ expect(children[0].y).toBe(0)+ expect(children[2].y).toBe(260)+ // Middle row centered: (0 + 260) / 2 = 130+ expect(children[1].y).toBe(130)+ })++ test('AUTO (default) packs wrapped rows at start', () => {+ const graph = new SceneGraph()+ const frame = autoFrame(graph, pageId(graph), {+ width: 200,+ height: 300,+ layoutWrap: 'WRAP',+ })+ rect(graph, frame.id, 120, 40)+ rect(graph, frame.id, 120, 40)+ rect(graph, frame.id, 120, 40)++ computeLayout(graph, frame.id)++ const children = graph.getChildren(frame.id)+ expect(children[0].y).toBe(0)+ expect(children[1].y).toBe(40)+ expect(children[2].y).toBe(80)+ })+ })++ describe('layoutAlignSelf extended values', () => {+ test('layoutAlignSelf CENTER positions child at cross-axis center', () => {+ const graph = new SceneGraph()+ const frame = autoFrame(graph, pageId(graph), {+ width: 400,+ height: 200,+ counterAxisAlign: 'MIN',+ })+ rect(graph, frame.id, 50, 50, { layoutAlignSelf: 'CENTER' as const })+ rect(graph, frame.id, 50, 50)++ computeLayout(graph, frame.id)++ const children = graph.getChildren(frame.id)+ expect(children[0].y).toBe(75)+ expect(children[1].y).toBe(0)+ })++ test('layoutAlignSelf MAX positions child at cross-axis end', () => {+ const graph = new SceneGraph()+ const frame = autoFrame(graph, pageId(graph), {+ width: 400,+ height: 200,+ counterAxisAlign: 'MIN',+ })+ rect(graph, frame.id, 50, 50, { layoutAlignSelf: 'MAX' as const })+ rect(graph, frame.id, 50, 50)++ computeLayout(graph, frame.id)++ const children = graph.getChildren(frame.id)+ expect(children[0].y).toBe(150)+ expect(children[1].y).toBe(0)+ })++ test('layoutAlignSelf MIN overrides parent STRETCH', () => {+ const graph = new SceneGraph()+ const frame = autoFrame(graph, pageId(graph), {+ width: 400,+ height: 200,+ counterAxisAlign: 'STRETCH',+ })+ rect(graph, frame.id, 50, 50, { layoutAlignSelf: 'MIN' as const })+ rect(graph, frame.id, 50, 50)++ computeLayout(graph, frame.id)++ const children = graph.getChildren(frame.id)+ expect(children[0].y).toBe(0)+ expect(children[0].height).toBe(50)+ expect(children[1].height).toBe(200)+ })++ test('layoutAlignSelf in vertical layout', () => {+ const graph = new SceneGraph()+ const frame = autoFrame(graph, pageId(graph), {+ layoutMode: 'VERTICAL',+ width: 300,+ height: 400,+ counterAxisAlign: 'MIN',+ })+ rect(graph, frame.id, 50, 50, { layoutAlignSelf: 'CENTER' as const })+ rect(graph, frame.id, 50, 50, { layoutAlignSelf: 'MAX' as const })++ computeLayout(graph, frame.id)++ const children = graph.getChildren(frame.id)+ expect(children[0].x).toBe(125)+ expect(children[1].x).toBe(250)+ })+ })++ describe('FILL flexBasis', () => {+ test('FILL children with different content sizes get equal width', () => {+ const graph = new SceneGraph()+ const frame = autoFrame(graph, pageId(graph), {+ width: 400,+ height: 100,+ })++ const inner1 = autoFrame(graph, frame.id, {+ primaryAxisSizing: 'FIXED',+ counterAxisSizing: 'FIXED',+ width: 100,+ height: 50,+ layoutGrow: 1,+ })+ rect(graph, inner1.id, 100, 50)++ const inner2 = autoFrame(graph, frame.id, {+ primaryAxisSizing: 'FIXED',+ counterAxisSizing: 'FIXED',+ width: 200,+ height: 50,+ layoutGrow: 1,+ })+ rect(graph, inner2.id, 200, 50)++ computeLayout(graph, frame.id)++ const children = graph.getChildren(frame.id)+ expect(children[0].width).toBe(200)+ expect(children[1].width).toBe(200)+ })++ test('nested FILL children distribute from zero basis', () => {+ const graph = new SceneGraph()+ const frame = autoFrame(graph, pageId(graph), {+ width: 300,+ height: 100,+ itemSpacing: 0,+ })+ autoFrame(graph, frame.id, {+ primaryAxisSizing: 'FILL' as const,+ counterAxisSizing: 'FIXED',+ width: 50,+ height: 100,+ })+ autoFrame(graph, frame.id, {+ primaryAxisSizing: 'FILL' as const,+ counterAxisSizing: 'FIXED',+ width: 50,+ height: 100,+ })+ autoFrame(graph, frame.id, {+ primaryAxisSizing: 'FILL' as const,+ counterAxisSizing: 'FIXED',+ width: 50,+ height: 100,+ })++ computeLayout(graph, frame.id)++ const children = graph.getChildren(frame.id)+ expect(children[0].width).toBe(100)+ expect(children[1].width).toBe(100)+ expect(children[2].width).toBe(100)+ })+ })++ describe('hidden children preserve dimensions', () => {+ test('re-showing a hidden child restores original size', () => {+ const graph = new SceneGraph()+ const frame = autoFrame(graph, pageId(graph), {+ width: 300,+ height: 100,+ })+ const child = rect(graph, frame.id, 80, 60)++ computeLayout(graph, frame.id)+ expect(graph.getNode(child.id)!.width).toBe(80)++ graph.updateNode(child.id, { visible: false })+ computeLayout(graph, frame.id)+ expect(graph.getNode(child.id)!.width).toBe(80)+ expect(graph.getNode(child.id)!.height).toBe(60)++ graph.updateNode(child.id, { visible: true })+ computeLayout(graph, frame.id)+ expect(graph.getNode(child.id)!.width).toBe(80)+ expect(graph.getNode(child.id)!.height).toBe(60)+ })+ })++ describe('absolute children in Yoga tree', () => {+ test('absolute children do not affect auto-layout flow', () => {+ const graph = new SceneGraph()+ const frame = autoFrame(graph, pageId(graph), {+ width: 400,+ height: 200,+ primaryAxisSizing: 'HUG',+ counterAxisSizing: 'HUG',+ })+ rect(graph, frame.id, 50, 50)+ rect(graph, frame.id, 100, 100, { layoutPositioning: 'ABSOLUTE', x: 300, y: 150 })+ rect(graph, frame.id, 50, 50)++ computeLayout(graph, frame.id)++ const f = graph.getNode(frame.id)!+ expect(f.width).toBe(100)++ const children = graph.getChildren(frame.id)+ expect(children[0].x).toBe(0)+ expect(children[2].x).toBe(50)++ expect(children[1].x).toBe(300)+ expect(children[1].y).toBe(150)+ })++ test('absolute children preserve position when parent resizes', () => {+ const graph = new SceneGraph()+ const frame = autoFrame(graph, pageId(graph), {+ width: 400,+ height: 200,+ itemSpacing: 10,+ })+ rect(graph, frame.id, 50, 50)+ rect(graph, frame.id, 80, 40, { layoutPositioning: 'ABSOLUTE', x: 200, y: 100 })++ computeLayout(graph, frame.id)++ const children = graph.getChildren(frame.id)+ expect(children[0].x).toBe(0)+ expect(children[1].x).toBe(200)+ expect(children[1].y).toBe(100)+ expect(children[1].width).toBe(80)+ expect(children[1].height).toBe(40)+ })})})@@ -1307,7 +1753,7 @@ describe('Grid Layout', () => {})describe('hidden children', () => {- test('hidden children collapse in grid', () => {+ test('hidden children preserve size in grid', () => {const graph = new SceneGraph()const frame = gridFrame(graph, pageId(graph), [fr(), fr()], [fr()])rect(graph, frame.id, 50, 50, { visible: false })@@ -1316,8 +1762,8 @@ describe('Grid Layout', () => {computeLayout(graph, frame.id)const children = graph.getChildren(frame.id)- expect(children[0].width).toBe(0)- expect(children[0].height).toBe(0)+ expect(children[0].width).toBe(50)+ expect(children[0].height).toBe(50)})})@@ -1408,4 +1854,38 @@ describe('Grid Layout', () => {expect(outerChildren[1].y).toBe(110)})})++ describe('grid stretch sizing', () => {+ test('STRETCH child fills grid cell', () => {+ const graph = new SceneGraph()+ const frame = gridFrame(graph, pageId(graph), [fr(), fr()], [fr()], {+ width: 300,+ height: 100,+ })+ rect(graph, frame.id, 50, 50, { layoutAlignSelf: 'STRETCH' as const })+ rect(graph, frame.id, 50, 50)++ computeLayout(graph, frame.id)++ const children = graph.getChildren(frame.id)+ expect(children[0].width).toBe(150)+ expect(children[0].height).toBe(100)+ })++ test('layoutGrow child fills grid cell', () => {+ const graph = new SceneGraph()+ const frame = gridFrame(graph, pageId(graph), [fr(), fr()], [fr()], {+ width: 400,+ height: 200,+ })+ rect(graph, frame.id, 50, 50, { layoutGrow: 1 })+ rect(graph, frame.id, 50, 50)++ computeLayout(graph, frame.id)++ const children = graph.getChildren(frame.id)+ expect(children[0].width).toBe(200)+ expect(children[0].height).toBe(200)+ })+ })})diff --git a/tests/engine/render.test.ts b/tests/engine/render.test.tsindex d1f8840c9..2a14ce0fe 100644--- a/tests/engine/render.test.ts+++ b/tests/engine/render.test.ts@@ -5,6 +5,8 @@ import {renderTree,renderJSX,renderTreeNode,+ computeLayout,+ computeAllLayouts,Frame,Text,Rectangle,@@ -168,6 +170,20 @@ describe('renderTree', () => {expect(node.layoutWrap).toBe('WRAP')})+ it('justify/items without flex auto-enables auto-layout', () => {+ const g = createGraph()+ const tree = Frame(+ { name: 'IconBtn', w: 36, h: 36, justify: 'center', items: 'center' },+ Text({ size: 16, color: '#FFFFFF', children: '★' })+ )+ const result = renderTree(g, tree)+ const n = g.nodes.get(result.id)!++ expect(n.layoutMode).toBe('VERTICAL')+ expect(n.primaryAxisAlign).toBe('CENTER')+ expect(n.counterAxisAlign).toBe('CENTER')+ })+it('handles padding shorthands', () => {const g = createGraph()const tree = Frame({ name: 'Padded', px: 16, py: 8, pt: 4 })@@ -355,3 +371,298 @@ describe('renderJSX (string → scene graph)', () => {expect(node.y).toBe(200)})})++describe('grid layout rendering', () => {+ it('creates grid frame with template columns', () => {+ const g = createGraph()+ const tree = Frame({ name: 'Grid', w: 300, h: 200, grid: true, columns: '1fr 1fr 1fr' },+ Rectangle({ name: 'A', w: 50, h: 50 }),+ Rectangle({ name: 'B', w: 50, h: 50 }),+ Rectangle({ name: 'C', w: 50, h: 50 })+ )+ const result = renderTree(g, tree)+ const frame = g.nodes.get(result.id)!++ expect(frame.layoutMode).toBe('GRID')+ expect(frame.gridTemplateColumns).toEqual([+ { sizing: 'FR', value: 1 },+ { sizing: 'FR', value: 1 },+ { sizing: 'FR', value: 1 }+ ])+ })++ it('creates grid frame with mixed track sizes', () => {+ const g = createGraph()+ const tree = Frame({ name: 'Grid', w: 400, h: 200, grid: true, columns: '100 1fr 2fr' })+ const result = renderTree(g, tree)+ const frame = g.nodes.get(result.id)!++ expect(frame.gridTemplateColumns).toEqual([+ { sizing: 'FIXED', value: 100 },+ { sizing: 'FR', value: 1 },+ { sizing: 'FR', value: 2 }+ ])+ })++ it('creates grid with numeric columns shorthand', () => {+ const g = createGraph()+ const tree = Frame({ name: 'Grid', w: 300, h: 200, grid: true, columns: 3 })+ const result = renderTree(g, tree)+ const frame = g.nodes.get(result.id)!++ expect(frame.gridTemplateColumns).toEqual([+ { sizing: 'FR', value: 1 },+ { sizing: 'FR', value: 1 },+ { sizing: 'FR', value: 1 }+ ])+ })++ it('sets grid gaps', () => {+ const g = createGraph()+ const tree = Frame({ name: 'Grid', w: 300, h: 200, grid: true, columns: '1fr 1fr', columnGap: 10, rowGap: 20 })+ const result = renderTree(g, tree)+ const frame = g.nodes.get(result.id)!++ expect(frame.gridColumnGap).toBe(10)+ expect(frame.gridRowGap).toBe(20)+ })++ it('sets grid gap shorthand', () => {+ const g = createGraph()+ const tree = Frame({ name: 'Grid', w: 300, h: 200, grid: true, columns: '1fr 1fr', gap: 16 })+ const result = renderTree(g, tree)+ const frame = g.nodes.get(result.id)!++ expect(frame.gridColumnGap).toBe(16)+ expect(frame.gridRowGap).toBe(16)+ })++ it('applies grid padding', () => {+ const g = createGraph()+ const tree = Frame({ name: 'Grid', w: 300, h: 200, grid: true, columns: '1fr 1fr', p: 10 })+ const result = renderTree(g, tree)+ const frame = g.nodes.get(result.id)!++ expect(frame.paddingTop).toBe(10)+ expect(frame.paddingRight).toBe(10)+ expect(frame.paddingBottom).toBe(10)+ expect(frame.paddingLeft).toBe(10)+ })++ it('sets grid rows', () => {+ const g = createGraph()+ const tree = Frame({ name: 'Grid', w: 300, h: 200, grid: true, columns: '1fr', rows: '100 1fr' })+ const result = renderTree(g, tree)+ const frame = g.nodes.get(result.id)!++ expect(frame.gridTemplateRows).toEqual([+ { sizing: 'FIXED', value: 100 },+ { sizing: 'FR', value: 1 }+ ])+ })++ it('sets grid child position', () => {+ const g = createGraph()+ const tree = Frame({ name: 'Grid', w: 300, h: 200, grid: true, columns: '1fr 1fr 1fr', rows: '1fr 1fr' },+ Rectangle({ name: 'A', w: 50, h: 50, colStart: 2, rowStart: 1 })+ )+ const result = renderTree(g, tree)+ const children = g.getChildren(result.id)++ expect(children[0].gridPosition).toEqual({ column: 2, row: 1, columnSpan: 1, rowSpan: 1 })+ })++ it('sets grid child span', () => {+ const g = createGraph()+ const tree = Frame({ name: 'Grid', w: 300, h: 200, grid: true, columns: '1fr 1fr 1fr', rows: '1fr 1fr' },+ Rectangle({ name: 'A', w: 50, h: 50, colStart: 1, colSpan: 2, rowStart: 1, rowSpan: 2 })+ )+ const result = renderTree(g, tree)+ const children = g.getChildren(result.id)++ expect(children[0].gridPosition).toEqual({ column: 1, row: 1, columnSpan: 2, rowSpan: 2 })+ })++ it('grid + computeLayout positions children in cells', () => {+ const g = createGraph()+ const tree = Frame({ name: 'Grid', w: 300, h: 200, grid: true, columns: '1fr 1fr 1fr', rows: '1fr' },+ Rectangle({ name: 'A', w: 50, h: 50 }),+ Rectangle({ name: 'B', w: 50, h: 50 }),+ Rectangle({ name: 'C', w: 50, h: 50 })+ )+ const result = renderTree(g, tree)+ computeLayout(g, result.id)++ const children = g.getChildren(result.id)+ expect(children[0].x).toBe(0)+ expect(children[1].x).toBe(100)+ expect(children[2].x).toBe(200)+ })++ it('grid 2x2 with gap positions correctly', () => {+ const g = createGraph()+ const tree = Frame({ name: 'Grid', w: 210, h: 210, grid: true, columns: '1fr 1fr', rows: '1fr 1fr', gap: 10 },+ Rectangle({ name: 'A', w: 30, h: 30 }),+ Rectangle({ name: 'B', w: 30, h: 30 }),+ Rectangle({ name: 'C', w: 30, h: 30 }),+ Rectangle({ name: 'D', w: 30, h: 30 })+ )+ const result = renderTree(g, tree)+ computeLayout(g, result.id)++ const children = g.getChildren(result.id)+ expect(children[0].x).toBe(0)+ expect(children[0].y).toBe(0)+ expect(children[1].x).toBe(110)+ expect(children[1].y).toBe(0)+ expect(children[2].x).toBe(0)+ expect(children[2].y).toBe(110)+ expect(children[3].x).toBe(110)+ expect(children[3].y).toBe(110)+ })++ it('renders grid from JSX string', async () => {+ const g = createGraph()+ const jsx = `+ <Frame name="Grid" w={300} h={100} grid columns="1fr 1fr" gap={10}>+ <Rectangle name="A" w={50} h={50} />+ <Rectangle name="B" w={50} h={50} />+ </Frame>+ `+ const result = await renderJSX(g, jsx)+ const frame = g.nodes.get(result.id)!++ expect(frame.layoutMode).toBe('GRID')+ expect(frame.gridTemplateColumns).toEqual([+ { sizing: 'FR', value: 1 },+ { sizing: 'FR', value: 1 }+ ])+ expect(frame.gridColumnGap).toBe(10)+ expect(frame.gridRowGap).toBe(10)++ computeLayout(g, result.id)+ const children = g.getChildren(result.id)+ expect(children[0].x).toBe(0)+ expect(children[1].x).toBe(155)+ })++ it('grid auto-height (no rows) grows to fit content', () => {+ const g = createGraph()+ const tree = Frame({ name: 'Grid', w: 300, grid: true, columns: '1fr 1fr', gap: 10 },+ Rectangle({ name: 'A', w: 50, h: 80 }),+ Rectangle({ name: 'B', w: 50, h: 80 }),+ Rectangle({ name: 'C', w: 50, h: 60 }),+ Rectangle({ name: 'D', w: 50, h: 60 })+ )+ const result = renderTree(g, tree)+ const frame = g.nodes.get(result.id)!+ expect(frame.gridTemplateRows).toEqual([])++ computeLayout(g, result.id)+ const updated = g.nodes.get(result.id)!+ expect(updated.height).toBe(150)+ })++ it('grid children with flex stretch to cell width', () => {+ const g = createGraph()+ const tree = Frame({ name: 'Grid', w: 200, grid: true, columns: '1fr 1fr', gap: 0 },+ Frame({ name: 'A', flex: 'col', gap: 4, p: 8, children: [+ Rectangle({ name: 'R1', w: 10, h: 20 })+ ]}),+ Frame({ name: 'B', flex: 'col', gap: 4, p: 8, children: [+ Rectangle({ name: 'R2', w: 10, h: 20 })+ ]})+ )+ const result = renderTree(g, tree)+ computeAllLayouts(g)++ const children = g.getChildren(result.id)+ expect(children[0].width).toBe(100)+ expect(children[1].width).toBe(100)+ expect(children[0].x).toBe(0)+ expect(children[1].x).toBe(100)+ })++ it('grid prop takes precedence over padding-triggered auto-layout', () => {+ const g = createGraph()+ const tree = Frame({ name: 'Grid', w: 300, grid: true, columns: '1fr 1fr', p: 20 },+ Rectangle({ name: 'A', w: 50, h: 50 }),+ Rectangle({ name: 'B', w: 50, h: 50 })+ )+ const result = renderTree(g, tree)+ const frame = g.nodes.get(result.id)!+ expect(frame.layoutMode).toBe('GRID')+ })++ it('grid w=fill stretches in flex-col parent', async () => {+ const g = createGraph()+ const jsx = `+ <Frame name="P" flex="col" w={400} p={20}>+ <Frame name="G" grid columns="1fr 1fr" gap={10} w="fill">+ <Rectangle w={10} h={30} />+ <Rectangle w={10} h={30} />+ </Frame>+ </Frame>+ `+ const result = await renderJSX(g, jsx)+ computeAllLayouts(g)+ const grid = g.getChildren(result.id).find(c => c.name === 'G')!+ expect(grid.width).toBe(360)+ expect(grid.layoutMode).toBe('GRID')+ })++ it('grid grow=1 fills remaining space in flex-row', async () => {+ const g = createGraph()+ const jsx = `+ <Frame name="P" flex="row" w={500} p={20} gap={10}>+ <Rectangle w={100} h={50} />+ <Frame name="G" grid columns="1fr 1fr" gap={10} grow={1}>+ <Rectangle w={10} h={30} />+ <Rectangle w={10} h={30} />+ </Frame>+ </Frame>+ `+ const result = await renderJSX(g, jsx)+ computeAllLayouts(g)+ const grid = g.getChildren(result.id).find(c => c.name === 'G')!+ expect(grid.width).toBe(350)+ })++ it('nested flex > flex > grid: grid stretches to correct width', async () => {+ const g = createGraph()+ const jsx = `+ <Frame name="Card" flex="col" w={780}>+ <Frame name="Content" flex="col" w="fill" p={28}>+ <Frame name="G" grid columns="1fr 1fr 1fr" w="fill" columnGap={16}>+ <Rectangle w={10} h={30} />+ <Rectangle w={10} h={30} />+ <Rectangle w={10} h={30} />+ </Frame>+ </Frame>+ </Frame>+ `+ const result = await renderJSX(g, jsx)+ computeAllLayouts(g)+ const content = g.getChildren(result.id).find(c => c.name === 'Content')!+ const grid = g.getChildren(content.id).find(c => c.name === 'G')!+ expect(content.width).toBe(780)+ expect(grid.width).toBe(724)+ })++ it('grid h=fill grows in flex-col parent', async () => {+ const g = createGraph()+ const jsx = `+ <Frame name="P" flex="col" w={400} h={600} p={20}>+ <Rectangle w={360} h={100} />+ <Frame name="G" grid columns="1fr 1fr" gap={10} h="fill">+ <Rectangle w={10} h={30} />+ <Rectangle w={10} h={30} />+ </Frame>+ </Frame>+ `+ const result = await renderJSX(g, jsx)+ computeAllLayouts(g)+ const grid = g.getChildren(result.id).find(c => c.name === 'G')!+ expect(grid.height).toBe(460)+ })+})diff --git a/tweet-0.9.0.txt b/tweet-0.9.0.txtnew file mode 100644index 000000000..b8b0224e3--- /dev/null+++ b/tweet-0.9.0.txt@@ -0,0 +1,26 @@+OpenPencil v0.9.0 — a lot happened since 0.7.++Features:+→ CSS Grid layout — forked Yoga with cherry-picked Grid PRs. Configure tracks (fr/px/auto), gaps, padding+→ Tailwind CSS v4 export — Code panel toggles between OpenPencil JSX and HTML+Tailwind. Grid layouts export too: 𝚐𝚛𝚒𝚍 𝚐𝚛𝚒𝚍-𝚌𝚘𝚕𝚜-𝙽, 𝚌𝚘𝚕-𝚜𝚙𝚊𝚗-*+→ Multi-provider AI — connect to Anthropic, OpenAI, Google AI, or any OpenAI-compatible endpoint directly, not just OpenRouter. Per-provider keys, Completions/Responses API toggle, visual verification (model sees what it built via vision)+→ XPath queries — 𝚘𝚙𝚎𝚗-𝚙𝚎𝚗𝚌𝚒𝚕 𝚚𝚞𝚎𝚛𝚢 𝚍𝚎𝚜𝚒𝚐𝚗.𝚏𝚒𝚐 "//𝙵𝚁𝙰𝙼𝙴[@𝚠𝚒𝚍𝚝𝚑 < 𝟹𝟶𝟶]" from CLI or AI+→ CLI-to-app RPC bridge — run 𝚋𝚞𝚗 𝚘𝚙𝚎𝚗-𝚙𝚎𝚗𝚌𝚒𝚕 𝚝𝚛𝚎𝚎 against the live editor, no file needed+→ Undo for auto-layout reorder, layer tree reorder, and drag reparent+→ Double-click to rename layers, auto-layout icons in layer tree, draggable frame titles on canvas, compact icon-based layout controls+→ Shift+A auto-detects horizontal vs vertical direction. Padding auto-enables auto-layout.+→ Figma zoom shortcuts: ⌘0/⌘1/⌘2+→ Homebrew tap: 𝚋𝚛𝚎𝚠 𝚒𝚗𝚜𝚝𝚊𝚕𝚕 𝚘𝚙𝚎𝚗-𝚙𝚎𝚗𝚌𝚒𝚕/𝚝𝚊𝚙/𝚘𝚙𝚎𝚗-𝚙𝚎𝚗𝚌𝚒𝚕+→ VitePress docs site at openpencil.dev — 6 locales++91 AI/MCP tools now. New ones: 𝚐𝚎𝚝_𝚓𝚜𝚡, 𝚍𝚒𝚏𝚏_𝚓𝚜𝚡, 𝚍𝚎𝚜𝚌𝚛𝚒𝚋𝚎, 𝚊𝚗𝚊𝚕𝚢𝚣𝚎_*, 𝚚𝚞𝚎𝚛𝚢_𝚗𝚘𝚍𝚎𝚜, 𝚊𝚛𝚛𝚊𝚗𝚐𝚎, 𝚗𝚘𝚍𝚎_𝚝𝚘_𝚌𝚘𝚖𝚙𝚘𝚗𝚎𝚗𝚝. AI mutations get page-level undo and immediate layout recomputation.++MCP and CLI became a lot more usable — updated tools, better prompts, improved output. Worth trying if you haven't recently. We also published an open-pencil skill for AI coding agents — 𝚗𝚙𝚡 𝚜𝚔𝚒𝚕𝚕𝚜 𝚊𝚍𝚍 𝚘𝚙𝚎𝚗-𝚙𝚎𝚗𝚌𝚒𝚕/𝚜𝚔𝚒𝚕𝚕𝚜@𝚘𝚙𝚎𝚗-𝚙𝚎𝚗𝚌𝚒𝚕 — so Claude Code / Cursor can work with .fig files out of the box.++Big .fig compat fixes: variables/collections/bindings were lost on save — fixed. Text typography lost on Figma clipboard paste — fixed. Gradient transforms dropped on copy — fixed. Orphaned instances on paste detach to FRAME. Collab sync for reorder.++Figma compatibility handles ~90% of complex files now, but the gap is still there — some edge cases in nested instances, certain effect combos, and node types we don't support yet. Closing it steadily.++Performance: event bus cut render calls from 94 to 22, typed copy helpers are ~24× faster than structuredClone. Still not where we want it — raster caching and large file handling coming next.++Lots of hardening behind the scenes — custom oxlint rules to catch AI-generated slop at compile time, type-aware linting with tsgo, complexity limits. Renderer split from one 3,200-line file into 10. esbuild-wasm (14 MB) swapped for sucrase (201 KB). 233 new tests.