mirror of
https://github.com/storytold/figcraft.git
synced 2026-11-29 01:34:37 +01:00
Merge pull request #2622 from Ap3pp3rs94/fix/vector-code-assets
fix(dev): use SVG assets for vector code
This commit is contained in:
8 files changed
+222
-12
No files matched your search
@@ -384,6 +384,10 @@ fn stroke_color(n: &Node) -> Option<Color> {
|
||||
/// The CSS borders a solid stroke makes: one `border`, or with individual stroke sides a border
|
||||
/// on each side that has a weight.
|
||||
fn css_borders(doc: &Document, n: &Node, t: &mut Tokens) -> Vec<(String, String)> {
|
||||
// A vector's stroke belongs to its path, not to a rectangle around its bounding box.
|
||||
if matches!(n.kind, NodeKind::Vector { .. }) {
|
||||
return Vec::new();
|
||||
}
|
||||
let Some(c) = stroke_color(n) else { return Vec::new() };
|
||||
let Some(sides) = n.stroke.sides else {
|
||||
let weight = tok(doc, n, &["strokeWeight"], format!("{}px", num(n.stroke.weight)), t);
|
||||
@@ -573,6 +577,126 @@ mod tests {
|
||||
assert!(!css.contains("gradient"), "{css}");
|
||||
}
|
||||
|
||||
fn embedded_svgs(code: &str) -> Vec<String> {
|
||||
use base64::Engine as _;
|
||||
code.split("data:image/svg+xml;base64,")
|
||||
.skip(1)
|
||||
.map(|rest| {
|
||||
let b64 = rest.split('"').next().unwrap();
|
||||
String::from_utf8(base64::engine::general_purpose::STANDARD.decode(b64).unwrap()).unwrap()
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn vector_code_uses_its_svg_asset_not_a_box_border() {
|
||||
let mut s = Session::new();
|
||||
let icon =
|
||||
id_of(&s.execute("frame.create", &json!({"name": "icon", "width": 24, "height": 24, "props": {"fill": "none"}})).unwrap()["id"]).unwrap();
|
||||
let check = id_of(&s.execute("vector.create", &json!({"path": "M4 12 L10 18 L20 6", "parent": icon, "name": "check", "props": {"fill": "none", "stroke": "#1F3A68", "strokeWeight": 2}})).unwrap()["id"]).unwrap();
|
||||
s.doc_mut().unwrap().get_mut(check).unwrap().fills = vec![Paint::solid(Color::WHITE)];
|
||||
let doc = s.doc().unwrap();
|
||||
let html = code_for(doc, icon, CodeLang::Html);
|
||||
assert!(html.contains("<div class=\"check\">"), "node wrapper: {html}");
|
||||
assert!(html.contains("<img class=\"check-asset\" src=\"data:image/svg+xml;base64,"), "{html}");
|
||||
assert!(html.contains("alt=\"check\""), "{html}");
|
||||
assert!(!html.contains("border: 2px solid"), "{html}");
|
||||
assert!(!html.contains("background:"), "the vector's fill belongs to its SVG, not its box: {html}");
|
||||
let opaque = embedded_svgs(&html);
|
||||
assert_eq!(opaque.len(), 1, "{html}");
|
||||
assert!(opaque[0].contains("<path") && opaque[0].contains("#1F3A68"), "{:?}", opaque[0]);
|
||||
for lang in [CodeLang::React, CodeLang::Vue, CodeLang::Leptos, CodeLang::Tailwind] {
|
||||
let code = code_for(doc, icon, lang);
|
||||
assert!(code.contains("<img") && code.contains("src=\"data:image/svg+xml;base64,"), "{}: {code}", lang.id());
|
||||
assert!(!code.contains("border: 2px solid") && !code.contains("border-[2px]"), "{}: {code}", lang.id());
|
||||
}
|
||||
let css = code_for(doc, icon, CodeLang::Css);
|
||||
assert!(!css.contains("border: 2px solid"), "{css}");
|
||||
let swift = code_for(doc, icon, CodeLang::SwiftUi);
|
||||
assert!(swift.contains("Image(\"check\")"), "{swift}");
|
||||
assert!(!swift.contains(".overlay(RoundedRectangle"), "{swift}");
|
||||
let ark = code_for(doc, icon, CodeLang::ArkUi);
|
||||
assert!(!ark.contains(".border({"), "{ark}");
|
||||
|
||||
// CSS owns the node's rotation and opacity, so the embedded asset must not bake them in.
|
||||
s.doc_mut().unwrap().get_mut(check).unwrap().opacity = 0.5;
|
||||
s.doc_mut().unwrap().get_mut(check).unwrap().transform = figcraft_geom::Affine::rotate(30f64.to_radians());
|
||||
let transformed = code_for(s.doc().unwrap(), icon, CodeLang::Html);
|
||||
assert!(transformed.contains("opacity: 0.5;"), "{transformed}");
|
||||
assert!(transformed.contains("transform: rotate("), "{transformed}");
|
||||
assert_eq!(embedded_svgs(&transformed), opaque, "the asset stays node-local and opaque: {transformed}");
|
||||
|
||||
let rectangle =
|
||||
id_of(&s.execute("shape.rectangle", &json!({"parent": icon, "props": {"stroke": "#1F3A68", "strokeWeight": 2}})).unwrap()["id"]).unwrap();
|
||||
assert!(code_for(s.doc().unwrap(), rectangle, CodeLang::Css).contains("border: 2px solid"), "box strokes remain");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn vector_assets_are_self_contained_and_leptos_literals_escape() {
|
||||
let mut s = Session::new();
|
||||
let icon = id_of(&s.execute("frame.create", &json!({"name": "Icons", "width": 24, "height": 24})).unwrap()["id"]).unwrap();
|
||||
for name in ["Check Icon", "Check Icon", r"icon\q", "check#dark"] {
|
||||
s.execute("vector.create", &json!({"path": "M4 12 L10 18 L20 6", "parent": icon, "name": name, "props": {"fill": "none"}})).unwrap();
|
||||
}
|
||||
let html = code_for(s.doc().unwrap(), icon, CodeLang::Html);
|
||||
assert_eq!(embedded_svgs(&html).len(), 4, "nested vectors need no separate filesystem export: {html}");
|
||||
assert!(!html.contains("src=\"check#dark.svg\""), "{html}");
|
||||
let leptos = code_for(s.doc().unwrap(), icon, CodeLang::Leptos);
|
||||
assert!(leptos.contains("alt=\"icon\\\\q\""), "{leptos}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn vector_asset_keeps_stroke_overflow_inside_a_node_sized_wrapper() {
|
||||
let mut s = Session::new();
|
||||
let badge = id_of(
|
||||
&s.execute(
|
||||
"vector.create",
|
||||
&json!({"path": "M0 0 H24 V24 H0 Z", "name": "badge", "props": {"fill": "none", "stroke": "#1F3A68", "strokeWeight": 2}}),
|
||||
)
|
||||
.unwrap()["id"],
|
||||
)
|
||||
.unwrap();
|
||||
s.doc_mut().unwrap().get_mut(badge).unwrap().stroke.miter_limit = 1.0;
|
||||
let html = code_for(s.doc().unwrap(), badge, CodeLang::Html);
|
||||
assert!(html.contains("<div class=\"badge\">"), "node-sized wrapper: {html}");
|
||||
assert!(html.contains("<img class=\"badge-asset\""), "inner asset: {html}");
|
||||
assert!(html.contains("overflow: visible;"), "stroke is not clipped: {html}");
|
||||
assert!(html.contains("left: -2px;") && html.contains("top: -2px;"), "asset offset: {html}");
|
||||
assert!(html.contains("width: 28px;") && html.contains("height: 28px;"), "asset keeps its bounds: {html}");
|
||||
assert!(html.contains("max-width: none;"), "the wrapper cannot shrink the asset: {html}");
|
||||
let svg = embedded_svgs(&html);
|
||||
assert_eq!(svg.len(), 1, "{html}");
|
||||
assert!(svg[0].contains("width=\"28\" height=\"28\""), "{}", svg[0]);
|
||||
let tailwind = code_for(s.doc().unwrap(), badge, CodeLang::Tailwind);
|
||||
assert!(tailwind.contains("overflow-visible") && tailwind.contains("max-w-none"), "{tailwind}");
|
||||
assert!(tailwind.contains("w-7") && tailwind.contains("h-7"), "28px on the spacing scale: {tailwind}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn vector_markup_does_not_duplicate_svg_effects() {
|
||||
let mut s = Session::new();
|
||||
let vector = id_of(
|
||||
&s.execute("vector.create", &json!({"path": "M0 0 H24 V24 H0 Z", "name": "effect icon", "props": {"fill": "#FFFFFF"}})).unwrap()["id"],
|
||||
)
|
||||
.unwrap();
|
||||
s.doc_mut().unwrap().get_mut(vector).unwrap().effects = vec![
|
||||
figcraft_doc::Effect { kind: EffectKind::LayerBlur(figcraft_doc::Blur::uniform(8.0)), visible: true },
|
||||
figcraft_doc::Effect { kind: EffectKind::DropShadow(Shadow { radius: 4.0, offset: (3.0, 4.0), ..Default::default() }), visible: true },
|
||||
];
|
||||
let html = code_for(s.doc().unwrap(), vector, CodeLang::Html);
|
||||
assert!(!html.contains("filter: blur(") && !html.contains("box-shadow:"), "the SVG owns these effects: {html}");
|
||||
let svg = embedded_svgs(&html);
|
||||
assert_eq!(svg.len(), 1, "{html}");
|
||||
assert!(svg[0].contains("feGaussianBlur") && svg[0].contains("feOffset"), "{}", svg[0]);
|
||||
let standalone = code_for(s.doc().unwrap(), vector, CodeLang::Css);
|
||||
assert!(standalone.contains("filter: blur(4px)") && standalone.contains("box-shadow:"), "standalone CSS is unchanged: {standalone}");
|
||||
|
||||
let rectangle = id_of(&s.execute("shape.rectangle", &json!({"name": "ordinary", "width": 24, "height": 24})).unwrap()["id"]).unwrap();
|
||||
s.doc_mut().unwrap().get_mut(rectangle).unwrap().effects = s.doc().unwrap().node(vector).unwrap().effects.clone();
|
||||
let ordinary = code_for(s.doc().unwrap(), rectangle, CodeLang::Html);
|
||||
assert!(ordinary.contains("filter: blur(4px)") && ordinary.contains("box-shadow:"), "ordinary shapes keep CSS effects: {ordinary}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn swiftui_and_compose_for_an_auto_layout_card() {
|
||||
let mut s = Session::new();
|
||||
|
||||
@@ -216,7 +216,7 @@ fn arkui_layer(ctx: &Ctx, n: &Node, depth: usize, out: &mut String, extra: &[Str
|
||||
}
|
||||
}
|
||||
// Ellipses take their stroke as a shape attribute (above).
|
||||
if !matches!(n.kind, NodeKind::Ellipse { .. })
|
||||
if !matches!(n.kind, NodeKind::Ellipse { .. } | NodeKind::Vector { .. })
|
||||
&& let Some(c) = stroke_color(n)
|
||||
{
|
||||
mods.push(format!(".border({{ width: {}, color: {} }})", num(n.stroke.weight), ark_color(c)));
|
||||
|
||||
@@ -126,6 +126,16 @@ pub(super) fn css(doc: &Document, id: NodeId) -> String {
|
||||
/// The CSS declarations for `n`'s own look and size, one per line; `hug` leaves out the width
|
||||
/// and/or height (they follow the content). Bound variables become `var(--name, value)`.
|
||||
pub(crate) fn css_decls(doc: &Document, n: &Node, t: &mut Tokens, hug: (bool, bool)) -> String {
|
||||
css_decls_impl(doc, n, t, hug, false)
|
||||
}
|
||||
|
||||
/// The declarations around an embedded vector image: its SVG owns shadows and layer blur, so
|
||||
/// only the markup wrapper omits those. Standalone CSS and ordinary shapes keep them.
|
||||
pub(crate) fn css_decls_for_markup(doc: &Document, n: &Node, t: &mut Tokens, hug: (bool, bool)) -> String {
|
||||
css_decls_impl(doc, n, t, hug, true)
|
||||
}
|
||||
|
||||
fn css_decls_impl(doc: &Document, n: &Node, t: &mut Tokens, hug: (bool, bool), vector_svg: bool) -> String {
|
||||
let px = |v: f64| format!("{}px", num(v));
|
||||
let mut out = String::new();
|
||||
let mut put = |key: &str, value: String| out.push_str(&format!("{key}: {value};\n"));
|
||||
@@ -188,7 +198,12 @@ pub(crate) fn css_decls(doc: &Document, n: &Node, t: &mut Tokens, hug: (bool, bo
|
||||
// One `background` with every visible fill as a layer, top first (a document's fills run
|
||||
// bottom to top, as the renderer paints them). CSS allows a plain colour only as the last
|
||||
// layer, so a solid above another fill becomes a one-colour gradient.
|
||||
let visible: Vec<(usize, &figcraft_color::Paint)> = n.fills.iter().enumerate().filter(|(_, p)| p.visible).collect();
|
||||
let visible: Vec<(usize, &figcraft_color::Paint)> = if matches!(n.kind, NodeKind::Vector { .. }) {
|
||||
// The SVG carries the path's fills; an image's box must not get a rectangular one.
|
||||
Vec::new()
|
||||
} else {
|
||||
n.fills.iter().enumerate().filter(|(_, p)| p.visible).collect()
|
||||
};
|
||||
let layers: Vec<String> = visible
|
||||
.iter()
|
||||
.enumerate()
|
||||
@@ -217,7 +232,7 @@ pub(crate) fn css_decls(doc: &Document, n: &Node, t: &mut Tokens, hug: (bool, bo
|
||||
for (key, value) in css_borders(doc, n, t) {
|
||||
put(&key, value);
|
||||
}
|
||||
effect_decls(n, &mut put);
|
||||
effect_decls(n, &mut put, vector_svg && matches!(n.kind, NodeKind::Vector { .. }));
|
||||
if let NodeKind::Text(tx) = &n.kind {
|
||||
text_decls(doc, n, tx, t, &mut put);
|
||||
}
|
||||
@@ -274,12 +289,14 @@ fn layout_decls(doc: &Document, n: &Node, l: &figcraft_doc::AutoLayout, t: &mut
|
||||
}
|
||||
}
|
||||
|
||||
/// Shadows and blurs of `n`.
|
||||
fn effect_decls(n: &Node, put: &mut impl FnMut(&str, String)) {
|
||||
/// Shadows and blurs of `n`. `svg_owned` leaves shadows and layer blur to the embedded SVG;
|
||||
/// backdrop filters stay in CSS because the self-contained asset has no outer page behind it.
|
||||
fn effect_decls(n: &Node, put: &mut impl FnMut(&str, String), svg_owned: bool) {
|
||||
let shadows: Vec<String> = n
|
||||
.effects
|
||||
.iter()
|
||||
.filter(|e| e.visible)
|
||||
.filter(|e| !(svg_owned && matches!(e.kind, EffectKind::DropShadow(_) | EffectKind::InnerShadow(_))))
|
||||
.filter_map(|e| match &e.kind {
|
||||
EffectKind::DropShadow(s) => {
|
||||
Some(format!("{}px {}px {}px {}px {}", num(s.offset.0), num(s.offset.1), num(s.radius), num(s.spread), s.color.to_css()))
|
||||
@@ -296,7 +313,7 @@ fn effect_decls(n: &Node, put: &mut impl FnMut(&str, String)) {
|
||||
for e in n.effects.iter().filter(|e| e.visible) {
|
||||
match e.kind {
|
||||
// CSS blurs are uniform: a progressive blur has no CSS equivalent and is left out.
|
||||
EffectKind::LayerBlur(ref b) if !b.is_progressive() => put("filter", format!("blur({}px)", num(b.radius / 2.0))),
|
||||
EffectKind::LayerBlur(ref b) if !svg_owned && !b.is_progressive() => put("filter", format!("blur({}px)", num(b.radius / 2.0))),
|
||||
EffectKind::BackgroundBlur(ref b) if !b.is_progressive() => put("backdrop-filter", format!("blur({}px)", num(b.radius / 2.0))),
|
||||
// CSS has no refraction: the frost is the nearest.
|
||||
EffectKind::Glass(ref g) => put("backdrop-filter", format!("blur({}px)", num(g.sanitized().frost / 2.0))),
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
use super::css::{Tokens, css_decls};
|
||||
use base64::Engine as _;
|
||||
|
||||
use super::css::{Tokens, css_decls_for_markup};
|
||||
use super::{CodeLang, Ctx, Document, LayoutMode, Node, NodeId, NodeKind, Param, Sizing, indent, num, with_v_if};
|
||||
|
||||
// ------------------------------------------------------------------ HTML and React markup
|
||||
@@ -85,6 +87,24 @@ fn html_escape(s: &str) -> String {
|
||||
s.replace('&', "&").replace('<', "<").replace('>', ">").replace('\n', "<br>")
|
||||
}
|
||||
|
||||
/// A layer name in a quoted markup attribute, with line breaks flattened.
|
||||
fn attr_escape(s: &str) -> String {
|
||||
s.replace('&', "&").replace('<', "<").replace('>', ">").replace('"', """).replace(['\n', '\r'], " ")
|
||||
}
|
||||
|
||||
/// A vector as a self-contained SVG asset and its local painted bounds. CSS owns the node's
|
||||
/// placement and opacity, so the embedded geometry is node-local and fully opaque. No filesystem
|
||||
/// export or URL escaping is needed, and nested vectors work exactly like top-level ones.
|
||||
fn vector_data_uri(doc: &mut Document, n: &Node) -> Option<(String, figcraft_geom::Rect)> {
|
||||
let node = doc.get_mut(n.id).ok()?;
|
||||
node.parent = None;
|
||||
node.transform = figcraft_geom::Affine::IDENTITY;
|
||||
node.opacity = 1.0;
|
||||
let bounds = figcraft_render::export_bounds(doc, n.id)?;
|
||||
let svg = figcraft_svg::export_svg(doc, &[n.id], &Default::default())?;
|
||||
Some((format!("data:image/svg+xml;base64,{}", base64::engine::general_purpose::STANDARD.encode(svg)), bounds))
|
||||
}
|
||||
|
||||
/// Text as JSX children: HTML escapes, braces as expressions, line breaks as `<br />`.
|
||||
fn jsx_text(s: &str) -> String {
|
||||
let mut out = String::new();
|
||||
@@ -147,6 +167,8 @@ pub(crate) struct Markup<'c, 'a> {
|
||||
/// With `fluid`, other layers at least this share of the root's width are fluid too (a
|
||||
/// divider, a banner image); smaller ones (icons) keep their size. Default: none.
|
||||
pub fluid_leaves: f64,
|
||||
/// Lazily cloned once for node-local SVG assets, not once per vector.
|
||||
asset_doc: Option<Document>,
|
||||
}
|
||||
|
||||
/// How `n` sits in its parent: in the flex flow, or placed at its position.
|
||||
@@ -175,6 +197,18 @@ fn placement_decls(n: &Node, parent: Option<&Node>, root: bool, in_flow: bool) -
|
||||
decls
|
||||
}
|
||||
|
||||
/// Extra declarations around an embedded vector image. The inner SVG can be larger than the
|
||||
/// node box, so the wrapper must establish positioning in flex flow and leave overflow visible.
|
||||
fn vector_wrapper_decls(n: &Node, in_flow: bool, own: &mut String) {
|
||||
if !matches!(n.kind, NodeKind::Vector { .. }) {
|
||||
return;
|
||||
}
|
||||
own.push_str("overflow: visible;\n");
|
||||
if in_flow {
|
||||
own.push_str("position: relative;\n");
|
||||
}
|
||||
}
|
||||
|
||||
impl<'c, 'a> Markup<'c, 'a> {
|
||||
pub fn new(ctx: &'c Ctx<'a>, lang: CodeLang) -> Self {
|
||||
Markup {
|
||||
@@ -192,6 +226,7 @@ impl<'c, 'a> Markup<'c, 'a> {
|
||||
inline: false,
|
||||
fluid: false,
|
||||
fluid_leaves: f64::INFINITY,
|
||||
asset_doc: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -290,6 +325,30 @@ impl<'c, 'a> Markup<'c, 'a> {
|
||||
}
|
||||
}
|
||||
|
||||
/// A node-sized wrapper and its inner SVG image. The inner rule uses the exported bounds,
|
||||
/// so strokes and effects keep their size and can overflow the wrapper without clipping.
|
||||
fn vector_element(&mut self, n: &Node, depth: usize, path: &str, class: &str, attr: &str, pad: &str, attrs: &str) {
|
||||
let root_doc = self.ctx.doc;
|
||||
let asset = vector_data_uri(self.asset_doc.get_or_insert_with(|| root_doc.clone()), n);
|
||||
let bounds = asset.as_ref().map(|(_, b)| *b).unwrap_or_else(|| n.local_rect());
|
||||
let asset_class = class_name(&format!("{class} asset"), "asset", &mut self.used);
|
||||
let asset_decls = format!(
|
||||
"display: block;\nposition: absolute;\nleft: {}px;\ntop: {}px;\nwidth: {}px;\nheight: {}px;\nmax-width: none;\n",
|
||||
num(bounds.x0),
|
||||
num(bounds.y0),
|
||||
num(bounds.width()),
|
||||
num(bounds.height())
|
||||
);
|
||||
self.rule(&format!("{path}/$svg"), &asset_class, asset_decls);
|
||||
// Leptos attributes are Rust string literals; the other targets use HTML escaping.
|
||||
let lang = self.lang;
|
||||
let quote = |value: &str| if lang == CodeLang::Leptos { format!("{value:?}") } else { format!("\"{}\"", attr_escape(value)) };
|
||||
let src = asset.map(|(uri, _)| format!(" src={}", quote(&uri))).unwrap_or_default();
|
||||
let alt = quote(&n.name);
|
||||
let inner = self.pad(depth + 1);
|
||||
self.markup.push_str(&format!("{pad}<div {attr}=\"{class}\"{attrs}>\n{inner}<img {attr}=\"{asset_class}\"{src} alt={alt} />\n{pad}</div>\n"));
|
||||
}
|
||||
|
||||
fn element(&mut self, n: &Node, parent: Option<&Node>, depth: usize, path: &str) {
|
||||
let doc = self.ctx.doc;
|
||||
let root = n.id == self.ctx.root;
|
||||
@@ -319,7 +378,7 @@ impl<'c, 'a> Markup<'c, 'a> {
|
||||
}
|
||||
let hugs = n.layout.is_some() || matches!(n.kind, NodeKind::Text(_));
|
||||
let hug = (hugs && n.child_layout.sizing_h == Sizing::Hug, hugs && n.child_layout.sizing_v == Sizing::Hug);
|
||||
let mut own = css_decls(doc, n, &mut self.tokens, hug);
|
||||
let mut own = css_decls_for_markup(doc, n, &mut self.tokens, hug);
|
||||
let page = self.ctx.doc.node(self.ctx.root).map_or(f64::INFINITY, |r| r.width);
|
||||
if self.fluid && (n.layout.is_some() || matches!(n.kind, NodeKind::Text(_)) || (!root && n.width >= page * self.fluid_leaves)) {
|
||||
// Full width, or sized by the flex row (`flex: 1`): no cap needed.
|
||||
@@ -328,6 +387,7 @@ impl<'c, 'a> Markup<'c, 'a> {
|
||||
if n.layout.is_none() && !n.children.is_empty() && !root && in_flow {
|
||||
own.push_str("position: relative;\n");
|
||||
}
|
||||
vector_wrapper_decls(n, in_flow, &mut own);
|
||||
decls.push_str(&own);
|
||||
self.rule(path, &class, decls);
|
||||
// The root's variant attributes, and a Vue `v-if` guard, ride on the open tag.
|
||||
@@ -339,6 +399,7 @@ impl<'c, 'a> Markup<'c, 'a> {
|
||||
}
|
||||
let open = |tag: &str| format!("{pad}<{tag} {attr}=\"{class}\"{attrs}>");
|
||||
match &n.kind {
|
||||
NodeKind::Vector { .. } => self.vector_element(n, depth, path, &class, attr, &pad, &attrs),
|
||||
NodeKind::Text(t) => {
|
||||
let body = self.text_body(n, t);
|
||||
self.markup.push_str(&format!("{}{body}</p>\n", open("p")));
|
||||
|
||||
@@ -192,7 +192,9 @@ fn swift_layer(ctx: &Ctx, n: &Node, depth: usize, out: &mut String, extra: &[Str
|
||||
mods.push(format!(".frame(width: {w}, height: {h})"));
|
||||
}
|
||||
}
|
||||
if let Some(c) = stroke_color(n) {
|
||||
if !matches!(n.kind, NodeKind::Vector { .. })
|
||||
&& let Some(c) = stroke_color(n)
|
||||
{
|
||||
mods.push(format!(
|
||||
".overlay(RoundedRectangle(cornerRadius: {corner}).stroke({}, lineWidth: {}))",
|
||||
bound(&["stroke"], swift_color(c)),
|
||||
|
||||
@@ -274,8 +274,10 @@ fn decl(key: &str, value: &str) -> Vec<(String, String)> {
|
||||
("width", "100%") => kw("w-full"),
|
||||
("width", v) => one(spacing("w", v)),
|
||||
("height", v) => one(spacing("h", v)),
|
||||
("max-width", "none") => kw("max-w-none"),
|
||||
("max-width", v) => one(format!("max-w-{}", arb(v))),
|
||||
("min-height", v) => one(format!("min-h-{}", arb(v))),
|
||||
("overflow", "visible") => kw("overflow-visible"),
|
||||
("margin-inline", "auto") => kw("mx-auto"),
|
||||
("gap", v) => one(spacing("gap", v)),
|
||||
("padding", v) => padding(v),
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
# Dev Mode parity
|
||||
|
||||
> **Last reviewed:** 2026-10-24 · **Last updated:** 2026-11-12 · **Change:** patch (SwiftUI, Compose and Flutter code write every visible colour and gradient fill of a frame, group, rectangle or ellipse in paint order, gradients as gradients, instead of one colour per layer (chained `.background` in SwiftUI, chained `Modifier.background` in Compose, a `DecoratedBox` for each fill under the top one in Flutter); CSS code export writes several fills as one layered `background`, top first, as the incumbent does (#2271): a solid above another fill becomes a one-colour gradient, the bottom solid stays a plain colour, Tailwind gets one `[background:...]` class; the Annotation tool (Shift+T, `tool.annotation {id?}`): with a layer selected (or an `id`) it asks the UI for that layer's note at once, and in the tool a press on a layer selects it and asks for its note, a press on empty canvas does nothing; the Inspect tab then opens (never toggles away) with the caret in that layer's new-note field, and the engine never writes the note itself (#1840); the handoff mode reads Developer Mode in the interface, its ids and saved fields unchanged; class names transliterate non-ASCII layer names (#1235); measurements kept on the canvas; a read-only layers panel in Dev Mode; earlier: import lines in generated layer trees; compare with any saved version; Dev Mode behaviour suite: an inspect-only canvas, Changed in the ready list, statuses only on frames and sections; plugin panels from the Inspect tab) · **Target:** Figma Design Dev Mode (desktop app 126.10.7)
|
||||
>
|
||||
> **2026-11-24 patch:** vector code export uses a self-contained SVG asset instead of inventing a box around its bounds: web markup embeds the node-local SVG as a data URI inside a node-sized wrapper with the SVG's painted bounds, and CSS, SwiftUI and ArkUI no longer draw a rectangle from the path stroke (#2270).
|
||||
|
||||
**Breadth ~98%, ready ~78% (estimated).** The inspect surface is broad, components connect
|
||||
to the code components of a repository (with their imports, also inside generated layer trees),
|
||||
@@ -10,6 +12,7 @@ repository, third-party integrations. Remaining: 1–2 h.
|
||||
|
||||
| Feature | Status | Notes |
|
||||
|---|---|---|
|
||||
| 2026-11-24 | patch | Vector code export drew a path's stroke as a box border around its bounds (#2270). CSS, HTML, React, Vue, Leptos and Tailwind no longer invent that border or a rectangular fill; the markup targets embed node-local SVG data URIs, so nested vectors need no external export and URL fragments cannot break them. A node-sized wrapper keeps layout, rotation and opacity, while the inner image uses the SVG's painted bounds with visible overflow. The SVG owns shadows and layer blur, so wrapper CSS does not apply them twice; standalone CSS and ordinary shapes keep theirs. SwiftUI and ArkUI no longer put a rectangle stroke around their vector image either. Ordinary box and ellipse strokes are unchanged. Tests: `dev::codegen::tests::vector_code_uses_its_svg_asset_not_a_box_border`, `dev::codegen::tests::vector_assets_are_self_contained_and_leptos_literals_escape`, `dev::codegen::tests::vector_asset_keeps_stroke_overflow_inside_a_node_sized_wrapper`, `dev::codegen::tests::vector_markup_does_not_duplicate_svg_effects`; real CLI checks nested assets, rotation/opacity, 24→28 stroke bounds and single-application effects |
|
||||
| 2026-11-12 | patch | SwiftUI, Compose and Flutter code export kept one colour per layer (the bottom visible solid, or a gradient's first stop) and dropped every other fill (#2271). Now each writes every visible solid and gradient fill of a frame, group, rectangle or ellipse, in paint order, and a gradient as a gradient. SwiftUI chains `.background(...)` with the top fill first, since each one goes behind the ones before it (a rectangle or ellipse fills with the bottom paint and lays a copy of the shape over it for each paint above). Compose chains `Modifier.background(...)` with the bottom fill first, since each one draws over the ones before it (a linear gradient snaps to eight directions, radial and angular ones sit at the box's centre). Flutter keeps the top fill in the `Container` and wraps each fill under it in a `DecoratedBox`, the bottom fill outermost and the drop shadow on the outermost box. A layer with one solid fill gives the same code as before; a lone gradient is now a gradient, not its first stop's colour. Still not written: image and pattern fills in the native targets, ArkUI (one background and one gradient per component, so a stack needs extra nodes) and text with several fills. The incumbent's iOS and Android output wasn't measured: the order follows how each platform paints. Percentages and hours unchanged |
|
||||
| 2026-11-07 | patch | Naming: the handoff mode is called Developer Mode in the interface, its shortcut row, its toasts, the control channel's refusal, the board refusal, the measurement parameter doc, the `.fig` export note, the CLI help and every catalog (24 languages, translations awaiting native review), since Figma holds a US registration for Dev Mode (7574348); command ids (`view.devMode`, `devMode.*`), preference keys and saved-document fields are unchanged, and the Actions palette still finds the command by the old name |
|
||||
| Dev Mode toggle (Shift+D), Inspect panel | done | the canvas only inspects: presses select, pan and comment but never move, resize, draw or edit text and vectors; menus and shortcuts refuse design edits with a note (Dev Mode's annotations, statuses, dev resources, measurements, code connections and comments still work); a drawing tool chosen in the toolbar goes back to the design. The layers panel only selects and expands (no renaming, reordering, hiding or locking; a double click says why), and the Pages list only opens pages (no adding, renaming, reordering, duplicating or deleting). Files dropped on the canvas aren't imported (a dropped document still opens as a file of its own), and the Assets panel places, swaps and applies nothing, doesn't change Hide when publishing, and doesn't accept library updates or add, remove or swap libraries; each says why |
|
||||
@@ -30,6 +33,7 @@ repository, third-party integrations. Remaining: 1–2 h.
|
||||
|
||||
| Date | Change | Summary |
|
||||
|---|---|---|
|
||||
| 2026-11-24 | patch | Vector code export embeds a self-contained SVG asset, not a rectangle made from the path's stroke (#2270). Percentages and hours unchanged. |
|
||||
| 2026-11-13 | patch | Rows that recent merges had duplicated or garbled are merged back into one row each (no behaviour change): Code: CSS, iOS (SwiftUI), Android (Compose), Flutter. |
|
||||
| 2026-11-12 | patch | CSS code export (#2271): a layer with several fills wrote one `background` per fill, so only the last survived. It now writes one `background` with every visible fill as a layer, top fill first, comma-separated: a solid above another fill is `linear-gradient(0deg, c, c)` (CSS allows a plain colour only as the last layer), the bottom solid stays a plain colour (with its variable), images and patterns keep their `url(...)` layers. Tailwind output carries the layered value as one `[background:...]` class. Text keeps one `color` per fill. Native targets unchanged. Percentages and hours unchanged |
|
||||
| 2026-11-09 | patch | The Annotation tool (Shift+T, `tool.annotation {id?}`): selects the layer pressed on (or the selection, or `id`) and asks the UI for its note, which the Inspect tab takes in its new-note field; the engine writes nothing itself, and Developer Mode lets the tool through its gates (#1840). Figma's placement, cursor and whether the tool stays selected are unmeasured (Developer Mode is paywalled in the web app); staying selected until V or Escape, like the Comment tool, is inferred, and there is no toolbar button or icon yet |
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
# Parity checklist
|
||||
|
||||
> **Generated:** 2026-10-21 by `cargo xtask parity`. Do not edit by hand.
|
||||
> **Generated:** 2026-11-25 by `cargo xtask parity`. Do not edit by hand.
|
||||
|
||||
FigCraft commands registered for the incumbent's main menu and toolbar (575 commands in the engine).
|
||||
FigCraft commands registered for the incumbent's main menu and toolbar (652 commands in the engine).
|
||||
|
||||
**212 / 212 menu items (100.0%)**
|
||||
**215 / 215 menu items (100.0%)**
|
||||
|
||||
Every catalog item has a command.
|
||||
|
||||
|
||||
Reference in new issue
Block a user