Theme icons: glyphs drawn whole in the icon's content box
Live 2026-10-01: X's search-field icon is a 28x16 box with 12px of padding; sized at 100% of that width a pixel glyph lost its top and bottom and sat left of X's own icon. Glyphs are now sized with contain (a scaled pack by the box's height) and placed in the content box, for masks and images alike.
This commit is contained in:
parent
48ed7c2d23
commit
13ac2827fe
2 changed files with 9 additions and 6 deletions
|
|
@ -268,14 +268,17 @@ export function compileIcons(pack: IconPack | null, theme: ThemeIcons | null | u
|
||||||
const gate = ctx.gate ? `html[${ctx.gate}~="${matcher.group}"] ` : '';
|
const gate = ctx.gate ? `html[${ctx.gate}~="${matcher.group}"] ` : '';
|
||||||
const selectors = iconSelectors(matcher).map(one => `${gate}${one}`);
|
const selectors = iconSelectors(matcher).map(one => `${gate}${one}`);
|
||||||
if (!selectors.length) continue;
|
if (!selectors.length) continue;
|
||||||
const size = `${Math.round(style.scale * 100)}%`;
|
// Drawn in the content box, whole (live 2026-10-01: X's search field icon is a 28x16 box with 12px of
|
||||||
|
// padding, and `100%` of that width cut the top and bottom off a pixel glyph and moved it left);
|
||||||
|
// a scaled pack is sized by the box's height, the smaller side of every icon box X draws.
|
||||||
|
const size = style.scale === 1 ? 'contain' : `auto ${Math.round(style.scale * 100)}%`;
|
||||||
if ('png' in glyph) {
|
if ('png' in glyph) {
|
||||||
colored.push(`${selectors.join(',')}{background:url("${glyph.png}") center / ${size} no-repeat !important;${glyph.pixel ? 'image-rendering:pixelated;' : ''}}`);
|
colored.push(`${selectors.join(',')}{background:url("${glyph.png}") center / ${size} no-repeat content-box !important;${glyph.pixel ? 'image-rendering:pixelated;' : ''}}`);
|
||||||
} else {
|
} else {
|
||||||
const svg = glyphSvg(glyph, style, ctx.colors);
|
const svg = glyphSvg(glyph, style, ctx.colors);
|
||||||
if (!svg) continue;
|
if (!svg) continue;
|
||||||
if (isColored(glyph)) colored.push(`${selectors.join(',')}{background:${svgUrl(svg)} center / ${size} no-repeat !important}`);
|
if (isColored(glyph)) colored.push(`${selectors.join(',')}{background:${svgUrl(svg)} center / ${size} no-repeat content-box !important}`);
|
||||||
else masked.push(`${selectors.join(',')}{background-color:currentColor !important;-webkit-mask:${svgUrl(svg)} center / ${size} no-repeat;mask:${svgUrl(svg)} center / ${size} no-repeat}`);
|
else masked.push(`${selectors.join(',')}{background-color:currentColor !important;-webkit-mask:${svgUrl(svg)} center / ${size} no-repeat content-box;mask:${svgUrl(svg)} center / ${size} no-repeat content-box}`);
|
||||||
}
|
}
|
||||||
hidden.push(...selectors.map(one => `${one} > *`));
|
hidden.push(...selectors.map(one => `${one} > *`));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -223,13 +223,13 @@ test('icons are drawn as masks of the current color (colored glyphs as images),
|
||||||
const out = compileIcons(PACK, null, TABLE, { colors: COLORS, gate: 'data-wb-icons' });
|
const out = compileIcons(PACK, null, TABLE, { colors: COLORS, gate: 'data-wb-icons' });
|
||||||
assert.ok(out.startsWith('@media (forced-colors:none){@supports ((mask-image:url("")) or (-webkit-mask-image:url(""))){'));
|
assert.ok(out.startsWith('@media (forced-colors:none){@supports ((mask-image:url("")) or (-webkit-mask-image:url(""))){'));
|
||||||
const home = out.split('\n').find(line => line.startsWith('html[data-wb-icons~="nav"] [data-nav="home"] svg{'))!;
|
const home = out.split('\n').find(line => line.startsWith('html[data-wb-icons~="nav"] [data-nav="home"] svg{'))!;
|
||||||
assert.ok(home.includes('background-color:currentColor !important') && home.includes('-webkit-mask:url("data:image/svg+xml,') && home.includes('mask:url("data:image/svg+xml,') && home.includes('/ 90% no-repeat'));
|
assert.ok(home.includes('background-color:currentColor !important') && home.includes('-webkit-mask:url("data:image/svg+xml,') && home.includes('mask:url("data:image/svg+xml,') && home.includes('/ auto 90% no-repeat content-box'));
|
||||||
const svgOf = (line: string) => decodeURIComponent(/url\("data:image\/svg\+xml,([^"]*)"\)/.exec(line)![1]!);
|
const svgOf = (line: string) => decodeURIComponent(/url\("data:image\/svg\+xml,([^"]*)"\)/.exec(line)![1]!);
|
||||||
assert.ok(svgOf(home).includes('stroke-width="2" stroke-linecap="square" stroke-linejoin="miter"'), 'the pack\'s stroke style');
|
assert.ok(svgOf(home).includes('stroke-width="2" stroke-linecap="square" stroke-linejoin="miter"'), 'the pack\'s stroke style');
|
||||||
const reply = out.split('\n').find(line => line.startsWith('html[data-wb-icons~="actions"] [data-act="reply"] svg{'))!;
|
const reply = out.split('\n').find(line => line.startsWith('html[data-wb-icons~="actions"] [data-act="reply"] svg{'))!;
|
||||||
assert.ok(reply.includes('background:url("data:image/svg+xml,') && !reply.includes('mask'), 'layers carry their own colors');
|
assert.ok(reply.includes('background:url("data:image/svg+xml,') && !reply.includes('mask'), 'layers carry their own colors');
|
||||||
assert.ok(svgOf(reply).includes(`fill="${COLORS.accent}" opacity="0.8"`) && svgOf(reply).includes('<linearGradient id="g0"'));
|
assert.ok(svgOf(reply).includes(`fill="${COLORS.accent}" opacity="0.8"`) && svgOf(reply).includes('<linearGradient id="g0"'));
|
||||||
assert.ok(out.includes('svg:has(> g > path[d^="M12 2.59l5.7 5.7"]){background:url("data:image/png;base64,iVBORw0KGgo=") center / 90% no-repeat !important;image-rendering:pixelated;}'));
|
assert.ok(out.includes('svg:has(> g > path[d^="M12 2.59l5.7 5.7"]){background:url("data:image/png;base64,iVBORw0KGgo=") center / auto 90% no-repeat content-box !important;image-rendering:pixelated;}'));
|
||||||
assert.ok(out.includes('[data-act="unlike"] svg > *') && out.includes('{opacity:0 !important}'), 'the site\'s own paths are hidden, not removed');
|
assert.ok(out.includes('[data-act="unlike"] svg > *') && out.includes('{opacity:0 !important}'), 'the site\'s own paths are hidden, not removed');
|
||||||
assert.ok(!out.includes('explore') && !out.includes('script'), 'no glyph: the site\'s icon stays; a signature that is not path data is never written');
|
assert.ok(!out.includes('explore') && !out.includes('script'), 'no glyph: the site\'s icon stays; a signature that is not path data is never written');
|
||||||
// No encoded quote can end the url("…") early.
|
// No encoded quote can end the url("…") early.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue