fix: count default-filled polylines when detecting tintable SVGs

This commit is contained in:
Marco Beretta 2026-06-23 11:25:46 +02:00
parent bc0fbed488
commit 0073ac106d
No known key found for this signature in database
GPG key ID: D918033D8E74CC11
2 changed files with 16 additions and 2 deletions

View file

@ -100,6 +100,17 @@ describe('isMonochromeSvg', () => {
expect(isMonochromeSvg(svg)).toBe(false);
});
it('rejects an explicit badge alongside a default-black polyline glyph', () => {
const svg =
'<svg viewBox="0 0 24 24"><rect x="0" y="0" width="8" height="8" fill="#fff" /><polyline points="6,6 18,6 18,18 6,18" /></svg>';
expect(isMonochromeSvg(svg)).toBe(false);
});
it('tints a glyph drawn as a single default-black polyline', () => {
const svg = '<svg viewBox="0 0 24 24"><polyline points="6,6 18,6 18,18 6,18" /></svg>';
expect(isMonochromeSvg(svg)).toBe(true);
});
it('inherits an ancestor fill instead of assuming the default black', () => {
const svg = '<svg viewBox="0 0 24 24"><g fill="#333"><path d="M4 4h16v16H4z" /></g></svg>';
expect(isMonochromeSvg(svg)).toBe(true);

View file

@ -35,8 +35,11 @@ const GRAY_LEVELS = new Map<string, number>([
/** Paint properties whose color values determine whether an SVG is monochrome. */
const PAINT_PROPS = ['fill', 'stroke', 'stop-color'];
/** Area shapes that render with SVG's default black fill when none is supplied. */
const FILLABLE_SHAPES = 'path, rect, circle, ellipse, polygon, text';
/**
* Shapes that render with SVG's default black fill when none is supplied. Includes
* `polyline` (SVG closes it for fill painting) but not `line`, which has no area.
*/
const FILLABLE_SHAPES = 'path, rect, circle, ellipse, polygon, polyline, text';
/**
* Containers whose descendants supply functional paint (clipping, masking,