1 package Shiar_Sheet::KeyboardChars;
5 use experimental 'signatures';
7 use Unicode::Normalize qw( NFKD );
8 use Text::Unidecode qw( unidecode );
9 use Shiar_Sheet::FormatChar;
11 our $VERSION = '1.00';
12 our @EXPORT = qw( kbchars kbmodes );
14 my $uc = Shiar_Sheet::FormatChar->new;
17 return kbmodes({'' => $rows});
20 sub kbmodes ($modes) {
21 my %g; # present group classes
25 for my $lead (keys %{$modes}) {
27 $info{def}->{''}->{$lead} = "g1 mode$lead";
29 $info{mode}->{$lead} //= "mode $lead";
30 $info{def}->{$lead}{$lead} = 'g1 mode'; # back
32 while (my ($c, $v) = each %{ $modes->{$lead} }) {
33 my ($glyph, $title) = $uc->glyph_html($v);
34 $info{key}{$lead.$c} = join "\n", $glyph, $title;
37 !defined $v || $c eq $v ? 1 # identical
38 : $v =~ /\A\p{Mn}+\z/ ? 9 # combining accent
39 : $v =~ /\A[\p{Sk}\p{Lm}]+\z/ ? 8 # modifier symbol
40 : $v =~ /\A[\pM\pP]+\z/ ? 7 # mark
41 : NFKD($v) =~ /\Q$c/ ? 2 # decomposed equivalent
42 : unidecode($v) =~ /\Q$c\E+/i ? 4 # transliterated
43 : $v =~ /^\p{Latin}/ ? 5 # latin script
47 $info{def}{$lead}{$c} //= $class;
51 g1 => ['mode' => "switch to an alternate set of keys"],
52 g2 => ['accented', "decomposes to the original letter with a combining accent"],
53 g4 => ['similar', "transliterates (mostly) into the unmodified letter"],
54 g5 => ['latin', "a different (accented) latin letter"],
55 g6 => ['symbol', "other character not directly deducible from key"],
56 g7 => ['punctuation', "(punctuation) mark"],
57 g8 => ['mark', "modifier letter or mark (spacing diacritic)"],
58 g9 => ['combining', "diacritical mark to be combined with a following character"],