Skip to content

AI-native design editor. Open-source Figma alternative.

refactor(fig): group source roundtrip metadata

Danila Poyarkov749585d73744
diff --git a/packages/core/src/io/formats/fig/export.ts b/packages/core/src/io/formats/fig/export.ts
index c77913166..d37d041fc 100644
--- a/packages/core/src/io/formats/fig/export.ts
+++ b/packages/core/src/io/formats/fig/export.ts
@@ -194,14 +194,14 @@ function appendVariablesForCollection(
}
function applyImportedCanvasFields(page: FigExportPage, canvasNc: KiwiNodeChange): void {
- if (!page.figmaGuid) return
- if (!('pageType' in page.figmaRawNodeFields)) delete canvasNc.pageType
- if ('backgroundColor' in page.figmaRawNodeFields) {
- canvasNc.backgroundColor = structuredClone(page.figmaRawNodeFields.backgroundColor)
+ if (!page.source.id) return
+ if (!('pageType' in page.source.fig.rawNodeFields)) delete canvasNc.pageType
+ if ('backgroundColor' in page.source.fig.rawNodeFields) {
+ canvasNc.backgroundColor = structuredClone(page.source.fig.rawNodeFields.backgroundColor)
}
- const strokeJoin = page.figmaRawNodeFields.strokeJoin
+ const strokeJoin = page.source.fig.rawNodeFields.strokeJoin
if (typeof strokeJoin === 'string') canvasNc.strokeJoin = strokeJoin
- const strokeWeight = page.figmaRawNodeFields.strokeWeight
+ const strokeWeight = page.source.fig.rawNodeFields.strokeWeight
if (typeof strokeWeight === 'number') canvasNc.strokeWeight = strokeWeight
}
@@ -216,8 +216,8 @@ function buildCanvasEntries(
let internalCanvasGuid: GUID | null = null
for (let p = 0; p < pages.length; p++) {
const page = pages[p]
- const canvasGuid = page.figmaGuid
- ? stringToGuid(page.figmaGuid)
+ const canvasGuid = page.source.id
+ ? stringToGuid(page.source.id)
: { sessionID: 0, localID: localIdCounter.value++ }
nodeIdToGuid.set(page.id, canvasGuid)
if (page.internalOnly) internalCanvasGuid = canvasGuid
@@ -225,7 +225,7 @@ function buildCanvasEntries(
const canvasNc = makeCanvasNodeChange(
canvasGuid,
docGuid,
- page.figmaParentIndexPosition ?? fractionalPosition(p),
+ page.source.orderKey ?? fractionalPosition(p),
page.name,
{
backgroundOpacity: 1,
@@ -272,7 +272,7 @@ export async function exportFigFile(
const documentNc = makeDocumentNodeChange(docGuid, graph.documentColorSpace)
const rootNode = graph.getNode(graph.rootId)
- if (rootNode) Object.assign(documentNc, rootNode.figmaRawNodeFields)
+ if (rootNode) Object.assign(documentNc, rootNode.source.fig.rawNodeFields)
const nodeChanges: KiwiNodeChange[] = [documentNc]
const blobs: Uint8Array[] = []
diff --git a/packages/core/src/kiwi/fig/import.ts b/packages/core/src/kiwi/fig/import.ts
index 6a88162f5..9bc552316 100644
--- a/packages/core/src/kiwi/fig/import.ts
+++ b/packages/core/src/kiwi/fig/import.ts
@@ -20,18 +20,20 @@ type AssetRef = { key: string; version?: string }
type AliasRef = { guid?: GUID; assetRef?: AssetRef }
function applyImportedCanvasMetadata(page: ReturnType<SceneGraph['addPage']>, canvasNc: NodeChange) {
- page.figmaParentIndexPosition = canvasNc.parentIndex?.position ?? null
- if (canvasNc.backgroundColor) page.figmaRawNodeFields.backgroundColor = structuredClone(canvasNc.backgroundColor)
- page.figmaRawNodeFields.strokeJoin = canvasNc.strokeJoin
- page.figmaRawNodeFields.strokeWeight = canvasNc.strokeWeight
- if (canvasNc.pageType) page.figmaRawNodeFields.pageType = canvasNc.pageType
+ page.source.format = 'fig'
+ page.source.orderKey = canvasNc.parentIndex?.position ?? null
+ if (canvasNc.backgroundColor) page.source.fig.rawNodeFields.backgroundColor = structuredClone(canvasNc.backgroundColor)
+ page.source.fig.rawNodeFields.strokeJoin = canvasNc.strokeJoin
+ page.source.fig.rawNodeFields.strokeWeight = canvasNc.strokeWeight
+ if (canvasNc.pageType) page.source.fig.rawNodeFields.pageType = canvasNc.pageType
}
function applyImportedDocumentMetadata(graph: SceneGraph, docNc: NodeChange | undefined) {
const rootNode = graph.getNode(graph.rootId)
if (!docNc || !rootNode) return
- rootNode.figmaRawNodeFields.strokeJoin = docNc.strokeJoin
- rootNode.figmaRawNodeFields.strokeWeight = docNc.strokeWeight
+ rootNode.source.format = 'fig'
+ rootNode.source.fig.rawNodeFields.strokeJoin = docNc.strokeJoin
+ rootNode.source.fig.rawNodeFields.strokeWeight = docNc.strokeWeight
}
function assetRefKey(assetRef: AssetRef): string {
@@ -303,7 +305,7 @@ function importPages(
if (!canvasNc) continue
if (canvasNc.type === 'CANVAS') {
const page = graph.addPage(canvasNc.name ?? 'Page')
- page.figmaGuid = canvasId
+ page.source.id = canvasId
applyImportedCanvasMetadata(page, canvasNc)
canvasIdToPageId.set(canvasId, page.id)
if (canvasNc.internalOnly) page.internalOnly = true
diff --git a/packages/core/src/kiwi/fig/instance-overrides/resolve.ts b/packages/core/src/kiwi/fig/instance-overrides/resolve.ts
index 9b7751f99..1190bbeda 100644
--- a/packages/core/src/kiwi/fig/instance-overrides/resolve.ts
+++ b/packages/core/src/kiwi/fig/instance-overrides/resolve.ts
@@ -119,26 +119,26 @@ function getSiblingGroups(ctx: OverrideContext): Map<string, string[]> {
return groups
}
-function sourceSiblingIndex(ctx: OverrideContext, figmaGuid: string): number | null {
+function sourceSiblingIndex(ctx: OverrideContext, sourceId: string): number | null {
let cache = siblingIndexCache.get(ctx)
if (!cache) {
cache = new Map()
siblingIndexCache.set(ctx, cache)
}
- if (cache.has(figmaGuid)) return cache.get(figmaGuid) ?? null
+ if (cache.has(sourceId)) return cache.get(sourceId) ?? null
- const nc = ctx.changeMap.get(figmaGuid)
+ const nc = ctx.changeMap.get(sourceId)
const parentId = nc?.parentIndex?.guid ? guidToString(nc.parentIndex.guid) : null
const symbolId = nc?.symbolData?.symbolID ? guidToString(nc.symbolData.symbolID) : null
if (!nc || !parentId || !symbolId) {
- cache.set(figmaGuid, null)
+ cache.set(sourceId, null)
return null
}
const siblings = getSiblingGroups(ctx).get(`${parentId}\0${symbolId}`) ?? []
- const index = siblings.indexOf(figmaGuid)
+ const index = siblings.indexOf(sourceId)
const result = index !== -1 ? index : null
- cache.set(figmaGuid, result)
+ cache.set(sourceId, result)
return result
}
@@ -169,9 +169,9 @@ function findNodeBySourceSiblingIndex(
ctx: OverrideContext,
parentId: string,
componentId: string,
- figmaGuid: string
+ sourceId: string
): string | null {
- const index = sourceSiblingIndex(ctx, figmaGuid)
+ const index = sourceSiblingIndex(ctx, sourceId)
if (index == null) return null
const targetRoot = ctx.preComputedRoot.get(componentId) ?? getComponentRoot(ctx, componentId)
@@ -265,13 +265,13 @@ export function findNodeByComponentId(
/**
* Resolve a guidPath to a target node within an instance subtree.
*
- * Each GUID in the path identifies an overrideKey → figmaGuid → graph node.
+ * Each GUID in the path identifies an overrideKey → source id → graph node.
* The chain walks from the instance down to the target.
*/
function resolveOverrideStep(
ctx: OverrideContext,
currentId: string,
- figmaGuid: string,
+ sourceId: string,
remapped: string | undefined,
targetNc: InstanceNodeChange | undefined
): string | null {
@@ -282,7 +282,7 @@ function resolveOverrideStep(
return (
findNodeByComponentId(ctx, currentId, remapped) ??
- findNodeBySourceSiblingIndex(ctx, currentId, remapped, figmaGuid) ??
+ findNodeBySourceSiblingIndex(ctx, currentId, remapped, sourceId) ??
findNodeByNameAndType(ctx, currentId, targetNc?.name, targetNc?.type)
)
}
@@ -295,14 +295,14 @@ export function resolveOverrideTarget(
let currentId = instanceId
for (let index = 0; index < guids.length; index++) {
const key = guidToString(guids[index])
- const figmaGuid = ctx.overrideKeyToGuid.get(key) ?? key
- const targetNc = ctx.changeMap.get(figmaGuid)
+ const sourceId = ctx.overrideKeyToGuid.get(key) ?? key
+ const targetNc = ctx.changeMap.get(sourceId)
const symbolGuid = targetNc?.symbolData?.symbolID
? guidToString(targetNc.symbolData.symbolID)
: null
const remapped =
- ctx.guidToNodeId.get(figmaGuid) ?? (symbolGuid ? ctx.guidToNodeId.get(symbolGuid) : undefined)
- const resolved = resolveOverrideStep(ctx, currentId, figmaGuid, remapped, targetNc)
+ ctx.guidToNodeId.get(sourceId) ?? (symbolGuid ? ctx.guidToNodeId.get(symbolGuid) : undefined)
+ const resolved = resolveOverrideStep(ctx, currentId, sourceId, remapped, targetNc)
if (resolved) {
currentId = resolved
continue
diff --git a/packages/core/src/kiwi/fig/node-change/convert.ts b/packages/core/src/kiwi/fig/node-change/convert.ts
index b66845119..90dd2d9c6 100644
--- a/packages/core/src/kiwi/fig/node-change/convert.ts
+++ b/packages/core/src/kiwi/fig/node-change/convert.ts
@@ -355,7 +355,6 @@ function convertLayoutProps(
): Pick<
SceneNode,
| 'layoutMode'
- | 'figmaLayout'
| 'itemSpacing'
| 'paddingTop'
| 'paddingBottom'
@@ -388,27 +387,6 @@ function convertLayoutProps(
return {
layoutMode,
- figmaLayout: {
- stackMode: nc.stackMode,
- stackSpacing: nc.stackSpacing,
- stackPadding: nc.stackPadding,
- stackPaddingRight: nc.stackPaddingRight,
- stackPaddingBottom: nc.stackPaddingBottom,
- stackCounterAlign: nc.stackCounterAlign,
- stackJustify: nc.stackJustify,
- stackCounterAlignItems: nc.stackCounterAlignItems,
- stackPrimaryAlignItems: nc.stackPrimaryAlignItems,
- stackPrimarySizing: nc.stackPrimarySizing,
- stackCounterSizing: nc.stackCounterSizing,
- stackVerticalPadding: nc.stackVerticalPadding,
- stackHorizontalPadding: nc.stackHorizontalPadding,
- stackWrap: nc.stackWrap,
- stackPositioning: nc.stackPositioning,
- stackChildPrimaryGrow: nc.stackChildPrimaryGrow,
- stackChildAlignSelf: nc.stackChildAlignSelf,
- stackCounterSpacing: nc.stackCounterSpacing,
- bordersTakeSpace: nc.bordersTakeSpace as boolean | undefined
- },
itemSpacing: nc.stackSpacing ?? 0,
...convertLayoutPadding(nc),
primaryAxisSizing,
@@ -482,9 +460,7 @@ export function nodeChangeToProps(
return {
nodeType,
name: nc.name ?? nodeType,
- ...extractFigmaNodeIdentity(nc),
- ...extractFigmaRawGeometry(nc, blobs),
- ...extractFigmaSymbolMetadata(nc, blobs),
+ source: extractSourceMetadata(nc, blobs),
...convertTransformProps(nc),
opacity: nc.opacity ?? 1,
visible: nc.visible ?? true,
@@ -653,10 +629,40 @@ function isComponentSet(nc: NodeChange): boolean {
return defs.some((d) => d.type === 'VARIANT')
}
-function extractFigmaNodeIdentity(nc: NodeChange) {
+function extractFigmaLayoutMetadata(nc: NodeChange): SceneNode['source']['fig']['layout'] {
return {
- figmaGuid: nc.guid ? guidToString(nc.guid) : null,
- figmaParentIndexPosition: nc.parentIndex?.position ?? null
+ stackMode: nc.stackMode,
+ stackSpacing: nc.stackSpacing,
+ stackPadding: nc.stackPadding,
+ stackPaddingRight: nc.stackPaddingRight,
+ stackPaddingBottom: nc.stackPaddingBottom,
+ stackCounterAlign: nc.stackCounterAlign,
+ stackJustify: nc.stackJustify,
+ stackCounterAlignItems: nc.stackCounterAlignItems,
+ stackPrimaryAlignItems: nc.stackPrimaryAlignItems,
+ stackPrimarySizing: nc.stackPrimarySizing,
+ stackCounterSizing: nc.stackCounterSizing,
+ stackVerticalPadding: nc.stackVerticalPadding,
+ stackHorizontalPadding: nc.stackHorizontalPadding,
+ stackWrap: nc.stackWrap,
+ stackPositioning: nc.stackPositioning,
+ stackChildPrimaryGrow: nc.stackChildPrimaryGrow,
+ stackChildAlignSelf: nc.stackChildAlignSelf,
+ stackCounterSpacing: nc.stackCounterSpacing,
+ bordersTakeSpace: nc.bordersTakeSpace as boolean | undefined
+ }
+}
+
+function extractSourceMetadata(nc: NodeChange, blobs: Uint8Array[]): SceneNode['source'] {
+ return {
+ format: 'fig',
+ id: nc.guid ? guidToString(nc.guid) : null,
+ orderKey: nc.parentIndex?.position ?? null,
+ fig: {
+ ...extractFigmaRawGeometry(nc, blobs),
+ ...extractFigmaSymbolMetadata(nc, blobs),
+ layout: extractFigmaLayoutMetadata(nc)
+ }
}
}
@@ -759,16 +765,16 @@ const FIGMA_RAW_NODE_FIELD_KEYS = [
function extractFigmaRawGeometry(
nc: NodeChange,
blobs: Uint8Array[]
-): Pick<SceneNode, 'figmaRawSize' | 'figmaRawTransform' | 'figmaRawNodeFields'> {
- const figmaRawNodeFields: Record<string, unknown> = {}
+): Pick<SceneNode['source']['fig'], 'rawSize' | 'rawTransform' | 'rawNodeFields'> {
+ const rawNodeFields: Record<string, unknown> = {}
for (const key of FIGMA_RAW_NODE_FIELD_KEYS) {
const value = (nc as Record<string, unknown>)[key]
- if (value !== undefined) figmaRawNodeFields[key] = preserveFigmaPayloadBlobs(value, blobs)
+ if (value !== undefined) rawNodeFields[key] = preserveFigmaPayloadBlobs(value, blobs)
}
return {
- figmaRawSize: nc.size ? { ...nc.size } : null,
- figmaRawTransform: nc.transform ? { ...nc.transform } : null,
- figmaRawNodeFields
+ rawSize: nc.size ? { ...nc.size } : null,
+ rawTransform: nc.transform ? { ...nc.transform } : null,
+ rawNodeFields
}
}
@@ -776,26 +782,23 @@ function extractFigmaSymbolMetadata(
nc: NodeChange,
blobs: Uint8Array[]
): Pick<
- SceneNode,
- | 'figmaSymbolOverrides'
- | 'figmaComponentPropAssignments'
- | 'figmaDerivedSymbolData'
- | 'figmaDerivedSymbolDataLayoutVersion'
- | 'figmaUniformScaleFactor'
+ SceneNode['source']['fig'],
+ | 'symbolOverrides'
+ | 'componentPropAssignments'
+ | 'derivedSymbolData'
+ | 'derivedSymbolDataLayoutVersion'
+ | 'uniformScaleFactor'
> {
const sd = nc.symbolData as
| { symbolOverrides?: unknown[]; uniformScaleFactor?: number }
| undefined
return {
- figmaSymbolOverrides: preserveFigmaPayloadBlobs(sd?.symbolOverrides ?? [], blobs) as unknown[],
- figmaComponentPropAssignments: preserveFigmaPayloadBlobs(
- nc.componentPropAssignments ?? [],
- blobs
- ) as unknown[],
- figmaDerivedSymbolData: preserveFigmaPayloadBlobs(nc.derivedSymbolData ?? [], blobs) as unknown[],
- figmaDerivedSymbolDataLayoutVersion:
+ symbolOverrides: preserveFigmaPayloadBlobs(sd?.symbolOverrides ?? [], blobs) as unknown[],
+ componentPropAssignments: preserveFigmaPayloadBlobs(nc.componentPropAssignments ?? [], blobs) as unknown[],
+ derivedSymbolData: preserveFigmaPayloadBlobs(nc.derivedSymbolData ?? [], blobs) as unknown[],
+ derivedSymbolDataLayoutVersion:
typeof nc.derivedSymbolDataLayoutVersion === 'number' ? nc.derivedSymbolDataLayoutVersion : null,
- figmaUniformScaleFactor: typeof sd?.uniformScaleFactor === 'number' ? sd.uniformScaleFactor : null
+ uniformScaleFactor: typeof sd?.uniformScaleFactor === 'number' ? sd.uniformScaleFactor : null
}
}
diff --git a/packages/core/src/kiwi/fig/node-change/export-node.ts b/packages/core/src/kiwi/fig/node-change/export-node.ts
index 60df43667..70885221d 100644
--- a/packages/core/src/kiwi/fig/node-change/export-node.ts
+++ b/packages/core/src/kiwi/fig/node-change/export-node.ts
@@ -211,10 +211,10 @@ function collectPaintVariableColorCounts(
export function buildFigmaPaintVariableColorMap(graph: SceneGraph): Map<string, Color> {
const counts = new Map<string, Map<string, { color: Color; count: number }>>()
for (const node of graph.nodes.values()) {
- collectPaintVariableColorCounts(node.figmaRawNodeFields, counts)
- collectPaintVariableColorCounts(node.figmaSymbolOverrides, counts)
- collectPaintVariableColorCounts(node.figmaComponentPropAssignments, counts)
- collectPaintVariableColorCounts(node.figmaDerivedSymbolData, counts)
+ collectPaintVariableColorCounts(node.source.fig.rawNodeFields, counts)
+ collectPaintVariableColorCounts(node.source.fig.symbolOverrides, counts)
+ collectPaintVariableColorCounts(node.source.fig.componentPropAssignments, counts)
+ collectPaintVariableColorCounts(node.source.fig.derivedSymbolData, counts)
}
const colors = new Map<string, Color>()
@@ -246,7 +246,7 @@ function getOrCreateNodeGuid(
const existing = context.nodeIdToGuid?.get(nodeId)
if (existing) return existing
const node = context.graph.getNode(nodeId)
- const importedGuid = node?.figmaGuid ? parseGuidOrNull(node.figmaGuid) : null
+ const importedGuid = node?.source.id ? parseGuidOrNull(node.source.id) : null
const guid = importedGuid ?? { sessionID: 1, localID: localIdCounter.value++ }
context.nodeIdToGuid?.set(nodeId, guid)
return guid
@@ -259,7 +259,7 @@ function applyRawFigmaNodeFields(
): void {
Object.assign(
nc,
- materializeFigmaPayload(node.figmaRawNodeFields, context.blobs, {
+ materializeFigmaPayload(node.source.fig.rawNodeFields, context.blobs, {
blobIndexByHex: context.blobIndexByHex
})
)
@@ -279,21 +279,21 @@ function applyInstancePayload(
)
if (symbolID) {
const symbolData: Record<string, unknown> = { symbolID }
- if (node.figmaSymbolOverrides.length > 0) {
- symbolData.symbolOverrides = materializeFigmaPayload(node.figmaSymbolOverrides, context.blobs, {
+ if (node.source.fig.symbolOverrides.length > 0) {
+ symbolData.symbolOverrides = materializeFigmaPayload(node.source.fig.symbolOverrides, context.blobs, {
blobIndexByHex: context.blobIndexByHex,
includeVariableMaps: true,
paintVariableColorMap: context.paintVariableColorMap
})
}
- if (node.figmaUniformScaleFactor != null) {
- symbolData.uniformScaleFactor = node.figmaUniformScaleFactor
+ if (node.source.fig.uniformScaleFactor != null) {
+ symbolData.uniformScaleFactor = node.source.fig.uniformScaleFactor
}
nc.symbolData = symbolData as KiwiNodeChange['symbolData']
}
- if (node.figmaComponentPropAssignments.length > 0) {
+ if (node.source.fig.componentPropAssignments.length > 0) {
nc.componentPropAssignments = materializeFigmaPayload(
- node.figmaComponentPropAssignments,
+ node.source.fig.componentPropAssignments,
context.blobs,
{
blobIndexByHex: context.blobIndexByHex,
@@ -302,15 +302,15 @@ function applyInstancePayload(
}
)
}
- if (node.figmaDerivedSymbolData.length > 0) {
- nc.derivedSymbolData = materializeFigmaPayload(node.figmaDerivedSymbolData, context.blobs, {
+ if (node.source.fig.derivedSymbolData.length > 0) {
+ nc.derivedSymbolData = materializeFigmaPayload(node.source.fig.derivedSymbolData, context.blobs, {
blobIndexByHex: context.blobIndexByHex,
includeVariableMaps: true,
paintVariableColorMap: context.paintVariableColorMap
})
}
- if (node.figmaDerivedSymbolDataLayoutVersion != null) {
- nc.derivedSymbolDataLayoutVersion = node.figmaDerivedSymbolDataLayoutVersion
+ if (node.source.fig.derivedSymbolDataLayoutVersion != null) {
+ nc.derivedSymbolDataLayoutVersion = node.source.fig.derivedSymbolDataLayoutVersion
}
}
@@ -354,19 +354,19 @@ function applyComponentMetadata(node: SceneNode, nc: KiwiNodeChange): void {
}
function exportNodeSize(node: SceneNode): Vector {
- return node.figmaRawSize ? { ...node.figmaRawSize } : { x: node.width, y: node.height }
+ return node.source.fig.rawSize ? { ...node.source.fig.rawSize } : { x: node.width, y: node.height }
}
function exportNodeTransform(context: SceneNodeToKiwiContext, node: SceneNode): Matrix {
- return node.figmaRawTransform ? { ...node.figmaRawTransform } : context.computeExportTransform(node)
+ return node.source.fig.rawTransform ? { ...node.source.fig.rawTransform } : context.computeExportTransform(node)
}
function hasRawGeometryPayload(node: SceneNode): boolean {
- return 'fillGeometry' in node.figmaRawNodeFields || 'strokeGeometry' in node.figmaRawNodeFields
+ return 'fillGeometry' in node.source.fig.rawNodeFields || 'strokeGeometry' in node.source.fig.rawNodeFields
}
function hasRawVectorPayload(node: SceneNode): boolean {
- return 'vectorData' in node.figmaRawNodeFields
+ return 'vectorData' in node.source.fig.rawNodeFields
}
function nodeForGeometryExport(node: SceneNode): SceneNode {
@@ -433,7 +433,7 @@ function applyNodeVisualProps(
if (node.verticalConstraint !== 'MIN') nc.verticalConstraint = node.verticalConstraint
if (node.strokeCap !== 'NONE') nc.strokeCap = node.strokeCap
if (node.strokeJoin !== 'MITER') nc.strokeJoin = node.strokeJoin
- if (!node.figmaGuid && node.strokeMiterLimit !== 28.96) nc.miterLimit = node.strokeMiterLimit
+ if (!node.source.id && node.strokeMiterLimit !== 28.96) nc.miterLimit = node.strokeMiterLimit
if (node.dashPattern.length > 0) nc.dashPattern = node.dashPattern
if (node.arcData) {
nc.arcData = {
@@ -463,7 +463,7 @@ export function sceneNodeToKiwiWithContext(
guid,
parentIndex: {
guid: parentGuid,
- position: node.figmaParentIndexPosition ?? context.fractionalPosition(childIndex)
+ position: node.source.orderKey ?? context.fractionalPosition(childIndex)
},
type: context.mapToFigmaType(node.type),
name: node.name,
diff --git a/packages/core/src/kiwi/fig/node-change/serialize.ts b/packages/core/src/kiwi/fig/node-change/serialize.ts
index f86833a7c..c45d2b11c 100644
--- a/packages/core/src/kiwi/fig/node-change/serialize.ts
+++ b/packages/core/src/kiwi/fig/node-change/serialize.ts
@@ -345,28 +345,28 @@ function normalizeStackCounterAlign(value: string | undefined): string | undefin
}
function serializeLayoutProps(node: SceneNode, nc: KiwiNodeChange): void {
- if (!node.figmaGuid) upsertPluginData(node, LAYOUT_DIRECTION_PLUGIN_KEY, node.layoutDirection)
- const figmaLayout = node.figmaLayout
- if (figmaLayout) {
- nc.stackMode = normalizeStackMode(figmaLayout.stackMode)
- nc.stackSpacing = figmaLayout.stackSpacing
- nc.stackPadding = figmaLayout.stackPadding
- nc.stackPaddingRight = figmaLayout.stackPaddingRight
- nc.stackPaddingBottom = figmaLayout.stackPaddingBottom
- nc.stackCounterAlign = normalizeStackCounterAlign(figmaLayout.stackCounterAlign)
- nc.stackJustify = normalizeStackJustify(figmaLayout.stackJustify)
- nc.stackCounterAlignItems = normalizeStackCounterAlign(figmaLayout.stackCounterAlignItems)
- nc.stackPrimaryAlignItems = normalizeStackJustify(figmaLayout.stackPrimaryAlignItems)
- nc.stackPrimarySizing = normalizeStackSizing(figmaLayout.stackPrimarySizing)
- nc.stackCounterSizing = normalizeStackSizing(figmaLayout.stackCounterSizing)
- nc.stackVerticalPadding = figmaLayout.stackVerticalPadding
- nc.stackHorizontalPadding = figmaLayout.stackHorizontalPadding
- nc.stackWrap = figmaLayout.stackWrap
- nc.stackPositioning = figmaLayout.stackPositioning
- nc.stackChildPrimaryGrow = figmaLayout.stackChildPrimaryGrow
- nc.stackChildAlignSelf = figmaLayout.stackChildAlignSelf
- nc.stackCounterSpacing = figmaLayout.stackCounterSpacing
- nc.bordersTakeSpace = figmaLayout.bordersTakeSpace
+ if (!node.source.id) upsertPluginData(node, LAYOUT_DIRECTION_PLUGIN_KEY, node.layoutDirection)
+ const figLayout = node.source.fig.layout
+ if (figLayout) {
+ nc.stackMode = normalizeStackMode(figLayout.stackMode)
+ nc.stackSpacing = figLayout.stackSpacing
+ nc.stackPadding = figLayout.stackPadding
+ nc.stackPaddingRight = figLayout.stackPaddingRight
+ nc.stackPaddingBottom = figLayout.stackPaddingBottom
+ nc.stackCounterAlign = normalizeStackCounterAlign(figLayout.stackCounterAlign)
+ nc.stackJustify = normalizeStackJustify(figLayout.stackJustify)
+ nc.stackCounterAlignItems = normalizeStackCounterAlign(figLayout.stackCounterAlignItems)
+ nc.stackPrimaryAlignItems = normalizeStackJustify(figLayout.stackPrimaryAlignItems)
+ nc.stackPrimarySizing = normalizeStackSizing(figLayout.stackPrimarySizing)
+ nc.stackCounterSizing = normalizeStackSizing(figLayout.stackCounterSizing)
+ nc.stackVerticalPadding = figLayout.stackVerticalPadding
+ nc.stackHorizontalPadding = figLayout.stackHorizontalPadding
+ nc.stackWrap = figLayout.stackWrap
+ nc.stackPositioning = figLayout.stackPositioning
+ nc.stackChildPrimaryGrow = figLayout.stackChildPrimaryGrow
+ nc.stackChildAlignSelf = figLayout.stackChildAlignSelf
+ nc.stackCounterSpacing = figLayout.stackCounterSpacing
+ nc.bordersTakeSpace = figLayout.bordersTakeSpace
return
}
if (node.layoutMode !== 'NONE' && node.layoutMode !== 'GRID') {
diff --git a/packages/core/src/scene-graph/node-defaults.ts b/packages/core/src/scene-graph/node-defaults.ts
index 407707f68..1db4f3628 100644
--- a/packages/core/src/scene-graph/node-defaults.ts
+++ b/packages/core/src/scene-graph/node-defaults.ts
@@ -18,9 +18,22 @@ export function createDefaultNode(
width: 100,
height: 100,
rotation: 0,
- figmaRawSize: null,
- figmaRawTransform: null,
- figmaRawNodeFields: {},
+ source: {
+ format: null,
+ id: null,
+ orderKey: null,
+ fig: {
+ rawSize: null,
+ rawTransform: null,
+ rawNodeFields: {},
+ layout: null,
+ symbolOverrides: [],
+ componentPropAssignments: [],
+ derivedSymbolData: [],
+ derivedSymbolDataLayoutVersion: null,
+ uniformScaleFactor: null
+ }
+ },
figmaDerivedLayout: null,
fills:
type === 'TEXT'
@@ -49,14 +62,6 @@ export function createDefaultNode(
lineHeight: null,
letterSpacing: 0,
layoutMode: 'NONE',
- figmaGuid: null,
- figmaParentIndexPosition: null,
- figmaLayout: null,
- figmaSymbolOverrides: [],
- figmaComponentPropAssignments: [],
- figmaDerivedSymbolData: [],
- figmaDerivedSymbolDataLayoutVersion: null,
- figmaUniformScaleFactor: null,
layoutDirection: 'AUTO',
layoutWrap: 'NO_WRAP',
primaryAxisAlign: 'MIN',
diff --git a/packages/core/src/scene-graph/types.ts b/packages/core/src/scene-graph/types.ts
index 677406fc2..0a235e90f 100644
--- a/packages/core/src/scene-graph/types.ts
+++ b/packages/core/src/scene-graph/types.ts
@@ -18,6 +18,25 @@ export type SceneGraphEventHandlers = Partial<{
export type DocumentColorSpace = 'srgb' | 'display-p3'
+export interface FigmaSourcePayload {
+ rawSize: Vector | null
+ rawTransform: Matrix | null
+ rawNodeFields: Record<string, unknown>
+ layout: FigmaLayoutMetadata | null
+ symbolOverrides: unknown[]
+ componentPropAssignments: unknown[]
+ derivedSymbolData: unknown[]
+ derivedSymbolDataLayoutVersion: number | null
+ uniformScaleFactor: number | null
+}
+
+export interface SourceMetadata {
+ format: 'fig' | null
+ id: string | null
+ orderKey: string | null
+ fig: FigmaSourcePayload
+}
+
export type HandleMirroring = 'NONE' | 'ANGLE' | 'ANGLE_AND_LENGTH'
export type WindingRule = 'NONZERO' | 'EVENODD'
@@ -269,9 +288,7 @@ export interface SceneNode {
width: number
height: number
rotation: number
- figmaRawSize: Vector | null
- figmaRawTransform: Matrix | null
- figmaRawNodeFields: Record<string, unknown>
+ source: SourceMetadata
figmaDerivedLayout: Partial<Rect> | null
fills: Fill[]
@@ -314,14 +331,6 @@ export interface SceneNode {
verticalConstraint: ConstraintType
layoutMode: LayoutMode
- figmaGuid: string | null
- figmaParentIndexPosition: string | null
- figmaLayout: FigmaLayoutMetadata | null
- figmaSymbolOverrides: unknown[]
- figmaComponentPropAssignments: unknown[]
- figmaDerivedSymbolData: unknown[]
- figmaDerivedSymbolDataLayoutVersion: number | null
- figmaUniformScaleFactor: number | null
layoutDirection: LayoutDirection
layoutWrap: LayoutWrap
primaryAxisAlign: LayoutAlign
diff --git a/tests/engine/kiwi/serialize-fixes/auto-layout/transforms.test.ts b/tests/engine/kiwi/serialize-fixes/auto-layout/transforms.test.ts
index 031c1f129..a98c7e48f 100644
--- a/tests/engine/kiwi/serialize-fixes/auto-layout/transforms.test.ts
+++ b/tests/engine/kiwi/serialize-fixes/auto-layout/transforms.test.ts
@@ -138,26 +138,26 @@ describe('Fix 1: auto-layout child transforms', () => {
height: 24,
layoutMode: 'HORIZONTAL',
counterAxisSizing: 'HUG',
- layoutAlignSelf: 'STRETCH',
- figmaLayout: {
- stackMode: 'HORIZONTAL',
- stackPrimarySizing: 'FIXED',
- stackCounterSizing: 'RESIZE_TO_FIT_WITH_IMPLICIT_SIZE',
- stackChildAlignSelf: 'STRETCH'
- }
+ layoutAlignSelf: 'STRETCH'
})
-
- graph.createNode('INSTANCE', parent.id, {
+ parent.source.fig.layout = {
+ stackMode: 'HORIZONTAL',
+ stackPrimarySizing: 'FIXED',
+ stackCounterSizing: 'RESIZE_TO_FIT_WITH_IMPLICIT_SIZE',
+ stackChildAlignSelf: 'STRETCH'
+ }
+
+ const child = graph.createNode('INSTANCE', parent.id, {
name: 'Lists',
width: 282.6666564941406,
height: 24,
layoutMode: 'VERTICAL',
- layoutGrow: 1,
- figmaLayout: {
- stackMode: 'VERTICAL',
- stackChildPrimaryGrow: 1
- }
+ layoutGrow: 1
})
+ child.source.fig.layout = {
+ stackMode: 'VERTICAL',
+ stackChildPrimaryGrow: 1
+ }
const blobs: Uint8Array[] = []
const changes = sceneNodeToKiwi(