9e4d6b53dc88bf3e2b99995d45a9a61a4bfd6708
[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} // 0) cmp ($idx{$b}{category} // 0)
138         || $a cmp $b
139 } keys %idx) {
140         print @sample ? '<tr><th>' : '<figure>';
141         printf '<a href="/%s">', $inc =~ s/\.eng$//r;
142         my $table = $idx{$inc};
143         my $title = $table && $table->{title} || $inc;
144
145         unless (@sample) {
146                 if ($table and my $img = $table->{image}) {
147                         EscapeHTML $name = $table->{imagealt} // $img =~ m{.*/([^/.]*)};
148                         print qq{<img src="/$img" alt="$name" />};
149                 }
150                 printf '<figcaption>%s</figcaption>', $title;
151                 say '</a></figure>';
152         }
153         else {
154                 print $title;
155                 print '</a>', "\n\t";
156                 my $keys = Shiar_Sheet::Keyboard->new($table);
157                 for my $mode ($keys->{mode} ? sort keys %{ $keys->{mode} } : '') {
158                         my %inventory;
159                         $inventory{$_}++ for grep { /^g[2-9]/ } map { s/ (?!ext).*//r }
160                                 values %{ $keys->{def}{$mode} };
161                         print '<span class=graph>';
162                         printf '<label>%s</label>', s/\s.*//r for $keys->{key}{$mode} || ();
163                         for my $g (sort keys %inventory) {
164                                 printf '<span class="%s" style="width:%.0f%%" title="%3$d %4$s"> %s</span>',
165                                         $g, $_/$most*100, $_,
166                                         join(' ', map {
167                                                 $keys->{flag}{$_}[0] || 'extra'  # legend label of each class
168                                         } reverse split / /, $g)
169                                         for $inventory{$g};
170                         }
171                         say '</span>';
172                 }
173                 print "\t<td class=ni>";
174                 print join ' ', map { $caticon{$_} // () } split m{/}, $keys->{category} // '';
175                 say '';
176                 $keys->print_key('', $_, ($keys->{def}{''}{$_} // 'ni') =~ s/ mode\S*//r)
177                         for @sample;
178                 say '</tr>';
179         }
180 }
181 print '</table>' if @sample;
182 :></section>
183