AI-native design editor. Open-source Figma alternative.
fix: image fills lost after save . hex hash corrupted in Kiwi byte[] encoding
Guilherme Maurercefa4331e317
diff --git a/packages/core/src/io/formats/fig/export.ts b/packages/core/src/io/formats/fig/export.tsindex a237eeea8..f3110ff95 100644--- a/packages/core/src/io/formats/fig/export.ts+++ b/packages/core/src/io/formats/fig/export.ts@@ -318,22 +318,11 @@ function compressViaWorker(worker.terminate()}- const imgCopies = imageEntries.map((e) => ({- name: e.name,- data: new Uint8Array(e.data)- }))-- const transferables = [- schemaDeflated.buffer,- kiwiData.buffer,- thumbnailPng.buffer,- ...imgCopies.map((e) => e.data.buffer)- ]-- worker.postMessage(- { schemaDeflated, kiwiData, thumbnailPng, metaJson, images: imgCopies },- transferables- )+ // Do NOT use transferables here. toUint8Array() in ByteBuffer returns a view of the+ // internal buffer, so transferring kiwiData.buffer or schemaDeflated.buffer detaches+ // buffers that may be shared with other views, causing "already detached" errors on+ // subsequent saves. Structured clone (the default) copies the data safely.+ worker.postMessage({ schemaDeflated, kiwiData, thumbnailPng, metaJson, images: imageEntries })})}diff --git a/packages/core/src/kiwi/binary/codec.ts b/packages/core/src/kiwi/binary/codec.tsindex e7ddb0010..f8278cf94 100644--- a/packages/core/src/kiwi/binary/codec.ts+++ b/packages/core/src/kiwi/binary/codec.ts@@ -195,7 +195,7 @@ export interface Paint {blendMode?: stringstops?: { color: Color; position: number }[]transform?: Matrix- image?: { hash: string }+ image?: { hash: string | Uint8Array }imageScaleMode?: stringcolorVariableBinding?: VariableBindingcolorVar?: {diff --git a/packages/core/src/kiwi/node-change/serialize.ts b/packages/core/src/kiwi/node-change/serialize.tsindex cd0d940d4..a31d0886d 100644--- a/packages/core/src/kiwi/node-change/serialize.ts+++ b/packages/core/src/kiwi/node-change/serialize.ts@@ -192,6 +192,14 @@ export function safeColor(c: { r: number; g: number; b: number; a?: number }): Creturn { r: c.r, g: c.g, b: c.b, a: c.a ?? 1 }}+function hexToBytes(hex: string): Uint8Array {+ const bytes = new Uint8Array(hex.length / 2)+ for (let i = 0; i < bytes.length; i++) {+ bytes[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16)+ }+ return bytes+}+function fillToKiwiPaint(f: SceneNode['fills'][number]): Paint {const paint: Paint = {type: f.type,@@ -204,7 +212,7 @@ function fillToKiwiPaint(f: SceneNode['fills'][number]): Paint {paint.stops = f.gradientStops.map((s) => ({ color: safeColor(s.color), position: s.position }))}if (f.gradientTransform) paint.transform = f.gradientTransform- if (f.imageHash) paint.image = { hash: f.imageHash }+ if (f.imageHash) paint.image = { hash: hexToBytes(f.imageHash) }if (f.imageScaleMode) paint.imageScaleMode = f.imageScaleModeif (f.imageTransform) paint.transform = f.imageTransformreturn paint