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