Repository navigation
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
Conversation
…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>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
draws unturned. So does a style with only
transformBox,transformOriginandtransform. Add afillto 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 0is 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::nextjumps 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.shcomparesmixed.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-boxunder a viewBox that doesn't start at 0 0Chrome 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_boxreturned the viewBox's own rectangle, x and y included, andsvg_css_transformmoves the origin by the box's corner, so atransform-originof 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_boxreturns the viewBox's size at 0 0. A viewport without a viewBox was at 0 0 already.Testing
bench/svg-css-transform/check.shgainsviewbox.tsx(a group scaled by 2, a square turned 180deg about50% 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.mixed.tsx: each square's turned top edge, and its unturned one empty (4 probes)viewbox.tsx: scale,50% 50%origin, nested viewBox (4 probes)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:rotate(90deg), origin50% 50%transform-box: view-boxrotate(90), style origin50% 50%rotate(10deg)rotate(90deg), origin200px 150pxThe original report's page (
viewBox="100 50 400 300", a 40 px square underscale(2)): Chrome 157 has it at 100,50 to 180,130,maindraws 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,
mainat bb0a176. Onmainthe 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.shandpublic-guard.shpass on the branch.Not run: macOS and Linux, the WPT css-transforms set, and the P26 rows that draw SVG.
cargo dupesandcargo sheararen'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