fix(fig): prefer shared stroke styles

This commit is contained in:
Danila Poyarkov 2026-05-18 02:30:37 +03:00
parent 2dda4358d3
commit 773b1539d2
2 changed files with 45 additions and 1 deletions

View file

@ -40,7 +40,7 @@ export function applyStyleRefsToFields(
}
const strokeFillStyleGuid = fields.styleIdForStrokeFill?.guid
if (strokeFillStyleGuid && fields.strokePaints === undefined) {
if (strokeFillStyleGuid) {
const style = changeMap.get(guidToString(strokeFillStyleGuid))
if (style?.styleType === 'FILL' && style.fillPaints) fields.strokePaints = style.fillPaints
}

View file

@ -0,0 +1,44 @@
import { describe, expect, test } from 'bun:test'
import type { NodeChange } from '#core/kiwi/binary/codec'
import { applyStyleRefsToFields } from '#core/kiwi/node-change/style-refs'
describe('fig import style refs', () => {
test('stroke fill style overrides stale direct stroke paint', () => {
const styleGuid = { sessionID: 4, localID: 4594 }
const stylePaint = {
type: 'SOLID' as const,
color: { r: 0.886274516582489, g: 0.9098039269447327, b: 0.9411764740943909, a: 1 },
opacity: 1,
visible: true,
blendMode: 'NORMAL' as const
}
const fields: Record<string, unknown> & Pick<NodeChange, 'styleIdForStrokeFill' | 'strokePaints'> = {
styleIdForStrokeFill: { guid: styleGuid },
strokePaints: [
{
type: 'SOLID',
color: { r: 0, g: 0, b: 0, a: 1 },
opacity: 1,
visible: true,
blendMode: 'NORMAL'
}
]
}
applyStyleRefsToFields(
new Map([
[
'4:4594',
{
styleType: 'FILL',
fillPaints: [stylePaint]
}
]
]),
fields
)
expect(fields.strokePaints).toEqual([stylePaint])
})
})