Render Anything Engine: tell your AI what to make. Videos, motion graphics, 3D and games as React and TypeScript, rendered on your own GPU. Rust + Bevy, macOS, Linux and Windows.
TypeScript 3dagent-skillsai-agentsai-videobevyclaude-codegame-enginegpulinuxmacosmotion-designmotion-graphicsreactrusttypescriptvideo-editingvideo-renderingwgpuwindows
An SVG shape's transform from a <style> inside its <svg> turns it, as Chrome does (closes #60)
shinyobjectzde1a6830c29f
diff --git a/bench/svg-css-transform/check.sh b/bench/svg-css-transform/check.shnew file mode 100755index 00000000..26c1ee55--- /dev/null+++ b/bench/svg-css-transform/check.sh@@ -0,0 +1,27 @@+#!/bin/bash+# #60: an SVG shape's transform, transform-box and transform-origin from a <style> inside its <svg> turn it, as Chrome+# does. A composition's <style> there goes to usvg in the SVG's markup, and usvg applied that sheet's transform and+# transform-origin over the transform raea had computed from the cascade (`rotate(30deg)`, which SVG's syntax can't+# read: the shape drew unturned). sheet.tsx's class-turned square (red) must be the inline-turned one (green) moved+# 600 px (each recoloured black, so only its shape counts), and mixed.tsx's class box and origin with an inline turn+# must be the all-inline square. Before: 8827 and 5598 px differed. Exits 1 on a failure.+# bench/svg-css-transform/check.sh (RAEA_BIN: the raea to run, default target/release/raea)+cd "$(dirname "$0")/../.." || exit 2+BIN=${RAEA_BIN:-$PWD/target/release/raea}+export RAEA_SIGN=0 RAEA_MARK=0 RAEA_EXPORT_CACHE=0+OUT=$(mktemp -d "${TMPDIR:-/tmp}/raea-svg-css-transform.XXXXXX")+trap 'rm -rf "$OUT"' EXIT+status=0+for c in sheet mixed; do+ "$BIN" render bench/svg-css-transform/$c.tsx --at 0 -o "$OUT/$c" > "$OUT/$c.log" 2>&1 && [ -f "$OUT/$c/frame-00000.png" ] || { echo "FAIL $c: the render failed"; sed 's/^/ /' "$OUT/$c.log" | tail -4; exit 1; }+done+same() { # PNG LEFT-COLOUR RIGHT-COLOUR MAX WHAT+ magick "$1" -crop 300x300+0+0 +repage -fuzz 35% -fill black -opaque "$2" "$OUT/a.png"+ magick "$1" -crop 300x300+600+0 +repage -fuzz 35% -fill black -opaque "$3" "$OUT/b.png"+ local d; d=$(magick compare -metric AE -fuzz 10% "$OUT/a.png" "$OUT/b.png" null: 2>&1 | cut -d' ' -f1)+ (( ${d%.*} <= $4 )) && echo "ok $5 ($d px differ)" || { echo "FAIL $5: $d px differ, at most $4"; status=1; }+}+same "$OUT/sheet/frame-00000.png" "#e0245e" "#17bf63" 300 "a class's transform, box and origin turn it as inline ones do"+same "$OUT/mixed/frame-00000.png" "#000000" "#000000" 50 "a class's box and origin with an inline turn"+[ $status = 0 ] && echo "PASS SVG transforms from a stylesheet"+exit $statusdiff --git a/bench/svg-css-transform/mixed.tsx b/bench/svg-css-transform/mixed.tsxnew file mode 100644index 00000000..9b8926c2--- /dev/null+++ b/bench/svg-css-transform/mixed.tsx@@ -0,0 +1,16 @@+// #60: a class giving transform-box and transform-origin (from a <style> inside the <svg>) with the transform inline+// (left), against all three inline (right). Both turn 30deg about their centres, so the two are the same picture.+// bench/svg-css-transform/check.sh+import { AbsoluteFill, Composition, registerRoot } from "raea";+function O() {+ return (+ <AbsoluteFill style={{ background: "#fff" }}>+ <svg width={900} height={300}>+ <style>{`.box { transform-box: fill-box; transform-origin: center; } .k { stroke: #000; stroke-width: 6; fill: none; }`}</style>+ <rect className="box k" x={50} y={50} width={200} height={200} style={{ transform: "rotate(30deg)" }} />+ <rect className="k" x={650} y={50} width={200} height={200} style={{ transformBox: "fill-box", transformOrigin: "center", transform: "rotate(30deg)" }} />+ </svg>+ </AbsoluteFill>+ );+}+registerRoot(() => <Composition id="o" component={O} width={900} height={300} fps={30} durationInFrames={1} />);diff --git a/bench/svg-css-transform/sheet.tsx b/bench/svg-css-transform/sheet.tsxnew file mode 100644index 00000000..f91cbd90--- /dev/null+++ b/bench/svg-css-transform/sheet.tsx@@ -0,0 +1,18 @@+// #60: an SVG shape turned by a <style> inside its <svg> (red: transform-box, transform-origin and transform from a+// class), by the transform attribute (blue) and by the three set inline (green). Chrome turns all three 30deg about+// their centres. bench/svg-css-transform/check.sh+import { AbsoluteFill, Composition, registerRoot } from "raea";+function O() {+ return (+ <AbsoluteFill style={{ background: "#fff" }}>+ <svg width={900} height={300}>+ <style>{`.css { fill: none; stroke: #e0245e; stroke-width: 6; transform-box: fill-box; transform-origin: center; transform: rotate(30deg); }+ .attr { fill: none; stroke: #1d9bf0; stroke-width: 6; }`}</style>+ <rect className="css" x={50} y={50} width={200} height={200} />+ <rect className="attr" x={350} y={50} width={200} height={200} transform="rotate(30 450 150)" />+ <rect x={650} y={50} width={200} height={200} style={{ fill: "none", stroke: "#17bf63", strokeWidth: 6, transformBox: "fill-box", transformOrigin: "center", transform: "rotate(30deg)" }} />+ </svg>+ </AbsoluteFill>+ );+}+registerRoot(() => <Composition id="o" component={O} width={900} height={300} fps={30} durationInFrames={1} />);diff --git a/vendor/blitz-dom/src/node/serialize.rs b/vendor/blitz-dom/src/node/serialize.rsindex 790d2141..b9f8ebf2 100644--- a/vendor/blitz-dom/src/node/serialize.rs+++ b/vendor/blitz-dom/src/node/serialize.rs@@ -438,19 +438,26 @@ impl Node {.flatten();#[cfg(not(feature = "svg"))]let css_transform: Option<String> = None;- if let Some(t) = css_transform.as_deref().filter(|t| !t.is_empty()) {- writer.push_str(" transform=\"");- writer.push_str(t);- writer.push('"');- }// raea: the SVG paint properties CSS sets on it (a stylesheet's, a class's), into its style attribute (#45)#[cfg(feature = "svg")]- let css_paint = (opts.resolve_current_color && data.name.ns == ns!(svg))+ let mut css_paint = (opts.resolve_current_color && data.name.ns == ns!(svg)).then(|| self.svg_css_paint(current_color.as_deref())).unwrap_or_default();#[cfg(not(feature = "svg"))]- let css_paint = String::new();+ let mut css_paint = String::new();+ // raea: and the computed transform there too, with its origin already in the matrix: a <style> inside+ // the svg goes to usvg with it, and usvg applies that sheet's transform and transform-origin over a+ // transform attribute (`rotate(30deg)`, which SVG's syntax can't read, so the shape drew unturned, #60).+ // A style attribute's declarations win over a sheet's in usvg, as in CSS. The identity is written too,+ // so a sheet's transform can't turn a shape the cascade leaves unturned.+ if let Some(t) = css_transform.as_deref() {+ let t = if t.is_empty() { "matrix(1 0 0 1 0 0)" } else { t };+ if !css_paint.is_empty() {+ css_paint.push(';');+ }+ css_paint.push_str(&format!("transform:{t};transform-origin:0 0"));+ }for attr in data.attrs() {if css_transform.is_some()&& attr.name.ns == ns!()