-our %rows;
-my %g; # present group classes
-{
- rows => [0, 1],
- def => {
- '' => {
- map {
- my $v = $rows{$_};
- my $class = (
- !defined $v || $_ eq $v ? 1 # identical
- : $v =~ /\A\p{Mn}+\z/ ? 9 # combining accent
- : $v =~ /\A[\p{Sk}\p{Lm}]+\z/ ? 8 # modifier symbol
- : $v =~ /\A[\pM\pP]+\z/ ? 7 # mark
- : NFKD($v) =~ /\Q$_/ ? 2 # decomposed equivalent
- : unidecode($v) =~ /\Q$_\E+/i ? 4 # transliterated
- : $v =~ /^\p{Latin}/ ? 5 # latin script
- : 6
- );
- $g{$class} = 1;
- $_ => "g$class"
- } keys %rows
- },
- },
- key => \%rows,
- flag => {
- g1 => ['unaltered', "same results as without modifier"],
+my $uc = Shiar_Sheet::FormatChar->new;
+
+sub kbchars ($rows) {
+ return kbmodes({'' => $rows});
+}
+
+sub kbmodes ($modes) {
+ my %g; # present group classes
+ my %info = (
+ rows => [1, 0],
+ );
+ for my $lead (keys %{$modes}) {
+ if ($lead ne '') {
+ $info{def}->{''}->{$lead} = "g1 mode$lead";
+ $g{g1} = 1;
+ $info{mode}->{$lead} //= "mode $lead";
+ $info{def}->{$lead}{$lead} = 'g1 mode'; # back
+ }
+ while (my ($c, $v) = each %{ $modes->{$lead} }) {
+ my ($glyph, $title) = $uc->glyph_html($v);
+ $info{key}{$lead.$c} = join "\n", $glyph, $title;
+
+ my $class = 'g'.(
+ !defined $v || $c eq $v ? 1 # identical
+ : $v =~ /\A\p{Mn}+\z/ ? 9 # combining accent
+ : $v =~ /\A[\p{Sk}\p{Lm}]+\z/ ? 8 # modifier symbol
+ : $v =~ /\A[\pM\pP]+\z/ ? 7 # mark
+ : NFKD($v) =~ /\Q$c/ ? 2 # decomposed equivalent
+ : unidecode($v) =~ /\Q$c\E+/i ? 4 # transliterated
+ : $v =~ /^\p{Latin}/ ? 5 # latin script
+ : 6
+ );
+ $g{$class} = 1;
+ $info{def}{$lead}{$c} //= $class;
+ }
+ }
+ $info{flag} = {%{{
+ g1 => ['mode' => "switch to an alternate set of keys"],