Skip to content

Commit

Permalink
Remove the old :where(img) css close and don't embed svgs when img ta…
Browse files Browse the repository at this point in the history
…g has width or height
  • Loading branch information
georges-gomes committed Oct 11, 2024
1 parent 5aadb4c commit 8f10d7e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/config-default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const default_options: Options = {
browserslist: 'defaults', // defaults = '> 0.5%, last 2 versions, Firefox ESR, not dead'
},
html: {
add_css_reset_as: 'inline',
add_css_reset_as: 'off',
sort_attributes: false,
},
css: {
Expand Down
8 changes: 1 addition & 7 deletions src/config-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,7 @@ export type Options = {
browserslist: string; // browserslist query string
};
html: {
/*
jampack adds a little bit of css to make
image keep correct aspect ratio after adding
image dimensions.
":where(img){height:auto}"
*/
add_css_reset_as: 'inline' | 'off';
add_css_reset_as: 'inline' | 'off'; // 'inline': adds "<style>:where(img){height:auto}</style>" on top of the <head>
sort_attributes: boolean;
};
js: {
Expand Down
4 changes: 4 additions & 0 deletions src/optimize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,10 @@ async function processImage(
const ifmt = imageToEmbed.format;
switch (ifmt) {
case 'svg':
// When embedded, if the SVG file has width and height attributes (or viewBox without corresponding width/height),
// the browser respects those attributes over the external <img> tag attributes.
// TODO update the SVG - meanwhile don't embed it if there are attributes
if (img.attr('width') || img.attr('height')) break;
datauri = svgToMiniDataURI(imageToEmbed.data.toString());
break;
case 'webp':
Expand Down

0 comments on commit 8f10d7e

Please sign in to comment.