AI-native design editor. Open-source Figma alternative.
Fig and Kiwi
@open-pencil/kiwi owns Kiwi schema, runtime, codecs, containers, and parse helpers without SceneGraph knowledge. @open-pencil/fig owns complete .fig archive parsing, SceneGraph conversion, metadata policy, component/instance interpretation, and the Figma clipboard format. Core owns format-neutral orchestration, runtime fonts and workers, and thumbnails.
- Keep Kiwi runtime changes minimal; put project policy in wrappers, not in the runtime.
- A schema is compiled once into tables,
compileSchema(schema).schema, and decoding, skipping, encoding, the page manifest scan, and record patching all read fields through them; do not add another type switch or name lookup over Kiwi values (packages/kiwi/tests/compiled-schema.test.ts). - Figma clipboard envelope encoding, decoding, and bounds belong to
@open-pencil/fig/clipboard; converting those records to a SceneGraph ismaterializeFigFragmentinpackages/fig/src/document/fragment.ts, which Core drives frompackages/core/src/clipboard/fig-import.ts. Core prepares runtime fonts and text and owns editor placement and history; browser and Tauri adapters own system clipboard I/O. Do not add platform clipboard APIs here. - One reader serves every
.figpath — parse, worker, page population, session recovery, export, and paste — through the document sessions inpackages/fig/src/document/. Read what it could not resolve withreaderDiagnostics(graph)frompackages/core/src/kiwi/fig/session/document-state.ts; do not add a second import path. - A generated frame's
.figrecord carries its sublayers asnodeGenerationDataand their derived geometry. Each generated type registers aGeneratedFrameCodecthat reads and writes them inpackages/fig/src/node-change/generated/codecs.ts; the import and export dispatch through it and never test node types (packages/fig/tests/node-change/generated/codecs.test.ts). .figdocument data is written with Zstd at the document'sfigCompressionlevel:build_fig_fileindesktop/on Tauri,loadFigDataCompressorfrom@open-pencil/kiwi/fig/containerelsewhere, which is Bun's Zstd or a WebAssembly build. Figma rejects a Zstd frame that does not declare its decompressed size, so every encoder must write it (packages/kiwi/tests/container.test.ts).- Reading uses the same Zstd through the synchronous
decompressFigKiwiData, which needsloadFigDataDecompressorawaited once per thread outside Bun:parseFigFileand the session worker do that, so page recovery and archive patches on either thread never wait (packages/kiwi/tests/container.test.ts). - Saving a document opened from a
.figwrites only the fields its edits changed, merged into the archive's records, and copies the rest as bytes (packages/core/src/io/formats/fig/export/patch/,patchFigMessageinpackages/fig/src/record-patch/); the full export remains for documents with no archive. A change is what the archive tracker sees outside page loads and outsideapplyDerivedLayoutDuring, which wraps layout derived from the file or its fonts; layout an edit causes counts, and the tracker keeps each edited layer as it was so the fields are found by comparing records (packages/core/tests/io/formats/fig/export/patch/). - Changes to
.figbehavior require round-trip validation in Figma.packages/docs/development/roadmap.mdtracks raw metadata coverage and the code map for import/export mapping and schema files. - Measure a reader change over a whole archive, not one frame: capture before and after with
visual-oracles compare digest --file F --out baseline.jsonthen--baseline baseline.json, and account for every node it reports.compare interpreted-documentchecks one frame against live Figma and will report no change while a rule breaks pages it does not cover. - A rule about Figma's override or binding semantics holds only where it was observed. Before encoding one, find a second archive or frame that exercises it and confirm the outcome in live Figma; several plausible rules here fit one file and are contradicted by the next.
- Fixtures under
tests/fixtures/*.figuse Git LFS; use a normalgit pushwhen they change, andgit push --no-verifyto skip the LFS hook otherwise. - Tests address the package by alias rather than drilling:
#fig/*for source,#fig-tests/*for shared test helpers, both registered intools/checks/architecture/src/steiger-rules/support.ts.