@@ -13,21 +13,40 @@ class Home extends StatefulComponent {
1313
1414class _HomeState extends State <Home > {
1515 String _text = '안녕하세요, 만나서 반갑습니다.' ;
16- late String _romanized = TextRomanizer .romanize (_text);
16+ late List < RomanizedText > _romanized = TextRomanizer .analyze (_text);
1717
1818 void _syncScroll (web.Event event, String otherId) {
19- final source = event.target as web.HTMLTextAreaElement ;
20- final other = web.document.getElementById (otherId) as web.HTMLTextAreaElement ? ;
21- if (other != null && other.scrollTop != source.scrollTop ) {
19+ final source = event.target as web.HTMLElement ;
20+ final other = web.document.getElementById (otherId) as web.HTMLElement ? ;
21+ if (other != null ) {
2222 other.scrollTop = source.scrollTop;
2323 }
2424 }
2525
26+ Color _getColorForLanguage (String languageCode) {
27+ switch (languageCode) {
28+ case 'korean' :
29+ return Color ('#3B82F6' ); // Blue
30+ case 'japanese' :
31+ return Color ('#EF4444' ); // Red
32+ case 'chinese' :
33+ return Color ('#F59E0B' ); // Amber
34+ case 'arabic' :
35+ return Color ('#10B981' ); // Green
36+ case 'hebrew' :
37+ return Color ('#EC4899' ); // Pink
38+ case 'cyrillic' :
39+ return Color ('#8B5CF6' ); // Purple
40+ default :
41+ return Color ('#6B7280' ); // Neutral Gray
42+ }
43+ }
44+
2645 @override
2746 Component build (BuildContext context) {
2847 final textareaStyle = Styles (
2948 width: Unit .percent (100 ),
30- height: Unit .percent ( 100 ),
49+ height: Unit .vh ( 60 ),
3150 padding: Spacing .all (Unit .pixels (16 )),
3251 boxSizing: BoxSizing .borderBox,
3352 border: Border .all (color: Color ('#d1d5db' )),
@@ -39,7 +58,9 @@ class _HomeState extends State<Home> {
3958 offsetX: Unit .zero,
4059 offsetY: Unit .pixels (1 ),
4160 ),
61+ fontFamily: FontFamily ('inherit' ),
4262 fontSize: Unit .rem (1 ),
63+ lineHeight: Unit .rem (1.5 ),
4364 backgroundColor: Colors .white,
4465 raw: {
4566 'resize' : 'none' ,
@@ -48,9 +69,11 @@ class _HomeState extends State<Home> {
4869
4970 final sectionStyle = Styles (
5071 display: Display .flex,
72+ height: Unit .percent (70 ),
73+ minWidth: Unit .pixels (300 ),
5174 flexDirection: FlexDirection .column,
5275 gap: Gap .all (Unit .pixels (12 )),
53- flex: Flex (grow: 1 , shrink: 1 ),
76+ flex: Flex (grow: 1 , shrink: 0 , basis : Unit . pixels ( 400 ) ),
5477 );
5578
5679 final labelStyle = Styles (
@@ -79,35 +102,42 @@ class _HomeState extends State<Home> {
79102 onInput: (text) async {
80103 _text = text;
81104 _romanized = await service.convert (text);
82- if (mounted) {
83- setState (() {});
84- }
105+ if (mounted) setState (() {});
85106 },
86- rows: 15 ,
87107 required : true ,
88108 spellCheck: SpellCheck .isFalse,
89- styles: textareaStyle,
109+ styles: textareaStyle.combine (
110+ Styles (raw: {'resize' : 'none' }),
111+ ),
90112 [.text (_text)],
91113 ),
92114 ]),
93115 div (styles: sectionStyle, [
94116 h3 (styles: labelStyle, [.text ('Output' )]),
95- textarea (
117+ div (
96118 id: 'output-area' ,
97119 events: {
98120 'scroll' : (e) => _syncScroll (e, 'input-area' ),
99121 },
100- placeholder: 'Type your text here...' ,
101- rows: 15 ,
102- readonly: true ,
103- spellCheck: SpellCheck .isFalse,
104122 styles: textareaStyle.combine (
105123 Styles (
106- color: Color ('#4b5563' ),
124+ overflow: Overflow .auto,
125+ whiteSpace: WhiteSpace .preWrap,
107126 backgroundColor: Color ('#f9fafb' ),
127+ raw: {
128+ 'word-break' : 'break-word' ,
129+ },
108130 ),
109131 ),
110- [.text (_romanized)],
132+ _romanized.map ((item) {
133+ return span (
134+ styles: Styles (
135+ color: _getColorForLanguage (item.language),
136+ fontWeight: FontWeight .w500,
137+ ),
138+ [.text (item.romanizedText)],
139+ );
140+ }).toList (),
111141 ),
112142 ]),
113143 ],
0 commit comments