Skip to content

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

fix(fig): apply shared fill styles

Danila Poyarkov4234cf3b338a
diff --git a/packages/core/src/kiwi/binary/codec.ts b/packages/core/src/kiwi/binary/codec.ts
index 85317cab4..3b3a8f5de 100644
--- a/packages/core/src/kiwi/binary/codec.ts
+++ b/packages/core/src/kiwi/binary/codec.ts
@@ -353,6 +353,7 @@ export interface NodeChange {
}
styleType?: string
styleIdForText?: { guid?: GUID }
+ styleIdForFill?: { guid?: GUID }
textUserLayoutVersion?: number
textExplicitLayoutVersion?: number
textBidiVersion?: number
diff --git a/packages/core/src/kiwi/fig/import.ts b/packages/core/src/kiwi/fig/import.ts
index e1da9fe74..dee60e635 100644
--- a/packages/core/src/kiwi/fig/import.ts
+++ b/packages/core/src/kiwi/fig/import.ts
@@ -349,7 +349,7 @@ function parseDocumentColorSpace(nodeChanges: NodeChange[]): 'srgb' | 'display-p
return documentNode?.documentColorProfile === 'DISPLAY_P3' ? 'display-p3' : 'srgb'
}
-function applyTextStyleRefs(changeMap: Map<string, NodeChange>): void {
+function applyStyleRefs(changeMap: Map<string, NodeChange>): void {
const textStyleFields = [
'fontSize',
'fontName',
@@ -360,10 +360,16 @@ function applyTextStyleRefs(changeMap: Map<string, NodeChange>): void {
] as const
for (const nc of changeMap.values()) {
+ const fillStyleGuid = nc.styleIdForFill?.guid
+ if (fillStyleGuid) {
+ const style = changeMap.get(guidToString(fillStyleGuid))
+ if (style?.styleType === 'FILL' && style.fillPaints) nc.fillPaints = style.fillPaints
+ }
+
if (nc.type !== 'TEXT') continue
- const styleGuid = nc.styleIdForText?.guid
- if (!styleGuid) continue
- const style = changeMap.get(guidToString(styleGuid))
+ const textStyleGuid = nc.styleIdForText?.guid
+ if (!textStyleGuid) continue
+ const style = changeMap.get(guidToString(textStyleGuid))
if (style?.type !== 'TEXT' || style.styleType !== 'TEXT') continue
for (const field of textStyleFields) {
if (field === 'textDecoration') {
@@ -399,7 +405,7 @@ export function importNodeChanges(
}
const { changeMap, parentMap, childrenMap } = buildChangeMaps(nodeChanges)
- applyTextStyleRefs(changeMap)
+ applyStyleRefs(changeMap)
const assetRefs = buildAssetRefMap(changeMap)
setVariableColorResolver(buildVariableColorResolver(changeMap, assetRefs))
diff --git a/tests/engine/io/fig/import/legacy/text.test.ts b/tests/engine/io/fig/import/legacy/text.test.ts
index 052a08df2..10420df00 100644
--- a/tests/engine/io/fig/import/legacy/text.test.ts
+++ b/tests/engine/io/fig/import/legacy/text.test.ts
@@ -75,6 +75,45 @@ describe('fig-import: text properties', () => {
expect(styled?.textDecoration).toBe('NONE')
})
+ test('applies shared fill style refs', () => {
+ const graph = importNodeChanges([
+ doc(),
+ canvas(),
+ node('ROUNDED_RECTANGLE', 30, 1, {
+ name: 'slate/900',
+ styleType: 'FILL',
+ fillPaints: [
+ {
+ type: 'SOLID',
+ color: { r: 0.05882352963089943, g: 0.09019608050584793, b: 0.16470588743686676, a: 1 },
+ opacity: 1,
+ visible: true,
+ blendMode: 'NORMAL'
+ }
+ ]
+ } as Partial<NodeChange>),
+ node('ROUNDED_RECTANGLE', 10, 1, {
+ fillPaints: [
+ {
+ type: 'SOLID',
+ color: { r: 1, g: 1, b: 1, a: 1 },
+ opacity: 1,
+ visible: true,
+ blendMode: 'NORMAL'
+ }
+ ],
+ styleIdForFill: { guid: { sessionID: 1, localID: 30 } }
+ } as Partial<NodeChange>)
+ ])
+ const styled = graph.getChildren(graph.getPages()[0].id).find((node) => node.name === 'ROUNDED_RECTANGLE_10')
+ expect(styled?.fills[0]?.color).toEqual({
+ r: 0.05882352963089943,
+ g: 0.09019608050584793,
+ b: 0.16470588743686676,
+ a: 1
+ })
+ })
+
test('font weight mapping', () => {
const cases = [
['Bold', 700],