keyboard/altgr/index: calculate maximum inventory without names
[sheet.git] / keyboard / altgr / index.inc.plp
1 <: # included from keyboard.plp
2 use 5.014;
3 use warnings;
4 use utf8;
5
6 my $dirbase = 'keyboard/altgr';
7 my $indexfile = "$dirbase/index";
8
9 Html({
10         title => "altgr keyboard cheat sheets",
11         version => '1.3',
12         description => [
13                 "Overview of alternate keyboard modes,",
14                 "offering extended Unicode characters if a modifier key",
15                 "(such as AltGr or option) is pressed.",
16         ],
17         keywords => [qw'
18                 sheet cheat reference overview keyboard altgr option
19         '],
20         image => "$dirbase/thumb/ibm-m.jpg",
21         stylesheet => [qw( light dark circus mono red )],
22         data => ["$dirbase/index.inc.plp", "$indexfile.inc.pl"],
23         raw => <<'.',
24 <style>
25 .keys.cmp {
26         display: inline-table; /* centered */
27         float: none;
28         margin: 0;
29         border-collapse: separate;
30         border-spacing: 2px;
31         border-spacing: .4vw; /* inline td margin equivalent */
32 }
33 .keys.big.cmp tbody {
34         font-size: 150%;
35 }
36 @media (max-width: 48em) {
37         .keys.big.cmp tbody {
38                 font-size: 100%;
39         }
40         .keys.big.cmp tbody a {
41                 white-space: normal;
42         }
43 }
44 .keys.cmp tbody {
45         display: table-row-group;
46 }
47 .keys.cmp tr {
48         display: table-row;
49 }
50 .keys.cmp tr > * {
51         display: table-cell;
52         position: static; /* under sticky thead */
53 }
54 .keys.cmp tbody th {
55         padding-right: 1ex;
56         text-align: right;
57 }
58
59 @font-face {
60         font-family: osicons;
61         src: url(/osicon.ttf);
62 }
63 .icon {
64         font-family: osicons;
65 }
66 .keys.cmp tbody .ni {
67         font-size: 80%;
68         padding: 0 .2em;
69 }
70
71 .graph {
72         display: block;
73         line-height: 1ex;
74         height: 1.2ex;
75         margin-top: .4ex;
76 }
77 .graph ~ .graph {
78         /* subsequent graphs */
79         height: .7ex;
80 }
81 .graph > * {
82         display: inline-block;
83         height: 100%;
84         vertical-align: top;
85 }
86 .graph > label {
87         font-size: 75%;
88         margin-right: .2em;
89 }
90 .graph > span {
91         border: 1px solid #000;
92         border-right-width: 0;
93         font-size: 0;
94 }
95 .graph > :last-of-type {
96         border-right-width: 1px;
97 }
98 .graph > .ext {
99         border-left: 0; /* assume following unext */
100 }
101
102 img {
103         object-fit: cover;
104         height: 100%;
105         vertical-align: middle;
106 }
107 </style>
108 .
109 });
110
111 :>
112 <h1>Extended keyboards</h1>
113
114 <p>Overview of available key layouts with AltGr or similar modifier keys.
115 Also see <a href="/digraphs">digraphs</a> for compose key combinations.
116 </p>
117
118 <:
119 my $idx = Data($indexfile);
120 my @incs;
121 push @incs, @{ $idx->{$_} } for @{ $idx->{default} };
122
123 my @sample = split /(?<!\+)/, $get{sample} // 'asSci1!+1';
124 require Shiar_Sheet::Keyboard;
125 Shiar_Sheet::Keyboard->VERSION(3.00);
126 use List::Util qw( uniq max sum );
127
128 my %caticon = (
129         legacy  => qq{<span class=icon title="deprecated">\N{TOP HAT}</span>},
130         windows => qq{<span class=icon title="Windows">\x{1FA9F}</span>}, # \N{WINDOW}
131         macos   => qq{<span class=icon title="MacOS">\N{RED APPLE}</span>},
132         xorg    => qq{<span class=icon title="Xorg">\N{PENGUIN}</span>},
133 );
134
135 printf '<section class="%s">', @sample ? 'section' : 'gallery';
136 if (@sample) {
137         print '<table class="big keys cmp">';
138         print '<thead><tr><th colspan=2>';
139         print "<th>$_" for @sample;
140         say '</tr></thead>';
141 }
142 my $most = max(
143         map { sum values %{$_} } map { $_->{inventory}{''} } @{$idx}{@incs}
144 );
145 for my $inc (@incs) {
146         my $table = $idx->{$inc};
147         print @sample ? '<tr><th>' : '<figure>';
148         printf '<a href="/%s">', "$dirbase/$inc";
149         my $title = $table->{title} || $inc;
150
151         unless (@sample) {
152                 if (my $img = $table->{image}) {
153                         EscapeHTML $name = $table->{imagealt} // $img =~ m{.*/([^/.]*)};
154                         print qq{<img src="/$img" alt="$name" />};
155                 }
156                 printf '<figcaption>%s</figcaption>', $title;
157                 say '</a></figure>';
158         }
159         else {
160                 print $title;
161                 print '</a>', "\n\t";
162                 for my $mode ($table->{mode} ? sort keys %{ $table->{mode} } : '') {
163                         print '<span class=graph>';
164                         printf "<label>%s</label>", m/^(\S*)/
165                                 for $mode && $table->{mode}{$mode} || ();
166                         for my $g (sort keys %{ $table->{inventory}{$mode} }) {
167                                 printf '<span class="%s" style="width:%.0f%%" title="%3$d %4$s"> %s</span>',
168                                         $g, $_/$most*100, $_,
169                                         join(' ', map {
170                                                 $table->{flag}{$_}[0] || 'extra'  # legend label of each class
171                                         } reverse split / /, $g)
172                                         for $table->{inventory}{$mode}{$g};
173                         }
174                         say '</span>';
175                 }
176                 print "\t<td class=ni>";
177                 print join ' ', map { $caticon{$_} // () }
178                         split m{/}, $table->{category} // '';
179                 say '';
180                 if (my $keys = eval {
181                         my $keydata = Data("$dirbase/$inc.eng");
182                         Shiar_Sheet::Keyboard->new($keydata)
183                 }) {
184                         for my $c (@sample) {
185                                 my $def = $keys->{def}{''}{$c} // [];
186                                 $def->[0] //= 'ni';
187                                 $def->[0] =~ s/ mode\S*//;
188                                 $keys->print_key('', $c, $def);
189                         }
190                 }
191                 say '</tr>';
192         }
193 }
194 print '</table>' if @sample;
195 :></section>
196