Skip to content

Commit 124436c

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 124436c

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

lib/src/common/utils/web_colors.dart

Lines changed: 37 additions & 0 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,
@@ -437,5 +439,40 @@ class WebColors {
437439
'slategray': slateGray,
438440
'darkslategray': darkSlateGray,
439441
'black': black,
442+
443+
// the follow colors were part of the CSS2 standard, but have since been removed.
444+
// however these names tend to show up when copy/pasting from Microsoft products
445+
// into Quill on web. W3C recommends using a default color for these.
446+
//
447+
// For more info, see here
448+
// http://w3.org/TR/CSS2/ui.html#system-colors
449+
'activeborder': black,
450+
'activecaption': black,
451+
'appworkspace': transparent,
452+
'background': transparent,
453+
'buttonface': transparent,
454+
'buttonhighlight': transparent,
455+
'buttonshadow': transparent,
456+
'buttontext': black,
457+
'captiontext': black,
458+
'graytext': gray,
459+
'highlight': gray,
460+
'highlighttext': black,
461+
'inactiveborder': black,
462+
'inactivecaption': black,
463+
'inactivecaptiontext': black,
464+
'infobackground': transparent,
465+
'infotext': black,
466+
'menu': transparent,
467+
'menutext': black,
468+
'scrollbar': transparent,
469+
'threeddarkshadow': transparent,
470+
'threedface': transparent,
471+
'threedhighlight': transparent,
472+
'threedlightshadow': transparent,
473+
'threedshadow': transparent,
474+
'window': transparent,
475+
'windowframe': black,
476+
'windowtext': black,
440477
};
441478
}

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)