We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 80d92db commit 5ab0e77Copy full SHA for 5ab0e77
5 files changed
apps/automated/src/color/color-tests.ts
@@ -72,6 +72,24 @@ export var test_rgb_Color_CSS = function () {
72
TKUnit.assertEqual(color.argb, 0xffff6464, 'Color.argb not properly parsed');
73
};
74
75
+export var test_rgb_Color_CSS_lvl4 = function () {
76
+ var alpha = 0.5;
77
+ var expected = 0x80;
78
+ // <snippet module="color" title="color">
79
+ // ### Creating a Color from four RGB values
80
+ // ``` JavaScript
81
+ // Creates the color with 255 red, 100 green, 100 blue
82
+ var color = new Color(`rgb(255 100 100 / ${alpha})`);
83
+ // ```
84
+ // </snippet>
85
+ TKUnit.assertEqual(color.a, expected, 'Color.a not properly parsed');
86
+ TKUnit.assertEqual(color.r, 255, 'Color.r not properly parsed');
87
+ TKUnit.assertEqual(color.g, 100, 'Color.g not properly parsed');
88
+ TKUnit.assertEqual(color.b, 100, 'Color.b not properly parsed');
89
+ TKUnit.assertEqual(color.hex, '#FF646480', 'Color.hex not properly parsed');
90
+ TKUnit.assertEqual(color.argb, 0x80ff6464, 'Color.argb not properly parsed');
91
+};
92
+
93
export var test_rgba_Color_CSS = function () {
94
var alpha = 0.5;
95
var expected = 0x80;
apps/automated/src/ui/styling/style-properties-tests.ts
@@ -59,6 +59,10 @@ export function test_setting_borderColorRGB_property_from_CSS_is_applied_to_Styl
59
test_property_from_CSS_is_applied_to_style('borderColor', 'border-color', new Color('#FF0000'), 'rgb(255, 0, 0)');
60
}
61
62
+export function test_setting_borderColorRGBLvl4_property_from_CSS_is_applied_to_Style() {
63
+ test_property_from_CSS_is_applied_to_style('borderColor', 'border-color', new Color('#FF0000'), 'rgb(255 0 0 / 1)');
64
+}
65
66
export function test_setting_borderColorRGBA_property_from_CSS_is_applied_to_Style() {
67
test_property_from_CSS_is_applied_to_style('borderColor', 'border-color', new Color('#FF0000'), 'rgba(255,0,0,1)');
68
packages/core/__tests__/css/parser.ts
@@ -44,6 +44,8 @@ describe('css', () => {
44
test(parseColor, ' #456789 ', { start: 0, end: 10, value: new Color(0xff456789) });
45
test(parseColor, ' #45678985 ', { start: 0, end: 12, value: new Color(0x45678985) });
46
test(parseColor, ' rgb(255, 8, 128) ', { start: 0, end: 18, value: new Color(0xffff0880) });
47
+ test(parseColor, ' rgb(255 8 128 / .5) ', { start: 0, end: 24, value: new Color(0x80ff0880) });
48
+ test(parseColor, ' rgb(255 8 128/0.5) ', { start: 0, end: 24, value: new Color(0x80ff0880) });
49
test(parseColor, ' rgba(255, 8, 128, 0.5) ', { start: 0, end: 24, value: new Color(0x80ff0880) });
50
test(parseColor, ' hsl(330.9, 100%, 51.6%) ', { start: 0, end: 25, value: new Color(0xffff0880) });
51
test(parseColor, ' hsla(330.9, 100%, 51.6%, 0.5) ', { start: 0, end: 31, value: new Color(0x80ff0880) });
packages/core/color/color-common.ts
@@ -406,12 +406,15 @@ function isHsvOrHsva(value: string): boolean {
406
407
408
function parseColorWithAlpha(value: string): any {
409
+ const separator = value.indexOf(',') > -1 ? ',' : ' ';
410
const parts = value
411
.replace(/(rgb|hsl|hsv)a?\(/, '')
412
.replace(')', '')
413
+ .replace(/\//, ' ')
414
.replace(/%/g, '')
415
.trim()
- .split(',');
416
+ .split(separator)
417
+ .filter((part) => Boolean(part.length));
418
419
let f = 255;
420
let s = 255;
packages/core/css/parser.ts
@@ -135,7 +135,6 @@ export function parseColorKeyword(value, start: number, keyword = parseKeyword(v
135
const parseColor = keyword && getKnownColor(keyword.value);
136
if (parseColor != null) {
137
const end = keyword.end;
138
- const value = parseColor;
139
return { start, end, value: new Color(parseColor) };
140
141
return null;
0 commit comments