Skip to content

Commit 4a14878

Browse files
committed
Add support for obsolete CSS2 colors
System colors that were part of the CSS2 spec, but have since been removed. However, they show up when pasting text from Microsoft software like Word into Quill on web.
1 parent 768f84d commit 4a14878

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

lib/src/common/utils/web_colors.dart

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// https://github.com/vincevargadev/kolors_flutter
33

44
import 'dart:ui';
5+
import 'package:flutter/foundation.dart';
56

67
/// All the named web colors.
78
class WebColors {
@@ -146,6 +147,7 @@ class WebColors {
146147
static const slateGray = Color(0xFF708090);
147148
static const darkSlateGray = Color(0xFF2F4F4F);
148149
static const black = Color(0xFF000000);
150+
static const transparent = Color(0);
149151

150152
static const values = [
151153
indianRed,
@@ -291,10 +293,7 @@ class WebColors {
291293
black,
292294
];
293295

294-
/// Return all colors in [Kolors] as a Map<String, Color>.
295-
///
296-
/// Can be useful when working with UIs where the user can see all colors
297-
/// and select from a list.
296+
/// All web colors as a Map<String, Color>.
298297
static const namedColors = {
299298
'indianred': indianRed,
300299
'lightcoral': lightCoral,
@@ -437,5 +436,40 @@ class WebColors {
437436
'slategray': slateGray,
438437
'darkslategray': darkSlateGray,
439438
'black': black,
439+
440+
// the follow colors were part of the CSS2 standard, but have since been removed.
441+
// however these names tend to show up when copy/pasting from Microsoft products
442+
// into Quill on web. W3C recommends using a default color for these.
443+
//
444+
// For more info, see here
445+
// http://w3.org/TR/CSS2/ui.html#system-colors
446+
'activeborder': black,
447+
'activecaption': black,
448+
'appworkspace': transparent,
449+
'background': transparent,
450+
'buttonface': transparent,
451+
'buttonhighlight': transparent,
452+
'buttonshadow': transparent,
453+
'buttontext': black,
454+
'captiontext': black,
455+
'graytext': gray,
456+
'highlight': gray,
457+
'highlighttext': black,
458+
'inactiveborder': black,
459+
'inactivecaption': black,
460+
'inactivecaptiontext': black,
461+
'infobackground': transparent,
462+
'infotext': black,
463+
'menu': transparent,
464+
'menutext': black,
465+
'scrollbar': transparent,
466+
'threeddarkshadow': transparent,
467+
'threedface': transparent,
468+
'threedhighlight': transparent,
469+
'threedlightshadow': transparent,
470+
'threedshadow': transparent,
471+
'window': transparent,
472+
'windowframe': black,
473+
'windowtext': black,
440474
};
441475
}

test/common/utils/color_test.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ void main() {
1414
expect(stringToColor('lightgoldenrodyellow').toARGB32(), 0xFFFAFAD2);
1515
expect(stringToColor('LIGHTGOLDENRODYELLOW').toARGB32(), 0xFFFAFAD2);
1616
});
17+
test('Obsolete CSS2 color names pasted from word resolve to a value', () {
18+
// test some web colors to make sure they resolve correctly
19+
expect(stringToColor('windowtext').toARGB32(), 0xff000000);
20+
});
1721
test('Can resolve transparent', () {
1822
// test some web colors to make sure they resolve correctly
1923
expect(stringToColor('transparent').toARGB32(), 0);

0 commit comments

Comments
 (0)