Skip to content

An inline SVG's CSS transform: a style of transforms alone turns its shape, and view-box origins are at user 0 0 - #92

Merged
shinyobjectz merged 2 commits into
shinyobjectz:mainfrom
JimGHTB12:svg-css-transforms
Nov 10, 2026
Merged

shinyobjectz merged 2 commits into
shinyobjectz:mainfrom
JimGHTB12:svg-css-transforms

Conversation

@JimGHTB12

Copy link
Copy Markdown
Contributor

Two faults in how an inline SVG's CSS transform reaches usvg, both in vendor/blitz-dom/src/node/serialize.rs. One commit each.

1. A style attribute holding transforms alone draws unturned

<rect x={50} y={50} width={200} height={200} style={{ transform: "rotate(30deg)" }} />

draws unturned. So does a style with only transformBox, transformOrigin and transform. Add a fill to the same style and it turns.

Why. Since de1a683 the computed transform is written into the element's style attribute for usvg: the element's own transform declarations are taken out and ;transform:matrix(...);transform-origin:0 0 is added after what is left. When nothing is left, the attribute starts with ;. usvg reads style attributes with simplecss, whose declaration parser stops at a ; before the first declaration (DeclarationTokenizer::next jumps to the end on the error), so every declaration in the attribute is dropped.

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

The bench that missed it. bench/svg-css-transform/check.sh compares mixed.tsx's two squares with each other. Both are of this kind, both draw unturned, and the comparison passes at 0 px. The check now also probes each square on its turned top edge and where its unturned edge would be.

2. transform-box: view-box under a viewBox that doesn't start at 0 0

<svg width={400} height={300} viewBox="100 50 400 300">
  <g transform="scale(2)"><rect x={100} y={50} width={40} height={40} /></g>
</svg>

Chrome 157 draws the square at 100,50 to 180,130. raea drew it at 0,0 to 80,80.

Why. css-transforms-1 puts the view-box reference box at the origin of the user space the viewBox sets up, with the viewBox's width and height. 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 a transform-origin of 0 0 became 100 50. Every scale or rotation under such a viewBox turned about the wrong point. A translate, a viewBox at 0 0, and a fill-box or stroke-box origin were not affected.

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

Testing

bench/svg-css-transform/check.sh gains viewbox.tsx (a group scaled by 2, a square turned 180deg about 50% 50%, and a square scaled inside a nested svg with its own viewBox) and eight probes. The expected places are the client rects Chrome 157 reports for the same markup.

main this branch
the two earlier comparisons ok (75 px, 0 px) ok (75 px, 0 px)
mixed.tsx: each square's turned top edge, and its unturned one empty (4 probes) 4 fail 4 pass
viewbox.tsx: scale, 50% 50% origin, nested viewBox (4 probes) 4 fail 4 pass

Five more single-shape pages under viewBox="100 50 400 300", a 40x20 rect at user 200,150, each against Chrome 157's client rect:

the rect's transform Chrome 157 main this branch
style rotate(90deg), origin 50% 50% 80,100 to 100,140 100,100 to 140,120 (unturned) 80,100 to 100,140
the same with transform-box: view-box 80,100 to 100,140 unturned 80,100 to 100,140
attribute rotate(90), style origin 50% 50% 80,100 to 100,140 unturned 80,100 to 100,140
style rotate(10deg) 67.4,132.5 to 110.3,159.1 unturned 68,133 to 110,159
style rotate(90deg), origin 200px 150px 80,100 to 100,140 unturned 80,100 to 100,140

The original report's page (viewBox="100 50 400 300", a 40 px square under scale(2)): Chrome 157 has it at 100,50 to 180,130, main draws it at 0,0 to 80,80, this branch at 100,50 to 180,130.

With the second commit alone, the scaled group and the nested one landed where Chrome puts them and the 50% 50% square stayed unturned, which is how the first fault showed up.

Run on Windows 11 (Vulkan) with release builds, main at bb0a176. On main the bench's stills don't start at all since bb0a176 (see the stills-folder pull request), so for these runs the output folders were made first. tools/size.sh, layers.sh, names.sh, one-version.sh, no-void.sh and public-guard.sh pass on the branch.

Not run: macOS and Linux, the WPT css-transforms set, and the P26 rows that draw SVG. cargo dupes and cargo shear aren't installed here.

Reviewed over three rounds by GPT-6.1 Sol (high effort), a different model family from the one that wrote it. Its findings were about the style rewrite (a comment or an author's own ; before the first declaration), and all are fixed; the last round found nothing more.

Created with Claude Fable 5.2 in T3 Code (Claude Code).

🤖 Generated with Claude Code

JimGHTB12 and others added 2 commits November 10, 2026 13:16
…y them

Since de1a683 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 <noreply@anthropic.com>
…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 <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-10T22:01:42.050933Z c6f4c91 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@shinyobjectz
shinyobjectz merged commit ff3515e into shinyobjectz:main Nov 10, 2026
4 checks passed
@shinyobjectz

Copy link
Copy Markdown
Owner

Merged, thanks. The strengthened probes in bench/svg-css-transform are the part I'm most glad of: the old check passed both squares unturned.

shinyobjectz added a commit that referenced this pull request Nov 16, 2026
…y (80067cc, pushed and merged), with #91's characters guide and #92's reference/feed.md (plan_close, raea-feed #61), whose stale copy failed every lane's L0 and L1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants