67249ec302e5a5816e71bbb2cd94be1d4c6fe71e
[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.</p>
115
116 <:
117 my $idx = Data($indexfile);
118 my @incs;
119 push @incs, @{ $idx->{$_} } for @{ $idx->{default} };
120
121 my @sample = split /(?<!\+)/, $get{sample} // 'asSci1!+1';
122 require Shiar_Sheet::Keyboard;
123 Shiar_Sheet::Keyboard->VERSION(3.00);
124 use List::Util qw( uniq max sum );
125
126 my %caticon = (
127         legacy  => qq{<span class=icon title="deprecated">\N{TOP HAT}</span>},
128         windows => qq{<span class=icon title="Windows">\x{1FA9F}</span>}, # \N{WINDOW}
129         macos   => qq{<span class=icon title="MacOS">\N{RED APPLE}</span>},
130         xorg    => qq{<span class=icon title="Xorg">\N{PENGUIN}</span>},
131 );
132
133 printf '<section class="%s">', @sample ? 'section' : 'gallery';
134 if (@sample) {
135         print '<table class="big keys cmp">';
136         print '<thead><tr><th colspan=2>';
137         print "<th>$_" for @sample;
138         say '</tr></thead>';
139 }
140 my $most = max(map { sum values %{ $_->{inventory}{''} } } %{$idx}{@incs});
141 for my $inc (@incs) {
142         my $table = $idx->{$inc};
143         print @sample ? '<tr><th>' : '<figure>';
144         printf '<a href="/%s">', "$dirbase/$inc";
145         my $title = $table->{title} || $inc;
146
147         unless (@sample) {
148                 if (my $img = $table->{image}) {
149                         EscapeHTML $name = $table->{imagealt} // $img =~ m{.*/([^/.]*)};
150                         print qq{<img src="/$img" alt="$name" />};
151                 }
152                 printf '<figcaption>%s</figcaption>', $title;
153                 say '</a></figure>';
154         }
155         else {
156                 print $title;
157                 print '</a>', "\n\t";
158                 for my $mode ($table->{mode} ? sort keys %{ $table->{mode} } : '') {
159                         print '<span class=graph>';
160                         printf "<label>%s</label>", m/^(\S*)/
161                                 for $mode && $table->{mode}{$mode} || ();
162                         for my $g (sort keys %{ $table->{inventory}{$mode} }) {
163                                 printf '<span class="%s" style="width:%.0f%%" title="%3$d %4$s"> %s</span>',
164                                         $g, $_/$most*100, $_,
165                                         join(' ', map {
166                                                 $table->{flag}{$_}[0] || 'extra'  # legend label of each class
167                                         } reverse split / /, $g)
168                                         for $table->{inventory}{$mode}{$g};
169                         }
170                         say '</span>';
171                 }
172                 print "\t<td class=ni>";
173                 print join ' ', map { $caticon{$_} // () }
174                         split m{/}, $table->{category} // '';
175                 say '';
176                 if (my $keys = eval {
177                         my $keydata = Data("$dirbase/$inc.eng");
178                         Shiar_Sheet::Keyboard->new($keydata)
179                 }) {
180                         for my $c (@sample) {
181                                 my $def = $keys->{def}{''}{$c} // [];
182                                 $def->[0] //= 'ni';
183                                 $def->[0] =~ s/ mode\S*//;
184                                 $keys->print_key('', $c, $def);
185                         }
186                 }
187                 say '</tr>';
188         }
189 }
190 print '</table>' if @sample;
191 :></section>
192