mirror of
https://github.com/shinyobjectz/raea.git
synced 2026-12-01 12:44:11 -10:00
In a composition, a <style> inside an <svg> goes to usvg in the SVG's markup (raea's HTML host turns it into a hidden div first, so HTML pages weren't hit). Blitz had already computed the shape's transform from the cascade, with its transform-box and transform-origin, and written it as a transform attribute; usvg then applied the sheet's own transform and transform-origin over it. `rotate(30deg)` isn't SVG transform syntax, so the shape drew unturned, and a class giving only transform-box and transform-origin turned an inline transform about the SVG's 0,0. The computed transform now goes into the element's style attribute with transform-origin: 0 0 (its origin is in the matrix), where usvg lets it win over a sheet's rule as CSS does; the identity is written too, so a sheet can't turn a shape the cascade leaves unturned. The separate transform attribute is no longer written. bench/svg-css-transform/check.sh: the class-turned square against the inline-turned one, 78 px differ (antialiased edges; before 8827), and a class's box and origin with an inline turn against all-inline, 0 px (before 5598). The svg-css-paint, svg-stroke-box, rotated-paint and background-clip-text benches pass; the P26 rows that draw SVG score the same as before (studio 3/3, css/svg 1/1; bevy/datamaps is 0.971-0.976 on main with or without this).
19 lines
1.2 KiB
TypeScript
19 lines
1.2 KiB
TypeScript
// #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} />);
|