Skip to content

Commit c1f4082

Browse files
Support RGB Percentage Values (#320)
Co-authored-by: Lukas Holländer <[email protected]>
1 parent 353ad51 commit c1f4082

File tree

4 files changed

+16
-0
lines changed

4 files changed

+16
-0
lines changed

src/utils/rgbcolor.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,17 @@ export class RGBColor {
196196
return [parseInt(bits[1]), parseInt(bits[2]), parseInt(bits[3])]
197197
}
198198
},
199+
{
200+
re: /^rgb\(([0-9.]+)%,\s*([0-9.]+)%,\s*([0-9.]+)%\)$/,
201+
example: ['rgb(50.5%, 25.75%, 75.5%)', 'rgb(100%,0%,0%)'],
202+
process: function(bits: any) {
203+
return [
204+
Math.round(parseFloat(bits[1]) * 2.55),
205+
Math.round(parseFloat(bits[2]) * 2.55),
206+
Math.round(parseFloat(bits[3]) * 2.55)
207+
]
208+
}
209+
},
199210
{
200211
re: /^(\w{2})(\w{2})(\w{2})$/,
201212
example: ['#00ff00', '336699'],

test/common/tests.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ window.tests = [
4444
'rect',
4545
'references',
4646
'remote-images',
47+
'rgb-color-percent',
4748
['size-options/no-params-no-attrs-no-viewbox', [400, 300], {}],
4849
['size-options/no-params-no-attrs-with-viewbox', [400, 300], {}],
4950
['size-options/no-params-with-attrs-no-viewbox', [400, 300], {}],
3.15 KB
Binary file not shown.
Lines changed: 4 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)