diff --git a/packages/core/src/figma-api/index.ts b/packages/core/src/figma-api/index.ts index 8f1201adc..adede5158 100644 --- a/packages/core/src/figma-api/index.ts +++ b/packages/core/src/figma-api/index.ts @@ -261,7 +261,9 @@ export class FigmaAPI implements NodeProxyHost { paddingBottom: raw.paddingBottom, paddingLeft: raw.paddingLeft, pluginData: structuredClone(raw.pluginData), - pluginRelaunchData: structuredClone(raw.pluginRelaunchData) + pluginRelaunchData: structuredClone(raw.pluginRelaunchData), + boundVariables: { ...raw.boundVariables }, + variableModes: { ...raw.variableModes } }) for (const childId of raw.childIds) { this.graph.cloneTree(childId, comp.id) diff --git a/tests/engine/figma/api/create/component-from-node.test.ts b/tests/engine/figma/api/create/component-from-node.test.ts index 574b616fa..31125cb57 100644 --- a/tests/engine/figma/api/create/component-from-node.test.ts +++ b/tests/engine/figma/api/create/component-from-node.test.ts @@ -25,6 +25,27 @@ describe('createComponentFromNode', () => { expect(api.getNodeById(frameId)).toBeNull() }) + test('preserves root variable bindings and explicit modes', () => { + const api = createAPI() + const collection = api.createVariableCollection('Radii') + const variable = api.createVariable('radius/md', 'FLOAT', collection.id, 8) + + const frame = api.createFrame() + frame.name = 'Card' + frame.resize(200, 50) + frame.cornerRadius = 8 + api.bindVariable(frame.id, 'cornerRadius', variable.id) + api.graph.updateNode(frame.id, { + variableModes: { [collection.id]: collection.defaultModeId } + }) + + const comp = api.createComponentFromNode(frame) + const raw = api.graph.getNode(comp.id) + + expect(raw?.boundVariables.cornerRadius).toBe(variable.id) + expect(raw?.variableModes).toEqual({ [collection.id]: collection.defaultModeId }) + }) + test('preserves auto-layout HUG sizing when padding changes after conversion', () => { const api = createAPI() const frame = api.createFrame()