1 package Shiar_Sheet::KeyboardChars;
6 use experimental 'signatures';
8 use Unicode::Normalize qw( NFKD );
9 use Text::Unidecode ();
10 use Shiar_Sheet::FormatChar;
12 our $VERSION = '1.02';
13 our @EXPORT = qw( kbchars kbmodes );
15 my $uc = Shiar_Sheet::FormatChar->new;
18 ⍺ a ⍵ w ∊ E ⍷ E ⍴ r ⍳ i ⍸ i ○ O ⍥ O ⌿ / ⍟ (*)
22 return $unaccent{$_[0]} // Text::Unidecode::unidecode($_[0]);
26 return kbmodes({'' => $rows});
29 sub kbmodes ($modes) {
30 my %g; # present group classes
34 for my $lead (keys %{$modes}) {
36 $info{def}->{''}->{$lead} = "g1 mode$lead";
38 $info{mode}->{$lead} //= "mode $lead";
39 $info{def}->{$lead}{$lead} = 'g1 mode'; # back
41 while (my ($c, $v) = each %{ $modes->{$lead} }) {
42 my ($glyph, $title) = $uc->glyph_html($v);
43 $info{key}{$lead.$c} = join "\n", $glyph, $title;
46 !defined $v || $c eq $v ? 1 # identical
47 : $v =~ /\A\p{Mn}+\z/ ? 9 # combining accent
48 : NFKD($v) =~ /\Q$c/ ? 2 # decomposed equivalent
49 : unidecode($v) =~ /\Q$c\E+/i ? 4 # transliterated
50 : $v =~ /\A[\p{Sk}\p{Lm}]+\z/ ? 8 # modifier symbol
51 : $v =~ /\A[\pM\pP]+\z/ ? 7 # mark
52 : $v =~ /^\p{Latin}/ ? 5 # latin script
56 $info{def}{$lead}{$c} //= $class;
60 g1 => ['mode' => "switch to an alternate set of keys"],
61 g2 => ['accented', "decomposes to the original letter with a combining accent"],
62 g4 => ['similar', "transliterates (mostly) into the unmodified letter"],
63 g5 => ['latin', "a different (accented) latin letter"],
64 g6 => ['symbol', "other character not directly deducible from key"],
65 g7 => ['punctuation', "(punctuation) mark"],
66 g8 => ['mark', "modifier letter or mark (spacing diacritic)"],
67 g9 => ['combining', "diacritical mark to be combined with a following character"],