Repository navigation
blitz: responsive srcset/sizes selection and inline SVG stylesheet fill/stroke - #210
BernardoPe wants to merge 5 commits into
Conversation
8f03280 to
996a5a3
Compare
996a5a3 to
0d9efa7
Compare
01cad62 to
b7b647b
Compare
b7b647b to
a47553a
Compare
a47553a to
349fe1e
Compare
349fe1e to
502d3e5
Compare
| + && parent_styles | ||
| + .as_ref() | ||
| + .is_some_and(|ps| ps.clone_fill().kind == *fill_kind); | ||
| + if !fill_is_initial && !fill_inherited { |
There was a problem hiding this comment.
beep-boop-rui-agent-🤖
Blocking: an inherited CSS fill still overrides a fill set on an ancestor <g> or <use>.
This fixes the case where the element has its own fill= attribute, but not the other half of the multi-colour icon case from the earlier thread.
When the element has no fill attribute, has_own_fill is false, so fill_inherited is false. The code then stamps the value the element inherited through Stylo. Stylo never sees the fill attribute on the <g> in between. The stamped attribute on the child beats inheritance in usvg, so the child paints the CSS colour instead of the <g> colour.
Two common patterns hit this:
- Sketch-style exports:
svg { fill: currentColor }with<g fill="none"><g fill="#FFF"><path/></g></g>. The path paintscurrentColor, not white. - Same-document sprites:
<symbol>paths used through<use fill="red">. The DOM parent chain issymbol → defs → svg, so the path is stampedcurrentColor, not red.
On the base branch nothing is stamped, so both cases inherit the <g> or <use> colour, as in Chrome. stroke has the same problem (line 440).
Fix: stamp only where the computed value differs from the DOM parent's computed value, whether or not the element has its own attribute. Stamp the snapshot root too, so that direct children of a CSS-filled <svg> still get the CSS colour. Tests in svg_mutation_resnapshot.rs:
svg { fill: #dd0000 }with<g fill="#0000ff"><rect/></g>paints a blue rect.- The same with
<g fill="none">paints no fill.
There was a problem hiding this comment.
Fixed in aa36fa1c: updated blitz-dom patch 0112 (src/node/serialize.rs) to stamp computed fill/stroke on the root <svg> when non-initial and on descendants only when their computed paint (with currentColor resolved) differs from their DOM parent, so ancestor <g fill> / <use fill> attributes are preserved. Added tests for <g fill="#0000ff">, <g fill="none">, and <use fill="#0000ff"> in packages/core/src/paint/tests/svg_mutation_resnapshot.rs.
502d3e5 to
aa36fa1
Compare
ruifigueira
left a comment
There was a problem hiding this comment.
beep-boop-rui-agent-🤖
The blocking findings are fixed. Approving.
abb73ba to
a6e90cd
Compare
`select_image_url` ignored `sizes` and `<source media="...">`, always picking the largest width descriptor regardless of the viewport or declared slot size (causing oversized hero and article images on nasa.gov and docs.github.com). Evaluate `sizes` (defaulting to `100vw`) against the viewport width and DPR, picking the smallest width candidate that covers `source_size * dpr` (or the largest available if none does), and skip `<picture><source>` elements whose `media` condition does not match the viewport. https://html.spec.whatwg.org/multipage/images.html#selecting-an-image-source-from-the-source-set Signed-off-by: bpereira <bpereira@cloudflare.com>
usvg only sees the serialized SVG snapshot, never document stylesheets, so
author CSS rules targeting SVG children (such as `.logo path { fill: #a31f34 }`
for the MIT wordmark) were dropped and elements painted with default black fill
or no stroke.
Stamp non-initial computed `fill` and `stroke` onto SVG graphics and group
descendants during usvg serialization via `paint_attr`, leaving initial values
unstamped so explicit presentation attributes and inherited `<svg fill>` remain
intact.
https://svgwg.org/svg2-draft/styling.html#PresentationAttributes
Signed-off-by: bpereira <bpereira@cloudflare.com>
…ributes and honour viewport for responsive images
Skip stamping computed CSS fill/stroke onto inline SVG descendants when
the element carries its own attribute and its computed value matches its
parent's (so inherited rules like `svg { fill: currentColor }` no longer
overwrite `<path fill="none">` or explicit child colours), lazily
borrowing parent styles only when own fill/stroke attributes are present.
Pass the initial viewport dimensions into DomHandle::newUtf8 before HTML
parsing and track responsive_image_urls on BaseDocument so viewport width
changes re-select only responsive <img> candidates whose URL changed.
Cap calc() nesting depth in sizes/media parsing, inherit <img sizes> for
<picture><source> elements without sizes, and evaluate prefers-color-scheme,
orientation, height, and case-insensitive AND in media conditions.
Signed-off-by: bpereira <bpereira@cloudflare.com>
…iffer Inherited CSS fill/stroke was still stamped on descendants without their own attribute, overriding fill/stroke set on an ancestor <g> or <use>. Stamp the snapshot root when non-initial and stamp descendants only when the computed paint differs from the DOM parent's. Signed-off-by: bpereira <bpereira@cloudflare.com>
…rentColor Compute parent_styles for the root <svg> from its HTML parent so inherited CSS fill/stroke does not override the root element's own presentation attributes. Stamp literal currentColor on the root so usvg resolves it against color= attributes on <svg> or descendant <g> elements. Signed-off-by: bpereira <bpereira@cloudflare.com>
a6e90cd to
e5a99ae
Compare
Part 5 of 5 in a stacked compatibility series (stacked on #209).
Changes
srcset/sizesand<picture><source media>(blitz-dompatch0105): Evaluatesizes(defaulting to100vw) against the viewport width and DPR, selecting the smallest width descriptor that coverssource_size * dpr(or the largest available if none does), and skip<picture><source>elements whosemediacondition does not match the viewport (nasa.gov, docs.github.com).fill/strokeon inline SVG descendants (blitz-dompatch0106): Stamp non-initial computedfillandstrokeonto SVG graphics and group descendants during usvg serialization viapaint_attrso author CSS rules targeting SVG children reach usvg, while leaving initial values unstamped so explicit presentation attributes and inherited<svg fill>stay intact (mit.edu).Verification
packages/engine/test/e2e/img-srcset-sizes.e2e.test.tspackages/core/src/paint/tests/svg_mutation_resnapshot.rs(stylesheet_fill_and_stroke_reach_inline_svg_snapshot)