keyboard/altgr/index: move ctrl rows to distinct inventory mode
[sheet.git] / keyboard / altgr / index.inc.plp
index 75c2cc382bced54cd0f6ea4061863ae65673099e..c6accc7669958fa79fd273e60ec06dae8414a54c 100644 (file)
@@ -1,12 +1,14 @@
 <: # included from keyboard.plp
 use 5.014;
 use warnings;
+use utf8;
 
-my @incs = glob 'keyboard/altgr/*.eng.inc.pl';
+my $dirbase = 'keyboard/altgr';
+my $indexfile = "$dirbase/index";
 
 Html({
        title => "altgr keyboard cheat sheets",
-       version => '1.0',
+       version => '1.3',
        description => [
                "Overview of alternate keyboard modes,",
                "offering extended Unicode characters if a modifier key",
@@ -15,13 +17,92 @@ Html({
        keywords => [qw'
                sheet cheat reference overview keyboard altgr option
        '],
+       image => "$dirbase/thumb/ibm-m.jpg",
        stylesheet => [qw( light dark circus mono red )],
-       data => ['keyboard/altgr/index.inc.plp', @incs],
+       data => ["$dirbase/index.inc.plp", "$indexfile.inc.pl"],
        raw => <<'.',
 <style>
+.keys.cmp {
+       display: inline-table; /* centered */
+       float: none;
+       margin: 0;
+       border-collapse: separate;
+       border-spacing: 2px;
+       border-spacing: .4vw; /* inline td margin equivalent */
+}
+.keys.big.cmp tbody {
+       font-size: 150%;
+}
+@media (max-width: 48em) {
+       .keys.big.cmp tbody {
+               font-size: 100%;
+       }
+       .keys.big.cmp tbody a {
+               white-space: normal;
+       }
+}
+.keys.cmp tbody {
+       display: table-row-group;
+}
+.keys.cmp tr {
+       display: table-row;
+}
+.keys.cmp tr > * {
+       display: table-cell;
+       position: static; /* under sticky thead */
+}
+.keys.cmp tbody th {
+       padding-right: 1ex;
+       text-align: right;
+}
+
+@font-face {
+       font-family: osicons;
+       src: url(/osicon.ttf);
+}
+.icon {
+       font-family: osicons;
+}
+.keys.cmp tbody .ni {
+       font-size: 80%;
+       padding: 0 .2em;
+}
+
+.graph {
+       display: block;
+       line-height: 1ex;
+       height: 1.2ex;
+       margin-top: .4ex;
+}
+.graph ~ .graph {
+       /* subsequent graphs */
+       height: .7ex;
+}
+.graph > * {
+       display: inline-block;
+       height: 100%;
+       vertical-align: top;
+}
+.graph > label {
+       font-size: 75%;
+       margin-right: .2em;
+}
+.graph > span {
+       border: 1px solid #000;
+       border-right-width: 0;
+       font-size: 0;
+}
+.graph > :last-of-type {
+       border-right-width: 1px;
+}
+.graph > .ext {
+       border-left: 0; /* assume following unext */
+}
+
 img {
        object-fit: cover;
        height: 100%;
+       vertical-align: middle;
 }
 </style>
 .
@@ -30,23 +111,86 @@ img {
 :>
 <h1>Extended keyboards</h1>
 
-<p>Representative images of available layouts
-with AltGr or similar modifier keys.</p>
+<p>Overview of available key layouts with AltGr or similar modifier keys.
+Also see <a href="/digraphs">digraphs</a> for compose key combinations.
+</p>
+
+<:
+my $idx = Data($indexfile);
+my @incs;
+push @incs, @{ $idx->{$_} } for @{ $idx->{default} };
 
-<section class="gallery"><:
+my @sample = split /(?<!\+)/, $get{sample} // 'asSci1!+1';
+require Shiar_Sheet::Keyboard;
+Shiar_Sheet::Keyboard->VERSION(3.00);
+use List::Util qw( uniq max sum );
+
+my %caticon = (
+       legacy  => qq{<span class=icon title="deprecated">\N{TOP HAT}</span>},
+       windows => qq{<span class=icon title="Windows">\x{1FA9F}</span>}, # \N{WINDOW}
+       macos   => qq{<span class=icon title="MacOS">\N{RED APPLE}</span>},
+       xorg    => qq{<span class=icon title="Xorg">\N{PENGUIN}</span>},
+);
+
+printf '<section class="%s">', @sample ? 'section' : 'gallery';
+if (@sample) {
+       print '<table class="big keys cmp">';
+       print '<thead><tr><th colspan=2>';
+       print "<th>$_" for @sample;
+       say '</tr></thead>';
+}
+my $most = max(
+       map { sum values %{$_} } map { $_->{inventory}{''} } @{$idx}{@incs}
+);
 for my $inc (@incs) {
-       $inc =~ s/\Q.inc.pl\E$//;
-       print '<figure>';
-       printf '<a href="/%s">', $inc =~ s/\.eng$//r;
-       if (my $table = eval { Data($inc) }) {
+       my $table = $idx->{$inc};
+       print @sample ? '<tr><th>' : '<figure>';
+       printf '<a href="/%s">', "$dirbase/$inc";
+       my $title = $table->{title} || $inc;
+
+       unless (@sample) {
                if (my $img = $table->{image}) {
                        EscapeHTML $name = $table->{imagealt} // $img =~ m{.*/([^/.]*)};
                        print qq{<img src="/$img" alt="$name" />};
                }
-               $inc = $table->{title};
+               printf '<figcaption>%s</figcaption>', $title;
+               say '</a></figure>';
+       }
+       else {
+               print $title;
+               print '</a>', "\n\t";
+               for my $mode ($table->{mode} ? sort keys %{ $table->{mode} } : '') {
+                       print '<span class=graph>';
+                       printf "<label>%s</label>", m/^(\S*)/
+                               for $mode && $table->{mode}{$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 {
+                                               $table->{flag}{$_}[0] || 'extra'  # legend label of each class
+                                       } reverse split / /, $g)
+                                       for $table->{inventory}{$mode}{$g};
+                       }
+                       say '</span>';
+               }
+               print "\t<td class=ni>";
+               print join ' ', map { $caticon{$_} // () }
+                       split m{/}, $table->{category} // '';
+               say '';
+               if (my $keys = eval {
+                       my $keydata = Data("$dirbase/$inc.eng");
+                       Shiar_Sheet::Keyboard->new($keydata)
+               }) {
+                       for my $c (@sample) {
+                               my $def = $keys->{def}{''}{$c} // [];
+                               $def->[0] //= 'ni';
+                               $def->[0] =~ s/ mode\S*//;
+                               $keys->print_key('', $c, $def);
+                       }
+               }
+               say '</tr>';
        }
-       printf '<figcaption>%s</figcaption>', $inc;
-       say '</a></figure>';
 }
+print '</table>' if @sample;
 :></section>