use strict;
-+{
+use warnings;
+
+my %cat = (
default => [qw( euro latin science graph )],
euro => [qw( windows ukext macos macos-abc weur eurkey msx )],
latin => [qw( ipa olpc boyeg drix )],
science => [qw( symbolics apl spacecadet )],
graph => [qw( unigraph emojiworks )],
extra => [qw( msx-graph p8scii zoo )],
+);
+
+for my $name (map {@{$_}} values %cat) {
+ my $keys = do "keyboard/altgr/$name.eng.inc.pl" or next;
+ my %row = %{$keys}{qw( title category flag mode image imagealt )};
+ $cat{$name} = \%row;
+
+ $keys->{mode} //= {'' => undef};
+ for my $mode (keys %{ $keys->{mode} }) {
+ $row{key}{$_} = $keys->{key}{$_} for $mode || ();
+ $row{inventory}{$mode}{$_}++ for grep { /^g[2-9]/ } map { s/ (?!ext).*//r }
+ values %{ $keys->{def}{$mode} };
+ }
}
+
+\%cat
my @sample = split /(?<!\+)/, $get{sample} // 'asSci1!+1';
require Shiar_Sheet::Keyboard;
-use List::Util qw( uniq max );
+use List::Util qw( uniq max sum );
my %caticon = (
legacy => qq{<span class=icon title="deprecated">\N{TOP HAT}</span>},
print "<th>$_" for @sample;
say '</tr></thead>';
}
-my %idx = map {($_ => scalar eval{ Data("$dirbase/$_.eng") })} @incs;
-my $most = max(map { scalar keys %{$_->{def}{''}} } values %idx);
+my $most = max(map { sum values %{ $_->{inventory}{''} } } %{$idx}{@incs});
for my $inc (@incs) {
+ my $table = $idx->{$inc};
print @sample ? '<tr><th>' : '<figure>';
printf '<a href="/%s">', "$dirbase/$inc";
- my $table = $idx{$inc};
- my $title = $table && $table->{title} || $inc;
+ my $title = $table->{title} || $inc;
unless (@sample) {
- if ($table and my $img = $table->{image}) {
+ if (my $img = $table->{image}) {
EscapeHTML $name = $table->{imagealt} // $img =~ m{.*/([^/.]*)};
print qq{<img src="/$img" alt="$name" />};
}
else {
print $title;
print '</a>', "\n\t";
- my $keys = Shiar_Sheet::Keyboard->new($table);
- for my $mode ($keys->{mode} ? sort keys %{ $keys->{mode} } : '') {
- my %inventory;
- $inventory{$_}++ for grep { /^g[2-9]/ } map { s/ (?!ext).*//r }
- values %{ $keys->{def}{$mode} };
+ for my $mode ($table->{mode} ? sort keys %{ $table->{mode} } : '') {
print '<span class=graph>';
- printf '<label>%s</label>', s/\s.*//r for $keys->{key}{$mode} || ();
- for my $g (sort keys %inventory) {
+ printf '<label>%s</label>', s/\s.*//r for $table->{key}{$mode} || ();
+ for my $g (sort keys %{ $table->{inventory}{$mode} }) {
printf '<span class="%s" style="width:%.0f%%" title="%3$d %4$s"> %s</span>',
$g, $_/$most*100, $_,
join(' ', map {
- $keys->{flag}{$_}[0] || 'extra' # legend label of each class
+ $table->{flag}{$_}[0] || 'extra' # legend label of each class
} reverse split / /, $g)
- for $inventory{$g};
+ for $table->{inventory}{$mode}{$g};
}
say '</span>';
}
print "\t<td class=ni>";
- print join ' ', map { $caticon{$_} // () } split m{/}, $keys->{category} // '';
+ print join ' ', map { $caticon{$_} // () } split m{/}, $table->{category} // '';
say '';
- $keys->print_key('', $_, ($keys->{def}{''}{$_} // 'ni') =~ s/ mode\S*//r)
- for @sample;
+ if (my $keys = eval {
+ my $keydata = Data("$dirbase/$inc.eng");
+ Shiar_Sheet::Keyboard->new($keydata)
+ }) {
+ $keys->print_key('', $_, ($keys->{def}{''}{$_} // 'ni') =~ s/ mode\S*//r)
+ for @sample;
+ }
say '</tr>';
}
}