Skip to content

Commit

Permalink
Use records instead of list in html_utils.toRGBA
Browse files Browse the repository at this point in the history
  • Loading branch information
Amir-P committed Aug 23, 2024
1 parent e725636 commit 1dbca0c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
4 changes: 2 additions & 2 deletions packages/parchment/lib/src/codecs/html.dart
Original file line number Diff line number Diff line change
Expand Up @@ -539,13 +539,13 @@ class _HtmlInlineTag extends _HtmlTag {
final argb = toRGBA(value);
return '<${_inlineAttributesParchmentToHtml[key]} '
'style="color: '
'rgba(${argb[1]},${argb[2]},${argb[3]},${argb[0] / 255})">';
'rgba(${argb.R},${argb.G},${argb.B},${argb.A / 255})">';
}
if (key == ParchmentAttribute.backgroundColor.key) {
final argb = toRGBA(value);
return '<${_inlineAttributesParchmentToHtml[key]} '
'style="background-color: '
'rgba(${argb[1]},${argb[2]},${argb[3]},${argb[0] / 255})">';
'rgba(${argb.R},${argb.G},${argb.B},${argb.A / 255})">';
}
return '<${_inlineAttributesParchmentToHtml[key]}>';
}
Expand Down
15 changes: 7 additions & 8 deletions packages/parchment/lib/src/codecs/html_utils.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
// TODO: Use tuple once Parchment is ported to Dart 3
List<int> toRGBA(int colorValue) {
return [
(0xff000000 & colorValue) >> 24,
(0x00ff0000 & colorValue) >> 16,
(0x0000ff00 & colorValue) >> 8,
(0x000000ff & colorValue) >> 0
];
({int R, int G, int B, int A}) toRGBA(int colorValue) {
return (
A: (0xff000000 & colorValue) >> 24,
R: (0x00ff0000 & colorValue) >> 16,
G: (0x0000ff00 & colorValue) >> 8,
B: (0x000000ff & colorValue) >> 0
);
}

int colorValueFromCSS(String cssColor) {
Expand Down

0 comments on commit 1dbca0c

Please sign in to comment.