4
4
type LabelShape ,
5
5
type ZoneId ,
6
6
} from "@keybr/keyboard" ;
7
+ import { type CodePoint } from "@keybr/unicode" ;
8
+ import { type ClassName } from "@keybr/widget" ;
7
9
import { clsx } from "clsx" ;
8
10
import {
9
11
type FunctionComponent ,
@@ -27,23 +29,29 @@ export type KeyProps = {
27
29
} ;
28
30
29
31
export function makeKeyComponent ( shape : KeyShape ) : FunctionComponent < KeyProps > {
32
+ const { id, a, b, c, d, finger } = shape ;
33
+ const x = shape . x * keySize ;
34
+ const y = shape . y * keySize ;
35
+ const w = shape . w * keySize - keyGap ;
36
+ const h = shape . h * keySize - keyGap ;
30
37
const children : ReactNode [ ] = [ ] ;
31
38
children . push (
32
39
shape . shape ? (
33
40
< path className = { styles . button } d = { shape . shape } />
34
41
) : (
35
- < rect
36
- className = { styles . button }
37
- x = { 0 }
38
- y = { 0 }
39
- width = { shape . w * keySize - keyGap }
40
- height = { shape . h * keySize - keyGap }
41
- />
42
+ < rect className = { styles . button } x = { 0 } y = { 0 } width = { w } height = { h } />
42
43
) ,
43
44
) ;
44
- const { a, b, c, d } = shape ;
45
- const ab = a > 0 && b > 0 && keySymbol ( a ) === keySymbol ( b ) ;
46
- const cd = c > 0 && d > 0 && keySymbol ( c ) === keySymbol ( d ) ;
45
+ if ( shape . homing ) {
46
+ children . push (
47
+ < circle className = { styles . bump } cx = { w / 2 } cy = { h - 5 } r = { 3 } /> ,
48
+ ) ;
49
+ }
50
+ for ( const label of shape . labels ) {
51
+ children . push ( makeLabel ( label ) ) ;
52
+ }
53
+ const ab = a > 0 && b > 0 && symbolText ( a ) === symbolText ( b ) ;
54
+ const cd = c > 0 && d > 0 && symbolText ( c ) === symbolText ( d ) ;
47
55
if ( a > 0 && ! ab ) {
48
56
children . push ( makeSymbolLabel ( a , 10 , 27 , styles . secondarySymbol ) ) ;
49
57
}
@@ -62,18 +70,6 @@ export function makeKeyComponent(shape: KeyShape): FunctionComponent<KeyProps> {
62
70
if ( c > 0 && cd ) {
63
71
children . push ( makeSymbolLabel ( c , 25 , 27 , styles . primarySymbol ) ) ;
64
72
}
65
- for ( const label of shape . labels ) {
66
- children . push ( makeLabel ( label ) ) ;
67
- }
68
- if ( shape . homing ) {
69
- children . push ( < circle className = { styles . bump } cx = { 20 } cy = { 33 } r = { 3 } /> ) ;
70
- }
71
- const id = shape . id ;
72
- const x = shape . x * keySize ;
73
- const y = shape . y * keySize ;
74
- const w = shape . w * keySize - keyGap ;
75
- const h = shape . h * keySize - keyGap ;
76
- const finger = shape . finger ;
77
73
function KeyComponent ( {
78
74
depressed,
79
75
toggled,
@@ -111,7 +107,7 @@ export function makeKeyComponent(shape: KeyShape): FunctionComponent<KeyProps> {
111
107
return memo ( KeyComponent ) ;
112
108
}
113
109
114
- function makeLabel ( label : LabelShape , className : any = null ) : ReactNode {
110
+ function makeLabel ( label : LabelShape , className : ClassName = null ) : ReactNode {
115
111
const { text, pos = [ 10 , 20 ] , align = [ "s" , "m" ] } = label ;
116
112
const [ x , y ] = pos ;
117
113
const [ ha , va ] = align ;
@@ -157,29 +153,28 @@ function makeSymbolLabel(
157
153
codePoint : number ,
158
154
x : number ,
159
155
y : number ,
160
- className : any ,
156
+ className : ClassName ,
161
157
) : ReactNode {
158
+ if ( codePoint === 0x0020 ) {
159
+ return null ;
160
+ }
162
161
let text : string ;
163
162
if ( isDiacritic ( codePoint ) ) {
164
- text = deadKeySymbol ( codePoint ) ;
165
- className = clsx ( styles . deadSymbol , className ) ;
163
+ text = String . fromCodePoint ( /* ◌ */ 0x25cc , codePoint ) ;
164
+ className = clsx ( className , styles . deadSymbol ) ;
166
165
} else {
167
- text = keySymbol ( codePoint ) ;
166
+ text = symbolText ( codePoint ) ;
168
167
}
169
168
return makeLabel ( { text, pos : [ x , y ] , align : [ "m" , "m" ] } , className ) ;
170
169
}
171
170
172
- function keySymbol ( codePoint : number ) : string {
171
+ function symbolText ( codePoint : CodePoint ) : string {
173
172
if ( codePoint === /* ß */ 0x00df || codePoint === /* ẞ */ 0x1e9e ) {
174
173
return "ẞ" ;
175
174
}
176
175
return String . fromCodePoint ( codePoint ) . toUpperCase ( ) ;
177
176
}
178
177
179
- function deadKeySymbol ( codePoint : number ) : string {
180
- return String . fromCodePoint ( /* ◌ */ 0x25cc , codePoint ) ;
181
- }
182
-
183
178
function fingerStyleName ( finger : ZoneId | null ) : string | null {
184
179
switch ( finger ) {
185
180
case "pinky" :
0 commit comments