From 87e43cccf0d059415b7c5e22842d29a3ae8001f1 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Mon, 16 Nov 2026 21:22:16 -0500 Subject: [PATCH 1/5] format: write Penpot containers through shared incremental writer --- Cargo.lock | 22 +++++++++++++++ Cargo.toml | 3 ++ crates/format/Cargo.toml | 1 + crates/format/src/penpot/export.rs | 35 +++++++++--------------- crates/format/src/penpot/export_tests.rs | 16 +++++++++++ 5 files changed, 55 insertions(+), 22 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d6d010579..07e4fa1b4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1131,6 +1131,17 @@ dependencies = [ "objc2-app-kit 0.3.2", ] +[[package]] +name = "craft-penpot" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=f7c87b3b3a90fffd44b4a414acee966e66cb006e#f7c87b3b3a90fffd44b4a414acee966e66cb006e" +dependencies = [ + "craft-zip 0.1.0 (git+https://github.com/storytold/craft-libs?rev=f7c87b3b3a90fffd44b4a414acee966e66cb006e)", + "serde", + "serde_json", + "thiserror 2.0.21", +] + [[package]] name = "craft-quit" version = "0.1.0" @@ -1265,6 +1276,16 @@ dependencies = [ "zip 9.1.1", ] +[[package]] +name = "craft-zip" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=f7c87b3b3a90fffd44b4a414acee966e66cb006e#f7c87b3b3a90fffd44b4a414acee966e66cb006e" +dependencies = [ + "flate2", + "thiserror 2.0.21", + "zip 9.1.1", +] + [[package]] name = "crc32fast" version = "1.5.3" @@ -2017,6 +2038,7 @@ dependencies = [ "craft-fig", "craft-figcraft-format", "craft-figma-rest", + "craft-penpot", "figcraft-doc", "figcraft-layout", "figcraft-pathops", diff --git a/Cargo.toml b/Cargo.toml index 05aa2d393..75995debf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -58,6 +58,9 @@ craft-menu = { git = "https://github.com/storytold/craft-libs", rev = "e11f9d9ae # Where the settings live: the suite's folder rules, portable mode included (craft-libs). craft-settings = { git = "https://github.com/storytold/craft-libs", rev = "e11f9d9aebea5f6b8e74643c1ea1ed172ba5f545" } +# Penpot export container only; JSON values cross this boundary, not shared model types. +craft-penpot = { git = "https://github.com/storytold/craft-libs", rev = "f7c87b3b3a90fffd44b4a414acee966e66cb006e" } + # The design-file formats (craft-libs): the .fig container and its kiwi encoding, the mapping of # a .fig message onto the REST file JSON, and that JSON's shared helpers. These crates share # types, so they stay on one rev; they share none with the crates above. diff --git a/crates/format/Cargo.toml b/crates/format/Cargo.toml index 9424b95e0..46869824c 100644 --- a/crates/format/Cargo.toml +++ b/crates/format/Cargo.toml @@ -20,6 +20,7 @@ ruzstd = { workspace = true } sha1 = { workspace = true } sha2 = { workspace = true } image = { workspace = true } +craft-penpot = { workspace = true } craft-fig = { workspace = true } craft-figcraft-format = { workspace = true } craft-figma-rest = { workspace = true } diff --git a/crates/format/src/penpot/export.rs b/crates/format/src/penpot/export.rs index d0b9d3046..10811022a 100644 --- a/crates/format/src/penpot/export.rs +++ b/crates/format/src/penpot/export.rs @@ -1,5 +1,4 @@ use std::collections::{BTreeMap, BTreeSet}; -use std::io::{Cursor, Write}; use figcraft_doc::color::{BlendMode, Color, Gradient, GradientKind, ImageScaleMode, Paint, PaintKind}; use figcraft_doc::geom::kurbo::PathEl; @@ -13,7 +12,7 @@ use figcraft_doc::{ use serde_json::{Map, Value, json}; use super::{ROOT_ID, fingerprint, layout_fingerprint, strokes_fingerprint, text_fingerprint, tokens_fingerprint, uuid}; -use crate::{FormatError, io_err, json_options}; +use crate::{FormatError, io_err}; const DEFAULT_FEATURES: &[&str] = &["fdata/path-data", "design-tokens/v1", "variants/v1", "layout/grid", "components/v2", "fdata/shape-data-type"]; @@ -565,27 +564,19 @@ impl<'a> Exporter<'a> { "files": [{"id": self.file_id, "name": name, "features": file.get("features").cloned().unwrap_or(Value::Null)}], "relations": [], }); - let mut buf = Cursor::new(Vec::new()); - { - let mut z = zip::ZipWriter::new(&mut buf); - let mut put = |path: &str, bytes: &[u8]| -> Result<(), FormatError> { - z.start_file(path, json_options()).map_err(io_err)?; - z.write_all(bytes).map_err(io_err) - }; - put("manifest.json", &serde_json::to_vec_pretty(&manifest).map_err(io_err)?)?; - put(&format!("{base}.json"), &serde_json::to_vec_pretty(&file).map_err(io_err)?)?; - if let Some(tokens) = tokens { - put(&format!("{base}/tokens.json"), tokens.as_bytes())?; - } - for (path, value) in &entries { - put(path, &serde_json::to_vec_pretty(value).map_err(io_err)?)?; - } - for (path, bytes) in &blobs { - put(path, bytes)?; - } - z.finish().map_err(io_err)?; + let mut writer = craft_penpot::Writer::new(); + writer.add("manifest.json", &serde_json::to_vec_pretty(&manifest).map_err(io_err)?).map_err(io_err)?; + writer.add(&format!("{base}.json"), &serde_json::to_vec_pretty(&file).map_err(io_err)?).map_err(io_err)?; + if let Some(tokens) = tokens { + writer.add(&format!("{base}/tokens.json"), tokens.as_bytes()).map_err(io_err)?; } - Ok((buf.into_inner(), self.warnings)) + for (path, value) in &entries { + writer.add(path, &serde_json::to_vec_pretty(value).map_err(io_err)?).map_err(io_err)?; + } + for (path, bytes) in &blobs { + writer.add(path, bytes).map_err(io_err)?; + } + Ok((writer.finish().map_err(io_err)?, self.warnings)) } fn page_json(&self, page: NodeId, page_id: &str, index: usize, background: Color) -> Value { diff --git a/crates/format/src/penpot/export_tests.rs b/crates/format/src/penpot/export_tests.rs index 1e9e95638..e3ad744ef 100644 --- a/crates/format/src/penpot/export_tests.rs +++ b/crates/format/src/penpot/export_tests.rs @@ -1027,3 +1027,19 @@ fn stored_variable_ids_keep_penpot_token_identity() { assert_eq!(width, &expected); } } + +#[test] +fn shared_writer_keeps_manifest_first_and_deflated_members() { + let doc = Document::new("Shared container"); + let (bytes, _) = export(&doc).unwrap(); + let mut zip = zip::ZipArchive::new(Cursor::new(bytes.as_slice())).unwrap(); + assert_eq!(zip.by_index(0).unwrap().name(), "manifest.json"); + for index in 0..zip.len() { + assert_eq!(zip.by_index(index).unwrap().compression(), zip::CompressionMethod::Deflated); + } + let archive = craft_penpot::Archive::open(&bytes).unwrap(); + assert_eq!(archive.files.len(), 1); + assert_eq!(archive.files[0].name.as_deref(), Some("Shared container")); + assert_eq!(archive.manifest["generatedBy"], format!("figcraft/{}", env!("CARGO_PKG_VERSION"))); + assert!(import(&bytes).is_ok()); +} From 26fa159c0c7771095df4e963736ec994bdda480c Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Mon, 16 Nov 2026 21:24:19 -0500 Subject: [PATCH 2/5] deps: pin documented Penpot writer error contract --- Cargo.lock | 6 +++--- Cargo.toml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 07e4fa1b4..8adab0b43 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1134,9 +1134,9 @@ dependencies = [ [[package]] name = "craft-penpot" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=f7c87b3b3a90fffd44b4a414acee966e66cb006e#f7c87b3b3a90fffd44b4a414acee966e66cb006e" +source = "git+https://github.com/storytold/craft-libs?rev=8418f9a9e846d27bb4f5e854f370405fd013e9e3#8418f9a9e846d27bb4f5e854f370405fd013e9e3" dependencies = [ - "craft-zip 0.1.0 (git+https://github.com/storytold/craft-libs?rev=f7c87b3b3a90fffd44b4a414acee966e66cb006e)", + "craft-zip 0.1.0 (git+https://github.com/storytold/craft-libs?rev=8418f9a9e846d27bb4f5e854f370405fd013e9e3)", "serde", "serde_json", "thiserror 2.0.21", @@ -1279,7 +1279,7 @@ dependencies = [ [[package]] name = "craft-zip" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=f7c87b3b3a90fffd44b4a414acee966e66cb006e#f7c87b3b3a90fffd44b4a414acee966e66cb006e" +source = "git+https://github.com/storytold/craft-libs?rev=8418f9a9e846d27bb4f5e854f370405fd013e9e3#8418f9a9e846d27bb4f5e854f370405fd013e9e3" dependencies = [ "flate2", "thiserror 2.0.21", diff --git a/Cargo.toml b/Cargo.toml index 75995debf..ac3aedee2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -59,7 +59,7 @@ craft-menu = { git = "https://github.com/storytold/craft-libs", rev = "e11f9d9ae craft-settings = { git = "https://github.com/storytold/craft-libs", rev = "e11f9d9aebea5f6b8e74643c1ea1ed172ba5f545" } # Penpot export container only; JSON values cross this boundary, not shared model types. -craft-penpot = { git = "https://github.com/storytold/craft-libs", rev = "f7c87b3b3a90fffd44b4a414acee966e66cb006e" } +craft-penpot = { git = "https://github.com/storytold/craft-libs", rev = "8418f9a9e846d27bb4f5e854f370405fd013e9e3" } # The design-file formats (craft-libs): the .fig container and its kiwi encoding, the mapping of # a .fig message onto the REST file JSON, and that JSON's shared helpers. These crates share From 931a1467b20eac928fae2f293c0413c606af55fa Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Mon, 16 Nov 2026 21:50:31 -0500 Subject: [PATCH 3/5] fix(format): retain Cursor import for embedded Penpot PNG encoding --- crates/format/src/penpot/export.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/format/src/penpot/export.rs b/crates/format/src/penpot/export.rs index 10811022a..071809cab 100644 --- a/crates/format/src/penpot/export.rs +++ b/crates/format/src/penpot/export.rs @@ -1,4 +1,5 @@ use std::collections::{BTreeMap, BTreeSet}; +use std::io::Cursor; use figcraft_doc::color::{BlendMode, Color, Gradient, GradientKind, ImageScaleMode, Paint, PaintKind}; use figcraft_doc::geom::kurbo::PathEl; From 5ee60ec708201fe93b44ea5dacbce49b96b3598e Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Mon, 16 Nov 2026 22:01:33 -0500 Subject: [PATCH 4/5] fix(format): keep legacy ZIP options only for remaining test fixture --- crates/format/src/lib.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/format/src/lib.rs b/crates/format/src/lib.rs index 167444c62..1c246bb89 100644 --- a/crates/format/src/lib.rs +++ b/crates/format/src/lib.rs @@ -47,6 +47,7 @@ pub use craft_figcraft_format::{ MAX_VERSION_INDEX, MAX_VERSION_NAME, MAX_VERSIONS, ReadBudget, VERSION, VersionEntry as NativeVersionEntry, VersionIndex as NativeVersionIndex, clip, document_limit, is_valid_version_id, }; +#[cfg(test)] const JSON_LEVEL: i64 = 3; /// The export warning for colour calculations that resolve to nothing (an operand missing, or more /// than 32 variables to read), shared by the Penpot and `.fig` exports. @@ -411,7 +412,8 @@ pub(crate) fn io_err(e: impl std::fmt::Display) -> FormatError { FormatError::Io(e.to_string()) } -/// JSON compression for Penpot and external ZIP exporters. +/// JSON compression for legacy Penpot test fixtures. +#[cfg(test)] pub(crate) fn json_options() -> zip::write::SimpleFileOptions { zip::write::SimpleFileOptions::default().compression_method(zip::CompressionMethod::Deflated).compression_level(Some(JSON_LEVEL)) } From 4aae3f2733a3fb1e42c80ab5ba81730a4a55339e Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Mon, 16 Nov 2026 23:11:07 -0500 Subject: [PATCH 5/5] chore(penpot): pin merged writer and canonicalize lock order --- Cargo.lock | 24 ++++++++++++------------ Cargo.toml | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 77abcfa01..879856783 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1144,9 +1144,9 @@ dependencies = [ [[package]] name = "craft-penpot" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=8418f9a9e846d27bb4f5e854f370405fd013e9e3#8418f9a9e846d27bb4f5e854f370405fd013e9e3" +source = "git+https://github.com/storytold/craft-libs?rev=064afccce82b01cbf85da5e265bcf897553bea2a#064afccce82b01cbf85da5e265bcf897553bea2a" dependencies = [ - "craft-zip 0.1.0 (git+https://github.com/storytold/craft-libs?rev=8418f9a9e846d27bb4f5e854f370405fd013e9e3)", + "craft-zip 0.1.0 (git+https://github.com/storytold/craft-libs?rev=064afccce82b01cbf85da5e265bcf897553bea2a)", "serde", "serde_json", "thiserror 2.0.21", @@ -1278,6 +1278,16 @@ dependencies = [ "thiserror 2.0.21", ] +[[package]] +name = "craft-zip" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=064afccce82b01cbf85da5e265bcf897553bea2a#064afccce82b01cbf85da5e265bcf897553bea2a" +dependencies = [ + "flate2", + "thiserror 2.0.21", + "zip 9.1.1", +] + [[package]] name = "craft-zip" version = "0.1.0" @@ -1298,16 +1308,6 @@ dependencies = [ "zip 9.1.1", ] -[[package]] -name = "craft-zip" -version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=8418f9a9e846d27bb4f5e854f370405fd013e9e3#8418f9a9e846d27bb4f5e854f370405fd013e9e3" -dependencies = [ - "flate2", - "thiserror 2.0.21", - "zip 9.1.1", -] - [[package]] name = "craft-zip" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index dd33c406c..82831e556 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -59,7 +59,7 @@ craft-menu = { git = "https://github.com/storytold/craft-libs", rev = "e11f9d9ae craft-settings = { git = "https://github.com/storytold/craft-libs", rev = "e11f9d9aebea5f6b8e74643c1ea1ed172ba5f545" } # Penpot export container only; JSON values cross this boundary, not shared model types. -craft-penpot = { git = "https://github.com/storytold/craft-libs", rev = "8418f9a9e846d27bb4f5e854f370405fd013e9e3" } +craft-penpot = { git = "https://github.com/storytold/craft-libs", rev = "064afccce82b01cbf85da5e265bcf897553bea2a" } # The design-file formats (craft-libs): the .fig container and its kiwi encoding, the mapping of # a .fig message onto the REST file JSON, and that JSON's shared helpers. These crates share