Skip to content

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

Fix .fig export: Zstd compression, IS_TAURI constant, fs permissions

Danila Poyarkov197323162f72
diff --git a/bun.lock b/bun.lock
index 8218e2019..31b35b506 100644
--- a/bun.lock
+++ b/bun.lock
@@ -19,6 +19,7 @@
"tailwindcss": "^4.2.1",
"vue": "^3.5.29",
"yoga-layout": "^3.2.1",
+ "zstd-wasm": "^0.0.9",
},
"devDependencies": {
"@iconify-json/lucide": "^1.2.94",
@@ -520,6 +521,8 @@
"yoga-layout": ["[email protected]", "", {}, "sha512-0LPOt3AxKqMdFBZA3HBAt/t/8vIKq7VaQYbuA8WxCgung+p9TVyKRYdpvCb80HcdTN2NkbIKbhNwKUfm3tQywQ=="],
+ "zstd-wasm": ["[email protected]", "", {}, "sha512-V96PWYhAKv4LfdhH92ntYUlTY1cPtvuxGBoZNDd20UyC9ALwlM9Ae1SKik+KI7NwU9xd62MTXVZAP6fq8SfKVg=="],
+
"@tailwindcss/oxide-wasm32-wasi/@emnapi/core": ["@emnapi/[email protected]", "", { "dependencies": { "@emnapi/wasi-threads": "1.1.0", "tslib": "^2.4.0" }, "bundled": true }, "sha512-AvT9QFpxK0Zd8J0jopedNm+w/2fIzvtPKPjqyw9jwvBaReTTqPBk9Hixaz7KbjimP+QNz605/XnjFcDAL2pqBg=="],
"@tailwindcss/oxide-wasm32-wasi/@emnapi/runtime": ["@emnapi/[email protected]", "", { "dependencies": { "tslib": "^2.4.0" }, "bundled": true }, "sha512-mehfKSMWjjNol8659Z8KxEMrdSJDDot5SXMq00dM8BN4o+CLNXQ0xH2V7EchNHV4RmbZLmmPdEaXZc5H2FXmDg=="],
diff --git a/desktop/capabilities/default.json b/desktop/capabilities/default.json
index 1d81037b4..013a1cc65 100644
--- a/desktop/capabilities/default.json
+++ b/desktop/capabilities/default.json
@@ -9,8 +9,13 @@
"dialog:default",
"dialog:allow-save",
"dialog:allow-open",
- "fs:default",
- "fs:allow-read",
- "fs:allow-write"
+ {
+ "identifier": "fs:allow-read-file",
+ "allow": [{ "path": "**" }]
+ },
+ {
+ "identifier": "fs:allow-write-file",
+ "allow": [{ "path": "**" }]
+ }
]
}
diff --git a/package.json b/package.json
index e63f9c49e..ee39871cf 100644
--- a/package.json
+++ b/package.json
@@ -32,7 +32,8 @@
"reka-ui": "^2.8.2",
"tailwindcss": "^4.2.1",
"vue": "^3.5.29",
- "yoga-layout": "^3.2.1"
+ "yoga-layout": "^3.2.1",
+ "zstd-wasm": "^0.0.9"
},
"devDependencies": {
"@iconify-json/lucide": "^1.2.94",
diff --git a/src/composables/use-menu.ts b/src/composables/use-menu.ts
index 559383bf2..0016597a7 100644
--- a/src/composables/use-menu.ts
+++ b/src/composables/use-menu.ts
@@ -1,9 +1,10 @@
import { onUnmounted } from 'vue'
+import { IS_TAURI } from '../constants'
import type { EditorStore } from '../stores/editor'
export async function openFileDialog(store: EditorStore) {
- if ('__TAURI_INTERNALS__' in window) {
+ if (IS_TAURI) {
const { open } = await import('@tauri-apps/plugin-dialog')
const { readFile } = await import('@tauri-apps/plugin-fs')
const path = await open({
@@ -55,7 +56,7 @@ const MENU_ACTIONS: Record<string, (store: EditorStore) => void> = {
}
export function useMenu(store: EditorStore) {
- if (!('__TAURI_INTERNALS__' in window)) return
+ if (!IS_TAURI) return
let unlisten: (() => void) | undefined
diff --git a/src/constants.ts b/src/constants.ts
index 6a8b06bbb..6020650e1 100644
--- a/src/constants.ts
+++ b/src/constants.ts
@@ -1,6 +1,8 @@
import type { Color } from './types'
import type { Fill, Stroke } from './engine/scene-graph'
+export const IS_TAURI = '__TAURI_INTERNALS__' in window
+
export const SELECTION_COLOR = { r: 0.23, g: 0.51, b: 0.96, a: 1 } satisfies Color
export const SNAP_COLOR = { r: 1.0, g: 0.0, b: 0.56, a: 1 } satisfies Color
export const CANVAS_BG_COLOR = { r: 0.96, g: 0.96, b: 0.96, a: 1 } satisfies Color
diff --git a/src/engine/fig-export.ts b/src/engine/fig-export.ts
index 57ec8f55f..bedcd89f3 100644
--- a/src/engine/fig-export.ts
+++ b/src/engine/fig-export.ts
@@ -1,6 +1,6 @@
import { zipSync } from 'fflate'
import { decodeBinarySchema, compileSchema, ByteBuffer } from '../kiwi/kiwi-schema'
-import { inflateSync, deflateSync } from 'fflate'
+import { inflateSync } from 'fflate'
import { encodeVectorNetworkBlob } from './vector'
import type { SceneGraph, SceneNode, Color } from './scene-graph'
@@ -208,11 +208,13 @@ function sceneNodeToKiwi(
return result
}
-function buildFigKiwi(schemaDeflated: Uint8Array, dataRaw: Uint8Array): Uint8Array {
- const dataDeflated = deflateSync(dataRaw)
+async function buildFigKiwi(schemaDeflated: Uint8Array, dataRaw: Uint8Array): Promise<Uint8Array> {
+ const { ZstdCodec } = await import('zstd-wasm')
+ const zstd = await ZstdCodec.run()
+ const dataCompressed = zstd.compress(dataRaw)
const FIG_KIWI_VERSION = 106
- const total = 8 + 4 + 4 + schemaDeflated.length + 4 + dataDeflated.length
+ const total = 8 + 4 + 4 + schemaDeflated.length + 4 + dataCompressed.length
const out = new Uint8Array(total)
const view = new DataView(out.buffer)
@@ -226,9 +228,9 @@ function buildFigKiwi(schemaDeflated: Uint8Array, dataRaw: Uint8Array): Uint8Arr
out.set(schemaDeflated, offset)
offset += schemaDeflated.length
- view.setUint32(offset, dataDeflated.length, true)
+ view.setUint32(offset, dataCompressed.length, true)
offset += 4
- out.set(dataDeflated, offset)
+ out.set(dataCompressed, offset)
return out
}
@@ -288,7 +290,7 @@ export async function exportFigFile(graph: SceneGraph): Promise<Uint8Array> {
}
const dataRaw = compiled.encodeMessage(msg)
- const canvasData = buildFigKiwi(schemaDeflated, dataRaw)
+ const canvasData = await buildFigKiwi(schemaDeflated, dataRaw)
const meta = JSON.stringify({
version: 1,
diff --git a/src/stores/editor.ts b/src/stores/editor.ts
index 115c64df5..5e46c7fd8 100644
--- a/src/stores/editor.ts
+++ b/src/stores/editor.ts
@@ -1,6 +1,6 @@
import { reactive, shallowRef, computed } from 'vue'
-import { DEFAULT_SHAPE_FILL, DEFAULT_FRAME_FILL, SECTION_DEFAULT_FILL, SECTION_DEFAULT_STROKE, CANVAS_BG_COLOR, ZOOM_SENSITIVITY } from '../constants'
+import { IS_TAURI, DEFAULT_SHAPE_FILL, DEFAULT_FRAME_FILL, SECTION_DEFAULT_FILL, SECTION_DEFAULT_STROKE, CANVAS_BG_COLOR, ZOOM_SENSITIVITY } from '../constants'
import type { Color } from '../types'
import {
parseFigmaClipboard,
@@ -462,7 +462,7 @@ export function createEditorStore() {
async function saveFigFileAs() {
const data = await exportFigFile(graph)
- if ('__TAURI_INTERNALS__' in window) {
+ if (IS_TAURI) {
const { save } = await import('@tauri-apps/plugin-dialog')
const path = await save({
defaultPath: 'Untitled.fig',
@@ -503,7 +503,7 @@ export function createEditorStore() {
}
async function writeFile(data: Uint8Array) {
- if (filePath && '__TAURI_INTERNALS__' in window) {
+ if (filePath && IS_TAURI) {
const { writeFile: tauriWrite } = await import('@tauri-apps/plugin-fs')
await tauriWrite(filePath, data)
return