Skip to content

Commit

Permalink
fix(inlineStyles): inline styles in order of priority
Browse files Browse the repository at this point in the history
  • Loading branch information
SethFalco committed Nov 12, 2023
1 parent 1f766ac commit c75d836
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 6 deletions.
13 changes: 12 additions & 1 deletion plugins/inlineStyles.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,17 @@ exports.fn = (root, params) => {
continue;
}
const styleDeclarationItems = new Map();

/** @type {csstree.ListItem<csstree.CssNode>} */
let firstListItem;

csstree.walk(styleDeclarationList, {
visit: 'Declaration',
enter(node, item) {
if (firstListItem == null) {
firstListItem = item;
}

styleDeclarationItems.set(node.property.toLowerCase(), item);
},
});
Expand All @@ -232,7 +240,10 @@ exports.fn = (root, params) => {
const ruleDeclarationItem =
styleDeclarationList.children.createItem(ruleDeclaration);
if (matchedItem == null) {
styleDeclarationList.children.append(ruleDeclarationItem);
styleDeclarationList.children.insert(
ruleDeclarationItem,
firstListItem
);
} else if (
matchedItem.data.important !== true &&
ruleDeclaration.important === true
Expand Down
2 changes: 1 addition & 1 deletion test/plugins/inlineStyles.03.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion test/plugins/inlineStyles.05.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion test/plugins/inlineStyles.16.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion test/plugins/inlineStyles.19.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion test/plugins/inlineStyles.22.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c75d836

Please sign in to comment.