Commit Graph
3 Commits
Author SHA1 Message Date
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
James DimachkieandClaude eb3c8ea6bf An SVG shape whose style attribute holds transforms alone is turned by them
Since de1a6830 an SVG element's computed transform goes to usvg in its style attribute: the element's own
transform declarations are taken out and `;transform:matrix(...);transform-origin:0 0` is written after what is
left. When the style held nothing else, nothing was left, and the attribute began with `;`. usvg reads a style
attribute with simplecss, whose declaration parser stops at a `;` before the first declaration, so every
declaration in it was dropped: `<rect style={{ transform: "rotate(30deg)" }}>` drew unturned, and so did one with
only transform-box, transform-origin and transform. A style that also set a fill or a stroke was read.

The element's own declarations are now written from the first of them on (without the separators, spaces and
comments CSS allows before it, which stop simplecss the same way), and the separator only after them when there are
any.

bench/svg-css-transform/check.sh compared mixed.tsx's two squares with each other. Both are of this kind, both drew
unturned, and the comparison passed at 0 px. The check now also probes each square on its turned top edge and where
its unturned edge would be. The raea before this fails those four probes; with it they pass, and the two comparisons
read 75 and 0 px as before.

Co-Authored-By: Claude <[email protected]>
2026-11-10 13:16:55 -08:00
shinyobjectz de1a6830c2 An SVG shape's transform from a <style> inside its <svg> turns it, as Chrome does (closes #60)
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).
2026-11-08 13:34:33 -08:00