Files
James DimachkieandClaude c6f4c9132d An SVG element's transform under a viewBox that doesn't start at 0 0 lands where Chrome puts it
transform-box: view-box, an SVG element's default, takes the nearest viewport as its reference box, and
css-transforms-1 puts that box at the origin of the user space the viewBox sets up, with the viewBox's width and
height. blitz-dom's svg_view_box returned the viewBox's own rectangle, x and y included, and svg_css_transform moves
the origin by the box's corner. So under `viewBox="100 50 400 300"` a `transform-origin` of 0 0 became 100 50:
`<g transform="scale(2)">` drew its content 100 px left of and 50 px above where a browser draws it, and a rotation
turned about the wrong point. A viewBox starting at 0 0, a translate, and a fill-box or stroke-box origin weren't
affected.

svg_view_box now returns the viewBox's size at 0 0. A viewport without a viewBox was at 0 0 already.

bench/svg-css-transform/check.sh gains viewbox.tsx: a square scaled by 2, one turned 180deg about 50% 50%, and one
scaled inside a nested svg with a viewBox of its own, each probed where Chrome 157 draws it (their client rects read
from the same markup in Chrome). The raea before this fails all four probes; with it they pass, and the bench's two
earlier cases are unchanged.

Co-Authored-By: Claude <[email protected]>
2026-11-10 13:16:55 -08:00

20 lines
1.2 KiB
TypeScript

// transform-box: view-box (an SVG element's default) under a viewBox that doesn't start at 0 0: the reference box is the
// viewBox's size at the origin of user space, so a 0 0 origin is user 0 0 and 50% 50% is half the viewBox's size.
// Chrome 157 draws the black square at 100,50 to 220,170, the green at 60,160 to 100,200 and the red at 70,90 to
// 110,130. bench/svg-css-transform/check.sh
import { AbsoluteFill, Composition, registerRoot } from "raea";
function O() {
return (
<AbsoluteFill style={{ background: "#fff" }}>
<svg width={300} height={300} viewBox="100 50 300 300" style={{ position: "absolute", left: 0, top: 0 }}>
<rect x={100} y={50} width={40} height={40} fill="#008000" style={{ transformOrigin: "50% 50%", transform: "rotate(180deg)" }} />
<g transform="scale(2)"><rect x={100} y={50} width={60} height={60} fill="#000" /></g>
<svg x={150} y={100} width={100} height={100} viewBox="10 20 50 50">
<rect x={10} y={20} width={10} height={10} fill="#f00" transform="scale(2)" />
</svg>
</svg>
</AbsoluteFill>
);
}
registerRoot(() => <Composition id="o" component={O} width={300} height={300} fps={30} durationInFrames={1} />);