Fix save crash when COLOR variable is missing alpha

Reuse safeColor() (which defaults a ?? 1) in the variable export
path. The Kiwi schema requires all Color struct fields — variables
created without explicit alpha caused 'Missing required field a'.

Fixes #128
This commit is contained in:
Danila Poyarkov 2026-03-16 14:17:28 +03:00
parent 8d7dd0a36b
commit 9391ac0112
2 changed files with 3 additions and 3 deletions

View file

@ -1,7 +1,7 @@
import { zipSync, deflateSync, type Zippable } from 'fflate'
import { CANVAS_BG_COLOR, IS_BROWSER, IS_TAURI } from './constants'
import { sceneNodeToKiwi, fractionalPosition, buildFigKiwi, buildFontDigestMap } from './kiwi-serialize'
import { sceneNodeToKiwi, fractionalPosition, buildFigKiwi, buildFontDigestMap, safeColor } from './kiwi-serialize'
import { initCodec, getCompiledSchema, getSchemaBytes } from './kiwi/codec'
import { stringToGuid } from './kiwi/kiwi-convert'
import { renderThumbnail } from './render-image'
@ -34,7 +34,7 @@ function variableValueToKiwi(
}
if (type === 'COLOR' && typeof value === 'object' && 'r' in value) {
return {
value: { colorValue: { r: value.r, g: value.g, b: value.b, a: value.a } },
value: { colorValue: safeColor(value as { r: number; g: number; b: number; a?: number }) },
dataType: 'COLOR',
resolvedDataType: 'COLOR'
}

View file

@ -251,7 +251,7 @@ function exportTextData(node: SceneNode): NodeChange['textData'] {
}
}
function safeColor(c: { r: number; g: number; b: number; a?: number }): Color {
export function safeColor(c: { r: number; g: number; b: number; a?: number }): Color {
return { r: c.r, g: c.g, b: c.b, a: c.a ?? 1 }
}