Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mostly fix monochrome svg rendering color and styling #1700

Merged
merged 11 commits into from
Dec 27, 2024
10 changes: 10 additions & 0 deletions dev/data/structured-content-overrides.css
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,13 @@
.gloss-sc-summary {
/* remove-rule */
}
.gloss-image-background {
background-color: currentColor;
/* remove-property display */
}
.gloss-image-link:not([data-appearance=monochrome]) .gloss-image-background {
display: none;
}
.gloss-image-link[data-appearance=monochrome] .gloss-image {
opacity: 0;
}
16 changes: 12 additions & 4 deletions ext/css/structured-content.css
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
/* Glossary images */
.gloss-image-container {
display: inline-block;
white-space: nowrap;
max-width: 100%;
max-height: 100vh;
position: relative;
Expand Down Expand Up @@ -85,14 +86,21 @@
mask-mode: alpha;
mask-size: contain;
mask-image: var(--image);
display: none;
}
.gloss-image {
display: inline-block;
vertical-align: top;
object-fit: contain;
border: none;
outline: none;
}
.gloss-image-link[data-has-aspect-ratio=true] .gloss-image {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
}
.gloss-image-link[data-image-rendering=pixelated] .gloss-image,
.gloss-image-link[data-image-rendering=pixelated] .gloss-image-background {
Expand Down Expand Up @@ -137,10 +145,10 @@
}

.gloss-image-link[data-appearance=monochrome] .gloss-image {
filter: grayscale(1);
}
.gloss-image-link:not([data-appearance=monochrome]) .gloss-image-background {
display: none;
/* Workaround for coloring monochrome gloss images due to issues with masking using a canvas without loading extra media */
/* drop-shadow with 0.01px blur is at minimum required for Firefox to render the shadow when used on a canvas */
--shadow-settings: 0 0 0.01px var(--text-color);
filter: grayscale(1) opacity(0.5) drop-shadow(var(--shadow-settings)) drop-shadow(var(--shadow-settings)) saturate(1000%) brightness(1000%);
}

.gloss-image-link[data-size-units=em] .gloss-image-container {
Expand Down
34 changes: 23 additions & 11 deletions ext/data/structured-content-style.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"selectors": [".gloss-image-container"],
"styles": [
["display", "inline-block"],
["white-space", "nowrap"],
["max-width", "100%"],
["max-height", "100vh"],
["position", "relative"],
Expand Down Expand Up @@ -66,7 +67,6 @@
["top", "0"],
["width", "100%"],
["height", "100%"],
["background-color", "var(--text-color)"],
["-webkit-mask-repeat", "no-repeat"],
["-webkit-mask-position", "center center"],
["-webkit-mask-mode", "alpha"],
Expand All @@ -76,7 +76,8 @@
["mask-position", "center center"],
["mask-mode", "alpha"],
["mask-size", "contain"],
["mask-image", "var(--image)"]
["mask-image", "var(--image)"],
["background-color", "currentColor"]
]
},
{
Expand All @@ -86,8 +87,17 @@
["vertical-align", "top"],
["object-fit", "contain"],
["border", "none"],
["outline", "none"],
["width", "100%"]
["outline", "none"]
]
},
{
"selectors": [".gloss-image-link[data-has-aspect-ratio=true] .gloss-image"],
"styles": [
["position", "absolute"],
["left", "0"],
["top", "0"],
["width", "100%"],
["height", "100%"]
]
},
{
Expand Down Expand Up @@ -164,13 +174,9 @@
{
"selectors": [".gloss-image-link[data-appearance=monochrome] .gloss-image"],
"styles": [
["filter", "grayscale(1)"]
]
},
{
"selectors": [".gloss-image-link:not([data-appearance=monochrome]) .gloss-image-background"],
"styles": [
["display", "none"]
["--shadow-settings", "0 0 0.01px var(--text-color)"],
["filter", "grayscale(1) opacity(0.5) drop-shadow(var(--shadow-settings)) drop-shadow(var(--shadow-settings)) saturate(1000%) brightness(1000%)"],
["opacity", "0"]
]
},
{
Expand Down Expand Up @@ -329,5 +335,11 @@
["border-width", "1px"],
["border-color", "currentColor"]
]
},
{
"selectors": [".gloss-image-link:not([data-appearance=monochrome]) .gloss-image-background"],
"styles": [
["display", "none"]
]
}
]
5 changes: 5 additions & 0 deletions ext/js/display/structured-content-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ export class StructuredContentGenerator {
const imageContainer = this._createElement('span', 'gloss-image-container');
node.appendChild(imageContainer);

const aspectRatioSizer = this._createElement('span', 'gloss-image-sizer');
imageContainer.appendChild(aspectRatioSizer);

const imageBackground = this._createElement('span', 'gloss-image-background');
imageContainer.appendChild(imageBackground);

Expand All @@ -120,6 +123,8 @@ export class StructuredContentGenerator {
node.dataset.sizeUnits = sizeUnits;
}

aspectRatioSizer.style.paddingTop = `${invAspectRatio * 100}%`;

if (typeof border === 'string') { imageContainer.style.border = border; }
if (typeof borderRadius === 'string') { imageContainer.style.borderRadius = borderRadius; }
imageContainer.style.width = `${usedWidth}em`;
Expand Down
Loading
Loading