Normalize colors at FigmaAPI proxy boundary

Root cause of 'Missing required field a' crash: fills/strokes/effects
set via the Figma Plugin API proxy were stored without color validation.
Colors missing the 'a' field (e.g. from AI tools or eval) caused Kiwi
encodeColor to crash on save/copy.

Fix: normalize colors in the proxy setters for fills, strokes, effects,
and gradient stops using normalizeColor() which defaults a to 1.
This commit is contained in:
Danila Poyarkov 2026-03-13 13:04:29 +03:00
parent 9f98833495
commit 7c63fc3b22

View file

@ -8,6 +8,7 @@ import type {
Effect,
LayoutMode,
} from './scene-graph'
import { normalizeColor } from './color'
import type { Rect } from './types'
import { copyFills, copyStrokes, copyEffects } from './copy'
@ -167,7 +168,13 @@ export class FigmaNodeProxy {
}
set fills(v: readonly Fill[]) {
this[INTERNAL_GRAPH].updateNode(this[INTERNAL_ID], { fills: [...v] })
this[INTERNAL_GRAPH].updateNode(this[INTERNAL_ID], {
fills: v.map((f) => ({
...f,
color: normalizeColor(f.color),
gradientStops: f.gradientStops?.map((s) => ({ ...s, color: normalizeColor(s.color) }))
}))
})
}
get strokes(): readonly Stroke[] {
@ -175,7 +182,9 @@ export class FigmaNodeProxy {
}
set strokes(v: readonly Stroke[]) {
this[INTERNAL_GRAPH].updateNode(this[INTERNAL_ID], { strokes: [...v] })
this[INTERNAL_GRAPH].updateNode(this[INTERNAL_ID], {
strokes: v.map((s) => ({ ...s, color: normalizeColor(s.color) }))
})
}
get effects(): readonly Effect[] {
@ -183,7 +192,9 @@ export class FigmaNodeProxy {
}
set effects(v: readonly Effect[]) {
this[INTERNAL_GRAPH].updateNode(this[INTERNAL_ID], { effects: [...v] })
this[INTERNAL_GRAPH].updateNode(this[INTERNAL_ID], {
effects: v.map((e) => ({ ...e, color: normalizeColor(e.color) }))
})
}
get opacity(): number {